<?xml version="1.0" encoding="UTF-8"?>

<StructureMap xmlns="http://hl7.org/fhir">
  <id value="QuestionnaireResponseToObservationBase"/>
  <text>
    <status value="generated"/><div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap QuestionnaireResponseToObservationBase</b></p><a name="QuestionnaireResponseToObservationBase"> </a><a name="hcQuestionnaireResponseToObservationBase"> </a><pre class="fml">
<b>map</b><span style="color: navy"> &quot;</span>https://fhir.hl7.at/prenudge/appdata/r4/StructureMap/QuestionnaireResponseToObservationBase<span style="color: navy">&quot; = &quot;</span>QuestionnaireResponseToObservationBase<span style="color: navy">&quot;

</span><span style="color: navy">// </span><span style="color: green">Shared base for Q to O</span>

<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R4/questionnaireresponse.html" title="QuestionnaireResponse">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style="color: navy">&quot; </span><b>alias </b>QR <b>as </b><b>source</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R4/observation.html" title="Observation">http://hl7.org/fhir/StructureDefinition/Observation</a><span style="color: navy">&quot; </span><b>alias </b>Obs <b>as </b><b>target</b>

<b>group </b>SetObservationBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">tgt</span><span style="color: navy"> : </span>Obs<span style="color: navy">)</span><span style="color: navy"> {
</span>  <span style="color: navy">// </span><span style="color: green">Fixed values</span>
  src<span style="color: navy"><b> -&gt; </b></span>tgt.status = <span style="color: blue">'final'</span> <i>&quot;SetStatus&quot;</i><span style="color: navy">;</span>
  src<span style="color: navy"><b> -&gt; </b></span>tgt.method = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'http://snomed.info/sct'</span><span style="color: navy">, </span><span style="color: blue">'87982008'</span><span style="color: navy">, </span><span style="color: blue">'Manual'</span><span style="color: navy">)</span> <i>&quot;SetMethod&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Copy identifier from QuestionnaireResponse to Observation</span>
  src.identifier<b> as </b><span style="color: maroon">srcId</span><span style="color: navy"><b> -&gt; </b></span>tgt.identifier = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Identifier'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">tgtId</span><b> then</b><span style="color: navy"> {
</span>    srcId.system<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>tgtId.system = <span style="color: maroon">s</span> <i>&quot;CopyIdSystem&quot;</i><span style="color: navy">;</span>
    srcId.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>tgtId.value = <span style="color: maroon">v</span> <i>&quot;CopyIdValue&quot;</i><span style="color: navy">;</span>
    srcId.use<b> as </b><span style="color: maroon">u</span><span style="color: navy"><b> -&gt; </b></span>tgtId.use = <span style="color: maroon">u</span> <i>&quot;CopyIdUse&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;CopyIdentifier&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Set derivedFrom reference back to the QuestionnaireResponse</span>
  src.id<b> as </b><span style="color: maroon">srcRefId</span><span style="color: navy"><b> -&gt; </b></span> tgt.derivedFrom = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><span style="color: navy">, </span> ref.reference = <b>append</b><span style="color: navy">(</span><span style="color: blue">'QuestionnaireResponse/'</span><span style="color: navy">, </span><span style="color: maroon">srcRefId</span><span style="color: navy">)</span> <i>&quot;SetDerivedFrom&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Subject reference</span>
  src.subject<b> as </b><span style="color: maroon">subject</span><span style="color: navy"><b> -&gt; </b></span>tgt.subject = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><b> then</b><span style="color: navy"> {
</span>    subject.reference<b> as </b><span style="color: maroon">r</span><span style="color: navy"><b> -&gt; </b></span>ref.reference = <span style="color: maroon">r</span> <i>&quot;CopySubjectRef&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;SetSubject&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Instance creation datetime</span>
  src.authored<b> as </b><span style="color: maroon">authored</span><span style="color: navy"><b> -&gt; </b></span>tgt.issued = <span style="color: maroon">authored</span> <i>&quot;SetEffective&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <url value="https://fhir.hl7.at/prenudge/appdata/r4/StructureMap/QuestionnaireResponseToObservationBase"/>
  <version value="0.1.0"/>
  <name value="QuestionnaireResponseToObservationBase"/>
  <title value="Shared base for Q to O"/>
  <status value="active"/>
  <date value="2026-05-28T10:55:10+00:00"/>
  <publisher value="The PreNUDGE Consortium"/>
  <contact>
    <name value="The PreNUDGE Consortium"/>
    <telecom>
      <system value="url"/>
      <value value="https://prenudge.at"/>
    </telecom>
  </contact>
  <contact>
    <name value="The PreNUDGE Consortium"/>
    <telecom>
      <system value="url"/>
      <value value="https://prenudge.at"/>
      <use value="work"/>
    </telecom>
  </contact>
  <description value="Shared base for Q to O"/>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse"/>
    <mode value="source"/>
    <alias value="QR"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Observation"/>
    <mode value="target"/>
    <alias value="Obs"/>
  </structure>
  <group>
    <name value="SetObservationBase"/>
    <typeMode value="none"/>
    <input>
      <name value="src"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="tgt"/>
      <type value="Obs"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="SetStatus"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="final"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="SetMethod"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="method"/>
        <transform value="cc"/>
        <parameter>
          <valueString value="http://snomed.info/sct"/>
        </parameter>
        <parameter>
          <valueString value="87982008"/>
        </parameter>
        <parameter>
          <valueString value="Manual"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="CopyIdentifier"/>
      <source>
        <context value="src"/>
        <element value="identifier"/>
        <variable value="srcId"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="identifier"/>
        <variable value="tgtId"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Identifier"/>
        </parameter>
      </target>
      <rule>
        <name value="CopyIdSystem"/>
        <source>
          <context value="srcId"/>
          <element value="system"/>
          <variable value="s"/>
        </source>
        <target>
          <context value="tgtId"/>
          <contextType value="variable"/>
          <element value="system"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="s"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="CopyIdValue"/>
        <source>
          <context value="srcId"/>
          <element value="value"/>
          <variable value="v"/>
        </source>
        <target>
          <context value="tgtId"/>
          <contextType value="variable"/>
          <element value="value"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="v"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="CopyIdUse"/>
        <source>
          <context value="srcId"/>
          <element value="use"/>
          <variable value="u"/>
        </source>
        <target>
          <context value="tgtId"/>
          <contextType value="variable"/>
          <element value="use"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="u"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="SetDerivedFrom"/>
      <source>
        <context value="src"/>
        <element value="id"/>
        <variable value="srcRefId"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="derivedFrom"/>
        <variable value="ref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="ref"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="append"/>
        <parameter>
          <valueString value="QuestionnaireResponse/"/>
        </parameter>
        <parameter>
          <valueId value="srcRefId"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="SetSubject"/>
      <source>
        <context value="src"/>
        <element value="subject"/>
        <variable value="subject"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="subject"/>
        <variable value="ref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <rule>
        <name value="CopySubjectRef"/>
        <source>
          <context value="subject"/>
          <element value="reference"/>
          <variable value="r"/>
        </source>
        <target>
          <context value="ref"/>
          <contextType value="variable"/>
          <element value="reference"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="r"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="SetEffective"/>
      <source>
        <context value="src"/>
        <element value="authored"/>
        <variable value="authored"/>
      </source>
      <target>
        <context value="tgt"/>
        <contextType value="variable"/>
        <element value="issued"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="authored"/>
        </parameter>
      </target>
    </rule>
  </group>
</StructureMap>