# Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR - Data Management with FHIR v0.1.0

* [**Table of Contents**](toc.md)
* [**Artifacts Summary**](artifacts.md)
* **Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR**

## StructureMap: Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR 

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

 
Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR 

```

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

// Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR

uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreDataSet" alias DataSet as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CorePatient" alias PatientTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreSejour" alias SejourTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreBiology" alias BiologyTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreClinical" alias ClinicalTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreDiag" alias DiagTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreActe" alias ActeTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreAddress" alias AddressTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreMedicationAdm" alias MedicationAdmTable as source
uses "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreMedicationPre" alias MedicationPreTable as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias FHIRBundle as target
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias FHIRPatient as target
uses "http://hl7.org/fhir/StructureDefinition/Encounter" alias FHIREncounter as target
uses "http://hl7.org/fhir/StructureDefinition/Observation" alias FHIRObservation as target
uses "http://hl7.org/fhir/StructureDefinition/Meta" alias FHIRMeta as target
uses "http://hl7.org/fhir/StructureDefinition/Procedure" alias FHIRProcedure as target
uses "http://hl7.org/fhir/StructureDefinition/Condition" alias FHIRCondition as target

group dataSet(source srcDataSet : DataSet, target tgtBundle : FHIRBundle) <<types>> {
  srcDataSet -> tgtBundle.id = uuid() "setId";
  srcDataSet -> tgtBundle.type = 'transaction' "setType";
  srcDataSet.patient as srcPatient ->  tgtBundle.entry as tgtPatientEntry,  tgtPatientEntry.resource = create('Patient') as newPatient then {
    srcPatient then patient(srcPatient, newPatient) "setPatient";
    srcPatient then setEntryRequestAndFullUrl(newPatient, tgtPatientEntry) "setRequestAndFullUrl";
    srcDataSet.address as srcAddress where patientNi.reference = ('PatientCore/' + %srcPatient.patientNi.toString()) then patientAddress(srcAddress, newPatient) "addPatientAddress";
    srcDataSet.sejour as srcSejour where patientNi.reference = ('PatientCore/' + %srcPatient.patientNi.toString()) ->  tgtBundle.entry as tgtEncounterEntry,  tgtEncounterEntry.resource = create('Encounter') as newEncounter then {
      srcSejour then encounter(srcSejour, newPatient, newEncounter) "setEncounter";
      srcSejour then setEntryRequestAndFullUrl(newEncounter, tgtEncounterEntry) "setRequestAndFullUrl";
      srcDataSet.acte as srcActe where sejourNi.reference = ('SejourCore/' + %srcSejour.sejourNi.toString()) ->  tgtBundle.entry as tgtProcedureEntry,  tgtProcedureEntry.resource = create('Procedure') as newProcedure then {
        srcActe then procedure(srcActe, newPatient, newEncounter, newProcedure) "setProcedure";
        srcActe then setEntryRequestAndFullUrl(newProcedure, tgtProcedureEntry) "setRequestAndFullUrl";
      } "createProcedure";
      srcDataSet.diag as srcDiag where sejourNi.reference = ('SejourCore/' + %srcSejour.sejourNi.toString()) ->  tgtBundle.entry as tgtConditionEntry,  tgtConditionEntry.resource = create('Condition') as newCondition then {
        srcDiag then condition(srcDiag, newPatient, newEncounter, newCondition) "setCondition";
        srcDiag then setEntryRequestAndFullUrl(newCondition, tgtConditionEntry) "setRequestAndFullUrl";
      } "createProcedure";
      srcDataSet.biology as srcBiology where sejourNi.reference = ('SejourCore/' + %srcSejour.sejourNi.toString()) ->  tgtBundle.entry as tgtBiologyEntry,  tgtBiologyEntry.resource = create('Observation') as newObservation then {
        srcBiology then observationBiol(srcBiology, newPatient, newEncounter, newObservation) "setBiology";
        srcBiology then setEntryRequestAndFullUrl(newObservation, tgtBiologyEntry) "setRequestAndFullUrl";
      } "createObservation";
    } "createEncounter";
  } "createPatient";
}

group patient(source srcPatient : PatientTable, target tgtPatient : FHIRPatient) {
  srcPatient -> tgtPatient.id = uuid() "setId";
  srcPatient.patientNi as srcNi -> tgtPatient.meta as tgtMeta then setPatientMeta(srcNi, tgtMeta) "setMeta"; // copie la valeur du champ patientNi de la table Patient dans l'élément id de la ressource FHIR Patient
  srcPatient -> tgtPatient.name as tgtPatientName then setHumainName(srcPatient, tgtPatientName) "setHumainName";
  srcPatient -> tgtPatient.identifier as tgtPatientIdentifier then setHumainNir(srcPatient, tgtPatientIdentifier) "setHumainNir";
  srcPatient.gender as srcPatientGender -> tgtPatient.gender = translate(srcPatientGender, 'https://interop.aphp.fr/ig/fhir/dm/ConceptMap/DpiGender2Hl7Gender', 'code') "setGender"; // traduit la valeur du champ gender de la table Patient dans l'élément gender de la ressource FHIR Patient
  srcPatient.birthDate as srcPatientBirthDate -> tgtPatient.birthDate = srcPatientBirthDate "setBirthDate"; // copie la valeur du champ birthDate de la table Patient dans l'élément birthDate de la ressource FHIR Patient
}

group setPatientMeta(source srcNi, target tgtMeta : FHIRMeta) {
  srcNi -> tgtMeta.source = ('https://aphp.fr/fhir/Endpoint/dpi/PatientTable' + '/' + %srcNi.toString()) "setSource";
}

group setHumainName(source srcPatient : PatientTable, target tgtPatientName) {
  srcPatient -> tgtPatientName.use = 'usual' "setUse";
  // srcPatient -> tgtPatientName.text = (%srcPatient.firstName + ' ' + %srcPatient.name) "setText";
  // srcPatient.name as srcPatientName -> tgtPatientName.family = srcPatientName "setName";
  // srcPatient.firstName as srcPatientFirstName -> tgtPatientName.given = srcPatientFirstName "setFirstName";
  // les trois lignes précédentes marchent dans matchbox mais génèrent une erreur au QA. La solution ci dessous marche dans matchbox et ne génère pas d'erreur au QA.
  srcPatient.name as srcPatientName -> tgtPatientName.family = srcPatientName then {
    srcPatient.firstName as srcPatientFirstName ->  tgtPatientName.given = srcPatientFirstName,  tgtPatientName.text = (%srcPatientFirstName + ' ' + %srcPatientName) "setFirstNameAndText";
  } "setName";
}

group setHumainNir(source srcPatient : PatientTable, target tgtPatientIdentifier) {
  srcPatient.nir as srcPatientNir ->  tgtPatientIdentifier.use = 'official',  tgtPatientIdentifier.type = cc('https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-v2-0203', 'INS-NIR'),  tgtPatientIdentifier.system = 'urn:oid:1.2.250.1.213.1.4.8',  tgtPatientIdentifier.value = srcPatientNir "setNir";
}

group patientAddress(source srcAddress : AddressTable, target tgtPatient : FHIRPatient) {
  srcAddress -> tgtPatient.address = create('Address') as newAddress then {
    srcAddress.zipCode as srczip -> newAddress.postalCode = srczip "setZip";
    srcAddress.city as srcCity -> newAddress.city = srcCity "setCity";
    srcAddress.country as srcCountry -> newAddress.country = srcCountry "setCountry";
    srcAddress.address as srcAddressText -> newAddress.text = srcAddressText "setText";
    srcAddress where current = true -> newAddress.use = 'home' "setUseHome";
    srcAddress where current = false -> newAddress.use = 'old' "setUseOld";
    srcAddress where latitude.exists() or longitude.exists() -> newAddress.extension = create('Extension') as firstLevelExtension then {
      srcAddress -> firstLevelExtension.url = ('http://hl7.org/fhir/StructureDefinition/geolocation') then {
        srcAddress.latitude as srcLat -> firstLevelExtension.extension = create('Extension') as latExtension then {
          srcLat ->  latExtension.url = ('latitude'),  latExtension.value = srcLat "setLat";
        } "setLatExt";
        srcAddress.longitude as srcLong -> firstLevelExtension.extension = create('Extension') as longExtension then {
          srcLong ->  longExtension.url = ('longitude'),  longExtension.value = srcLong "setLong";
        } "setLongExt";
      } "setflext";
    } "setCoordinatesExtension";
  } "setAddress";
}

group encounter(source srcSejour : SejourTable, source srcPatient : FHIRPatient, target tgtEncounter : FHIREncounter) {
  srcSejour -> tgtEncounter.id = uuid() "setId";
  srcSejour.sejourNi as srcNi -> tgtEncounter.meta as tgtMeta then setEncounterMeta(srcNi, tgtMeta) "setMeta"; // copie la valeur du champ patientNi de la table Patient dans l'élément id de la ressource FHIR Patient
  srcSejour -> tgtEncounter.status = 'finished' "setStatus";
  srcSejour.sejourType as srcSejourType -> tgtEncounter.class = translate(srcSejourType, 'https://interop.aphp.fr/ig/fhir/dm/ConceptMap/DpiEncounterType2SemanticLayerEncounterClass', 'Coding') "setEncounterClass";
  srcPatient.id as patientId -> tgtEncounter.subject = create('Reference') as newSubject then setSubjectReference(patientId, newSubject) "setSubjectReference";
  srcSejour.patientNi; // fk vers le patient à conserver pour la construction auto du périmètre final
  srcSejour -> tgtEncounter.period = create('Period') as newActualPeriod then {
    srcSejour.sejourStart as srcPeriodStart -> newActualPeriod.start = srcPeriodStart "setStart";
    srcSejour.sejourEnd as srcPeriodEnd -> newActualPeriod.end = srcPeriodEnd "setEnd";
  } "setPeriod";
}

group setEncounterMeta(source srcNi, target tgtMeta : FHIRMeta) {
  srcNi -> tgtMeta.source = ('https://aphp.fr/fhir/Endpoint/dpi/SejourTable' + '/' + %srcNi.toString()) "setSource";
}

group setSubjectReference(source srcPatientId, target newSubject) {
  srcPatientId -> newSubject.reference = ('Patient/' + %srcPatientId.toString()) "setReference";
}

group procedure(source srcActe : ActeTable, source srcPatient : FHIRPatient, source srcEncounter : FHIREncounter, target tgtProcedure : FHIRProcedure) {
  srcActe -> tgtProcedure.id = uuid() "setId";
  srcActe.acteNi as srcNi -> tgtProcedure.meta as tgtMeta then setProcedureMeta(srcNi, tgtMeta) "setMeta";
  srcPatient.id as patientId -> tgtProcedure.subject = create('Reference') as newSubject then setSubjectReference(patientId, newSubject) "setSubjectReference";
  srcEncounter.id as encounterId -> tgtProcedure.encounter = create('Reference') as newEncounter then setEncounterReference(encounterId, newEncounter) "setEncounterReference";
  srcActe -> tgtProcedure.status = 'completed' "setStatus";
  srcActe where dateStart.exists() or dateEnd.exists -> tgtProcedure.performed = create('Period') as tgtProcedurePeriod then {
    srcActe.dateStart as srcActeStart -> tgtProcedurePeriod.start = srcActeStart "setActeStart";
    srcActe.dateEnd as srcActeEnd -> tgtProcedurePeriod.end = srcActeEnd "setActeEnd";
  } "setDate";
  srcActe.code as acteCode -> tgtProcedure.code = cc('https://smt.esante.gouv.fr/terminologie-ccam', acteCode) "setCode"; // C'est le code de la CCAM facturante
}

group setProcedureMeta(source srcNi, target tgtMeta : FHIRMeta) {
  srcNi -> tgtMeta.source = ('https://aphp.fr/fhir/Endpoint/dpi/ActeTable' + '/' + %srcNi.toString()) "setSource";
}

group setEncounterReference(source srcEncounterId, target newEncounter) {
  srcEncounterId -> newEncounter.reference = ('Encounter/' + %srcEncounterId.toString()) "setReference";
}

group condition(source srcDiag : DiagTable, source srcPatient : FHIRPatient, source srcEncounter : FHIREncounter, target tgtCondition : FHIRCondition) {
  srcDiag -> tgtCondition.id = uuid() "setId";
  srcDiag.diagNi as srcNi -> tgtCondition.meta as tgtMeta then setConditionMeta(srcNi, tgtMeta) "setMeta";
  srcPatient.id as patientId -> tgtCondition.subject = create('Reference') as newSubject then setSubjectReference(patientId, newSubject) "setSubjectReference";
  srcEncounter.id as encounterId -> tgtCondition.encounter = create('Reference') as newEncounter then setEncounterReference(encounterId, newEncounter) "setEncounterReference";
  srcDiag -> tgtCondition.verificationStatus = 'confirmed' "setVerificationStatus";
  srcDiag -> tgtCondition.category = cc('http://terminology.hl7.org/CodeSystem/condition-category', 'encounter-diagnosis') "setCategory";
  srcDiag.code as diagCode -> tgtCondition.code = cc('http://hl7.org/fhir/sid/icd-10', diagCode) "setCode";
}

group setConditionMeta(source srcNi, target tgtMeta : FHIRMeta) {
  srcNi -> tgtMeta.source = ('https://aphp.fr/fhir/Endpoint/dpi/DiagTable' + '/' + %srcNi.toString()) "setSource";
}

group observationBiol(source srcBiology : BiologyTable, source srcPatient : FHIRPatient, source srcEncounter : FHIREncounter, target tgtObservation : FHIRObservation) {
  srcBiology -> tgtObservation.id = uuid() "setId";
  srcBiology.biologyNi as srcNi -> tgtObservation.meta as tgtMeta then setBiologyMeta(srcNi, tgtMeta) "setMeta";
  srcPatient.id as patientId -> tgtObservation.subject = create('Reference') as newSubject then setSubjectReference(patientId, newSubject) "setSubjectReference";
  srcEncounter.id as encounterId -> tgtObservation.encounter = create('Reference') as newEncounter then setEncounterReference(encounterId, newEncounter) "setEncounterReference";
  srcBiology -> tgtObservation.status = 'final' "setStatus";
  srcBiology -> tgtObservation.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'vital-signs') "setCategory";
  srcBiology.biologyDatePrel as biologyDatePrel -> tgtObservation.effective = biologyDatePrel "setDate";
  srcBiology.biologyCode as biologyCode -> tgtObservation.code = cc('http://loinc.org', biologyCode) "setCode";
  srcBiology.biologyValue -> tgtObservation.value = create('Quantity') as tgtObsQuantity then {
    srcBiology.biologyValue as biologyValue -> tgtObsQuantity.value = biologyValue "setValue";
    srcBiology.biologyUnit as biologyUnit ->  tgtObsQuantity.code = biologyUnit,  tgtObsQuantity.unit = biologyUnit,  tgtObsQuantity.system = 'http://unitsofmeasure.org' "setUnit";
  } "setQuantity";
}

group setBiologyMeta(source srcNi, target tgtMeta : FHIRMeta) {
  srcNi -> tgtMeta.source = ('https://aphp.fr/fhir/Endpoint/dpi/BiologyTable' + '/' + %srcNi.toString()) "setSource";
}

group setEntryRequestAndFullUrl(source newRes, target tgtEntry) {
  newRes.id as newResId then {
    newResId -> tgtEntry.fullUrl = ('https://aphp.fr/' + %newRes.type().name + '/' + %newResId) "setFullUrl";
    newResId ->  tgtEntry.request as tgtEntryRequest,  tgtEntryRequest.method = 'POST',  tgtEntryRequest.url = (%newRes.type().name + '/' + %newResId) "setRequest";
  } "setResourceType";
}


```



