PreNUDGE FHIR® IG for Data Provider / Data from Apps (R4)
0.1.0 - ci-build

PreNUDGE FHIR® IG for Data Provider / Data from Apps (R4) - Local Development build (v0.1.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

StructureMap: Blood Glucose Q to O

Official URL: https://fhir.hl7.at/prenudge/appdata/r4/StructureMap/BloodGlucoseQuestionnaireResponseToObservation Version: 0.1.0
Active as of 2026-04-03 Responsible: The PreNUDGE Consortium Computable Name: BloodGlucoseQuestionnaireResponseToObservation

Blood Glucose Q to O

map "https://fhir.hl7.at/prenudge/appdata/r4/StructureMap/BloodGlucoseQuestionnaireResponseToObservation" = "BloodGlucoseQuestionnaireResponseToObservation"

// Blood Glucose Q to O

uses "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse" alias QR as source
uses "http://hl7.org/fhir/StructureDefinition/Observation" alias Obs as target
uses "http://hl7.org/fhir/StructureDefinition/Quantity" alias Quantity as source

imports "http://hl7.org/fhir/StructureMap/*"
imports "https://fhir.hl7.at/prenudge/appdata/r4/StructureMap/QuestionnaireResponseToObservationBase"

group BloodGlucoseQuestionnaireResponseToObservation(source src : QR, target tgt : Obs) {
  src then SetObservationBase(src, tgt) "Base";
  src ->  tgt.meta = create('Meta') as meta,  meta.profile = 'https://fhir.hl7.at/prenudge/appdata/r4/StructureDefinition/at-prenudge-bloodglucose-observation' "SetProfile";
  src -> tgt.code = cc('http://loinc.org', '41653-7', 'Glucose [Mass/volume] in Capillary blood by Glucometer') "SetCode";
  src.item as item where linkId = 'blood-glucose' then MapBloodGlucose(item, tgt) "ProcessItem";
}

group MapBloodGlucose(source src : QR, target tgt : Obs) {
  // Process the answer first to get access to nested items
  src.answer as answer then {
    // effectiveDateTime from nested item
    answer.item as dtItem where linkId = 'datetime' then {
      dtItem.answer as dtAns then {
        dtAns.valueDateTime as dt -> tgt.effectiveDateTime = dt "SetEffectiveFromDatetime";
      } "ExtractDateTime";
    } "ProcessDatetime";
    // Meal context → component[mealContext]
    answer.item as mcItem where linkId = 'meal-context' then {
      mcItem.answer as mcAns then {
        mcAns.valueCoding as coding ->  tgt.component as comp,  comp.code = cc('http://snomed.info/sct', '309602000', 'Temporal periods relating to feeding and eating'),  comp.value = create('CodeableConcept') as cc,  cc.coding = coding "SetMealContextCoding";
      } "ExtractCoding";
    } "ProcessMealContext";
    // Map the blood glucose value
    answer.valueQuantity as srcQty then MapBloodGlucoseQuantity(srcQty, tgt) "MapValueQuantity";
  } "ProcessAnswer";
}

group MapBloodGlucoseQuantity(source srcQty : Quantity, target tgt : Obs) {
  srcQty.value as v then {
    v.value as numVal ->  tgt.value = create('Quantity') as qty,  qty.value = numVal,  qty.unit = 'mg/dL',  qty.system = 'http://unitsofmeasure.org',  qty.code = 'mg/dL' "SetQuantity";
  } "ExtractValue";
}