CDA-FHIR-Maps (R4)
0.1.1 - CI build

CDA-FHIR-Maps (R4), published by ahdis. This is not an authorized publication; it is the continuous build for version 0.1.1). This version is based on the current content of https://github.com/hl7ch/cda-fhir-maps/ and changes regularly. See the Directory of published versions

FHIR to CDA types

Format(s):

Narrative view

map "http://fhir.ch/ig/cda-fhir-maps/StructureMap/FhirToCdaTypes" = "FhirToCdaTypes"

// Adapted from https://github.com/HL7/ccda-to-fhir/tree/master/mappings
// CDA:  http://build.fhir.org/ig/ahdis/cda-core-2.0/branches/master/index.html
// FHIR: http://hl7.org/fhir/r4/

conceptmap "uri2oid" {
  prefix s = "http://hl7.org/fhir"
  prefix t = "http://hl7.org/cda"

  s:"http://snomed.info/sct" == t:"2.16.840.1.113883.6.96"
  s:"http://loinc.org" == t:"2.16.840.1.113883.6.1"
  s:"http://hl7.org/fhir/sid/atc" == t:"2.16.840.1.113883.6.73"
  s:"http://www.whocc.no/atc" == t:"2.16.840.1.113883.6.73"
  s:"http://terminology.hl7.org/CodeSystem/v3-substanceAdminSubstitution" == t:"2.16.840.1.113883.5.1070"
}

conceptmap "uri2system" {
  prefix s = "http://hl7.org/fhir"
  prefix t = "http://hl7.org/cda"

  s:"http://snomed.info/sct" == t:"SNOMED CT"
  s:"http://loinc.org" == t:LOINC
  s:"http://hl7.org/fhir/sid/atc" == t:"ATC WHO"
  s:"http://www.whocc.no/atc" == t:"ATC WHO"
  s:"http://terminology.hl7.org/CodeSystem/v3-substanceAdminSubstitution" == t:"HL7 Substance Admin Substitution"
}

conceptmap "oid2system" {
  prefix s = "http://hl7.org/fhir"
  prefix t = "http://hl7.org/cda"

  s:"urn:oid:2.51.1.1" == t:GTIN
  s:"urn:oid:1.3.6.1.4.1.19376.1.9.2.1" == t:"IHE Pharmaceutical Advice Status List"
}

conceptmap "addressUse" {
  prefix s = "http://hl7.org/fhir/valueset-address-use.html"
  prefix t = "http://terminology.hl7.org/ValueSet/v3-AddressUse"

  s:home == t:H
  s:work == t:WP
  s:temp == t:TMP
  s:old == t:OLD
}

uses "http://hl7.org/fhir/StructureDefinition/Identifier" as source
uses "http://hl7.org/fhir/cda/StructureDefinition/II" as target

group Any(source src, target tgt) {
  src.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor' -> tgt.nullFlavor as nullFlavor then {
    extension.valueCode as valueCode then {
      valueCode.value as v -> nullFlavor.value = cast(v, 'string');
    } "nullFlavor";
  };
}

group IdentifierII(source src : Identifier, target tgt : II) extends Any <<types>> {
  src.value as value where src.system.empty() and src.value.startsWith('urn:uuid:') -> tgt.root = (value.substring(9).upper()) "idAsUuid";
  src.value as value where src.system = 'urn:ietf:rfc:3986' -> tgt.root = (value.substring(9).upper()) "idAsUuid";
  src.value as value where src.system.startsWith('urn:oid:') then {
    src.system as system ->  tgt.root = (system.substring(8)),  tgt.extension = value "oidident";
  } "system";
}

group IntegerINT(source src : integer, target tgt : INT) extends Any <<types>> {
  src.value as v -> tgt.value = v "integer";
}

// group Identifier(source src : Identifier, target tgt : II) extends Any <<types>> {
// src.system as system then {
// src.value as value then {
// value.value as v where system.value = 'urn:ietf:rfc:3986' -> tgt.root = cast(v, 'string') "noExtension";
// system.value as v where system.value != 'urn:ietf:rfc:3986' -> tgt.root = v then {
// value.value as val -> tgt.extension = cast(val, 'string') "extension";
// } "withExtension";
// } "rootValue";
// } "root";
// src.value as value -> tgt.root = '123' "test";
// src -> tgt.root = '123' "test";
// src.assigner as a then {
// a.display as display then {
// display.value as val -> tgt.assigningAuthorityName = cast(val, 'string');
// } "display";
// } "assigner";
// src.extension as ext where ext.url = 'http://hl7.org/fhir/cdaStructureDefinition/extension-displayable' -> tgt.displayable as displayable then {
// ext.value as v -> displayable.value = cast(v, 'string');
// } "displayable";
// }
group InstantTS(source src : instant, target tgt : TS) extends Any <<types>> {
  src.value as v -> tgt.value = v "copy";
}

group DateTimeTS(source src : dateTime, target tgt : TS) extends InstantTS <<types>> {
}

