def fhir_condition(obj): """ Converts Disease to FHIR Condition. """ condition = cond.Condition() condition.id = str(obj['id']) condition.code = fhir_codeable_concept(obj['term']) # subject is required by Pheno-FHIR mapping Guide and by FHIR, set to 'unknown' condition.subject = fhirreference.FHIRReference() condition.subject.reference = 'unknown' condition.extension = [] # only adds disease-onset if it's ontology term # NOTE it is required element by Pheno-FHIR mapping guide but not Phenopackets if check_disease_onset(obj): onset_extension = extension.Extension() onset_extension.url = PHENOPACKETS_ON_FHIR_MAPPING['disease']['onset'] onset_extension.valueCodeableConcept = fhir_codeable_concept( obj['onset']['age']) condition.extension.append(onset_extension) if 'disease_stage' in obj.keys(): for item in obj['disease_stage']: disease_stage_extension = extension.Extension() disease_stage_extension.url = PHENOPACKETS_ON_FHIR_MAPPING[ 'disease']['disease_stage'] disease_stage_extension.valueCodeableConcept = fhir_codeable_concept( item) condition.extension.append(disease_stage_extension) return condition.as_json()
def __init__(self, Patient=None): """ Uses fhirclient.models to create, validate, and post a Condition FHIR resource. :returns: GenerateCondition object which has Condition object as an attribute. """ if Patient == None: self.Patient = generatepatient.GeneratePatient().Patient else: self.Patient = Patient self._generate_icd_code() Condition = cond.Condition() Condition.clinicalStatus = 'active' Condition.verificationStatus = 'confirmed' # Condition.verificationStatus = 'active' # Condition.category = self._create_FHIRCodeableConcept(code='problem', system='urn:oid:2.16.840.1.113883.4.642.3.153', display='Problem List Item') Condition.code = self._create_FHIRCodeableConcept( code=self.icd_code, system='urn:oid:2.16.840.1.113883.6.3', display=self.icd_description) Condition.patient = self._create_FHIRReference(self.Patient) self._validate(Condition) self.response = self.post_resource(Condition) Condition.id = self._extract_id() self.Condition = Condition self.Condition.Patient = self.Patient print(self)
def condition_to_disease(obj): """ FHIR Condition to Phenopackets Disease. """ condition = cond.Condition(obj) codeable_concept = condition.code # CodeableConcept disease = { "term": { # id is an integer AutoField, legacy id can be a string # "id": condition.id, "id": f"{codeable_concept.coding[0].system}:{codeable_concept.coding[0].code}", "label": codeable_concept.coding[0].display # TODO collect system info in metadata }, "extra_properties": condition.as_json() } # condition.stage.type is only in FHIR 4.0.0 version return disease
def import_condition(self, res, options): """Import a single condition""" verbosity = options['verbosity'] strict = options['strict'] force = options['force'] f_condition = cond.Condition(res, strict=strict) logger.info(f'Importing {f_condition}') d_condition = Condition( code=self.get_codeableconcept(f_condition.code), onset_datetime=f_condition.onsetDateTime.date, subject_id=f_condition.subject.reference[ 9:] # Remove urn:uuid: prefix ) try: d_condition.save() except IntegrityError as err: logger.error('Saving condition to database failed', exc_info=True)
def disease_to_fhir(obj): """Converts Disease to FHIR Condition. :param obj: Disease json :return: FHIR Condition json """ schema_path = os.path.join(SCHEMA_PATH, 'disease_schema.json') try: validate_schema(schema_path, obj) except jsonschema.exceptions.ValidationError: raise Exception("The disease object is not valid.") condition = cond.Condition() if 'id' in obj: condition.id = str(obj['id']) condition.code = fhir_codeable_concept(obj['term']) # subject is required by Pheno-FHIR mapping Guide and by FHIR, set to 'unknown' condition.subject = fhirreference.FHIRReference() condition.subject.reference = 'unknown' condition.extension = [] # only adds disease-onset if it's ontology term # NOTE it is required element by Phenopackets IG but not Phenopackets # what do to if it's AGE string? if check_disease_onset(obj): onset_extension = extension.Extension() onset_extension.url = PHENOPACKETS_ON_FHIR_MAPPING['disease']['onset'] onset_extension.valueCodeableConcept = fhir_codeable_concept( obj['onset']['age']) condition.extension.append(onset_extension) if 'diseaseStage' in obj: for item in obj['diseaseStage']: disease_stage_extension = extension.Extension() disease_stage_extension.url = PHENOPACKETS_ON_FHIR_MAPPING[ 'disease']['disease_stage'] disease_stage_extension.valueCodeableConcept = fhir_codeable_concept( item) condition.extension.append(disease_stage_extension) return condition.as_json()
def to_fhir_obj(self): condition = c.Condition(base_condition) #observation.subject_reference = self.subject_reference condition.subject.reference = self.subject_reference return condition