Purpose
This WS is designed to search (get list) for(of) Medication requests.
According to requirements:
User can see all Medication Requests of which he is an author
User of MSP, PRIMARY_CARE, OUTPATIENT (DOCTOR, SPECIALIST, etc) can see all Medication requests from the user's legal entity
DOCTOR can see all the Medication requests of the patients whom he has an active declaration with doctor (employee_id)User of NHS_ADMIN can see all Medication requests (without limitations)
User of MSP, PRIMARY_CARE, OUTPATIENT (DOCTOR, SPECIALIST, etc) can see all Medication request based on the approval of the care plan that is contained in the Medication request
Specification
Logic
Logic WS
Verify the validity of access token
Return 401 in case validation fails
Check user scopes in order to perform this action (scope = 'medication_request:read')
Return 403 in case invalid scope(s)
Get `my_party_id` from `$.context.user_id`
Return 500 in case ("Not found party for this user!")
Get list of employees to `my_employees_list` for this `party_id` & `$.context.legal_entity_id`
SELECT E.id FROM parties P JOIN employees E ON P.id = E.party_id JOIN party_users PU ON parties.id = party_users.party_id WHERE PU.user_id=$.context.user_id AND E.legal_entity_id = $.context.legal_entity.id
Search Medication requests by filters with use `my_employees_list` :
SELECT * FROM medication_request MR LEFT JOIN declarations D ON MR.person_id = D.person_id AND D.status = ACTIVE WHERE (MR.employee_id IN [my_employees_list] OR D.employee_id IN [my_employees_list] ) AND (MR.status = $.status OR $.status IS NULL) AND (MR.person_id = $.person_id OR $.person_id IS NULL) AND (MR.medication_id = $.medication_id OR $.medication_id IS NULL) AND (MR.number = $.request_number OR $.request_number IS NULL) AND (MR.created_at >= $.created_from OR $.created_from IS NULL) AND (MR.created_at <= $.created_to OR $.created_to IS NULL)
Logic WS for `client_type` = NHS_ADMIN
Verify the validity of access token
Return 401 in case validation fails
Check user scopes in order to perform this action (scope = 'medication_request:read')
Return 403 in case invalid scope(s)
Search Medication requests by filters:
SELECT * FROM medication_request MR WHERE AND (MR.employee_id == $.employee_id OR $.employee_id IS NULL) AND (MR.status == $.status OR $.status IS NULL) AND (MR.person_id == $.person_id OR $.person_id IS NULL) AND (MR.medication_id = $.medication_id OR $.medication_id IS NULL) AND (MR.number = $.request_number OR $.request_number IS NULL) AND (MR.created_at >= $.created_from OR $.created_from IS NULL) AND (MR.created_at <= $.created_to OR $.created_to IS NULL) AND (MR.legal_entity_id == $.legal_entity_id OR $.legal_entity_id IS NULL)
Preconditions
No
Global and configurable parameters
No
Input parameters
No
Filters
See on Apiary
Request structure
API paragraph not found
Authorize
Request to process the request using a token in the headers
Headers
Content-Type:application/json
Authorization:Bearer c2778f3064753ea70de870a53795f5c9
Validate request
API paragraph not found
Request data validation
API paragraph not found
Processing
If according to filters requests are not found, WS returns empty data array:
WS also returns pagination data - for technical info.
Response structure
See on Apiary
Example:
Post-processing processes
No
HTTP status codes
HTTP status code | Message | What caused the error |
---|---|---|
200 | Response |
|
401 | Invalid access token |
|
403 | Your scope does not allow to access this resource. Missing allowances: medication_request_request:read |
|
500 | Not found party for this user! |
Backward compatibility
API paragraph not found