Table of Contents |
---|
Specification
Purpose
This WS is designed to qualify Medication request (post) - check the ability of using Medication request within the Medication program.
Input parameters (filters)
id
ARRAY [program] (mandatory)
Authorize
Verify the validity of access token
Check user scope (scope = 'medication_request:details') in order to perform this action
In case error - generate 401 response
Validate request (JSON schema)
Validate request using JSON schema
Validate FK
Validate id - medication_request_id exists
Return 404 in case (not found medication request in DB with this ID)
Validate [programs.id] - medical programs id exists
Return 422 in case validation fails (422 EView - not found medical program in DB with this ID)
Get Medication Request
Invoke Get Medication request by ID
Validation status
For info - status charts: Medication_request
Check Medication Request `status` = ACTIVE
if invalid - return 409 error (message: "Invalid status Medication request for qualify action!")'
Validate related Care plan
If medication_request.based_on is present and not null:
Verify Care plan:
It should be in active status
in case of error - return 409 (message: "Care plan is not active")
Care plan's period end (if exist) should be greater than current date or equal.
in case of error - return 409 (message: “Care plan expired“)
Verify care plan Activity:
It has scheduled, in_progress status
in case of error - return 409 (message: "Invalid activity status")
If it has quantity then calculate remaining quantity:
select all MRR in status NEW which based on current activity
select all MR in statuses ACTIVE, COMPLETED based on current activity
calculate reserved at the moment medication quantity as sum of medication_qty in the filtered MRR and MR list, including medication_qty from current MRR
calculate remaining quantity by subtracting reserved quantity from activity quantity
Check remaining quantity is greater then or equal to zero
in case of error return 409 "The total amount of the prescribed medication quantity exceeds quantity in care plan activity"
Validate division
If division_id submitted:
Validate division is active
in case of error - return 409 ("Division is not active")
Validate division belongs to user's legal entity
in case of error - return 409 ("Division does not belong to user's legal entity")
If chart parameter DISPENSE_DIVISION_DLS_VERIFY is on, then validate division is DLS verified (dls_verified=true)
in case of error - return 409 "Division is not verified in DLS"
If chart parameter MEDICAL_PROGRAM_PROVISION_VERIFY, then check division provide each submitted program. For each medical program provision validate:
it is exist and active:
in case of error - return 409 ("Division is not provide the medical program")
it relate to the actual reimbursement contract: contract.start_date <= current_date <= contract.end_date, is_active = true, status = VERIFIED.
in case of error - return 409 ("Medical program provision is not actual for the current date")
Logic for qualify (analyze compliance with 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
Validate 2 checks (below in the text) for programs
if passed - save status this program for response = VALID
Check INNM_dosage compliance for the programs
Applies to the following programs:
...
|
Check absence a same medication for the programs
Applies to the following programs:
Dostupni liky
Netsukrovyy diabet
Insuliny z doplatoyu
Insuliny bezoplatno
Epilepsiya
Rozlady psykhiky ta povedinky
Validation purpose: It could be done several dispenses for one medication request per one innm for one patient until sum(medication_dispenses.medication_qty) < medication_request.medication_qty
...
For info - status charts: Medication Request Status Chart & Medication Dispense Status Chart
Get `check_innm_id`
Code Block SELECT I.innm_child_id FROM ingredients I WHERE I.parent_id = _MR.medication_id AND I.is_primary = TRUE
Get Medication requests with their linked completed Medication dispense by person_id & innm_id
Code Block SELECT * FROM medication_requests MR INNER JOIN medication_dispense MD ON MD.medication_request_id = MR.id AND MD.status IN (PROCESSED) INNER JOIN ingredients I ON I.parent_id = MR.medication_id -- type = INNM_DOSAGE AND I.innm_child_id = `check_innm_id` AND I.is_primary = TRUE WHERE MR.person_id == _MR.person_id AND MR.status IN (ACTIVE, COMPLETED) AND NOT($.started_at> MR.ended_at OR $.ended_at < MR.started_at)
Validate medication request_id
for medication_dispense.medication_request_id !== $.id
Validate exist (IF EXIST () - that is any crossing calculating term (started_at + ended_at) for payload with terms selecting Medication requests with linked Medication dispense (started_at + ended_at)).
if found
get $.medical_programs.medical_program_setting by medical_program_id from request
validate skip_mnn_in_treatment_period variable
in case skip_mnn_in_treatment_period == FALSE (or absent)
validate request according to logic:
add to response: status = INVALID
add to response: rejection_reason = "For the patient at the same term there can be only 1 dispensed medication request per one and the same innm!"
in case skip_mnn_in_treatment_period == TRUE
skip validating frequency of receiving drugs
for medication_dispense.medication_request_id = $.id
Validate medication request qty: sum(medication_dispenses.medication_qty) >= medication_request.medication_qty
if found
add to response: status = INVALID
add to response: rejection_reason = "Sum of dispense's medication quantity can not be more then medication_request.medication_qty"
Generate structure for response
Collect response array for all programs in payload with status for each (VALID or INVALID) and rejection_reason
For all VALID programs - Get linked medications (type = BRAND) with reimbursement info
Show only active program medications based on start_date and end (start_date must be earlier or equal to current date or empty, end_date must be greater or equal to current date or empty)
Code Block SELECT * FROM program_medications pm INNER JOIN ingredients i ON (i.parent_id = pm.medication_id AND i.medication_child_id = :medication_request_medication_id AND i.is_primary = TRUE) INNER JOIN medications m ON (m.id = pm.medication_id) WHERE pm.medical_program_id = $.id AND pm.is_active = TRUE AND m.is_active = TRUE AND (pm.start_date <= now() OR pm.start_date IS NULL) AND (pm.end_date >= now() OR pm.end_date IS NULL)
Prepare & return response data structure
Fill response WS data structure
Validate response using JSON schemas
Return 422 with list of validation errors in case validation fails (422 EView)