@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