ЕСОЗ - публічна документація

RC_1_PSYHO_PreQualify Medication request_EN

Specification

Purpose

This WS is designed to Pre-qualify data of Medication request Request (post) - check whether it's possible to use Medication request within the particular Medical program.

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. It also can't be qualified

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

Input parameters (filters)

  • created_at

  • started_at

  • ended_at

  • person_id 

  • employee_id 

  • division_id

  • medication_id 

  • medication_qty

  • ARRAY [program] (optional)

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

Validate request (JSON schema)

Validate request using JSON schema. 

Check medication request type

Only medication request with type (intent) order can be qualified.

  1. Check medication request intent

    1. if medication request intent == plan - return 409, "Plan can't be qualified"

Check that care plan is mandatory for programs

Applies to the programs according to medical program settings:

Applies to the following programs:

  1. Netsukrovyy diabet

  2. Insuliny z doplatoyu

  3. Insuliny bezoplatno

Validation purpose:  It is need to check if the medication request with a program need a care plan (with `care_plan_required` == TRUE) for a this program.

  1. Check if there is a based_on in the request

    1. Check care_plan_required value

      SELECT medical_program_setting->>'care_plan_required' FROM medical_programs WHERE id = 'medical_program_id';

       

    2. if care_plan_required true:

      1. check based_on (reference on care_plan and it activity) in request

        1. in case based_on not found:

          1. add to response: status = INVALID

          2. add to response: rejection_reason = "Care plan with activity on "<medical_programs.name>\" is required for for program \"<medical_programs.name>\""

Check diagnosis comply with programs

Applies to the programs according to medical program settings:

Validation purpose: It is needed to check if medication request with a program needed a context (encounter) with a specified diagnosis. 

  1. If program has CONDITIONS_ICD10_AM_ALLOWED parameter in medical_program_settings:

    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 200 with status = INVALID and rejection_reason = “Encounter in context has no primary diagnosis allowed for the medical program“ 

  2. If program has CONDITIONS_ICPC2_ALLOWED parameter in medical_program_settings:

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

      1. Check diagnosis code in CONDITIONS_ICPC2_ALLOWED

        1. in case of error - return 200 with status = INVALID and rejection_reason = “Encounter in context has no primary diagnosis allowed for the medical program“

5. Validate employee

Applies to programs: any

Validation purpose: It is needed to check if medication request with a program allowed to create for specified employee.

Validate employee_id as described on Create Medication request Request

6. Validate Care plan and Activity

Applies to programs: any

Validation purpose: It is needed to check if medication request with a program allowed to create for specified care plan and activity.

Validare based_on as described on Create Medication request Request

7. Validate period

Applies to programs: any

Validation purpose: It is needed to check if medication request period does not exceed allowed maximum of days.

  1. If medication request has program with MEDICATION_REQUEST_MAX_PERIOD_DAY in medical program setting:

    1. Check that medication request period (ended_at - started_at) less than or equal to medical program setting MEDICATION_REQUEST_MAX_PERIOD_DAY parameter

      1. in case of error - return 200 with status = INVALID and rejection_reason = “Period length exceeds allowed value for the medical program“ 

  2. If medication request has program without MEDICATION_REQUEST_MAX_PERIOD_DAY in medical program setting:

    1. Check that medication request period (ended_at - started_at) less than or equal to MEDICATION_REQUEST_MAX_PERIOD_DAY parameter from charts

      1. in case of error - return 200 with status = INVALID and rejection_reason = “Period length exceeds default maximum value“

Logics for qualify (analyze ability use medical programs)

  • Each Medical program may have its unique conditions for the medication dispense. It can be based on analysis of personal info, medications list, terms, locations and combinations of them. For now - we don't know those conditions.

  • For now there are only conditions for the program DOSTUPNI LIKI and we check them.

  • Also, it is possible to have the medication dispense without any Medical program.

  • However for any Medical program we need a separate block of branching logic.

  • Check compatibility only for programs which are available in payload (array)

  • If program status is invalid, the reason must be saved and returned in response

Check compliance for program "DOSTUPNI LIKI"

  1. 2 checks (below in the text) must be passed for the program "DOSTUPNI LIKI"

    1. if passed - save the response by this program - status = VALID

Check INNM complience for the program "DOSTUPNI LIKI"

Validation purpose:  There is a list of medications (which links to Innms)  which can be used for the program. It must be check whether there is at least one available medication (with `medication_request_allowed` == TRUE)  for the Innm for the particular program 

  1. Check compatibility of innm with medication list for the program 

    1. if data is not found:

      1. add to response: status = INVALID

      2. add to response: rejection_reason = " Not found any approved medications ( linked with innm_dosage) for the program 'DOSTUPNI LIKI' !"

IF EXISTS (SELECT * FROM program_medications MP INNER JOIN medications M ON M.id = MP.medication_id AND M.type = BRANDS AND MP.medication_request_allowed == TRUE INNER JOIN ingredients I ON I.parend_id = M.id AND I.is_primary = TRUE AND I.medication_child_id = $.medication_id WHERE MP.medical_program_id == `DOSTUPNI LIKI`      AND MP.is_active == TRUE AND M.is_active == TRUE)

Check absence the same medications for the program "DOSTUPNI LIKI"

Validation purpose:  It can be only 1 Medication request (ACTIVE, COMPLETED)  per one innm for the one patient at defined period of time.

Example validation: without crossing time

EP

 Preconditions # 1

Result validate #1 

 Preconditions #2

Result validate #2 

 Preconditions #3

Result validate #2 

EP

 Preconditions # 1

Result validate #1 

 Preconditions #2

Result validate #2 

 Preconditions #3

Result validate #2 

PreQualifyMedicationRequestRequest

No records in MedicationRequest

OK

Created record in MedicationRequest

Not valid

Medications request
dispensed (COMPLETED)

Not valid

QualifyMedicationRequestByID

No records in MedicationRequest

Not possible

Create record in MedicationRequest

OK

Medications request
dispensed (COMPLETED) 

Not valid

  1. For info - status charts: Medication_request

  2. Get `check_innm_id

    SELECT I.innm_child_id FROM ingredients I WHERE I.parent_id = $.medication_id AND I.is_primary = TRUE

     

  3. Get Medication requests with their completed Medication dispense by person_id & check_innm_id

     

  4. Validate exist (IF EXIST ()  - that is any crossing  calculating term (started_at + ended_at) for payload with terms selecting Medication requests (started_at + ended_at) with connected medication_dispense in status in (NEW,PROCESSED)).  

    1. if found  

      1. add to response: status = INVALID

      2. add to response: rejection_reason = "It can be only 1 active/ completed medication request request or medication request per one innm for the same patient at the same period of time!"

  5. Fetch Medication Request by $innm_dosge, $medical_program_id, $person_id and max(end_date). In case there is  Medication Request with ended_at>=current_date then next one  can be done in

    • if (ended_at - started_at) => mrr_standart_duration then
      NEW created_at >= ended at - max_mrr_renew_days>=current_day

      • in case of error return 422 error ('It's to early to crate new medication request for such innm_dosage and medical_program_id')

    • if (ended_at - started_at) < mrr_standart_duration then
      NEW created_at >= ended_at - min_mrr_renew_days>=current_day

      • in case of error return 422 error ('It's to early to crate new medication request for such innm_dosage and medical_program_id')

     

Generate structure for response

  • Collect array for all programs in payload with status for each (VALID or INVALID) and rejection_reason

ЕСОЗ - публічна документація