## Resource Content

```json
{
  "resourceType" : "StructureMap",
  "id" : "CorePhysical2FHIR",
  "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureMap/CorePhysical2FHIR",
  "version" : "0.1.0",
  "name" : "CorePhysical2FHIR",
  "title" : "Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR",
  "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" : "Alignement de l''usage Core du modèle physique du DPI vers les ressources FHIR",
  "jurisdiction" : [
    {
      "coding" : [
        {
          "system" : "urn:iso:std:iso:3166",
          "code" : "FR",
          "display" : "France"
        }
      ]
    }
  ],
  "structure" : [
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreDataSet",
      "mode" : "source",
      "alias" : "DataSet"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CorePatient",
      "mode" : "source",
      "alias" : "PatientTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreSejour",
      "mode" : "source",
      "alias" : "SejourTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreBiology",
      "mode" : "source",
      "alias" : "BiologyTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreClinical",
      "mode" : "source",
      "alias" : "ClinicalTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreDiag",
      "mode" : "source",
      "alias" : "DiagTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreActe",
      "mode" : "source",
      "alias" : "ActeTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreAddress",
      "mode" : "source",
      "alias" : "AddressTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreMedicationAdm",
      "mode" : "source",
      "alias" : "MedicationAdmTable"
    },
    {
      "url" : "https://interop.aphp.fr/ig/fhir/dm/StructureDefinition/CoreMedicationPre",
      "mode" : "source",
      "alias" : "MedicationPreTable"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Bundle",
      "mode" : "target",
      "alias" : "FHIRBundle"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Patient",
      "mode" : "target",
      "alias" : "FHIRPatient"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Encounter",
      "mode" : "target",
      "alias" : "FHIREncounter"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Observation",
      "mode" : "target",
      "alias" : "FHIRObservation"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Meta",
      "mode" : "target",
      "alias" : "FHIRMeta"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Procedure",
      "mode" : "target",
      "alias" : "FHIRProcedure"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Condition",
      "mode" : "target",
      "alias" : "FHIRCondition"
    }
  ],
  "group" : [
    {
      "name" : "dataSet",
      "typeMode" : "types",
      "input" : [
        {
          "name" : "srcDataSet",
          "type" : "DataSet",
          "mode" : "source"
        },
        {
          "name" : "tgtBundle",
          "type" : "FHIRBundle",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setId",
          "source" : [
            {
              "context" : "srcDataSet"
            }
          ],
          "target" : [
            {
              "context" : "tgtBundle",
              "contextType" : "variable",
              "element" : "id",
              "transform" : "uuid"
            }
          ]
        },
        {
          "name" : "setType",
          "source" : [
            {
              "context" : "srcDataSet"
            }
          ],
          "target" : [
            {
              "context" : "tgtBundle",
              "contextType" : "variable",
              "element" : "type",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "transaction"
                }
              ]
            }
          ]
        },
        {
          "name" : "createPatient",
          "source" : [
            {
              "context" : "srcDataSet",
              "element" : "patient",
              "variable" : "srcPatient"
            }
          ],
          "target" : [
            {
              "context" : "tgtBundle",
              "contextType" : "variable",
              "element" : "entry",
              "variable" : "tgtPatientEntry"
            },
            {
              "context" : "tgtPatientEntry",
              "contextType" : "variable",
              "element" : "resource",
              "variable" : "newPatient",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Patient"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "setPatient",
              "source" : [
                {
                  "context" : "srcPatient"
                }
              ],
              "dependent" : [
                {
                  "name" : "patient",
                  "variable" : ["srcPatient", "newPatient"]
                }
              ]
            },
            {
              "name" : "setRequestAndFullUrl",
              "source" : [
                {
                  "context" : "srcPatient"
                }
              ],
              "dependent" : [
                {
                  "name" : "setEntryRequestAndFullUrl",
                  "variable" : ["newPatient", "tgtPatientEntry"]
                }
              ]
            },
            {
              "name" : "addPatientAddress",
              "source" : [
                {
                  "context" : "srcDataSet",
                  "element" : "address",
                  "variable" : "srcAddress",
                  "condition" : "patientNi.reference = ('PatientCore/' + %srcPatient.patientNi.toString())"
                }
              ],
              "dependent" : [
                {
                  "name" : "patientAddress",
                  "variable" : ["srcAddress", "newPatient"]
                }
              ]
            },
            {
              "name" : "createEncounter",
              "source" : [
                {
                  "context" : "srcDataSet",
                  "element" : "sejour",
                  "variable" : "srcSejour",
                  "condition" : "patientNi.reference = ('PatientCore/' + %srcPatient.patientNi.toString())"
                }
              ],
              "target" : [
                {
                  "context" : "tgtBundle",
                  "contextType" : "variable",
                  "element" : "entry",
                  "variable" : "tgtEncounterEntry"
                },
                {
                  "context" : "tgtEncounterEntry",
                  "contextType" : "variable",
                  "element" : "resource",
                  "variable" : "newEncounter",
                  "transform" : "create",
                  "parameter" : [
                    {
                      "valueString" : "Encounter"
                    }
                  ]
                }
              ],
              "rule" : [
                {
                  "name" : "setEncounter",
                  "source" : [
                    {
                      "context" : "srcSejour"
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "encounter",
                      "variable" : ["srcSejour", "newPatient", "newEncounter"]
                    }
                  ]
                },
                {
                  "name" : "setRequestAndFullUrl",
                  "source" : [
                    {
                      "context" : "srcSejour"
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "setEntryRequestAndFullUrl",
                      "variable" : ["newEncounter", "tgtEncounterEntry"]
                    }
                  ]
                },
                {
                  "name" : "createProcedure",
                  "source" : [
                    {
                      "context" : "srcDataSet",
                      "element" : "acte",
                      "variable" : "srcActe",
                      "condition" : "sejourNi.reference = ('SejourCore/' + %srcSejour.sejourNi.toString())"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "tgtBundle",
                      "contextType" : "variable",
                      "element" : "entry",
                      "variable" : "tgtProcedureEntry"
                    },
                    {
                      "context" : "tgtProcedureEntry",
                      "contextType" : "variable",
                      "element" : "resource",
                      "variable" : "newProcedure",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "Procedure"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "setProcedure",
                      "source" : [
                        {
                          "context" : "srcActe"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "procedure",
                          "variable" : ["srcActe", "newPatient", "newEncounter", "newProcedure"]
                        }
                      ]
                    },
                    {
                      "name" : "setRequestAndFullUrl",
                      "source" : [
                        {
                          "context" : "srcActe"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "setEntryRequestAndFullUrl",
                          "variable" : ["newProcedure", "tgtProcedureEntry"]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "createProcedure",
                  "source" : [
                    {
                      "context" : "srcDataSet",
                      "element" : "diag",
                      "variable" : "srcDiag",
                      "condition" : "sejourNi.reference = ('SejourCore/' + %srcSejour.sejourNi.toString())"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "tgtBundle",
                      "contextType" : "variable",
                      "element" : "entry",
                      "variable" : "tgtConditionEntry"
                    },
                    {
                      "context" : "tgtConditionEntry",
                      "contextType" : "variable",
                      "element" : "resource",
                      "variable" : "newCondition",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "Condition"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "setCondition",
                      "source" : [
                        {
                          "context" : "srcDiag"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "condition",
                          "variable" : ["srcDiag", "newPatient", "newEncounter", "newCondition"]
                        }
                      ]
                    },
                    {
                      "name" : "setRequestAndFullUrl",
                      "source" : [
                        {
                          "context" : "srcDiag"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "setEntryRequestAndFullUrl",
                          "variable" : ["newCondition", "tgtConditionEntry"]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "createObservation",
                  "source" : [
                    {
                      "context" : "srcDataSet",
                      "element" : "biology",
                      "variable" : "srcBiology",
                      "condition" : "sejourNi.reference = ('SejourCore/' + %srcSejour.sejourNi.toString())"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "tgtBundle",
                      "contextType" : "variable",
                      "element" : "entry",
                      "variable" : "tgtBiologyEntry"
                    },
                    {
                      "context" : "tgtBiologyEntry",
                      "contextType" : "variable",
                      "element" : "resource",
                      "variable" : "newObservation",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "Observation"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "setBiology",
                      "source" : [
                        {
                          "context" : "srcBiology"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "observationBiol",
                          "variable" : ["srcBiology", "newPatient", "newEncounter", "newObservation"]
                        }
                      ]
                    },
                    {
                      "name" : "setRequestAndFullUrl",
                      "source" : [
                        {
                          "context" : "srcBiology"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "setEntryRequestAndFullUrl",
                          "variable" : ["newObservation", "tgtBiologyEntry"]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "patient",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcPatient",
          "type" : "PatientTable",
          "mode" : "source"
        },
        {
          "name" : "tgtPatient",
          "type" : "FHIRPatient",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setId",
          "source" : [
            {
              "context" : "srcPatient"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "id",
              "transform" : "uuid"
            }
          ]
        },
        {
          "name" : "setMeta",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "patientNi",
              "variable" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "meta",
              "variable" : "tgtMeta"
            }
          ],
          "dependent" : [
            {
              "name" : "setPatientMeta",
              "variable" : ["srcNi", "tgtMeta"]
            }
          ],
          "documentation" : "copie la valeur du champ patientNi de la table Patient dans l'élément id de la ressource FHIR Patient"
        },
        {
          "name" : "setHumainName",
          "source" : [
            {
              "context" : "srcPatient"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "name",
              "variable" : "tgtPatientName"
            }
          ],
          "dependent" : [
            {
              "name" : "setHumainName",
              "variable" : ["srcPatient", "tgtPatientName"]
            }
          ]
        },
        {
          "name" : "setHumainNir",
          "source" : [
            {
              "context" : "srcPatient"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "identifier",
              "variable" : "tgtPatientIdentifier"
            }
          ],
          "dependent" : [
            {
              "name" : "setHumainNir",
              "variable" : ["srcPatient", "tgtPatientIdentifier"]
            }
          ]
        },
        {
          "name" : "setGender",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "gender",
              "variable" : "srcPatientGender"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "gender",
              "transform" : "translate",
              "parameter" : [
                {
                  "valueId" : "srcPatientGender"
                },
                {
                  "valueString" : "https://interop.aphp.fr/ig/fhir/dm/ConceptMap/DpiGender2Hl7Gender"
                },
                {
                  "valueString" : "code"
                }
              ]
            }
          ],
          "documentation" : "traduit la valeur du champ gender de la table Patient dans l'élément gender de la ressource FHIR Patient"
        },
        {
          "name" : "setBirthDate",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "birthDate",
              "variable" : "srcPatientBirthDate"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "birthDate",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueId" : "srcPatientBirthDate"
                }
              ]
            }
          ],
          "documentation" : "copie la valeur du champ birthDate de la table Patient dans l'élément birthDate de la ressource FHIR Patient"
        }
      ]
    },
    {
      "name" : "setPatientMeta",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcNi",
          "mode" : "source"
        },
        {
          "name" : "tgtMeta",
          "type" : "FHIRMeta",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setSource",
          "source" : [
            {
              "context" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtMeta",
              "contextType" : "variable",
              "element" : "source",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'https://aphp.fr/fhir/Endpoint/dpi/PatientTable' + '/' + %srcNi.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setHumainName",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcPatient",
          "type" : "PatientTable",
          "mode" : "source"
        },
        {
          "name" : "tgtPatientName",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setUse",
          "source" : [
            {
              "context" : "srcPatient"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatientName",
              "contextType" : "variable",
              "element" : "use",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "usual"
                }
              ]
            }
          ]
        },
        {
          "name" : "setName",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "name",
              "variable" : "srcPatientName"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatientName",
              "contextType" : "variable",
              "element" : "family",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueId" : "srcPatientName"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "setFirstNameAndText",
              "source" : [
                {
                  "context" : "srcPatient",
                  "element" : "firstName",
                  "variable" : "srcPatientFirstName"
                }
              ],
              "target" : [
                {
                  "context" : "tgtPatientName",
                  "contextType" : "variable",
                  "element" : "given",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcPatientFirstName"
                    }
                  ]
                },
                {
                  "context" : "tgtPatientName",
                  "contextType" : "variable",
                  "element" : "text",
                  "transform" : "evaluate",
                  "parameter" : [
                    {
                      "valueString" : "%srcPatientFirstName + ' ' + %srcPatientName"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setHumainNir",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcPatient",
          "type" : "PatientTable",
          "mode" : "source"
        },
        {
          "name" : "tgtPatientIdentifier",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setNir",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "nir",
              "variable" : "srcPatientNir"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatientIdentifier",
              "contextType" : "variable",
              "element" : "use",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "official"
                }
              ]
            },
            {
              "context" : "tgtPatientIdentifier",
              "contextType" : "variable",
              "element" : "type",
              "transform" : "cc",
              "parameter" : [
                {
                  "valueString" : "https://hl7.fr/ig/fhir/core/CodeSystem/fr-core-cs-v2-0203"
                },
                {
                  "valueString" : "INS-NIR"
                }
              ]
            },
            {
              "context" : "tgtPatientIdentifier",
              "contextType" : "variable",
              "element" : "system",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "urn:oid:1.2.250.1.213.1.4.8"
                }
              ]
            },
            {
              "context" : "tgtPatientIdentifier",
              "contextType" : "variable",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueId" : "srcPatientNir"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "patientAddress",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcAddress",
          "type" : "AddressTable",
          "mode" : "source"
        },
        {
          "name" : "tgtPatient",
          "type" : "FHIRPatient",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setAddress",
          "source" : [
            {
              "context" : "srcAddress"
            }
          ],
          "target" : [
            {
              "context" : "tgtPatient",
              "contextType" : "variable",
              "element" : "address",
              "variable" : "newAddress",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Address"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "setZip",
              "source" : [
                {
                  "context" : "srcAddress",
                  "element" : "zipCode",
                  "variable" : "srczip"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "postalCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srczip"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setCity",
              "source" : [
                {
                  "context" : "srcAddress",
                  "element" : "city",
                  "variable" : "srcCity"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "city",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcCity"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setCountry",
              "source" : [
                {
                  "context" : "srcAddress",
                  "element" : "country",
                  "variable" : "srcCountry"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "country",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcCountry"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setText",
              "source" : [
                {
                  "context" : "srcAddress",
                  "element" : "address",
                  "variable" : "srcAddressText"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "text",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcAddressText"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setUseHome",
              "source" : [
                {
                  "context" : "srcAddress",
                  "condition" : "current = true"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "use",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "home"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setUseOld",
              "source" : [
                {
                  "context" : "srcAddress",
                  "condition" : "current = false"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "use",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "old"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setCoordinatesExtension",
              "source" : [
                {
                  "context" : "srcAddress",
                  "condition" : "latitude.exists() or longitude.exists()"
                }
              ],
              "target" : [
                {
                  "context" : "newAddress",
                  "contextType" : "variable",
                  "element" : "extension",
                  "variable" : "firstLevelExtension",
                  "transform" : "create",
                  "parameter" : [
                    {
                      "valueString" : "Extension"
                    }
                  ]
                }
              ],
              "rule" : [
                {
                  "name" : "setflext",
                  "source" : [
                    {
                      "context" : "srcAddress"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "firstLevelExtension",
                      "contextType" : "variable",
                      "element" : "url",
                      "transform" : "evaluate",
                      "parameter" : [
                        {
                          "valueString" : "'http://hl7.org/fhir/StructureDefinition/geolocation'"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "setLatExt",
                      "source" : [
                        {
                          "context" : "srcAddress",
                          "element" : "latitude",
                          "variable" : "srcLat"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "firstLevelExtension",
                          "contextType" : "variable",
                          "element" : "extension",
                          "variable" : "latExtension",
                          "transform" : "create",
                          "parameter" : [
                            {
                              "valueString" : "Extension"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "setLat",
                          "source" : [
                            {
                              "context" : "srcLat"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "latExtension",
                              "contextType" : "variable",
                              "element" : "url",
                              "transform" : "evaluate",
                              "parameter" : [
                                {
                                  "valueString" : "'latitude'"
                                }
                              ]
                            },
                            {
                              "context" : "latExtension",
                              "contextType" : "variable",
                              "element" : "value",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueId" : "srcLat"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "setLongExt",
                      "source" : [
                        {
                          "context" : "srcAddress",
                          "element" : "longitude",
                          "variable" : "srcLong"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "firstLevelExtension",
                          "contextType" : "variable",
                          "element" : "extension",
                          "variable" : "longExtension",
                          "transform" : "create",
                          "parameter" : [
                            {
                              "valueString" : "Extension"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "setLong",
                          "source" : [
                            {
                              "context" : "srcLong"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "longExtension",
                              "contextType" : "variable",
                              "element" : "url",
                              "transform" : "evaluate",
                              "parameter" : [
                                {
                                  "valueString" : "'longitude'"
                                }
                              ]
                            },
                            {
                              "context" : "longExtension",
                              "contextType" : "variable",
                              "element" : "value",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueId" : "srcLong"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "encounter",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcSejour",
          "type" : "SejourTable",
          "mode" : "source"
        },
        {
          "name" : "srcPatient",
          "type" : "FHIRPatient",
          "mode" : "source"
        },
        {
          "name" : "tgtEncounter",
          "type" : "FHIREncounter",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setId",
          "source" : [
            {
              "context" : "srcSejour"
            }
          ],
          "target" : [
            {
              "context" : "tgtEncounter",
              "contextType" : "variable",
              "element" : "id",
              "transform" : "uuid"
            }
          ]
        },
        {
          "name" : "setMeta",
          "source" : [
            {
              "context" : "srcSejour",
              "element" : "sejourNi",
              "variable" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtEncounter",
              "contextType" : "variable",
              "element" : "meta",
              "variable" : "tgtMeta"
            }
          ],
          "dependent" : [
            {
              "name" : "setEncounterMeta",
              "variable" : ["srcNi", "tgtMeta"]
            }
          ],
          "documentation" : "copie la valeur du champ patientNi de la table Patient dans l'élément id de la ressource FHIR Patient"
        },
        {
          "name" : "setStatus",
          "source" : [
            {
              "context" : "srcSejour"
            }
          ],
          "target" : [
            {
              "context" : "tgtEncounter",
              "contextType" : "variable",
              "element" : "status",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "finished"
                }
              ]
            }
          ]
        },
        {
          "name" : "setEncounterClass",
          "source" : [
            {
              "context" : "srcSejour",
              "element" : "sejourType",
              "variable" : "srcSejourType"
            }
          ],
          "target" : [
            {
              "context" : "tgtEncounter",
              "contextType" : "variable",
              "element" : "class",
              "transform" : "translate",
              "parameter" : [
                {
                  "valueId" : "srcSejourType"
                },
                {
                  "valueString" : "https://interop.aphp.fr/ig/fhir/dm/ConceptMap/DpiEncounterType2SemanticLayerEncounterClass"
                },
                {
                  "valueString" : "Coding"
                }
              ]
            }
          ]
        },
        {
          "name" : "setSubjectReference",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "id",
              "variable" : "patientId"
            }
          ],
          "target" : [
            {
              "context" : "tgtEncounter",
              "contextType" : "variable",
              "element" : "subject",
              "variable" : "newSubject",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setSubjectReference",
              "variable" : ["patientId", "newSubject"]
            }
          ]
        },
        {
          "name" : "patientNi",
          "source" : [
            {
              "context" : "srcSejour",
              "element" : "patientNi"
            }
          ],
          "documentation" : "fk vers le patient à conserver pour la construction auto du périmètre final"
        },
        {
          "name" : "setPeriod",
          "source" : [
            {
              "context" : "srcSejour"
            }
          ],
          "target" : [
            {
              "context" : "tgtEncounter",
              "contextType" : "variable",
              "element" : "period",
              "variable" : "newActualPeriod",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Period"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "setStart",
              "source" : [
                {
                  "context" : "srcSejour",
                  "element" : "sejourStart",
                  "variable" : "srcPeriodStart"
                }
              ],
              "target" : [
                {
                  "context" : "newActualPeriod",
                  "contextType" : "variable",
                  "element" : "start",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcPeriodStart"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setEnd",
              "source" : [
                {
                  "context" : "srcSejour",
                  "element" : "sejourEnd",
                  "variable" : "srcPeriodEnd"
                }
              ],
              "target" : [
                {
                  "context" : "newActualPeriod",
                  "contextType" : "variable",
                  "element" : "end",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcPeriodEnd"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setEncounterMeta",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcNi",
          "mode" : "source"
        },
        {
          "name" : "tgtMeta",
          "type" : "FHIRMeta",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setSource",
          "source" : [
            {
              "context" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtMeta",
              "contextType" : "variable",
              "element" : "source",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'https://aphp.fr/fhir/Endpoint/dpi/SejourTable' + '/' + %srcNi.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setSubjectReference",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcPatientId",
          "mode" : "source"
        },
        {
          "name" : "newSubject",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setReference",
          "source" : [
            {
              "context" : "srcPatientId"
            }
          ],
          "target" : [
            {
              "context" : "newSubject",
              "contextType" : "variable",
              "element" : "reference",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'Patient/' + %srcPatientId.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "procedure",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcActe",
          "type" : "ActeTable",
          "mode" : "source"
        },
        {
          "name" : "srcPatient",
          "type" : "FHIRPatient",
          "mode" : "source"
        },
        {
          "name" : "srcEncounter",
          "type" : "FHIREncounter",
          "mode" : "source"
        },
        {
          "name" : "tgtProcedure",
          "type" : "FHIRProcedure",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setId",
          "source" : [
            {
              "context" : "srcActe"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "id",
              "transform" : "uuid"
            }
          ]
        },
        {
          "name" : "setMeta",
          "source" : [
            {
              "context" : "srcActe",
              "element" : "acteNi",
              "variable" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "meta",
              "variable" : "tgtMeta"
            }
          ],
          "dependent" : [
            {
              "name" : "setProcedureMeta",
              "variable" : ["srcNi", "tgtMeta"]
            }
          ]
        },
        {
          "name" : "setSubjectReference",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "id",
              "variable" : "patientId"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "subject",
              "variable" : "newSubject",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setSubjectReference",
              "variable" : ["patientId", "newSubject"]
            }
          ]
        },
        {
          "name" : "setEncounterReference",
          "source" : [
            {
              "context" : "srcEncounter",
              "element" : "id",
              "variable" : "encounterId"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "encounter",
              "variable" : "newEncounter",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setEncounterReference",
              "variable" : ["encounterId", "newEncounter"]
            }
          ]
        },
        {
          "name" : "setStatus",
          "source" : [
            {
              "context" : "srcActe"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "status",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        },
        {
          "name" : "setDate",
          "source" : [
            {
              "context" : "srcActe",
              "condition" : "dateStart.exists() or dateEnd.exists"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "performed",
              "variable" : "tgtProcedurePeriod",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Period"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "setActeStart",
              "source" : [
                {
                  "context" : "srcActe",
                  "element" : "dateStart",
                  "variable" : "srcActeStart"
                }
              ],
              "target" : [
                {
                  "context" : "tgtProcedurePeriod",
                  "contextType" : "variable",
                  "element" : "start",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcActeStart"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setActeEnd",
              "source" : [
                {
                  "context" : "srcActe",
                  "element" : "dateEnd",
                  "variable" : "srcActeEnd"
                }
              ],
              "target" : [
                {
                  "context" : "tgtProcedurePeriod",
                  "contextType" : "variable",
                  "element" : "end",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "srcActeEnd"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "setCode",
          "source" : [
            {
              "context" : "srcActe",
              "element" : "code",
              "variable" : "acteCode"
            }
          ],
          "target" : [
            {
              "context" : "tgtProcedure",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "cc",
              "parameter" : [
                {
                  "valueString" : "https://smt.esante.gouv.fr/terminologie-ccam"
                },
                {
                  "valueId" : "acteCode"
                }
              ]
            }
          ],
          "documentation" : "C'est le code de la CCAM facturante"
        }
      ]
    },
    {
      "name" : "setProcedureMeta",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcNi",
          "mode" : "source"
        },
        {
          "name" : "tgtMeta",
          "type" : "FHIRMeta",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setSource",
          "source" : [
            {
              "context" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtMeta",
              "contextType" : "variable",
              "element" : "source",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'https://aphp.fr/fhir/Endpoint/dpi/ActeTable' + '/' + %srcNi.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setEncounterReference",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcEncounterId",
          "mode" : "source"
        },
        {
          "name" : "newEncounter",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setReference",
          "source" : [
            {
              "context" : "srcEncounterId"
            }
          ],
          "target" : [
            {
              "context" : "newEncounter",
              "contextType" : "variable",
              "element" : "reference",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'Encounter/' + %srcEncounterId.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "condition",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcDiag",
          "type" : "DiagTable",
          "mode" : "source"
        },
        {
          "name" : "srcPatient",
          "type" : "FHIRPatient",
          "mode" : "source"
        },
        {
          "name" : "srcEncounter",
          "type" : "FHIREncounter",
          "mode" : "source"
        },
        {
          "name" : "tgtCondition",
          "type" : "FHIRCondition",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setId",
          "source" : [
            {
              "context" : "srcDiag"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "id",
              "transform" : "uuid"
            }
          ]
        },
        {
          "name" : "setMeta",
          "source" : [
            {
              "context" : "srcDiag",
              "element" : "diagNi",
              "variable" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "meta",
              "variable" : "tgtMeta"
            }
          ],
          "dependent" : [
            {
              "name" : "setConditionMeta",
              "variable" : ["srcNi", "tgtMeta"]
            }
          ]
        },
        {
          "name" : "setSubjectReference",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "id",
              "variable" : "patientId"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "subject",
              "variable" : "newSubject",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setSubjectReference",
              "variable" : ["patientId", "newSubject"]
            }
          ]
        },
        {
          "name" : "setEncounterReference",
          "source" : [
            {
              "context" : "srcEncounter",
              "element" : "id",
              "variable" : "encounterId"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "encounter",
              "variable" : "newEncounter",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setEncounterReference",
              "variable" : ["encounterId", "newEncounter"]
            }
          ]
        },
        {
          "name" : "setVerificationStatus",
          "source" : [
            {
              "context" : "srcDiag"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "verificationStatus",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "confirmed"
                }
              ]
            }
          ]
        },
        {
          "name" : "setCategory",
          "source" : [
            {
              "context" : "srcDiag"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "category",
              "transform" : "cc",
              "parameter" : [
                {
                  "valueString" : "http://terminology.hl7.org/CodeSystem/condition-category"
                },
                {
                  "valueString" : "encounter-diagnosis"
                }
              ]
            }
          ]
        },
        {
          "name" : "setCode",
          "source" : [
            {
              "context" : "srcDiag",
              "element" : "code",
              "variable" : "diagCode"
            }
          ],
          "target" : [
            {
              "context" : "tgtCondition",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "cc",
              "parameter" : [
                {
                  "valueString" : "http://hl7.org/fhir/sid/icd-10"
                },
                {
                  "valueId" : "diagCode"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setConditionMeta",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcNi",
          "mode" : "source"
        },
        {
          "name" : "tgtMeta",
          "type" : "FHIRMeta",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setSource",
          "source" : [
            {
              "context" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtMeta",
              "contextType" : "variable",
              "element" : "source",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'https://aphp.fr/fhir/Endpoint/dpi/DiagTable' + '/' + %srcNi.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "observationBiol",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcBiology",
          "type" : "BiologyTable",
          "mode" : "source"
        },
        {
          "name" : "srcPatient",
          "type" : "FHIRPatient",
          "mode" : "source"
        },
        {
          "name" : "srcEncounter",
          "type" : "FHIREncounter",
          "mode" : "source"
        },
        {
          "name" : "tgtObservation",
          "type" : "FHIRObservation",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setId",
          "source" : [
            {
              "context" : "srcBiology"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "id",
              "transform" : "uuid"
            }
          ]
        },
        {
          "name" : "setMeta",
          "source" : [
            {
              "context" : "srcBiology",
              "element" : "biologyNi",
              "variable" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "meta",
              "variable" : "tgtMeta"
            }
          ],
          "dependent" : [
            {
              "name" : "setBiologyMeta",
              "variable" : ["srcNi", "tgtMeta"]
            }
          ]
        },
        {
          "name" : "setSubjectReference",
          "source" : [
            {
              "context" : "srcPatient",
              "element" : "id",
              "variable" : "patientId"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "subject",
              "variable" : "newSubject",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setSubjectReference",
              "variable" : ["patientId", "newSubject"]
            }
          ]
        },
        {
          "name" : "setEncounterReference",
          "source" : [
            {
              "context" : "srcEncounter",
              "element" : "id",
              "variable" : "encounterId"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "encounter",
              "variable" : "newEncounter",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Reference"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "setEncounterReference",
              "variable" : ["encounterId", "newEncounter"]
            }
          ]
        },
        {
          "name" : "setStatus",
          "source" : [
            {
              "context" : "srcBiology"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "status",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "final"
                }
              ]
            }
          ]
        },
        {
          "name" : "setCategory",
          "source" : [
            {
              "context" : "srcBiology"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "category",
              "transform" : "cc",
              "parameter" : [
                {
                  "valueString" : "http://terminology.hl7.org/CodeSystem/observation-category"
                },
                {
                  "valueString" : "vital-signs"
                }
              ]
            }
          ]
        },
        {
          "name" : "setDate",
          "source" : [
            {
              "context" : "srcBiology",
              "element" : "biologyDatePrel",
              "variable" : "biologyDatePrel"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "effective",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueId" : "biologyDatePrel"
                }
              ]
            }
          ]
        },
        {
          "name" : "setCode",
          "source" : [
            {
              "context" : "srcBiology",
              "element" : "biologyCode",
              "variable" : "biologyCode"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "cc",
              "parameter" : [
                {
                  "valueString" : "http://loinc.org"
                },
                {
                  "valueId" : "biologyCode"
                }
              ]
            }
          ]
        },
        {
          "name" : "setQuantity",
          "source" : [
            {
              "context" : "srcBiology",
              "element" : "biologyValue"
            }
          ],
          "target" : [
            {
              "context" : "tgtObservation",
              "contextType" : "variable",
              "element" : "value",
              "variable" : "tgtObsQuantity",
              "transform" : "create",
              "parameter" : [
                {
                  "valueString" : "Quantity"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "setValue",
              "source" : [
                {
                  "context" : "srcBiology",
                  "element" : "biologyValue",
                  "variable" : "biologyValue"
                }
              ],
              "target" : [
                {
                  "context" : "tgtObsQuantity",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "biologyValue"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setUnit",
              "source" : [
                {
                  "context" : "srcBiology",
                  "element" : "biologyUnit",
                  "variable" : "biologyUnit"
                }
              ],
              "target" : [
                {
                  "context" : "tgtObsQuantity",
                  "contextType" : "variable",
                  "element" : "code",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "biologyUnit"
                    }
                  ]
                },
                {
                  "context" : "tgtObsQuantity",
                  "contextType" : "variable",
                  "element" : "unit",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "biologyUnit"
                    }
                  ]
                },
                {
                  "context" : "tgtObsQuantity",
                  "contextType" : "variable",
                  "element" : "system",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "http://unitsofmeasure.org"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "setBiologyMeta",
      "typeMode" : "none",
      "input" : [
        {
          "name" : "srcNi",
          "mode" : "source"
        },
        {
          "name" : "tgtMeta",
          "type" : "FHIRMeta",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "setSource",
          "source" : [
            {
              "context" : "srcNi"
            }
          ],
          "target" : [
            {
              "context" : "tgtMeta",
              "contextType" : "variable",
              "element" : "source",
              "transform" : "evaluate",
              "parameter" : [
                {
                  "valueString" : "'https://aphp.fr/fhir/Endpoint/dpi/BiologyTable' + '/' + %srcNi.toString()"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "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" : "'https://aphp.fr/' + %newRes.type().name + '/' + %newResId"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "setRequest",
              "source" : [
                {
                  "context" : "newResId"
                }
              ],
              "target" : [
                {
                  "context" : "tgtEntry",
                  "contextType" : "variable",
                  "element" : "request",
                  "variable" : "tgtEntryRequest"
                },
                {
                  "context" : "tgtEntryRequest",
                  "contextType" : "variable",
                  "element" : "method",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "POST"
                    }
                  ]
                },
                {
                  "context" : "tgtEntryRequest",
                  "contextType" : "variable",
                  "element" : "url",
                  "transform" : "evaluate",
                  "parameter" : [
                    {
                      "valueString" : "%newRes.type().name + '/' + %newResId"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

```
