{
  "resourceType": "StructureDefinition",
  "id": "au-device",
  "url": "http://hl7.org.au/fhir/StructureDefinition/au-device",
  "version": "1.1.0",
  "name": "AUBaseDevice",
  "title": "AU Base Device",
  "status": "draft",
  "date": "2017-09-26T05:50:09.867+00:00",
  "publisher": "Health Level Seven Australia (Patient Administration WG)",
  "contact": [
    {
      "telecom": [
        {
          "system": "url",
          "value": "http://hl7.org.au/fhir",
          "use": "work"
        }
      ]
    }
  ],
  "description": "This profile defines a device administration details structure that includes core localisation concepts for use in an Australian context.",
  "fhirVersion": "3.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "Device",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Device",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Device",
        "path": "Device",
        "short": "A device in an Australian healthcare context"
      },
      {
        "id": "Device.identifier",
        "path": "Device.identifier",
        "slicing": {
          "discriminator": [
            {
              "type": "pattern",
              "path": "type"
            },
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "Device.identifier:paid",
        "path": "Device.identifier",
        "sliceName": "paid",
        "short": "My Health Record Assigned Identity for Devices (PAI-D)",
        "definition": "My Health Record (PCEHR) Assigned Identity for Devices (PAI-D) numbers. An identifier for devices which may author documents on behalf of organisations.",
        "max": "1",
        "constraint": [
          {
            "key": "inv-paid-value-0",
            "requirements": "The value shall be a 16 digit number.",
            "severity": "error",
            "human": "PAI-D shall be an exactly 16 digit number",
            "expression": "value.matches('^([0-9]{16})$')"
          },
          {
            "key": "inv-paid-value-1",
            "severity": "error",
            "human": "PAI-D prefix is 8003640003",
            "expression": "value.startsWith('8003640003')"
          },
          {
            "key": "inv-paid-value-2",
            "requirements": "PAI-D shall pass the Luhn algorithm check",
            "severity": "error",
            "human": "The identifier shall pass the Luhn algorithm check",
            "expression": "(((select(value.substring(0,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(1,1).toInteger())+(select(value.substring(2,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(3,1).toInteger())+(select(value.substring(4,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(5,1).toInteger())+(select(value.substring(6,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(7,1).toInteger())+(select(value.substring(8,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(9,1).toInteger())+(select(value.substring(10,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(11,1).toInteger())+(select(value.substring(12,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(13,1).toInteger())+(select(value.substring(14,1).toInteger()).select(iif($this<5, $this*2, (($this*2)-9))))+(value.substring(15,1).toInteger()))mod 10=0)"
          }
        ]
      },
      {
        "id": "Device.identifier:paid.type",
        "path": "Device.identifier.type",
        "short": "Coded identifier type for PAI-D",
        "definition": "Element describing the type of identifier.",
        "patternCodeableConcept": {
          "coding": [
            {
              "system": "http://hl7.org.au/fhir/v2/0203",
              "code": "NDI"
            }
          ]
        },
        "binding": {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName",
              "valueString": "IdentifierType"
            },
            {
              "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding",
              "valueBoolean": true
            }
          ],
          "strength": "required",
          "description": "Local Identifier Type",
          "valueSetReference": {
            "reference": "http://hl7.org.au/fhir/ValueSet/au-hl7v2-0203"
          }
        }
      },
      {
        "id": "Device.identifier:paid.type.text",
        "extension": [
          {
            "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-translatable",
            "valueBoolean": true
          }
        ],
        "path": "Device.identifier.type.text",
        "fixedString": "PAI-D"
      },
      {
        "id": "Device.identifier:paid.system",
        "path": "Device.identifier.system",
        "short": "Namespace for PAI-D",
        "definition": "This namespace is used for qualified identifiers to represent My Health Record Assigned Identity for Devices (PAI-D) numbers.",
        "min": 1,
        "fixedUri": "http://ns.electronichealth.net.au/id/pcehr/paid/1.0"
      },
      {
        "id": "Device.identifier:paid.value",
        "path": "Device.identifier.value",
        "short": "PAI-D number",
        "min": 1,
        "example": [
          {
            "label": "PAI-D number",
            "valueString": "8003640003999998"
          }
        ],
        "maxLength": 16
      },
      {
        "id": "Device.udi",
        "path": "Device.udi",
        "definition": "Unique device identifier (UDI) assigned to device label or package."
      }
    ]
  }
}