Generated Narrative: StructureMap MedicationOverviewLMToMedicationOverviewBundle #xD; map "http://smart.who.int/ph4h/StructureMap/MedicationOverviewLMToMedicationOverviewBundle" = "MedicationOverviewLMToMedicationOverviewBundle"#xD; #xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/MedicationOverviewLM" alias MedicationOverviewLM as source#xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/PatientLM" alias PatientLM as source#xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/MedicationTreatmentLineLM" alias MedicationTreatmentLineLM as source#xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/PractitionerLM" alias PractitionerLM as source#xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/MedicationOverview" alias MedicationOverviewBundle as target#xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/MedicationOverviewComposition" alias MedicationOverviewComposition as target#xD; uses "https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/MedicationTreatmentLine" alias MedicationTreatmentLine as target#xD; uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as target#xD; uses "http://hl7.org/fhir/StructureDefinition/Practitioner" alias Practitioner as target#xD; #xD; // ---------------------------------------------------------------------------#xD; // Top-level group: assemble MedicationOverview Bundle (document)#xD; // ---------------------------------------------------------------------------#xD; group MedicationOverviewLMToMedicationOverviewBundle(source src : MedicationOverviewLM, target tgt : MedicationOverviewBundle) {#xD; src -> tgt.type = 'document' "bundleType";#xD; src -> tgt.timestamp = (now()) "bundleTimestamp";#xD; // Generate fixed UUIDs once; reuse them across entries and Reference targets.#xD; src -> uuid() as bid, uuid() as cid, uuid() as pid then {#xD; // Bundle.identifier (UUID identifier per RFC 4122)#xD; src -> tgt.identifier as id, id.system = 'urn:ietf:rfc:4122', id.value = bid "bundleIdentifier";#xD; // Composition entry. The Composition group ALSO emits the treatment-line bundle#xD; // entries (passing tgt in), so each section.entry reference can share the same#xD; // UUID as its bundle entry — making the lines reachable from the Composition.#xD; src -> tgt.entry as ce, ce.fullUrl = append('urn:uuid:', cid), ce.resource = create('MedicationOverviewComposition') as comp then {#xD; src then MedicationOverviewLMToComposition(src, comp, pid, tgt) "compositionContent";#xD; } "compositionEntry";#xD; // Patient entry#xD; src.patient as pref -> tgt.entry as pe, pe.fullUrl = append('urn:uuid:', pid), pe.resource = create('Patient') as pat then {#xD; pref then PatientLMToPatient(pref, pat) "patientContent";#xD; } "patientEntry";#xD; } "setEntries";#xD; }#xD; #xD; // ---------------------------------------------------------------------------#xD; // MedicationOverviewLM -> MedicationOverviewComposition#xD; // Receives the Patient entry's UUID (pid) so subject can reference it.#xD; // ---------------------------------------------------------------------------#xD; group MedicationOverviewLMToComposition(source src : MedicationOverviewLM, target tgt : MedicationOverviewComposition, source pid, target bundle : MedicationOverviewBundle) {#xD; src -> tgt.status = 'final' "compStatus";#xD; // Composition.type — LOINC 56445-0 "Medication summary Document"#xD; src -> create('Coding') as cc, cc.system = 'http://loinc.org', cc.code = '56445-0', cc.display = 'Medication summary Document', create('CodeableConcept') as ct, ct.coding = cc, tgt.type = ct "compType";#xD; // Composition.subject -> Patient entry by uuid#xD; src -> create('Reference') as subj, subj.reference = append('urn:uuid:', pid), tgt.subject = subj "compSubject";#xD; src -> tgt.date = (now()) "compDate";#xD; src -> tgt.title = 'Medication Overview' "compTitle";#xD; // Composition.author is 1..* (required). The Min source carries no author, so#xD; // emit a display-only placeholder Reference to satisfy the cardinality.#xD; // TODO: replace with the real authoring Organization/Device once the source#xD; // (or a config value) provides it.#xD; src -> create('Reference') as au, au.display = 'Medication Overview generator', tgt.author = au "compAuthor";#xD; // Section: MedRecordTreatmentLine#xD; src -> tgt.section as sect then {#xD; src -> sect.title = 'Medication Treatment Lines' "sectTitle";#xD; src -> create('Coding') as scc, scc.system = 'http://loinc.org', scc.code = '10160-0', scc.display = 'History of Medication use Narrative', create('CodeableConcept') as sc, sc.coding = scc, sect.code = sc "sectCode";#xD; // One UUID per line, shared by the section.entry reference AND the bundle entry,#xD; // so each treatment line is reachable by forward traversal from the Composition#xD; // (mirrors the ICVP ICVPLMToIPS pattern). This is why the group receives the#xD; // Bundle: the line entries are created here, not in the top-level group.#xD; src.medicationTreatmentLine as lref -> uuid() as tid then {#xD; lref -> sect.entry as se, se.reference = append('urn:uuid:', tid) "sectEntry";#xD; lref -> bundle.entry as te, te.fullUrl = append('urn:uuid:', tid), te.resource = create('MedicationTreatmentLine') as ms then {#xD; lref then MedicationTreatmentLineLMToMedicationStatement(lref, ms, pid) "lineContent";#xD; } "lineEntry";#xD; } "treatmentLines";#xD; } "sectionTreatmentLines";#xD; // Attester from verification BackboneElement#xD; src.verification as v -> tgt.attester as att then {#xD; v -> att.mode = 'professional' "attMode";#xD; v.verificationTime as vt -> att.time = vt "attTime";#xD; // practicioner is Reference(PractitionerLM) in the LM — copy the reference#xD; // as-is ((pr.name.text) was invalid: References have no name).#xD; v.practicioner as pr -> att.party = pr "attParty";#xD; } "attester";#xD; // Comment -> R4 Composition has NO `note` element (R5-only). Use the#xD; // cross-version extension, mirroring the r4 profile's approach for adherence.#xD; src.comment as cm -> create('Extension') as ext, ext.url = 'http://hl7.org/fhir/5.0/StructureDefinition/extension-Composition.note', create('Annotation') as nt then {#xD; cm.commentText as ctxt -> nt.text = ctxt "noteText";#xD; cm.date as d -> nt.time = d "noteTime";#xD; // author is a Reference in the LM; Annotation.author[x] resolves by type.#xD; cm.author as a -> nt.author = a "noteAuthor";#xD; cm -> ext.value = nt, tgt.extension = ext "noteAssign";#xD; } "noteFromComment";#xD; }#xD; #xD; // ---------------------------------------------------------------------------#xD; // PatientLM -> FHIR Patient#xD; // ---------------------------------------------------------------------------#xD; group PatientLMToPatient(source src : PatientLM, target tgt : Patient) {#xD; src.identifier as id -> tgt.identifier = id "patIdentifier";#xD; src.name as n -> tgt.name = n "patName";#xD; // gender: navigate instead of a FHIRPath evaluate — validator can't scope#xD; // rule variables inside (…) expressions.#xD; src.gender as g then {#xD; g.coding as gc then {#xD; gc.code as gcode -> tgt.gender = gcode "patGenderCode";#xD; } "patGenderCoding";#xD; } "patGender";#xD; // dateOfBirth is dateTime in LM; birthDate is date — silent truncation expected.#xD; src.dateOfBirth as d -> tgt.birthDate = d "patBirthDate";#xD; }#xD; #xD; // ---------------------------------------------------------------------------#xD; // MedicationTreatmentLineLM -> MedicationTreatmentLine (profile on MedicationStatement, R4)#xD; // Receives the Patient entry's UUID (pid) so MS.subject can reference it.#xD; // ---------------------------------------------------------------------------#xD; group MedicationTreatmentLineLMToMedicationStatement(source src : MedicationTreatmentLineLM, target tgt : MedicationTreatmentLine, source pid) {#xD; src.identifier as id -> tgt.identifier = id;#xD; // subject -> Patient entry by uuid (MS.subject is 1..1)#xD; src -> create('Reference') as subj, subj.reference = append('urn:uuid:', pid), tgt.subject = subj "subject";#xD; src.status as st -> tgt.status = st;#xD; // medication[x] choice -> R4 medication[x] (no CodeableReference in R4;#xD; // the engine resolves medicationReference/medicationCodeableConcept by value type)#xD; src.medication : Reference as mr -> tgt.medication = mr "medicationRef";#xD; src.medication : CodeableConcept as mc -> tgt.medication = mc "medicationCC";#xD; // effective[x] on R4 MedicationStatement — address the choice by base name.#xD; src.effectivePeriod as ep -> tgt.effective = ep;#xD; src.recordingMetadata as rm then {#xD; rm.recordedTime as rt -> tgt.dateAsserted = rt "dateAsserted";#xD; rm.recorder as rc -> tgt.informationSource = rc "informationSource";#xD; };#xD; // reason -> R4 reasonCode (0..* CodeableConcept; no CodeableReference in R4)#xD; src.indication as ind -> tgt.reasonCode = ind "reasonIndication";#xD; src.indicationText as it -> create('CodeableConcept') as cc, cc.text = it, tgt.reasonCode = cc "reasonIndicationText";#xD; // intendedUse: no R4 MedicationStatement element and no extension slice in the#xD; // r4 MEOW profile — intentionally not mapped (stays LM-only).#xD; src.usageInstructions as ui -> tgt.dosage = ui "dosage";#xD; src.preparationInstructions as pi -> create('Dosage') as dos, dos.text = pi, tgt.dosage = dos "prepInstructions";#xD; // note = comment#xD; src.comment as cm -> create('Annotation') as nt then {#xD; cm.commentText as ct -> nt.text = ct "lineNoteText";#xD; cm.date as d -> nt.time = d "lineNoteTime";#xD; cm.author as a -> nt.author = a "lineNoteAuthor";#xD; cm -> tgt.note = nt "lineNoteAssign";#xD; } "lineNote";#xD; // adherence -> R4 has no MS.adherence; the r4 profile slices the R5#xD; // cross-version extension (1..1 in the profile, sub-extensions code/reason).#xD; src.treatmentStatus as ts -> create('Extension') as ext, ext.url = 'http://hl7.org/fhir/5.0/StructureDefinition/extension-MedicationStatement.adherence', create('Extension') as e1, e1.url = 'code', e1.value = ts, ext.extension = e1, tgt.extension = ext "extAdherence";#xD; src.treatmentStatusReasonCode as tsr -> create('Extension') as ext, ext.url = 'http://hl7.org/fhir/5.0/StructureDefinition/extension-MedicationStatement.adherence', create('Extension') as e1, e1.url = 'reason', e1.value = tsr, ext.extension = e1, tgt.extension = ext "extAdherenceReason";#xD; src.category as cat -> tgt.category = cat;#xD; src.derivedFrom as df then {#xD; df.request as rq -> tgt.derivedFrom = rq "derivedFromRequest";#xD; df.statement as stm -> tgt.derivedFrom = stm "derivedFromStatement";#xD; df.dispensation as dsp -> tgt.derivedFrom = dsp "derivedFromDispensation";#xD; df.administration as adm -> tgt.derivedFrom = adm "derivedFromAdministration";#xD; df.other as oth -> tgt.derivedFrom = oth "derivedFromOther";#xD; };#xD; // Extension: artifact-version#xD; src.version as v -> create('Extension') as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/artifact-version', ext.value = v, tgt.extension = ext "extVersion";#xD; // Extension: VerificationInformation#xD; src.verificationInformation as vi -> create('Extension') as ext then {#xD; vi -> ext.url = 'https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/ihe-ext-medicationstatement-verificationinformation' "viUrl";#xD; vi.verifier as vr -> create('Extension') as e1, e1.url = 'verifier', e1.value = vr, ext.extension = e1 "viVerifier";#xD; vi.verificationTime as vt -> create('Extension') as e2, e2.url = 'verificationTime', e2.value = vt, ext.extension = e2 "viTime";#xD; vi -> tgt.extension = ext "viAssign";#xD; } "extVerification";#xD; // Extension: Substitution#xD; src.substitution as sub -> create('Extension') as ext then {#xD; sub -> ext.url = 'https://profiles.ihe.net/PHARM/MEOW/StructureDefinition/ihe-ext-medicationstatement-substitution' "subUrl";#xD; sub.substitutionType as t -> create('Extension') as e1, e1.url = 'substitutionType', e1.value = t, ext.extension = e1 "subType";#xD; sub.substitutionTypeReason as r -> create('Extension') as e2, e2.url = 'substitutionTypeReason', e2.value = r, ext.extension = e2 "subReason";#xD; sub.substitutionTypeReasonText as rt -> create('Extension') as e3, e3.url = 'substitutionTypeReasonText', e3.value = rt, ext.extension = e3 "subReasonText";#xD; sub -> tgt.extension = ext "subAssign";#xD; } "extSubstitution";#xD; }#xD; #xD; // ---------------------------------------------------------------------------#xD; // PractitionerLM -> FHIR Practitioner#xD; // ---------------------------------------------------------------------------#xD; group PractitionerLMToPractitioner(source src : PractitionerLM, target tgt : Practitioner) {#xD; src.identifier as id -> tgt.identifier = id "practIdentifier";#xD; src.name as n -> tgt.name = n "practName";#xD; }#xD; #xD;