{
  "resourceType": "StructureDefinition",
  "id": "HealthLinkEncounter",
  "extension": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-category",
      "valueString": "Base.Management"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category",
      "valueCode": "patient"
    }
  ],
  "url": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkEncounter",
  "version": "0.5.2",
  "name": "HealthLinkEncounter",
  "title": "Health Link Encounter Profile",
  "status": "active",
  "fhirVersion": "4.0.1",
  "mapping": [
    {
      "identity": "workflow",
      "uri": "http://hl7.org/fhir/workflow",
      "name": "Workflow Pattern"
    },
    {
      "identity": "rim",
      "uri": "http://hl7.org/v3",
      "name": "RIM Mapping"
    },
    {
      "identity": "w5",
      "uri": "http://hl7.org/fhir/fivews",
      "name": "FiveWs Pattern Mapping"
    },
    {
      "identity": "v2",
      "uri": "http://hl7.org/v2",
      "name": "HL7 v2 Mapping"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "Encounter",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Encounter",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Encounter",
        "path": "Encounter",
        "constraint": [
          {
            "key": "hlval-enc-1",
            "severity": "error",
            "human": "Encounter must contain a period element",
            "expression": "status != 'finished' or period.exists()",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkEncounter"
          },
          {
            "key": "hlval-enc-2",
            "severity": "error",
            "human": "Encounter must contain a serviceProvider element",
            "expression": "status != 'finished' or serviceProvider.exists()",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkEncounter"
          }
        ]
      },
      {
        "id": "Encounter.id",
        "path": "Encounter.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/HealthLinkEncounter"
          }
        ]
      },
      {
        "id": "Encounter.identifier",
        "path": "Encounter.identifier",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "Encounter.identifier:mdp",
        "path": "Encounter.identifier",
        "sliceName": "mdp",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Encounter.identifier:mdp.use",
        "path": "Encounter.identifier.use",
        "patternCode": "official"
      },
      {
        "id": "Encounter.identifier:mdp.system",
        "path": "Encounter.identifier.system",
        "min": 1,
        "patternUri": "http://203.157.10.8/hcode_2020/query_set.php"
      },
      {
        "id": "Encounter.identifier:mdp.value",
        "path": "Encounter.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/HealthLinkEncounter"
          }
        ]
      },
      {
        "id": "Encounter.class",
        "path": "Encounter.class",
        "binding": {
          "strength": "required",
          "valueSet": "https://healthlink.go.th/fhir/ValueSet/EncounterClass"
        }
      },
      {
        "id": "Encounter.class.system",
        "path": "Encounter.class.system",
        "min": 1
      },
      {
        "id": "Encounter.class.code",
        "path": "Encounter.class.code",
        "min": 1
      },
      {
        "id": "Encounter.class.display",
        "path": "Encounter.class.display",
        "min": 1
      },
      {
        "id": "Encounter.type.coding.system",
        "path": "Encounter.type.coding.system",
        "min": 1
      },
      {
        "id": "Encounter.type.coding.code",
        "path": "Encounter.type.coding.code",
        "min": 1
      },
      {
        "id": "Encounter.type.coding.display",
        "path": "Encounter.type.coding.display",
        "min": 1
      },
      {
        "id": "Encounter.serviceType.coding.system",
        "path": "Encounter.serviceType.coding.system",
        "min": 1
      },
      {
        "id": "Encounter.serviceType.coding.code",
        "path": "Encounter.serviceType.coding.code",
        "min": 1
      },
      {
        "id": "Encounter.serviceType.coding.display",
        "path": "Encounter.serviceType.coding.display",
        "min": 1
      },
      {
        "id": "Encounter.subject",
        "path": "Encounter.subject",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Patient"
            ]
          }
        ]
      },
      {
        "id": "Encounter.subject.reference",
        "path": "Encounter.subject.reference",
        "min": 1
      },
      {
        "id": "Encounter.period.start",
        "path": "Encounter.period.start",
        "min": 1
      },
      {
        "id": "Encounter.reasonCode.coding.system",
        "path": "Encounter.reasonCode.coding.system",
        "min": 1
      },
      {
        "id": "Encounter.reasonCode.coding.code",
        "path": "Encounter.reasonCode.coding.code",
        "min": 1
      },
      {
        "id": "Encounter.reasonCode.coding.display",
        "path": "Encounter.reasonCode.coding.display",
        "min": 1
      },
      {
        "id": "Encounter.diagnosis.condition.reference",
        "path": "Encounter.diagnosis.condition.reference",
        "min": 1
      },
      {
        "id": "Encounter.diagnosis.rank",
        "path": "Encounter.diagnosis.rank",
        "min": 1
      },
      {
        "id": "Encounter.serviceProvider.reference",
        "path": "Encounter.serviceProvider.reference",
        "min": 1
      }
    ]
  }
}