Table of Contents |
---|
...
Page Properties | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Logic
...
Validate $.container_dosage field by schemata
$.container_dosage.code and $.container_dosage.value should be both filled
in case of error return 422 error ("required property %{property} was not present")
$.container_dosage.system should be “MEDICATION_UNIT”
in case of error return 422 error ("value is not allowed in enum")
if $.container_dosage is filled then $.container_dosage.unit should be checked with the MEDICATION_UNIT dictionary by $.container_dosage.code as a key.in case of error return 422 error ("value is not allowed in enum")
Check if there is at list one record of Brand with requested primary container volume
a. if not exist - return 404 error (message: "Not found any appropriate medication with such container parameters")
Validate priority
Check by schemata if $.priority is filled with the value of MEDICATION_REQUEST_PRIORITY dictionary
in case of error return 422 error ("value is not allowed in enum")
...
Validate that created_at, started_at, ended_at in date format
in case invalid return 422 with msg ("expected \"%{actual}\" to be a valid ISO 8601 date")
Validate ended_at >= started_at
if invalid - return 422 error (message: "Ended date must be >= Started date!")
Validate started_at >= created_at, but not greater than (created_at + MEDICATION_REQUEST_REQUEST_EXTENDED_LIMIT_STARTED_AT_DAYS)
if invalid - return 422 error (message: "The start date should be equal to or greater than the creation date, but the difference between them should be not exceed {{MEDICATION_REQUEST_REQUEST_EXTENDED_LIMIT_STARTED_AT_DAYS}} day(s).")
Validate started_at >= current_date()if invalid - return 422 error (message: "Started date must be >= current date!")
Validate created_at >= current_date() - MEDICATION_REQUEST_REQUEST_DELAY_INPUT chart param
if invalid - return 422 error (message: "Create date must be >= Current date - MRR delay input!")
Validate started_at regarding frequency of receiving drugs
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: PreQualify Medication request: 2. Check absence the same medications for the programs
in case skip_mnn_in_treatment_period == TRUE
skip validating frequency of receiving drugs
Validate created_at regarding frequency of receiving drugs
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: PreQualify Medication request: 2. Check absence the same medications for the programs
in case skip_mnn_in_treatment_period == TRUE
skip validating frequency of receiving drugs
Validate period length (ended_at - started_at):
If medical program has been submitted:
validate request according to logic: PreQualify Medication request: 7. Validate period
else:
Check that medication request period less than or equal to MEDICATION_REQUEST_MAX_PERIOD_DAY parameter from charts
in case of error - return 409 “Period length exceeds default maximum value“
...
Verify Care plan:
It should belong to the same person as set in MRR
in case of error return 422 with msg ("Care plan not found")
It should be in active status
Verify submitted Activity:
It belongs to the Care plan.
in case of error return 422 with msg ("Activity not found")
It has activity.detail.kind=medication_request; activity.detail.product_reference=medication_id.
in case of error return 422 with msg ("Invalid activity kind")
It has scheduled, in_progress status.
in case of error return 422 with msg ("Invalid activity status")
if it has quantity then calculate remaining quantity:
validate $.activity.details.remaining_quantity_type:
if $.activity.details.remaining_quantity_type =for_request than:
select all MRR in status NEW which based on current activity
select all MR in statuses ACTIVE based on current activity
select all MD (medication dispenses) in status PROCESSED related to the Medication requests which are in status COMPLETE, REJECTED, EXPIRED
calculate:
reserved_qty as sum of medication_qty in the filtered MRR and MR list
dispensed_qty as sum of medication_qty in the filtered MD list
current_qty as medication_qty from current MRR
calculate remaining quantity by subtracting reserved_quantity, dispensed_qty, current_qty from activity quantity
if $.activity.details.remaining_quantity_type = for_use than:
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"
check that medical_program_id equal to $.activity[].program
in case of error return 422 with msg ("Medical program from activity should be equal to medical program from request")
Validate started_at/ended_at of Medication request Request:
if care plan activity has detail.scheduled_timing.repeat.bounds_period - validate started_at/ended_at within bounds_period
if care plan activity has detail.scheduled_period - validate started_at/ended_at within scheduled_period
else - validate started_at/ended_at
crossingwithin care_plan.periodin the case of started_at/ended_at is not within care_plan.period return 422 with msg ("Invalid care plan period")
...
set:
dispense_valid_from = created_at
dispensed_valid_to = dispensed_valid_from + dispense_period
Fill 'data' structure for Response & save in IL.medication_request_requests
If encounter is present in the request context then based on it - fill the IL.medication_request_requests.context_episode_id
Fill separately
data_employee_id,
data_intent,
data_based_on_care_plan_id,
data_based_on_activity_id,
data_context_id,
data_patient_id,
data_legal_entity_id
Update based_on
If the medication request request is based on activity with quantity - set remaining_quantity for the activity which was calculated at validation Create Medication Request: Validate based_on (p. 2.d.1 )
Generate content for response
...