Guide d'implémentation pour l'atelier
0.1.0 - ci-build

Guide d'implémentation pour l'atelier - version de développement local (intégration continue v0.1.0) construite par les outils de publication FHIR (HL7® FHIR® Standard). Voir le répertoire des versions publiées

## : Transformation FHIR DocumentReference en message HL7v2 MDM^T02 (description) - TTL Representation

Active as of 2026-03-31

Raw ttl | Download

    @prefix fhir: <http://hl7.org/fhir/> .
    @prefix owl: <http://www.w3.org/2002/07/owl#> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

    # - resource -------------------------------------------------------------------

     a fhir:StructureMap ;
      fhir:nodeRole fhir:treeRoot ;
      fhir:id [ fhir:v "DocumentReferenceToT02"] ; #
      fhir:text [
    fhir:status [ fhir:v "generated" ] ;
    fhir:div [ fhir:v "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p class=\"res-header-id\"><b>Narratif généré : StructureMap DocumentReferenceToT02</b></p><a name=\"DocumentReferenceToT02\"> </a><a name=\"hcDocumentReferenceToT02\"> </a><pre class=\"fml\">#xD;\n<b>map</b><span style=\"color: navy\"> \"</span>https://interop.aphp.fr/ig/fhir/atelier/StructureMap/DocumentReferenceToT02<span style=\"color: navy\">\" = \"</span>DocumentReferenceToT02<span style=\"color: navy\">\"#xD;\n#xD;\n</span><span style=\"color: navy\">// </span><span style=\"color: green\">Transformation FHIR DocumentReference en message HL7v2 MDM^T02 (description)</span>#xD;\n#xD;\n<b>uses</b><span style=\"color: navy\"> \"</span><a href=\"http://hl7.org/fhir/R4/documentreference.html\" title=\"DocumentReference\">http://hl7.org/fhir/StructureDefinition/DocumentReference|4.0.1</a><span style=\"color: navy\">\" </span><b>alias </b>DocumentReference <b>as </b><b>source</b>#xD;\n<b>uses</b><span style=\"color: navy\"> \"</span><a href=\"StructureDefinition-mdm.html\" title=\"MDM - full message\">https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/mdm|0.1.0</a><span style=\"color: navy\">\" </span><b>alias </b>Mdm <b>as </b><b>target</b>#xD;\n<b>uses</b><span style=\"color: navy\"> \"</span><a href=\"StructureDefinition-msh.html\" title=\"MSH - Message header\">https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/msh|0.1.0</a><span style=\"color: navy\">\" </span><b>alias </b>Msh <b>as </b><b>target</b>#xD;\n<b>uses</b><span style=\"color: navy\"> \"</span><a href=\"StructureDefinition-pid.html\" title=\"PID - Patient Identification\">https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/pid|0.1.0</a><span style=\"color: navy\">\" </span><b>alias </b>Pid <b>as </b><b>target</b>#xD;\n#xD;\n<b>group </b>documentReferenceToT02<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">srcDocRef</span><span style=\"color: navy\"> : </span>DocumentReference, <b>target</b> <span style=\"color: maroon\">tgtMdm</span><span style=\"color: navy\"> : </span>Mdm<span style=\"color: navy\">)</span><span style=\"color: navy\"> {#xD;\n</span>  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMdm.msh<b> as </b><span style=\"color: maroon\">tgtMsh</span><b> then </b>toMsh<span style=\"color: navy\">(</span><span style=\"color: maroon\">srcDocRef</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">tgtMsh</span><span style=\"color: navy\">)</span> <i>\"toMsh\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMdm.pid<b> as </b><span style=\"color: maroon\">tgtPid</span><b> then </b>toPid<span style=\"color: navy\">(</span><span style=\"color: maroon\">srcDocRef</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">tgtPid</span><span style=\"color: navy\">)</span> <i>\"toPid\"</i><span style=\"color: navy\">;</span>#xD;\n<span style=\"color: navy\">}#xD;\n#xD;\n</span><b>group </b>toMsh<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">srcDocRef</span>, <b>target</b> <span style=\"color: maroon\">tgtMsh</span><span style=\"color: navy\"> : </span>Msh<span style=\"color: navy\">)</span><span style=\"color: navy\"> {#xD;\n</span>  <span style=\"color: navy\">// </span><span style=\"color: green\">--- Champs fixes MSH ---</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh1 = <span style=\"color: blue\">'|'</span> <i>\"setFieldSep\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh2 = <span style=\"color: navy\">(</span>'^~\\\\&amp;'<span style=\"color: navy\">)</span> <i>\"setEncoding\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh5 = <span style=\"color: blue\">'DPI'</span> <i>\"setReceivingApp\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh6 = <span style=\"color: blue\">'APHP'</span> <i>\"setReceivingFacility\"</i><span style=\"color: navy\">;</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">msh7 : date/heure au format HL7 v2 (YYYYMMDDHHmmss)</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">On utilise une expression unique sur now() pour éviter plusieurs appels retournant des timestamps différents.</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">now() retourne un format ISO 8601 (ex: 2024-01-15T14:30:00+01:00) ;</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">on supprime les séparateurs '-', 'T', ':' puis on tronque à 14 caractères.</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh7 = <span style=\"color: navy\">(</span>now().toString().replace('-', '').replace('T', '').replace(':', '').substring(0, 14)<span style=\"color: navy\">)</span> <i>\"setDateTime\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh9 = <span style=\"color: blue\">'MDM^T02'</span> <i>\"setMessageType\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh10 = <b>uuid</b><span style=\"color: navy\">(</span><span style=\"color: navy\">)</span> <i>\"setMsgControlId\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh11 = <span style=\"color: blue\">'P'</span> <i>\"setProcessingId\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh12 = <span style=\"color: blue\">'2.5'</span> <i>\"setVersion\"</i><span style=\"color: navy\">;</span>#xD;\n  srcDocRef<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh18 = <span style=\"color: blue\">'8859/15'</span> <i>\"setCharSet\"</i><span style=\"color: navy\">;</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">--- Champs variables MSH ---</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">msh3 : application d'envoi (identifiant Hopex du custodian)</span>#xD;\n  srcDocRef.custodian<b> as </b><span style=\"color: maroon\">srcCustodian</span><b> then</b><span style=\"color: navy\"> {#xD;\n</span>    srcCustodian.identifier<b> as </b><span style=\"color: maroon\">srcCustIdentifier</span><b> where </b>system = 'https://interop.aphp.fr/info/Device/hopex'<b> then</b><span style=\"color: navy\"> {#xD;\n</span>      srcCustIdentifier.value<b> as </b><span style=\"color: maroon\">srcCustIdentVal</span><span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh3 = <span style=\"color: maroon\">srcCustIdentVal</span> <i>\"setMsh3\"</i><span style=\"color: navy\">;</span>#xD;\n    <span style=\"color: navy\">}</span> <i>\"navCustIdentifier\"</i><span style=\"color: navy\">;</span>#xD;\n  <span style=\"color: navy\">}</span> <i>\"navCustodian\"</i><span style=\"color: navy\">;</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">msh4 : code hôpital (3 premiers caractères de l'identifiant Sirius)</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Précondition : la valeur doit faire au moins 3 caractères (garde explicite).</span>#xD;\n  srcDocRef.author<b> as </b><span style=\"color: maroon\">srcServiceRespMed</span><b> where </b>(identifier.system = 'https://interop.aphp.fr/info/Organization/Sirius')<b> then</b><span style=\"color: navy\"> {#xD;\n</span>    srcServiceRespMed.identifier<b> as </b><span style=\"color: maroon\">srcServiceRespMedId</span><b> then</b><span style=\"color: navy\"> {#xD;\n</span>      srcServiceRespMedId.value<b> as </b><span style=\"color: maroon\">srcServiceRespMedIdValue</span><b> where </b>($this.length() &gt;= 3)<span style=\"color: navy\"><b> -&gt; </b></span>tgtMsh.msh4 = <span style=\"color: navy\">(</span>%srcServiceRespMedIdValue.substring(0, 3)<span style=\"color: navy\">)</span> <i>\"setMsh4\"</i><span style=\"color: navy\">;</span>#xD;\n    <span style=\"color: navy\">}</span> <i>\"navUnitIdentifier\"</i><span style=\"color: navy\">;</span>#xD;\n  <span style=\"color: navy\">}</span> <i>\"navUnit\"</i><span style=\"color: navy\">;</span>#xD;\n<span style=\"color: navy\">}#xD;\n#xD;\n</span><b>group </b>toPid<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">srcDocRef</span>, <b>target</b> <span style=\"color: maroon\">tgtPid</span><span style=\"color: navy\"> : </span>Pid<span style=\"color: navy\">)</span><span style=\"color: navy\"> {#xD;\n</span>  <span style=\"color: navy\">// </span><span style=\"color: green\">Précondition : subject.reference doit pointer vers une ressource Patient contained (#id).</span>#xD;\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Si la référence est externe, aucun segment PID ne sera généré (échec silencieux documenté).</span>#xD;\n  srcDocRef.subject<b> as </b><span style=\"color: maroon\">srcSubject</span><b> then</b><span style=\"color: navy\"> {#xD;\n</span>    srcSubject.reference<b> as </b><span style=\"color: maroon\">srcSubjectReference</span><b> then</b><span style=\"color: navy\"> {#xD;\n</span>      srcDocRef.contained<span style=\"color: navy\"> : </span>Patient<b> as </b><span style=\"color: maroon\">srcDocSubj</span><b> where </b>(('#' + id) = %srcSubjectReference)<b> then</b><span style=\"color: navy\"> {#xD;\n</span>        <span style=\"color: navy\">// </span><span style=\"color: green\">pid3 : IPP patient</span>#xD;\n        srcDocSubj.identifier<b> as </b><span style=\"color: maroon\">srcDocSubjIdentifier</span><b> where </b>system = 'https://interop.aphp.fr/info/Patient/ipp'<span style=\"color: navy\"><b> -&gt; </b></span> tgtPid.pid3<b> as </b><span style=\"color: maroon\">tgtPid3</span><span style=\"color: navy\">, </span> tgtPid3.cx5 = <span style=\"color: blue\">'PN'</span><span style=\"color: navy\">, </span> tgtPid3.cx4 = <span style=\"color: blue\">'APHP'</span><span style=\"color: navy\">, </span> tgtPid3.cx1 = <span style=\"color: navy\">(</span>%srcDocSubjIdentifier.value<span style=\"color: navy\">)</span> <i>\"setPid3\"</i><span style=\"color: navy\">;</span>#xD;\n        <span style=\"color: navy\">// </span><span style=\"color: green\">pid5 : nom officiel</span>#xD;\n        srcDocSubj.name<b> as </b><span style=\"color: maroon\">srcSubjName</span><b> where </b>use = 'official'<span style=\"color: navy\"><b> -&gt; </b></span>tgtPid.pid5<b> as </b><span style=\"color: maroon\">tgtPid5</span><b> then</b><span style=\"color: navy\"> {#xD;\n</span>          srcSubjName.family<b> as </b><span style=\"color: maroon\">srcSubjFamilyName</span><span style=\"color: navy\"><b> -&gt; </b></span>tgtPid5.xpn1 = <span style=\"color: maroon\">srcSubjFamilyName</span> <i>\"setFamilyName\"</i><span style=\"color: navy\">;</span>#xD;\n          srcSubjName.given<b> as </b><span style=\"color: maroon\">srcSubjGivenName</span><span style=\"color: navy\"><b> -&gt; </b></span>tgtPid5.xpn2 = <span style=\"color: maroon\">srcSubjGivenName</span><b> then</b><span style=\"color: navy\"> {#xD;\n</span>            <span style=\"color: navy\">// </span><span style=\"color: green\">xpn3 : prénoms secondaires extraits de l'extension fr-core birth-list-given-name.</span>#xD;\n            <span style=\"color: navy\">// </span><span style=\"color: green\">Hypothèse : la valeur de l'extension contient le prénom usuel suivi d'un espace</span>#xD;\n            <span style=\"color: navy\">// </span><span style=\"color: green\">puis des prénoms secondaires (ex: \"Jean Pierre Marie\").</span>#xD;\n            <span style=\"color: navy\">// </span><span style=\"color: green\">On extrait la partie après le prénom usuel (longueur + 1 pour l'espace).</span>#xD;\n            <span style=\"color: navy\">// </span><span style=\"color: green\">Si le format de l'extension change, cette logique doit être revisitée.</span>#xD;\n            srcSubjName.extension<b> as </b><span style=\"color: maroon\">srcSubjectGivenNamesExt</span><b> where </b>url = 'https://hl7.fr/ig/fhir/core/StructureDefinition/fr-core-patient-birth-list-given-name'<b> then</b><span style=\"color: navy\"> {#xD;\n</span>              srcSubjectGivenNamesExt.value<span style=\"color: navy\"> : </span>string<b> as </b><span style=\"color: maroon\">srcSubjectGivenNamesValue</span><span style=\"color: navy\"><b> -&gt; </b></span>tgtPid5.xpn3 = <span style=\"color: navy\">(</span>%srcSubjectGivenNamesValue.toString().substring(%srcSubjGivenName.length() + 1)<span style=\"color: navy\">)</span> <i>\"setGivenNames\"</i><span style=\"color: navy\">;</span>#xD;\n            <span style=\"color: navy\">}</span> <i>\"navGivenNamesExt\"</i><span style=\"color: navy\">;</span>#xD;\n          <span style=\"color: navy\">}</span> <i>\"setGivenName\"</i><span style=\"color: navy\">;</span>#xD;\n        <span style=\"color: navy\">}</span> <i>\"navName\"</i><span style=\"color: navy\">;</span>#xD;\n        <span style=\"color: navy\">// </span><span style=\"color: green\">pid7 : date de naissance au format HL7 v2 (YYYYMMDD)</span>#xD;\n        <span style=\"color: navy\">// </span><span style=\"color: green\">On supprime les tirets du format ISO 8601 (YYYY-MM-DD -&gt; YYYYMMDD).</span>#xD;\n        srcDocSubj.birthDate<b> as </b><span style=\"color: maroon\">srcSubjBirthDate</span><span style=\"color: navy\"><b> -&gt; </b></span>tgtPid.pid7 = <span style=\"color: navy\">(</span>%srcSubjBirthDate.toString().replace('-', '')<span style=\"color: navy\">)</span> <i>\"setBirthDate\"</i><span style=\"color: navy\">;</span>#xD;\n        <span style=\"color: navy\">// </span><span style=\"color: green\">pid8 : sexe (via ConceptMap FHIR -&gt; table HL7 0001)</span>#xD;\n        srcDocSubj.gender<b> as </b><span style=\"color: maroon\">srcSubjGender</span><span style=\"color: navy\"><b> -&gt; </b></span>tgtPid.pid8 = <b>translate</b><span style=\"color: navy\">(</span><span style=\"color: maroon\">srcSubjGender</span><span style=\"color: navy\">, </span><span style=\"color: blue\">'https://interop.aphp.fr/ig/fhir/atelier/ConceptMap/patient-gender-to-aphp-table-0001'</span><span style=\"color: navy\">, </span><span style=\"color: blue\">'code'</span><span style=\"color: navy\">)</span> <i>\"setGender\"</i><span style=\"color: navy\">;</span>#xD;\n        <span style=\"color: navy\">// </span><span style=\"color: green\">pid18 : NDA (valeur fixe provisoire — TODO: voir pv1-19)</span>#xD;\n        srcDocSubj<span style=\"color: navy\"><b> -&gt; </b></span>tgtPid.pid18 = <span style=\"color: blue\">'NDA'</span> <i>\"setPid18\"</i><span style=\"color: navy\">;</span>#xD;\n      <span style=\"color: navy\">}</span> <i>\"navContainedSubject\"</i><span style=\"color: navy\">;</span>#xD;\n    <span style=\"color: navy\">}</span> <i>\"navSubjectReference\"</i><span style=\"color: navy\">;</span>#xD;\n  <span style=\"color: navy\">}</span> <i>\"navSubject\"</i><span style=\"color: navy\">;</span>#xD;\n<span style=\"color: navy\">}#xD;\n#xD;\n</span></pre></div>"^^rdf:XMLLiteral ]
      ] ; #
      fhir:url [
    fhir:v "https://interop.aphp.fr/ig/fhir/atelier/StructureMap/DocumentReferenceToT02"^^xsd:anyURI ;
    fhir:l <https://interop.aphp.fr/ig/fhir/atelier/StructureMap/DocumentReferenceToT02>
      ] ; #
      fhir:version [ fhir:v "0.1.0"] ; #
      fhir:name [ fhir:v "DocumentReferenceToT02"] ; #
      fhir:title [ fhir:v "Transformation FHIR DocumentReference en message HL7v2 MDM^T02 (description)"] ; #
      fhir:status [ fhir:v "active"] ; #
      fhir:date [ fhir:v "2026-03-31T08:46:55+00:00"^^xsd:dateTime] ; #
      fhir:publisher [ fhir:v "AP-HP"] ; #
      fhir:contact ( [
    fhir:name [ fhir:v "AP-HP" ] ;
        ( fhir:telecom [
    fhir:system [ fhir:v "url" ] ;
    fhir:value [ fhir:v "https://aphp.fr" ]     ] )
      ] ) ; #
      fhir:description [ fhir:v "Transformation FHIR DocumentReference en message HL7v2 MDM^T02 (description)"] ; #
      fhir:jurisdiction ( [
        ( fhir:coding [
    fhir:system [
    fhir:v "urn:iso:std:iso:3166"^^xsd:anyURI ;
    fhir:l <urn:iso:std:iso:3166>       ] ;
    fhir:code [ fhir:v "FRA" ]     ] )
      ] ) ; #
      fhir:structure ( [
    fhir:url [
    fhir:v "http://hl7.org/fhir/StructureDefinition/DocumentReference|4.0.1"^^xsd:anyURI ;
    fhir:l <http://hl7.org/fhir/StructureDefinition/DocumentReference?version=4.0.1>     ] ;
    fhir:mode [ fhir:v "source" ] ;
    fhir:alias [ fhir:v "DocumentReference" ]
      ] [
    fhir:url [
    fhir:v "https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/mdm|0.1.0"^^xsd:anyURI ;
    fhir:l <https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/mdm?version=0.1.0>     ] ;
    fhir:mode [ fhir:v "target" ] ;
    fhir:alias [ fhir:v "Mdm" ]
      ] [
    fhir:url [
    fhir:v "https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/msh|0.1.0"^^xsd:anyURI ;
    fhir:l <https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/msh?version=0.1.0>     ] ;
    fhir:mode [ fhir:v "target" ] ;
    fhir:alias [ fhir:v "Msh" ]
      ] [
    fhir:url [
    fhir:v "https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/pid|0.1.0"^^xsd:anyURI ;
    fhir:l <https://interop.aphp.fr/ig/fhir/atelier/StructureDefinition/pid?version=0.1.0>     ] ;
    fhir:mode [ fhir:v "target" ] ;
    fhir:alias [ fhir:v "Pid" ]
      ] ) ; #
      fhir:group ( [
    fhir:name [ fhir:v "documentReferenceToT02" ] ;
    fhir:typeMode [ fhir:v "none" ] ;
        ( fhir:input [
    fhir:name [ fhir:v "srcDocRef" ] ;
    fhir:type [ fhir:v "DocumentReference" ] ;
    fhir:mode [ fhir:v "source" ]     ] [
    fhir:name [ fhir:v "tgtMdm" ] ;
    fhir:type [ fhir:v "Mdm" ] ;
    fhir:mode [ fhir:v "target" ]     ] ) ;
        ( fhir:rule [
    fhir:name [ fhir:v "toMsh" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMdm" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh" ] ;
    fhir:variable [ fhir:v "tgtMsh" ]       ] ) ;
          ( fhir:dependent [
    fhir:name [ fhir:v "toMsh" ] ;
            ( fhir:variable [ fhir:v "srcDocRef" ] [ fhir:v "tgtMsh" ] )       ] )     ] [
    fhir:name [ fhir:v "toPid" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMdm" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "pid" ] ;
    fhir:variable [ fhir:v "tgtPid" ]       ] ) ;
          ( fhir:dependent [
    fhir:name [ fhir:v "toPid" ] ;
            ( fhir:variable [ fhir:v "srcDocRef" ] [ fhir:v "tgtPid" ] )       ] )     ] )
      ] [
    fhir:name [ fhir:v "toMsh" ] ;
    fhir:typeMode [ fhir:v "none" ] ;
        ( fhir:input [
    fhir:name [ fhir:v "srcDocRef" ] ;
    fhir:mode [ fhir:v "source" ]     ] [
    fhir:name [ fhir:v "tgtMsh" ] ;
    fhir:type [ fhir:v "Msh" ] ;
    fhir:mode [ fhir:v "target" ]     ] ) ;
        ( fhir:rule [
    fhir:name [ fhir:v "setFieldSep" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh1" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "|"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setEncoding" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh2" ] ;
    fhir:transform [ fhir:v "evaluate" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "'^~\\\\&'"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setReceivingApp" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh5" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "DPI"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setReceivingFacility" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh6" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "APHP"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setDateTime" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh7" ] ;
    fhir:transform [ fhir:v "evaluate" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "now().toString().replace('-', '').replace('T', '').replace(':', '').substring(0, 14)"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setMessageType" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh9" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "MDM^T02"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setMsgControlId" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh10" ] ;
    fhir:transform [ fhir:v "uuid" ]       ] )     ] [
    fhir:name [ fhir:v "setProcessingId" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh11" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "P"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setVersion" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh12" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "2.5"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "setCharSet" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ]       ] ) ;
          ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh18" ] ;
    fhir:transform [ fhir:v "copy" ] ;
            ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "8859/15"           ]         ] )       ] )     ] [
    fhir:name [ fhir:v "navCustodian" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ] ;
    fhir:element [ fhir:v "custodian" ] ;
    fhir:variable [ fhir:v "srcCustodian" ]       ] ) ;
          ( fhir:rule [
    fhir:name [ fhir:v "navCustIdentifier" ] ;
            ( fhir:source [
    fhir:context [ fhir:v "srcCustodian" ] ;
    fhir:element [ fhir:v "identifier" ] ;
    fhir:variable [ fhir:v "srcCustIdentifier" ] ;
    fhir:condition [ fhir:v "system = 'https://interop.aphp.fr/info/Device/hopex'" ]         ] ) ;
            ( fhir:rule [
    fhir:name [ fhir:v "setMsh3" ] ;
              ( fhir:source [
    fhir:context [ fhir:v "srcCustIdentifier" ] ;
    fhir:element [ fhir:v "value" ] ;
    fhir:variable [ fhir:v "srcCustIdentVal" ]           ] ) ;
              ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh3" ] ;
    fhir:transform [ fhir:v "copy" ] ;
                ( fhir:parameter [
    fhir:value [
    a fhir:Id ;
    fhir:v "srcCustIdentVal"               ]             ] )           ] )         ] )       ] )     ] [
    fhir:name [ fhir:v "navUnit" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ] ;
    fhir:element [ fhir:v "author" ] ;
    fhir:variable [ fhir:v "srcServiceRespMed" ] ;
    fhir:condition [ fhir:v "(identifier.system = 'https://interop.aphp.fr/info/Organization/Sirius')" ]       ] ) ;
          ( fhir:rule [
    fhir:name [ fhir:v "navUnitIdentifier" ] ;
            ( fhir:source [
    fhir:context [ fhir:v "srcServiceRespMed" ] ;
    fhir:element [ fhir:v "identifier" ] ;
    fhir:variable [ fhir:v "srcServiceRespMedId" ]         ] ) ;
            ( fhir:rule [
    fhir:name [ fhir:v "setMsh4" ] ;
              ( fhir:source [
    fhir:context [ fhir:v "srcServiceRespMedId" ] ;
    fhir:element [ fhir:v "value" ] ;
    fhir:variable [ fhir:v "srcServiceRespMedIdValue" ] ;
    fhir:condition [ fhir:v "($this.length() >= 3)" ]           ] ) ;
              ( fhir:target [
    fhir:context [ fhir:v "tgtMsh" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "msh4" ] ;
    fhir:transform [ fhir:v "evaluate" ] ;
                ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "%srcServiceRespMedIdValue.substring(0, 3)"               ]             ] )           ] )         ] )       ] )     ] )
      ] [
    fhir:name [ fhir:v "toPid" ] ;
    fhir:typeMode [ fhir:v "none" ] ;
        ( fhir:input [
    fhir:name [ fhir:v "srcDocRef" ] ;
    fhir:mode [ fhir:v "source" ]     ] [
    fhir:name [ fhir:v "tgtPid" ] ;
    fhir:type [ fhir:v "Pid" ] ;
    fhir:mode [ fhir:v "target" ]     ] ) ;
        ( fhir:rule [
    fhir:name [ fhir:v "navSubject" ] ;
          ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ] ;
    fhir:element [ fhir:v "subject" ] ;
    fhir:variable [ fhir:v "srcSubject" ]       ] ) ;
          ( fhir:rule [
    fhir:name [ fhir:v "navSubjectReference" ] ;
            ( fhir:source [
    fhir:context [ fhir:v "srcSubject" ] ;
    fhir:element [ fhir:v "reference" ] ;
    fhir:variable [ fhir:v "srcSubjectReference" ]         ] ) ;
            ( fhir:rule [
    fhir:name [ fhir:v "navContainedSubject" ] ;
              ( fhir:source [
    fhir:context [ fhir:v "srcDocRef" ] ;
    fhir:type [ fhir:v "Patient" ] ;
    fhir:element [ fhir:v "contained" ] ;
    fhir:variable [ fhir:v "srcDocSubj" ] ;
    fhir:condition [ fhir:v "(('#' + id) = %srcSubjectReference)" ]           ] ) ;
              ( fhir:rule [
    fhir:name [ fhir:v "setPid3" ] ;
                ( fhir:source [
    fhir:context [ fhir:v "srcDocSubj" ] ;
    fhir:element [ fhir:v "identifier" ] ;
    fhir:variable [ fhir:v "srcDocSubjIdentifier" ] ;
    fhir:condition [ fhir:v "system = 'https://interop.aphp.fr/info/Patient/ipp'" ]             ] ) ;
                ( fhir:target [
    fhir:context [ fhir:v "tgtPid" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "pid3" ] ;
    fhir:variable [ fhir:v "tgtPid3" ]             ] [
    fhir:context [ fhir:v "tgtPid3" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "cx5" ] ;
    fhir:transform [ fhir:v "copy" ] ;
                  ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "PN"                 ]               ] )             ] [
    fhir:context [ fhir:v "tgtPid3" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "cx4" ] ;
    fhir:transform [ fhir:v "copy" ] ;
                  ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "APHP"                 ]               ] )             ] [
    fhir:context [ fhir:v "tgtPid3" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "cx1" ] ;
    fhir:transform [ fhir:v "evaluate" ] ;
                  ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "%srcDocSubjIdentifier.value"                 ]               ] )             ] )           ] [
    fhir:name [ fhir:v "navName" ] ;
                ( fhir:source [
    fhir:context [ fhir:v "srcDocSubj" ] ;
    fhir:element [ fhir:v "name" ] ;
    fhir:variable [ fhir:v "srcSubjName" ] ;
    fhir:condition [ fhir:v "use = 'official'" ]             ] ) ;
                ( fhir:target [
    fhir:context [ fhir:v "tgtPid" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "pid5" ] ;
    fhir:variable [ fhir:v "tgtPid5" ]             ] ) ;
                ( fhir:rule [
    fhir:name [ fhir:v "setFamilyName" ] ;
                  ( fhir:source [
    fhir:context [ fhir:v "srcSubjName" ] ;
    fhir:element [ fhir:v "family" ] ;
    fhir:variable [ fhir:v "srcSubjFamilyName" ]               ] ) ;
                  ( fhir:target [
    fhir:context [ fhir:v "tgtPid5" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "xpn1" ] ;
    fhir:transform [ fhir:v "copy" ] ;
                    ( fhir:parameter [
    fhir:value [
    a fhir:Id ;
    fhir:v "srcSubjFamilyName"                   ]                 ] )               ] )             ] [
    fhir:name [ fhir:v "setGivenName" ] ;
                  ( fhir:source [
    fhir:context [ fhir:v "srcSubjName" ] ;
    fhir:element [ fhir:v "given" ] ;
    fhir:variable [ fhir:v "srcSubjGivenName" ]               ] ) ;
                  ( fhir:target [
    fhir:context [ fhir:v "tgtPid5" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "xpn2" ] ;
    fhir:transform [ fhir:v "copy" ] ;
                    ( fhir:parameter [
    fhir:value [
    a fhir:Id ;
    fhir:v "srcSubjGivenName"                   ]                 ] )               ] ) ;
                  ( fhir:rule [
    fhir:name [ fhir:v "navGivenNamesExt" ] ;
                    ( fhir:source [
    fhir:context [ fhir:v "srcSubjName" ] ;
    fhir:element [ fhir:v "extension" ] ;
    fhir:variable [ fhir:v "srcSubjectGivenNamesExt" ] ;
    fhir:condition [ fhir:v "url = 'https://hl7.fr/ig/fhir/core/StructureDefinition/fr-core-patient-birth-list-given-name'" ]                 ] ) ;
                    ( fhir:rule [
    fhir:name [ fhir:v "setGivenNames" ] ;
                      ( fhir:source [
    fhir:context [ fhir:v "srcSubjectGivenNamesExt" ] ;
    fhir:type [ fhir:v "string" ] ;
    fhir:element [ fhir:v "value" ] ;
    fhir:variable [ fhir:v "srcSubjectGivenNamesValue" ]                   ] ) ;
                      ( fhir:target [
    fhir:context [ fhir:v "tgtPid5" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "xpn3" ] ;
    fhir:transform [ fhir:v "evaluate" ] ;
                        ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "%srcSubjectGivenNamesValue.toString().substring(%srcSubjGivenName.length() + 1)"                       ]                     ] )                   ] )                 ] )               ] )             ] )           ] [
    fhir:name [ fhir:v "setBirthDate" ] ;
                ( fhir:source [
    fhir:context [ fhir:v "srcDocSubj" ] ;
    fhir:element [ fhir:v "birthDate" ] ;
    fhir:variable [ fhir:v "srcSubjBirthDate" ]             ] ) ;
                ( fhir:target [
    fhir:context [ fhir:v "tgtPid" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "pid7" ] ;
    fhir:transform [ fhir:v "evaluate" ] ;
                  ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "%srcSubjBirthDate.toString().replace('-', '')"                 ]               ] )             ] )           ] [
    fhir:name [ fhir:v "setGender" ] ;
                ( fhir:source [
    fhir:context [ fhir:v "srcDocSubj" ] ;
    fhir:element [ fhir:v "gender" ] ;
    fhir:variable [ fhir:v "srcSubjGender" ]             ] ) ;
                ( fhir:target [
    fhir:context [ fhir:v "tgtPid" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "pid8" ] ;
    fhir:transform [ fhir:v "translate" ] ;
                  ( fhir:parameter [
    fhir:value [
    a fhir:Id ;
    fhir:v "srcSubjGender"                 ]               ] [
    fhir:value [
    a fhir:String ;
    fhir:v "https://interop.aphp.fr/ig/fhir/atelier/ConceptMap/patient-gender-to-aphp-table-0001"                 ]               ] [
    fhir:value [
    a fhir:String ;
    fhir:v "code"                 ]               ] )             ] )           ] [
    fhir:name [ fhir:v "setPid18" ] ;
                ( fhir:source [
    fhir:context [ fhir:v "srcDocSubj" ]             ] ) ;
                ( fhir:target [
    fhir:context [ fhir:v "tgtPid" ] ;
    fhir:contextType [ fhir:v "variable" ] ;
    fhir:element [ fhir:v "pid18" ] ;
    fhir:transform [ fhir:v "copy" ] ;
                  ( fhir:parameter [
    fhir:value [
    a fhir:String ;
    fhir:v "NDA"                 ]               ] )             ] )           ] )         ] )       ] )     ] )
      ] ) . #