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: Sleep Duration Q to O

Official URL: https://fhir.hl7.at/prenudge/appdata/r4/StructureMap/SleepDurationQuestionnaireResponseToObservation | Version: 0.1.0
Active as of 2026-05-28 | Responsible: The PreNUDGE Consortium | Computable Name: SleepDurationQuestionnaireResponseToObservation

Sleep Duration Q to O

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

    // Sleep Duration 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 SleepDurationQuestionnaireResponseToObservation(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-sleep-duration-observation' "SetProfile";
      src -> tgt.code = cc('http://loinc.org', '93832-4', 'Sleep duration') "SetCode";
      src.item as item where linkId = 'sleep-duration' then MapSleepDuration(item, tgt) "ProcessItem";
    }

    group MapSleepDuration(source src : QR, target tgt : Obs) {
      src.answer as answer then {
        // effectiveDateTime from nested date item
        answer.item as dtItem where linkId = 'date' then {
          dtItem.answer as dtAns then {
            dtAns.valueDate as dt -> tgt.effectiveDateTime = dt "SetEffectiveFromDate";
          } "ExtractDate";
        } "ProcessDate";
        // Map sleep duration value
        answer.valueQuantity as srcQty then MapSleepDurationQuantity(srcQty, tgt) "MapValueQuantity";
      } "ProcessAnswer";
    }

    group MapSleepDurationQuantity(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 = 'h',  qty.system = 'http://unitsofmeasure.org',  qty.code = 'h' "SetQuantity";
      } "ExtractValue";
    }