<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="erp-service-request-prescription-request" />
  <url value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-prescription-request" />
  <version value="1.2.0" />
  <name value="ERPServiceRequestPrescriptionRequest" />
  <title value="ERP Service Request Rezeptanforderung" />
  <status value="active" />
  <experimental value="false" />
  <date value="2025-07-31" />
  <publisher value="gematik GmbH" />
  <description value="ServiceRequest, der zur Anforderung eines Rezepts verwendet wird" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="ServiceRequest" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/ServiceRequest" />
  <derivation value="constraint" />
  <differential>
    <element id="ServiceRequest">
      <path value="ServiceRequest" />
      <constraint>
        <key value="servicerequest-prescription-request-1" />
        <severity value="error" />
        <human value="Wenn der Status aktiv ist, muss der Anforderer vorhanden sein." />
        <expression value="status = 'active' implies requester.exists()" />
        <source value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-prescription-request" />
      </constraint>
      <constraint>
        <key value="servicerequest-prescription-request-2" />
        <severity value="error" />
        <human value="Wenn der Status abgeschlossen ist und das Rezept vom Patienten eingelöst werden soll, darf der E-Rezept-Token nicht vorhanden sein." />
        <expression value="(status = 'completed' and modifierExtension.where(url = 'https://gematik.de/fhir/erp-servicerequest/StructureDefinition/redeem-by-patient-ex').exists() and modifierExtension.where(url = 'https://gematik.de/fhir/erp-servicerequest/StructureDefinition/redeem-by-patient-ex').value = true) implies extension.where(url = 'https://gematik.de/fhir/erp-servicerequest/StructureDefinition/eprescription-token-ex').exists().not()" />
        <source value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-prescription-request" />
      </constraint>
      <constraint>
        <key value="servicerequest-prescription-request-3" />
        <severity value="error" />
        <human value="Wenn der Status widerrufen oder fehlerhaft eingegeben ist, muss der Grund oder eine Notiz vorhanden sein." />
        <expression value="(status = 'revoked' or status = 'entered-in-error') implies (reasonCode.text.exists() or note.exists())" />
        <source value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-prescription-request" />
      </constraint>
      <constraint>
        <key value="servicerequest-prescription-request-4" />
        <severity value="error" />
        <human value="Wenn der Status abgeschlossen ist, muss der Durchführende vorhanden sein." />
        <expression value="status = 'completed' implies performer.exists()" />
        <source value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-prescription-request" />
      </constraint>
      <constraint>
        <key value="servicerequest-prescription-request-5" />
        <severity value="error" />
        <human value="Wenn der Status abgeschlossen ist und das Rezept nicht vom Patienten eingelöst werden soll, muss der E-Rezept-Token vorhanden sein." />
        <expression value="(status = 'completed' and (modifierExtension.where(url = 'https://gematik.de/fhir/erp-servicerequest/StructureDefinition/redeem-by-patient-ex').value = false or modifierExtension.where(url = 'https://gematik.de/fhir/erp-servicerequest/StructureDefinition/redeem-by-patient-ex').exists().not())) implies extension.where(url = 'https://gematik.de/fhir/erp-servicerequest/StructureDefinition/eprescription-token-ex').exists()" />
        <source value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-prescription-request" />
      </constraint>
    </element>
    <element id="ServiceRequest.extension">
      <path value="ServiceRequest.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.extension:EPrescriptionToken">
      <path value="ServiceRequest.extension" />
      <sliceName value="EPrescriptionToken" />
      <short value="Here the e-prescription token(s) can be made available for processing in a pharmacy." />
      <definition value="One ServiceRequest must adress exactly one request for a medication. However the practitioner might choose to issue multiple prescriptions for that request, therefore the cardinality is 1..*." />
      <comment value="The token is of the form '/Task/{PrescriptionID}/$accept?ac={AccessCode}. See [gemSpec_DM_eRp](https://fachportal.gematik.de/fachportal-import/files/gemSpec_DM_eRp_V1.5.0.pdf)'." />
      <min value="0" />
      <max value="*" />
      <type>
        <code value="Extension" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/eprescription-token-ex" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.modifierExtension">
      <path value="ServiceRequest.modifierExtension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
    </element>
    <element id="ServiceRequest.modifierExtension:medicationChanged">
      <path value="ServiceRequest.modifierExtension" />
      <sliceName value="medicationChanged" />
      <short value="Indicates whether the medication has been changed by the prescriber." />
      <definition value="If the medication has been changed, the value is set to true." />
      <comment value="If the medication has been changed, the receiving system must display the changed medication to the receiving user." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/changed-medication-ex" />
      </type>
      <mustSupport value="true" />
      <isModifierReason value="If the medication has been changed, the receiving system must display the changed medication to the receiving user." />
    </element>
    <element id="ServiceRequest.modifierExtension:redeemByPatient">
      <path value="ServiceRequest.modifierExtension" />
      <sliceName value="redeemByPatient" />
      <short value="Redeem By Patient" />
      <definition value="Indicates whether the prescription should be redeemed by the patient." />
      <comment value="This determines the Flow Type of the prescription to be set to 160/200 so that the patient can redeem the prescription himself. If not set the Flow Type is set to 169/209." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/redeem-by-patient-ex" />
      </type>
      <mustSupport value="true" />
      <isModifierReason value="This determines the Flow Type of the prescription to be set to 160/200 so that the patient can redeem the prescription himself. If not set the Flow Type is set to 169/209." />
    </element>
    <element id="ServiceRequest.identifier">
      <path value="ServiceRequest.identifier" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <short value="Defines identifiers to be used in this profile." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.identifier:requestId">
      <path value="ServiceRequest.identifier" />
      <sliceName value="requestId" />
      <short value="Identifier that uniquely references a ServiceRequest." />
      <comment value="For referencing and assignment of ServiceRequest, e.g. if one ServiceRequest is to replace another, it is important to be able to make this assignment with the identifier. Can be mapped via a UUID, for example." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Identifier" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-request-identifier" />
      </type>
    </element>
    <element id="ServiceRequest.basedOn">
      <path value="ServiceRequest.basedOn" />
      <short value="Requested or fulfilled MedicationRequest." />
      <definition value="This field references the underlying MedicationRequest, which contains the medical information for the prescription request." />
      <comment value="Exactly one MedicationRequest is assigned to a ServiceRequest, so that independent processing is possible." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-medication-request" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.requisition">
      <path value="ServiceRequest.requisition" />
      <short value="Identifier of the overall process. Multiple ServiceRequests within a process are allocated the same ID." />
      <comment value="Is to be understood as a case or process ID (see mapping) in order to be able to track which request the ServiceRequest belongs to." />
      <min value="1" />
      <type>
        <code value="Identifier" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-procedure-identifier" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.status">
      <path value="ServiceRequest.status" />
      <short value="Indicates the processing status of a service request." />
      <comment value="If the status changes, this value is overwritten." />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://gematik.de/fhir/erp-servicerequest/ValueSet/service-request-status-vs" />
      </binding>
    </element>
    <element id="ServiceRequest.intent">
      <path value="ServiceRequest.intent" />
      <fixedCode value="order" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.priority">
      <path value="ServiceRequest.priority" />
      <short value="Indicates the urgency of the request." />
      <definition value="The priority can be used to indicate the urgency of the request." />
      <comment value="Allowed values: routine | urgent" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://gematik.de/fhir/erp-servicerequest/ValueSet/service-request-priority-vs" />
      </binding>
    </element>
    <element id="ServiceRequest.code">
      <path value="ServiceRequest.code" />
      <short value="Indicates the type of service request." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.code.coding">
      <path value="ServiceRequest.code.coding" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="$this" />
        </discriminator>
        <description value="Differentiates between the service request type and additional information." />
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.code.coding:request-type">
      <path value="ServiceRequest.code.coding" />
      <sliceName value="request-type" />
      <short value="Indicates the type of service request." />
      <min value="1" />
      <max value="1" />
      <patternCoding>
        <system value="https://gematik.de/fhir/erp-servicerequest/CodeSystem/service-request-type-cs" />
        <code value="prescription-request" />
      </patternCoding>
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://gematik.de/fhir/erp-servicerequest/ValueSet/service-request-type-vs" />
      </binding>
    </element>
    <element id="ServiceRequest.code.coding:request-type.system">
      <path value="ServiceRequest.code.coding.system" />
      <min value="1" />
    </element>
    <element id="ServiceRequest.code.coding:request-type.code">
      <path value="ServiceRequest.code.coding.code" />
      <comment value="#prescription-request defines this ServiceRequest as a prescription request from a requester to a doctor." />
      <min value="1" />
    </element>
    <element id="ServiceRequest.subject">
      <path value="ServiceRequest.subject" />
      <short value="Patient for whom a prescription is requested on behalf of the patient." />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-patient" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.occurrence[x]">
      <path value="ServiceRequest.occurrence[x]" />
      <short value="Specifies the date on which the prescription is to be issued (Bedarfszeitraum)." />
      <comment value="Can be used by the requester to make the timely urgency clear." />
      <type>
        <code value="dateTime" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.authoredOn">
      <path value="ServiceRequest.authoredOn" />
      <short value="Creation date of the request." />
      <comment value="Is initially created and then no longer changed." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.requester">
      <path value="ServiceRequest.requester" />
      <short value="Inquiring facility or practitioner." />
      <comment value="The KIM address is already stored in the message header." />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-organization" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.performer">
      <path value="ServiceRequest.performer" />
      <short value="Doctor who is to issue the prescription." />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-practitioner" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.reasonCode">
      <path value="ServiceRequest.reasonCode" />
      <short value="Reason for the prescription request." />
      <comment value="The reason for the prescription request can be documented here." />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.reasonCode.extension">
      <path value="ServiceRequest.reasonCode.extension" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.reasonCode.extension:remainingSupply">
      <path value="ServiceRequest.reasonCode.extension" />
      <sliceName value="remainingSupply" />
      <short value="Remaining supply" />
      <definition value="Indicates the remaining supply of the medication." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/remaining-supply-ex" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.reasonCode.extension:remainingSupplyFreeText">
      <path value="ServiceRequest.reasonCode.extension" />
      <sliceName value="remainingSupplyFreeText" />
      <short value="Remaining supply as free text" />
      <definition value="Here the remaining supply of the medication can be stated as free text." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/remaining-supply-free-text-ex" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.reasonCode.coding">
      <path value="ServiceRequest.reasonCode.coding" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://gematik.de/fhir/erp-servicerequest/ValueSet/medication-request-reason-vs" />
      </binding>
    </element>
    <element id="ServiceRequest.reasonCode.text">
      <path value="ServiceRequest.reasonCode.text" />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.supportingInfo">
      <path value="ServiceRequest.supportingInfo" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="type" />
        </discriminator>
        <description value="Additional information on the prescription request." />
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.supportingInfo:pflegeeinrichtungKopie">
      <path value="ServiceRequest.supportingInfo" />
      <sliceName value="pflegeeinrichtungKopie" />
      <short value="Reference to the care facility that receives a copy of the prescription." />
      <comment value="This needs to be set if the initiating Requester is a pharmacy." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/erp-servicerequest/StructureDefinition/erp-service-request-organization" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.supportingInfo:pflegeeinrichtungKopie.type">
      <path value="ServiceRequest.supportingInfo.type" />
      <min value="1" />
      <patternUri value="Organization" />
    </element>
    <element id="ServiceRequest.note">
      <path value="ServiceRequest.note" />
      <short value="Further information on the prescription request." />
      <comment value="Any use cases that are not specified can be placed here in free text." />
      <mustSupport value="true" />
    </element>
    <element id="ServiceRequest.note.time">
      <path value="ServiceRequest.note.time" />
      <comment value="This is used in order to sort the Annotations" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>