ЕСОЗ - публічна документація
(RC-1 MRIN) PreQualify Medication request
Specification
Apiary | |
JSON Schema request | |
JSON Schema response |
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
Verify the validity of access token
Check user scope (scope = 'medication_request_request:write') in order to perform this action
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.
Check medication request intent
if medication request intent == plan - return 409, "Plan can't be qualified"
Check that care plan is mandatory for programs
Applies to the following programs:
Netsukrovyy diabet
Insuliny z doplatoyu
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.
Check if there is a based_on in the request
Check care_plan_required value
SELECT medical_program_setting->>'care_plan_required' FROM medical_programs WHERE id = 'medical_program_id';
if care_plan_required true:
check based_on (reference on care_plan and it activity) in request
in case based_on not found:
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>\""
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"
2 checks (below in the text) must be passed for the program "DOSTUPNI LIKI"
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
Check compatibility of innm with medication list for the program
if data is not found:
add to response: status = INVALID
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 |
---|---|---|---|---|---|---|
PreQualifyMedicationRequestRequest | No records in MedicationRequest | OK | Created record in MedicationRequest | Not valid | Medications request | Not valid |
QualifyMedicationRequestByID | No records in MedicationRequest | Not possible | Create record in MedicationRequest | OK | Medications request | Not valid |
For info - status charts: Medication_request
Get `check_innm_id`
SELECT I.innm_child_id FROM ingredients I WHERE I.parent_id = $.medication_id AND I.is_primary = TRUE
Get Medication requests with their completed Medication dispense by person_id & check_innm_id
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)).
if found
add to response: status = INVALID
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!"
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_dayin 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_dayin 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
ЕСОЗ - публічна документація