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

Official URL: http://smart.who.int/ddcc/StructureMap/CoreDataSetToAddBundle Version: 1.0.0
Draft as of 2024-01-19 Computable Name: CoreDataSetToAddBundle
map "http://smart.who.int/ddcc/StructureMap/CoreDataSetToAddBundle" = "CoreDataSetToAddBundle"


uses "http://smart.who.int/ddcc/StructureDefinition/DDCCCoreDataSetPoV" alias DDCCPoV as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias AddBundle as target
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as target
uses "http://smart.who.int/ddcc/StructureDefinition/DDCCPatient" alias DDCCPatient as produced
uses "http://smart.who.int/ddcc/StructureDefinition/DDCCImmunization" alias DDCCImmunization as produced
uses "http://smart.who.int/ddcc/StructureDefinition/DDCCImmunizationRecommendation" alias DDCCImmRec as produced

group CoreDataSetToAddBundle(source ddcc : DDCCPoV, target bundle : AddBundle) {
  ddcc -> bundle.type = 'transaction' "set bundle type";
  ddcc ->  uuid() as pid,  uuid() as iid,  uuid() as irid then {
    ddcc ->  bundle.entry as entry,  entry.fullUrl = append('urn:uuid:', pid),  entry.request as request,  request.method = 'PUT',  request.url = append('Patient/', pid),  create('http://smart.who.int/ddcc/StructureDefinition/DDCCPatient') as patient then {
      ddcc then DDCCToPatient(ddcc, patient, pid) "setup patient";
      ddcc -> entry.resource = patient "set patient resource";
    } "create patient resource";
    ddcc.vaccination first as vaccination ->  bundle.entry as entry,  entry.fullUrl = append('urn:uuid:', iid),  entry.request as request,  request.method = 'PUT',  request.url = append('Immunization/', iid),  create('http://smart.who.int/ddcc/StructureDefinition/DDCCImmunization') as immunization then {
      ddcc.certificate as certificate then DDCCToImmunization(vaccination, immunization, certificate, iid, pid) "setup immunization";
      ddcc -> entry.resource = immunization "set immunization resource";
    } "create immunization resource";
    ddcc.vaccination first as vaccination ->  bundle.entry as entry,  entry.fullUrl = append('urn:uuid:', irid),  entry.request as request,  request.method = 'PUT',  request.url = append('ImmunizationRecommendation/', irid),  create('http://smart.who.int/ddcc/StructureDefinition/DDCCImmunizationRecommendation') as immrec then {
      vaccination then DDCCToImmRec(vaccination, immrec, irid, iid, pid) "setup immunization recommendation";
      ddcc -> entry.resource = immrec "set immunization recommendation resource";
    } "create immunization recommendation resource";
  } "set uuids";
}

group DDCCToPatient(source src : DDCCPoV, target patient : DDCCPatient, source pid) {
  pid -> patient.id = pid "set id";
  src.name as name -> patient.name as tName then {
    name as content -> tName.text = content "set name";
  } "set full name";
  src.birthDate as birthDate -> patient.birthDate = birthDate "set birthDate";
  src.sex as sex -> patient.gender = sex "set gender";
  src.identifier as identifier -> patient.identifier = identifier "set identifier";
}

