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: IPSToCoreDataSetVS

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

uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias IPS as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias DDCCBundle as target
uses "http://smart.who.int/ddcc/StructureDefinition/DDCCCoreDataSet.VS.PoV" alias DDCC as produced

group IPSToCoreDataSetVS(source ips : IPS, target ddccBundle : DDCCBundle) {
  ips.id as id -> ddccBundle.id = id "set id";
  ips.entry first as compentry then {
    compentry.resource : Composition as composition then {
      composition.subject as subject then {
        subject.reference as patientid then {
          ips.entry as findpatient where resource.is(Patient) and (resource.id = patientid.replaceMatches('.*Patient/(?<id>[A-Za-z0-9\\-\\.]{1,64})$', '${id}')) then {
            findpatient.resource as patient then {
              ips.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.PoV') as ddcc then {
                  immunization then PatientToDDCC(patient, ddcc) "set patient info";
                  immunization -> ddcc.vaccination as vaccination then ImmunizationToVaccination(immunization, vaccination) "set vaccination";
                  immunization -> ddcc.certificate as certificate then IPSToCertificate(composition, certificate, immunization) "set certificate";
                  immunization -> outentry.resource = ddcc "set outentry";
                } "immunizations";
              } "entries";
            } "get patient";
          } "find patient";
        } "get subject reference";
      } "get subject";
    } "get composition";
  } "get first entry";

group ImmunizationToVaccination(source immunization, target vaccination) {
  immunization.vaccineCode as vaccine then {
    vaccine.coding as coding where memberOf('http://smart.who.int/ddcc/ValueSet/who-ddcc-vaccines-covid-19') then {
      coding -> vaccination.vaccine = coding "set coding";
    } "copy vaccine";
    vaccine.coding as coding where memberOf('http://smart.who.int/ddcc/ValueSet/who-ddcc-vaccines-covid-19').not() then {
      coding -> vaccination.vaccine = translate(coding, 'who-ddcc-map-cvx-icd11-vaccines', 'Coding') "translate code";
    } "translate vaccine coding";
    vaccine.coding as coding -> vaccination.brand = translate(coding, 'who-ddcc-map-cvx-icd11-brands', 'Coding') "translate brand";
  } "set vaccine";
  immunization -> vaccination.country = c('urn:iso:std:iso:3166', 'USA') "set country";
  immunization.lotNumber as lot -> vaccination.lot = lot "set lot";
  immunization.occurrence as occurrence -> vaccination.date = occurrence "set date";
  immunization.manufacturer as manufacturer then {
    manufacturer.identifier as identifier -> vaccination.manufacturer as vMan then {
      identifier.system as system -> vMan.system = system "set manufacturer system";
      identifier.value as value -> vMan.code = value "set manufactutuer code";
    } "set manufacturer id";
  } "set manufacturer";

group IPSToCertificate(source composition, target certificate, source immunization) {
  immunization.id as id ->  certificate.ddccid as ddccid,  ddccid.value = id "set ddccid";
  composition.id as id ->  certificate.hcid as hcid,  hcid.value = id "set hcid";
  composition.author first as author -> certificate.issuer = author "set issuer";

group PatientToDDCC(source patient, target ddcc) {
  patient.name as name then NameToText(name, ddcc) "set name";
  patient.birthDate as birthDate -> ddcc.birthDate = birthDate "set birthdate";
  // patient.gender as gender -> ddcc.sex = gender "set sex";
  patient.identifier first as identifier -> ddcc.identifier = identifier "set identifier";

group NameToText(source name : HumanName, target ddcc) {
  // annoying because 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";