Table of Contents |
---|
Purpose
...
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")
...
Invoke employee_id from request
Validate employee
Validate that exists
in case invalid return 422 error with msg ("Employee not found")
Validate that $.employees.status == APPROVED
in case invalid return 409 error with msg ("Employee is not active")
Validate that $.employees.legal_entity_id == client_id from token
in case invalid return 422 error with msg ("Employee does not belong to legal entity from token")
If medical program has medical_program_settings.skip_employee_validation == false (or absent), then validate <employee_type>:
validate if employee_type is present in medical_program_settings.employee_types_for_create_medication_request variable
in case invalid return 422 error with msg ("Employee type can't create medication request with medical program from request")
in case employee_type = DOCTOR
if variable skip_medication_request_employee_declaration_verify = false or null/absent
then: get $.declarations by employee_id, person_id, status=ACTIVE
if not found - return 422 error "Only doctors with an active declaration with the patient can create medication request with medical program from request!"
else skip declaration verification on employee level (if true)
if variable skip_medication_request_legal_entity_declaration_verify = false or null/absent
then: get $.declarations by employee's legal_entity_id, person_id, status=ACTIVE
if not found - return 422 error "Only legal entity with an active declaration with the patient can create medication request with medical program from request!"
else skip declaration verification on legal entity level (if true)
else if both are true - skip declaration verification at all
in case employee_type = SPECIALIST
get $.employees.speciality.speciality(speciality_officio == true)
validate that speciality present in $.medical_programs.medical_program_setting.speciality_types_allowed variable
in case invalid return 422 error with msg ("Employee's specialty doesn't allow create medication request with medical program from request")
in case employee_type = MED_COORDINATOR
skip validation that speciality present in $.medical_programs.medical_program_setting.speciality_types_allowed variable
If medical program has medical_program_settings with medical_program_settings.skip_employee_validation == true any user who has a scope can create medication request
...
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:
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")
...