Table of Contents |
---|
...
If medication dispense has medical program with setting skip_contract_provision_verify = true, than skip contract validation
Else validate there is a contract in PRM.contracts that meets following requirements:
...
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 "Invalid division dls status"
If chart parameter MEDICAL_PROGRAM_PROVISION_VERIFY, then check division provide each submitted program. For each Medical Program Provision validate following:
If the medical program has no setting skip_contract_provision_verify or it is equal to false/null:
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"
else if skip_contract_provision_verify = true, then skip provision verification for the medical program
Qualify medication request
...
In case of error - return 403 error (message = "No more medication dispense could be done with this medication request")
Validate availability of active (status “NEW”) madication dispense
Check availability of madication dispense with the “NEW” status and the same medication_request_id:
if there isn't - move to the next validation
in case of error - return 422 "Active medication dispense already exist."
Validate medication quantity
Get multi_medication_dispense_allowed parameter from medical program settings:
if it is true - check that requested medication quantity less or equal to medication quantity in Medication Request
sum(:medication_qty) <= medication_request.medication_qty
in case of error - return 422 "Dispensed medication quantity must be lower or equal to medication quantity in Medication Request. Available quantity is #{available_qty}"
if it is false (absent) - check that requested medication quantity equal to medication quantity in Medication Request
medication_qty = medication_request.medication_qty
in case of error - return 422 "Dispensed medication quantity must be equal to medication quantity in Medication Request"
...
Get reimbursement amount for this medication_id according to medical_program_id
Determine calculation channel (FIXED, EXTERNAL)
Calculate reimbursement amount for the requested quantity of medications:
Get the reimbursement_amount from program_medications.reimbursement.reimbursement_amount (for the package)
Based on it, package_min_qty and requested medication_qty calculate the ratio and allowed reimbursement amount ((reimbursement_amount/package_qty)*medication_qty)
Service logic
Get skip_medication_dispense_sign from medical program settings.
If skip_medication_dispense_sign = false or absent:
2.1. Check payment_id, payment_amount is absent in the request.
in case if present - return 422 with path: $.<field_name> and message "schema does not allow additional properties"
2.2. Add record to medication_dispenses table:
Parameter | Source | Description |
---|---|---|
id | UUID | Autogenerated |
payment_id | NULL | NULL for new records |
payment_amount | NULL | NULL for new records. |
status | Const: NEW | NEW skip_medication_dispense_sign = false |
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 |
2.3. Add records to medication_dispense_details table:
Parameter | Source | Description |
---|---|---|
id | UUID | Autogenerated |
medication_dispense_id | FK: medication_dispense | |
reimbursement_amount |
3. If skip_medication_dispense_sign =
true:
3.1. Check if payment_amount in the request.
in case is absent - return 422 with path: $.payment_amount and message "required property payment_amount was not present"
3.2. Call Process Medication Dispense process, but without validation of digital sign and storage signed content to the bucket.
3.3. Add records as described on steps 2.2-2.3, but with following differences:
medication_dispenses table
Parameter | Source | Description |
---|---|---|
payment_id | Request: payment_id | optional parameter |
payment_amount | Request: payment_amount | required parameter |
status | Const: PROCESSED | PROCESSED skip_medication_dispense_sign = true |