Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

 

Specification

Apiary

Purpose

This WS is designed to create Request fo Medication request

There are two types of medication request:

...

plan - The request represents an intention to ensure something occurs without providing an authorization for others to act. Medication request with type plan can't be dispensed and only provide the instruction to administer the medicine. 

...

Table of Contents

Purpose

This WS is designed to create Request fo Medication request

There are two types of medication request:

  • plan - The request represents an intention to ensure something occurs without providing an authorization for others to act. Medication request with type plan can't be dispensed and only provide the instruction to administer the medicine. 

  • order - The request represents a request/demand and authorization for action. Medication request with type order can be dispensed

Specification*

Page Properties

Link

https://uaehealthapi.docs.apiary.io/#reference/public.-reimbursement/medication-request-requests/create-medication-request-request

Посилання на Apiary або Swagger

Resource

/api/medication_request_requests

Наприклад: /api/persons/create

Scope

medication_request_request:write

Зазначається потрібний scope

Components

ePrescription

Зазначається перелік бізнес компонентів, які використовують цей метод, наприклад: ePrescription

Microservices

Перелік мікросервісів, які використовує метод API. Наприклад: Auth, ABAC

Protocol type

REST

Тип протоколу, який використовується запитом, наприклад: SOAP | REST

Request type

POST

Тип HTTP методу, який використовується запитом, наприклад: POST | GET…

Sync/Async

Sync

Метод є синхронним чи асинхронним?

Logic*

...

Preconditions

API paragraph not found

Global and configuration parameters

API paragraph not found

Input parameters

None

Filters

None

Request structure*

See on Apiary

Example:

Expand
titleRequest example
Code Block
{
  "medication_request_request": {
    "person_id": "585044f5-1272-4bca-8d41-8440eefe7d26",
    "employee_id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
    "division_id": "881d6dee-dd3d-43f3-8983-922354c0e6ce",
    "created_at": "2017-08-17",
    "started_at": "2017-08-17",
    "ended_at": "2017-09-16",
    "medication_id": "1349a693-4db1-4a3f-9ac6-8c2f9e541982",
    "medication_qty": 10.34,
    "medical_program_id": "59781de0-2e64-4359-b716-bcc05a32c10f",
    "intent": "plan",
    "category": "community",
    "based_on": [
      {
        "identifier": {
          "type": {
            "coding": [
              {
                "system": "eHealth/resources",
                "code": "care_plan"
              }
            ]
          },
          "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
        }
      },
      {
        "identifier": {
          "type": {
            "coding": [
              {
                "system": "eHealth/resources",
                "code": "activity"
              }
            ]
          },
          "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
        }
      }
    ],
    "context": {
      "identifier": {
        "type": {
          "coding": [
            {
              "system": "eHealth/resources",
              "code": "encounter"
            }
          ]
        },
        "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
      }
    },
    "dosage_instruction": [
      {
        "sequence": 1,
        "text": "0.25mg PO every 6-12 hours as needed for menses from Jan 15-20, 2015.  Do not exceed more than 4mg per day",
        "additional_instruction": [
          {
            "coding": [
              {
                "system": "eHealth/SNOMED/additional_dosage_instructions",
                "code": "311504000"
              }
            ]
          }
        ],
        "patient_instruction": "0.25mg PO every 6-12 hours as needed for menses from Jan 15-20, 2015.  Do not exceed more than 4mg per day",
        "timing": {
          "event": [
            "2017-04-20T19:14:13Z"
          ],
          "repeat": {
            "bounds_duration": {
              "value": 10,
              "unit": "days",
              "system": "eHealth/ucum/units",
              "code": "d"
            },
            "count": 2,
            "count_max": 4,
            "duration": 4,
            "duration_max": 6,
            "duration_unit": "d",
            "frequency": 1,
            "frequency_max": 2,
            "period": 4,
            "period_max": 6,
            "period_unit": "d",
            "day_of_week": [
              "mon"
            ],
            "time_of_day": [
              "2017-04-20T19:14:13Z"
            ],
            "when": [
              "WAKE"
            ],
            "offset": 4
          },
          "code": {
            "coding": [
              {
                "system": "TIMING_ABBREVIATIONS",
                "code": "patient"
              }
            ]
          }
        },
        "as_needed_boolean": true,
        "site": {
          "coding": [
            {
              "system": "eHealth/SNOMED/anatomical_structure_administration_site_codes",
              "code": "344001"
            }
          ]
        },
        "route": {
          "coding": [
            {
              "system": "eHealth/SNOMED/route_codes",
              "code": "46713006"
            }
          ]
        },
        "method": {
          "coding": [
            {
              "system": "eHealth/SNOMED/administration_methods",
              "code": "419747000"
            }
          ]
        },
        "dose_and_rate": {
          "type": {
            "coding": [
              {
                "system": "eHealth/dose_and_rate",
                "code": "'ordered'"
              }
            ]
          },
          "dose_range": {
            "low": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            },
            "high": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            }
          },
          "rate_ratio": {
            "numerator": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            },
            "denominator": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            }
          }
        },
        "max_dose_per_period": {
          "numerator": {
            "value": 0,
            "unit": "mg",
            "system": "eHealth/ucum/units",
            "code": "mg"
          },
          "denominator": {
            "value": 0,
            "unit": "mg",
            "system": "eHealth/ucum/units",
            "code": "mg"
          }
        },
        "max_dose_per_administration": {
          "value": 0,
          "unit": "mg",
          "system": "eHealth/ucum/units",
          "code": "mg"
        },
        "max_dose_per_lifetime": {
          "value": 0,
          "unit": "mg",
          "system": "eHealth/ucum/units",
          "code": "mg"
        }
      }
    ],
    "priority": "routine",
    "prior_prescription": {
      "identifier": {
        "type": {
          "coding": [
            {
              "system": "eHealth/resources",
              "code": "medication_request"
            }
          ]
        },
        "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
      }
    },
    "container_dosage": {
      "system": "MEDICATION_UNIT",
      "code": "ML",
      "value": 4
    }
  }
}

