Skip to content

onconova.interoperability.fhir.schemas.genomic_variant

GenomicVariantProfile

Bases: OnconovaFhirBaseSchema, OnconovaGenomicVariant

__model__ class-attribute instance-attribute

__schema__ class-attribute instance-attribute

fhir_to_onconova(obj) classmethod

Source code in onconova/interoperability/fhir/schemas/genomic_variant.py
@classmethod
def fhir_to_onconova(
    cls, obj: fhir.OnconovaGenomicVariant
) -> schemas.GenomicVariantCreate:

    if (
        version := obj.fhirpath_single(
            "Observation.component.where(code.coding.code='81303-0').valueString.getValue()"
        )
    ) != HGVSRegex.VERSION:
        raise ValueError(
            f"Unsupported HGVS version: {version}. Only version {HGVSRegex.VERSION} is supported."
        )

    return schemas.GenomicVariantCreate(
        externalSource=None,
        externalSourceId=None,
        caseId=obj.fhirpath_single(
            "Observation.subject.reference.getValue()"
        ).replace("Patient/", ""),
        date=obj.fhirpath_single("Observation.effectiveDateTime.getValue()"),
        genes=[
            CodedConcept.model_validate(coding.model_dump())
            for coding in obj.fhirpath_values(
                "Observation.component.where(code.coding.code='48018-6').valueCodeableConcept.coding"
            )
        ],
        assessmentDate=obj.fhirpath_single(
            "Observation.extension('http://onconova.github.io/fhir/StructureDefinition/onconova-ext-genomic-variant-assessment-date').valueDateTime.getValue()",
        ),
        genePanel=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='C165600').valueString.getValue()",
        ),
        dnaHgvs=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='48004-6').valueCodeableConcept.coding.code.getValue()"
        )
        or obj.fhirpath_single(
            "Observation.component.where(code.coding.code='81290-9').valueCodeableConcept.coding.code.getValue()"
        ),
        proteinHgvs=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='48005-3').valueCodeableConcept.coding.code.getValue()"
        ),
        rnaHgvs=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='rna-hgvs').valueCodeableConcept.coding.code.getValue()"
        ),
        assessment=(
            cls.map_to_internal("GenomicVariantAssessment", assessment)
            if (
                assessment := obj.fhirpath_single(
                    "Observation.valueCodeableConcept.coding",
                )
            )
            else None
        ),
        confidence=(
            cls.map_to_internal("Confidence", confidence)
            if (
                confidence := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='variant-confidence-status').valueCodeableConcept.coding",
                )
            )
            else None
        ),
        analysisMethod=(
            CodedConcept.model_validate(method.model_dump())
            if (method := obj.fhirpath_single("Observation.method.coding"))
            else None
        ),
        clinicalRelevance=(
            cls.map_to_internal("ClinicalRelevance", relevance)
            if (
                relevance := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='LL4034-6').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        genomeAssemblyVersion=(
            CodedConcept.model_validate(coding.model_dump())
            if (
                coding := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='62374-4').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        molecularConsequence=(
            CodedConcept.model_validate(coding.model_dump())
            if (
                coding := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='molecular-consequence').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        copyNumber=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='82155-3').valueQuantity.value.getValue()"
        ),
        alleleFrequency=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='81258-6').valueQuantity.value / 100"
        ),
        alleleDepth=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='82121-5').valueQuantity.value.getValue()"
        ),
        zygosity=(
            CodedConcept.model_validate(coding.model_dump())
            if (
                coding := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='53034-5').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        source=(
            CodedConcept.model_validate(coding.model_dump())
            if (
                coding := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='48002-0').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        inheritance=(
            CodedConcept.model_validate(coding.model_dump())
            if (
                coding := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='variant-inheritance').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        coordinateSystem=(
            CodedConcept.model_validate(coding.model_dump())
            if (
                coding := obj.fhirpath_single(
                    "Observation.component.where(code.coding.code='92822-6').valueCodeableConcept.coding"
                )
            )
            else None
        ),
        clinvar=obj.fhirpath_single(
            "Observation.component.where(code.coding.code='81252-9').valueCodeableConcept.coding.code.getValue()"
        ),
    )

onconova_to_fhir(obj) classmethod

Source code in onconova/interoperability/fhir/schemas/genomic_variant.py
@classmethod
def onconova_to_fhir(
    cls, obj: schemas.GenomicVariant
) -> fhir.OnconovaGenomicVariant:
    resource = fhir.OnconovaGenomicVariant.model_construct()
    resource.id = str(obj.id)
    resource.text = Narrative(
        status="generated",
        div=f'<div xmlns="http://www.w3.org/1999/xhtml">{obj.description}</div>',
    )
    resource.effectiveDateTime = obj.date.isoformat()
    resource.subject = Reference(
        reference=f"Patient/{obj.caseId}",
    )
    resource.component = [
        fhir.OnconovaGenomicVariantHgvsVersion(
            valueString=obj.hgvsVersion,
        )
    ]
    if obj.assessmentDate:
        resource.extension = [
            fhir.GenomicVariantAssessmentDate(
                valueDateTime=obj.assessmentDate.isoformat(),
            )
        ]
    if obj.assessment:
        resource.valueCodeableConcept = construct_fhir_codeable_concept(
            cls.map_to_fhir("GenomicVariantAssessment", obj.assessment)
        )
    if obj.analysisMethod:
        resource.method = construct_fhir_codeable_concept(obj.analysisMethod)

    if obj.genePanel:
        resource.component.append(
            fhir.OnconovaGenomicVariantGenePanelSequencing(
                valueString=obj.genePanel,
            )
        )
    for gene in obj.genes:
        resource.component.append(
            fhir.GenomicFindingGeneStudied(
                valueCodeableConcept=construct_fhir_codeable_concept(gene),
            )
        )
    if obj.clinicalRelevance is not None:
        if coding := cls.map_to_fhir("ClinicalRelevance", obj.clinicalRelevance):
            resource.component.append(
                fhir.OnconovaGenomicVariantClinicalRelevance(
                    valueCodeableConcept=construct_fhir_codeable_concept(coding)
                )
            )
    if obj.cytogeneticLocation is not None:
        resource.component.append(
            fhir.GenomicFindingCytogeneticLocation(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(
                        code=obj.cytogeneticLocation,
                        system="https://iscn.karger.com",
                    )
                )
            )
        )
    if obj.chromosomes is not None:
        resource.component.extend(
            [
                fhir.VariantChromosomeIdentifier(
                    valueCodeableConcept=construct_fhir_codeable_concept(
                        cls.map_to_fhir("Chromosomes", chr)
                    )
                )
                for chr in obj.chromosomes
            ]
        )
    if obj.genomeAssemblyVersion is not None:
        resource.component.append(
            fhir.GenomicFindingReferenceSequenceAssembly(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    obj.genomeAssemblyVersion
                )
            )
        )
    if obj.dnaHgvs and "c." in obj.dnaHgvs:
        resource.component.append(
            fhir.VariantCodingHgvs(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(code=obj.dnaHgvs, system="http://varnomen.hgvs.org")
                ),
            )
        )
    if obj.dnaHgvs and "g." in obj.dnaHgvs:
        resource.component.append(
            fhir.OnconovaGenomicVariantGenomicHgvs(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(code=obj.dnaHgvs, system="http://varnomen.hgvs.org")
                ),
            )
        )
    if obj.proteinHgvs is not None:
        resource.component.append(
            fhir.VariantProteinHgvs(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(code=obj.proteinHgvs, system="http://varnomen.hgvs.org")
                ),
            )
        )
    if obj.rnaHgvs is not None:
        resource.component.append(
            fhir.OnconovaGenomicVariantRnaHgvs(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(code=obj.rnaHgvs, system="http://varnomen.hgvs.org")
                ),
            )
        )
    if obj.dnaReferenceSequence is not None:
        if re.search(
            rf"{HGVSRegex.GENOMIC_REFSEQ}",
            obj.dnaReferenceSequence,
        ):
            component = fhir.VariantGenomicRefSeq
        else:
            component = fhir.VariantTranscriptRefSeq
        resource.component.append(
            component(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(
                        code=obj.dnaReferenceSequence,
                        system="http://www.ncbi.nlm.nih.gov/refseq",
                    )
                )
            )
        )
    if obj.coordinateSystem is not None:
        resource.component.append(
            fhir.VariantCoordinateSystem(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    obj.coordinateSystem
                )
            )
        )
    if obj.dnaChangeType is not None:
        mapped_code = cls.map_to_fhir("CodingChangeType", obj.dnaChangeType)
        if mapped_code is not None:
            resource.component.append(
                fhir.VariantCodingChangeType(
                    valueCodeableConcept=construct_fhir_codeable_concept(
                        mapped_code
                    )
                )
            )
    if obj.proteinChangeType is not None:
        mapped_code = cls.map_to_fhir("AminoAcidChangeType", obj.proteinChangeType)
        if mapped_code is not None:
            resource.component.append(
                fhir.VariantAminoAcidChangeType(
                    valueCodeableConcept=construct_fhir_codeable_concept(
                        mapped_code
                    )
                )
            )
    if obj.molecularConsequence is not None:
        resource.component.append(
            fhir.VariantMolecularConsequence(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    obj.molecularConsequence
                )
            )
        )
    if obj.confidence is not None:
        resource.component.append(
            fhir.VariantVariantConfidenceStatus(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    cls.map_to_fhir("Confidence", obj.confidence)
                )
            )
        )
    if obj.zygosity is not None:
        resource.component.append(
            fhir.VariantAllelicState(
                valueCodeableConcept=construct_fhir_codeable_concept(obj.zygosity)
            )
        )
    if obj.inheritance is not None:
        resource.component.append(
            fhir.VariantVariantInheritance(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    obj.inheritance
                )
            )
        )
    if obj.alleleDepth is not None:
        resource.component.append(
            fhir.VariantAllelicReadDepth(
                valueQuantity=Quantity(
                    value=obj.alleleDepth,
                    code="{reads}",
                    system="http://unitsofmeasure.org",
                    unit="reads",
                ),
            )
        )
    if obj.alleleFrequency is not None:
        resource.component.append(
            fhir.VariantSampleAllelicFrequency(
                valueQuantity=fhir.VariantValueQuantity(
                    value=obj.alleleFrequency * 100,
                    code="%",
                    system="http://unitsofmeasure.org",
                ),
            )
        )
    if obj.source is not None:
        resource.component.append(
            fhir.GenomicVariantGenomicSourceClass(
                valueCodeableConcept=construct_fhir_codeable_concept(obj.source)
            )
        )
    if obj.copyNumber is not None:
        resource.component.append(
            fhir.VariantCopyNumber(
                valueQuantity=Quantity(
                    value=obj.copyNumber,
                    code="{copies}",
                    system="http://unitsofmeasure.org",
                    unit="copies",
                ),
            )
        )
    if obj.nucleotidesLength is not None:
        resource.component.append(
            fhir.OnconovaGenomicVariantNucleotidesCount(
                valueInteger=obj.nucleotidesLength,
            )
        )
    if obj.regions is not None:
        resource.component.extend(
            [
                fhir.OnconovaGenomicVariantGeneRegion(valueString=region)
                for region in obj.regions
            ]
        )
    if obj.clinvar is not None:
        resource.component.append(
            fhir.GenomicVariantVariationCode(
                valueCodeableConcept=construct_fhir_codeable_concept(
                    Coding(
                        code=obj.clinvar,
                        system="https://www.ncbi.nlm.nih.gov/clinvar",
                    )
                )
            )
        )
    return resource
runner