…
Validation of the request
Validate resources or block of resources
Approvals are processed in the async way
Validate resources
Search for the resource in DB is done by the pair patient_id
+ resources_id
due to solution architecture when all resources must be discovered via patient identifier
In case no records found using this combination - system will respond with 404 error
if episode_of_care is presented in request as the code of resource
Check episode_of_care in the request exists and is in active or closed status in DB
in case of error return - 422 (Episode is canceled)
Check if resource from granted_to = 'employee':
in case of error return - 422 ("$.resource. value is not allowed in enum")
if diagnostic_report is presented in request as the code of resource
Check diagnostic_report block in the request exists and is in final status in DB
in case of error return - 422 (Diagnostic report in \"entered_in_error\" status can not be referenced or Diagnostic report with such id is not found)
Check if resource from granted_to = 'employee':
in case of error return - 422 ("$.resource. value is not allowed in enum")
if care_plan is presented in request as the code of resource
Check care_plan in the request exists in DB
in case of error return - 422 (Care plan with such id is not found)
Check there no other objects in request
in case of error return - 422 (Approval for care plan can not contain other entities)
Check if resource from granted_to = 'employee':
in case of error return - 422 ("$.resource. value is not allowed in enum")
If access_level = 'write':
Check if care_plans.managing_organization = granted_to.employees.legal_entity_id:
in case of error return - 422 ('User is not allowed to write care plan from another legal_entity')
if encounter is presented in request as the code of resource
Check encounter in the request exists in DB and is not in “entered_in_error” status in DB
(Encounter in \"entered_in_error\" status can not be referenced or Encounter with such id is not found)
Check if resource from granted_to = 'employee':
in case of error return - 422 ("$.resource. value is not allowed in enum")
Validate episode related to the encounter:
exists
in case of error - return 422 ('Encounter refers to episode that does not exist')
is “active” or “closed”
in case of error - return 422 ('Encounter refers to episode that is not active or closed')
it’s managing organization matches with author’s legal entity (client_id)
in case of error - return 422 ('Encounter is from another legal entity')