<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="ie-core-location" />
  <url value="https://hl7-ie.github.io/ie-core/fhir/ie/core/StructureDefinition/ie-core-location" />
  <name value="IECoreLocation" />
  <title value="IE Core Location" />
  <status value="draft" />
  <description value="The IE Core Location Profile is based upon the core FHIR Location Resource and defines the minimum set of data required to query and retrieve location information within the Irish healthcare system. It covers details such as the location name, type, address, and managing organization." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Location" />
  <baseDefinition value="http://hl7.eu/fhir/base/StructureDefinition/location-eu-core" />
  <derivation value="constraint" />
  <snapshot />
  <differential>
    <element id="Location.identifier">
      <path value="Location.identifier" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <short value="Unique code or number identifying the location to its users" />
      <mustSupport value="true" />
    </element>
    <element id="Location.identifier:GLN">
      <path value="Location.identifier" />
      <sliceName value="GLN" />
      <short value="Global Location Number (GLN)" />
      <comment value="HIQA EP/PS 2.11 Location ID (GLN) (Required 0..1): a 13-digit number made up of a GS1 company prefix, a location reference and a check digit. Not an organisation identifier: each GP practice in a shared building has its own GLN. System: GS1 GLN (HL7 Terminology NamingSystem/GLN)." />
      <min value="0" />
      <max value="1" />
      <constraint>
        <key value="ie-loc-gln-1" />
        <severity value="error" />
        <human value="GLN SHALL be 13 digits with a valid GS1 mod-10 check digit (HIQA EP/PS 2.11)" />
        <expression value="value.matches('^[0-9]{13}$') and (((10 - ((value.substring(0,1).toInteger() + value.substring(1,1).toInteger()*3 + value.substring(2,1).toInteger() + value.substring(3,1).toInteger()*3 + value.substring(4,1).toInteger() + value.substring(5,1).toInteger()*3 + value.substring(6,1).toInteger() + value.substring(7,1).toInteger()*3 + value.substring(8,1).toInteger() + value.substring(9,1).toInteger()*3 + value.substring(10,1).toInteger() + value.substring(11,1).toInteger()*3) mod 10)) mod 10) = value.substring(12,1).toInteger())" />
        <source value="https://hl7-ie.github.io/ie-core/fhir/ie/core/StructureDefinition/ie-core-location" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Location.identifier:GLN.system">
      <path value="Location.identifier.system" />
      <min value="1" />
      <patternUri value="http://www.gs1.org/gln" />
      <mustSupport value="true" />
    </element>
    <element id="Location.identifier:GLN.value">
      <path value="Location.identifier.value" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Location.status">
      <path value="Location.status" />
      <mustSupport value="true" />
    </element>
    <element id="Location.operationalStatus">
      <path value="Location.operationalStatus" />
      <mustSupport value="true" />
    </element>
    <element id="Location.name">
      <path value="Location.name" />
      <short value="Name of the location as used by humans" />
      <mustSupport value="true" />
    </element>
    <element id="Location.alias">
      <path value="Location.alias" />
      <mustSupport value="true" />
    </element>
    <element id="Location.description">
      <path value="Location.description" />
      <short value="Additional details about the location" />
      <mustSupport value="true" />
    </element>
    <element id="Location.mode">
      <path value="Location.mode" />
      <mustSupport value="true" />
    </element>
    <element id="Location.type">
      <path value="Location.type" />
      <short value="Type of function performed at the location" />
      <mustSupport value="true" />
      <binding>
        <strength value="extensible" />
        <valueSet value="http://terminology.hl7.org/ValueSet/v3-ServiceDeliveryLocationRoleType" />
      </binding>
    </element>
    <element id="Location.telecom">
      <path value="Location.telecom" />
      <short value="Contact details of the location" />
      <mustSupport value="true" />
    </element>
    <element id="Location.telecom.system">
      <path value="Location.telecom.system" />
      <mustSupport value="true" />
    </element>
    <element id="Location.telecom.value">
      <path value="Location.telecom.value" />
      <mustSupport value="true" />
    </element>
    <element id="Location.telecom.use">
      <path value="Location.telecom.use" />
      <mustSupport value="true" />
    </element>
    <element id="Location.address">
      <path value="Location.address" />
      <short value="Physical location address" />
      <mustSupport value="true" />
    </element>
    <element id="Location.address.line">
      <path value="Location.address.line" />
      <mustSupport value="true" />
    </element>
    <element id="Location.address.city">
      <path value="Location.address.city" />
      <mustSupport value="true" />
    </element>
    <element id="Location.address.state">
      <path value="Location.address.state" />
      <short value="County" />
      <mustSupport value="true" />
      <binding>
        <strength value="extensible" />
        <valueSet value="https://hl7-ie.github.io/ie-core/fhir/ie/core/ValueSet/ie-core-county" />
      </binding>
    </element>
    <element id="Location.address.postalCode">
      <path value="Location.address.postalCode" />
      <short value="Eircode or postal code" />
      <mustSupport value="true" />
    </element>
    <element id="Location.address.country">
      <path value="Location.address.country" />
      <mustSupport value="true" />
    </element>
    <element id="Location.physicalType">
      <path value="Location.physicalType" />
      <mustSupport value="true" />
    </element>
    <element id="Location.position">
      <path value="Location.position" />
      <mustSupport value="true" />
    </element>
    <element id="Location.position.longitude">
      <path value="Location.position.longitude" />
      <mustSupport value="true" />
    </element>
    <element id="Location.position.latitude">
      <path value="Location.position.latitude" />
      <mustSupport value="true" />
    </element>
    <element id="Location.managingOrganization">
      <path value="Location.managingOrganization" />
      <short value="Organization responsible for provisioning and upkeep" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://hl7-ie.github.io/ie-core/fhir/ie/core/StructureDefinition/ie-core-organization" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Location.partOf">
      <path value="Location.partOf" />
      <type>
        <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-hierarchy">
          <valueBoolean value="true" />
        </extension>
        <code value="Reference" />
        <targetProfile value="https://hl7-ie.github.io/ie-core/fhir/ie/core/StructureDefinition/ie-core-location" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Location.endpoint">
      <path value="Location.endpoint" />
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>