# Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container - Data Management with FHIR v0.1.0

* [**Table of Contents**](toc.md)
* [**Artifacts Summary**](artifacts.md)
* **Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container**

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

| | |
| :--- | :--- |
| *Official URL*:https://interop.aphp.fr/ig/fhir/dm/StructureMap/EHR2FSL | *Version*:0.1.0 |
| Draft as of 2025-10-23 | *Computable Name*:EHR2FSL |

 
Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container 

```

map "https://interop.aphp.fr/ig/fhir/dm/StructureMap/EHR2FSL" = "EHR2FSL"

// Transforms EHR logical model data to FHIR Semantic Layer resources using Bundle as container

uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/ehr" alias EHR as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target

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

// ---------------------------------------------------------
// PATIENT TRANSFORMATION
// ---------------------------------------------------------
group TransformPatient(source src, target tgt : Patient) {
  src -> tgt.id = uuid() "setId";
  // src.patientId as id -> tgt.id = id "patient-id";
  // Identifiers
  src.patientId as pid -> tgt.identifier as identifier then {
    pid -> identifier.use = 'usual' "iduse";
    pid -> identifier.type = cc('http://terminology.hl7.org/CodeSystem/v2-0203', 'PI', 'Patient Identifier') "idtype";
    pid -> identifier.system = 'https://hospital.eu/ehr/patient-id' "idsystem";
    pid -> identifier.value = pid "idvalue";
  } "patientidentifier";
  // NIR identifier <- 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.
  // src.nir as nir where nir.exists() -> tgt.identifier as insIdentifier then {     nir -> insIdentifier.use = 'official' "ins-use";     nir -> insIdentifier.type = cc('http://hl7.fr/fhir/CodeSystem/fr-v2-0203', 'INS-NIR') "ins-type";     nir -> insIdentifier.system = 'urn:oid:1.2.250.1.213.1.4.8' "ins-system";     nir -> insIdentifier.value = nir "ins-value";   } "ins-identifier";
  // Alternative INS from ins field
  src.ins as ins where ins.exists() -> tgt.identifier as insIdentifier then {
    ins -> insIdentifier.use = 'official' "insuse"; // On part du principe qu'on n'est pas sur un old.
    ins -> insIdentifier.type = cc('https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-v2-0203', 'INS-NIR', 'NIR définitif') "instype";
    ins -> insIdentifier.system = 'urn:oid:1.2.250.1.213.1.4.8' "inssystem";
    ins -> insIdentifier.value = ins "insvalue";
  } "insidentifier";
  // Name
  src where src.nom.exists() or src.prenom.exists() -> tgt.name as name then {
    src.nom as lastName -> name.family = lastName "familyname";
    src.prenom as firstName -> name.given = firstName "givenname";
    src -> name.use = 'official' "nameuse"; // hypothèse un peu forte.
  } "patientname";
  // Demographics On aurait pu faire plus élégant avec un ConceptMap
  src.dateNaissance as birthDate -> tgt.birthDate = birthDate "birthdate";
  src.sexe as gender where gender = 'h' -> tgt.gender = 'male' "gendermale";
  src.sexe as gender where gender = 'f' -> tgt.gender = 'female' "genderfemale";
  src.sexe as gender where gender.exists() and (gender != 'h') and (gender != 'f') -> tgt.gender = 'unknown' "genderunknown"; // n'a pas grand sens en l'état des contraintes SQL
  // Death information
  src.dateDeces as deathDate where deathDate.exists() -> tgt.deceased = cast(deathDate, 'dateTime') as deceasedDate then {
    src.sourceDeces as deathSource where deathSource.exists() -> deceasedDate.extension as DeathSourceExtension then {
      deathSource -> DeathSourceExtension.url = 'https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/DeathSource' "deathSourceUrl";
      deathSource -> DeathSourceExtension.value = cast(deathSource, 'code') "deathSourceValue";
    } "deathSource";
  } "deathDate";
  // Multiple birth
  src.rangGemellaire as twin where twin.exists() -> tgt.multipleBirth = twin "multiplebirth";
}

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

// ========================================================================
// ENCOUNTER TRANSFORMATION
// ========================================================================
group TransformEncounter(source src, target tgtEnc : Encounter, source patient) {
  src -> tgtEnc.id = uuid() "setId";
  // src.pmsiId as id -> tgt.id = id "encounter-id";
  // Identifier
  src -> tgtEnc.identifier as identifier then {
    src -> identifier.type = cc('https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-identifier-type', 'VN', 'Visit Number') "idtype";
    src -> identifier.system = 'https://hospital.eu/ehr/pmsi-id' "encounteridsystem";
    src.pmsiId as srcEncoutnerId -> identifier.value = srcEncoutnerId "encounteridvalue";
  } "encounteridentifier";
  // Status - default to finished for historical data
  src -> tgtEnc.status = 'finished' "encounterstatus";
  // Class - assume inpatient for PMSI data
  src -> tgtEnc.class = c('http://terminology.hl7.org/CodeSystem/v3-ActCode', 'IMP', 'inpatient encounter') "encounterclass";
  // Reference patient
  src -> tgtEnc.subject = create('Reference') as ref then {
    patient.id as patientId ->  ref.reference = ('Patient/' + %patientId),  ref.type = 'Patient' "subjectreference";
  } "encountersubject";
  // Period
  src where src.dateDebutSejour.exists() or src.dateFinSejour.exists() -> tgtEnc.period as period then {
    src.dateDebutSejour as startDate -> period.start = startDate "periodstart";
    src.dateFinSejour as endDate -> period.end = endDate "periodend";
  } "encounterperiod";
  // Désactivé dans le modèle physique   // Duration   src.dureeSejour as duration -> tgtEnc.length as length then {     duration -> length.value = duration "length-value";     duration -> length.unit = 'd' "length-unit";     duration -> length.system = 'http://unitsofmeasure.org' "length-system";     duration -> length.code = 'd' "length-code";   } "encounter-length";
  // Hospitalization
  src where src.modeEntree.exists() or src.modeSortie.exists() -> tgtEnc.hospitalization as hosp then {
    src.modeEntree as admitSource -> hosp.admitSource as admitSrc then {
      admitSource -> admitSrc.text = admitSource "admitsourcetext";
    } "admitsource";
    src.modeSortie as dischargeDisp -> hosp.dischargeDisposition as dischargeDsp then {
      dischargeDisp -> dischargeDsp.text = dischargeDisp "dischargedisptext";
    } "dischargedisposition";
  } "encounterhospitalization";
  // Service Provider
  src where src.uniteFonctionnelle.exists() or src.service.exists() or src.etablissement.exists() -> tgtEnc.serviceProvider as provider then {
    src -> provider.display = (iif(%src.uniteFonctionnelle.exists(), %src.uniteFonctionnelle, iif(%src.service.exists(), %src.service, %src.etablissement))) "providerdisplay";
  } "provider";
// // 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 -> tgt.location as location then {     service -> location.location as loc then {       service -> loc.display = service "location-display";     } "location-ref";   } "encounter-location";
}

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

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

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

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

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

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

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

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

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

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

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

group TransformMedicationAdministrationWOrder(source src, target tgtMedAdmin : MedicationAdministration, source patient, source order) extends TransformMedicationAdministrationWOOrder {
  // Context (encounter) reference
  src -> tgtMedAdmin.request = create('Reference') as ref then {
    order.id as orderId ->  ref.reference = ('MedicationRequest/' + %orderId),  ref.type = 'MedicationRequest' "encounterref";
  } "admincontext";
}

group setEntryRequestAndFullUrl(source newRes, target tgtEntry) {
  newRes.id as newResId then {
    newResId -> tgtEntry.fullUrl = ('urn:ehr:' + %newRes.type().name + '/' + %newResId) "setFullUrl";
  } "setResourceType";
}


```



## Resource Content

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

```
