{
  "resourceType": "StructureDefinition",
  "id": "1.3.6.1.4.1.38760.FHIR.1.8.1",
  "url": "https://onko.vvis.gov.lv/fhir/StructureDefinition/Procedure/SurgeryTestValidation-v1",
  "version": "1",
  "name": "Surgery",
  "title": "Surgery",
  "status": "active",
  "experimental": false,
  "description": "Oncology treatment - Surgery",
  "fhirVersion": "4.3.0",
  "kind": "resource",
  "abstract": false,
  "type": "Procedure",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Procedure",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Procedure",
        "path": "Procedure",
        "constraint": [
          {
            "key": "Surgery-con-1",
            "severity": "error",
            "human": "At least one institution is mandatory - either Latvian (Profile: Procedure/Surgery, Field: Procedure.performer.actor.reference) or foreign (Profile: Procedure/Surgery, Field: Procedure.performer.actor.extension:foreignMedicalInstitution)",
            "expression": "performer.actor.reference.exists() or performer.actor.extension.where(url='https://onko.vvis.gov.lv/fhir/StructureDefinition/ForeignMedicalInstitutionExtension-v1').value.exists()"
          },
          {
            "key": "Surgery-con-2",
            "severity": "error",
            "human": "Procedure date (Profile: Procedure/Surgery, Field: Procedure.peformed) is mandatory and cannot be greater than sysdate",
            "expression": "iif(performed.exists(), performed.toDateTime() <= now(), false)"
          },
          {
            "key": "Surgery-con-4",
            "severity": "error",
            "human": "Only one medical institution can be submitted at a time - Latvian from the classifier (Profile: Procedure/Surgery, Field: Procedure.performer.actor.reference) or foreign in the text field (Profile: Procedure/Surgery, Field: Procedure.performer.actor.extension:foreignMedicalInstitution.value[x])",
            "expression": "(performer.actor.reference.exists() implies performer.actor.extension.value.exists().not()) and (performer.actor.extension.value.exists() implies performer.actor.reference.exists().not())"
          }
        ]
      },
      {
        "id": "Procedure.meta",
        "path": "Procedure.meta",
        "type": [
          {
            "code": "Meta",
            "profile": [
              "https://vvis.gov.lv/fhir/Datatype/Meta/OncologyMeta-v1"
            ]
          }
        ]
      },
      {
        "id": "Procedure.meta.profile",
        "path": "Procedure.meta.profile",
        "constraint": [
          {
            "key": "Surgery-con-3",
            "severity": "error",
            "human": "If the Profile on Procedure is Surgery (Profile: Procedure/Surgery, Field: Procedure.meta.profile), then treatment type (Profile: Procedure/Surgery, Field: Procedure.category.coding:procedureType.code) should be 1 - Surgery",
            "expression": "$this='https://onko.vvis.gov.lv/fhir/StructureDefinition/Procedure/Surgery-v1' implies (%resource.category.ofType(CodeableConcept).coding.where(system='https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.628').code = '1')"
          }
        ]
      },
      {
        "id": "Procedure.implicitRules",
        "path": "Procedure.implicitRules",
        "max": "0"
      },
      {
        "id": "Procedure.language",
        "path": "Procedure.language",
        "max": "0"
      },
      {
        "id": "Procedure.text",
        "path": "Procedure.text",
        "max": "0"
      },
      {
        "id": "Procedure.contained",
        "path": "Procedure.contained",
        "max": "0"
      },
      {
        "id": "Procedure.identifier",
        "path": "Procedure.identifier",
        "short": "External Identifier | Ārējās sistēmas ieraksta ID",
        "min": 1,
        "type": [
          {
            "code": "Identifier",
            "profile": [
              "https://vvis.gov.lv/fhir/Datatype/Identifier/OncologyIdentifier-v1"
            ]
          }
        ]
      },
      {
        "id": "Procedure.identifier.use",
        "path": "Procedure.identifier.use",
        "mustSupport": false
      },
      {
        "id": "Procedure.identifier.value",
        "path": "Procedure.identifier.value",
        "mustSupport": false
      },
      {
        "id": "Procedure.identifier.assigner",
        "path": "Procedure.identifier.assigner",
        "mustSupport": false
      },
      {
        "id": "Procedure.instantiatesCanonical",
        "path": "Procedure.instantiatesCanonical",
        "max": "0"
      },
      {
        "id": "Procedure.instantiatesUri",
        "path": "Procedure.instantiatesUri",
        "max": "0"
      },
      {
        "id": "Procedure.basedOn",
        "path": "Procedure.basedOn",
        "max": "0"
      },
      {
        "id": "Procedure.partOf",
        "path": "Procedure.partOf",
        "max": "0"
      },
      {
        "id": "Procedure.statusReason",
        "path": "Procedure.statusReason",
        "max": "0"
      },
      {
        "id": "Procedure.category",
        "path": "Procedure.category",
        "short": "Type of procedure | Operācijas veids",
        "min": 1
      },
      {
        "id": "Procedure.category.coding",
        "path": "Procedure.category.coding",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "Procedure.category.coding:typeOfTreatment",
        "path": "Procedure.category.coding",
        "sliceName": "typeOfTreatment",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Procedure.category.coding:typeOfTreatment.system",
        "path": "Procedure.category.coding.system",
        "short": "Classifier of types of treatment | Ārstēšanas veidu klasifikators",
        "fixedUri": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.not_found"
      },
      {
        "id": "Procedure.category.coding:typeOfTreatment.code",
        "path": "Procedure.category.coding.code",
        "binding": {
          "strength": "required",
          "description": "Classifier of types of treatment code | Ārstēšanas veidu klasifikators kods",
          "valueSet": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.not_found"
        }
      },
      {
        "id": "Procedure.category.coding:procedureType",
        "path": "Procedure.category.coding",
        "sliceName": "procedureType",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Procedure.category.coding:procedureType.system",
        "path": "Procedure.category.coding.system",
        "short": "Classifier of types of treatment | Ārstēšanas veidu klasifikators",
        "fixedUri": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.630"
      },
      {
        "id": "Procedure.category.coding:procedureType.code",
        "path": "Procedure.category.coding.code",
        "binding": {
          "strength": "required",
          "description": "Classifier of types of treatment code | Ārstēšanas veidu klasifikators kods",
          "valueSet": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.628"
        }
      },
      {
        "id": "Procedure.code",
        "path": "Procedure.code",
        "short": "Procedure code | Operācijas kods",
        "min": 1
      },
      {
        "id": "Procedure.code.coding",
        "path": "Procedure.code.coding",
        "min": 1
      },
      {
        "id": "Procedure.code.coding.system",
        "path": "Procedure.code.coding.system",
        "short": "(NOMESCO) Nordic Classification of Surgical Procedures | (NOMESCO) Ziemeļvalstu ķirurģisko procedūru klasifikācija",
        "fixedUri": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.175"
      },
      {
        "id": "Procedure.code.coding.code",
        "path": "Procedure.code.coding.code",
        "binding": {
          "strength": "required",
          "description": "(NOMESCO) Nordic Classification of Surgical Procedures code | (NOMESCO) Ziemeļvalstu ķirurģisko procedūru klasifikācijas kods",
          "valueSet": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.175"
        }
      },
      {
        "id": "Procedure.subject",
        "path": "Procedure.subject",
        "short": "Reference to Patient profile | Saite uz Patient profilu",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://vvis.gov.lv/fhir/StructureDefinition/Patient/LVPatient"
            ]
          }
        ]
      },
      {
        "id": "Procedure.encounter",
        "path": "Procedure.encounter",
        "max": "0"
      },
      {
        "id": "Procedure.performed[x]",
        "path": "Procedure.performed[x]",
        "short": "When the procedure was performed | Operācijas datums",
        "min": 1,
        "type": [
          {
            "code": "dateTime"
          }
        ],
        "condition": [
          "Surgery-con-2"
        ]
      },
      {
        "id": "Procedure.recorder",
        "path": "Procedure.recorder",
        "max": "0"
      },
      {
        "id": "Procedure.asserter",
        "path": "Procedure.asserter",
        "max": "0"
      },
      {
        "id": "Procedure.performer",
        "path": "Procedure.performer",
        "short": "Medical institution where the treatment was received | Ārstniecības iestāde, kurā saņemta ārstēšana",
        "min": 1,
        "max": "1",
        "condition": [
          "Surgery-con-1"
        ]
      },
      {
        "id": "Procedure.performer.actor",
        "path": "Procedure.performer.actor",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://vvis.gov.lv/fhir/StructureDefinition/Organization/MedicalInstitution"
            ]
          }
        ]
      },
      {
        "id": "Procedure.performer.actor.extension:foreignMedicalInstitution",
        "path": "Procedure.performer.actor.extension",
        "sliceName": "foreignMedicalInstitution",
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "https://onko.vvis.gov.lv/fhir/StructureDefinition/ForeignMedicalInstitutionExtension-v1"
            ]
          }
        ],
        "isModifier": false
      },
      {
        "id": "Procedure.location",
        "path": "Procedure.location",
        "max": "0"
      },
      {
        "id": "Procedure.reasonCode",
        "path": "Procedure.reasonCode",
        "max": "0"
      },
      {
        "id": "Procedure.reasonReference",
        "path": "Procedure.reasonReference",
        "short": "Treated disease | Ārstētā slimība",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://onko.vvis.gov.lv/fhir/StructureDefinition/Condition/OncologyBasicDataOfDisease-v1"
            ]
          }
        ]
      },
      {
        "id": "Procedure.reasonReference.identifier",
        "path": "Procedure.reasonReference.identifier",
        "max": "0"
      },
      {
        "id": "Procedure.reasonReference.display",
        "path": "Procedure.reasonReference.display",
        "max": "0"
      },
      {
        "id": "Procedure.bodySite",
        "path": "Procedure.bodySite",
        "max": "0"
      },
      {
        "id": "Procedure.outcome",
        "path": "Procedure.outcome",
        "max": "0"
      },
      {
        "id": "Procedure.report",
        "path": "Procedure.report",
        "max": "0"
      },
      {
        "id": "Procedure.complication",
        "path": "Procedure.complication",
        "max": "0"
      },
      {
        "id": "Procedure.complicationDetail",
        "path": "Procedure.complicationDetail",
        "max": "0"
      },
      {
        "id": "Procedure.followUp",
        "path": "Procedure.followUp",
        "short": "Indication of further treatment/monitoring of patients | Norāde par pacientu tālāko ārstēšanu/uzraudzību",
        "max": "1"
      },
      {
        "id": "Procedure.followUp.coding",
        "path": "Procedure.followUp.coding",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "Procedure.followUp.coding:followUp",
        "path": "Procedure.followUp.coding",
        "sliceName": "followUp"
      },
      {
        "id": "Procedure.followUp.coding:followUp.system",
        "path": "Procedure.followUp.coding.system",
        "short": "Further treatment or monitoring of the patient classifier | Pacienta tālāka ārstēšana vai uzraudzība klasifikators",
        "fixedUri": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.629"
      },
      {
        "id": "Procedure.followUp.coding:followUp.code",
        "path": "Procedure.followUp.coding.code",
        "binding": {
          "strength": "required",
          "description": "Further treatment or monitoring of the patient classifier code | Pacienta tālāka ārstēšana vai uzraudzība klasifikatora kods",
          "valueSet": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.629"
        }
      },
      {
        "id": "Procedure.followUp.coding:followUpOld",
        "path": "Procedure.followUp.coding",
        "sliceName": "followUpOld"
      },
      {
        "id": "Procedure.followUp.coding:followUpOld.system",
        "path": "Procedure.followUp.coding.system",
        "short": "Further treatment or monitoring of the patient classifier old | Pacienta tālāka ārstēšana vai uzraudzība klasifikators vēsturiskais",
        "definition": "Further treatment or monitoring of the patient classifier old (only for historical cards until 2024) | Pacienta tālāka ārstēšana vai uzraudzība klasifikators vēsturiskais (tikai vēsturiskām kartēm līdz 2024.gadam)",
        "fixedUri": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.204"
      },
      {
        "id": "Procedure.followUp.coding:followUpOld.code",
        "path": "Procedure.followUp.coding.code",
        "binding": {
          "strength": "required",
          "description": "Further treatment or monitoring of the patient classifier code old | Pacienta tālāka ārstēšana vai uzraudzība klasifikatora kods vēsturiskais",
          "valueSet": "https://vvis.gov.lv/fhir/ValueSet/1.3.6.1.4.1.38760.2.204"
        }
      },
      {
        "id": "Procedure.note",
        "path": "Procedure.note",
        "max": "0"
      },
      {
        "id": "Procedure.focalDevice",
        "path": "Procedure.focalDevice",
        "max": "0"
      },
      {
        "id": "Procedure.usedReference",
        "path": "Procedure.usedReference",
        "max": "0"
      },
      {
        "id": "Procedure.usedCode",
        "path": "Procedure.usedCode",
        "max": "0"
      }
    ]
  }
}