<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="DOCUMENT-REFERENCE-LETTER-TEMPLATE" />
  <url value="https://health.gov.on.ca/idms/fhir/StructureDefinition/IDMS-DocumentReference-Letter-Template" />
  <version value="1.0.0" />
  <name value="IDMSDocumentLetterTemplate" />
  <title value="IDMS - DocumentReference - Letter Template" />
  <status value="active" />
  <description value="These are letter templates,  they need to be searchable by type, category, product type, submission type and review path" />
  <fhirVersion value="5.0.0" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="DocumentReference" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/DocumentReference" />
  <derivation value="constraint" />
  <differential>
    <element id="DocumentReference.identifier">
      <path value="DocumentReference.identifier" />
      <short value="Template Identifier" />
      <definition value="#### **_`IDMS:  This is the template's unique identifier. When a letter is generated this identfier is saved with the letter (see DocumentReference.content.profile.valueURI) so we can trace back which template was used.`_**" />
      <min value="1" />
    </element>
    <element id="DocumentReference.identifier.extension">
      <path value="DocumentReference.identifier.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.identifier.use">
      <path value="DocumentReference.identifier.use" />
      <max value="0" />
    </element>
    <element id="DocumentReference.identifier.type">
      <path value="DocumentReference.identifier.type" />
      <max value="0" />
    </element>
    <element id="DocumentReference.identifier.type.coding.system">
      <path value="DocumentReference.identifier.type.coding.system" />
      <min value="1" />
    </element>
    <element id="DocumentReference.identifier.type.coding.code">
      <path value="DocumentReference.identifier.type.coding.code" />
      <min value="1" />
    </element>
    <element id="DocumentReference.identifier.type.coding.display">
      <path value="DocumentReference.identifier.type.coding.display" />
      <min value="1" />
    </element>
    <element id="DocumentReference.identifier.system">
      <path value="DocumentReference.identifier.system" />
      <short value="Primary File Number System" />
      <definition value="IDMS's Primary File Number System" />
      <min value="1" />
      <fixedUri value="urn:idms:letter:template" />
    </element>
    <element id="DocumentReference.identifier.value">
      <path value="DocumentReference.identifier.value" />
      <short value="Primary File Number" />
      <definition value="#### **_`IDMS: Letter template unique identifier. Format urn:idms:template + template name +  .v  + version number    `_**" />
      <min value="1" />
    </element>
    <element id="DocumentReference.identifier.period">
      <path value="DocumentReference.identifier.period" />
      <max value="0" />
    </element>
    <element id="DocumentReference.identifier.assigner">
      <path value="DocumentReference.identifier.assigner" />
      <max value="0" />
    </element>
    <element id="DocumentReference.version">
      <path value="DocumentReference.version" />
      <max value="0" />
    </element>
    <element id="DocumentReference.basedOn">
      <path value="DocumentReference.basedOn" />
      <max value="0" />
    </element>
    <element id="DocumentReference.status">
      <path value="DocumentReference.status" />
      <definition value="#### **_`IDMS:  This is mandatory according to FHIR, it will always be 'current'.`_**" />
    </element>
    <element id="DocumentReference.docStatus">
      <path value="DocumentReference.docStatus" />
      <max value="0" />
    </element>
    <element id="DocumentReference.modality">
      <path value="DocumentReference.modality" />
      <max value="0" />
    </element>
    <element id="DocumentReference.type">
      <path value="DocumentReference.type" />
      <definition value="#### **_`IDMS:  This is the Letter Template Type.  Example 'NDSS - Complete'.`_**" />
      <min value="1" />
    </element>
    <element id="DocumentReference.type.extension">
      <path value="DocumentReference.type.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.type.coding">
      <path value="DocumentReference.type.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="DocumentReference.type.coding.extension">
      <path value="DocumentReference.type.coding.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.type.coding.system">
      <path value="DocumentReference.type.coding.system" />
      <min value="1" />
      <fixedUri value="https://health.gov.on.ca/idms/fhir/CodeSystem/IDMS-Internal" />
    </element>
    <element id="DocumentReference.type.coding.version">
      <path value="DocumentReference.type.coding.version" />
      <max value="0" />
    </element>
    <element id="DocumentReference.type.coding.code">
      <path value="DocumentReference.type.coding.code" />
      <min value="1" />
      <binding>
        <strength value="required" />
        <valueSet value="https://health.gov.on.ca/idms/fhir/ValueSet/IDMS-DocumentReference-Letter-Types" />
      </binding>
    </element>
    <element id="DocumentReference.type.coding.display">
      <path value="DocumentReference.type.coding.display" />
    </element>
    <element id="DocumentReference.type.coding.userSelected">
      <path value="DocumentReference.type.coding.userSelected" />
      <max value="0" />
    </element>
    <element id="DocumentReference.type.text">
      <path value="DocumentReference.type.text" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category">
      <path value="DocumentReference.category" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="coding.version" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <short value="Classifications of the Letter Template" />
      <definition value="#### **_`IDMS: Category, Product Type , Submission Type , Generic Type .`_**" />
      <max value="4" />
    </element>
    <element id="DocumentReference.category:RequestCategory">
      <path value="DocumentReference.category" />
      <sliceName value="RequestCategory" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:RequestCategory.extension">
      <path value="DocumentReference.category.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:RequestCategory.coding">
      <path value="DocumentReference.category.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:RequestCategory.coding.extension">
      <path value="DocumentReference.category.coding.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:RequestCategory.coding.system">
      <path value="DocumentReference.category.coding.system" />
      <min value="1" />
      <fixedUri value="https://health.gov.on.ca/idms/fhir/CodeSystem/Internal-Request-Category-Types" />
    </element>
    <element id="DocumentReference.category:RequestCategory.coding.version">
      <path value="DocumentReference.category.coding.version" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:RequestCategory.coding.code">
      <path value="DocumentReference.category.coding.code" />
      <min value="1" />
      <binding>
        <strength value="required" />
        <description value="Request Category" />
        <valueSet value="https://health.gov.on.ca/idms/fhir/ValueSet/Request-Category" />
      </binding>
    </element>
    <element id="DocumentReference.category:RequestCategory.coding.display">
      <path value="DocumentReference.category.coding.display" />
      <min value="1" />
    </element>
    <element id="DocumentReference.category:RequestCategory.coding.userSelected">
      <path value="DocumentReference.category.coding.userSelected" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:RequestCategory.text">
      <path value="DocumentReference.category.text" />
      <short value="Distinquishes this as the ProductType Code,  has a fixed value of 'ProductType'" />
      <max value="0" />
      <fixedString value="RequestCategory" />
    </element>
    <element id="DocumentReference.category:ProductType">
      <path value="DocumentReference.category" />
      <sliceName value="ProductType" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:ProductType.extension">
      <path value="DocumentReference.category.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:ProductType.coding">
      <path value="DocumentReference.category.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:ProductType.coding.extension">
      <path value="DocumentReference.category.coding.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:ProductType.coding.system">
      <path value="DocumentReference.category.coding.system" />
      <short value="IDMS Product Submission Code System" />
      <min value="1" />
      <fixedUri value="https://health.gov.on.ca/idms/fhir/CodeSystem/Internal-Product-Types" />
    </element>
    <element id="DocumentReference.category:ProductType.coding.version">
      <path value="DocumentReference.category.coding.version" />
      <short value="Type of Code" />
      <definition value="This being used as the discriminator,  it is the type of code.  (The version of the code system is not relevant in IDMS so this is being reused)" />
      <max value="0" />
      <fixedString value="ProductType" />
    </element>
    <element id="DocumentReference.category:ProductType.coding.code">
      <path value="DocumentReference.category.coding.code" />
      <short value="This is the Product Type Code" />
      <min value="1" />
      <binding>
        <strength value="required" />
        <description value="List of Product Types" />
        <valueSet value="https://health.gov.on.ca/idms/fhir/ValueSet/IDMS-Product-Types" />
      </binding>
    </element>
    <element id="DocumentReference.category:ProductType.coding.display">
      <path value="DocumentReference.category.coding.display" />
      <short value="Display Value for the Product Type code" />
      <min value="1" />
    </element>
    <element id="DocumentReference.category:ProductType.coding.userSelected">
      <path value="DocumentReference.category.coding.userSelected" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:ProductType.text">
      <path value="DocumentReference.category.text" />
      <short value="Distinquishes this as the ProductType Code,  has a fixed value of 'ProductType'" />
      <max value="0" />
      <fixedString value="ProductType" />
    </element>
    <element id="DocumentReference.category:SubmissionType">
      <path value="DocumentReference.category" />
      <sliceName value="SubmissionType" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:SubmissionType.extension">
      <path value="DocumentReference.category.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:SubmissionType.coding">
      <path value="DocumentReference.category.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:SubmissionType.coding.extension">
      <path value="DocumentReference.category.coding.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:SubmissionType.coding.system">
      <path value="DocumentReference.category.coding.system" />
      <min value="1" />
      <fixedUri value="https://health.gov.on.ca/idms/fhir/CodeSystem/Internal-Submission-Types" />
    </element>
    <element id="DocumentReference.category:SubmissionType.coding.version">
      <path value="DocumentReference.category.coding.version" />
      <short value="Type of Code" />
      <definition value="This being used as the discriminator,  it is the type of code.  (The version of the code system is not relevant in IDMS so this is being reused)" />
      <max value="0" />
      <fixedString value="SubmissionType" />
    </element>
    <element id="DocumentReference.category:SubmissionType.coding.code">
      <path value="DocumentReference.category.coding.code" />
      <short value="This is the Submission Code" />
      <min value="1" />
      <binding>
        <strength value="required" />
        <description value="Submission Types" />
        <valueSet value="https://health.gov.on.ca/idms/fhir/ValueSet/IDMS-Submission-Types" />
      </binding>
    </element>
    <element id="DocumentReference.category:SubmissionType.coding.display">
      <path value="DocumentReference.category.coding.display" />
      <short value="This is the display Value for the Submission Code" />
      <min value="1" />
    </element>
    <element id="DocumentReference.category:SubmissionType.coding.userSelected">
      <path value="DocumentReference.category.coding.userSelected" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:SubmissionType.text">
      <path value="DocumentReference.category.text" />
      <short value="Distinquishes this as the SubmissionType Code,  has a fixed value of 'SubmissionType'" />
      <max value="0" />
      <fixedString value="SubmissionType" />
    </element>
    <element id="DocumentReference.category:GenericClassification">
      <path value="DocumentReference.category" />
      <sliceName value="GenericClassification" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:GenericClassification.extension">
      <path value="DocumentReference.category.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:GenericClassification.coding">
      <path value="DocumentReference.category.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="DocumentReference.category:GenericClassification.coding.extension">
      <path value="DocumentReference.category.coding.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:GenericClassification.coding.system">
      <path value="DocumentReference.category.coding.system" />
      <min value="1" />
      <fixedUri value="https://health.gov.on.ca/idms/fhir/CodeSystem/Generic-Classification" />
    </element>
    <element id="DocumentReference.category:GenericClassification.coding.version">
      <path value="DocumentReference.category.coding.version" />
      <short value="Type of Code" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:GenericClassification.coding.code">
      <path value="DocumentReference.category.coding.code" />
      <min value="1" />
      <binding>
        <strength value="required" />
        <description value="Request Types" />
        <valueSet value="https://health.gov.on.ca/idms/fhir/ValueSet/IDMS-New-Generic-Classification" />
      </binding>
    </element>
    <element id="DocumentReference.category:GenericClassification.coding.display">
      <path value="DocumentReference.category.coding.display" />
      <short value="This is the display Value for the Request Type" />
      <min value="1" />
    </element>
    <element id="DocumentReference.category:GenericClassification.coding.userSelected">
      <path value="DocumentReference.category.coding.userSelected" />
      <max value="0" />
    </element>
    <element id="DocumentReference.category:GenericClassification.text">
      <path value="DocumentReference.category.text" />
      <max value="0" />
    </element>
    <element id="DocumentReference.subject">
      <path value="DocumentReference.subject" />
      <max value="0" />
    </element>
    <element id="DocumentReference.context">
      <path value="DocumentReference.context" />
      <max value="0" />
    </element>
    <element id="DocumentReference.event">
      <path value="DocumentReference.event" />
      <max value="0" />
    </element>
    <element id="DocumentReference.bodySite">
      <path value="DocumentReference.bodySite" />
      <max value="0" />
    </element>
    <element id="DocumentReference.facilityType">
      <path value="DocumentReference.facilityType" />
      <max value="0" />
    </element>
    <element id="DocumentReference.practiceSetting">
      <path value="DocumentReference.practiceSetting" />
      <max value="0" />
    </element>
    <element id="DocumentReference.period">
      <path value="DocumentReference.period" />
      <max value="0" />
    </element>
    <element id="DocumentReference.date">
      <path value="DocumentReference.date" />
      <max value="0" />
    </element>
    <element id="DocumentReference.author">
      <path value="DocumentReference.author" />
      <max value="0" />
    </element>
    <element id="DocumentReference.attester">
      <path value="DocumentReference.attester" />
      <max value="0" />
    </element>
    <element id="DocumentReference.custodian">
      <path value="DocumentReference.custodian" />
      <max value="0" />
    </element>
    <element id="DocumentReference.relatesTo">
      <path value="DocumentReference.relatesTo" />
      <max value="0" />
    </element>
    <element id="DocumentReference.description">
      <path value="DocumentReference.description" />
      <max value="0" />
    </element>
    <element id="DocumentReference.securityLabel">
      <path value="DocumentReference.securityLabel" />
      <max value="0" />
    </element>
    <element id="DocumentReference.content">
      <path value="DocumentReference.content" />
      <definition value="#### **_`IDMS: The letter template.`_**" />
      <max value="1" />
    </element>
    <element id="DocumentReference.content.extension">
      <path value="DocumentReference.content.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.content.modifierExtension">
      <path value="DocumentReference.content.modifierExtension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.content.attachment">
      <path value="DocumentReference.content.attachment" />
      <definition value="#### **_`IDMS:  Link to the letter template.`_**" />
      <max value="1" />
    </element>
    <element id="DocumentReference.content.profile">
      <path value="DocumentReference.content.profile" />
      <definition value="#### **_`IDMS:  For generated letters the template that was used to generate the letter. The 'valueCoding.display' element is populated with the template name.   `_**" />
      <max value="0" />
    </element>
    <element id="DocumentReference.content.profile.extension">
      <path value="DocumentReference.content.profile.extension" />
      <max value="0" />
    </element>
    <element id="DocumentReference.content.profile.modifierExtension">
      <path value="DocumentReference.content.profile.modifierExtension" />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>