0.1.0 - ci-build
HIVFHIRIG, published by intellisoftkenya. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/IntelliSOFT-Consulting/HIV-FHIR-IG/ and changes regularly. See the Directory of published versions
Official URL: https://IntelliSOFT-Consulting.github.io/HIV-FHIR-IG/StructureMap/HIVObservationHIVCondition | Version: 0.1.0 | |||
Draft as of 2024-09-18 | Computable Name: HIVObservationHIVCondition |
declare the structure defs used
Generated Narrative: StructureMap HIVObservationHIVCondition
map "https://IntelliSOFT-Consulting.github.io/HIV-FHIR-IG/StructureMap/HIVObservationHIVCondition" = "HIVObservationHIVCondition" // declare the structure defs used uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias input as source uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias output as target // declare group with local vars (src, tgt) and their aliases // anything ending with semicolon is a rule group HIVObservationHIVCondition(source src : input, target tgt : output) { // set bundle type for the output bundle src -> tgt.type = 'transaction' "setBundleType"; // loop through patients in input bundle src.entry as entry -> tgt.entry as tentry then { entry.resource : Patient as patient -> tentry.resource = patient, tentry.request as newrequest then { entry -> tentry.fullUrl = ('urn:uuid:' & patient.id) "setFullUrl"; entry -> newrequest.method = 'PUT', newrequest.url = ('Patient/' & patient.id) "setPatientRequest"; entry -> tgt.entry as pentry, pentry.resource = create('Provenance') as prov, uuid() as pid, pentry.request as prequest then { patient -> prov.id = pid "setPId"; patient -> pentry.fullUrl = ('urn:uuid:' & pid) "setFullUrl"; patient -> prequest.method = 'PUT', prequest.url = ('Provenance/' & pid) "setrequest"; patient -> prov.target as ptarg then { patient -> ptarg.reference = ('urn:uuid:' & patient.id) "setTargetRef"; } "setTarget"; patient -> prov.entity as entity then { patient -> entity.role = 'source' "setRole"; patient -> entity.what as pwhat then setProvenanceFromBundleId(src, pwhat) "setWhatId"; } "setEntity"; } "setProvenance"; // for observations of that patient look for art program enrollment // create a condition resource in output with uuid src.entry as obsentry where resource.is(Observation) and resource.subject.exists(reference = ('Patient/' & patient.id)) and resource.code.exists(coding.exists((system = 'https://cielterminology.org') and (code = '160540'))) -> tgt.entry as newentry, newentry.resource = create('Condition') as cond, uuid() as cid then { obsentry.resource as obs -> newentry.fullUrl = ('urn:uuid:' & cid), newentry.request as newrequest then { obsentry -> cond.id = cid "setCId"; // setrequest rule for resource in transaction bundle // needs to be processed properly before putting on existing data on fhir server obsentry -> newrequest.method = 'PUT', newrequest.url = ('Condition/' & cid) "setrequest"; patient -> cond.subject as subject then { patient -> subject.reference = reference(patient) "setSubjectRef"; } "setSubject"; obs.effective as effective -> cond.onset = effective "setOnset"; obsentry -> cond.clinicalStatus = cc('http://terminology.hl7.org/CodeSystem/condition-clinical', 'active', 'Active') "setClinicalStatus"; obsentry -> cond.code = cc('http://smart.who.int/hiv/CodeSystem/HIVConcepts', 'HIV.B.DE116', 'HIV-positive') "setCode"; obsentry -> cond.category = cc('http://terminology.hl7.org/CodeSystem/condition-category', 'encounter-diagnosis', 'Encounter Diagnosis') "setCategory"; // create provenance resource to document input/output resources links obs -> tgt.entry as pentry, pentry.resource = create('Provenance') as prov, uuid() as pid, pentry.request as prequest then { obs -> prov.id = pid "setPId"; obs -> pentry.fullUrl = ('urn:uuid:' & pid) "setFullUrl"; obs -> prequest.method = 'PUT', prequest.url = ('Provenance/' & pid) "setrequest"; obs -> prov.target as ptarg then { obs -> ptarg.reference = ('urn:uuid:' & cid) "setTargetRef"; } "setTarget"; obs -> prov.entity as entity then { obs -> entity.role = 'source' "setRole"; obs -> entity.what as pwhat then setProvenanceFromBundleId(src, pwhat) "setWhatId"; } "setEntity"; } "setProvenance"; } "setCondition"; } "getOnARTObservation"; // for observations of that patient look for return visit date // create a medication request resource in output with uuid src.entry as obsentry where resource.is(Observation) and resource.subject.exists(reference = ('Patient/' & patient.id)) and resource.code.exists(coding.exists((system = 'https://cielterminology.org') and (code = '5096'))) -> tgt.entry as newentry, newentry.resource = create('MedicationStatement') as ms, uuid() as msid then { obsentry.resource as obs -> newentry.fullUrl = ('urn:uuid:' & msid), newentry.request as newrequest then { obsentry -> ms.id = msid "setMSId"; // setrequest rule for resource in transaction bundle // needs to be processed properly before putting on existing data on fhir server obsentry -> newrequest.method = 'PUT', newrequest.url = ('MedicationStatement/' & msid) "setrequest"; patient -> ms.subject as subject then { patient -> subject.reference = reference(patient) "setSubjectRef"; } "setSubject"; // obs.effective as effective -> ms.effective = effective "setEffective"; obs.effective : dateTime as effective -> ms.effective = create('Period') as mseffective then { effective -> mseffective.start = effective "setEffectiveStart"; effective -> mseffective.end = (%effective + 30 'days') "setEffectiveEnd"; } "setEffective"; // not correct in hiv l3 obsentry -> ms.status = 'active' "setStatus"; obsentry -> ms.reasonCode = cc('http://smart.who.int/hiv/CodeSystem/HIVConcepts', 'HIV.H.DE47', 'On ART') "setMSReasonCode"; obsentry -> ms.medication = create('CodeableConcept') as medication then { obsentry -> medication.coding as coding then { obsentry -> coding.code = '160119', coding.display = 'CURRENTLY TAKING ARV', coding.system = 'https://cielterminology.org' "setMSCoding"; } "setMSCoding"; } "SetMSMedication"; // create provenance resource to document input/output resources links obs -> tgt.entry as pentry, pentry.resource = create('Provenance') as prov, uuid() as pid, pentry.request as prequest then { obs -> prov.id = pid "setPId"; obs -> pentry.fullUrl = ('urn:uuid:' & pid) "setFullUrl"; obs -> prequest.method = 'PUT', prequest.url = ('Provenance/' & pid) "setrequest"; obs -> prov.target as ptarg then { obs -> ptarg.reference = ('urn:uuid:' & msid) "setTargetRef"; } "setTarget"; obs -> prov.entity as entity then { obs -> entity.role = 'source' "setRole"; obs -> entity.what as pwhat then setProvenanceFromBundleId(src, pwhat) "setWhatId"; } "setEntity"; } "setProvenance"; } "setMedicationStatement"; } "getVisitObservation"; // create observation resource with the positive hiv test codes // this will have to be one for hiv positive and one for hiv negative src.entry as obsentry where resource.is(Observation) and resource.subject.exists(reference = ('Patient/' & patient.id)) and resource.code.exists(coding.exists((system = 'https://cielterminology.org') and (code = '159427'))) -> tgt.entry as newentry, newentry.resource = create('Observation') as observe, uuid() as obsd then { obsentry.resource as obs -> newentry.fullUrl = ('urn:uuid:' & obsd), newentry.request as newrequest then { obsentry -> observe.id = obsd "setOBSd"; obsentry -> newrequest.method = 'PUT', newrequest.url = ('Observation/' & obsd) "setrequest"; patient -> observe.subject as subject then { patient -> subject.reference = reference(patient) "setSubjectRef"; } "setSubject"; obs.effective as effective -> observe.effective = effective "setOnset"; obs.code as code -> observe.code = code "setCode"; obs.value : CodeableConcept as value where coding.exists((system = 'https://cielterminology.org') and (code = '664')) -> observe.value = create('CodeableConcept') as val then { value -> val.coding as coding then { value -> coding.system = 'http://smart.who.int/hiv/CodeSystem/HIVConcepts', coding.code = 'HIV.B.DE117', coding.display = 'HIV-negative' "setNegativeCC"; } "setNegativeCoding"; } "setValueNegative"; obs.value : CodeableConcept as value where coding.exists((system = 'https://cielterminology.org') and (code = '138571')) -> observe.value = create('CodeableConcept') as val then { value -> val.coding as coding then { value -> coding.system = 'http://smart.who.int/hiv/CodeSystem/HIVConcepts', coding.code = 'HIV.B.DE116', coding.display = 'HIV-positive' "setPositiveCC"; } "setPositiveCoding"; } "setValuePositive1"; obs.value : CodeableConcept as value where coding.exists((system = 'https://cielterminology.org') and (code = '703')) -> observe.value = create('CodeableConcept') as val then { value -> val.coding as coding then { value -> coding.system = 'http://smart.who.int/hiv/CodeSystem/HIVConcepts', coding.code = 'HIV.B.DE116', coding.display = 'HIV-positive' "setPositiveCC"; } "setPositiveCoding"; } "setValuePositive2"; obsentry -> observe.status = cc('http://hl7.org/fhir/observation-status', 'final', 'Final') "setStatus"; obs -> tgt.entry as pentry, pentry.resource = create('Provenance') as prov, uuid() as pid, pentry.request as prequest then { obs -> prov.id = pid "setPId"; obs -> pentry.fullUrl = ('urn:uuid:' & pid) "setFullUrl"; obs -> prequest.method = 'PUT', prequest.url = ('Provenance/' & pid) "setrequest"; obs -> prov.target as ptarg then { obs -> ptarg.reference = ('urn:uuid:' & cid) "setTargetRef"; } "setTarget"; obs -> prov.entity as entity then { obs -> entity.role = 'source' "setRole"; obs -> entity.what as pwhat then setProvenanceFromBundleId(src, pwhat) "setWhatId"; } "setEntity"; } "setProvenance"; } "setHIVPositiveTest"; } "getOnARTObservation"; } "patientResource"; } "copyPatient"; } group setProvenanceFromBundleId(source bundle : input, target provwhat : Reference) { bundle.id as bundleid -> provwhat.identifier as whatid then { bundleid -> whatid.value = ('Bundle/' & bundleid) "setWhatIdValue"; } "setWhatId"; }