<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="profile-ClaimResponse" />
  <url value="https://bpcs.exchange/fhir/StructureDefinition/profile-ClaimResponse" />
  <name value="ClaimResponse" />
  <title value="Claim Response" />
  <status value="active" />
  <experimental value="false" />
  <description value="The information returned by BPCS in response to a claims submission" />
  <fhirVersion value="5.0.0" />
  <mapping>
    <identity value="BPCS" />
    <name value="Internal BPCS API" />
  </mapping>
  <kind value="resource" />
  <abstract value="true" />
  <type value="ClaimResponse" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/ClaimResponse" />
  <derivation value="constraint" />
  <differential>
    <element id="ClaimResponse.contained">
      <path value="ClaimResponse.contained" />
      <slicing>
        <discriminator>
          <type value="profile" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="ClaimResponse.contained:duplicates">
      <path value="ClaimResponse.contained" />
      <sliceName value="duplicates" />
      <max value="1" />
      <type>
        <code value="ExplanationOfBenefit" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/profile-ExplanationOfBenefit-duplicate" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.contained:dispenses">
      <path value="ClaimResponse.contained" />
      <sliceName value="dispenses" />
      <type>
        <code value="MedicationDispense" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/profile-MedicationDispense" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.status">
      <path value="ClaimResponse.status" />
      <short value="draft | active" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://bpcs.exchange/fhir/ValueSet/vs-FinancialStatus" />
      </binding>
      <mapping>
        <identity value="BPCS" />
        <map value="BatchRecordDTO.batchStatus" />
      </mapping>
    </element>
    <element id="ClaimResponse.type">
      <path value="ClaimResponse.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://terminology.hl7.org/CodeSystem/claim-type" />
          <code value="pharmacy" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="ClaimResponse.use">
      <path value="ClaimResponse.use" />
      <patternCode value="claim" />
    </element>
    <element id="ClaimResponse.patient">
      <path value="ClaimResponse.patient" />
      <type>
        <code value="Reference" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/profile-Reference-group-or-patient" />
        <targetProfile value="https://bpcs.exchange/fhir/StructureDefinition/profile-Patient-create" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.created">
      <path value="ClaimResponse.created" />
      <comment value="This is the 'current' date when the ClaimResponse is produced" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.insurer">
      <path value="ClaimResponse.insurer" />
      <patternReference>
        <reference value="Organization/bpcs" />
      </patternReference>
    </element>
    <element id="ClaimResponse.request">
      <path value="ClaimResponse.request" />
      <comment value="References SHALL be a reference to an actual FHIR resource, and SHALL be resolvable (allowing for access control, temporary unavailability, etc.). Resolution can be either by retrieval from the URL, or, where applicable by resource type, by treating an absolute reference as a canonical URL and looking it up in a local registry/repository.&#xD;&#xA;  This will only be present if the submitted Claim has an id (because the Claim has previously been held)" />
      <type>
        <code value="Reference" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/profile-Reference-rest" />
        <targetProfile value="https://bpcs.exchange/fhir/StructureDefinition/profile-Claim-create" />
      </type>
      <mustSupport value="true" />
      <mapping>
        <identity value="BPCS" />
        <map value="BatchRecordDTO.dateReceived (second-last component of id), BatchRecordDTO.batchSeqNum (last component of id)" />
      </mapping>
    </element>
    <element id="ClaimResponse.outcome">
      <path value="ClaimResponse.outcome" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item">
      <path value="ClaimResponse.item" />
      <comment value="There will be a ClaimResponse.item for each item in the associated claim submission" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.extension">
      <path value="ClaimResponse.item.extension" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.extension:receiptPlan">
      <path value="ClaimResponse.item.extension" />
      <sliceName value="receiptPlan" />
      <min value="1" />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-Resource-ReceiptPlan" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.extension:presetModifier">
      <path value="ClaimResponse.item.extension" />
      <sliceName value="presetModifier" />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-ClaimResponse-PresetModifier" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.itemSequence">
      <path value="ClaimResponse.item.itemSequence" />
      <comment value="This will match the Claim.item.sequence of the corresponding repetition in the associated Claim submission" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome">
      <path value="ClaimResponse.item.reviewOutcome" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome.extension:info">
      <path value="ClaimResponse.item.reviewOutcome.extension" />
      <sliceName value="info" />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-ClaimResponse-Info" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome.decision">
      <path value="ClaimResponse.item.reviewOutcome.decision" />
      <min value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://bpcs.exchange/fhir/ValueSet/vs-Receipt-status" />
      </binding>
    </element>
    <element id="ClaimResponse.item.reviewOutcome.reason">
      <path value="ClaimResponse.item.reviewOutcome.reason" />
      <comment value="If multiple issues are identified, there is no specific order in which they should be displayed or addressed.  In some cases, a UI might display and allow addressing all issues at once." />
      <mustSupport value="true" />
      <binding>
        <strength value="extensible" />
        <valueSet value="https://bpcs.exchange/fhir/ValueSet/vs-ClaimResponse" />
      </binding>
      <mapping>
        <identity value="BPCS" />
        <map value="AssessContext.responseCodes, AssessmentFlag.(various EFlags)" />
      </mapping>
    </element>
    <element id="ClaimResponse.item.reviewOutcome.reason.extension:allowedModifier">
      <path value="ClaimResponse.item.reviewOutcome.reason.extension" />
      <sliceName value="allowedModifier" />
      <comment value="Indicates modifier codes permitted to override for this response code (if any)." />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-ClaimResponse-AllowedModifier" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome.reason.extension:allowedModifier.value[x]">
      <path value="ClaimResponse.item.reviewOutcome.reason.extension.value[x]" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome.reason.extension:allowedModifier.value[x].extension:default">
      <path value="ClaimResponse.item.reviewOutcome.reason.extension.value[x].extension" />
      <sliceName value="default" />
      <comment value="May only be present on one modifier within a reason." />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-ClaimResponse-AllowedModifierDefault" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome.reason.extension:allowedModifier.value[x].extension:preExistingCondition">
      <path value="ClaimResponse.item.reviewOutcome.reason.extension.value[x].extension" />
      <sliceName value="preExistingCondition" />
      <comment value="Only allowed where an 'allowed modifier' is a health condition." />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-ClaimResponse-PreExistingCondition" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.reviewOutcome.reason.extension:duplicate">
      <path value="ClaimResponse.item.reviewOutcome.reason.extension" />
      <sliceName value="duplicate" />
      <comment value="This will only be present if the reason code is ED and then only if there is not an exact match.  If present, the user must identify which of the submitted claims from the pharmacy point of service correspond to the manually submitted receipt.  This allows information such as coverage from other payers to be taken into account when adjudicating the paper claim.  The selected duplicate will then be conveyed in the 'duplicateVersion' extension when re-adjudicating the receipt." />
      <type>
        <code value="Extension" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/ext-ClaimResponse-DuplicateReceipts" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.adjudication">
      <path value="ClaimResponse.item.adjudication" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="category" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="2" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.adjudication:eligible">
      <path value="ClaimResponse.item.adjudication" />
      <sliceName value="eligible" />
      <short value="Eligible amount" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.adjudication:eligible.category">
      <path value="ClaimResponse.item.adjudication.category" />
      <patternCodeableConcept>
        <coding>
          <system value="http://terminology.hl7.org/CodeSystem/adjudication" />
          <code value="eligible" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="ClaimResponse.item.adjudication:eligible.amount">
      <path value="ClaimResponse.item.adjudication.amount" />
      <min value="1" />
      <type>
        <code value="Money" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/profile-Money-CAD-NonNeg" />
      </type>
      <mustSupport value="true" />
      <mapping>
        <identity value="BPCS" />
        <map value="ReceiptDTO.allowedRxExp" />
      </mapping>
    </element>
    <element id="ClaimResponse.item.adjudication:benefit">
      <path value="ClaimResponse.item.adjudication" />
      <sliceName value="benefit" />
      <short value="Benefit amount" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="ClaimResponse.item.adjudication:benefit.category">
      <path value="ClaimResponse.item.adjudication.category" />
      <patternCodeableConcept>
        <coding>
          <system value="http://terminology.hl7.org/CodeSystem/adjudication" />
          <code value="benefit" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="ClaimResponse.item.adjudication:benefit.amount">
      <path value="ClaimResponse.item.adjudication.amount" />
      <min value="1" />
      <type>
        <code value="Money" />
        <profile value="https://bpcs.exchange/fhir/StructureDefinition/profile-Money-CAD-NonNeg" />
      </type>
      <mustSupport value="true" />
      <mapping>
        <identity value="BPCS" />
        <map value="ReceiptDTO.reimbAmt" />
      </mapping>
    </element>
  </differential>
</StructureDefinition>