{
  "resourceType": "StructureDefinition",
  "id": "HealthLinkMedicationStatement",
  "extension": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-category",
      "valueString": "Clinical.Medications"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category",
      "valueCode": "patient"
    }
  ],
  "url": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkMedicationStatement",
  "version": "0.5.2",
  "name": "HealthLinkMedicationStatement",
  "title": "Health Link MedicationStatement 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": "MedicationStatement",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/MedicationStatement",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "MedicationStatement.id",
        "path": "MedicationStatement.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/HealthLinkMedicationStatement"
          }
        ]
      },
      {
        "id": "MedicationStatement.extension",
        "path": "MedicationStatement.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "MedicationStatement.extension:medicationQuantity",
        "path": "MedicationStatement.extension",
        "sliceName": "medicationQuantity",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "https://apis.healthlink.go.th/api/v1/fhir/StructureDefinition/MedicationQuantity"
            ]
          }
        ]
      },
      {
        "id": "MedicationStatement.identifier",
        "path": "MedicationStatement.identifier",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "MedicationStatement.identifier:mdp",
        "path": "MedicationStatement.identifier",
        "sliceName": "mdp",
        "min": 1,
        "max": "1"
      },
      {
        "id": "MedicationStatement.identifier:mdp.use",
        "path": "MedicationStatement.identifier.use",
        "patternCode": "official"
      },
      {
        "id": "MedicationStatement.identifier:mdp.system",
        "path": "MedicationStatement.identifier.system",
        "min": 1,
        "patternUri": "http://203.157.10.8/hcode_2020/query_set.php"
      },
      {
        "id": "MedicationStatement.identifier:mdp.value",
        "path": "MedicationStatement.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/HealthLinkMedicationStatement"
          }
        ]
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept",
        "path": "MedicationStatement.medicationCodeableConcept",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "CodeableConcept"
          }
        ],
        "constraint": [
          {
            "key": "health-link-7",
            "severity": "error",
            "human": "CodableConcept of a required field must have a coding or text",
            "expression": "coding.exists() or text.exists()",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkMedicationStatement"
          }
        ]
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding",
        "path": "MedicationStatement.medicationCodeableConcept.coding",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding.system",
        "path": "MedicationStatement.medicationCodeableConcept.coding.system",
        "min": 1
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding.code",
        "path": "MedicationStatement.medicationCodeableConcept.coding.code",
        "min": 1
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding.display",
        "path": "MedicationStatement.medicationCodeableConcept.coding.display",
        "min": 1
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding:tmttpu",
        "path": "MedicationStatement.medicationCodeableConcept.coding",
        "sliceName": "tmttpu",
        "min": 0,
        "max": "1",
        "binding": {
          "strength": "preferred",
          "valueSet": "https://healthlink.go.th/fhir/ValueSet/tmt-tpu"
        }
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding:tmttpu.system",
        "path": "MedicationStatement.medicationCodeableConcept.coding.system",
        "patternUri": "https://healthlink.go.th/tmt/tpu"
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding:tmtgpu",
        "path": "MedicationStatement.medicationCodeableConcept.coding",
        "sliceName": "tmtgpu",
        "min": 0,
        "max": "1",
        "binding": {
          "strength": "preferred",
          "valueSet": "https://healthlink.go.th/fhir/ValueSet/tmt-gpu"
        }
      },
      {
        "id": "MedicationStatement.medicationCodeableConcept.coding:tmtgpu.system",
        "path": "MedicationStatement.medicationCodeableConcept.coding.system",
        "patternUri": "https://healthlink.go.th/tmt/gpu"
      },
      {
        "id": "MedicationStatement.subject",
        "path": "MedicationStatement.subject",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Patient"
            ]
          }
        ]
      },
      {
        "id": "MedicationStatement.subject.reference",
        "path": "MedicationStatement.subject.reference",
        "min": 1
      },
      {
        "id": "MedicationStatement.context",
        "path": "MedicationStatement.context",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Encounter"
            ]
          }
        ]
      },
      {
        "id": "MedicationStatement.context.reference",
        "path": "MedicationStatement.context.reference",
        "min": 1
      },
      {
        "id": "MedicationStatement.effective[x]",
        "path": "MedicationStatement.effective[x]",
        "slicing": {
          "discriminator": [
            {
              "type": "type",
              "path": "$this"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "MedicationStatement.effectivePeriod",
        "path": "MedicationStatement.effectivePeriod",
        "min": 0,
        "max": "1",
        "type": [
          {
            "code": "Period"
          }
        ]
      },
      {
        "id": "MedicationStatement.effectivePeriod.start",
        "path": "MedicationStatement.effectivePeriod.start",
        "min": 1
      },
      {
        "id": "MedicationStatement.informationSource",
        "path": "MedicationStatement.informationSource",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Organization"
            ]
          }
        ]
      },
      {
        "id": "MedicationStatement.informationSource.reference",
        "path": "MedicationStatement.informationSource.reference",
        "min": 1
      },
      {
        "id": "MedicationStatement.dosage",
        "path": "MedicationStatement.dosage",
        "constraint": [
          {
            "key": "health-link-8",
            "severity": "error",
            "human": "Dosage must have at least one of text, timing, or doseAndRate",
            "expression": "text.exists() or timing.exists() or doseAndRate.exists()",
            "source": "https://healthlink.go.th/fhir/StructureDefinition/HealthLinkMedicationStatement"
          }
        ]
      },
      {
        "id": "MedicationStatement.dosage.timing.repeat",
        "path": "MedicationStatement.dosage.timing.repeat",
        "min": 1
      },
      {
        "id": "MedicationStatement.dosage.timing.repeat.period",
        "path": "MedicationStatement.dosage.timing.repeat.period",
        "min": 1
      },
      {
        "id": "MedicationStatement.dosage.timing.repeat.periodUnit",
        "path": "MedicationStatement.dosage.timing.repeat.periodUnit",
        "min": 1
      },
      {
        "id": "MedicationStatement.dosage.doseAndRate.dose[x]",
        "path": "MedicationStatement.dosage.doseAndRate.dose[x]",
        "slicing": {
          "discriminator": [
            {
              "type": "type",
              "path": "$this"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "MedicationStatement.dosage.doseAndRate.doseQuantity",
        "path": "MedicationStatement.dosage.doseAndRate.doseQuantity",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Quantity",
            "profile": [
              "http://hl7.org/fhir/StructureDefinition/SimpleQuantity"
            ]
          }
        ]
      },
      {
        "id": "MedicationStatement.dosage.doseAndRate.doseQuantity.value",
        "path": "MedicationStatement.dosage.doseAndRate.doseQuantity.value",
        "min": 1
      },
      {
        "id": "MedicationStatement.dosage.doseAndRate.doseQuantity.unit",
        "path": "MedicationStatement.dosage.doseAndRate.doseQuantity.unit",
        "min": 1
      }
    ]
  }
}