<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="va-pghd-patient-base-v1.0" />
  <url value="https://veteran.apps.va.gov/smart-pgd-fhir/v2/StructureDefinition/va-pghd-patient-base-v1.0" />
  <version value="1.0" />
  <name value="VAPghdPatientProfileBase" />
  <title value="VA PGHD Patient Base Profile for Mobile App Data" />
  <status value="active" />
  <date value="2022-09-01" />
  <description value="VA PGHD Patient base profile defining the common constraints for all PGHD patients. It should have at least 1 ICN identifier with ICN type, and the right VA ICN system (urn:oid:2.16.840.1.113883.4.349) and ICN value format ([0-9]{10}V[0-9]{6}). The local identifier type code - ICN is defined in the VA PGHD code system." />
  <purpose value="This is the PGHD patient base profile defining the common constraints for all VA PGHD patient profiles. Other PGHD patient profiles should derive from this base profile. It requires at least 1 ICN identifier with 'ICN' type." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Patient" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Patient" />
  <derivation value="constraint" />
  <differential>
    <element id="Patient">
      <path value="Patient" />
      <short value="PGHD Governance Rules for Patients" />
      <constraint>
        <key value="pghd-meta-tag-1" />
        <severity value="error" />
        <human value="A Patient must have exactly one meta tag, with system = 'https://wiki.mobilehealth.va.gov/x/Onc1C', a code, and a display value" />
        <expression value="meta.tag.count() = 1 and meta.tag.exists(system = 'https://wiki.mobilehealth.va.gov/x/Onc1C' and code.exists() and display.exists())" />
      </constraint>
      <constraint>
        <key value="pghd-patient-identifier-1" />
        <severity value="error" />
        <human value="A Patient identifier must have both system and value properties" />
        <expression value="identifier.all(system.exists() and value.exists())" />
      </constraint>
      <constraint>
        <key value="pghd-patient-identifier-icn-1" />
        <severity value="error" />
        <human value="A Patient must have exactly one ICN identifier, having type.text or type.coding.code = 'ICN', system = 'urn:oid:2.16.840.1.113883.4.349' or 'urn:uuid:2.16.840.1.113883.4.349', and a value matching 0000000000V000000 (where 0 indicates a decimal digit)" />
        <expression value="(identifier.where((type.text = 'ICN' or type.coding.where(code = 'ICN').count() = 1) and 'urn:oid:2.16.840.1.113883.4.349,urn:uuid:2.16.840.1.113883.4.349'.contains($this.system) and value.matches('[0-9]{10}V[0-9]{6}'))).count() = 1" />
      </constraint>
      <constraint>
        <key value="pghd-patient-identifier-icn-2" />
        <severity value="warning" />
        <human value="Patient ICN system of 'urn:uuid:2.16.840.1.113883.4.349' is deprecated; use system 'urn:oid:2.16.840.1.113883.4.349' instead" />
        <expression value="identifier.exists(system = 'urn:uuid:2.16.840.1.113883.4.349').not()" />
      </constraint>
      <constraint>
        <key value="pghd-patient-identifier-type-1" />
        <severity value="warning" />
        <human value="Patient identifier type.text is deprecated; use type.coding instead" />
        <expression value="identifier.type.text.exists().not()" />
      </constraint>
      <constraint>
        <key value="pghd-patient-identifier-type-2" />
        <severity value="error" />
        <human value="Patient identifier type.text and type.coding.code values must be one of 'ICN', 'VALIDIC', OR 'EDIPI'" />
        <expression value="identifier.all((type.text.exists() implies 'ICN,VALIDIC,EDIPI'.contains($this.type.text)))" />
      </constraint>
      <constraint>
        <key value="pghd-patient-identifier-type-3" />
        <severity value="error" />
        <human value="Patient identifier type must have exactly one of text or coding properties" />
        <expression value="(identifier.type.text.exists() and identifier.type.coding.exists()).not()" />
      </constraint>
      <constraint>
        <key value="pghd-patient-codesystem-1" />
        <severity value="warning" />
        <human value="CodeSystem url https://mobile.va.gov/fhir/codesystem/pghd is deprecated; use https://connectedcare.va.gov/pghd/code-system-v1.1 instead" />
        <expression value="identifier.type.coding.exists(system = 'https://mobile.va.gov/fhir/codesystem/pghd').not()" />
      </constraint>
    </element>
    <element id="Patient.identifier.type">
      <path value="Patient.identifier.type" />
      <binding>
        <strength value="required" />
        <description value="PGHD identifier types." />
        <valueSet value="https://veteran.apps.va.gov/smart-pgd-fhir/v2/ValueSet/va-pghd-identifier-type-v1.0" />
      </binding>
    </element>
  </differential>
</StructureDefinition>