Authorize

  1. Verify the validity of access token

  2. Check user scope (scope = 'medication_request_request:write') in order to perform this action

    1. In case error - generate 401 response

Headers*

Content-Type:application/json

Authorization:Bearer c2778f3064753ea70de870a53795f5c9

Validate request

...

*

Validate request using JSON schema. 

  1. in case of error return 422 error with msg ("required property %{property} was not present"))

Request data validation*

Validate employee

Purpose validation: Validation of an employee for the possibility of creating a medication request.

  1. Invoke employee_id from request

  2. Validate employee

    1. Validate that exists

      1. in case invalid return 422 error with msg ("Employee not found")

    2. Validate that $.employees.status == APPROVED

      1. in case invalid return 409 error with msg ("Employee is not active")

    3. Validate that $.employees.legal_entity_id == client_id from token

      1. in case invalid return 422 error with msg ("Employee does not belong to legal entity from token")

    4. Validate that $.employees.employee_type == <employee_type>

      1. in case medical_program_id present in request validate medical_program_settings.skip_employee_validation == false (or absent)

        1. validate <employee_type>

          1. get $.medical_programs.medical_program_setting by medical_program_id from request

            1. validate that employee_type present in employee_types_for_create_medication_request variable

  3. in case invalid return 422 error with msg ("Employee type can't create medication request with medical program from request") 

in case employee_type = DOCTOR

a. if variable skip_medication_request_employee_declaration_verify = false or null/absent

i. then: get $.declarations by employee_id, person_id, status=ACTIVE

if not found - return 422 error  "Only doctors with an active declaration with the patient can create medication request!"

ii. else skip declaration verification on employee level (if true)

b. if variable skip_medication_request_legal_entity_declaration_verify = false or null/absent

i. then: get $.declarations by employee's legal_entity_id, person_id, status=ACTIVE

if not found - return 422 error "Only legal entity with an active declaration with the patient can create medication request!"

ii. else skip declaration verification on legal entity level (if true)

c. else if both are true - skip declaration verification at all

  1. in case employee_type = SPECIALIST

