ЕСОЗ - публічна документація
(RC-1 MRIN) Create Medication request Request
- 1 Specification
- 2 Purpose
- 3 Authorize
- 4 Validate request (JSON schema)
- 4.1 Validate employee
- 4.2 Validate division
- 4.3 Validate legal entity
- 4.4 Validate person
- 4.5 Validate dates
- 4.6 Validate medication
- 4.7 Validate context
- 4.8 Validate dosage instruction
- 4.9 Validate based_on
- 4.10 Validate medical program
- 4.11 Validate multiplicity & medication request allowed for participants
- 5 Generate number & verification_code for Medication request
- 6 Create Medication request Request
- 7 Generate content for response
Specification
Purpose
This WS is designed to create Request fo Medication request
There are two types of medication request:
plan - The request represents an intention to ensure something occurs without providing an authorization for others to act. Medication request with type plan can't be dispensed and only provide the instruction to administer the medicine.
order - The request represents a request/demand and authorization for action. Medication request with type order can be dispensed
Authorize
Verify the validity of access token
Check user scope (scope = 'medication_request_request:write') in order to perform this action
In case error - generate 401 response
Validate request (JSON schema)
Validate request using JSON schema.
in case of error return 422 error with msg ("required property %{property} was not present")
Validate employee
Purpose validation: Validation of an employee for the possibility of creating a medication request.
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")
Validate that $.employees.employee_type == <employee_type>
in case medical_program_id present in request validate medical_program_settings.skip_employee_validation == false (or absent)
validate <employee_type>
get $.medical_programs.medical_program_setting by medical_program_id from request
validate that employee_type present in 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
get $.declarations by employee_id, person_id, status=ACTIVE or check MEDICATION_REQUEST_DECLARATION_VERIFY param (which allow to create medication request for any doctor from LE where person have declaration)
if not found - return 422 error (message: "Employee must have an active declaration with the patient to create medication request!")
in case employee_type = SPECIALIST
get $.employees.speciality.speciality(speciality_officio == true)
validate that speciality present in$.medical_programs.medical_program_setting.speciality_types_to_create_medication_request 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 = <XXX>
in case invalid return 422 error with msg ("Employee type can't create medication request with medical program from request")
in case medical_program_settings.skip_employee_validation == true or there is no medical_program_id in the request, any user who has a scope can create medication request
Validate division
Purpose validation: Validation of division for the possibility of creating a medication request.
Invoke Get division details
Validate division_id - division_id exists
in case invalid return 422 error with msg ("Division not found")
Validate Response $.data.status==ACTIVE
if not found - return 422 error (message: "Only employee of active divisions can create medication request!")
Division should be active and refers to current legal_entity
is_active = true
status = 'ACTIVE'
division.legal_entity_id = client_id (context)
Validate legal entity
Purpose validation: Validation of legal entity for the possibility of creating a medication request.
Get client_id from token
Validate client_id=legal_entity_id
check that legal_entity exist
in case invalid return 422 error with msg (422 Legal entity not found)
check that legal_entities.status == ACTIVE
in case invalid return 422 error with msg ("Only active legal entity can provide medication request")
Validate person
Purpose validation: Validation of person for the possibility of creating a medication request.
Invoke Get patient by ID
Validate person_id - mpi_id exists
in case invalid return 422 (422 Person not found)
Save temporary variables from: $.data.authentication_methods
Validate Response $.data.is_active==TRUE
if not found - return 422 error (message: "Only for active MPI record can be created medication request!")
Validate dates
created_at - similar to assertion date in FHIR -> Actual date medication request being created
inserted_at - date when Medication request was registered in E-Health
dispence_valid_from - Used for dispense validation. As for now equals Created at.
dispense_valid_to - Dispense valid from + medication_dispense_period parameter value. Implements dispense expiration period.
Purpose validation: Must be: ended_at >= started_at >= created_at
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
if invalid - return 422 error (message: "Started date must be >= Created date!")
Validate started_at >= current_date()
if invalid - return 422 error (message: "Started date must be >= current date!")
Validate created_at >= current_date() - mrr_delay_input
if invalid - return 422 error (message: "Create date must be = current date!")
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.Checkabsencethesamemedicationsfortheprograms
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.Checkabsencethesamemedicationsfortheprograms
in case skip_mnn_in_treatment_period == TRUE
skip validating frequency of receiving drugs
Validate medication
Purpose validation: Check FK, status `is_active`=TRUE, type = INNM_DOSAGE
Invoke Get INNM Dosage by ID
Validate medication_id - medication_id exists
in case of error return 422 ("Medication not found")
Validate Response code == 200
if invalid - return 422 error (message: "Only medication with type `INNM_DOSAGE` can be use for created medication request!")\
Validate Response $.is_active==TRUE
if not found - return 422 error (message: "Only active innm_dosage can be use for created medication request!")
Validate context
Validate "context" is an active (not entered-in-error) entity from corresponding dictionary, that belongs to the current patient
Validate there is an entity in collection $.data.context.identifier.type.coding[0].code with id == $.data.context.identifier.value that belongs to the current patient
in case of error 409 "{$.data.context.identifier.type.coding[*].code} not found"
Validate that entity is not in status "entered-in-error"
in case of error 409 "Entity in status "entered-in-error" can not be referenced"
Validate dosage instruction
Each non-empty attribute must be valid and reference to appropriate dictionary or object
Sequence must be unique within dosage instruction array
in case of error return (422, "Sequence must be unique")
Additional instruction must refer to a valid dictionary
$.dosage_instruction[*].additional_instruction.coding[*].system == "eHealth/SNOMED/additional_dosage_instructions"
$.dosage_instruction[*].additional_instruction.coding[*].code is a valid entry in dictionary "eHealth/SNOMED/additional_dosage_instructions"
in case of error return 409 "Incorrect additional instruction"
Site must refer to a valid dictionary
$.dosage_instruction[*].site.coding[*].system == "eHealth/SNOMED/anatomical_structure_administration_site_codes"
$.dosage_instruction[*].site.coding[*].code is a valid entry in dictionary "eHealth/SNOMED/anatomical_structure_administration_site_codes"
in case of error return 409 "Incorrect site"
Route must refer to a valid dictionary
$.dosage_instruction[*].route.coding[*].system == "eHealth/SNOMED/route_codes"
$.dosage_instruction[*].route.coding[*].code is a valid entry in dictionary "eHealth/SNOMED/route_codes"
in case of error return 409 "Incorrect route"
Method must refer to a valid dictionary
$.dosage_instruction[*].method.coding[*].system == "eHealth/SNOMED/administration_methods"
$.dosage_instruction[*].method.coding[*].code is a valid entry in dictionary "eHealth/SNOMED/administration_methods"
in case of error return 409 "Incorrect method"
Dose and rate type must refer to a valid dictionary
$.dosage_instruction[*].dose_and_rate.type.coding[*].system == "eHealth/SNOMED/dose_and_rate"
$.dosage_instruction[*].dose_and_rate.type.coding[*].code is a valid entry in dictionary "eHealth/SNOMED/dose_and_rate"
in case of error return 409 "Incorrect dose and rate type"
Validate based_on
If submitted, check field has array with two values of Reference type: one is valid Care plan resource, another - Activity resource.
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
Care plan's period end (if exist) should be greater than current date or equal.
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;
in case of error return 422 with msg ("Invalid activity kind")
activity.detail.product_reference=medication_id.
in case of error return 422 with msg ("Invalid activity product reference")
It has scheduled, in_progress 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")
Verify activity period:
If it has scheduled_timing:
if bounds_period.end defined then check it greater than current date or equal.
If it has scheduled_period:
if scheduled_period.end defined then check it greater than current date or equal.
Validate medical program
Validate medical_program_id - medical_program_id exists
in case of error return 422 ("Medical program not found")
Validate medical_programs.medical_program_setting parameters
check if care_plan_required == true then the request should contain a based_on with care plan and activity that contains the same medical program
in case of error return 422 with msg ("Care plan and activity with the same medical program should be present in request")
Validate multiplicity & medication request allowed for participants
Purpose validation: Request quantity must have multiplicity package_min_qty for linked medications. Result (Mod or % operator) must = 0 .
Also if present Medical_program - must exists medications with `medication_request_allowed`== TRUE for participants.
If `$.medical_program_id` present in payload (non null) - Check exist (IF EXIST()) medication & participant
if not exist - return 404 error (message: "Not found any medications allowed for create medication request for this medical program!")
SELECT * FROM medications MI -- 2nd level: Medication - type = INNM_DOSAGE INNER JOIN ingredients I ON I.medication_child_id = MI.id AND I.is_primary =TRUE INNER JOIN medications MED -- 3rd level: Medication - type = BRAND ON MED.type == BRAND AND I.parent_id = MED.id AND MED.is_active == TRUE INNER JOIN program_medications MP ON MP.medical_program_id == `DOSTUPNI LIKI` MED.id = MP.medication_id AND MP.is_active == TRUE AND MP.medication_request_allowed == TRUE WHERE MI.id == $.medication_id AND MI.type == INNM_DOSAGE AND MI.is_active == TRUE
Check exist (IF EXIST()) medication & get combinations of manufacture
if not exist - return 404 error (message: "Not found any active linked medication for this innm dosage!")
SELECT DISTINCT MED.package_min_qty FROM medications MI -- 2nd level: Medication - type = INNM_DOSAGE INNER JOIN ingredients I ON I.medication_child_id = MI.id AND I.is_primary =TRUE INNER JOIN medications MED -- 3rd level: Medication - type = BRAND ON MED.type == BRAND AND I.parent_id = MED.id AND MED.is_active == TRUE WHERE MI.id == $.medication_id AND MI.type == INNM_DOSAGE AND MI.is_active == TRUE
Vaildate multiplicity (Mod == 0) for all elements in result (`$.medication_qty` Mod `MED.package_min_qty` == 0)
if all result of Mod operator - NOT 0 - return 409 eror (message: "The amount of medications in medication request must be divisible to package minimum quantity")
Generate number & verification_code for Medication request
Generate human readable number for receipt (See specs)
Structure number XXXX-1234-5678-9012-345-C , where: - XXXX - series: numbers + only some letters (A, E, H, K, M, P, T, X) - 1234-5678-9012-345 - randomly generated numbers - C - checksum: Should be calculated using the Damn algorithm or Verhoeff algorithm After new Request number was generated we should check that it is unique in the DB (entity: medication_request + medication_request_request
Generate verification_code for MPI.person_authentication_methods == OTP or OFFLINE
Create Medication request Request
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
Generate content for response
Generate data structure with Responce WS structure
Set IL.medication_request_requests this structure
in case if response is VALID enrich response with urgent_data:
get authetification_method by person_id and return masked number (in case if any)
ЕСОЗ - публічна документація