{
  "resourceType": "StructureDefinition",
  "id": "HealthLinkDocumentReference",
  "extension": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-category",
      "valueString": "Foundation.Documents"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category",
      "valueCode": "not-classified"
    }
  ],
  "url": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkDocumentReference",
  "version": "0.5.2",
  "name": "HealthLinkDocumentReference",
  "title": "Health Link DocumentReference Profile",
  "status": "active",
  "fhirVersion": "4.0.1",
  "mapping": [
    {
      "identity": "workflow",
      "uri": "http://hl7.org/fhir/workflow",
      "name": "Workflow Pattern"
    },
    {
      "identity": "fhircomposition",
      "uri": "http://hl7.org/fhir/composition",
      "name": "FHIR Composition"
    },
    {
      "identity": "rim",
      "uri": "http://hl7.org/v3",
      "name": "RIM Mapping"
    },
    {
      "identity": "cda",
      "uri": "http://hl7.org/v3/cda",
      "name": "CDA (R2)"
    },
    {
      "identity": "w5",
      "uri": "http://hl7.org/fhir/fivews",
      "name": "FiveWs Pattern Mapping"
    },
    {
      "identity": "v2",
      "uri": "http://hl7.org/v2",
      "name": "HL7 v2 Mapping"
    },
    {
      "identity": "xds",
      "uri": "http://ihe.net/xds",
      "name": "XDS metadata equivalent"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "DocumentReference",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/DocumentReference",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "DocumentReference.id",
        "path": "DocumentReference.id",
        "min": 1,
        "constraint": [
          {
            "key": "health-link-6",
            "severity": "error",
            "human": "Resource id must be 'mdp9Id-cid-uuid' (9-digit mdp9id + 13-digit cid + any uuid). Total length does not excced 64 chars.",
            "expression": "matches(\"^[0-9]{9}-[0-9]{13}-.*\")",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkDocumentReference"
          }
        ]
      },
      {
        "id": "DocumentReference.identifier",
        "path": "DocumentReference.identifier",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "DocumentReference.identifier:mdp",
        "path": "DocumentReference.identifier",
        "sliceName": "mdp",
        "min": 1,
        "max": "1"
      },
      {
        "id": "DocumentReference.identifier:mdp.use",
        "path": "DocumentReference.identifier.use",
        "patternCode": "official"
      },
      {
        "id": "DocumentReference.identifier:mdp.system",
        "path": "DocumentReference.identifier.system",
        "min": 1,
        "patternUri": "http://203.157.10.8/hcode_2020/query_set.php"
      },
      {
        "id": "DocumentReference.identifier:mdp.value",
        "path": "DocumentReference.identifier.value",
        "min": 1,
        "constraint": [
          {
            "key": "health-link-4",
            "severity": "error",
            "human": "Resource identifer.value must be a 9 digit number (hcode)",
            "expression": "matches(\"^[0-9]{9}$\")",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkDocumentReference"
          }
        ]
      },
      {
        "id": "DocumentReference.subject",
        "path": "DocumentReference.subject",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Patient"
            ]
          }
        ]
      },
      {
        "id": "DocumentReference.subject.reference",
        "path": "DocumentReference.subject.reference",
        "min": 1
      },
      {
        "id": "DocumentReference.author",
        "path": "DocumentReference.author",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Organization"
            ]
          }
        ]
      },
      {
        "id": "DocumentReference.author.reference",
        "path": "DocumentReference.author.reference",
        "min": 1
      },
      {
        "id": "DocumentReference.content.attachment",
        "path": "DocumentReference.content.attachment",
        "constraint": [
          {
            "key": "health-link-9",
            "severity": "error",
            "human": "Attachment must have a data or url",
            "expression": "data.exists() or url.exists()",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkDocumentReference"
          }
        ]
      },
      {
        "id": "DocumentReference.context",
        "path": "DocumentReference.context",
        "constraint": [
          {
            "key": "health-link-10",
            "severity": "error",
            "human": "DocumentReference context must have an encounter or related",
            "expression": "encounter.exists() or related.exists()",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkDocumentReference"
          }
        ]
      },
      {
        "id": "DocumentReference.context.encounter.reference",
        "path": "DocumentReference.context.encounter.reference",
        "min": 1
      },
      {
        "id": "DocumentReference.context.related.reference",
        "path": "DocumentReference.context.related.reference",
        "min": 1
      }
    ]
  }
}