<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="profile-DwLocation" />
  <url value="https://www.telus.com/health/fhir/dwemrextract/StructureDefinition/DwLocation" />
  <version value="2.0.0" />
  <name value="DwLocation" />
  <status value="active" />
  <date value="2026-05-29" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Location" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Location" />
  <derivation value="constraint" />
  <differential>
    <element id="Location.id">
      <path value="Location.id" />
      <definition value="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.&#xD;&#xA;&#xD;&#xA;All Locations provided by TELUS Health EMR Data Warehouse will match the pattern urn:telus:emr:{emrType}:{emrInstanceId}:dw-emr-location" />
      <comment value="CHR has two location types: Clinic Locations and Room Locations. Room Locations are child locations under Clinic Locations." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Location.meta">
      <path value="Location.meta" />
      <mustSupport value="true" />
    </element>
    <element id="Location.meta.lastUpdated">
      <path value="Location.meta.lastUpdated" />
      <mustSupport value="true" />
    </element>
    <element id="Location.meta.source">
      <path value="Location.meta.source" />
      <mustSupport value="true" />
    </element>
    <element id="Location.text">
      <path value="Location.text" />
      <comment value="Usage Note: Narrative text representation of the location when available from the EMR." />
    </element>
    <element id="Location.identifier">
      <path value="Location.identifier" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <definition value="Unique code or number identifying the location." />
      <comment value="Usage Note: Identifier(s) that uniquely identify this location within the EMR system." />
      <min value="1" />
    </element>
    <element id="Location.identifier:TelusIdentifier">
      <path value="Location.identifier" />
      <sliceName value="TelusIdentifier" />
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Location.identifier:TelusIdentifier.type.text">
      <path value="Location.identifier.type.text" />
      <comment value="Usage Note: Telus Identifier" />
    </element>
    <element id="Location.identifier:TelusIdentifier.system">
      <path value="Location.identifier.system" />
      <comment value="Pattern: urn:telus:emr:{emrtype}:{emrinstance}:location&#xA;Example: urn:telus:emr:chr:{region}:{accountId}:location" />
      <min value="1" />
    </element>
    <element id="Location.identifier:TelusIdentifier.value">
      <path value="Location.identifier.value" />
      <comment value="Usage Note: The location identifier value from the source EMR system." />
      <min value="1" />
    </element>
    <element id="Location.status">
      <path value="Location.status" />
      <definition value="The status of the location." />
      <comment value="Usage Note: active | suspended | inactive. CHR includes archived/deleted locations as 'inactive' rather than omitting them, so a deletion in the source EMR is reflected as a status change here." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Location.name">
      <path value="Location.name" />
      <short value="Location Name" />
      <definition value="Name of the location as presented to users." />
      <comment value="Usage Note: The name of the location as it appears in the EMR. (e.g., 'Exam Room 1', 'Procedure Room A')." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Location.alias">
      <path value="Location.alias" />
      <comment value="CHR may provide up to two aliases: the internal location name and the online booking description title." />
    </element>
    <element id="Location.description">
      <path value="Location.description" />
      <definition value="Additional details about the location that could be displayed as further information to identify the location beyond its name." />
      <comment value="CHR provides the online booking description for the location." />
    </element>
    <element id="Location.type">
      <path value="Location.type" />
      <comment value="MA always sets a fixed facility type value; it is not derived per-location.&#xA;Binding: http://terminology.hl7.org/ValueSet/v3-ServiceDeliveryLocationRoleType" />
    </element>
    <element id="Location.telecom">
      <path value="Location.telecom" />
      <definition value="The contact details of communication devices available at the location." />
      <comment value="CHR provides phone and fax contact details for clinic locations (room locations inherit their parent clinic's contact details). MA provides phone/fax from the associated provider's address record when exactly one matching address exists; absent otherwise." />
      <mustSupport value="true" />
    </element>
    <element id="Location.telecom.system">
      <path value="Location.telecom.system" />
      <comment value="Usage Note: phone | fax | email | pager | url | sms | other" />
      <mustSupport value="true" />
    </element>
    <element id="Location.telecom.value">
      <path value="Location.telecom.value" />
      <comment value="Usage Note: Will be NULL if no linked facility to location." />
      <mustSupport value="true" />
    </element>
    <element id="Location.telecom.use">
      <path value="Location.telecom.use" />
      <comment value="Usage Note: CHR hard-codes 'work' for both phone and fax." />
    </element>
    <element id="Location.address">
      <path value="Location.address" />
      <definition value="Physical location address." />
      <comment value="CHR provides the full address for clinic locations (room locations inherit their parent clinic's address). MA provides the address from the associated provider's address record when exactly one matching address exists; absent otherwise." />
      <mustSupport value="true" />
    </element>
    <element id="Location.address.use">
      <path value="Location.address.use" />
      <comment value="Usage Note: CHR hard-codes 'work'." />
    </element>
    <element id="Location.address.line">
      <path value="Location.address.line" />
      <comment value="Usage Note: Each address line is provided as a separate element. MA provides up to three address lines." />
    </element>
    <element id="Location.address.state">
      <path value="Location.address.state" />
      <comment value="Usage Note: MA provides the province code (not the full province name)." />
    </element>
    <element id="Location.address.country">
      <path value="Location.address.country" />
      <comment value="Usage Note: MA provides the 3-letter country code." />
    </element>
    <element id="Location.physicalType">
      <path value="Location.physicalType" />
      <definition value="Physical form of the location, e.g. a room, building, or vehicle." />
      <comment value="CHR always sets this to 'Site' for clinic locations and 'Room' for room locations.&#xA;Binding: http://terminology.hl7.org/ValueSet/location-physical-type" />
    </element>
    <element id="Location.position">
      <path value="Location.position" />
      <definition value="The absolute geographic location of the Location, expressed using the WGS84 datum." />
      <comment value="Usage Note: GPS coordinates when available from the EMR (rarely populated)." />
    </element>
    <element id="Location.managingOrganization">
      <path value="Location.managingOrganization" />
      <comment value="Usage Note: Reference to the Organization that manages this location.&#xD;&#xA;References SHALL be a reference to an actual FHIR resource, and SHALL be resolveable (allowing for access control, temporary unavailability, etc.)." />
      <type>
        <code value="Reference" />
        <targetProfile value="https://www.telus.com/health/fhir/dwemrextract/StructureDefinition/DwOrganization" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Location.partOf">
      <path value="Location.partOf" />
      <comment value="CHR room locations reference their parent clinic location via partOf. Clinic locations are top-level and never populate partOf." />
      <type>
        <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-hierarchy">
          <valueBoolean value="true" />
        </extension>
        <code value="Reference" />
        <targetProfile value="https://www.telus.com/health/fhir/dwemrextract/StructureDefinition/DwLocation" />
      </type>
    </element>
    <element id="Location.hoursOfOperation">
      <path value="Location.hoursOfOperation" />
      <comment value="Not currently populated by any EMR source." />
    </element>
    <element id="Location.hoursOfOperation.daysOfWeek">
      <path value="Location.hoursOfOperation.daysOfWeek" />
      <comment value="Usage Note: mon | tue | wed | thu | fri | sat | sun" />
    </element>
  </differential>
</StructureDefinition>