<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="TimingDgMP" />
  <url value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
  <name value="TimingDgMP" />
  <title value="Timing dgMP" />
  <status value="draft" />
  <description value="Beschreibt ein Ereignis, das mehrfach auftreten kann. Zeitpläne werden verwendet, um festzuhalten, wann etwas geplant, erwartet oder angefordert ist. Die häufigste Anwendung ist in Dosierungsanweisungen für Medikamente. Sie werden aber auch für die Planung verschiedener Versorgungsleistungen genutzt und können zur Dokumentation von bereits erfolgten oder laufenden Aktivitäten verwendet werden." />
  <fhirVersion value="4.0.1" />
  <kind value="complex-type" />
  <abstract value="false" />
  <type value="Timing" />
  <baseDefinition value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDE" />
  <derivation value="constraint" />
  <differential>
    <element id="Timing.event">
      <path value="Timing.event" />
      <comment value="Begründung Einschränkung Kardinalität: Der Zeitpunkt des Ereignisses ist in der ersten Ausbaustufe des dgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat">
      <path value="Timing.repeat" />
      <min value="1" />
      <constraint>
        <key value="TimingOnlyOneType" />
        <severity value="error" />
        <human value="Only one kind of Timing is allowed. Current allowed timings: 4-Scheme, TimeOfDay, DayOfWeek, Interval, DayOfWeek and Time/4-Schema, Interval and Time/4-Schema" />
        <expression value="/* DayOfWeek */&#xA;(&#xA;  %resource.ofType(MedicationRequest).dosageInstruction | &#xA;  ofType(MedicationDispense).dosageInstruction | &#xA;  ofType(MedicationStatement).dosage&#xA;).all(&#xA;  timing.repeat.dayOfWeek.exists() and&#xA;  timing.repeat.frequency.exists() and&#xA;  (timing.repeat.period.exists() and timing.repeat.period = 1) and&#xA;  (timing.repeat.periodUnit.exists()) and&#xA;  timing.repeat.when.empty() and&#xA;  timing.repeat.timeOfDay.empty()&#xA;) or&#xA;&#xA;/* Interval */&#xA;(&#xA;  %resource.ofType(MedicationRequest).dosageInstruction | &#xA;  ofType(MedicationDispense).dosageInstruction | &#xA;  ofType(MedicationStatement).dosage&#xA;).all(&#xA;  timing.repeat.frequency.exists() and&#xA;  timing.repeat.period.exists() and&#xA;  timing.repeat.periodUnit.exists() and&#xA;  timing.repeat.when.empty() and&#xA;  timing.repeat.timeOfDay.empty() and&#xA;  timing.repeat.dayOfWeek.empty()&#xA;) or&#xA;&#xA;/* DayOfWeek and Time/4-Schema */&#xA;(&#xA;  %resource.ofType(MedicationRequest).dosageInstruction | &#xA;  ofType(MedicationDispense).dosageInstruction | &#xA;  ofType(MedicationStatement).dosage&#xA;).all(&#xA;  timing.repeat.dayOfWeek.exists() and&#xA;  timing.repeat.frequency.exists() and&#xA;  (timing.repeat.period.exists() and timing.repeat.period = 1) and&#xA;  (timing.repeat.periodUnit.exists()) and&#xA;  (&#xA;    (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or&#xA;    (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())&#xA;  )&#xA;) or&#xA;&#xA;/* Interval and Time/4-Schema */&#xA;(&#xA;  %resource.ofType(MedicationRequest).dosageInstruction | &#xA;  ofType(MedicationDispense).dosageInstruction | &#xA;  ofType(MedicationStatement).dosage&#xA;).all(&#xA;  timing.repeat.frequency.exists() and&#xA;  timing.repeat.period.exists() and&#xA;  timing.repeat.periodUnit.exists() and&#xA;  timing.repeat.dayOfWeek.empty() and&#xA;  (&#xA;    (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or&#xA;    (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingIntervalOnlyOneFrequency" />
        <severity value="error" />
        <human value="If a dosage is defined by a pure interval, then only one dosage is allowed in the resource." />
        <expression value="( /* Detect Interval */&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;)&#xA;.all(&#xA;  (&#xA;    timing.repeat.frequency.exists()&#xA;    and timing.repeat.period.exists()&#xA;    and timing.repeat.periodUnit.exists()&#xA;    and timing.repeat.when.empty()&#xA;    and timing.repeat.timeOfDay.empty()&#xA;    and timing.repeat.dayOfWeek.empty()&#xA;  )&#xA;  /* Only One Dosage allowed for Interval */&#xA;  implies&#xA;  (&#xA;    (&#xA;      (&#xA;        %resource.ofType(MedicationRequest).exists()&#xA;        or %resource.ofType(MedicationDispense).exists()&#xA;      )&#xA;      implies (&#xA;        %resource.dosageInstruction.count() = 1&#xA;      )&#xA;    )&#xA;    and&#xA;    (&#xA;      %resource.ofType(MedicationStatement).exists()&#xA;      implies&#xA;      %resource.dosage.count() = 1&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingOnlyOneWhen" />
        <severity value="error" />
        <human value="Dosages Timings must not state the same period of day across multiple dosage instances" />
        <expression value="( /* Detect 4-Schema */&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;).all(&#xA;    timing.repeat.frequency.exists() and&#xA;    timing.repeat.period.exists() and&#xA;    timing.repeat.periodUnit.exists() and&#xA;    timing.repeat.dayOfWeek.empty() and&#xA;    timing.repeat.when.exists() and &#xA;    timing.repeat.timeOfDay.empty()&#xA;  implies&#xA;  (&#xA;    (&#xA;      (%resource.ofType(MedicationRequest).exists() or %resource.ofType(MedicationDispense).exists())&#xA;      implies&#xA;      (%resource.dosageInstruction.timing.repeat.when.distinct().count() = %resource.dosageInstruction.timing.repeat.when.count())&#xA;    )&#xA;    and&#xA;    (&#xA;      %resource.ofType(MedicationStatement).exists()&#xA;      implies&#xA;      (%resource.dosage.timing.repeat.when.distinct().count() = %resource.dosage.timing.repeat.when.count())&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingOnlyOneTimeOfDay" />
        <severity value="error" />
        <human value="Dosages Timings must not state the same time of day across multiple dosage instances" />
        <expression value="( /* Detect TimeOfDay */&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;).all(&#xA;  (&#xA;    timing.repeat.frequency.exists() and&#xA;    timing.repeat.period.exists() and&#xA;    timing.repeat.periodUnit.exists() and&#xA;    timing.repeat.dayOfWeek.empty() and&#xA;    timing.repeat.timeOfDay.exists() and&#xA;    timing.repeat.when.empty() &#xA;  )&#xA;  implies&#xA;  (&#xA;    (&#xA;      (%resource.ofType(MedicationRequest).exists() or %resource.ofType(MedicationDispense).exists())&#xA;      implies&#xA;      (%resource.dosageInstruction.timing.repeat.timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.timeOfDay.count())&#xA;    )&#xA;    and&#xA;    (&#xA;      %resource.ofType(MedicationStatement).exists()&#xA;      implies&#xA;      (%resource.dosage.timing.repeat.timeOfDay.distinct().count() = %resource.dosage.timing.repeat.timeOfDay.count())&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingOnlyOneDayOfWeek" />
        <severity value="error" />
        <human value="Dosages Timings must not state the same day across multiple dosage instances" />
        <expression value="( /* Detect DayOfWeek */&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;).all(&#xA;  (&#xA;    timing.repeat.frequency.exists() and&#xA;    timing.repeat.period.exists() and&#xA;    timing.repeat.periodUnit.exists() and&#xA;    timing.repeat.dayOfWeek.exists() and&#xA;    timing.repeat.when.empty() and &#xA;    timing.repeat.timeOfDay.empty()&#xA;  )&#xA;  implies&#xA;  (&#xA;    (&#xA;      (%resource.ofType(MedicationRequest).exists() or %resource.ofType(MedicationDispense).exists())&#xA;      implies&#xA;      (%resource.dosageInstruction.timing.repeat.dayOfWeek.distinct().count() = %resource.dosageInstruction.timing.repeat.dayOfWeek.count())&#xA;    )&#xA;    and&#xA;    (&#xA;      %resource.ofType(MedicationStatement).exists()&#xA;      implies&#xA;      (%resource.dosage.timing.repeat.dayOfWeek.distinct().count() = %resource.dosage.timing.repeat.dayOfWeek.count())&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingOnlyOnePeriodForDayOfWeek" />
        <severity value="error" />
        <human value="For schedules using only dayOfWeek with either timeOfDay or when, each (day + period of day/time) combination must be unique across all dosage instructions." />
        <expression value="( /* Detect DayOfWeek and Time/4-Schema */&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;).all(&#xA;  (&#xA;    timing.repeat.dayOfWeek.exists() and&#xA;    timing.repeat.frequency.exists() and&#xA;    timing.repeat.period.exists() and&#xA;    timing.repeat.periodUnit.exists() and&#xA;      (&#xA;        (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or&#xA;        (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())&#xA;      )&#xA;  )&#xA;  implies&#xA;  (&#xA;    (&#xA;      (%resource.ofType(MedicationRequest).exists() or %resource.ofType(MedicationDispense).exists())&#xA;      implies&#xA;      (&#xA;        /* For each day of week */&#xA;        /* if Mon occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'mon')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'mon').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('mon' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('mon' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('mon' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('mon' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        &#xA;        /* if tue occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'tue')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'tue').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('tue' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('tue' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('tue' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('tue' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if wed occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'wed')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'wed').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('wed' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('wed' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('wed' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('wed' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if thu occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'thu')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'thu').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('thu' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('thu' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('thu' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('thu' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if fri occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'fri')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'fri').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('fri' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('fri' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('fri' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('fri' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if sat occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'sat')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'sat').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('sat' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('sat' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('sat' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('sat' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        &#xA;        /* if sun occurs multiple times */&#xA;        ((&#xA;          %resource.dosageInstruction.timing.repeat.dayOfWeek&#xA;          .where($this = 'sun')&#xA;          .where(%resource.dosageInstruction.timing.repeat.dayOfWeek.where($this = 'sun').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosageInstruction.timing.repeat.where('sun' in dayOfWeek).when.distinct().count() = %resource.dosageInstruction.timing.repeat.where('sun' in dayOfWeek).when.count()) and&#xA;          (%resource.dosageInstruction.timing.repeat.where('sun' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.where('sun' in dayOfWeek).timeOfDay.count())&#xA;        ))&#xA;      )&#xA;    )&#xA;    and&#xA;    (&#xA;      %resource.ofType(MedicationStatement).exists()&#xA;      implies&#xA;      (&#xA;        /* For each day of week */&#xA;        /* if Mon occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'mon')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'mon').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('mon' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('mon' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('mon' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('mon' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        &#xA;        /* if tue occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'tue')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'tue').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('tue' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('tue' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('tue' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('tue' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if wed occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'wed')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'wed').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('wed' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('wed' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('wed' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('wed' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if thu occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'thu')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'thu').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('thu' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('thu' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('thu' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('thu' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if fri occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'fri')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'fri').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('fri' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('fri' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('fri' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('fri' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        /* if sat occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'sat')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'sat').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('sat' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('sat' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('sat' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('sat' in dayOfWeek).timeOfDay.count())&#xA;        )) and&#xA;        &#xA;        /* if sun occurs multiple times */&#xA;        ((&#xA;          %resource.dosage.timing.repeat.dayOfWeek&#xA;          .where($this = 'sun')&#xA;          .where(%resource.dosage.timing.repeat.dayOfWeek.where($this = 'sun').count() &gt; 1)&#xA;          .distinct()&#xA;        ) implies &#xA;        (&#xA;          (%resource.dosage.timing.repeat.where('sun' in dayOfWeek).when.distinct().count() = %resource.dosage.timing.repeat.where('sun' in dayOfWeek).when.count()) and&#xA;          (%resource.dosage.timing.repeat.where('sun' in dayOfWeek).timeOfDay.distinct().count() = %resource.dosage.timing.repeat.where('sun' in dayOfWeek).timeOfDay.count())&#xA;        ))&#xA;      )&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingOnlyOneTimeForInterval" />
        <severity value="error" />
        <human value="Dosage Interval Timings must not state the same time of day across multiple dosage instances" />
        <expression value="/* Detect Interval and Time/4-Schema */&#xA;(&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;)&#xA;.all(&#xA;  (&#xA;    timing.repeat.frequency.exists() and&#xA;    timing.repeat.period.exists() and&#xA;    timing.repeat.periodUnit.exists() and&#xA;    timing.repeat.dayOfWeek.empty() and&#xA;    (&#xA;      (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or&#xA;      (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())&#xA;    )&#xA;  )&#xA;  implies&#xA;  (&#xA;    (&#xA;      %resource.ofType(MedicationRequest).exists()&#xA;      or %resource.ofType(MedicationDispense).exists()&#xA;    )&#xA;    implies&#xA;    (&#xA;      %resource.dosageInstruction.timing.repeat.period.distinct().count() = 1&#xA;      and %resource.dosageInstruction.timing.repeat.periodUnit.distinct().count() = 1&#xA;    )&#xA;    and&#xA;    (&#xA;      (%resource.dosageInstruction.timing.repeat.timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.timeOfDay.count())&#xA;      and&#xA;      (%resource.dosageInstruction.timing.repeat.when.distinct().count() = %resource.dosageInstruction.timing.repeat.when.count())&#xA;    )&#xA;  )&#xA;  and&#xA;  (&#xA;    %resource.ofType(MedicationStatement).exists()&#xA;    implies&#xA;    (&#xA;      (&#xA;        %resource.ofType(MedicationRequest).exists()&#xA;        or %resource.ofType(MedicationDispense).exists()&#xA;      )&#xA;      implies&#xA;      (&#xA;        %resource.dosage.timing.repeat.period.distinct().count() = 1&#xA;        and %resource.dosage.timing.repeat.periodUnit.distinct().count() = 1&#xA;      )&#xA;      and&#xA;      (&#xA;        (%resource.dosage.timing.repeat.timeOfDay.distinct().count() = %resource.dosage.timing.repeat.timeOfDay.count())&#xA;        and&#xA;        (%resource.dosage.timing.repeat.when.distinct().count() = %resource.dosage.timing.repeat.when.count())&#xA;      )&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingOnlyOneBounds" />
        <severity value="error" />
        <human value="Dosages Timings must not state the same bounds duration across multiple dosage instances" />
        <expression value="(&#xA;  %resource.ofType(MedicationRequest).dosageInstruction&#xA;  | %resource.ofType(MedicationDispense).dosageInstruction&#xA;  | %resource.ofType(MedicationStatement).dosage&#xA;).all(&#xA;  (&#xA;    ( /* only one different value and code are allowed*/&#xA;      (%resource.ofType(MedicationRequest).exists() or %resource.ofType(MedicationDispense).exists())&#xA;      implies&#xA;      %resource.dosageInstruction.timing.repeat.bounds.ofType(Duration).exists().not() or&#xA;      (&#xA;        (%resource.dosageInstruction.timing.repeat.bounds.ofType(Duration).value.distinct().count() = 1)&#xA;        and&#xA;        (%resource.dosageInstruction.timing.repeat.bounds.ofType(Duration).code.distinct().count() = 1)&#xA;      )&#xA;    )&#xA;    and&#xA;    (&#xA;      %resource.ofType(MedicationStatement).exists()&#xA;      implies&#xA;      %resource.dosage.timing.repeat.bounds.ofType(Duration).exists().not() or&#xA;      (&#xA;        (%resource.dosage.timing.repeat.bounds.ofType(Duration).value.distinct().count() = 1)&#xA;        and&#xA;        (%resource.dosage.timing.repeat.bounds.ofType(Duration).code.distinct().count() = 1)&#xA;      )&#xA;    )&#xA;  )&#xA;)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingFrequencyCount" />
        <severity value="error" />
        <human value="The frequency of the timing needs to reflect the count of timeOfDay or when" />
        <expression value="(when.exists() and dayOfWeek.empty() implies when.count() = frequency)&#xA;and&#xA;(when.exists() and dayOfWeek.exists() implies (when.count() * dayOfWeek.count()) = frequency)&#xA;and&#xA;(timeOfDay.exists() and dayOfWeek.empty() implies timeOfDay.count() = frequency)&#xA;and&#xA;(timeOfDay.exists() and dayOfWeek.exists() implies (timeOfDay.count() * dayOfWeek.count()) = frequency)&#xA;and&#xA;(dayOfWeek.exists() and timeOfDay.empty() and when.empty() implies dayOfWeek.count() = frequency)" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
      <constraint>
        <key value="TimingPeriodUnit" />
        <severity value="error" />
        <human value="If weekdays are given the periodUnit must be week, otherwise day" />
        <expression value="(dayOfWeek.exists() implies periodUnit = 'wk')&#xA;and&#xA;((dayOfWeek.empty() and (when.exists() or timeOfDay.exists())) implies periodUnit = 'd')" />
        <source value="http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP" />
      </constraint>
    </element>
    <element id="Timing.repeat.bounds[x]">
      <path value="Timing.repeat.bounds[x]" />
      <comment value="Begründung Einschränkung Datentyp: Nur eine Angabe zur Dauer ist in der ersten Ausbaustufe des dgMP vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <type>
        <code value="Duration" />
      </type>
    </element>
    <element id="Timing.repeat.bounds[x]:boundsDuration">
      <path value="Timing.repeat.bounds[x]" />
      <sliceName value="boundsDuration" />
      <type>
        <code value="Duration" />
      </type>
    </element>
    <element id="Timing.repeat.bounds[x]:boundsDuration.unit">
      <path value="Timing.repeat.bounds[x].unit" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Timing.repeat.bounds[x]:boundsDuration.system">
      <path value="Timing.repeat.bounds[x].system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Timing.repeat.bounds[x]:boundsDuration.code">
      <path value="Timing.repeat.bounds[x].code" />
      <min value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://ig.fhir.de/igs/medication/ValueSet/DosageUnitsOfTimeDgMP" />
      </binding>
    </element>
    <element id="Timing.repeat.count">
      <path value="Timing.repeat.count" />
      <comment value="Begründung Einschränkung Kardinalität: Wiederholungen sind in der ersten Ausbaustufe des dgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.countMax">
      <path value="Timing.repeat.countMax" />
      <comment value="Begründung Einschränkung Kardinalität: Maximale Wiederholungen sind in der ersten Ausbaustufe des dgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.duration">
      <path value="Timing.repeat.duration" />
      <comment value="Begründung Einschränkung Kardinalität: Angaben zur Dauer einer Einzelgabe sind in der ersten Ausbaustufe des dgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.durationMax">
      <path value="Timing.repeat.durationMax" />
      <comment value="Begründung Einschränkung Kardinalität: Angaben zur maximalen Dauer einer Einzelgabe sind in der ersten Ausbaustufe desdgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.durationUnit">
      <path value="Timing.repeat.durationUnit" />
      <comment value="Begründung Einschränkung Kardinalität: Angaben zur Einheit der Dauer einer Einzelgabe sind in der ersten Ausbaustufe desdgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.frequency">
      <path value="Timing.repeat.frequency" />
      <min value="1" />
    </element>
    <element id="Timing.repeat.frequencyMax">
      <path value="Timing.repeat.frequencyMax" />
      <comment value="Begründung Einschränkung Kardinalität: Eine maximale Frequenz ist in der ersten Ausbaustufe des dgMP nicht vorgesehen – es wird immer eine Frequenz explizit gesetzt, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.period">
      <path value="Timing.repeat.period" />
      <min value="1" />
    </element>
    <element id="Timing.repeat.periodMax">
      <path value="Timing.repeat.periodMax" />
      <comment value="Begründung Einschränkung Kardinalität: Eine maximale Periodendauer ist in der ersten Ausbaustufe des dgMP nicht vorgesehen – es wird immer eine Dauer explizit gesetzt, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.repeat.periodUnit">
      <path value="Timing.repeat.periodUnit" />
      <min value="1" />
      <binding>
        <strength value="required" />
        <valueSet value="http://ig.fhir.de/igs/medication/ValueSet/PeriodUnitsOfTimeDgMP" />
      </binding>
    </element>
    <element id="Timing.repeat.when">
      <path value="Timing.repeat.when" />
      <binding>
        <strength value="required" />
        <valueSet value="http://ig.fhir.de/igs/medication/ValueSet/TimingWhenDgMP" />
      </binding>
    </element>
    <element id="Timing.repeat.offset">
      <path value="Timing.repeat.offset" />
      <short value="Zeitversatz" />
      <comment value="Begründung Einschränkung Kardinalität: Ein Zeitversatz ist in der ersten Ausbaustufe desdgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen." />
      <max value="0" />
    </element>
    <element id="Timing.code">
      <path value="Timing.code" />
      <comment value="Begründung Einschränkung Kardinalität: Ein Timing-Code ist in der ersten Ausbaustufe des dgMP nicht vorgesehen, um die Komplexität zu reduzieren und die Übersichtlichkeit zu erhöhen. Stattdessen muss das Zeitmuster explizit strukturiert angegeben werden." />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>