POC - Mapping CDA to FHIR
0.1.0 - ci-build

POC - Mapping CDA to FHIR - Local Development build (v0.1.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

## StructureMap: Mapping de CDA vers les FHIR Types (A partir des sources de Oliver Egger)

Official URL: https://interop.esante.gouv.fr/ig/fhir/mappingcdafhir/StructureMap/CdaToFHIRTypes | Version: 0.1.0
Draft as of 2025-11-07 | Computable Name: CdaToFHIRTypes

Mapping de CDA vers les FHIR Types (A partir des sources de Oliver Egger)

    map "https://interop.esante.gouv.fr/ig/fhir/mappingcdafhir/StructureMap/CdaToFHIRTypes" = "CdaToFHIRTypes"

    // Mapping de CDA vers les FHIR Types (A partir des sources de Oliver Egger)

    uses "http://hl7.org/cda/stds/core/StructureDefinition/ED" alias ED as source
    uses "http://hl7.org/cda/stds/core/StructureDefinition/PN" alias PN as source
    uses "http://hl7.org/cda/stds/core/StructureDefinition/II" alias II as source
    uses "http://hl7.org/fhir/StructureDefinition/Identifier" alias Identifier as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/TS" alias TS as source
    uses "http://hl7.org/fhir/StructureDefinition/instant" alias instant as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/CS" alias CS as source
    uses "http://hl7.org/fhir/StructureDefinition/code" alias code as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/CE" alias CE as source
    uses "http://hl7.org/fhir/StructureDefinition/CodeableConcept" alias CodeableConcept as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/ST" alias ST as source
    uses "http://hl7.org/fhir/StructureDefinition/string" alias string as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/EN" alias EN as source
    uses "http://hl7.org/fhir/StructureDefinition/HumanName" alias HumanName as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/AD" alias AD as source
    uses "http://hl7.org/fhir/StructureDefinition/Address" alias Address as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/TEL" alias TEL as source
    uses "http://hl7.org/fhir/StructureDefinition/ContactPoint" alias ContactPoint as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/BL" alias BL as source
    uses "http://hl7.org/fhir/StructureDefinition/boolean" alias boolean as target
    uses "http://hl7.org/cda/stds/core/StructureDefinition/IVL-TS" alias IVL_TS as source
    uses "http://hl7.org/fhir/StructureDefinition/Period" alias Period as target

    group Any(source src, target tgt) {
      src -> tgt "base";
    }

    group II(source src : II, target tgt : Identifier) extends Any <<types>> {
      src.root as r where src.extension.exists() -> tgt.system = append('urn:oid:', r) "root1";
      src.root as r where src.extension.empty() and src.root.matches('[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}') ->  tgt.system = 'urn:ietf:rfc:3986',  tgt.value = ('urn:uuid:' + r.lower()) "rootuuid";
      src.root as r where src.extension.empty() and src.root.contains('.') ->  tgt.system = 'urn:ietf:rfc:3986',  tgt.value = append('urn:oid:', r) "rootoid";
      src.extension as e -> tgt.value = e;
      src.assigningAuthorityName as s ->  tgt.assigner as a,  a.display = s; // there's no equivalent for displayable in FHIR - and it probably will never matter, but if it does, it might map to Identifier.use.
      src.displayable as displayable -> tgt.extension as ext then {
        displayable -> ext.url = 'http://hl7.org/fhir/cdaStructureDefinition/extension-displayable' "url";
        displayable.value as v -> ext.value = cast(v, 'string');
      } "extension";
    }

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

    group TemplateID(source template : II, target tgt) {
      template -> tgt.extension as ext then {
        template -> ext.url = 'http://hl7.org/cda/stds/core/StructureDefinition/templateID' "url";
        template -> ext.value = create('Identifier') as value then II(template, value) "value";
      } "templateId";
    }

    group Negation(source negation : BL, target tgt) {
      negation -> tgt.modifierExtension as ext then {
        negation -> ext.url = 'http://hl7.org/cda/stds/core/StructureDefinition/negationIndicator' "url";
        negation as neg ->  ext.value = create('boolean'),  ext.value = neg "value";
      } "negation";
    }

    group TSInstant(source src : TS, target tgt : instant) extends Any <<types>> {
      src.value as v -> tgt.value = cast(v, 'string');
    }

    group TSDateTime(source src : TS, target tgt : dateTime) extends TSInstant <<types>> {
      src -> tgt "inherit";
    }

    group TSDate(source src : TS, target tgt : date) extends TSInstant <<types>> {
      src -> tgt "inherit";
    }

    group IVLTSPeriod(source src : IVL_TS, target tgt : Period) extends Any <<types>> {
      src.low as low -> tgt.start = create('dateTime') as start then TSDateTime(low, start);
      src.high as high -> tgt.end = create('dateTime') as end then TSDateTime(high, end);
    }

    group IVLTSDateTime(source src : IVL_TS, target tgt : dateTime) extends Any <<types>> {
      src.low as s then TSDateTime(s, tgt);
    }

    group STstring(source src : ST, target tgt : string) {
      src as v -> tgt.value = cast(v, 'string') "value";
    }

    group EDstring(source src : ED, target tgt : string) extends STstring <<types>> {
      src -> tgt "inherit";
    }

    group ONstring(source src : ON, target tgt : string) extends STstring <<types>> {
      src -> tgt "inherit";
    }

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

    group CECode(source src : CE, target tgt : code) extends CSCode <<types>> {
      src -> tgt "inherit";
    }

    group CDCode(source src : CD, target tgt : code) extends CSCode <<types>> {
      src -> tgt "inherit";
    }

    group CECodeableConcept(source src : CE, target tgt : CodeableConcept) {
      src.originalText as originalText -> tgt.text = originalText "setOriginalText";
      src -> tgt.coding as coding then {
        src.code as code -> coding.code = cast(code, 'string');
        src.codeSystem as system -> coding.system = append('urn:oid:', system);
        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 = append('urn:oid:', system);
        translation.displayName as display -> coding.display = cast(display, 'string');
      };
    }

    group CSCodeableConcept(source src : CS, target tgt : CodeableConcept) extends CECodeableConcept <<types>> {
      src -> tgt "inherit";
    }

    group CDCodeableConcept(source src : CD, target tgt : CodeableConcept) extends CECodeableConcept <<types>> {
      src -> tgt "inherit";
    }

    group ENHumanName(source src : EN, target tgt : HumanName) {
      src.item as item then {
        item.family as v -> tgt.family = (v.xmlText);
        item.given as v -> tgt.given = (v.xmlText);
        item.prefix as v -> tgt.prefix = (v.xmlText);
        item.suffix as v -> tgt.suffix = (v.xmlText);
      };
      src.validTime as validTime -> tgt.period = validTime;
    }

    group PNHumanName(source src : PN, target tgt : HumanName) extends ENHumanName <<types>> {
      src -> tgt "inherit";
    }

    group ADAddress(source src : AD, target tgt : Address) {
      src.item as item then {
        item.country as v -> tgt.country = (v.xmlText);
        item.state as v -> tgt.state = (v.xmlText);
        item.county as v -> tgt.district = (v.xmlText);
        item.city as v -> tgt.city = (v.xmlText);
        item.postalCode as v -> tgt.postalCode = (v.xmlText);
        item.streetAddressLine as v -> tgt.line = (v.xmlText);
        item -> tgt.line as line then {
          item where src.censusTract.exists() then {
            item.censusTract as v -> line.extension as ext1 then CensusTract(v, ext1) "line";
          } "sfgfdsg";
        } "CensusTract";
        // as streetAddress then{
        // src.censusTract as v->tgt.line as line, line.extension as ext1 then CensusTract(v, ext1) "line";
        // src.censusTract as v ->tgt.line as line, line.extension as ext1 then CensusTract(v, ext1) "line";
        item.streetName as v -> tgt.line = (v.xmlText);
        item.houseNumber as v -> tgt.line = (v.xmlText);
      };
      src.useablePeriod as useablePeriod -> tgt.period = useablePeriod;
    }

    group TELContactPoint(source src : TEL, target tgt : ContactPoint) {
      src.value as v where (src.value.startsWith('tel:')) ->  tgt.value = (v.substring(4)),  tgt.system = 'phone' "valuetel";
      src.value as v where (src.value.startsWith('fax:')) ->  tgt.value = (v.substring(4)),  tgt.system = 'fax' "valuefax";
      src.value as v where (src.value.startsWith('mailto:')) ->  tgt.value = (v.substring(7)),  tgt.system = 'email' "valuemail";
      src.value as v where (src.value.startsWith('http:')) ->  tgt.value = (v.substring(5)),  tgt.system = 'url' "valuehttp";
      src.use where (src.use.startsWith('H')) -> tgt.use = 'home' "usehome";
      src.use where ((src.use = 'WP') or (src.use = 'DIR') or (src.use = 'PUB')) -> tgt.use = 'work' "usework";
      src.use where (src.use = 'BAD') -> tgt.use = 'old' "usebad";
      src.use where (src.use = 'TMP') -> tgt.use = 'temp' "usetmp";
      src.use where (src.use = 'MC') -> tgt.use = 'mobile' "usemobile";
      src.useablePeriod as useablePeriod -> tgt.period = useablePeriod; // use: for src.use as c make tgt.use = translate(c, 'http://hl7.org/fhir/ConceptMap/cm-telecom-use-v3', 'code')
    }

    group PQQuantity(source src : PQ, target tgt : Quantity) {
      src.unit as unit -> tgt.unit = unit;
      src.unit as unit -> tgt.code = unit;
      src.unit as unit -> tgt.system = 'http://unitsofmeasure.org';
      src.value as value -> tgt.value = value;
    }

    group RTOPQPQRatio(source src : RTO_PQ_PQ, target tgt : Ratio) {
      src.numerator as numerator -> tgt.numerator as targetNumerator then PQQuantity(numerator, targetNumerator);
      src.denominator as denominator -> tgt.denominator as targetDenominator then PQQuantity(denominator, targetDenominator);
    }