...

  1. Validate that created_at, started_at, ended_at in date format

    1. in case invalid return 422 with msg ("expected \"%{actual}\" to be a valid ISO 8601 date")

  2. Validate ended_at >= started_at

    1. if invalid - return 422 error  (message: "Ended date must be >= Started date!")

  3. Validate started_at` >= created_at

    1. if invalid - return 422 error  (message: "Started date must be >= Created date!")

  4. Validate started_at >= current_date()

    1. if invalid - return 422 error  (message: "Started date must be >= current date!")

  5. Validate created_at >= current_date() - mrr_delay_input

    1. if invalid - return 422 error  (message: "Create date must be = current date!")

  6. Validate started_at regarding frequency of receiving drugs

    1. get $.medical_programs.medical_program_setting by medical_program_id from request

      1. validate skip_mnn_in_treatment_period variable

        1. in case skip_mnn_in_treatment_period == FALSE (or absent)

          1. validate request according to logic: PreQualify Medication request#2.Checkabsencethesamemedicationsfortheprograms

        2. in case skip_mnn_in_treatment_period == TRUE

          1. skip validating frequency of receiving drugs

  7. Validate created_at regarding frequency of receiving drugs

    1. get $.medical_programs.medical_program_setting by medical_program_id from request

      1. validate skip_mnn_in_treatment_period variable

        1. in case skip_mnn_in_treatment_period == FALSE (or absent)

          1. validate request according to logic: PreQualify Medication request#2.Checkabsencethesamemedicationsfortheprograms

        2. in case skip_mnn_in_treatment_period == TRUE

          1. skip validating frequency of receiving drugs

  8. Validate period length (ended_at - started_at):

    1. If medical program has been submitted:

      1. validate request according to logic: PreQualify Medication request: 7. Validate period

    2. else:

      1. Check that medication request period less than or equal to MEDICATION_REQUEST_MAX_PERIOD_DAY parameter from charts

        1. in case of error - return 409 “Period length exceeds default maximum value“

...

Purpose validation: Check FK, status `is_active`=TRUE, type = INNM_DOSAGE

  1. Invoke Get INNM Dosage by ID

  2. Validate medication_id - medication_id exists

    1. in case of error return 422 ("Medication not found")

  3. Validate Response code == 200

    1. if invalid - return 422 error (message: "Only medication with type `INNM_DOSAGE` can be use for created medication request!")\

  4. Validate Response $.is_active==TRUE

    1. if not found - return 422 error (message: "Only active innm_dosage can be use for created medication request!")

...

  1. Validate medical_program_id is present in the request

    1. in case of error return 422 ("required property medical_program_id was not present")

  2. Validate medical_program_id - medical_program_id exists

    1. in case of error return 422 ("Medical program not found")

  3. Validate context with encounter is present in the request

    1. in case of error return 422 ("Context with encounter is required as medical program is present in the request")

    2. encounter diagnosis is not empty in $.encounter.diagnosis

      1. in case of error return 422 ("Encounter without diagnosis can not be referenced")

  4. Validate medical_programs.medical_program_setting parameters

    1. check if care_plan_required == true then the request should contain a based_on with care plan and activity that contains the same medical program

      1. in case of error return 422 with msg ("Care plan and activity with the same medical program should be present in request")

    2. If there is CONDITIONS_ICD10_AM_ALLOWED parameter, then:

      1. Check if primary diagnosis from the encounter in context has code from eHealth/ICD10_AM/condition_codes dictionary

        1. Check diagnosis code in CONDITIONS_ICD10_AM_ALLOWED

          1. in case of error - return 422 “Encounter in context has no primary diagnosis allowed for the medical program“

    3. If there is CONDITIONS_ICPC2_ALLOWED parameter, then:

      1. Check if primary diagnosis from the encounter in context has code from eHealth/ICPC2/condition_codes dictionary

        1. Check diagnosis code in CONDITIONS_ICPC2_ALLOWED

          1. in case of error - return 422 “Encounter in context has no primary diagnosis allowed for the medical program“

    4. if skip_medication_request_employee_declaration_verify = false or null/absent

      1. then: get $.declarations by employee_id, person_id, status=ACTIVE

        1. if not found - return 422 error  "Only doctors with an active declaration with the patient can create medication request!"

      2. else skip declaration verification on employee level (if true)

    5. if skip_medication_request_legal_entity_declaration_verify = false or null/absent

      1. then: get $.declarations by employee's legal_entity_id, person_id, status=ACTIVE

        1. if not found - return 422 error "Only legal entity with an active declaration with the patient can create medication request!"

      2. else skip declaration verification on legal entity level (if true)

Validate multiplicity & medication request allowed for participants

...

  1. If `$.medical_program_id` present in payload (non null) - Check exist (IF EXIST()) medication & participant 

    1. if not exist - return 404 error (message: "Not found any medications allowed for create medication request for this medical program!")

      Code Block
      SELECT *
      FROM medications MI											-- 2nd level: Medication - type = INNM_DOSAGE
      	INNER JOIN ingredients I
      		ON I.medication_child_id = MI.id
      			AND I.is_primary =TRUE
          INNER JOIN medications MED                              -- 3rd level: Medication - type = BRAND
              ON MED.type == BRAND
                  AND I.parent_id = MED.id
      			AND MED.is_active == TRUE
      	INNER JOIN program_medications MP
      		ON MP.medical_program_id == `DOSTUPNI LIKI`
      			MED.id = MP.medication_id
                  AND MP.is_active == TRUE
                  AND MP.medication_request_allowed == TRUE
      WHERE MI.id == $.medication_id
      	AND MI.type == INNM_DOSAGE
      	AND MI.is_active == TRUE
      

    2. Check exist (IF EXIST()) medication & get combinations of manufacture

      1. if not exist - return 404 error (message: "Not found any active linked medication for this innm dosage!")

        Code Block
        SELECT DISTINCT MED.package_min_qty
        FROM medications MI											-- 2nd level: Medication - type = INNM_DOSAGE
        	INNER JOIN ingredients I
        		ON I.medication_child_id = MI.id
        			AND I.is_primary =TRUE
            INNER JOIN medications MED                              -- 3rd level: Medication - type = BRAND
                ON MED.type == BRAND
                    AND I.parent_id = MED.id
        			AND MED.is_active == TRUE
        WHERE MI.id == $.medication_id
        	AND MI.type == INNM_DOSAGE
        	AND MI.is_active == TRUE
        

    3. Vaildate multiplicity (Mod == 0) for all elements in result (`$.medication_qty` Mod `MED.package_min_qty` == 0)

      if all result of Mod operator  - NOT 0 - return 409 eror (message: "The amount of medications in medication request must be divisible to package minimum quantity") 

      == 0)

      1. if all result of Mod operator  - NOT 0 - return 409 eror (message: "The amount of medications in medication request must be divisible to package minimum quantity") 

Parameters that are used when processing the request

Configuration parameters

Наприклад: Доступ до методу визначається скоупом covid_certificate:get . Дозвіл на даний скоуп визначається адміністратором Системи шляхом конфігурування скоупів в контексті клієнтів і ролей.

Dictionaries

Потрібно вказати словники, які використовує метод API

Processing*

Generate number & verification_code for Medication request

...

  • Generate human readable number for receipt (See specs)

    Code BlockStructure number XXXX-1234-5678-9012-345-C , where: - XXXX - series: numbers + only some letters (A, E, H, K, M, P, T, X) - 1234-5678-9012-345

    human readable number for receipt (See specs)

    Code Block
    Structure number XXXX-1234-5678-9012-345-C , where:
    - XXXX - series: numbers + only some letters (A, E, H, K, M, P, T, X)
    - 1234-5678-9012-345 - randomly generated numbers
    - C - checksum: Should be calculated using the Damn algorithm or Verhoeff algorithm
    After new Request number was generated we should check that it is unique in the DB (entity: medication_request + medication_request_request
    
    • Generate verification_code for MPI.person_authentication_methods == OTP or OFFLINE

      Code Block
      Structure code 1234, where:
      - 1234 - randomly generated 
    numbers - C - checksum: Should be calculated using the Damn algorithm or Verhoeff algorithm After new Request number was generated we should check that it is unique in the DB (entity: medication_request + medication_request_request

    Generate verification_code for MPI.person_authentication_methods == OTP or OFFLINE

    Code Block
    Structure code 1234, where:
    - 1234 - randomly generated numbers 
    

Create Medication request Request

  1. set:

    1. dispense_valid_from = created_at

    2. dispensed_valid_to = dispensed_valid_from + dispense_period

  2. Fill 'data' structure for Response & save in IL.medication_request_requests

Generate content for response

  • Generate data structure with Responce WS structure

    • Set IL.medication_request_requests this structure

  • in case if response is VALID enrich response with urgent_data:

    • get authetification_method by person_id and return masked number (in case if any)

    • numbers 
      

Create Medication request Request

  1. set:

    1. dispense_valid_from = created_at

    2. dispensed_valid_to = dispensed_valid_from + dispense_period

  2. Fill 'data' structure for Response & save in IL.medication_request_requests

Generate content for response

  • Generate data structure with Responce WS structure

    • Set IL.medication_request_requests this structure

  • in case if response is VALID enrich response with urgent_data:

    • get authetification_method by person_id and return masked number (in case if any)

Code Block
"urgent": {
    "authentication_method_current": {
      "type": "OTP",
      "number": "+38093*****85"
    }
  }

Response structure*

See on Apiary

Example:

Expand
titleResponse example
Code Block
{
  "meta": {
    "code": "422",
    "url": "https://example.com/resource",
    "type": "object",
    "request_id": "req-adasdoijasdojsda"
  },
  "error": {
    "type": "

...

unverified",

...


    "

...

message": "

...

Only active employee with type DOCTOR can create medication request!"
  }
}

Post-processing processes*

None

HTTP status codes

HTTP status code

Message

What caused the error

 201

 Response

 

 422

 Only active employee with type DOCTOR can create medication request!

 

Backward compatibility

Сумісність з попередніми версіями методу