Table of Contents |
---|
Purpose
...
Table of Contents |
---|
Purpose
This method is designed to create hold (reservation) on medication in order to prevent multiple dispenses under the same Medication Request. This hold lasts certain time (configuration parameter MEDICATION_DISPENSE_EXPIRATION) after with it goes to EXPIRED status
...
In case medications are dispensed to patient under specific medical program, program medication id must be provided provided by client or calculated by the system
In case program medication id exists in request:
Check that this program medication id relates to provided medical program and relates to provided medication
In case of error - return 422 (Invalid program medication id)
Calculate program medication id if it is absent in request:
Get last program_medication_id related to medical program and medication
In case of error - return 422 (There are no active program medications for this program and medication)
Get legal entity from token
Extract legal_entity_id (client_id) from token
Get Party from token
Extract party_user (user_id) from token.
Validate FK
Validate
legal_entity_id - legal_entity_id exists
In case error - return 422 error:specific medical program, program medication id must be provided provided by client or calculated by the system
In case program medication id exists in request:
Check that this program medication id relates to provided medical program and relates to provided medication
In case of error - return 422 (Invalid program medication id)
Calculate program medication id if it is absent in request:
Get last program_medication_id related to medical program and medication
In case of error - return 422 (There are no active program medications for this program and medication)
Get legal entity from token
Extract legal_entity_id (client_id) from token
Get Party from token
Extract party_user (user_id) from token.
Validate FK
Validate
legal_entity_id - legal_entity_id exists
In case error - return 422 error:
Code Block |
---|
{:error, [{%{
description: "Legal entity not found",
params: [],
rule: :invalid
}, "$.legal_entity_id"}]} |
Validate
medication_request_id - medication_request_id exists
Code Block |
---|
{:error, [{%{ description: "LegalMedication entityrequest not found", params: [], rule: :invalid }, "$.legalmedication_entityrequest_id"}]} |
Validate
medicationparty_request_id - medicationparty_request_id exists
Code Block |
---|
{:error, [{%{ description: "Medication requestParty not found", params: [], rule: :invalid }, "$.medicationparty_request_id"}]} |
Validate
partydivision_id - partydivision_id exists
Code Block |
---|
{:error, [{%{ description: "PartyDivision not found", params: [], rule: :invalid }, "$.partydivision_id"}]} |
Validate
divisionmedical_program_id - divisionmedical_program_id exists
Code Block |
---|
{:error, [{%{ description: "DivisionMedical program not found", params: [], rule: :invalid }, "$.division_id"}]} |
Validate
...
rule: :invalid
}, "$.medical_program_id"}]} |
5.1 Validate there is a contract in PRM.contracts that meets following requirements:
contracts.type==reimbursement
contracts.status==VERIFIED
Contract dates: start_date <= current_date & end_date >= current_date
contracts.contractor_legal_entity_id=token.client_id
$division_id in contract_divisionscontracts.medical_program_id==$.medical_program_id
сontracts.is_suspended ==false
In case of error 409 - "Program cannot be used - no active contract exists"
Validate all medication_id (brand_id) - brand_id exists
Code Block |
---|
{:error, [{%{ description: "Medical programMedication not found", params: [], rule: :invalid }, "$.medical_programdispense_details[:index].medication_id"}]} |
5.1 Validate there is a contract in PRM.contracts that meets following requirements:
contracts.type==reimbursement
contracts.status==VERIFIED
Contract dates: start_date <= current_date & end_date >= current_date
contracts.contractor_legal_entity_id=token.client_id
$division_id in contract_divisions
contracts.medical_program_id==$.medical_program_id
сontracts.is_suspended ==false
In case of error 409 - "Program cannot be used - no active contract exists"
Validate all medication_id (brand_id) - brand_id exists
Code Block |
---|
{:error, [{%{
description: "Medication not found",
params: [],
rule: :invalid
}, "$.dispense_details[:index].medication_id"}]} |
Validate related Care plan
If (medication_request.based_on is present and not null) AND medication_program is absent:
Verify Care plan:
It should be in active status
in case of error - return 409 (message: "Invalid care plan status")
Verify care plan Activity:
It has scheduled, in_progress status
in case of error - return 409 (message: "Invalid activity status")
...
Validate related Care plan
If (medication_request.based_on is present and not null) AND medication_program is absent:
Verify Care plan:
It should be in active status
in case of error - return 409 (message: "Invalid care plan status")
Verify care plan Activity:
It has scheduled, in_progress status
in case of error - return 409 (message: "Invalid activity status")
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 status=INVALID for a program, rejection_reason= "Division does not provide the medical program"
it relates to the actual reimbursement contract: contract.start_date <= current_date <= contract.end_date, is_active = true, status = VERIFIED.
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"
Validate code
Check that code in request is equal to code in medication_request (or both is empty)
In case code exists in request - it should match with code in medication_request
Return 401 in case code doesn't match (message = "Incorrect code")
In case code is missing in request - check that code in medication_request is NULL
Return 401 in case code in medication_request is not NULL (message = "Missing or Invalid code")
...
Add record to medication_dispenses
Parameter | Source | Description |
---|---|---|
id | UUID | Autogenerated |
payment_id | NULL | NULL for new records |
status | Const: NEW | Always NEW for new records |
is_active | Const: TRUE | Alwayls TRUE for new records |
inserted_at | Timestamp: now() | Get current date-time |
inserted_by | Token: user_id | Extract user from token |
updated_at | Timestamp: now() | Get current date-time |
updated_by | Token: user_id | Extract user from token |
Add records to medication_dispense_details
Parameter | Source | Description |
---|---|---|
id | UUID | Autogenerated |
medication_dispense_id | FK: medication_dispense | |
reimbursement_amount |