WHO Digital Documentation of COVID-19 Certificates (DDCC)
1.0.0 - CI Build International flag

This is the continuous build for version 1.0.0. This version is based on the current content of https://github.com/WorldHealthOrganization/ddcc and changes regularly.

StructureMap: SHCToCoreDataSetTR

Official URL: http://smart.who.int/ddcc/StructureMap/SHCToCoreDataSetTR Version: 1.0.0
Draft as of 2024-04-24 Computable Name: SHCToCoreDataSetTR
map "http://smart.who.int/ddcc/StructureMap/SHCToCoreDataSetTR" = "SHCToCoreDataSetTR"

uses "http://hl7.org/fhir/uv/shc-vaccination/StructureDefinition/shc-infectious-disease-laboratory-bundle-dm" alias SHCLabBundleDM as source
uses "http://hl7.org/fhir/uv/shc-vaccination/StructureDefinition/shc-patient-general-dm" alias SHCPatientDM as source
uses "http://hl7.org/fhir/uv/shc-vaccination/StructureDefinition/shc-infectious-disease-laboratory-result-observation-dm" alias SHCLabDM as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias DDCCBundle as target
uses "http://smart.who.int/ddcc/StructureDefinition/DDCCCoreDataSet.TR" alias DDCCTR as produced

group SHCToTR(source shc : SHCLabBundleDM, target ddccBundle : DDCCBundle) {
  shc.entry as patientEntrySHC then {
    patientEntrySHC.resource : Patient first as patient then {
      shc.entry as entry then {
        // entry.resource : Immunization as immunization where vaccineCode.memberOf('http://smart.who.int/ddcc/ValueSet/who-ddcc-allowed-vaccines-covid-19') ->  ddccBundle.entry as outentry,  create('http://smart.who.int/ddcc/StructureDefinition/DDCCCoreDataSet.VS') as ddcc then {
        entry.resource : Observation as lab ->  ddccBundle.entry as outentry,  create('http://smart.who.int/ddcc/StructureDefinition/DDCCCoreDataSet.TR') as ddcc then {
          lab then PatientToDDCCTR(patient, ddcc) "set patient";
          lab -> ddcc.test as test then LabToDDCC(lab, test) "set test";
          lab -> outentry.resource = ddcc "set outentry";
        } "labs";
      } "entries";
    } "get patient";
  } "find patient";

group PatientToDDCCTR(source patient : SHCPatientDM, target tgt : DDCCTR) {
  patient.name as name then NameToText(name, tgt) "set name";
  patient.birthDate as birthDate -> tgt.birthDate = birthDate "set birthDate";
  patient.identifier first as identifier -> tgt.identifier = identifier "set identifier";

group NameToText(source name : HumanName, target ddcc) {
  // append doesn't work until ddcc.name is set
  name.given first as given -> ddcc.name = (given.replaceMatches('$', ' ')) "set first name";
  // name.given not_first as other -> ddcc.name as tName, ddcc.name = append( tName, other ) "set other names";
  name.given not_first as other ->  ddcc.name as tName,  (other.replaceMatches('$', ' ')) as spaced,  ddcc.name = append(tName, spaced) "set other names";
  name.family as family ->  ddcc.name as tName,  ddcc.name = append(tName, family) "add family name";
  name.text as text -> ddcc.name = text "set full name";

group LabToDDCC(source lab : SHCLabDM, target test) {
  lab.code as code then {
    code.coding first as labType then {
      labType -> test.type = labType "set default type";
      labType where labType.memberOf('http://smart.who.int/ddcc/ValueSet/lab-test-type-covid19-loinc') -> test.type = translate(labType, 'http://smart.who.int/ddcc/ConceptMap/lab-test-type-covid19-loinc-to-icd11', 'Coding') "translate loinc type";
      labType where labType.memberOf('http://smart.who.int/ddcc/ValueSet/lab-test-type-covid19-loinc') -> test.pathogen = c('http://id.who.int/icd11/mms', 'XN109') "set pathogen to COVID";
  lab.effectiveDateTime as date -> test.date = date "set date";
  lab.valueCodeableConcept as value then {
    value.coding first as result then {
      result -> test.result = result "set default result";
      result where result.memberOf('http://smart.who.int/ddcc/ValueSet/lab-test-qual-result-snomed') -> test.result = translate(result, 'http://smart.who.int/ddcc/ConceptMap/lab-test-qual-result-snomed-to-icd11') "translate snomed result";