Purpose
This method is designed to process previously created Medication dispense.
...
Page Properties | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Logic
Save signed content to media storage.
Update Medication dispense data in OPS DB:
set status = ‘PROCESSED’
updated_by = user_id
updated_at = now()
Update related Medication request data in OPS DB:
set status = ‘COMPLETED’
updated_by = user_id
updated_at = now()
Write changes to event manager (Medication dispense and Medication request).
Change Care plan activity (If related medication request has reference on Care plan, then corresponding care plan activity should be changed in async way after Medication dispense processed. Update activity events invokes using ops.medication_dispense_process table):
Set activity status to in_progress if previous activity status was scheduled.
Check the MD identifier in outcome_reference attribute of the activity:
if not found:
Add reference on the medication dispense resource to the outcome_reference attribute .
If quantity in the activity was set then calculate and set remaining quantity:
select all MD in status PROCESSED related to MR which based on care plan and current activity;
calculate dispensed quantity in the current activity as sum of medication_qty in the filtered MD list;
calculate remaining quantity by subtracting dispensed quantity from activity quantity;
update remaining_quantity value in the activity with calculated value.
If found, then skip updating activity (it means that activity has been already updated by event from current MD processing).
...
Validate request is signed
in case of error - return 400 (“document must be signed by 1 signer but contains 0 signatures”).
Validate that DS is valid and not expired.
Validate that DS belongs to the user
Check that DRFO from DS and party.tax_id matches
in case of error - return 422 (“Does not match the signer drfo“).
Check that Last Name from DS and party.last_name matches
in case of error - return 422 (“Does not match the signer last name“).
Validate Medication dispense
...
Check that signed content is equal to online generated dispense with ids in DB:
Do not compare:
payment_amount field;
payment_id field;
medication_request/legal_entity object;
medication_request/division object;
medication_request/employee object;
medication_request/person/id field;
medication_request/rejected_at field;
medication_request/rejected_by field;
in case error return 422 ("Signed content does not match to previously created dispense").
...
Validate related Medication request
Medication request should be active in order to process medication dispense
is_active = true
status = 'ACTIVE'
In case error - return 409 ("Medication request is not active").
Medication request should not be blocked in order to process medication dispense
is_blocked <> true
In case error - return 409 ("Medication request is blocked").
Check if related medication request has reference on the Care plan - based_on attribute filled. If it has, validate following:
...
Page Properties | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...