Data Management with FHIR
0.1.0 - ci-build

Data Management with FHIR - Local Development build (v0.1.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

## : Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container - XML Representation

Draft as of 2025-10-23

Raw xml | Download

    <StructureMap xmlns="http://hl7.org/fhir">
      <id value="EHR2FSL"/>
      <text>
        <status value="generated"/>
        <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Narratif généré : StructureMap EHR2FSL</b></p><a name="EHR2FSL"> </a><a name="hcEHR2FSL"> </a><pre class="fml">
    <b>map</b><span style="color: navy"> &quot;</span>https://interop.aphp.fr/ig/fhir/dm/StructureMap/EHR2FSL<span style="color: navy">&quot; = &quot;</span>EHR2FSL<span style="color: navy">&quot;

    </span><span style="color: navy">// </span><span style="color: green">Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container</span>

    <b>uses</b><span style="color: navy"> &quot;</span><a href="StructureDefinition-ehr.html" title="Electronic Health Record Data Model">https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/ehr</a><span style="color: navy">&quot; </span><b>alias </b>EHR <b>as </b><b>source</b>
    <b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R4/bundle.html" title="Bundle">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style="color: navy">&quot; </span><b>alias </b>Bundle <b>as </b><b>target</b>

    <b>group </b>EHR2FSL<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span><span style="color: navy"> : </span>EHR, <b>target</b> <span style="color: maroon">bundle</span><span style="color: navy"> : </span>Bundle<span style="color: navy">)</span><span style="color: navy"> {
    </span>  <span style="color: navy">// </span><span style="color: green">Initialize Bundle</span>
      src<span style="color: navy"><b> -&gt; </b></span>bundle.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;bundleid&quot;</i><span style="color: navy">;</span>
      src<span style="color: navy"><b> -&gt; </b></span>bundle.type = <span style="color: blue">'collection'</span> <i>&quot;bundletype&quot;</i><span style="color: navy">;</span>
      src<span style="color: navy"><b> -&gt; </b></span><span style="color: navy">(</span>now()<span style="color: navy">)</span><b> as </b><span style="color: maroon">timestamp</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>bundle.timestamp = <span style="color: maroon">timestamp</span> <i>&quot;affectTimestamp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;setTimestamp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Transform Patient</span>
      src.patient<b> as </b><span style="color: maroon">patient</span><span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">patientEntry</span><b> then</b><span style="color: navy"> {
    </span>    patient<span style="color: navy"><b> -&gt; </b></span>patientEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Patient'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmPatient</span><b> then</b><span style="color: navy"> {
    </span>      patient<b> then </b>TransformPatient<span style="color: navy">(</span><span style="color: maroon">patient</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;transformpatient&quot;</i><span style="color: navy">;</span>
          patient<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmPatient</span><span style="color: navy">, </span><span style="color: maroon">patientEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
          src.patientAdresse<b> as </b><span style="color: maroon">patientAdresse</span><b> where </b>patientAdresse.patientId = %patient.patientId<b> then </b>setAddress<span style="color: navy">(</span><span style="color: maroon">patientAdresse</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;transformpatientAdresse&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">Transform PMSI Encounters</span>
          src.donneesPmsi<b> as </b><span style="color: maroon">pmsi</span><b> where </b>pmsi.patientId = %patient.patientId<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">encounterEntry</span><b> then</b><span style="color: navy"> {
    </span>        pmsi<span style="color: navy"><b> -&gt; </b></span>encounterEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Encounter'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmEncounter</span><b> then</b><span style="color: navy"> {
    </span>          pmsi<b> then </b>TransformEncounter<span style="color: navy">(</span><span style="color: maroon">pmsi</span><span style="color: navy">, </span><span style="color: maroon">dmEncounter</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;transformencounter&quot;</i><span style="color: navy">;</span>
              pmsi<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmEncounter</span><span style="color: navy">, </span><span style="color: maroon">encounterEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">// </span><span style="color: green">Transform Conditions (Diagnostics)</span>
              src.diagnostics<b> as </b><span style="color: maroon">diag</span><b> where </b>(diag.patientId = %patient.patientId) and (diag.pmsiId = %pmsi.pmsiId)<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">conditionEntry</span><b> then</b><span style="color: navy"> {
    </span>            diag<span style="color: navy"><b> -&gt; </b></span>conditionEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Condition'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmCondition</span><b> then</b><span style="color: navy"> {
    </span>              diag<b> then </b>TransformCondition<span style="color: navy">(</span><span style="color: maroon">diag</span><span style="color: navy">, </span><span style="color: maroon">dmCondition</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">, </span><span style="color: maroon">dmEncounter</span><span style="color: navy">)</span> <i>&quot;transformcondition&quot;</i><span style="color: navy">;</span>
                  diag<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmCondition</span><span style="color: navy">, </span><span style="color: maroon">conditionEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
                <span style="color: navy">}</span> <i>&quot;createcondition&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;conditionentries&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">// </span><span style="color: green">Transform Procedures (Actes)</span>
              src.actes<b> as </b><span style="color: maroon">acte</span><b> where </b>(acte.patientId = %patient.patientId) and (acte.pmsiId = %pmsi.pmsiId)<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">procedureEntry</span><b> then</b><span style="color: navy"> {
    </span>            acte<span style="color: navy"><b> -&gt; </b></span>procedureEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Procedure'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmProcedure</span><b> then</b><span style="color: navy"> {
    </span>              acte<b> then </b>TransformProcedure<span style="color: navy">(</span><span style="color: maroon">acte</span><span style="color: navy">, </span><span style="color: maroon">dmProcedure</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">, </span><span style="color: maroon">dmEncounter</span><span style="color: navy">)</span> <i>&quot;transformprocedure&quot;</i><span style="color: navy">;</span>
                  acte<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmProcedure</span><span style="color: navy">, </span><span style="color: maroon">procedureEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
                <span style="color: navy">}</span> <i>&quot;createprocedure&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;procedureentries&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;createencounter&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;encounterentries&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">Transform Laboratory Observations</span>
          src.biologie<b> as </b><span style="color: maroon">lab</span><b> where </b>lab.patientId = %patient.patientId<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">labEntry</span><b> then</b><span style="color: navy"> {
    </span>        lab<span style="color: navy"><b> -&gt; </b></span>labEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmLab</span><b> then</b><span style="color: navy"> {
    </span>          lab<b> then </b>TransformLabObservation<span style="color: navy">(</span><span style="color: maroon">lab</span><span style="color: navy">, </span><span style="color: maroon">dmLab</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;transformLabObs&quot;</i><span style="color: navy">;</span>
              lab<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmLab</span><span style="color: navy">, </span><span style="color: maroon">labEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;createlabobs&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;labentries&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">Transform Medication Requests</span>
          src.prescription<b> as </b><span style="color: maroon">pres</span><b> where </b>pres.patientId = %patient.patientId<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">medReqEntry</span><b> then</b><span style="color: navy"> {
    </span>        pres<span style="color: navy"><b> -&gt; </b></span>medReqEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'MedicationRequest'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmMedReq</span><b> then</b><span style="color: navy"> {
    </span>          src<b> then </b>TransformMedicationRequest<span style="color: navy">(</span><span style="color: maroon">pres</span><span style="color: navy">, </span><span style="color: maroon">dmMedReq</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createmedrequest&quot;</i><span style="color: navy">;</span>
              pres<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmMedReq</span><span style="color: navy">, </span><span style="color: maroon">medReqEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
              src.posologie<b> as </b><span style="color: maroon">poso</span><b> where </b>%poso.prescriptionId = %pres.prescriptionId<b> then </b>setPoso<span style="color: navy">(</span><span style="color: maroon">poso</span><span style="color: navy">, </span><span style="color: maroon">pres</span><span style="color: navy">, </span><span style="color: maroon">dmMedReq</span><span style="color: navy">)</span> <i>&quot;transformPoso&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">// </span><span style="color: green">Transform Administration (W prescription)</span>
              src.administration<b> as </b><span style="color: maroon">admin</span><b> where </b>(admin.patientId = %patient.patientId) and (admin.prescriptionId = pres.prescriptionId)<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">adminEntry</span><b> then</b><span style="color: navy"> {
    </span>            admin<span style="color: navy"><b> -&gt; </b></span>adminEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'MedicationAdministration'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmAdmin</span><b> then</b><span style="color: navy"> {
    </span>              admin<b> then </b>TransformMedicationAdministrationWOrder<span style="color: navy">(</span><span style="color: maroon">admin</span><span style="color: navy">, </span><span style="color: maroon">dmAdmin</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">, </span><span style="color: maroon">dmMedReq</span><span style="color: navy">)</span> <i>&quot;createmedadmin&quot;</i><span style="color: navy">;</span>
                  admin<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmAdmin</span><span style="color: navy">, </span><span style="color: maroon">adminEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
                <span style="color: navy">}</span> <i>&quot;createmedadmin&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;administrationentries&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;createmedreq&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;medicationentries&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">Transform Lifestyle Observations - separate observation for each lifestyle element</span>
          src.styleVie<b> as </b><span style="color: maroon">lifestyle</span><b> where </b>lifestyle.patientId = %patient.patientId<b> then</b><span style="color: navy"> {
    </span>        <span style="color: navy">// </span><span style="color: green">Tobacco consumption observation</span>
            lifestyle.consommationTabac<b> as </b><span style="color: maroon">tobacco</span><b> where </b>tobacco.exists()<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">tobaccoEntry</span><b> then</b><span style="color: navy"> {
    </span>          tobacco<span style="color: navy"><b> -&gt; </b></span>tobaccoEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">tobaccoObs</span><b> then</b><span style="color: navy"> {
    </span>            lifestyle<b> then </b>TransformTobaccoObservation<span style="color: navy">(</span><span style="color: maroon">lifestyle</span><span style="color: navy">, </span><span style="color: maroon">tobaccoObs</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createtobaccoobs&quot;</i><span style="color: navy">;</span>
                lifestyle<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">tobaccoObs</span><span style="color: navy">, </span><span style="color: maroon">tobaccoEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;createtobaccoobs&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;tobaccoentries&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">// </span><span style="color: green">Alcohol consumption observation</span>
            lifestyle.consommationAlcool<b> as </b><span style="color: maroon">alcohol</span><b> where </b>alcohol.exists()<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">alcoholEntry</span><b> then</b><span style="color: navy"> {
    </span>          alcohol<span style="color: navy"><b> -&gt; </b></span>alcoholEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">alcoholObs</span><b> then</b><span style="color: navy"> {
    </span>            lifestyle<b> then </b>TransformAlcoholObservation<span style="color: navy">(</span><span style="color: maroon">lifestyle</span><span style="color: navy">, </span><span style="color: maroon">alcoholObs</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createalcoholobs&quot;</i><span style="color: navy">;</span>
                lifestyle<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">alcoholObs</span><span style="color: navy">, </span><span style="color: maroon">alcoholEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;createalcoholobs&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;alcoholentries&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">// </span><span style="color: green">Drug consumption observation</span>
            lifestyle.consommationAutresDrogues<b> as </b><span style="color: maroon">drugs</span><b> where </b>drugs.exists()<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">drugEntry</span><b> then</b><span style="color: navy"> {
    </span>          drugs<span style="color: navy"><b> -&gt; </b></span>drugEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">drugObs</span><b> then</b><span style="color: navy"> {
    </span>            lifestyle<b> then </b>TransformDrugObservation<span style="color: navy">(</span><span style="color: maroon">lifestyle</span><span style="color: navy">, </span><span style="color: maroon">drugObs</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createdrugobs&quot;</i><span style="color: navy">;</span>
                lifestyle<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">drugObs</span><span style="color: navy">, </span><span style="color: maroon">drugEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;createdrugobs&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;drugentries&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">// </span><span style="color: green">Physical activity observation</span>
            lifestyle.activitePhysique<b> as </b><span style="color: maroon">physical</span><b> where </b>physical.exists()<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">physicalEntry</span><b> then</b><span style="color: navy"> {
    </span>          physical<span style="color: navy"><b> -&gt; </b></span>physicalEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">physicalObs</span><b> then</b><span style="color: navy"> {
    </span>            lifestyle<b> then </b>TransformPhysicalActivityObservation<span style="color: navy">(</span><span style="color: maroon">lifestyle</span><span style="color: navy">, </span><span style="color: maroon">physicalObs</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createphysicalobs&quot;</i><span style="color: navy">;</span>
                lifestyle<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">physicalObs</span><span style="color: navy">, </span><span style="color: maroon">physicalEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;createphysicalobs&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;physicalentries&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;lifestyleentries&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">Transform Care Observations (s)</span>
          src.dossierSoins<b> as </b><span style="color: maroon">soin</span><b> where </b>soin.patientId = %patient.patientId<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">vitalEntry</span><b> then</b><span style="color: navy"> {
    </span>        soin<span style="color: navy"><b> -&gt; </b></span>vitalEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmObs</span><b> then</b><span style="color: navy"> {
    </span>          soin<b> then </b>TransformVitalSigns<span style="color: navy">(</span><span style="color: maroon">soin</span><span style="color: navy">, </span><span style="color: maroon">dmObs</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createmesureobs&quot;</i><span style="color: navy">;</span>
              soin<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmObs</span><span style="color: navy">, </span><span style="color: maroon">vitalEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;createmesureobs&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;vitalentries&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">Transform Administration (WO prescription)</span>
          src.administration<b> as </b><span style="color: maroon">admin</span><b> where </b>(admin.patientId = %patient.patientId) and admin.prescriptionId.empty()<span style="color: navy"><b> -&gt; </b></span>bundle.entry<b> as </b><span style="color: maroon">adminEntry</span><b> then</b><span style="color: navy"> {
    </span>        admin<span style="color: navy"><b> -&gt; </b></span>adminEntry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'MedicationAdministration'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dmAdmin</span><b> then</b><span style="color: navy"> {
    </span>          admin<b> then </b>TransformMedicationAdministrationWOOrder<span style="color: navy">(</span><span style="color: maroon">admin</span><span style="color: navy">, </span><span style="color: maroon">dmAdmin</span><span style="color: navy">, </span><span style="color: maroon">dmPatient</span><span style="color: navy">)</span> <i>&quot;createmedadmin&quot;</i><span style="color: navy">;</span>
              admin<b> then </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><span style="color: maroon">dmAdmin</span><span style="color: navy">, </span><span style="color: maroon">adminEntry</span><span style="color: navy">)</span> <i>&quot;setRequestAndFullUrl&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;createmedadmin&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;administrationentries&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;createpatient&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;patiententry&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">---------------------------------------------------------</span>
    <span style="color: navy">// </span><span style="color: green">PATIENT TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">---------------------------------------------------------</span>
    <b>group </b>TransformPatient<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgt</span><span style="color: navy"> : </span>Patient<span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgt.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: #b36b00" title="Cet élément nétait pas défini avant R5">// src.patientId as id -&gt; tgt.id = id &quot;patient-id&quot;;</span>
      <span style="color: navy">// </span><span style="color: green">Identifiers</span>
      src.patientId<b> as </b><span style="color: maroon">pid</span><span style="color: navy"><b> -&gt; </b></span>tgt.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    pid<span style="color: navy"><b> -&gt; </b></span>identifier.use = <span style="color: blue">'usual'</span> <i>&quot;iduse&quot;</i><span style="color: navy">;</span>
        pid<span style="color: navy"><b> -&gt; </b></span>identifier.type = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'http://terminology.hl7.org/CodeSystem/v2-0203'</span><span style="color: navy">, </span><span style="color: blue">'PI'</span><span style="color: navy">, </span><span style="color: blue">'Patient Identifier'</span><span style="color: navy">)</span> <i>&quot;idtype&quot;</i><span style="color: navy">;</span>
        pid<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/patient-id'</span> <i>&quot;idsystem&quot;</i><span style="color: navy">;</span>
        pid<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">pid</span> <i>&quot;idvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;patientidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">NIR identifier &lt;- C'est pas terrible côté expression de besoin : qu'est ce qu'ils veulent quand ils disent NIR ? ça peut être le NSS, mais du coup c'est pas un identifier (un NSS peut correspondre à plusieurs ayant droits), et ce serait plutôt une info qui irait côté claim. ça peut aussi être l'ins-nir, mais du coup qu'est ce qu'ils attendent dans l'ins ? Bref, à mon avis, faut discuter cette variable au niveau du GT.</span>
      <span style="color: #b36b00" title="Cet élément nétait pas défini avant R5">// src.nir as nir where nir.exists() -&gt; tgt.identifier as insIdentifier then {     nir -&gt; insIdentifier.use = 'official' &quot;ins-use&quot;;     nir -&gt; insIdentifier.type = cc('http://hl7.fr/fhir/CodeSystem/fr-v2-0203', 'INS-NIR') &quot;ins-type&quot;;     nir -&gt; insIdentifier.system = 'urn:oid:1.2.250.1.213.1.4.8' &quot;ins-system&quot;;     nir -&gt; insIdentifier.value = nir &quot;ins-value&quot;;   } &quot;ins-identifier&quot;;</span>
      <span style="color: navy">// </span><span style="color: green">Alternative INS from ins field</span>
      src.ins<b> as </b><span style="color: maroon">ins</span><b> where </b>ins.exists()<span style="color: navy"><b> -&gt; </b></span>tgt.identifier<b> as </b><span style="color: maroon">insIdentifier</span><b> then</b><span style="color: navy"> {
    </span>    ins<span style="color: navy"><b> -&gt; </b></span>insIdentifier.use = <span style="color: blue">'official'</span> <i>&quot;insuse&quot;</i><span style="color: navy">;</span> <span style="color: navy">// </span><span style="color: green">On part du principe qu'on n'est pas sur un old.</span>
        ins<span style="color: navy"><b> -&gt; </b></span>insIdentifier.type = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-v2-0203'</span><span style="color: navy">, </span><span style="color: blue">'INS-NIR'</span><span style="color: navy">, </span><span style="color: blue">'NIR définitif'</span><span style="color: navy">)</span> <i>&quot;instype&quot;</i><span style="color: navy">;</span>
        ins<span style="color: navy"><b> -&gt; </b></span>insIdentifier.system = <span style="color: blue">'urn:oid:1.2.250.1.213.1.4.8'</span> <i>&quot;inssystem&quot;</i><span style="color: navy">;</span>
        ins<span style="color: navy"><b> -&gt; </b></span>insIdentifier.value = <span style="color: maroon">ins</span> <i>&quot;insvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;insidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Name</span>
      src<b> where </b>src.nom.exists() or src.prenom.exists()<span style="color: navy"><b> -&gt; </b></span>tgt.name<b> as </b><span style="color: maroon">name</span><b> then</b><span style="color: navy"> {
    </span>    src.nom<b> as </b><span style="color: maroon">lastName</span><span style="color: navy"><b> -&gt; </b></span>name.family = <span style="color: maroon">lastName</span> <i>&quot;familyname&quot;</i><span style="color: navy">;</span>
        src.prenom<b> as </b><span style="color: maroon">firstName</span><span style="color: navy"><b> -&gt; </b></span>name.given = <span style="color: maroon">firstName</span> <i>&quot;givenname&quot;</i><span style="color: navy">;</span>
        src<span style="color: navy"><b> -&gt; </b></span>name.use = <span style="color: blue">'official'</span> <i>&quot;nameuse&quot;</i><span style="color: navy">;</span> <span style="color: navy">// </span><span style="color: green">hypothèse un peu forte.</span>
      <span style="color: navy">}</span> <i>&quot;patientname&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Demographics On aurait pu faire plus élégant avec un ConceptMap</span>
      src.dateNaissance<b> as </b><span style="color: maroon">birthDate</span><span style="color: navy"><b> -&gt; </b></span>tgt.birthDate = <span style="color: maroon">birthDate</span> <i>&quot;birthdate&quot;</i><span style="color: navy">;</span>
      src.sexe<b> as </b><span style="color: maroon">gender</span><b> where </b>gender = 'h'<span style="color: navy"><b> -&gt; </b></span>tgt.gender = <span style="color: blue">'male'</span> <i>&quot;gendermale&quot;</i><span style="color: navy">;</span>
      src.sexe<b> as </b><span style="color: maroon">gender</span><b> where </b>gender = 'f'<span style="color: navy"><b> -&gt; </b></span>tgt.gender = <span style="color: blue">'female'</span> <i>&quot;genderfemale&quot;</i><span style="color: navy">;</span>
      src.sexe<b> as </b><span style="color: maroon">gender</span><b> where </b>gender.exists() and (gender != 'h') and (gender != 'f')<span style="color: navy"><b> -&gt; </b></span>tgt.gender = <span style="color: blue">'unknown'</span> <i>&quot;genderunknown&quot;</i><span style="color: navy">;</span> <span style="color: navy">// </span><span style="color: green">n'a pas grand sens en l'état des contraintes SQL</span>
      <span style="color: navy">// </span><span style="color: green">Death information</span>
      src.dateDeces<b> as </b><span style="color: maroon">deathDate</span><b> where </b>deathDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgt.deceased = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">deathDate</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">deceasedDate</span><b> then</b><span style="color: navy"> {
    </span>    src.sourceDeces<b> as </b><span style="color: maroon">deathSource</span><b> where </b>deathSource.exists()<span style="color: navy"><b> -&gt; </b></span>deceasedDate.extension<b> as </b><span style="color: maroon">DeathSourceExtension</span><b> then</b><span style="color: navy"> {
    </span>      deathSource<span style="color: navy"><b> -&gt; </b></span>DeathSourceExtension.url = <span style="color: blue">'https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/DeathSource'</span> <i>&quot;deathSourceUrl&quot;</i><span style="color: navy">;</span>
          deathSource<span style="color: navy"><b> -&gt; </b></span>DeathSourceExtension.value = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">deathSource</span><span style="color: navy">, </span><span style="color: blue">'code'</span><span style="color: navy">)</span> <i>&quot;deathSourceValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;deathSource&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;deathDate&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Multiple birth</span>
      src.rangGemellaire<b> as </b><span style="color: maroon">twin</span><b> where </b>twin.exists()<span style="color: navy"><b> -&gt; </b></span>tgt.multipleBirth = <span style="color: maroon">twin</span> <i>&quot;multiplebirth&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">PATIENT_LOCATION TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>setAddress<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtPat</span><span style="color: navy"> : </span>Patient<span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<b> where </b>src.latitude.exists() or src.longitude.exists() or src.codeIris.exists() or src.libelleIris.exists() or src.codeGeographiqueResidence.exists()<b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>tgtPat.address<b> as </b><span style="color: maroon">newAddress</span><b> then</b><span style="color: navy"> {
    </span>      src<b> where </b>src.latitude.exists() or src.longitude.exists()<span style="color: navy"><b> -&gt; </b></span> newAddress.extension<b> as </b><span style="color: maroon">geolocationExtension</span><span style="color: navy">, </span> geolocationExtension.url = <span style="color: blue">'http://hl7.org/fhir/StructureDefinition/geolocation'</span><b> then</b><span style="color: navy"> {
    </span>        src.latitude<b> as </b><span style="color: maroon">srcLat</span><span style="color: navy"><b> -&gt; </b></span> geolocationExtension.extension<b> as </b><span style="color: maroon">tgtLat</span><span style="color: navy">, </span> tgtLat.url = <span style="color: blue">'latitude'</span><span style="color: navy">, </span> tgtLat.value = <span style="color: maroon">srcLat</span> <i>&quot;setLat&quot;</i><span style="color: navy">;</span>
            src.longitude<b> as </b><span style="color: maroon">srcLong</span><span style="color: navy"><b> -&gt; </b></span> geolocationExtension.extension<b> as </b><span style="color: maroon">tgtLong</span><span style="color: navy">, </span> tgtLong.url = <span style="color: blue">'longitude'</span><span style="color: navy">, </span> tgtLong.value = <span style="color: maroon">srcLong</span> <i>&quot;setLong&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;setCoordinates&quot;</i><span style="color: navy">;</span>
          src<b> where </b>src.codeIris.exists() or src.libelleIris.exists()<span style="color: navy"><b> -&gt; </b></span> newAddress.line = <span style="color: navy">(</span>%src.libelleIris<span style="color: navy">)</span><b> as </b><span style="color: maroon">irisLine</span><span style="color: navy">, </span> irisLine.extension = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Extension'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">irisExtension</span><span style="color: navy">, </span> irisExtension.url = <span style="color: blue">'http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-censusTract'</span><span style="color: navy">, </span> irisExtension.value = <span style="color: navy">(</span>%src.codeIris<span style="color: navy">)</span> <i>&quot;setIris&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">// </span><span style="color: green">src where src.codeIris.exists() or src.libelleIris.exists() -&gt; newAddress.extension as irisExtension,</span>
          <span style="color: navy">// </span><span style="color: green">irisExtension.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-censusTract',</span>
          <span style="color: navy">// </span><span style="color: green">irisExtension.value = (iif(%src.codeIris.exists() and %src.libelleIris.exists(), %src.codeIris &amp; ' - ' &amp; %src.libelleIris, %src.codeIris &amp; %src.libelleIris)) &quot;setIris&quot;;</span>
          src.codeGeographiqueResidence<b> as </b><span style="color: maroon">srcCodeGeographiqueResidence</span><b> where </b>src.codeGeographiqueResidence.exists()<span style="color: navy"><b> -&gt; </b></span> newAddress.extension<b> as </b><span style="color: maroon">residencePmsiExtension</span><span style="color: navy">, </span> residencePmsiExtension.url = <span style="color: blue">'https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/PmsiCodeGeo'</span><span style="color: navy">, </span> residencePmsiExtension.value = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">srcCodeGeographiqueResidence</span><span style="color: navy">, </span><span style="color: blue">'code'</span><span style="color: navy">)</span> <i>&quot;SetResidencePmsi&quot;</i><span style="color: navy">;</span>
          src.dateRecueil<b> as </b><span style="color: maroon">dateRecueil</span><span style="color: navy"><b> -&gt; </b></span> newAddress.period<b> as </b><span style="color: maroon">newAddressPeriod</span><span style="color: navy">, </span> newAddressPeriod.start = <span style="color: maroon">dateRecueil</span> <i>&quot;setDateRecueil&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;createAddress&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;checkSource&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">ENCOUNTER TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformEncounter<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtEnc</span><span style="color: navy"> : </span>Encounter, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtEnc.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: #b36b00" title="Cet élément nétait pas défini avant R5">// src.pmsiId as id -&gt; tgt.id = id &quot;encounter-id&quot;;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtEnc.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>identifier.type = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-identifier-type'</span><span style="color: navy">, </span><span style="color: blue">'VN'</span><span style="color: navy">, </span><span style="color: blue">'Visit Number'</span><span style="color: navy">)</span> <i>&quot;idtype&quot;</i><span style="color: navy">;</span>
        src<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/pmsi-id'</span> <i>&quot;encounteridsystem&quot;</i><span style="color: navy">;</span>
        src.pmsiId<b> as </b><span style="color: maroon">srcEncoutnerId</span><span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">srcEncoutnerId</span> <i>&quot;encounteridvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;encounteridentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status - default to finished for historical data</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtEnc.status = <span style="color: blue">'finished'</span> <i>&quot;encounterstatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Class - assume inpatient for PMSI data</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtEnc.class = <b>c</b><span style="color: navy">(</span><span style="color: blue">'http://terminology.hl7.org/CodeSystem/v3-ActCode'</span><span style="color: navy">, </span><span style="color: blue">'IMP'</span><span style="color: navy">, </span><span style="color: blue">'inpatient encounter'</span><span style="color: navy">)</span> <i>&quot;encounterclass&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Reference patient</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtEnc.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectreference&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;encountersubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Period</span>
      src<b> where </b>src.dateDebutSejour.exists() or src.dateFinSejour.exists()<span style="color: navy"><b> -&gt; </b></span>tgtEnc.period<b> as </b><span style="color: maroon">period</span><b> then</b><span style="color: navy"> {
    </span>    src.dateDebutSejour<b> as </b><span style="color: maroon">startDate</span><span style="color: navy"><b> -&gt; </b></span>period.start = <span style="color: maroon">startDate</span> <i>&quot;periodstart&quot;</i><span style="color: navy">;</span>
        src.dateFinSejour<b> as </b><span style="color: maroon">endDate</span><span style="color: navy"><b> -&gt; </b></span>period.end = <span style="color: maroon">endDate</span> <i>&quot;periodend&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;encounterperiod&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Désactivé dans le modèle physique   // Duration   src.dureeSejour as duration -&gt; tgtEnc.length as length then {     duration -&gt; length.value = duration &quot;length-value&quot;;     duration -&gt; length.unit = 'd' &quot;length-unit&quot;;     duration -&gt; length.system = 'http://unitsofmeasure.org' &quot;length-system&quot;;     duration -&gt; length.code = 'd' &quot;length-code&quot;;   } &quot;encounter-length&quot;;</span>
      <span style="color: navy">// </span><span style="color: green">Hospitalization</span>
      src<b> where </b>src.modeEntree.exists() or src.modeSortie.exists()<span style="color: navy"><b> -&gt; </b></span>tgtEnc.hospitalization<b> as </b><span style="color: maroon">hosp</span><b> then</b><span style="color: navy"> {
    </span>    src.modeEntree<b> as </b><span style="color: maroon">admitSource</span><span style="color: navy"><b> -&gt; </b></span>hosp.admitSource<b> as </b><span style="color: maroon">admitSrc</span><b> then</b><span style="color: navy"> {
    </span>      admitSource<span style="color: navy"><b> -&gt; </b></span>admitSrc.text = <span style="color: maroon">admitSource</span> <i>&quot;admitsourcetext&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;admitsource&quot;</i><span style="color: navy">;</span>
        src.modeSortie<b> as </b><span style="color: maroon">dischargeDisp</span><span style="color: navy"><b> -&gt; </b></span>hosp.dischargeDisposition<b> as </b><span style="color: maroon">dischargeDsp</span><b> then</b><span style="color: navy"> {
    </span>      dischargeDisp<span style="color: navy"><b> -&gt; </b></span>dischargeDsp.text = <span style="color: maroon">dischargeDisp</span> <i>&quot;dischargedisptext&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;dischargedisposition&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;encounterhospitalization&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Service Provider</span>
      src<b> where </b>src.uniteFonctionnelle.exists() or src.service.exists() or src.etablissement.exists()<span style="color: navy"><b> -&gt; </b></span>tgtEnc.serviceProvider<b> as </b><span style="color: maroon">provider</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>provider.display = <span style="color: navy">(</span>iif(%src.uniteFonctionnelle.exists(), %src.uniteFonctionnelle, iif(%src.service.exists(), %src.service, %src.etablissement))<span style="color: navy">)</span> <i>&quot;providerdisplay&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;provider&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">// Location - On n'a pas de location à gérer à ce stade (établissement, service et UF, halluciné par l'IA, sont des Organization que j'ai du coup mi dans Provider. )   src.service as service -&gt; tgt.location as location then {     service -&gt; location.location as loc then {       service -&gt; loc.display = service &quot;location-display&quot;;     } &quot;location-ref&quot;;   } &quot;encounter-location&quot;;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">CONDITION TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformCondition<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtCond</span><span style="color: navy"> : </span>Condition, <b>source</b> <span style="color: maroon">patient</span>, <b>source</b> <span style="color: maroon">encounter</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtCond.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.diagnosticId<b> as </b><span style="color: maroon">diagId</span><span style="color: navy"><b> -&gt; </b></span>tgtCond.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    diagId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/diagnostic-id'</span> <i>&quot;conditionidsystem&quot;</i><span style="color: navy">;</span>
        diagId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">diagId</span> <i>&quot;conditionidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;conditionidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category</span>
      <span style="color: navy">// </span><span style="color: green">Représentation des codes diagnostics du PMSI dans condition , plusieurs options :</span>
      <span style="color: navy">// </span><span style="color: green">- ce sont des infos de claim, pas de condition</span>
      <span style="color: navy">// </span><span style="color: green">- utiliser la catégorie 'encounter-diagnosis'</span>
      <span style="color: navy">// </span><span style="color: green">- utiliser les catégories du PMSI : DP, DR, DAS, DAD</span>
      <span style="color: navy">// </span><span style="color: green">- mettre les deux précédent &lt;- j'ai fait ça.</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtCond.category = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-category'</span><span style="color: navy">, </span><span style="color: blue">'encounter-diagnosis'</span><span style="color: navy">, </span><span style="color: blue">'Encounter Diagnosis'</span><span style="color: navy">)</span> <i>&quot;categoryencounterDiag&quot;</i><span style="color: navy">;</span>
      src.typeDiagnostic<b> as </b><span style="color: maroon">diagType</span><span style="color: navy"><b> -&gt; </b></span>tgtCond.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    diagType<span style="color: navy"><b> -&gt; </b></span>category.text = <span style="color: maroon">diagType</span> <i>&quot;categorytext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;conditioncategory&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code (ICD-10)</span>
      src.codeDiagnostic<b> as </b><span style="color: maroon">srcCode</span><span style="color: navy"><b> -&gt; </b></span>tgtCond.code<b> as </b><span style="color: maroon">conditionCode</span><b> then</b><span style="color: navy"> {
    </span>    <span style="color: navy">// </span><span style="color: green">la fonction cc ne peuple pas le display...</span>
        src.libelleDiagnostic<b> as </b><span style="color: maroon">label</span><span style="color: navy"><b> -&gt; </b></span> conditionCode.coding<b> as </b><span style="color: maroon">tgtCoding</span><span style="color: navy">, </span> tgtCoding.system = <span style="color: blue">'http://hl7.org/fhir/sid/icd-10'</span><span style="color: navy">, </span> tgtCoding.code = <span style="color: maroon">srcCode</span> <i>&quot;conditioncode&quot;</i><span style="color: navy">;</span>
        src.libelleDiagnostic<b> as </b><span style="color: maroon">text</span><span style="color: navy"><b> -&gt; </b></span>conditionCode.text = <span style="color: maroon">text</span> <i>&quot;codetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;varcode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtCond.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;conditionsubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Encounter reference</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtCond.encounter = <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>    encounter.id<b> as </b><span style="color: maroon">encounterId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Encounter/' + %encounterId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Encounter'</span> <i>&quot;encounterref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;conditionencounter&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Recorded date</span>
      src.dateRecueil<b> as </b><span style="color: maroon">entryDate</span><span style="color: navy"><b> -&gt; </b></span>tgtCond.recordedDate = <span style="color: maroon">entryDate</span> <i>&quot;conditionrecordeddate&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Clinical status - assume active for recorded diagnoses</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtCond.clinicalStatus = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-clinical'</span><span style="color: navy">, </span><span style="color: blue">'active'</span><span style="color: navy">)</span> <i>&quot;conditionclinicalstatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Verification status - assume confirmed for coded diagnoses</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtCond.verificationStatus = <b>cc</b><span style="color: navy">(</span><span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-ver-status'</span><span style="color: navy">, </span><span style="color: blue">'confirmed'</span><span style="color: navy">)</span> <i>&quot;conditionverificationstatus&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">PROCEDURE TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformProcedure<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtProc</span><span style="color: navy"> : </span>Procedure, <b>source</b> <span style="color: maroon">patient</span>, <b>source</b> <span style="color: maroon">encounter</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtProc.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.acteId<b> as </b><span style="color: maroon">acteId</span><span style="color: navy"><b> -&gt; </b></span>tgtProc.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    acteId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/acte-id'</span> <i>&quot;procedureidsystem&quot;</i><span style="color: navy">;</span>
        acteId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">acteId</span> <i>&quot;procedureidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;procedureidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status - assume completed for historical data</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtProc.status = <span style="color: blue">'completed'</span> <i>&quot;procedurestatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code (CCAM)</span>
      src.codeActe<b> as </b><span style="color: maroon">code</span><span style="color: navy"><b> -&gt; </b></span>tgtProc.code<b> as </b><span style="color: maroon">procedureCode</span><b> then</b><span style="color: navy"> {
    </span>    code<span style="color: navy"><b> -&gt; </b></span> procedureCode.coding<b> as </b><span style="color: maroon">coding</span><span style="color: navy">, </span> coding.system = <span style="color: blue">'https://interop.aphp.fr/ig/fhir/dm/CodeSystem/Ccam'</span><span style="color: navy">, </span> coding.code = <span style="color: maroon">code</span> <i>&quot;procedurecoding&quot;</i><span style="color: navy">;</span>
        src.libelleActe<b> as </b><span style="color: maroon">text</span><span style="color: navy"><b> -&gt; </b></span>procedureCode.text = <span style="color: maroon">text</span> <i>&quot;codetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;procedurecode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtProc.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;proceduresubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Encounter reference</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtProc.encounter = <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>    encounter.id<b> as </b><span style="color: maroon">encounterId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Encounter/' + %encounterId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Encounter'</span> <i>&quot;encounterref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;procedureencounter&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Performed date/time</span>
      src.dateActe<b> as </b><span style="color: maroon">performedDate</span><b> where </b>%performedDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgtProc.performed = <span style="color: maroon">performedDate</span> <i>&quot;procedureperformed&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Performer</span>
      src.executant<b> as </b><span style="color: maroon">performer</span><span style="color: navy"><b> -&gt; </b></span>tgtProc.performer<b> as </b><span style="color: maroon">perf</span><b> then</b><span style="color: navy"> {
    </span>    performer<span style="color: navy"><b> -&gt; </b></span>perf.actor<b> as </b><span style="color: maroon">actor</span><b> then</b><span style="color: navy"> {
    </span>      performer<span style="color: navy"><b> -&gt; </b></span>actor.display = <span style="color: maroon">performer</span> <i>&quot;performerdisplay&quot;</i><span style="color: navy">;</span>
          performer<span style="color: navy"><b> -&gt; </b></span>actor.type = <span style="color: blue">'Practitioner'</span> <i>&quot;performerType&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;performeractor&quot;</i><span style="color: navy">;</span>
        performer<span style="color: navy"><b> -&gt; </b></span> perf.function<b> as </b><span style="color: maroon">function</span><span style="color: navy">, </span> function.text = <span style="color: blue">'Exécutant'</span> <i>&quot;performerFunction&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;procedureperformer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">LABORATORY OBSERVATION TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformLabObservation<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtObs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtObs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.biologieId<b> as </b><span style="color: maroon">bioId</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    bioId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/biologie-id'</span> <i>&quot;labidsystem&quot;</i><span style="color: navy">;</span>
        bioId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">bioId</span> <i>&quot;labidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status - map validation status or default to final</span>
      src.statutValidation<b> as </b><span style="color: maroon">validation</span><b> where </b>validation = 'VALIDE'<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;statusvalidated&quot;</i><span style="color: navy">;</span>
      src<b> where </b>src.statutValidation.exists().not()<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;statusdefault&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>category.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorysystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'laboratory'</span> <i>&quot;categorycode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Laboratory'</span> <i>&quot;categorydisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;categorycoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labcategory&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code (LOINC)</span>
      src.codeLoinc<b> as </b><span style="color: maroon">loinc</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
    </span>    loinc<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      loinc<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codesystem&quot;</i><span style="color: navy">;</span>
          loinc<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: maroon">loinc</span> <i>&quot;codevalue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;labcoding&quot;</i><span style="color: navy">;</span>
        src.libelleTest<b> as </b><span style="color: maroon">text</span><span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: maroon">text</span> <i>&quot;codetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labcode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labsubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Effective date/time</span>
      src.datePrelevement<b> as </b><span style="color: maroon">collectionDate</span><b> where </b>%collectionDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.effective = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">collectionDate</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;labeffective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Value (numeric or text)</span>
      src.valeur<b> as </b><span style="color: maroon">numValue</span><b> where </b>numValue.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">qty</span><b> then</b><span style="color: navy"> {
    </span>    numValue<span style="color: navy"><b> -&gt; </b></span>qty.value = <span style="color: maroon">numValue</span> <i>&quot;quantityvalue&quot;</i><span style="color: navy">;</span>
        src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>qty.unit = <span style="color: maroon">unit</span> <i>&quot;quantityunit&quot;</i><span style="color: navy">;</span>
        src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>qty.code = <span style="color: maroon">unit</span> <i>&quot;quantitycode&quot;</i><span style="color: navy">;</span>
        src<span style="color: navy"><b> -&gt; </b></span>qty.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;quantitysystem&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labvaluequantity&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">On n'a pas de résultats textuels de prévu</span>
      <span style="color: #b36b00" title="Cet élément nétait pas défini avant R5">// src.valeurTexte as textValue where textValue.exists() and src.valeur.exists().not() -&gt; tgtObs.value = textValue &quot;lab-value-string&quot;;</span>
      <span style="color: navy">// </span><span style="color: green">Reference range</span>
      src<b> where </b>src.borneInfNormale.exists() or src.borneSupNormale.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.referenceRange<b> as </b><span style="color: maroon">range</span><b> then</b><span style="color: navy"> {
    </span>    src.borneInfNormale<b> as </b><span style="color: maroon">low</span><span style="color: navy"><b> -&gt; </b></span>range.low<b> as </b><span style="color: maroon">lowQty</span><b> then</b><span style="color: navy"> {
    </span>      low<span style="color: navy"><b> -&gt; </b></span>lowQty.value = <span style="color: maroon">low</span> <i>&quot;reflowvalue&quot;</i><span style="color: navy">;</span>
          src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>lowQty.unit = <span style="color: maroon">unit</span> <i>&quot;reflowunit&quot;</i><span style="color: navy">;</span>
          src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>lowQty.code = <span style="color: maroon">unit</span> <i>&quot;reflowcode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>lowQty.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;reflowsystem&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;referencelow&quot;</i><span style="color: navy">;</span>
        src.borneSupNormale<b> as </b><span style="color: maroon">high</span><span style="color: navy"><b> -&gt; </b></span>range.high<b> as </b><span style="color: maroon">highQty</span><b> then</b><span style="color: navy"> {
    </span>      high<span style="color: navy"><b> -&gt; </b></span>highQty.value = <span style="color: maroon">high</span> <i>&quot;refhighvalue&quot;</i><span style="color: navy">;</span>
          src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>highQty.unit = <span style="color: maroon">unit</span> <i>&quot;refhighunit&quot;</i><span style="color: navy">;</span>
          src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>highQty.code = <span style="color: maroon">unit</span> <i>&quot;refhighcode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>highQty.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;refhighsystem&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;referencehigh&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labreferencerange&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Performer</span>
      src.laboratoire<b> as </b><span style="color: maroon">lab</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.performer<b> as </b><span style="color: maroon">performer</span><b> then</b><span style="color: navy"> {
    </span>    lab<span style="color: navy"><b> -&gt; </b></span>performer.display = <span style="color: maroon">lab</span> <i>&quot;performerdisplay&quot;</i><span style="color: navy">;</span>
        lab<span style="color: navy"><b> -&gt; </b></span>performer.type = <span style="color: blue">'Organization'</span> <i>&quot;performerType&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;labperformer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">MEDICATION REQUEST TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformMedicationRequest<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtMedReq</span><span style="color: navy"> : </span>MedicationRequest, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtMedReq.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.prescriptionId<b> as </b><span style="color: maroon">presId</span><span style="color: navy"><b> -&gt; </b></span>tgtMedReq.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    presId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/prescription-id'</span> <i>&quot;medrequestidsystem&quot;</i><span style="color: navy">;</span>
        presId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">presId</span> <i>&quot;medrequestidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medrequestidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status - assume unknown for historical prescriptions</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtMedReq.status = <span style="color: blue">'unknown'</span> <i>&quot;medrequeststatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Intent</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtMedReq.intent = <span style="color: blue">'order'</span> <i>&quot;medrequestintent&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtMedReq.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medrequestsubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Medication</span>
      src.denomination<b> as </b><span style="color: maroon">denomination</span><span style="color: navy"><b> -&gt; </b></span>tgtMedReq.medication = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">medication</span><b> then</b><span style="color: navy"> {
    </span>    denomination<b> as </b><span style="color: maroon">text</span><span style="color: navy"><b> -&gt; </b></span>medication.text = <span style="color: maroon">text</span> <i>&quot;medicationtext&quot;</i><span style="color: navy">;</span>
        src.codeAtc<b> as </b><span style="color: maroon">atc</span><span style="color: navy"><b> -&gt; </b></span>medication.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      atc<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://www.whocc.no/atc'</span> <i>&quot;atcsystem&quot;</i><span style="color: navy">;</span>
          atc<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: maroon">atc</span> <i>&quot;atccode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;atccoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medicationdenomination&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Authored date</span>
      src.datePrescription<b> as </b><span style="color: maroon">prescDate</span><span style="color: navy"><b> -&gt; </b></span>tgtMedReq.authoredOn = <span style="color: maroon">prescDate</span> <i>&quot;medauthored&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Requester</span>
      src.prescripteur<b> as </b><span style="color: maroon">prescriber</span><span style="color: navy"><b> -&gt; </b></span>tgtMedReq.requester<b> as </b><span style="color: maroon">requesterRef</span><b> then</b><span style="color: navy"> {
    </span>    prescriber<span style="color: navy"><b> -&gt; </b></span>requesterRef.display = <span style="color: maroon">prescriber</span> <i>&quot;requesterdisplay&quot;</i><span style="color: navy">;</span>
        prescriber<span style="color: navy"><b> -&gt; </b></span>requesterRef.type = <span style="color: blue">'Practitioner'</span> <i>&quot;requesterType&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medrequester&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">POSOLOGIE TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>setPoso<span style="color: navy">(</span><b>source</b> <span style="color: maroon">srcPoso</span>, <b>source</b> <span style="color: maroon">srcPres</span>, <b>target</b> <span style="color: maroon">tgtMedReq</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  srcPres<span style="color: navy"><b> -&gt; </b></span>tgtMedReq.dosageInstruction<b> as </b><span style="color: maroon">dosageInstruction</span><b> then</b><span style="color: navy"> {
    </span>    <span style="color: navy">// </span><span style="color: green">Human-readable dosage text - construct from available fields</span>
        srcPoso<span style="color: navy"><b> -&gt; </b></span>dosageInstruction.text = <span style="color: navy">(</span>'Prendre' + iif(%srcPoso.quantite.exists(), ' ' + %srcPoso.quantite.toString(), '1') + iif(%srcPoso.uniteQuantite.exists(), ' ' + %srcPoso.uniteQuantite, ' comprimé') + iif(%srcPoso.nombrePrisesParJour.exists(), ' ' + %srcPoso.nombrePrisesParJour.toString() + ' fois par jour', ' selon prescription')<span style="color: navy">)</span> <i>&quot;dosagetext&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">// </span><span style="color: green">Route of administration from prescription</span>
        srcPres.voieAdministration<b> as </b><span style="color: maroon">route</span><span style="color: navy"><b> -&gt; </b></span>dosageInstruction.route<b> as </b><span style="color: maroon">routeCC</span><b> then</b><span style="color: navy"> {
    </span>      route<span style="color: navy"><b> -&gt; </b></span>routeCC.coding<b> as </b><span style="color: maroon">routeCoding</span><b> then</b><span style="color: navy"> {
    </span>        route<span style="color: navy"><b> -&gt; </b></span>routeCoding.code = <span style="color: maroon">route</span> <i>&quot;routecode&quot;</i><span style="color: navy">;</span>
            route<span style="color: navy"><b> -&gt; </b></span>routeCoding.system = <span style="color: blue">'https://smt.esante.gouv.fr/terminologie-standardterms'</span> <i>&quot;routesystem&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;routecoding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;dosageroute&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">// </span><span style="color: green">Timing</span>
        srcPoso<span style="color: navy"><b> -&gt; </b></span>dosageInstruction.timing<b> as </b><span style="color: maroon">timing</span><b> then</b><span style="color: navy"> {
    </span>      srcPoso<span style="color: navy"><b> -&gt; </b></span>timing.repeat<b> as </b><span style="color: maroon">timingRepeat</span><b> then</b><span style="color: navy"> {
    </span>        <span style="color: navy">// </span><span style="color: green">Set prescription period as bounds if available</span>
            srcPres<b> where </b>srcPres.dateDebutPrescription.exists() or srcPres.dateFinPrescription.exists()<span style="color: navy"><b> -&gt; </b></span>timingRepeat.bounds = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Period'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">medReqPeriod</span><b> then</b><span style="color: navy"> {
    </span>          srcPres.dateDebutPrescription<b> as </b><span style="color: maroon">startDate</span><span style="color: navy"><b> -&gt; </b></span>medReqPeriod.start = <span style="color: maroon">startDate</span> <i>&quot;periodstart&quot;</i><span style="color: navy">;</span>
              srcPres.dateFinPrescription<b> as </b><span style="color: maroon">endDate</span><span style="color: navy"><b> -&gt; </b></span>medReqPeriod.end = <span style="color: maroon">endDate</span> <i>&quot;periodend&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;prescriptionperiod&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">// </span><span style="color: green">Frequency from posology</span>
            srcPoso.nombrePrisesParJour<b> as </b><span style="color: maroon">frequency</span><span style="color: navy"><b> -&gt; </b></span>timingRepeat.frequency = <span style="color: maroon">frequency</span> <i>&quot;timingfrequency&quot;</i><span style="color: navy">;</span>
            srcPoso.nombrePrisesParJour<b> as </b><span style="color: maroon">frequency</span><span style="color: navy"><b> -&gt; </b></span>timingRepeat.period = <span style="color: blue">'1'</span> <i>&quot;timingperiod&quot;</i><span style="color: navy">;</span>
            srcPoso.nombrePrisesParJour<b> as </b><span style="color: maroon">frequency</span><span style="color: navy"><b> -&gt; </b></span>timingRepeat.periodUnit = <span style="color: blue">'d'</span> <i>&quot;timingperiodunit&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;timingrepeat&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;dosagetiming&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">// </span><span style="color: green">Dose and rate</span>
        srcPoso.quantite<b> as </b><span style="color: maroon">quantity</span><span style="color: navy"><b> -&gt; </b></span>dosageInstruction.doseAndRate<b> as </b><span style="color: maroon">doseRate</span><b> then</b><span style="color: navy"> {
    </span>      quantity<span style="color: navy"><b> -&gt; </b></span>doseRate.dose = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">doseQuantity</span><b> then</b><span style="color: navy"> {
    </span>        quantity<span style="color: navy"><b> -&gt; </b></span>doseQuantity.value = <span style="color: maroon">quantity</span> <i>&quot;dosevalue&quot;</i><span style="color: navy">;</span>
            srcPoso.uniteQuantite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>doseQuantity.unit = <span style="color: maroon">unit</span> <i>&quot;doseunit&quot;</i><span style="color: navy">;</span>
            srcPoso.uniteQuantite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>doseQuantity.code = <span style="color: maroon">unit</span> <i>&quot;dosecode&quot;</i><span style="color: navy">;</span>
            srcPoso<span style="color: navy"><b> -&gt; </b></span>doseQuantity.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;dosesystem&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;dosequantity&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;doseandrate&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;dosageinstruction&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">VITAL SIGNS TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformVitalSigns<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtObs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtObs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.soinId<b> as </b><span style="color: maroon">soinId</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    soinId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/soin-id'</span> <i>&quot;soinidsystem&quot;</i><span style="color: navy">;</span>
        soinId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">soinId</span> <i>&quot;soinidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medrequestidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status - assume final</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category - vital-signs</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>category.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorysystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'vital-signs'</span> <i>&quot;categorycode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;categorycoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">code (LOINC)</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codesystem&quot;</i><span style="color: navy">;</span>
          src.codeLoinc<b> as </b><span style="color: maroon">codeLoinc</span><span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: maroon">codeLoinc</span> <i>&quot;codevalue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        src.libelleTest<b> as </b><span style="color: maroon">label</span><span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: maroon">label</span> <i>&quot;codetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;obssubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Date de l'observation</span>
      src.dateMesure<b> as </b><span style="color: maroon">date</span><b> where </b>%date.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.effective = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">date</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;effective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Valeur (quantitiative)</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">qty</span><b> then</b><span style="color: navy"> {
    </span>    src.valeur<b> as </b><span style="color: maroon">mesure</span><span style="color: navy"><b> -&gt; </b></span>qty.value = <span style="color: maroon">mesure</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>qty.unit = <span style="color: maroon">unit</span> <i>&quot;unit&quot;</i><span style="color: navy">;</span>
        src.unite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>qty.code = <span style="color: maroon">unit</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        src<span style="color: navy"><b> -&gt; </b></span>qty.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;system&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;quantity&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Blood pressure observation - would need separate entry with components</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">LIFESTYLE TRANSFORMATION - SEPARATE OBSERVATIONS</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformTobaccoObservation<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtObs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtObs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.styleVieId<b> as </b><span style="color: maroon">lsId</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    lsId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/lifestyle-id'</span> <i>&quot;lifestyleidsystem&quot;</i><span style="color: navy">;</span>
        lsId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: navy">(</span>%lsId &amp; '-tobacco'<span style="color: navy">)</span> <i>&quot;lifestyleidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestyleidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;lifestylestatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category - social-history</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>category.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorysystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'social-history'</span> <i>&quot;categorycode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Social History'</span> <i>&quot;categorydisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;categorycoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylecategory&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code - tobacco use status</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codesystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'72166-2'</span> <i>&quot;codevalue&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Tobacco smoking status'</span> <i>&quot;codedisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;tobaccocoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;tobaccocode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylesubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Effective date</span>
      src.dateRecueil<b> as </b><span style="color: maroon">collectDate</span><b> where </b>%collectDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.effective = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">collectDate</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;lifestyleeffective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Value</span>
      src.consommationTabac<b> as </b><span style="color: maroon">tobacco</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">valueCC</span><b> then</b><span style="color: navy"> {
    </span>    tobacco<span style="color: navy"><b> -&gt; </b></span>valueCC.text = <span style="color: maroon">tobacco</span> <i>&quot;tobaccovaluetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;tobaccovalue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><b>group </b>TransformAlcoholObservation<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtObs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtObs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.styleVieId<b> as </b><span style="color: maroon">lsId</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    lsId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/lifestyle-id'</span> <i>&quot;lifestyleidsystem&quot;</i><span style="color: navy">;</span>
        lsId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: navy">(</span>%lsId &amp; '-alcohol'<span style="color: navy">)</span> <i>&quot;lifestyleidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestyleidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;lifestylestatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category - social-history</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>category.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorysystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'social-history'</span> <i>&quot;categorycode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Social History'</span> <i>&quot;categorydisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;categorycoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylecategory&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code - alcohol use</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codesystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'11331-6'</span> <i>&quot;codevalue&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'History of alcohol use'</span> <i>&quot;codedisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;alcoholcoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;alcoholcode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylesubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Effective date</span>
      src.dateRecueil<b> as </b><span style="color: maroon">collectDate</span><b> where </b>%collectDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.effective = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">collectDate</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;lifestyleeffective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Value</span>
      src.consommationAlcool<b> as </b><span style="color: maroon">alcohol</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">valueCC</span><b> then</b><span style="color: navy"> {
    </span>    alcohol<span style="color: navy"><b> -&gt; </b></span>valueCC.text = <span style="color: maroon">alcohol</span> <i>&quot;alcoholvaluetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;alcoholvalue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><b>group </b>TransformDrugObservation<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtObs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtObs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.styleVieId<b> as </b><span style="color: maroon">lsId</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    lsId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/lifestyle-id'</span> <i>&quot;lifestyleidsystem&quot;</i><span style="color: navy">;</span>
        lsId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: navy">(</span>%lsId &amp; '-drugs'<span style="color: navy">)</span> <i>&quot;lifestyleidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestyleidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;lifestylestatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category - social-history</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>category.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorysystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'social-history'</span> <i>&quot;categorycode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Social History'</span> <i>&quot;categorydisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;categorycoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylecategory&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code - drug use</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codesystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'11342-3'</span> <i>&quot;codevalue&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'History of drug use'</span> <i>&quot;codedisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;drugcoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;drugcode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylesubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Effective date</span>
      src.dateRecueil<b> as </b><span style="color: maroon">collectDate</span><b> where </b>%collectDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.effective = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">collectDate</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;lifestyleeffective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Value</span>
      src.consommationAutresDrogues<b> as </b><span style="color: maroon">drugs</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">valueCC</span><b> then</b><span style="color: navy"> {
    </span>    drugs<span style="color: navy"><b> -&gt; </b></span>valueCC.text = <span style="color: maroon">drugs</span> <i>&quot;drugvaluetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;drugvalue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><b>group </b>TransformPhysicalActivityObservation<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtObs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtObs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.styleVieId<b> as </b><span style="color: maroon">lsId</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    lsId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/lifestyle-id'</span> <i>&quot;lifestyleidsystem&quot;</i><span style="color: navy">;</span>
        lsId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: navy">(</span>%lsId &amp; '-physical'<span style="color: navy">)</span> <i>&quot;lifestyleidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestyleidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.status = <span style="color: blue">'final'</span> <i>&quot;lifestylestatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Category - social-history</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.category<b> as </b><span style="color: maroon">category</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>category.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorysystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'social-history'</span> <i>&quot;categorycode&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Social History'</span> <i>&quot;categorydisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;categorycoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylecategory&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Code - physical activity</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
    </span>    src<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      src<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codesystem&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'67504-6'</span> <i>&quot;codevalue&quot;</i><span style="color: navy">;</span>
          src<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Exercise activity'</span> <i>&quot;codedisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;physicalcoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;physicalcode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtObs.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lifestylesubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Effective date</span>
      src.dateRecueil<b> as </b><span style="color: maroon">collectDate</span><b> where </b>%collectDate.exists()<span style="color: navy"><b> -&gt; </b></span>tgtObs.effective = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">collectDate</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;lifestyleeffective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Value</span>
      src.activitePhysique<b> as </b><span style="color: maroon">physical</span><span style="color: navy"><b> -&gt; </b></span>tgtObs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">valueCC</span><b> then</b><span style="color: navy"> {
    </span>    physical<span style="color: navy"><b> -&gt; </b></span>valueCC.text = <span style="color: maroon">physical</span> <i>&quot;physicalvaluetext&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;physicalvalue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <span style="color: navy">// </span><span style="color: green">MEDICATION ADMINISTRATION TRANSFORMATION</span>
    <span style="color: navy">// </span><span style="color: green">========================================================================</span>
    <b>group </b>TransformMedicationAdministrationWOOrder<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtMedAdmin</span><span style="color: navy"> : </span>MedicationAdministration, <b>source</b> <span style="color: maroon">patient</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  src<span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span> <i>&quot;setId&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Identifier</span>
      src.administrationId<b> as </b><span style="color: maroon">adminId</span><span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.identifier<b> as </b><span style="color: maroon">identifier</span><b> then</b><span style="color: navy"> {
    </span>    adminId<span style="color: navy"><b> -&gt; </b></span>identifier.system = <span style="color: blue">'https://hospital.eu/ehr/administration-id'</span> <i>&quot;adminidsystem&quot;</i><span style="color: navy">;</span>
        adminId<span style="color: navy"><b> -&gt; </b></span>identifier.value = <span style="color: maroon">adminId</span> <i>&quot;adminidvalue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;adminidentifier&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Status - assume completed</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.status = <span style="color: blue">'completed'</span> <i>&quot;adminstatus&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Subject</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.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>    patient.id<b> as </b><span style="color: maroon">patientId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'Patient/' + %patientId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'Patient'</span> <i>&quot;subjectref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;adminsubject&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Medication</span>
      src.denomination<b> as </b><span style="color: maroon">denomination</span><span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.medication = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">medication</span><b> then</b><span style="color: navy"> {
    </span>    denomination<span style="color: navy"><b> -&gt; </b></span>medication.text = <span style="color: maroon">denomination</span> <i>&quot;medicationtext&quot;</i><span style="color: navy">;</span>
        src.codeAtc<b> as </b><span style="color: maroon">atc</span><span style="color: navy"><b> -&gt; </b></span>medication.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
    </span>      atc<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://www.whocc.no/atc'</span> <i>&quot;atcsystem&quot;</i><span style="color: navy">;</span>
          atc<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: maroon">atc</span> <i>&quot;atccode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;atccoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;adminmedication&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Effective period</span>
      src<b> where </b>src.dateHeureDebut.exists() or src.dateHeureFin.exists()<span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.effective = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Period'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">period</span><b> then</b><span style="color: navy"> {
    </span>    src.dateHeureDebut<b> as </b><span style="color: maroon">startDate</span><span style="color: navy"><b> -&gt; </b></span>period.start = <span style="color: maroon">startDate</span> <i>&quot;periodstart&quot;</i><span style="color: navy">;</span>
        src.dateHeureFin<b> as </b><span style="color: maroon">endDate</span><span style="color: navy"><b> -&gt; </b></span>period.end = <span style="color: maroon">endDate</span> <i>&quot;periodend&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;admineffective&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">Dosage</span>
      src<b> where </b>src.quantite.exists() or src.voieAdministration.exists()<span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.dosage<b> as </b><span style="color: maroon">dosage</span><b> then</b><span style="color: navy"> {
    </span>    src.quantite<b> as </b><span style="color: maroon">quantity</span><span style="color: navy"><b> -&gt; </b></span>dosage.dose = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">dose</span><b> then</b><span style="color: navy"> {
    </span>      quantity<span style="color: navy"><b> -&gt; </b></span>dose.value = <span style="color: maroon">quantity</span> <i>&quot;dosevalue&quot;</i><span style="color: navy">;</span>
          src.uniteQuantite<b> as </b><span style="color: maroon">unit</span><span style="color: navy"><b> -&gt; </b></span>dose.unit = <span style="color: maroon">unit</span> <i>&quot;doseunit&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;admindose&quot;</i><span style="color: navy">;</span>
        src.voieAdministration<b> as </b><span style="color: maroon">route</span><span style="color: navy"><b> -&gt; </b></span>dosage.route<b> as </b><span style="color: maroon">routeCC</span><b> then</b><span style="color: navy"> {
    </span>      route<span style="color: navy"><b> -&gt; </b></span>routeCC.coding<b> as </b><span style="color: maroon">routeCoding</span><b> then</b><span style="color: navy"> {
    </span>        route<span style="color: navy"><b> -&gt; </b></span>routeCoding.code = <span style="color: maroon">route</span> <i>&quot;routecode&quot;</i><span style="color: navy">;</span>
            route<span style="color: navy"><b> -&gt; </b></span>routeCoding.system = <span style="color: blue">'https://smt.esante.gouv.fr/terminologie-standardterms'</span> <i>&quot;routesystem&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;routecoding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;dosageroute&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;admindosage&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><b>group </b>TransformMedicationAdministrationWOrder<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span>, <b>target</b> <span style="color: maroon">tgtMedAdmin</span><span style="color: navy"> : </span>MedicationAdministration, <b>source</b> <span style="color: maroon">patient</span>, <b>source</b> <span style="color: maroon">order</span><span style="color: navy">)</span><b> extends </b>TransformMedicationAdministrationWOOrder<span style="color: navy"> {
    </span>  <span style="color: navy">// </span><span style="color: green">Context (encounter) reference</span>
      src<span style="color: navy"><b> -&gt; </b></span>tgtMedAdmin.request = <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>    order.id<b> as </b><span style="color: maroon">orderId</span><span style="color: navy"><b> -&gt; </b></span> ref.reference = <span style="color: navy">(</span>'MedicationRequest/' + %orderId<span style="color: navy">)</span><span style="color: navy">, </span> ref.type = <span style="color: blue">'MedicationRequest'</span> <i>&quot;encounterref&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;admincontext&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span><b>group </b>setEntryRequestAndFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">newRes</span>, <b>target</b> <span style="color: maroon">tgtEntry</span><span style="color: navy">)</span><span style="color: navy"> {
    </span>  newRes.id<b> as </b><span style="color: maroon">newResId</span><b> then</b><span style="color: navy"> {
    </span>    newResId<span style="color: navy"><b> -&gt; </b></span>tgtEntry.fullUrl = <span style="color: navy">(</span>'urn:ehr:' + %newRes.type().name + '/' + %newResId<span style="color: navy">)</span> <i>&quot;setFullUrl&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;setResourceType&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </span></pre></div>
      </text>
      <url value="https://interop.aphp.fr/ig/fhir/dm/StructureMap/EHR2FSL"/>
      <version value="0.1.0"/>
      <name value="EHR2FSL"/>
      <title
             value="Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container"/>
      <status value="draft"/>
      <date value="2025-10-23T20:49:03+00:00"/>
      <publisher value="AP-HP"/>
      <contact>
        <name value="AP-HP"/>
        <telecom>
          <system value="url"/>
          <value value="https://aphp.fr"/>
        </telecom>
      </contact>
      <description
                   value="Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container"/>
      <jurisdiction>
        <coding>
          <system value="urn:iso:std:iso:3166"/>
          <code value="FR"/>
          <display value="France"/>
        </coding>
      </jurisdiction>
      <structure>
        <url value="https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/ehr"/>
        <mode value="source"/>
        <alias value="EHR"/>
      </structure>
      <structure>
        <url value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
        <mode value="target"/>
        <alias value="Bundle"/>
      </structure>
      <group>
        <name value="EHR2FSL"/>
        <typeMode value="none"/>
        <input>
          <name value="src"/>
          <type value="EHR"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="bundle"/>
          <type value="Bundle"/>
          <mode value="target"/>
        </input>
        <rule>
          <name value="bundleid"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="bundle"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="bundletype"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="bundle"/>
            <contextType value="variable"/>
            <element value="type"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="collection"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="setTimestamp"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <contextType value="variable"/>
            <variable value="timestamp"/>
            <transform value="evaluate"/>
            <parameter>
              <valueString value="now()"/>
            </parameter>
          </target>
          <rule>
            <name value="affectTimestamp"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="bundle"/>
              <contextType value="variable"/>
              <element value="timestamp"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="timestamp"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="patiententry"/>
          <source>
            <context value="src"/>
            <element value="patient"/>
            <variable value="patient"/>
          </source>
          <target>
            <context value="bundle"/>
            <contextType value="variable"/>
            <element value="entry"/>
            <variable value="patientEntry"/>
          </target>
          <rule>
            <name value="createpatient"/>
            <source>
              <context value="patient"/>
            </source>
            <target>
              <context value="patientEntry"/>
              <contextType value="variable"/>
              <element value="resource"/>
              <variable value="dmPatient"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
            <rule>
              <name value="transformpatient"/>
              <source>
                <context value="patient"/>
              </source>
              <dependent>
                <name value="TransformPatient"/>
                <variable value="patient"/>
                <variable value="dmPatient"/>
              </dependent>
            </rule>
            <rule>
              <name value="setRequestAndFullUrl"/>
              <source>
                <context value="patient"/>
              </source>
              <dependent>
                <name value="setEntryRequestAndFullUrl"/>
                <variable value="dmPatient"/>
                <variable value="patientEntry"/>
              </dependent>
            </rule>
            <rule>
              <name value="transformpatientAdresse"/>
              <source>
                <context value="src"/>
                <element value="patientAdresse"/>
                <variable value="patientAdresse"/>
                <condition value="patientAdresse.patientId = %patient.patientId"/>
              </source>
              <dependent>
                <name value="setAddress"/>
                <variable value="patientAdresse"/>
                <variable value="dmPatient"/>
              </dependent>
            </rule>
            <rule>
              <name value="encounterentries"/>
              <source>
                <context value="src"/>
                <element value="donneesPmsi"/>
                <variable value="pmsi"/>
                <condition value="pmsi.patientId = %patient.patientId"/>
              </source>
              <target>
                <context value="bundle"/>
                <contextType value="variable"/>
                <element value="entry"/>
                <variable value="encounterEntry"/>
              </target>
              <rule>
                <name value="createencounter"/>
                <source>
                  <context value="pmsi"/>
                </source>
                <target>
                  <context value="encounterEntry"/>
                  <contextType value="variable"/>
                  <element value="resource"/>
                  <variable value="dmEncounter"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="Encounter"/>
                  </parameter>
                </target>
                <rule>
                  <name value="transformencounter"/>
                  <source>
                    <context value="pmsi"/>
                  </source>
                  <dependent>
                    <name value="TransformEncounter"/>
                    <variable value="pmsi"/>
                    <variable value="dmEncounter"/>
                    <variable value="dmPatient"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="setRequestAndFullUrl"/>
                  <source>
                    <context value="pmsi"/>
                  </source>
                  <dependent>
                    <name value="setEntryRequestAndFullUrl"/>
                    <variable value="dmEncounter"/>
                    <variable value="encounterEntry"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="conditionentries"/>
                  <source>
                    <context value="src"/>
                    <element value="diagnostics"/>
                    <variable value="diag"/>
                    <condition
                               value="(diag.patientId = %patient.patientId) and (diag.pmsiId = %pmsi.pmsiId)"/>
                  </source>
                  <target>
                    <context value="bundle"/>
                    <contextType value="variable"/>
                    <element value="entry"/>
                    <variable value="conditionEntry"/>
                  </target>
                  <rule>
                    <name value="createcondition"/>
                    <source>
                      <context value="diag"/>
                    </source>
                    <target>
                      <context value="conditionEntry"/>
                      <contextType value="variable"/>
                      <element value="resource"/>
                      <variable value="dmCondition"/>
                      <transform value="create"/>
                      <parameter>
                        <valueString value="Condition"/>
                      </parameter>
                    </target>
                    <rule>
                      <name value="transformcondition"/>
                      <source>
                        <context value="diag"/>
                      </source>
                      <dependent>
                        <name value="TransformCondition"/>
                        <variable value="diag"/>
                        <variable value="dmCondition"/>
                        <variable value="dmPatient"/>
                        <variable value="dmEncounter"/>
                      </dependent>
                    </rule>
                    <rule>
                      <name value="setRequestAndFullUrl"/>
                      <source>
                        <context value="diag"/>
                      </source>
                      <dependent>
                        <name value="setEntryRequestAndFullUrl"/>
                        <variable value="dmCondition"/>
                        <variable value="conditionEntry"/>
                      </dependent>
                    </rule>
                  </rule>
                </rule>
                <rule>
                  <name value="procedureentries"/>
                  <source>
                    <context value="src"/>
                    <element value="actes"/>
                    <variable value="acte"/>
                    <condition
                               value="(acte.patientId = %patient.patientId) and (acte.pmsiId = %pmsi.pmsiId)"/>
                  </source>
                  <target>
                    <context value="bundle"/>
                    <contextType value="variable"/>
                    <element value="entry"/>
                    <variable value="procedureEntry"/>
                  </target>
                  <rule>
                    <name value="createprocedure"/>
                    <source>
                      <context value="acte"/>
                    </source>
                    <target>
                      <context value="procedureEntry"/>
                      <contextType value="variable"/>
                      <element value="resource"/>
                      <variable value="dmProcedure"/>
                      <transform value="create"/>
                      <parameter>
                        <valueString value="Procedure"/>
                      </parameter>
                    </target>
                    <rule>
                      <name value="transformprocedure"/>
                      <source>
                        <context value="acte"/>
                      </source>
                      <dependent>
                        <name value="TransformProcedure"/>
                        <variable value="acte"/>
                        <variable value="dmProcedure"/>
                        <variable value="dmPatient"/>
                        <variable value="dmEncounter"/>
                      </dependent>
                    </rule>
                    <rule>
                      <name value="setRequestAndFullUrl"/>
                      <source>
                        <context value="acte"/>
                      </source>
                      <dependent>
                        <name value="setEntryRequestAndFullUrl"/>
                        <variable value="dmProcedure"/>
                        <variable value="procedureEntry"/>
                      </dependent>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="labentries"/>
              <source>
                <context value="src"/>
                <element value="biologie"/>
                <variable value="lab"/>
                <condition value="lab.patientId = %patient.patientId"/>
              </source>
              <target>
                <context value="bundle"/>
                <contextType value="variable"/>
                <element value="entry"/>
                <variable value="labEntry"/>
              </target>
              <rule>
                <name value="createlabobs"/>
                <source>
                  <context value="lab"/>
                </source>
                <target>
                  <context value="labEntry"/>
                  <contextType value="variable"/>
                  <element value="resource"/>
                  <variable value="dmLab"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="Observation"/>
                  </parameter>
                </target>
                <rule>
                  <name value="transformLabObs"/>
                  <source>
                    <context value="lab"/>
                  </source>
                  <dependent>
                    <name value="TransformLabObservation"/>
                    <variable value="lab"/>
                    <variable value="dmLab"/>
                    <variable value="dmPatient"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="setRequestAndFullUrl"/>
                  <source>
                    <context value="lab"/>
                  </source>
                  <dependent>
                    <name value="setEntryRequestAndFullUrl"/>
                    <variable value="dmLab"/>
                    <variable value="labEntry"/>
                  </dependent>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="medicationentries"/>
              <source>
                <context value="src"/>
                <element value="prescription"/>
                <variable value="pres"/>
                <condition value="pres.patientId = %patient.patientId"/>
              </source>
              <target>
                <context value="bundle"/>
                <contextType value="variable"/>
                <element value="entry"/>
                <variable value="medReqEntry"/>
              </target>
              <rule>
                <name value="createmedreq"/>
                <source>
                  <context value="pres"/>
                </source>
                <target>
                  <context value="medReqEntry"/>
                  <contextType value="variable"/>
                  <element value="resource"/>
                  <variable value="dmMedReq"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="MedicationRequest"/>
                  </parameter>
                </target>
                <rule>
                  <name value="createmedrequest"/>
                  <source>
                    <context value="src"/>
                  </source>
                  <dependent>
                    <name value="TransformMedicationRequest"/>
                    <variable value="pres"/>
                    <variable value="dmMedReq"/>
                    <variable value="dmPatient"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="setRequestAndFullUrl"/>
                  <source>
                    <context value="pres"/>
                  </source>
                  <dependent>
                    <name value="setEntryRequestAndFullUrl"/>
                    <variable value="dmMedReq"/>
                    <variable value="medReqEntry"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="transformPoso"/>
                  <source>
                    <context value="src"/>
                    <element value="posologie"/>
                    <variable value="poso"/>
                    <condition
                               value="%poso.prescriptionId = %pres.prescriptionId"/>
                  </source>
                  <dependent>
                    <name value="setPoso"/>
                    <variable value="poso"/>
                    <variable value="pres"/>
                    <variable value="dmMedReq"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="administrationentries"/>
                  <source>
                    <context value="src"/>
                    <element value="administration"/>
                    <variable value="admin"/>
                    <condition
                               value="(admin.patientId = %patient.patientId) and (admin.prescriptionId = pres.prescriptionId)"/>
                  </source>
                  <target>
                    <context value="bundle"/>
                    <contextType value="variable"/>
                    <element value="entry"/>
                    <variable value="adminEntry"/>
                  </target>
                  <rule>
                    <name value="createmedadmin"/>
                    <source>
                      <context value="admin"/>
                    </source>
                    <target>
                      <context value="adminEntry"/>
                      <contextType value="variable"/>
                      <element value="resource"/>
                      <variable value="dmAdmin"/>
                      <transform value="create"/>
                      <parameter>
                        <valueString value="MedicationAdministration"/>
                      </parameter>
                    </target>
                    <rule>
                      <name value="createmedadmin"/>
                      <source>
                        <context value="admin"/>
                      </source>
                      <dependent>
                        <name value="TransformMedicationAdministrationWOrder"/>
                        <variable value="admin"/>
                        <variable value="dmAdmin"/>
                        <variable value="dmPatient"/>
                        <variable value="dmMedReq"/>
                      </dependent>
                    </rule>
                    <rule>
                      <name value="setRequestAndFullUrl"/>
                      <source>
                        <context value="admin"/>
                      </source>
                      <dependent>
                        <name value="setEntryRequestAndFullUrl"/>
                        <variable value="dmAdmin"/>
                        <variable value="adminEntry"/>
                      </dependent>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="lifestyleentries"/>
              <source>
                <context value="src"/>
                <element value="styleVie"/>
                <variable value="lifestyle"/>
                <condition value="lifestyle.patientId = %patient.patientId"/>
              </source>
              <rule>
                <name value="tobaccoentries"/>
                <source>
                  <context value="lifestyle"/>
                  <element value="consommationTabac"/>
                  <variable value="tobacco"/>
                  <condition value="tobacco.exists()"/>
                </source>
                <target>
                  <context value="bundle"/>
                  <contextType value="variable"/>
                  <element value="entry"/>
                  <variable value="tobaccoEntry"/>
                </target>
                <rule>
                  <name value="createtobaccoobs"/>
                  <source>
                    <context value="tobacco"/>
                  </source>
                  <target>
                    <context value="tobaccoEntry"/>
                    <contextType value="variable"/>
                    <element value="resource"/>
                    <variable value="tobaccoObs"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="Observation"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="createtobaccoobs"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="TransformTobaccoObservation"/>
                      <variable value="lifestyle"/>
                      <variable value="tobaccoObs"/>
                      <variable value="dmPatient"/>
                    </dependent>
                  </rule>
                  <rule>
                    <name value="setRequestAndFullUrl"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="setEntryRequestAndFullUrl"/>
                      <variable value="tobaccoObs"/>
                      <variable value="tobaccoEntry"/>
                    </dependent>
                  </rule>
                </rule>
              </rule>
              <rule>
                <name value="alcoholentries"/>
                <source>
                  <context value="lifestyle"/>
                  <element value="consommationAlcool"/>
                  <variable value="alcohol"/>
                  <condition value="alcohol.exists()"/>
                </source>
                <target>
                  <context value="bundle"/>
                  <contextType value="variable"/>
                  <element value="entry"/>
                  <variable value="alcoholEntry"/>
                </target>
                <rule>
                  <name value="createalcoholobs"/>
                  <source>
                    <context value="alcohol"/>
                  </source>
                  <target>
                    <context value="alcoholEntry"/>
                    <contextType value="variable"/>
                    <element value="resource"/>
                    <variable value="alcoholObs"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="Observation"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="createalcoholobs"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="TransformAlcoholObservation"/>
                      <variable value="lifestyle"/>
                      <variable value="alcoholObs"/>
                      <variable value="dmPatient"/>
                    </dependent>
                  </rule>
                  <rule>
                    <name value="setRequestAndFullUrl"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="setEntryRequestAndFullUrl"/>
                      <variable value="alcoholObs"/>
                      <variable value="alcoholEntry"/>
                    </dependent>
                  </rule>
                </rule>
              </rule>
              <rule>
                <name value="drugentries"/>
                <source>
                  <context value="lifestyle"/>
                  <element value="consommationAutresDrogues"/>
                  <variable value="drugs"/>
                  <condition value="drugs.exists()"/>
                </source>
                <target>
                  <context value="bundle"/>
                  <contextType value="variable"/>
                  <element value="entry"/>
                  <variable value="drugEntry"/>
                </target>
                <rule>
                  <name value="createdrugobs"/>
                  <source>
                    <context value="drugs"/>
                  </source>
                  <target>
                    <context value="drugEntry"/>
                    <contextType value="variable"/>
                    <element value="resource"/>
                    <variable value="drugObs"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="Observation"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="createdrugobs"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="TransformDrugObservation"/>
                      <variable value="lifestyle"/>
                      <variable value="drugObs"/>
                      <variable value="dmPatient"/>
                    </dependent>
                  </rule>
                  <rule>
                    <name value="setRequestAndFullUrl"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="setEntryRequestAndFullUrl"/>
                      <variable value="drugObs"/>
                      <variable value="drugEntry"/>
                    </dependent>
                  </rule>
                </rule>
              </rule>
              <rule>
                <name value="physicalentries"/>
                <source>
                  <context value="lifestyle"/>
                  <element value="activitePhysique"/>
                  <variable value="physical"/>
                  <condition value="physical.exists()"/>
                </source>
                <target>
                  <context value="bundle"/>
                  <contextType value="variable"/>
                  <element value="entry"/>
                  <variable value="physicalEntry"/>
                </target>
                <rule>
                  <name value="createphysicalobs"/>
                  <source>
                    <context value="physical"/>
                  </source>
                  <target>
                    <context value="physicalEntry"/>
                    <contextType value="variable"/>
                    <element value="resource"/>
                    <variable value="physicalObs"/>
                    <transform value="create"/>
                    <parameter>
                      <valueString value="Observation"/>
                    </parameter>
                  </target>
                  <rule>
                    <name value="createphysicalobs"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="TransformPhysicalActivityObservation"/>
                      <variable value="lifestyle"/>
                      <variable value="physicalObs"/>
                      <variable value="dmPatient"/>
                    </dependent>
                  </rule>
                  <rule>
                    <name value="setRequestAndFullUrl"/>
                    <source>
                      <context value="lifestyle"/>
                    </source>
                    <dependent>
                      <name value="setEntryRequestAndFullUrl"/>
                      <variable value="physicalObs"/>
                      <variable value="physicalEntry"/>
                    </dependent>
                  </rule>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="vitalentries"/>
              <source>
                <context value="src"/>
                <element value="dossierSoins"/>
                <variable value="soin"/>
                <condition value="soin.patientId = %patient.patientId"/>
              </source>
              <target>
                <context value="bundle"/>
                <contextType value="variable"/>
                <element value="entry"/>
                <variable value="vitalEntry"/>
              </target>
              <rule>
                <name value="createmesureobs"/>
                <source>
                  <context value="soin"/>
                </source>
                <target>
                  <context value="vitalEntry"/>
                  <contextType value="variable"/>
                  <element value="resource"/>
                  <variable value="dmObs"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="Observation"/>
                  </parameter>
                </target>
                <rule>
                  <name value="createmesureobs"/>
                  <source>
                    <context value="soin"/>
                  </source>
                  <dependent>
                    <name value="TransformVitalSigns"/>
                    <variable value="soin"/>
                    <variable value="dmObs"/>
                    <variable value="dmPatient"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="setRequestAndFullUrl"/>
                  <source>
                    <context value="soin"/>
                  </source>
                  <dependent>
                    <name value="setEntryRequestAndFullUrl"/>
                    <variable value="dmObs"/>
                    <variable value="vitalEntry"/>
                  </dependent>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="administrationentries"/>
              <source>
                <context value="src"/>
                <element value="administration"/>
                <variable value="admin"/>
                <condition
                           value="(admin.patientId = %patient.patientId) and admin.prescriptionId.empty()"/>
              </source>
              <target>
                <context value="bundle"/>
                <contextType value="variable"/>
                <element value="entry"/>
                <variable value="adminEntry"/>
              </target>
              <rule>
                <name value="createmedadmin"/>
                <source>
                  <context value="admin"/>
                </source>
                <target>
                  <context value="adminEntry"/>
                  <contextType value="variable"/>
                  <element value="resource"/>
                  <variable value="dmAdmin"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="MedicationAdministration"/>
                  </parameter>
                </target>
                <rule>
                  <name value="createmedadmin"/>
                  <source>
                    <context value="admin"/>
                  </source>
                  <dependent>
                    <name value="TransformMedicationAdministrationWOOrder"/>
                    <variable value="admin"/>
                    <variable value="dmAdmin"/>
                    <variable value="dmPatient"/>
                  </dependent>
                </rule>
                <rule>
                  <name value="setRequestAndFullUrl"/>
                  <source>
                    <context value="admin"/>
                  </source>
                  <dependent>
                    <name value="setEntryRequestAndFullUrl"/>
                    <variable value="dmAdmin"/>
                    <variable value="adminEntry"/>
                  </dependent>
                </rule>
              </rule>
            </rule>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformPatient"/>
        <typeMode value="none"/>
        <documentation
                       value="---------------------------------------------------------
    PATIENT TRANSFORMATION
    ---------------------------------------------------------"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgt"/>
          <type value="Patient"/>
          <mode value="target"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="patientidentifier"/>
          <source>
            <context value="src"/>
            <element value="patientId"/>
            <variable value="pid"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="iduse"/>
            <source>
              <context value="pid"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="use"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="usual"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="idtype"/>
            <source>
              <context value="pid"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="cc"/>
              <parameter>
                <valueString
                             value="http://terminology.hl7.org/CodeSystem/v2-0203"/>
              </parameter>
              <parameter>
                <valueString value="PI"/>
              </parameter>
              <parameter>
                <valueString value="Patient Identifier"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="idsystem"/>
            <source>
              <context value="pid"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/patient-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="idvalue"/>
            <source>
              <context value="pid"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="pid"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="insidentifier"/>
          <source>
            <context value="src"/>
            <element value="ins"/>
            <variable value="ins"/>
            <condition value="ins.exists()"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="insIdentifier"/>
          </target>
          <rule>
            <name value="insuse"/>
            <source>
              <context value="ins"/>
            </source>
            <target>
              <context value="insIdentifier"/>
              <contextType value="variable"/>
              <element value="use"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="official"/>
              </parameter>
            </target>
            <documentation
                           value="On part du principe qu'on n'est pas sur un old."/>
          </rule>
          <rule>
            <name value="instype"/>
            <source>
              <context value="ins"/>
            </source>
            <target>
              <context value="insIdentifier"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="cc"/>
              <parameter>
                <valueString
                             value="https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-v2-0203"/>
              </parameter>
              <parameter>
                <valueString value="INS-NIR"/>
              </parameter>
              <parameter>
                <valueString value="NIR définitif"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="inssystem"/>
            <source>
              <context value="ins"/>
            </source>
            <target>
              <context value="insIdentifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="urn:oid:1.2.250.1.213.1.4.8"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="insvalue"/>
            <source>
              <context value="ins"/>
            </source>
            <target>
              <context value="insIdentifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="ins"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="patientname"/>
          <source>
            <context value="src"/>
            <condition value="src.nom.exists() or src.prenom.exists()"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="name"/>
            <variable value="name"/>
          </target>
          <rule>
            <name value="familyname"/>
            <source>
              <context value="src"/>
              <element value="nom"/>
              <variable value="lastName"/>
            </source>
            <target>
              <context value="name"/>
              <contextType value="variable"/>
              <element value="family"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="lastName"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="givenname"/>
            <source>
              <context value="src"/>
              <element value="prenom"/>
              <variable value="firstName"/>
            </source>
            <target>
              <context value="name"/>
              <contextType value="variable"/>
              <element value="given"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="firstName"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="nameuse"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="name"/>
              <contextType value="variable"/>
              <element value="use"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="official"/>
              </parameter>
            </target>
            <documentation value="hypothèse un peu forte."/>
          </rule>
        </rule>
        <rule>
          <name value="birthdate"/>
          <source>
            <context value="src"/>
            <element value="dateNaissance"/>
            <variable value="birthDate"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="birthDate"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="birthDate"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="gendermale"/>
          <source>
            <context value="src"/>
            <element value="sexe"/>
            <variable value="gender"/>
            <condition value="gender = 'h'"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="gender"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="male"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="genderfemale"/>
          <source>
            <context value="src"/>
            <element value="sexe"/>
            <variable value="gender"/>
            <condition value="gender = 'f'"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="gender"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="female"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="genderunknown"/>
          <source>
            <context value="src"/>
            <element value="sexe"/>
            <variable value="gender"/>
            <condition
                       value="gender.exists() and (gender != 'h') and (gender != 'f')"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="gender"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="unknown"/>
            </parameter>
          </target>
          <documentation
                         value="n'a pas grand sens en l'état des contraintes SQL"/>
        </rule>
        <rule>
          <name value="deathDate"/>
          <source>
            <context value="src"/>
            <element value="dateDeces"/>
            <variable value="deathDate"/>
            <condition value="deathDate.exists()"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="deceased"/>
            <variable value="deceasedDate"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="deathDate"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
          <rule>
            <name value="deathSource"/>
            <source>
              <context value="src"/>
              <element value="sourceDeces"/>
              <variable value="deathSource"/>
              <condition value="deathSource.exists()"/>
            </source>
            <target>
              <context value="deceasedDate"/>
              <contextType value="variable"/>
              <element value="extension"/>
              <variable value="DeathSourceExtension"/>
            </target>
            <rule>
              <name value="deathSourceUrl"/>
              <source>
                <context value="deathSource"/>
              </source>
              <target>
                <context value="DeathSourceExtension"/>
                <contextType value="variable"/>
                <element value="url"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/DeathSource"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="deathSourceValue"/>
              <source>
                <context value="deathSource"/>
              </source>
              <target>
                <context value="DeathSourceExtension"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="cast"/>
                <parameter>
                  <valueId value="deathSource"/>
                </parameter>
                <parameter>
                  <valueString value="code"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="multiplebirth"/>
          <source>
            <context value="src"/>
            <element value="rangGemellaire"/>
            <variable value="twin"/>
            <condition value="twin.exists()"/>
          </source>
          <target>
            <context value="tgt"/>
            <contextType value="variable"/>
            <element value="multipleBirth"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="twin"/>
            </parameter>
          </target>
        </rule>
      </group>
      <group>
        <name value="setAddress"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    PATIENT_LOCATION TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtPat"/>
          <type value="Patient"/>
          <mode value="target"/>
        </input>
        <rule>
          <name value="checkSource"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.latitude.exists() or src.longitude.exists() or src.codeIris.exists() or src.libelleIris.exists() or src.codeGeographiqueResidence.exists()"/>
          </source>
          <rule>
            <name value="createAddress"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="tgtPat"/>
              <contextType value="variable"/>
              <element value="address"/>
              <variable value="newAddress"/>
            </target>
            <rule>
              <name value="setCoordinates"/>
              <source>
                <context value="src"/>
                <condition
                           value="src.latitude.exists() or src.longitude.exists()"/>
              </source>
              <target>
                <context value="newAddress"/>
                <contextType value="variable"/>
                <element value="extension"/>
                <variable value="geolocationExtension"/>
              </target>
              <target>
                <context value="geolocationExtension"/>
                <contextType value="variable"/>
                <element value="url"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://hl7.org/fhir/StructureDefinition/geolocation"/>
                </parameter>
              </target>
              <rule>
                <name value="setLat"/>
                <source>
                  <context value="src"/>
                  <element value="latitude"/>
                  <variable value="srcLat"/>
                </source>
                <target>
                  <context value="geolocationExtension"/>
                  <contextType value="variable"/>
                  <element value="extension"/>
                  <variable value="tgtLat"/>
                </target>
                <target>
                  <context value="tgtLat"/>
                  <contextType value="variable"/>
                  <element value="url"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="latitude"/>
                  </parameter>
                </target>
                <target>
                  <context value="tgtLat"/>
                  <contextType value="variable"/>
                  <element value="value"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="srcLat"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="setLong"/>
                <source>
                  <context value="src"/>
                  <element value="longitude"/>
                  <variable value="srcLong"/>
                </source>
                <target>
                  <context value="geolocationExtension"/>
                  <contextType value="variable"/>
                  <element value="extension"/>
                  <variable value="tgtLong"/>
                </target>
                <target>
                  <context value="tgtLong"/>
                  <contextType value="variable"/>
                  <element value="url"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="longitude"/>
                  </parameter>
                </target>
                <target>
                  <context value="tgtLong"/>
                  <contextType value="variable"/>
                  <element value="value"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="srcLong"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="setIris"/>
              <source>
                <context value="src"/>
                <condition
                           value="src.codeIris.exists() or src.libelleIris.exists()"/>
              </source>
              <target>
                <context value="newAddress"/>
                <contextType value="variable"/>
                <element value="line"/>
                <variable value="irisLine"/>
                <transform value="evaluate"/>
                <parameter>
                  <valueString value="%src.libelleIris"/>
                </parameter>
              </target>
              <target>
                <context value="irisLine"/>
                <contextType value="variable"/>
                <element value="extension"/>
                <variable value="irisExtension"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Extension"/>
                </parameter>
              </target>
              <target>
                <context value="irisExtension"/>
                <contextType value="variable"/>
                <element value="url"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-censusTract"/>
                </parameter>
              </target>
              <target>
                <context value="irisExtension"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="evaluate"/>
                <parameter>
                  <valueString value="%src.codeIris"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="SetResidencePmsi"/>
              <source>
                <context value="src"/>
                <element value="codeGeographiqueResidence"/>
                <variable value="srcCodeGeographiqueResidence"/>
                <condition value="src.codeGeographiqueResidence.exists()"/>
              </source>
              <target>
                <context value="newAddress"/>
                <contextType value="variable"/>
                <element value="extension"/>
                <variable value="residencePmsiExtension"/>
              </target>
              <target>
                <context value="residencePmsiExtension"/>
                <contextType value="variable"/>
                <element value="url"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/PmsiCodeGeo"/>
                </parameter>
              </target>
              <target>
                <context value="residencePmsiExtension"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="cast"/>
                <parameter>
                  <valueId value="srcCodeGeographiqueResidence"/>
                </parameter>
                <parameter>
                  <valueString value="code"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="setDateRecueil"/>
              <source>
                <context value="src"/>
                <element value="dateRecueil"/>
                <variable value="dateRecueil"/>
              </source>
              <target>
                <context value="newAddress"/>
                <contextType value="variable"/>
                <element value="period"/>
                <variable value="newAddressPeriod"/>
              </target>
              <target>
                <context value="newAddressPeriod"/>
                <contextType value="variable"/>
                <element value="start"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="dateRecueil"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformEncounter"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    ENCOUNTER TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtEnc"/>
          <type value="Encounter"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="encounteridentifier"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="idtype"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="cc"/>
              <parameter>
                <valueString
                             value="https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-identifier-type"/>
              </parameter>
              <parameter>
                <valueString value="VN"/>
              </parameter>
              <parameter>
                <valueString value="Visit Number"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="encounteridsystem"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/pmsi-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="encounteridvalue"/>
            <source>
              <context value="src"/>
              <element value="pmsiId"/>
              <variable value="srcEncoutnerId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="srcEncoutnerId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="encounterstatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="finished"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="encounterclass"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="class"/>
            <transform value="c"/>
            <parameter>
              <valueString
                           value="http://terminology.hl7.org/CodeSystem/v3-ActCode"/>
            </parameter>
            <parameter>
              <valueString value="IMP"/>
            </parameter>
            <parameter>
              <valueString value="inpatient encounter"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="encountersubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectreference"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="encounterperiod"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.dateDebutSejour.exists() or src.dateFinSejour.exists()"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="period"/>
            <variable value="period"/>
          </target>
          <rule>
            <name value="periodstart"/>
            <source>
              <context value="src"/>
              <element value="dateDebutSejour"/>
              <variable value="startDate"/>
            </source>
            <target>
              <context value="period"/>
              <contextType value="variable"/>
              <element value="start"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="startDate"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="periodend"/>
            <source>
              <context value="src"/>
              <element value="dateFinSejour"/>
              <variable value="endDate"/>
            </source>
            <target>
              <context value="period"/>
              <contextType value="variable"/>
              <element value="end"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="endDate"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="encounterhospitalization"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.modeEntree.exists() or src.modeSortie.exists()"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="hospitalization"/>
            <variable value="hosp"/>
          </target>
          <rule>
            <name value="admitsource"/>
            <source>
              <context value="src"/>
              <element value="modeEntree"/>
              <variable value="admitSource"/>
            </source>
            <target>
              <context value="hosp"/>
              <contextType value="variable"/>
              <element value="admitSource"/>
              <variable value="admitSrc"/>
            </target>
            <rule>
              <name value="admitsourcetext"/>
              <source>
                <context value="admitSource"/>
              </source>
              <target>
                <context value="admitSrc"/>
                <contextType value="variable"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="admitSource"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="dischargedisposition"/>
            <source>
              <context value="src"/>
              <element value="modeSortie"/>
              <variable value="dischargeDisp"/>
            </source>
            <target>
              <context value="hosp"/>
              <contextType value="variable"/>
              <element value="dischargeDisposition"/>
              <variable value="dischargeDsp"/>
            </target>
            <rule>
              <name value="dischargedisptext"/>
              <source>
                <context value="dischargeDisp"/>
              </source>
              <target>
                <context value="dischargeDsp"/>
                <contextType value="variable"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="dischargeDisp"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="provider"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.uniteFonctionnelle.exists() or src.service.exists() or src.etablissement.exists()"/>
          </source>
          <target>
            <context value="tgtEnc"/>
            <contextType value="variable"/>
            <element value="serviceProvider"/>
            <variable value="provider"/>
          </target>
          <rule>
            <name value="providerdisplay"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="provider"/>
              <contextType value="variable"/>
              <element value="display"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString
                             value="iif(%src.uniteFonctionnelle.exists(), %src.uniteFonctionnelle, iif(%src.service.exists(), %src.service, %src.etablissement))"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformCondition"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    CONDITION TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtCond"/>
          <type value="Condition"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="encounter"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="conditionidentifier"/>
          <source>
            <context value="src"/>
            <element value="diagnosticId"/>
            <variable value="diagId"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="conditionidsystem"/>
            <source>
              <context value="diagId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/diagnostic-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="conditionidvalue"/>
            <source>
              <context value="diagId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="diagId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="categoryencounterDiag"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="category"/>
            <transform value="cc"/>
            <parameter>
              <valueString
                           value="http://terminology.hl7.org/CodeSystem/condition-category"/>
            </parameter>
            <parameter>
              <valueString value="encounter-diagnosis"/>
            </parameter>
            <parameter>
              <valueString value="Encounter Diagnosis"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="conditioncategory"/>
          <source>
            <context value="src"/>
            <element value="typeDiagnostic"/>
            <variable value="diagType"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorytext"/>
            <source>
              <context value="diagType"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="diagType"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="varcode"/>
          <source>
            <context value="src"/>
            <element value="codeDiagnostic"/>
            <variable value="srcCode"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="conditionCode"/>
          </target>
          <rule>
            <name value="conditioncode"/>
            <source>
              <context value="src"/>
              <element value="libelleDiagnostic"/>
              <variable value="label"/>
            </source>
            <target>
              <context value="conditionCode"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="tgtCoding"/>
            </target>
            <target>
              <context value="tgtCoding"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://hl7.org/fhir/sid/icd-10"/>
              </parameter>
            </target>
            <target>
              <context value="tgtCoding"/>
              <contextType value="variable"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="srcCode"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="codetext"/>
            <source>
              <context value="src"/>
              <element value="libelleDiagnostic"/>
              <variable value="text"/>
            </source>
            <target>
              <context value="conditionCode"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="text"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="conditionsubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="conditionencounter"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="encounter"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="encounterref"/>
            <source>
              <context value="encounter"/>
              <element value="id"/>
              <variable value="encounterId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Encounter/' + %encounterId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Encounter"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="conditionrecordeddate"/>
          <source>
            <context value="src"/>
            <element value="dateRecueil"/>
            <variable value="entryDate"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="recordedDate"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="entryDate"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="conditionclinicalstatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="clinicalStatus"/>
            <transform value="cc"/>
            <parameter>
              <valueString
                           value="http://terminology.hl7.org/CodeSystem/condition-clinical"/>
            </parameter>
            <parameter>
              <valueString value="active"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="conditionverificationstatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtCond"/>
            <contextType value="variable"/>
            <element value="verificationStatus"/>
            <transform value="cc"/>
            <parameter>
              <valueString
                           value="http://terminology.hl7.org/CodeSystem/condition-ver-status"/>
            </parameter>
            <parameter>
              <valueString value="confirmed"/>
            </parameter>
          </target>
        </rule>
      </group>
      <group>
        <name value="TransformProcedure"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    PROCEDURE TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtProc"/>
          <type value="Procedure"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="encounter"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="procedureidentifier"/>
          <source>
            <context value="src"/>
            <element value="acteId"/>
            <variable value="acteId"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="procedureidsystem"/>
            <source>
              <context value="acteId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/acte-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="procedureidvalue"/>
            <source>
              <context value="acteId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="acteId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="procedurestatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="completed"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="procedurecode"/>
          <source>
            <context value="src"/>
            <element value="codeActe"/>
            <variable value="code"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="procedureCode"/>
          </target>
          <rule>
            <name value="procedurecoding"/>
            <source>
              <context value="code"/>
            </source>
            <target>
              <context value="procedureCode"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <target>
              <context value="coding"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString
                             value="https://interop.aphp.fr/ig/fhir/dm/CodeSystem/Ccam"/>
              </parameter>
            </target>
            <target>
              <context value="coding"/>
              <contextType value="variable"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="code"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="codetext"/>
            <source>
              <context value="src"/>
              <element value="libelleActe"/>
              <variable value="text"/>
            </source>
            <target>
              <context value="procedureCode"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="text"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="proceduresubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="procedureencounter"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="encounter"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="encounterref"/>
            <source>
              <context value="encounter"/>
              <element value="id"/>
              <variable value="encounterId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Encounter/' + %encounterId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Encounter"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="procedureperformed"/>
          <source>
            <context value="src"/>
            <element value="dateActe"/>
            <variable value="performedDate"/>
            <condition value="%performedDate.exists()"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="performed"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="performedDate"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="procedureperformer"/>
          <source>
            <context value="src"/>
            <element value="executant"/>
            <variable value="performer"/>
          </source>
          <target>
            <context value="tgtProc"/>
            <contextType value="variable"/>
            <element value="performer"/>
            <variable value="perf"/>
          </target>
          <rule>
            <name value="performeractor"/>
            <source>
              <context value="performer"/>
            </source>
            <target>
              <context value="perf"/>
              <contextType value="variable"/>
              <element value="actor"/>
              <variable value="actor"/>
            </target>
            <rule>
              <name value="performerdisplay"/>
              <source>
                <context value="performer"/>
              </source>
              <target>
                <context value="actor"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="performer"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="performerType"/>
              <source>
                <context value="performer"/>
              </source>
              <target>
                <context value="actor"/>
                <contextType value="variable"/>
                <element value="type"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Practitioner"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="performerFunction"/>
            <source>
              <context value="performer"/>
            </source>
            <target>
              <context value="perf"/>
              <contextType value="variable"/>
              <element value="function"/>
              <variable value="function"/>
            </target>
            <target>
              <context value="function"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Exécutant"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformLabObservation"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    LABORATORY OBSERVATION TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtObs"/>
          <type value="Observation"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="labidentifier"/>
          <source>
            <context value="src"/>
            <element value="biologieId"/>
            <variable value="bioId"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="labidsystem"/>
            <source>
              <context value="bioId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/biologie-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="labidvalue"/>
            <source>
              <context value="bioId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="bioId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="statusvalidated"/>
          <source>
            <context value="src"/>
            <element value="statutValidation"/>
            <variable value="validation"/>
            <condition value="validation = 'VALIDE'"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="statusdefault"/>
          <source>
            <context value="src"/>
            <condition value="src.statutValidation.exists().not()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="labcategory"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorycoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="categorysystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorycode"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="laboratory"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorydisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Laboratory"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="labcode"/>
          <source>
            <context value="src"/>
            <element value="codeLoinc"/>
            <variable value="loinc"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="code"/>
          </target>
          <rule>
            <name value="labcoding"/>
            <source>
              <context value="loinc"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="codesystem"/>
              <source>
                <context value="loinc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codevalue"/>
              <source>
                <context value="loinc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="loinc"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codetext"/>
            <source>
              <context value="src"/>
              <element value="libelleTest"/>
              <variable value="text"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="text"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="labsubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="labeffective"/>
          <source>
            <context value="src"/>
            <element value="datePrelevement"/>
            <variable value="collectionDate"/>
            <condition value="%collectionDate.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="collectionDate"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="labvaluequantity"/>
          <source>
            <context value="src"/>
            <element value="valeur"/>
            <variable value="numValue"/>
            <condition value="numValue.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="value"/>
            <variable value="qty"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Quantity"/>
            </parameter>
          </target>
          <rule>
            <name value="quantityvalue"/>
            <source>
              <context value="numValue"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="numValue"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="quantityunit"/>
            <source>
              <context value="src"/>
              <element value="unite"/>
              <variable value="unit"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="unit"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="unit"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="quantitycode"/>
            <source>
              <context value="src"/>
              <element value="unite"/>
              <variable value="unit"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="unit"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="quantitysystem"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://unitsofmeasure.org"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="labreferencerange"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.borneInfNormale.exists() or src.borneSupNormale.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="referenceRange"/>
            <variable value="range"/>
          </target>
          <rule>
            <name value="referencelow"/>
            <source>
              <context value="src"/>
              <element value="borneInfNormale"/>
              <variable value="low"/>
            </source>
            <target>
              <context value="range"/>
              <contextType value="variable"/>
              <element value="low"/>
              <variable value="lowQty"/>
            </target>
            <rule>
              <name value="reflowvalue"/>
              <source>
                <context value="low"/>
              </source>
              <target>
                <context value="lowQty"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="low"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="reflowunit"/>
              <source>
                <context value="src"/>
                <element value="unite"/>
                <variable value="unit"/>
              </source>
              <target>
                <context value="lowQty"/>
                <contextType value="variable"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="unit"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="reflowcode"/>
              <source>
                <context value="src"/>
                <element value="unite"/>
                <variable value="unit"/>
              </source>
              <target>
                <context value="lowQty"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="unit"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="reflowsystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="lowQty"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://unitsofmeasure.org"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="referencehigh"/>
            <source>
              <context value="src"/>
              <element value="borneSupNormale"/>
              <variable value="high"/>
            </source>
            <target>
              <context value="range"/>
              <contextType value="variable"/>
              <element value="high"/>
              <variable value="highQty"/>
            </target>
            <rule>
              <name value="refhighvalue"/>
              <source>
                <context value="high"/>
              </source>
              <target>
                <context value="highQty"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="high"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="refhighunit"/>
              <source>
                <context value="src"/>
                <element value="unite"/>
                <variable value="unit"/>
              </source>
              <target>
                <context value="highQty"/>
                <contextType value="variable"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="unit"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="refhighcode"/>
              <source>
                <context value="src"/>
                <element value="unite"/>
                <variable value="unit"/>
              </source>
              <target>
                <context value="highQty"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="unit"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="refhighsystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="highQty"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://unitsofmeasure.org"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="labperformer"/>
          <source>
            <context value="src"/>
            <element value="laboratoire"/>
            <variable value="lab"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="performer"/>
            <variable value="performer"/>
          </target>
          <rule>
            <name value="performerdisplay"/>
            <source>
              <context value="lab"/>
            </source>
            <target>
              <context value="performer"/>
              <contextType value="variable"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="lab"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="performerType"/>
            <source>
              <context value="lab"/>
            </source>
            <target>
              <context value="performer"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Organization"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformMedicationRequest"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    MEDICATION REQUEST TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtMedReq"/>
          <type value="MedicationRequest"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="medrequestidentifier"/>
          <source>
            <context value="src"/>
            <element value="prescriptionId"/>
            <variable value="presId"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="medrequestidsystem"/>
            <source>
              <context value="presId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/prescription-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="medrequestidvalue"/>
            <source>
              <context value="presId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="presId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="medrequeststatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="unknown"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="medrequestintent"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="intent"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="order"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="medrequestsubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="medicationdenomination"/>
          <source>
            <context value="src"/>
            <element value="denomination"/>
            <variable value="denomination"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="medication"/>
            <variable value="medication"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CodeableConcept"/>
            </parameter>
          </target>
          <rule>
            <name value="medicationtext"/>
            <source>
              <context value="denomination"/>
              <variable value="text"/>
            </source>
            <target>
              <context value="medication"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="text"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="atccoding"/>
            <source>
              <context value="src"/>
              <element value="codeAtc"/>
              <variable value="atc"/>
            </source>
            <target>
              <context value="medication"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="atcsystem"/>
              <source>
                <context value="atc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://www.whocc.no/atc"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="atccode"/>
              <source>
                <context value="atc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="atc"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="medauthored"/>
          <source>
            <context value="src"/>
            <element value="datePrescription"/>
            <variable value="prescDate"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="authoredOn"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="prescDate"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="medrequester"/>
          <source>
            <context value="src"/>
            <element value="prescripteur"/>
            <variable value="prescriber"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="requester"/>
            <variable value="requesterRef"/>
          </target>
          <rule>
            <name value="requesterdisplay"/>
            <source>
              <context value="prescriber"/>
            </source>
            <target>
              <context value="requesterRef"/>
              <contextType value="variable"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="prescriber"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="requesterType"/>
            <source>
              <context value="prescriber"/>
            </source>
            <target>
              <context value="requesterRef"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Practitioner"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="setPoso"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    POSOLOGIE TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="srcPoso"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="srcPres"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtMedReq"/>
          <mode value="target"/>
        </input>
        <rule>
          <name value="dosageinstruction"/>
          <source>
            <context value="srcPres"/>
          </source>
          <target>
            <context value="tgtMedReq"/>
            <contextType value="variable"/>
            <element value="dosageInstruction"/>
            <variable value="dosageInstruction"/>
          </target>
          <rule>
            <name value="dosagetext"/>
            <source>
              <context value="srcPoso"/>
            </source>
            <target>
              <context value="dosageInstruction"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString
                             value="'Prendre' + iif(%srcPoso.quantite.exists(), ' ' + %srcPoso.quantite.toString(), '1') + iif(%srcPoso.uniteQuantite.exists(), ' ' + %srcPoso.uniteQuantite, ' comprimé') + iif(%srcPoso.nombrePrisesParJour.exists(), ' ' + %srcPoso.nombrePrisesParJour.toString() + ' fois par jour', ' selon prescription')"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dosageroute"/>
            <source>
              <context value="srcPres"/>
              <element value="voieAdministration"/>
              <variable value="route"/>
            </source>
            <target>
              <context value="dosageInstruction"/>
              <contextType value="variable"/>
              <element value="route"/>
              <variable value="routeCC"/>
            </target>
            <rule>
              <name value="routecoding"/>
              <source>
                <context value="route"/>
              </source>
              <target>
                <context value="routeCC"/>
                <contextType value="variable"/>
                <element value="coding"/>
                <variable value="routeCoding"/>
              </target>
              <rule>
                <name value="routecode"/>
                <source>
                  <context value="route"/>
                </source>
                <target>
                  <context value="routeCoding"/>
                  <contextType value="variable"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="route"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="routesystem"/>
                <source>
                  <context value="route"/>
                </source>
                <target>
                  <context value="routeCoding"/>
                  <contextType value="variable"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString
                                 value="https://smt.esante.gouv.fr/terminologie-standardterms"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="dosagetiming"/>
            <source>
              <context value="srcPoso"/>
            </source>
            <target>
              <context value="dosageInstruction"/>
              <contextType value="variable"/>
              <element value="timing"/>
              <variable value="timing"/>
            </target>
            <rule>
              <name value="timingrepeat"/>
              <source>
                <context value="srcPoso"/>
              </source>
              <target>
                <context value="timing"/>
                <contextType value="variable"/>
                <element value="repeat"/>
                <variable value="timingRepeat"/>
              </target>
              <rule>
                <name value="prescriptionperiod"/>
                <source>
                  <context value="srcPres"/>
                  <condition
                             value="srcPres.dateDebutPrescription.exists() or srcPres.dateFinPrescription.exists()"/>
                </source>
                <target>
                  <context value="timingRepeat"/>
                  <contextType value="variable"/>
                  <element value="bounds"/>
                  <variable value="medReqPeriod"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="Period"/>
                  </parameter>
                </target>
                <rule>
                  <name value="periodstart"/>
                  <source>
                    <context value="srcPres"/>
                    <element value="dateDebutPrescription"/>
                    <variable value="startDate"/>
                  </source>
                  <target>
                    <context value="medReqPeriod"/>
                    <contextType value="variable"/>
                    <element value="start"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueId value="startDate"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="periodend"/>
                  <source>
                    <context value="srcPres"/>
                    <element value="dateFinPrescription"/>
                    <variable value="endDate"/>
                  </source>
                  <target>
                    <context value="medReqPeriod"/>
                    <contextType value="variable"/>
                    <element value="end"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueId value="endDate"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
              <rule>
                <name value="timingfrequency"/>
                <source>
                  <context value="srcPoso"/>
                  <element value="nombrePrisesParJour"/>
                  <variable value="frequency"/>
                </source>
                <target>
                  <context value="timingRepeat"/>
                  <contextType value="variable"/>
                  <element value="frequency"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="frequency"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="timingperiod"/>
                <source>
                  <context value="srcPoso"/>
                  <element value="nombrePrisesParJour"/>
                  <variable value="frequency"/>
                </source>
                <target>
                  <context value="timingRepeat"/>
                  <contextType value="variable"/>
                  <element value="period"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="1"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="timingperiodunit"/>
                <source>
                  <context value="srcPoso"/>
                  <element value="nombrePrisesParJour"/>
                  <variable value="frequency"/>
                </source>
                <target>
                  <context value="timingRepeat"/>
                  <contextType value="variable"/>
                  <element value="periodUnit"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="d"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="doseandrate"/>
            <source>
              <context value="srcPoso"/>
              <element value="quantite"/>
              <variable value="quantity"/>
            </source>
            <target>
              <context value="dosageInstruction"/>
              <contextType value="variable"/>
              <element value="doseAndRate"/>
              <variable value="doseRate"/>
            </target>
            <rule>
              <name value="dosequantity"/>
              <source>
                <context value="quantity"/>
              </source>
              <target>
                <context value="doseRate"/>
                <contextType value="variable"/>
                <element value="dose"/>
                <variable value="doseQuantity"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Quantity"/>
                </parameter>
              </target>
              <rule>
                <name value="dosevalue"/>
                <source>
                  <context value="quantity"/>
                </source>
                <target>
                  <context value="doseQuantity"/>
                  <contextType value="variable"/>
                  <element value="value"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="quantity"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="doseunit"/>
                <source>
                  <context value="srcPoso"/>
                  <element value="uniteQuantite"/>
                  <variable value="unit"/>
                </source>
                <target>
                  <context value="doseQuantity"/>
                  <contextType value="variable"/>
                  <element value="unit"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="unit"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dosecode"/>
                <source>
                  <context value="srcPoso"/>
                  <element value="uniteQuantite"/>
                  <variable value="unit"/>
                </source>
                <target>
                  <context value="doseQuantity"/>
                  <contextType value="variable"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="unit"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dosesystem"/>
                <source>
                  <context value="srcPoso"/>
                </source>
                <target>
                  <context value="doseQuantity"/>
                  <contextType value="variable"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://unitsofmeasure.org"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformVitalSigns"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    VITAL SIGNS TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtObs"/>
          <type value="Observation"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="medrequestidentifier"/>
          <source>
            <context value="src"/>
            <element value="soinId"/>
            <variable value="soinId"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="soinidsystem"/>
            <source>
              <context value="soinId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/soin-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="soinidvalue"/>
            <source>
              <context value="soinId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="soinId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="status"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorycoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="categorysystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorycode"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="vital-signs"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="code"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="codesystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codevalue"/>
              <source>
                <context value="src"/>
                <element value="codeLoinc"/>
                <variable value="codeLoinc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="codeLoinc"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codetext"/>
            <source>
              <context value="src"/>
              <element value="libelleTest"/>
              <variable value="label"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="label"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="obssubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="effective"/>
          <source>
            <context value="src"/>
            <element value="dateMesure"/>
            <variable value="date"/>
            <condition value="%date.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="date"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="quantity"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="value"/>
            <variable value="qty"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Quantity"/>
            </parameter>
          </target>
          <rule>
            <name value="value"/>
            <source>
              <context value="src"/>
              <element value="valeur"/>
              <variable value="mesure"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="mesure"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="unit"/>
            <source>
              <context value="src"/>
              <element value="unite"/>
              <variable value="unit"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="unit"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="unit"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="src"/>
              <element value="unite"/>
              <variable value="unit"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="unit"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="system"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="qty"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://unitsofmeasure.org"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformTobaccoObservation"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    LIFESTYLE TRANSFORMATION - SEPARATE OBSERVATIONS
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtObs"/>
          <type value="Observation"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="lifestyleidentifier"/>
          <source>
            <context value="src"/>
            <element value="styleVieId"/>
            <variable value="lsId"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="lifestyleidsystem"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/lifestyle-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="lifestyleidvalue"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="%lsId &amp; '-tobacco'"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestylestatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="lifestylecategory"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorycoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="categorysystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorycode"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="social-history"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorydisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Social History"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="tobaccocode"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="code"/>
          </target>
          <rule>
            <name value="tobaccocoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="codesystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codevalue"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="72166-2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codedisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Tobacco smoking status"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="lifestylesubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestyleeffective"/>
          <source>
            <context value="src"/>
            <element value="dateRecueil"/>
            <variable value="collectDate"/>
            <condition value="%collectDate.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="collectDate"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="tobaccovalue"/>
          <source>
            <context value="src"/>
            <element value="consommationTabac"/>
            <variable value="tobacco"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="value"/>
            <variable value="valueCC"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CodeableConcept"/>
            </parameter>
          </target>
          <rule>
            <name value="tobaccovaluetext"/>
            <source>
              <context value="tobacco"/>
            </source>
            <target>
              <context value="valueCC"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="tobacco"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformAlcoholObservation"/>
        <typeMode value="none"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtObs"/>
          <type value="Observation"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="lifestyleidentifier"/>
          <source>
            <context value="src"/>
            <element value="styleVieId"/>
            <variable value="lsId"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="lifestyleidsystem"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/lifestyle-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="lifestyleidvalue"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="%lsId &amp; '-alcohol'"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestylestatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="lifestylecategory"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorycoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="categorysystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorycode"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="social-history"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorydisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Social History"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="alcoholcode"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="code"/>
          </target>
          <rule>
            <name value="alcoholcoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="codesystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codevalue"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="11331-6"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codedisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="History of alcohol use"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="lifestylesubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestyleeffective"/>
          <source>
            <context value="src"/>
            <element value="dateRecueil"/>
            <variable value="collectDate"/>
            <condition value="%collectDate.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="collectDate"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="alcoholvalue"/>
          <source>
            <context value="src"/>
            <element value="consommationAlcool"/>
            <variable value="alcohol"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="value"/>
            <variable value="valueCC"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CodeableConcept"/>
            </parameter>
          </target>
          <rule>
            <name value="alcoholvaluetext"/>
            <source>
              <context value="alcohol"/>
            </source>
            <target>
              <context value="valueCC"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="alcohol"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformDrugObservation"/>
        <typeMode value="none"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtObs"/>
          <type value="Observation"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="lifestyleidentifier"/>
          <source>
            <context value="src"/>
            <element value="styleVieId"/>
            <variable value="lsId"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="lifestyleidsystem"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/lifestyle-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="lifestyleidvalue"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="%lsId &amp; '-drugs'"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestylestatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="lifestylecategory"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorycoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="categorysystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorycode"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="social-history"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorydisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Social History"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="drugcode"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="code"/>
          </target>
          <rule>
            <name value="drugcoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="codesystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codevalue"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="11342-3"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codedisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="History of drug use"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="lifestylesubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestyleeffective"/>
          <source>
            <context value="src"/>
            <element value="dateRecueil"/>
            <variable value="collectDate"/>
            <condition value="%collectDate.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="collectDate"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="drugvalue"/>
          <source>
            <context value="src"/>
            <element value="consommationAutresDrogues"/>
            <variable value="drugs"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="value"/>
            <variable value="valueCC"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CodeableConcept"/>
            </parameter>
          </target>
          <rule>
            <name value="drugvaluetext"/>
            <source>
              <context value="drugs"/>
            </source>
            <target>
              <context value="valueCC"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="drugs"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformPhysicalActivityObservation"/>
        <typeMode value="none"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtObs"/>
          <type value="Observation"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="lifestyleidentifier"/>
          <source>
            <context value="src"/>
            <element value="styleVieId"/>
            <variable value="lsId"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="lifestyleidsystem"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/lifestyle-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="lifestyleidvalue"/>
            <source>
              <context value="lsId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="%lsId &amp; '-physical'"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestylestatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="final"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="lifestylecategory"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="category"/>
            <variable value="category"/>
          </target>
          <rule>
            <name value="categorycoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="category"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="categorysystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorycode"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="social-history"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="categorydisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Social History"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="physicalcode"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="code"/>
            <variable value="code"/>
          </target>
          <rule>
            <name value="physicalcoding"/>
            <source>
              <context value="src"/>
            </source>
            <target>
              <context value="code"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="codesystem"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codevalue"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="67504-6"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codedisplay"/>
              <source>
                <context value="src"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Exercise activity"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="lifestylesubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lifestyleeffective"/>
          <source>
            <context value="src"/>
            <element value="dateRecueil"/>
            <variable value="collectDate"/>
            <condition value="%collectDate.exists()"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <transform value="cast"/>
            <parameter>
              <valueId value="collectDate"/>
            </parameter>
            <parameter>
              <valueString value="dateTime"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="physicalvalue"/>
          <source>
            <context value="src"/>
            <element value="activitePhysique"/>
            <variable value="physical"/>
          </source>
          <target>
            <context value="tgtObs"/>
            <contextType value="variable"/>
            <element value="value"/>
            <variable value="valueCC"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CodeableConcept"/>
            </parameter>
          </target>
          <rule>
            <name value="physicalvaluetext"/>
            <source>
              <context value="physical"/>
            </source>
            <target>
              <context value="valueCC"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="physical"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformMedicationAdministrationWOOrder"/>
        <typeMode value="none"/>
        <documentation
                       value="========================================================================
    MEDICATION ADMINISTRATION TRANSFORMATION
    ========================================================================"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtMedAdmin"/>
          <type value="MedicationAdministration"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="setId"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="id"/>
            <transform value="uuid"/>
          </target>
        </rule>
        <rule>
          <name value="adminidentifier"/>
          <source>
            <context value="src"/>
            <element value="administrationId"/>
            <variable value="adminId"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="identifier"/>
            <variable value="identifier"/>
          </target>
          <rule>
            <name value="adminidsystem"/>
            <source>
              <context value="adminId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://hospital.eu/ehr/administration-id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="adminidvalue"/>
            <source>
              <context value="adminId"/>
            </source>
            <target>
              <context value="identifier"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="adminId"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="adminstatus"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="completed"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="adminsubject"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="subject"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="subjectref"/>
            <source>
              <context value="patient"/>
              <element value="id"/>
              <variable value="patientId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'Patient/' + %patientId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Patient"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="adminmedication"/>
          <source>
            <context value="src"/>
            <element value="denomination"/>
            <variable value="denomination"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="medication"/>
            <variable value="medication"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CodeableConcept"/>
            </parameter>
          </target>
          <rule>
            <name value="medicationtext"/>
            <source>
              <context value="denomination"/>
            </source>
            <target>
              <context value="medication"/>
              <contextType value="variable"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="denomination"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="atccoding"/>
            <source>
              <context value="src"/>
              <element value="codeAtc"/>
              <variable value="atc"/>
            </source>
            <target>
              <context value="medication"/>
              <contextType value="variable"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="atcsystem"/>
              <source>
                <context value="atc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://www.whocc.no/atc"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="atccode"/>
              <source>
                <context value="atc"/>
              </source>
              <target>
                <context value="coding"/>
                <contextType value="variable"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="atc"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="admineffective"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.dateHeureDebut.exists() or src.dateHeureFin.exists()"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="effective"/>
            <variable value="period"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Period"/>
            </parameter>
          </target>
          <rule>
            <name value="periodstart"/>
            <source>
              <context value="src"/>
              <element value="dateHeureDebut"/>
              <variable value="startDate"/>
            </source>
            <target>
              <context value="period"/>
              <contextType value="variable"/>
              <element value="start"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="startDate"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="periodend"/>
            <source>
              <context value="src"/>
              <element value="dateHeureFin"/>
              <variable value="endDate"/>
            </source>
            <target>
              <context value="period"/>
              <contextType value="variable"/>
              <element value="end"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="endDate"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="admindosage"/>
          <source>
            <context value="src"/>
            <condition
                       value="src.quantite.exists() or src.voieAdministration.exists()"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="dosage"/>
            <variable value="dosage"/>
          </target>
          <rule>
            <name value="admindose"/>
            <source>
              <context value="src"/>
              <element value="quantite"/>
              <variable value="quantity"/>
            </source>
            <target>
              <context value="dosage"/>
              <contextType value="variable"/>
              <element value="dose"/>
              <variable value="dose"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Quantity"/>
              </parameter>
            </target>
            <rule>
              <name value="dosevalue"/>
              <source>
                <context value="quantity"/>
              </source>
              <target>
                <context value="dose"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="quantity"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="doseunit"/>
              <source>
                <context value="src"/>
                <element value="uniteQuantite"/>
                <variable value="unit"/>
              </source>
              <target>
                <context value="dose"/>
                <contextType value="variable"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="unit"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="dosageroute"/>
            <source>
              <context value="src"/>
              <element value="voieAdministration"/>
              <variable value="route"/>
            </source>
            <target>
              <context value="dosage"/>
              <contextType value="variable"/>
              <element value="route"/>
              <variable value="routeCC"/>
            </target>
            <rule>
              <name value="routecoding"/>
              <source>
                <context value="route"/>
              </source>
              <target>
                <context value="routeCC"/>
                <contextType value="variable"/>
                <element value="coding"/>
                <variable value="routeCoding"/>
              </target>
              <rule>
                <name value="routecode"/>
                <source>
                  <context value="route"/>
                </source>
                <target>
                  <context value="routeCoding"/>
                  <contextType value="variable"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="route"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="routesystem"/>
                <source>
                  <context value="route"/>
                </source>
                <target>
                  <context value="routeCoding"/>
                  <contextType value="variable"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString
                                 value="https://smt.esante.gouv.fr/terminologie-standardterms"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
      </group>
      <group>
        <name value="TransformMedicationAdministrationWOrder"/>
        <extends value="TransformMedicationAdministrationWOOrder"/>
        <typeMode value="none"/>
        <input>
          <name value="src"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtMedAdmin"/>
          <type value="MedicationAdministration"/>
          <mode value="target"/>
        </input>
        <input>
          <name value="patient"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="order"/>
          <mode value="source"/>
        </input>
        <rule>
          <name value="admincontext"/>
          <source>
            <context value="src"/>
          </source>
          <target>
            <context value="tgtMedAdmin"/>
            <contextType value="variable"/>
            <element value="request"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="encounterref"/>
            <source>
              <context value="order"/>
              <element value="id"/>
              <variable value="orderId"/>
            </source>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="reference"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="'MedicationRequest/' + %orderId"/>
              </parameter>
            </target>
            <target>
              <context value="ref"/>
              <contextType value="variable"/>
              <element value="type"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="MedicationRequest"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
      <group>
        <name value="setEntryRequestAndFullUrl"/>
        <typeMode value="none"/>
        <input>
          <name value="newRes"/>
          <mode value="source"/>
        </input>
        <input>
          <name value="tgtEntry"/>
          <mode value="target"/>
        </input>
        <rule>
          <name value="setResourceType"/>
          <source>
            <context value="newRes"/>
            <element value="id"/>
            <variable value="newResId"/>
          </source>
          <rule>
            <name value="setFullUrl"/>
            <source>
              <context value="newResId"/>
            </source>
            <target>
              <context value="tgtEntry"/>
              <contextType value="variable"/>
              <element value="fullUrl"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString
                             value="'urn:ehr:' + %newRes.type().name + '/' + %newResId"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </group>
    </StructureMap>