/
[DRAFT] REST API Get Medication Request by Id [API-005-008-002-0154]

ЕСОЗ - публічна документація

[DRAFT] REST API Get Medication Request by Id [API-005-008-002-0154]

Сторінка знаходиться в процесі розробки. Інформація на ній може бути застарілою.

https://e-health-ua.atlassian.net/wiki/spaces/EN/pages/17591304241 (remove the link block before publishing the document)

Properties of a REST API method document

Document type

Метод REST API

Document title

[DRAFT] REST API Get Medication Request by Id [API-005-008-002-0154]

Guideline ID

GUI-0011

Author

@Iryna Lishtaba (SoE eHealth)

Document version

1

Document status

DRAFT

Date of creation

04.03.2025

Date of update

04.03.2025

Method API ID

API-005-008-002-0154

Microservices (namespace)

IL

Link на API-специфікацію

https://esoz.docs.apiary.io/#reference/medical-events/medication-request/get-medication-request-by-id

Resource

{{host}}/api/medication_requests/{{id}}

Scope

medication_request:details

Protocol type

REST

Request type

GET

Sync/Async

Sync

Public/Private

Public

Purpose

This WS is designed to return Medication request detail.
Search Medication Request possible in 2 options: by `medication_request.id` OR `medication_request.request_number`.

According to requirements:

A user of MSP, PRIMARY_CARE, OUTPATIENT (DOCTOR, SPECIALIST, etc) can see all Medication request from the user's legal entity.

A user of MSP, PRIMARY_CARE (DOCTOR, etc) can see all the Medication requests of the patients whom he has an active declaration with by yourself a doctor (employee_id).

Users of PHARMACY can see all Medication requests (without limitations).

Users of MSP, PRIMARY_CARE, OUTPATIENT (DOCTOR, SPECIALIST, etc) can see all Medication requests based on the approval of the care plan that is contained in the Medication request.

Logic

  1. Verify the validity of access token

    1. Return 401 in case validation fails

  2. Check user scopes in order to perform this action (scope = 'medication_request:details')

    1. Return 403 in case invalid scope(s)

  3. Get `client_type` from `mithril.clients`

  4. Get `my_party_id`  from `$.context.user_id`

  5. Get list from `prm.employees` for this `party_id`  & `$.context.legal_entity_id`

  6. Search Medication requests by filters:

    SELECT * FROM medication_request MR     INNER JOIN employees E         ON E.party_id = my_party_id             AND (E.id = $.employee_id OR $.employee_id IS NULL)             AND (E.legal_entity_id == $.context.legal_entity_id OR $.context.legal_entity_id IS NULL)     LEFT JOIN declarations D         ON D.Employee_id = E.id             AND E.status = ACTIVE             AND D.status = ACTIVE             AND MR.person_id = D.person_id WHERE (MR.id = $.id OR MR.request_number = $.id)     AND MR.employee_id == E.id     AND MR.is_active = TRUE

Logic WS for medication requests based on care plan

  1. Get party_id  from $.context.user_id

  2. Get list from $.prm.employees for this party_id

  3. Get care_plan_id from $.medication_requests.based_on_care_plan_id

  4. Check $.approvals for user's employees (granted_to) on care_plan_id (granted_resources) and $.medication_requests.person_id (granted_by)

  5. Search Medication requests by filters: based_on_care_plan_id, person_id.

    SELECT * FROM medication_request MR WHERE (MR.id = $.id OR MR.request_number = $.id)     AND MR.based_on_care_plan_id = $.id     AND MR.person_id = $.id     AND MR.is_active = TRUE

Logic WS for `client_type` = PHARMACY

  1. Search Medication request by $.id: 

    SELECT * FROM medication_request MR WHERE (MR.id = $.id OR MR.request_number = $.id)     AND MR.is_active = TRUE

Configuration parameters

N/A

Dictionaries

N/A

Input parameters

Input parameter

Mandatory

Type

Description

Example

Input parameter

Mandatory

Type

Description

Example

1

id

M

String

Medication Request identifier OR request_number. Required.

48416485-cc98-46c4-8bba-e321de9e1ecd

Request structure

See on API-specification

Headers

Headers

Request data validation

Search Medication Request

  1. Search record by `$.id` in column `medication_request.id

    1. If not found -  Search record by `$.id` in column `medication_request.request_number`

      1. If not found - Return  404 in case "Not found"

Validate FK

  1. Read data from `ops.medication_requests` by `id`

  2. Validate legal_entity_id - legal_entity_id exists

    1. Return 422 in case validation fails (422 EView)

  3. Validate employee_id - employee_id exists

    1. Return 422 in case validation fails (422 EView)

  4. Validate division_id - division_id exists

    1. Return 422 in case validation fails (422 EView)

  5. Validate medical_program_id - medical_program_id exists

    1. Return 422 in case validation fails (422 EView)

  6. Validate all medication_id - medication_id exists

    1. Return 422 in case validation fails (422 EView)

  7. Validate person_id - mpi_id exists

    1. Return 422 in case validation fails (422 EView)

Processing

N/A

Response structure examples

  1. Return object with response structure from WS Sign Medication request Request.

  2. Calculate medication remaining quantity:

    1. Select all Medication Dispenses in status PROCESSED related to the Medication Request

    2. Sum medication_qty in the filtered Medication Dispenses as dispensed_qty

    3. Calculate medication_remaining_qty = medication_qty - dispensed_qty

  3. Return medication_remaining_qty in the response

See on API-specification

HTTP status codes

Response code

HTTP Status code

Message

Internal name

Description

Response code

HTTP Status code

Message

Internal name

Description

1

Базові

2

 

401

Validation fails

 

Помилка валідації

3

 

403

Invalid scope

 

Відсутній доступ

4

 

404

Not found

 

Не знайдено

5

Специфічні

6

 

422

422 EView

 

Помилка валідації

Post-processing processes

N/A

Technical modules where the method is used

 

Related content

REST API Get Medication Requests by Search Params [API-005-008-002-0146]
REST API Get Medication Requests by Search Params [API-005-008-002-0146]
More like this
REST API PRIVATE SPACE [AR] Private. Get Medication Request by Id [API-005-008-002-0160]
REST API PRIVATE SPACE [AR] Private. Get Medication Request by Id [API-005-008-002-0160]
More like this
[DRAFT] REST API Get Medication Administration by search params [API-007-004-006-0263]
[DRAFT] REST API Get Medication Administration by search params [API-007-004-006-0263]
More like this
[DRAFT] REST API Unblock Medication Request [API-005-008-002-0156]
[DRAFT] REST API Unblock Medication Request [API-005-008-002-0156]
Read with this
REST API Get medication request requests by search params [API-005-008-003-0163]
REST API Get medication request requests by search params [API-005-008-003-0163]
More like this

ЕСОЗ - публічна документація