Purpose
This WS is designed to qualify Medication request (post) - check the ability to use Medication request within the Medication program and receive program participants
...
Page Properties | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
MR should be found by number
Input parameters
Input parameter | Values | Type | Description | Example |
---|---|---|---|---|
id | String | Medication request identifier. Required. | 2848a935-5fd7-48ba-b235-a9b5d475c647 |
Request structure
See on Apiary
...
For info - status charts: Medication_request.
Check Medication Request `status` = ACTIVE
if invalid - return 409 error (message: "Invalid status Medication request for qualify action!")'.
...
Verify Care plan:
It should be in active status
in case of error - return 409 (message: "Invalid care plan status").
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").
Validate quantity is not exceeded
Select all MD (medication dispenses) in status PROCESSED related to the Medication requests which based_on one activity
Sum medication_qty in the filtered Medication dispenses as dispensed_qty
medication_qty from current MR as current_qtyCalculate remaining_qty = activity.quantity - (dispensed_qty
+current_qty)
Check remaining_qty is greater then zero
error return 409 "The total amount of the dispensed medication quantity exceeds quantity in care plan activity"
Validate division
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"
Check division participates in submitted programs. Validate Provision for each Medical Program:
If the medical program has no
setting skip_contract_provisionsetting skip_dispense_division_dls_verify or it is
equal toset in false/null validate:
if medical program in the request has funding_source one of NHS, LOCALCheck $.division.dls_verify == true:
In case of error - return
provision exist and active for the division:
in case of error - return status=INVALID for a program, rejection_reason= "Division does not provide the medical program"409 "Invalid division dls status"
else if skip_dispense_division_dls_verify = true, then skip license verification for the division
Check division participates in submitted programs. Validate Provision for each Medical Program:
If the medical program has no setting skip_contract_provision_verify or it is equal to false/null:
if it is exists andif medical program in the request has funding_source = one of NHS:
provision relates to the actual reimbursement contract: contract.start_date <= current_date <= contract.end_date, is_active = true, status = VERIFIED, contracts.type==reimbursement, contracts.contractor_legal_entity_id=token.client_id, contracts.medical_program_id==$.medical_program_id, LOCAL
In case of error - return status=INVALID for a program, rejection_reason="Program was configured incorrectly. Either incorrect source of funding or option skip_contract_provision_verify"
provision exist and active for the division:
in case of error - return status=INVALID for a program, rejection_reason= "
Medical program provision is not related to any actual contract for the current date"contract is_suspended = false
in case of error - return status=INVALID for a program, rejection_reason="Contract with number <contract_number> is suspendedDivision does not provide the medical program"
if medical program in the request has funding_source = LOCAL, then check medical_program_provision.msp_legal_entity_id = medication_request.legal_entity_NHS:
provision relates to the actual reimbursement contract: contract.start_date <= current_date <= contract.end_date, is_active = true, status = VERIFIED, contracts.type==reimbursement, contracts.contractor_legal_entity_id=token.client_id, contracts.medical_program_id==$.medical_program_id
in case of error - return status=INVALID for a program, rejection_
reason="Medical program
else if skip_contract_provision_verify = true, then skip provision verification for the medical program
Get license_types_allowed parameter from settings of medical program from request $.medical_program_id:
provision is not related to any actual contract for the current date"
contract is_suspended = false
in case of error - return status=INVALID for a program, rejection_reason="Contract with number <contract_number> is suspended"
if medical program in the request has funding_source = LOCAL, then check medical_program_provision.msp_legal_entity_id = medication_request.legal_entity_id
in case of error - return status=INVALID for a program, rejection_reson = "Medical program can not be provided for the legal entity specified in the medication request"
else if skip_contract_provision_verify = true, then skip provision verification for the medical program
Get license_types_allowed parameter from settings of medical program from request $.medical_program_id:
if it is exists and not empty, get list of all license types from parameter.
Check that division has active healthcare services with following parameters:legal_entity_id = client_id from access token
division_id = division_id from request
status = 'ACTIVE'
licensed_healthcare_service.status = 'ACTIVE'
healthcare_service.license_id is not null and licenses.type = value from license_types_allowed parameter
in case of error - return status=INVALID for a program, rejection_reason = 'Division does not have active licenses to provide the medical program'
Logic for qualify (analyze compliance with programs)
...
Check INNM_dosage compliance for the programs
Validation purpose: There There is a list of medications (which links to innm_dosage) which can be used for the program. It must be check whether there is at least one available medication for the innm_dosage for the particular program.
Check that there is at least one medication (brand or innm_dosage) associated with medical program that can be dispensed to the patient
Get info from Medication request by id in payload, set temp variable object `_MR`.
Validate the compatibility of innm with the medication program list
if data is not found:
add to response: status = INVALID
add to response: rejection_reason = "Innm not on the list of approved innms for program '#{program.name}"
...
Code Block |
---|
IF EXISTS
(SELECT * FROM program_medications MP
INNER JOIN medications M
ON M.id = MP.medication_id
AND M.type = BRANDS
INNER JOIN ingredients I
ON I.parend_id = M.id
AND I.is_primary = TRUE
AND I.medication_child_id = _MR.medication_id
WHERE MP.medical_program_id == $.id
AND MP.is_active == TRUE
AND M.is_active == TRUE)
|
Check absence a same medication for the programs
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
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
MedicationRequestRequest
and in MedicationRequest
...
OK
...
Create record in
MedicationRequestRequest
or in MedicationRequest
...
Not valid
...
Medications request
dispensed (COMPLETED)
...
Not valid
...
QualifyMedicationRequestByID
...
No records in
MedicationRequestRequest
and in MedicationRequest
...
Not possible
...
Create record in
MedicationRequestRequest
or in MedicationRequest
...
OK
...
Medications request
dispensed (COMPLETED)
...
Not valid
...
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".
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 nowthere are only conditionsfor 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:
Dostupni likyNetsukrovyy diabetInsuliny z doplatoyuInsuliny bezoplatno
Validation purpose: There is a list of medications (which links to innm_dosage) which can be used for the program. It must be check whether there is at least one available medication for the innm_dosage for the particular program.
Get info from Medication request by id in payload, set temp variable object `_MR`
Validate the compatibility of innm with the medication program list
if data is notSearch for active innm_dosages that associated with medical program
medications.is_active = true
medications.type = INNM_DOSAGE
program_medications.is_active = true
Search for active brands that have innm_dosage as primary ingredient and are associated with medical program
medications.is_active = true
medications.type = BRAND
ingredients.is_primary = true
program_medications.is_active = true
if nothing found:
add to response: status = INVALID
add to response: rejection_reason = "Innm not on the list of approved innms for program '#{program.name}"
|
|
|
|
|
|
|
|
|
|
Check absence a same medication
...
Applies to the following programs:
Dostupni likyNetsukrovyy diabetInsuliny z doplatoyuInsuliny bezoplatno
for the programs
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
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 | OK | Create record in | Not valid | Medications request | Not valid |
QualifyMedicationRequestByID | No records in | Not possible | Create record in | OK | Medications request | Not valid |
For info - status charts: Medication Request Status Chart & Medication Dispense Status Chart
Get `check_innm_id`
Code Block SELECT I.innm_child_id FROM FROM ingredients I WHERE I.parent_id = _MR.medication_id AND AND I.is_primary = TRUE
Get Medication requests with their linked completed Medication dispense by person_id & innm_id
MR INNERCode Block SELECT * FROM medication_requests MR
MD ONINNER JOIN medication_dispense MD
ANDON MD.medication_request_id = MR.id
INNERAND MD.status IN (PROCESSED)
I ONINNER JOIN ingredients
idI ON I.parent_id = MR.medication_
DOSAGE ANDid -- type = INNM_
id` ANDDOSAGE AND I.innm_child_id = `check_innm_
TRUE WHEREid` AND I.is_primary =
id ANDTRUE WHERE MR.person_id == _MR.person_
ANDid 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 skipvalidate
skip_mnn_in_treatment_periodskip_treatment_period variablein case skipcase
skip_mnn_in_treatment_periodperiodskip_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 skipcase
skip_mnn_in_treatment_periodskip_treatment_period period== TRUEskip 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".
Parameters that are used when processing the request
...
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 infoShow 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)
Filter participants simultaneously by container_dosage and max_request_dosage
|
Prepare & return response data structure
...