FHIR Mapping Language (FML)
0.1.0 - STU 1 World

FHIR Mapping Language (FML), published by HL7 International / FHIR Infrastructure. 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/HL7/mapping-language-ig/ and changes regularly. See the Directory of published versions

StructureMap: TransformReference

Official URL: http://hl7.org/fhir/uv/mapping-language/StructureMap/TransformReference Version:
Standards status: Informative Computable Name: TransformReference

Example demonstrating the reference transform to generate a resource reference

/// url = 'http://hl7.org/fhir/uv/mapping-language/StructureMap/TransformReference'
/// name = 'TransformReference'
/// status = 'active'
/// description = 'Example demonstrating the reference transform to generate a resource reference'

uses "http://hl7.org/fhir/StructureDefinition/Patient" as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" as target
uses "http://hl7.org/fhir/StructureDefinition/Encounter" as produced

group TransformReference(source src : Patient, target tgt : Bundle) {
  // add in the patient to the bundle as is
  src ->  tgt.entry as patEntry,  patEntry.resource = src "patEntry";
  src ->  create('Encounter') as enc,  tgt.entry as entry then {
    src.id as v ->  enc.subject as s,  s.reference = reference(src) "r2";
    // Note the encounter entry is added after it has been populated
    src -> entry.resource = enc "encounterEntry";
  } "encEntry";
}