group DDCCToImmunization(source src, target immunization : DDCCImmunization, source certificate, source iid, source pid) {
  iid -> immunization.id = iid "set id";
  src.brand as brand -> immunization.extension as ext then {
    brand ->  ext.url = 'https://smart.who.int/ddcc/StructureDefinition/DDCCVaccineBrand',  ext.value = brand "set brand extension values";
  } "set brand extension";
  src.maholder as maholder -> immunization.extension as ext then {
    maholder ->  ext.url = 'https://smart.who.int/ddcc/StructureDefinition/DDCCVaccineMarketAuthorization',  ext.value = maholder "set MA Holder extension values";
  } "set maholder extension";
  src.country as country -> immunization.extension as ext then {
    country.code as code ->  ext.url = 'https://smart.who.int/ddcc/StructureDefinition/DDCCCountryOfVaccination',  ext.value = code "set country extension values";
  } "set country extension";
  src.validFrom as validFrom -> immunization.extension as ext then {
    validFrom ->  ext.url = 'https://smart.who.int/ddcc/StructureDefinition/DDCCVaccineValidFrom',  ext.value = validFrom "set valid from extension values";
  } "set vaccine valid extension";
  src -> immunization.status = 'completed' "set status";
  src.vaccine as vaccine ->  immunization.vaccineCode as vacCode,  vacCode.coding = vaccine "set vaccine";
  src ->  immunization.patient as patient,  patient.reference = append('Patient/', pid) "set patient";
  src.manufacturer as manufacturer ->  immunization.manufacturer as tman,  tman.identifier as ident then {
    manufacturer.system as system -> ident.system = system "set system";
    manufacturer.code as code -> ident.value = code "set value";
  } "set manufacturer identifier";
  src.lot as lot -> immunization.lotNumber = lot "set lot number";
  src.date as date -> immunization.occurrence = date "set occurrence date";
  src.centre as centre -> immunization.location as location then {
    centre -> location.display = centre "set location display";
  } "set location";
  src.practitioner as practitioner -> immunization.performer as performer then {
    practitioner.value as hw -> performer.actor as actor then {
      hw ->  actor.type = 'Practitioner',  actor.identifier as identifier then {
        hw -> identifier.value = hw "set hw identifier";
      } "set actor";
    } "set performer";
  } "set practitioner";
  src -> immunization.protocolApplied as protocol then {
    src -> protocol.authority as authority then {
      certificate.issuer as issuer -> authority.type = 'Organization' then {
        issuer.identifier as pha -> authority.identifier as identifier then {
          pha.value as value -> identifier.value = value "set pha";
        } "set issuer identifier";
      } "set issuer";
    } "set authority";
    src.disease as disease -> protocol.targetDisease as tdisease then {
      disease -> tdisease.coding = disease "set target disease code";
    } "set target disease";
    src.dose as dose -> protocol.doseNumber = dose "set dose number";
    src.totalDoses as totalDoses -> protocol.seriesDoses = totalDoses "set total doses";
  } "set protocolApplied";
}

group DDCCToImmRec(source src, target immrec : DDCCImmunizationRecommendation, source irid, source iid, source pid) {
  src.date as date -> immrec.date = date "set date";
  src ->  immrec.patient as patient,  patient.reference = append('Patient/', pid) "set patient";
  src -> immrec.recommendation as rec then {
    src.vaccine as vaccine -> rec.vaccineCode as vaccineCode then {
      vaccine -> vaccineCode.coding = vaccine "set vaccine code coding";
    } "set vaccine code";
    src.disease as disease -> rec.targetDisease as targetDisease then {
      disease -> targetDisease.coding = disease "set target disease coding";
    } "set target disease";
    src -> rec.forecastStatus as forecast then {
      src -> forecast.coding as coding then {
        src -> coding.system = 'http://terminology.hl7.org/2.1.0/CodeSystem-immunization-recommendation-status.html' "set forecast system";
        src -> coding.code = 'due' "set forecast code";
      } "set forecast status coding";
    } "set forecast status";
    src -> rec.dateCriterion as due_date then {
      src -> due_date.code as code then {
        src -> code.coding as coding then {
          src -> coding.system = 'http://loinc.org' "set due date code system";
          src -> coding.code = '30980-7' "set due date code code";
        } "set due date code coding";
      } "set due date code";
      src.nextDose as nextDose -> due_date.value = nextDose "set due date value";
    } "set date criterion";
    src.dose as dose -> rec.doseNumber = (dose.toInteger() + 1) "set dose number";
    src.totalDoses as totalDoses -> rec.seriesDoses = totalDoses "set total doses";
    src ->  rec.supportingImmunization as imm,  imm.reference = append('Immunization/', iid) "set supporting immunization";
  } "set recommendation";
}