group DateTS(source src : date, target tgt : TS) extends InstantTS <<types>> {
}

group CodeCS(source src : code, target tgt : CS) extends Any <<types>> {
  src.code as c -> tgt.value = cast(c, 'string');
}

group CodeCE(source src : code, target tgt : CE) extends CodeCS <<types>> {
}

group CodeCD(source src : code, target tgt : CD) extends CodeCS <<types>> {
}

group CodingCE(source src : Coding, target tgt : CE) extends Any <<types>> {
  src.code as code -> tgt.code = code;
  src.system as system where $this.startsWith('http:') -> tgt.codeSystem = translate(system, '#uri2oid', 'code');
  src.system as system where $this.startsWith('urn:oid:') then {
    src.system as system -> tgt.codeSystem = (system.substring(8)) "oidident";
  };
  src.system as system where $this.startsWith('http:') -> tgt.codeSystemName = translate(system, '#uri2system', 'code') "systemName1";
  src.system as system where $this.startsWith('urn:oid:') -> tgt.codeSystemName = translate(system, '#oid2system', 'code') "systemName2";
  src.display as display -> tgt.displayName = display;
}

group CodeableConceptCE(source src : CodeableConcept, target tgt : CE) extends Any <<types>> {
  src.text as text ->  tgt.orginialText as originalText,  originalText.data = text;
  src.coding first as coding then CodingCE(coding, tgt) "first";
  src.coding not_first as coding -> tgt.translation as translation then CodingCE(coding, translation) "translation";
}

// group CECodeableConcept(source src : CE, target tgt : CodeableConcept) extends Any <<types>> {
// src.originalText -> tgt.text;
// src -> tgt.coding as coding then {
// src.code as code -> coding.code = cast(code, 'string');
// src.codeSystem as system -> coding.system = translate(system, 'http://hl7.org/fhir/ConceptMap/special-oid2uri', 'uri');
// src.displayName as display -> coding.display = cast(display, 'string');
// } "code";
// src.translation as translation -> tgt.coding as coding then {
// translation.code as code -> coding.code = cast(code, 'string');
// translation.codeSystem as system -> coding.system = translate(system, 'http://hl7.org/fhir/ConceptMap/special-oid2uri', 'uri');
// translation.displayName as display -> coding.display = cast(display, 'string');
// } "translation";
// }
// group CSCodeableConcept(source src : CS, target tgt : CodeableConcept) extends CECodeableConcept <<types>> {
// }
// group CDCodeableConcept(source src : CD, target tgt : CodeableConcept) extends CECodeableConcept <<types>> {
// }
group AddressAD(source src : Address, target tgt : AD) extends Any <<types>> {
  src.line as v ->  tgt.streetAddressLine as line,  line.data = v "streetAddress";
  src.postalCode as v ->  tgt.postalCode as postalCode,  postalCode.data = v;
  src.city as v ->  tgt.city as city,  city.data = v;
  src.state as v ->  tgt.state as state,  state.data = v;
  src.district as v ->  tgt.county as county,  county.data = v;
  src.country as v ->  tgt.country as country,  country.data = v;
  src.use as c -> tgt.use = translate(c, '#addressUse', 'code') "addressUse";
}

group ContactPointTEL(source src : ContactPoint, target tgt : TEL) extends Any <<types>> {
  src.value as value -> tgt.value = (iif(%src.system = 'phone', 'tel:', '') + iif(%src.system = 'fax', 'fax:', '') + iif(%src.system = 'email', 'mailto:', '') + iif(%src.system = 'url', 'http:', '') + value);
  src.use as use where $this = 'home' -> tgt.use = 'HP';
  src.use as use where $this = 'work' -> tgt.use = 'WP';
  // not complete see below
  src.use as use where $this = 'old' -> tgt.use = 'BAD';
  src.use as use where $this = 'temp' -> tgt.use = 'TMP';
  src.use as use where $this = 'mobile' -> tgt.use = 'MC';
}

group HumanNameEN(source src : HumanName, target tgt : EN) extends Any <<types>> {
  src.family as v ->  tgt.family as family,  family.data = v;
  src.given as v ->  tgt.given as given,  given.data = v;
  src.prefix as v ->  tgt.prefix as prefix,  prefix.data = v;
  src.suffix as v ->  tgt.suffix as suffix,  suffix.data = v;
}

group QuantityPQ(source src : Quantity, target tgt : PQ) extends Any <<types>> {
  // src.code as code -> tgt.unit = code;
  src.unit as unit -> tgt.unit = unit;
  src.value as value -> tgt.value = value;
}

group RatioRTOPQPQ(source src : Ratio, target tgt : RTO_PQ_PQ) extends Any <<types>> {
  src.numerator as numerator -> tgt.numerator as targetNumerator then QuantityPQ(numerator, targetNumerator);
  src.denominator as denominator -> tgt.denominator as targetDenominator then QuantityPQ(denominator, targetDenominator);
}