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 Pre-qualify data of Medication request Request (post) - check whether it's possible to use Medication request within the particular Medical program.

...

  • 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

  • programs

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)

  1. Validate request using JSON schema. 

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

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"

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 there are only conditions for the following programs "Dostupni liky", "Netsukrovyy diabet", "Insuliny z doplatoyu", "Insuliny bezoplatno" 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 programs

Some checks (below in the text) must be passed for the programs

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

1. Check INNM complience for the programs

Applies to the following programs:

  1. Dostupni liky

  2. Netsukrovyy diabet

  3. Insuliny z doplatoyu

  4. Insuliny bezoplatno

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 

...

Code Block
SELECT * 
FROM program_medications PM
    INNER JOIN medical_programs MP
      ON PM.medical_program_id=MP.id
        INNER JOIN medications M
            ON M.id = PM.medication_id
                AND M.type =  'BRAND'
        AND MP.medication_request_allowed = TRUE
        INNER JOIN ingredients I
            ON I.parent_id = M.id
                AND I.is_primary = TRUE
                AND I.medication_child_id = PM.medication_id
WHERE PM.medical_program_id = 'medical_program_id'
         AND MP.is_active = TRUE
         AND M.is_active = TRUE;

2. Check absence the same medications for the programs

Applies to the following programs:

  1. Dostupni liky

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

...

  1. For info - status charts: Medication_request

  2. Get `check_innm_id`

    Code Block
    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. Code Block
    SELECT * FROM medication_requests MR
        INNER JOIN medications MED
            ON MED.id = MR.medication_id
        INNER JOIN ingredients I
            ON I.parent_id = MED.id
                AND I.innm_child_id = `check_innm_id`
                AND I.is_primary = TRUE
        WHERE MR.person_id == $.person_id
            AND MR.status IN (ACTIVE, COMPLETED)
            AND NOT( $.started_at> MR.ended_at OR $.ended_at < MR.started_at)
  5. 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!"

  6. 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 create 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 create new medication request for such innm_dosage and medical_program_id')

3. Check that care plan is mandatory for programs

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

      Code Block
      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

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

4. Check diagnosis comply with programs

Applies to programs: any

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_codes dictionary

      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

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:Check that medication request period (ended_at - started_at) less than or equal to MEDICATION_REQUEST_MAX_PERIOD_DAY parameter from chartsin case of error - return 200 with status = INVALID and rejection_reason = “Period length exceeds default maximum value“

8. Validate context

  1. Validate "context" is an active (not entered-in-error) entity from corresponding dictionary, that belongs to the current patient

    1. Validate there is an entity in collection $.data.context.identifier.type.coding[0].code with id == $.data.context.identifier.value that belongs to the current patient

      1.  in case of error - return 200 with status = INVALID and rejection_reason = “Encounter entity is not found for program“

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

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

9. Valdate person

Applies to programs: any

Validation purpose: It is needed to check if person has allowed verification status to get medication.

Validate person's verification status as described on Create Medication request Request

10. Validate declaration for a program

Validation purpose: It is needed to check specified params for each medical program.

Declaration should always be validated for each program. Validate skip_medication_request_employee_declaration_verify and skip_medication_request_legal_entity_declaration_verify  parameters at medical program settings as described at Create Medication request Request if there are some exclusions.

Generate structure for response

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