<StructureDefinition xmlns="http://hl7.org/fhir">
  <url value="http://interopsante.org/fhir/StructureDefinition/FrMedication2unique" />
  <version value="0.1.0" />
  <name value="FrMedication2unique" />
  <status value="draft" />
  <experimental value="true" />
  <date value="2021-12-09" />
  <description value="ressource Medication unique regroupant les 4 profils en 1 (ucd, ucd-part, non-proprietary-name et compound)" />
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="script10.6" />
    <uri value="http://ncpdp.org/SCRIPT10_6" />
    <name value="Mapping to NCPDP SCRIPT 10.6" />
  </mapping>
  <mapping>
    <identity value="rim" />
    <uri value="http://hl7.org/v3" />
    <name value="RIM Mapping" />
  </mapping>
  <mapping>
    <identity value="w5" />
    <uri value="http://hl7.org/fhir/fivews" />
    <name value="FiveWs Pattern Mapping" />
  </mapping>
  <mapping>
    <identity value="v2" />
    <uri value="http://hl7.org/v2" />
    <name value="HL7 v2 Mapping" />
  </mapping>
  <kind value="resource" />
  <abstract value="false" />
  <type value="Medication" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Medication" />
  <derivation value="constraint" />
  <differential>
    <element id="Medication">
      <path value="Medication" />
      <constraint>
        <key value="frmed-med-1" />
        <severity value="error" />
        <human value="If fr-medication is a simple medication, ingredient SHALL NOT be a Reference" />
        <expression value="code.coding.system.exists() implies (ingredient.item as Reference).empty()" />
        <source value="http://interopsante.org/fhir/StructureDefinition/FrMedication2unique" />
      </constraint>
    </element>
    <element id="Medication.code">
      <path value="Medication.code" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="coding.system" />
        </discriminator>
        <description value="3 slices: 1. for branded medication ; 2. for non-proprietary named medication ; 3.  for compound medication. Induces 2 constrains on ingredient element: 1. for non-compound medication, ingredient element SHALL be a substance ; for compound medication, ingredient element SHALL be a branded or non-proprietary named medication." />
        <rules value="open" />
      </slicing>
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Medication.code:ucdCode">
      <path value="Medication.code" />
      <sliceName value="ucdCode" />
      <sliceIsConstraining value="false" />
      <short value="Codes that identify branded medication" />
      <requirements value="Identify a trade named medication" />
      <meaningWhenMissing value="this is not a trade named medication" />
      <mustSupport value="true" />
    </element>
    <element id="Medication.code:ucdCode.coding">
      <path value="Medication.code.coding" />
      <short value="Codes that identify this branded medication" />
      <definition value="Codes that identify this branded medication" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <description value="UCD code" />
        <valueSet value="http://phast.fr/fhir/ValueSet/Pharmacy/CIOdc/SIPh-CIO_UCD" />
      </binding>
    </element>
    <element id="Medication.code:ucdCode.coding.system">
      <path value="Medication.code.coding.system" />
      <short value="UCD codeSystem" />
      <definition value="The UCD code system (under the responsibility of the Club Inter Pharmaceutique (CIP)" />
      <comment value="In the absence of a uri defined by the Club Interpharceutique or the competent government authorities, the uri defined by PHAST is used." />
      <requirements value="The code system SHALL be the UCD code system" />
      <patternUri value="^http:\/\/phast\.fr\/fhir\/ValueSet\/Pharmacy\/CIOdc\/SIPh-CIO_UCD$" />
    </element>
    <element id="Medication.code:ucdCode.coding.code">
      <path value="Medication.code.coding.code" />
      <binding>
        <strength value="required" />
        <description value="code UCD valide" />
        <valueSet value="http://phast.fr/fhir/ValueSet/Pharmacy/CIOdc/SIPh-CIO_UCD" />
      </binding>
    </element>
    <element id="Medication.code:snomedMedicinalProductCode">
      <path value="Medication.code" />
      <sliceName value="snomedMedicinalProductCode" />
      <sliceIsConstraining value="false" />
      <short value="Codes that identify this simple medication" />
      <definition value="Codes identifying this simple medication, ie. a medication having ingredients only made of substance without reference to any other Medication ressource" />
      <meaningWhenMissing value="this is not a simple medication medication" />
      <mustSupport value="true" />
    </element>
    <element id="Medication.code:snomedMedicinalProductCode.coding">
      <path value="Medication.code.coding" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://interopsante.org/fhir/ValueSet/fr-medicinal-product-only" />
      </binding>
    </element>
    <element id="Medication.code:snomedMedicinalProductCode.coding.system">
      <path value="Medication.code.coding.system" />
      <short value="SNOMED CT codeSystem" />
      <requirements value="The code system SHALL be the SNOMED CT code system" />
      <patternUri value="^http:\/\/snomed\.info\/sct$" />
    </element>
    <element id="Medication.code:snomedMedicinalProductCode.coding.code">
      <path value="Medication.code.coding.code" />
      <binding>
        <strength value="required" />
        <description value="MP sctid valide" />
        <valueSet value="http://interopsante.org/fhir/ValueSet/fr-medicinal-product-only" />
      </binding>
    </element>
    <element id="Medication.code:otherMedicationCode">
      <path value="Medication.code" />
      <sliceName value="otherMedicationCode" />
      <sliceIsConstraining value="false" />
      <short value="Codes that identify this compound medication" />
      <definition value="Codes identifying this compound medication, ie. a medication having ingredients made of only references to other Medication ressources" />
      <constraint>
        <key value="frmed-med-2" />
        <severity value="error" />
        <human value="If fr-medication is an othter-medication, its code SHALL NOT be UCD" />
        <expression value="coding.system != 'http://phast.fr/fhir/ValueSet/Pharmacy/CIOdc/SIPh-CIO_UCD'" />
        <source value="http://interopsante.org/fhir/StructureDefinition/FrMedication2unique" />
      </constraint>
      <constraint>
        <key value="frmed-med-3" />
        <severity value="error" />
        <human value="If fr-medication is a other-medication, its code SHALL NOT be SNOMED CT" />
        <expression value="coding.system != 'http://snomed.info/sct'" />
        <source value="http://interopsante.org/fhir/StructureDefinition/FrMedication2unique" />
      </constraint>
      <constraint>
        <key value="frmed-med-4" />
        <severity value="error" />
        <human value="if fr-medication has no code it SHALL have a text" />
        <expression value="coding.code.exist() or text.exist()" />
        <source value="http://interopsante.org/fhir/StructureDefinition/FrMedication2unique" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Medication.code:otherMedicationCode.coding">
      <path value="Medication.code.coding" />
      <short value="Generaly no code for compound medicinal product" />
      <definition value="A code identifing the compound medicinal product. Generaly none : no code defined for G5 1L + NaCl 3g + KCl 2g." />
    </element>
    <element id="Medication.code:otherMedicationCode.coding.system">
      <path value="Medication.code.coding.system" />
      <patternUri value="^((?!http:\/\/phast\.fr\/fhir\/ValueSet\/Pharmacy\/CIOdc\/SIPh-CIO_UCD|http:\/\/snomed\.info\/sct).)*$" />
    </element>
    <element id="Medication.code:otherMedicationCode.text">
      <path value="Medication.code.text" />
      <comment value="If there is no code (usually not available for a compound drug or must be local if available), a name SHALL be provided." />
      <mustSupport value="true" />
    </element>
    <element id="Medication.ingredient">
      <path value="Medication.ingredient" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Medication.ingredient.item[x]">
      <path value="Medication.ingredient.item[x]" />
      <definition value="The actual ingredient - either a substance (simple medication's ingredient) or another medication (compound medciation's ingredient)." />
      <type>
        <code value="CodeableConcept" />
        <profile value="http://interopsante.org/fhir/StructureDefinition/FrMPSubstance2Active" />
      </type>
      <type>
        <code value="Reference" />
        <targetProfile value="http://interopsante.org/fhir/StructureDefinition/FrMedication2unique" />
      </type>
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>