Beispiel #1
0
def _create_or_update_pending_sampleSetItem(
        request, user, sampleSet_ids, sample, sampleGender,
        sampleRelationshipRole, sampleRelationshipGroup, sampleControlType,
        selectedBarcodeKit, selectedBarcode, sampleCancerType,
        sampleCellularityPct, sampleNucleotideType, pcrPlateRow,
        sampleBiopsyDays, sampleCellNum, sampleCoupleId, sampleEmbryoId,
        sampleSetItemDescription):

    if selectedBarcode:
        dnabarcode = models.dnaBarcode.objects.get(name=selectedBarcodeKit,
                                                   id_str=selectedBarcode)
    else:
        dnabarcode = None

    if sampleNucleotideType.lower() == "fusions":
        sampleNucleotideType = "rna"

    for sampleSet_id in sampleSet_ids:
        sampleSet = get_object_or_404(SampleSet, pk=sampleSet_id)
        relationshipGroup = int(
            sampleRelationshipGroup) if sampleRelationshipGroup else 0
        pcrPlateColumn = "1" if pcrPlateRow else ""

        sampleSetItem_kwargs = {
            'gender': sampleGender,
            'relationshipRole': sampleRelationshipRole,
            'relationshipGroup': relationshipGroup,
            'controlType': sampleControlType,
            'cancerType': sampleCancerType,
            'cellularityPct': sampleCellularityPct,
            'dnabarcode': dnabarcode,
            'pcrPlateRow': pcrPlateRow,
            'pcrPlateColumn': pcrPlateColumn,
            'biopsyDays': sampleBiopsyDays,
            'cellNum': sampleCellNum,
            'coupleId': sampleCoupleId,
            'embryoId': sampleEmbryoId,
            'description': sampleSetItemDescription,
            'lastModifiedUser': user,
        }
        try:
            sampleSetItem = SampleSetItem.objects.get(
                sample=sample,
                sampleSet_id=sampleSet_id,
                nucleotideType=sampleNucleotideType,
                dnabarcode=dnabarcode)
        except:
            sampleSetItem = SampleSetItem(sample=sample,
                                          sampleSet_id=sampleSet_id,
                                          nucleotideType=sampleNucleotideType,
                                          creator=user)

        for field, value in sampleSetItem_kwargs.iteritems():
            setattr(sampleSetItem, field, value)
        sampleSetItem.save()
Beispiel #2
0
def _create_or_update_pending_sampleSetItem(request, user, sampleSet_ids, sample, sampleGender, sampleRelationshipRole, sampleRelationshipGroup, sampleControlType,
        selectedBarcodeKit, selectedBarcode, sampleCancerType, sampleCellularityPct, sampleNucleotideType,
        pcrPlateRow, sampleBiopsyDays, sampleCellNum, sampleCoupleId, sampleEmbryoId, sampleSetItemDescription):

    if selectedBarcode:
        dnabarcode = models.dnaBarcode.objects.get(name=selectedBarcodeKit, id_str=selectedBarcode)
    else:
        dnabarcode = None

    if sampleNucleotideType.lower() == "fusions":
        sampleNucleotideType = "rna"

    for sampleSet_id in sampleSet_ids:
        sampleSet = get_object_or_404(SampleSet, pk=sampleSet_id)
        relationshipGroup = int(sampleRelationshipGroup) if sampleRelationshipGroup else 0
        pcrPlateColumn = "1" if pcrPlateRow else ""

        sampleSetItem_kwargs = {
            'gender': sampleGender,
            'relationshipRole': sampleRelationshipRole,
            'relationshipGroup': relationshipGroup,
            'controlType': sampleControlType,
            'cancerType': sampleCancerType,
            'cellularityPct': sampleCellularityPct,
            'dnabarcode': dnabarcode,
            'pcrPlateRow': pcrPlateRow,
            'pcrPlateColumn': pcrPlateColumn,
            'biopsyDays': sampleBiopsyDays,
            'cellNum': sampleCellNum,
            'coupleId': sampleCoupleId,
            'embryoId': sampleEmbryoId,
            'description': sampleSetItemDescription,
            'lastModifiedUser': user,
        }
        try:
            sampleSetItem = SampleSetItem.objects.get(sample=sample, sampleSet_id=sampleSet_id, nucleotideType=sampleNucleotideType, dnabarcode=dnabarcode)
        except:
            sampleSetItem = SampleSetItem(sample=sample, sampleSet_id=sampleSet_id, nucleotideType=sampleNucleotideType, creator=user)

        for field, value in sampleSetItem_kwargs.iteritems():
            setattr(sampleSetItem, field, value)
        sampleSetItem.save()
Beispiel #3
0
def _create_or_update_sampleSetItem(
    queryDict, user, item_id=None, sampleSet_id=None, sample=None
):
    # use case 1: if item_id is defined we are editing existing SampleSetItem
    # use case 2: if sampleSet_id is defined we are editing or adding a new SampleSetItem

    sampleSetItem_kwargs = _get_sampleSetItem_kwargs(queryDict, sampleSet_id)
    if item_id:
        sampleSetItem = get_object_or_404(SampleSetItem, pk=item_id)

    elif sampleSet_id:
        sampleSet = get_object_or_404(SampleSet, pk=sampleSet_id)
        try:
            sampleSetItem = SampleSetItem.objects.get(
                sample=sample,
                sampleSet_id=sampleSet_id,
                nucleotideType=sampleSetItem_kwargs["nucleotideType"],
                dnabarcode=sampleSetItem_kwargs["dnaBarcode"],
            )
        except Exception:
            sampleSetItem = SampleSetItem(
                sample=sample,
                sampleSet_id=sampleSet_id,
                nucleotideType=sampleSetItem_kwargs["nucleotideType"],
                creator=user,
            )
    else:
        raise Exception(
            "Unable to update sample: missing SampleSetItem id or SampleSet id"
        )

    for field, value in sampleSetItem_kwargs.items():
        setattr(sampleSetItem, field, value)

    logger.debug(
        "views_helper._create_or_update_sampleSetItem sampleSetItem_kwargs=%s"
        % (sampleSetItem_kwargs)
    )
    sampleSetItem.save()