PackagesCanonicalsLogsProblems
    Packages
    de.fhir.medication@2.0.0
    http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
description: 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.
package_name: de.fhir.medication
derivation: constraint
name: TimingDgMP
type: Timing
elements:
  event: {index: 0}
  repeat:
    constraint:
      TimingVarPeriodGtMin: {human: 'For a variable period, the maximum period must be greater than the minimum period.', source: 'http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP', severity: error, expression: periodMax.empty() or period.empty() or period < periodMax}
      TimingOnlyOneDayOfWeek:
        human: In a schema that uses only dayOfWeek, no weekday may occur in more than one of the Dosage elements that use this schema.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          ( /* Detect DayOfWeek */
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).where(
            timing.repeat.dayOfWeek.exists() and
            timing.repeat.when.empty() and
            timing.repeat.timeOfDay.empty()
          ).timing.repeat.dayOfWeek.isDistinct()
      TimingBoundsPeriodNotForWhen:
        human: If when is used, or dayOfWeek is used without timeOfDay, boundsPeriod.start and boundsPeriod.end may only state a date, not a time.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          (when.empty() and (dayOfWeek.empty() or timeOfDay.exists())) or
          (bounds.ofType(Period).start | bounds.ofType(Period).end).all(toString().length() <= 10)
      TimingBoundsUnitMatchesCode:
        human: boundsDuration.unit must match the UCUM boundsDuration.code (e.g. 'Woche(n)' only with code='wk').
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: "bounds.ofType(Duration).exists().not() or (\n  (\n    bounds.ofType(Duration).code = 'd'\n    implies \n    (\n      bounds.ofType(Duration).unit = 'Tag(e)' or\n      bounds.ofType(Duration).unit = 'Tag' or\n      bounds.ofType(Duration).unit = 'Tage'\n    )\n  ) and (\n    bounds.ofType(Duration).code = 'wk'\n    implies \n    (\n      bounds.ofType(Duration).unit = 'Woche(n)' or\n      bounds.ofType(Duration).unit = 'Woche' or\n      bounds.ofType(Duration).unit = 'Wochen'\n    )\n  ) and (\n    bounds.ofType(Duration).code = 'mo'\n    implies \n    (\n      bounds.ofType(Duration).unit = 'Monat(e)' or\n      bounds.ofType(Duration).unit = 'Monat' or\n      bounds.ofType(Duration).unit = 'Monate'\n    )\n  ) and (\n    bounds.ofType(Duration).code = 'a'\n    implies \n    (\n      bounds.ofType(Duration).unit = 'Jahr(e)' or\n      bounds.ofType(Duration).unit = 'Jahr' or\n      bounds.ofType(Duration).unit = 'Jahre'\n    )\n  )\n)"
      TimingFrequencyCount:
        human: If frequency is given together with when, timeOfDay or dayOfWeek, its value must match the number of concrete administrations.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          (when.exists() and dayOfWeek.empty() and frequency.exists() implies when.count() = frequency)
          and
          (when.exists() and dayOfWeek.exists() and frequency.exists() implies (when.count() * dayOfWeek.count()) = frequency)
          and
          (timeOfDay.exists() and dayOfWeek.empty() and frequency.exists() implies timeOfDay.count() = frequency)
          and
          (timeOfDay.exists() and dayOfWeek.exists() and frequency.exists() implies (timeOfDay.count() * dayOfWeek.count()) = frequency)
          and
          (dayOfWeek.exists() and timeOfDay.empty() and when.empty() and frequency.exists() implies dayOfWeek.count() = frequency)
      TimingOnlyOneTimeOfDay:
        human: In a schema that uses only timeOfDay, no time of day may occur in more than one of the Dosage elements that use this schema.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          ( /* Detect TimeOfDay */
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).where(
            timing.repeat.dayOfWeek.empty() and
            timing.repeat.timeOfDay.exists() and
            timing.repeat.when.empty()
          ).timing.repeat.timeOfDay.isDistinct()
      TimingBoundsPeriodFullDate: {human: 'boundsPeriod.start and boundsPeriod.end must state a full calendar date (YYYY-MM-DD, optionally with a time). FHIR dateTime also allows YYYY and YYYY-MM; the dosage text renders dates as DD.MM.YYYY and cannot represent a partial date.', source: 'http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP', severity: error, expression: (bounds.ofType(Period).start | bounds.ofType(Period).end).all(toString().length() >= 10)}
      TimingNoDuplicateValues: {human: 'Within a Timing, dayOfWeek, when and timeOfDay must not contain the same value more than once.', source: 'http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP', severity: error, expression: dayOfWeek.isDistinct() and when.isDistinct() and timeOfDay.isDistinct()}
      TimingValuesPositive:
        human: period, periodMax and boundsDuration.value must be greater than 0.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          (period.exists() implies period > 0) and
          (periodMax.exists() implies periodMax > 0) and
          bounds.ofType(Duration).value.all($this > 0)
      TimingOnlyOneTimeForInterval:
        human: In a schema that combines an interval with timeOfDay or when, all Dosage elements of a resource must use the same period, periodMax and periodUnit (periodMax either in all elements or in none), and each timeOfDay or when value must be unique across them.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          /* Detect Interval and Time/4-Schema */
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          )
          .where(
            timing.repeat.period.exists() and
            timing.repeat.periodUnit.exists() and
            timing.repeat.dayOfWeek.empty() and
            (
              (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or
              (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())
            )
          )
          .empty()
          or
          (
            (
              (
                %resource.ofType(MedicationRequest).exists()
                or %resource.ofType(MedicationDispense).exists()
              )
              implies
              (
                %resource.dosageInstruction.all(timing.repeat.period.exists() and timing.repeat.periodUnit.exists())
                and %resource.dosageInstruction.timing.repeat.period.distinct().count() = 1
                and %resource.dosageInstruction.timing.repeat.periodUnit.distinct().count() = 1
                and (
                  %resource.dosageInstruction.all(timing.repeat.periodMax.exists())
                  or %resource.dosageInstruction.all(timing.repeat.periodMax.empty())
                )
                and %resource.dosageInstruction.timing.repeat.periodMax.distinct().count() <= 1
              )
              and
              (
                (%resource.dosageInstruction.timing.repeat.timeOfDay.distinct().count() = %resource.dosageInstruction.timing.repeat.timeOfDay.count())
                and
                (%resource.dosageInstruction.timing.repeat.when.distinct().count() = %resource.dosageInstruction.timing.repeat.when.count())
              )
            )
            and
            (
              %resource.ofType(MedicationStatement).exists()
              implies
              (
                (
                  %resource.dosage.all(timing.repeat.period.exists() and timing.repeat.periodUnit.exists())
                  and %resource.dosage.timing.repeat.period.distinct().count() = 1
                  and %resource.dosage.timing.repeat.periodUnit.distinct().count() = 1
                  and (
                    %resource.dosage.all(timing.repeat.periodMax.exists())
                    or %resource.dosage.all(timing.repeat.periodMax.empty())
                  )
                  and %resource.dosage.timing.repeat.periodMax.distinct().count() <= 1
                )
                and
                (
                  (%resource.dosage.timing.repeat.timeOfDay.distinct().count() = %resource.dosage.timing.repeat.timeOfDay.count())
                  and
                  (%resource.dosage.timing.repeat.when.distinct().count() = %resource.dosage.timing.repeat.when.count())
                )
              )
            )
          )
      TimingIntervalOnlyOneFrequency:
        human: If a dosage is defined by a pure interval, only one Dosage element is allowed in the resource.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          ( /* Detect Interval */
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          )
          .all(
            (
              timing.repeat.frequency.exists()
              and timing.repeat.period.exists()
              and timing.repeat.periodUnit.exists()
              and timing.repeat.when.empty()
              and timing.repeat.timeOfDay.empty()
              and timing.repeat.dayOfWeek.empty()
            )
            /* Only One Dosage allowed for Interval */
            implies
            (
              (
                (
                  %resource.ofType(MedicationRequest).exists()
                  or %resource.ofType(MedicationDispense).exists()
                )
                implies (
                  %resource.dosageInstruction.count() = 1
                )
              )
              and
              (
                %resource.ofType(MedicationStatement).exists()
                implies
                %resource.dosage.count() = 1
              )
            )
          )
      TimingSingleDosageForWhen:
        human: If only when is used (without dayOfWeek), the times of day must be modelled in a single Dosage element, both for daily dosing and in an interval combination. Multiple Dosage elements are only allowed if every element carries a distinct dose, including its data type.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            (
              timing.repeat.dayOfWeek.empty() and
              timing.repeat.when.exists() and
              timing.repeat.timeOfDay.empty()
            )
            implies
            (
              (
                (
                  %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
                ).where(
                  timing.repeat.dayOfWeek.empty() and timing.repeat.when.exists() and timing.repeat.timeOfDay.empty()
                ).count() = 1
              )
              or
              (
                (
                  %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
                ).where(
                  timing.repeat.dayOfWeek.empty() and timing.repeat.when.exists() and timing.repeat.timeOfDay.empty()
                ).doseAndRate.dose.distinct().count()
                =
                (
                  %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
                ).where(
                  timing.repeat.dayOfWeek.empty() and timing.repeat.when.exists() and timing.repeat.timeOfDay.empty()
                ).count()
              )
            )
          )
      TimingOnlyWhenOrTimeOfDay:
        human: The Dosage elements of a resource must not mix a time of day (timeOfDay) and a part of the day (when).
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).where(
            timing.repeat.when.exists() or
            timing.repeat.timeOfDay.exists()
          ).empty()
          or
          (
            (
              (%resource.ofType(MedicationRequest).exists() or %resource.ofType(MedicationDispense).exists())
              implies
              (%resource.dosageInstruction.timing.repeat.when.exists() xor %resource.dosageInstruction.timing.repeat.timeOfDay.exists())
            )
            and
            (
              %resource.ofType(MedicationStatement).exists()
              implies
              (%resource.dosage.timing.repeat.when.exists() xor %resource.dosage.timing.repeat.timeOfDay.exists())
            )
          )
      TimingSingleDosageForTimeOfDay:
        human: If only timeOfDay is used (without dayOfWeek), the times must be modelled in a single Dosage element, both for daily dosing and in an interval combination. Multiple Dosage elements are only allowed if every element carries a distinct dose, including its data type.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            (
              timing.repeat.dayOfWeek.empty() and
              timing.repeat.timeOfDay.exists() and
              timing.repeat.when.empty()
            )
            implies
            (
              (
                (
                  %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
                ).where(
                  timing.repeat.dayOfWeek.empty() and timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()
                ).count() = 1
              )
              or
              (
                (
                  %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
                ).where(
                  timing.repeat.dayOfWeek.empty() and timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()
                ).doseAndRate.dose.distinct().count()
                =
                (
                  %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
                ).where(
                  timing.repeat.dayOfWeek.empty() and timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()
                ).count()
              )
            )
          )
      TimingPeriodOnlyWholeNumber: {human: period and periodMax must be whole numbers; decimal values are not allowed., source: 'http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP', severity: error, expression: (period.exists() implies period.truncate() = period) and (periodMax.exists() implies periodMax.truncate() = periodMax)}
      TimingPeriodUnit:
        human: periodUnit may only be given together with period. With dayOfWeek, only the redundant weekly statement is allowed; with when or timeOfDay without dayOfWeek, days, weeks or months are allowed.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          periodUnit.empty() or (
            period.exists() and
            (
              (dayOfWeek.exists() and periodUnit = 'wk' and period = 1) or
              (
                dayOfWeek.empty() and
                (
                  (when.empty() and timeOfDay.empty()) or
                  periodUnit = 'd' or
                  periodUnit = 'wk' or
                  periodUnit = 'mo'
                )
              )
            )
          )
      TimingVarFreqGtMin:
        human: For a variable frequency, the maximum frequency must be greater than the minimum frequency.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          frequencyMax.empty() or frequency.empty() or
            frequency.value.toInteger() < frequencyMax.value.toInteger()
      TimingFreqOrPeriodGtOne:
        human: 'If frequency and period are given together, only one of them may exceed 1 - either the frequency including frequencyMax or the period including periodMax. A statement in which both exceed 1, such as ''six times within three hours'', is hard to express in language and is not needed: the same meaning can be conveyed by adapting the period, e.g. ''every 30 minutes''. This also rules out combining a variable frequency with a variable period, such as ''1 to 3 times every 2 to 3 days'', because frequencyMax and periodMax are then both greater than 1.'
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          /* Detect Interval only */
          (
            timeOfDay.empty() and
            when.empty() and
            dayOfWeek.empty() and
            frequency.exists() and
            period.exists()
          ) implies
          (
            (
              (frequency > 1 or (frequencyMax.exists() and frequencyMax > 1))
              implies
              (
                period = 1 and
                (periodMax.empty() or periodMax = 1)
              )
            )
            and
            (
              (period > 1 or (periodMax.exists() and periodMax > 1))
              implies
              (
                frequency = 1 and
                (frequencyMax.empty() or frequencyMax = 1)
              )
            )
          )
      TimingOnlyOneBounds:
        human: All Dosage elements of a resource must state the same bounds (Duration or Period), and either all of them carry a bounds or none.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          /* Alle Dosage-Elemente tragen denselben Zeitrahmen: keines, alle dieselbe Dauer
             oder alle denselben Zeitraum (Start und Ende jeweils bei allen gleich oder bei
             allen fehlend). Die Textgenerierung liest den Zeitrahmen nur aus dem ersten
             Element. */
          (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Duration).empty() and timing.repeat.bounds.ofType(Period).empty())
          or
          (
            (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Duration).exists())
            and (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).timing.repeat.bounds.ofType(Duration).value.distinct().count() = 1
            and (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).timing.repeat.bounds.ofType(Duration).code.distinct().count() = 1
          )
          or
          (
            (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Period).exists())
            and (
              (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Period).start.exists())
              or (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Period).start.empty())
            )
            and (
              (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Period).end.exists())
              or (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).all(timing.repeat.bounds.ofType(Period).end.empty())
            )
            and (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).timing.repeat.bounds.ofType(Period).start.distinct().count() <= 1
            and (%resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)).timing.repeat.bounds.ofType(Period).end.distinct().count() <= 1
          )
      TimingBoundsDurationOnlyWholeNumber: {human: boundsDuration.value must be a whole number; decimal values are not allowed., source: 'http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP', severity: error, expression: bounds.ofType(Duration).value.all($this.truncate() = $this)}
      TimingOnlyOneWhen:
        human: In a schema that uses only when, no part of the day may occur in more than one of the Dosage elements that use this schema.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          ( /* Detect when-based schema */
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).where(
            timing.repeat.dayOfWeek.empty() and
            timing.repeat.when.exists() and
            timing.repeat.timeOfDay.empty()
          ).timing.repeat.when.isDistinct()
      TimingOnlyOneType:
        human: Exactly one of the supported timing schemas is allowed. With dayOfWeek, frequency and the pair period = 1 and periodUnit = wk are optional redundant legacy statements; they do not constitute an interval schema. With when or timeOfDay, frequency is optional; a non-daily period distinguishes the daily schema from a time interval combined with a time-of-day or clock-time reference. A variable frequency (frequencyMax) is reserved for the pure interval, because concrete times or weekdays already determine the number of administrations.
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          /* DayOfWeek only; legacy frequency and the exact 1 wk pair are optional */
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            timing.repeat.dayOfWeek.exists() and
            timing.repeat.when.empty() and
            timing.repeat.timeOfDay.empty() and
            timing.repeat.frequencyMax.empty() and
            timing.repeat.periodMax.empty() and
            (
              (timing.repeat.period.empty() and timing.repeat.periodUnit.empty()) or
              (timing.repeat.period = 1 and timing.repeat.periodUnit = 'wk')
            )
          ) or

          /* Interval only (frequency + period + periodUnit, no when/timeOfDay/dayOfWeek) */
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            timing.repeat.frequency.exists() and
            timing.repeat.period.exists() and
            timing.repeat.periodUnit.exists() and
            timing.repeat.when.empty() and
            timing.repeat.timeOfDay.empty() and
            timing.repeat.dayOfWeek.empty()
          ) or

          /* DayOfWeek and Time/4-Schema; legacy frequency and the exact 1 wk pair are optional */
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            timing.repeat.dayOfWeek.exists() and
            (
              (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or
              (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())
            ) and
            timing.repeat.frequencyMax.empty() and
            timing.repeat.periodMax.empty() and
            (
              (timing.repeat.period.empty() and timing.repeat.periodUnit.empty()) or
              (timing.repeat.period = 1 and timing.repeat.periodUnit = 'wk')
            )
          ) or

          /* Daily When or TimeOfDay; frequency is optional, a variable frequency is not */
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            timing.repeat.dayOfWeek.empty() and
            (
              (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or
              (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())
            ) and
            timing.repeat.frequencyMax.empty() and
            timing.repeat.periodMax.empty() and
            (
              (timing.repeat.period.empty() and timing.repeat.periodUnit.empty()) or
              (timing.repeat.period = 1 and timing.repeat.periodUnit = 'd')
            )
          ) or

          /* Non-daily interval combined with When or TimeOfDay; frequency is optional, a
             variable frequency is not */
          (
            %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
          ).all(
            timing.repeat.dayOfWeek.empty() and
            (
              (timing.repeat.timeOfDay.exists() and timing.repeat.when.empty()) or
              (timing.repeat.when.exists() and timing.repeat.timeOfDay.empty())
            ) and
            timing.repeat.frequencyMax.empty() and
            timing.repeat.period.exists() and
            timing.repeat.periodUnit.exists() and
            (timing.repeat.periodUnit = 'd' or timing.repeat.periodUnit = 'wk' or timing.repeat.periodUnit = 'mo') and
            (
              timing.repeat.periodUnit != 'd' or
              timing.repeat.period != 1 or
              timing.repeat.periodMax.exists()
            )
          )
      TimingBoundsPeriodMatchesTime:
        human: 'If timeOfDay is used and boundsPeriod.start or boundsPeriod.end states a time, it denotes the first or last administration and must therefore be one of the timeOfDay values of the resource. The time is compared as stated, so it has to be given in Europe/Berlin local time with the matching offset. Known limitation: this invariant does not validate the offset or convert time zones; applications must check consistency with Europe/Berlin separately.'
        source: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
        severity: error
        expression: |-
          timeOfDay.empty() or
          (bounds.ofType(Period).start | bounds.ofType(Period).end)
            .where(toString().length() > 10)
            .all(
              toString().substring(11, 8) in (
                %resource.ofType(MedicationRequest).dosageInstruction.combine(%resource.ofType(MedicationDispense).dosageInstruction).combine(%resource.ofType(MedicationStatement).dosage)
              ).timing.repeat.timeOfDay.select(toString().substring(0, 8))
            )
    index: 1
    elements:
      boundsPeriod:
        type: Period
        short: Start- und Endzeitpunkt der Dosieranweisung.
        choiceOf: bounds
        index: 16
        slicing:
          slices:
            boundsPeriod:
              match: {}
              schema: {type: Period, short: Start- und Endzeitpunkt der Dosieranweisung., choiceOf: bounds, index: 16}
      when:
        binding: {strength: required, valueSet: 'http://ig.fhir.de/igs/medication/ValueSet/TimingWhenDgMP'}
        index: 27
      offset: {short: Zeitversatz, index: 28}
      periodUnit:
        short: min | h | d | wk | mo - Zeiteinheit (UCUM)
        binding: {strength: required, valueSet: 'http://ig.fhir.de/igs/medication/ValueSet/PeriodUnitsOfTimeDgMP'}
        index: 26
      durationMax: {index: 22}
      duration: {index: 21}
      bounds:
        short: Start- und Endzeitpunkt der Dosieranweisung.
        choices: [boundsPeriod]
        index: 15
        slicing:
          slices:
            boundsPeriod:
              match: {}
              schema:
                short: Start- und Endzeitpunkt der Dosieranweisung.
                choices: [boundsPeriod]
                index: 15
      boundsDuration:
        type: Duration
        choiceOf: bounds
        index: 8
        slicing:
          slices:
            boundsDuration:
              match: {}
              schema: {type: Duration, choiceOf: bounds, index: 8}
      durationUnit: {index: 23}
      count: {index: 19}
      bounds[x]:
        elements:
          start: {short: Startdatum mit optionaler Uhrzeit und Zeitzone, index: 17}
          end: {short: Enddatum mit optionaler Uhrzeit und Zeitzone, index: 18}
      periodMax: {short: 'Obergrenze der Periode, ganze Zahl größer als period', index: 25}
      period: {short: 'Periode, ganze Zahl größer als 0', index: 24}
      countMax: {index: 20}
  code: {index: 29}
package_version: 2.0.0
class: complex-type
kind: complex-type
url: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDgMP
base: http://ig.fhir.de/igs/medication/StructureDefinition/TimingDE
version: 2.0.0
required: [repeat]