ЕСОЗ - публічна документація
RC_[NEW] [Trembita API] Create Device Dispense
- 1 Overview
- 1.1 Key points
- 2 Request
- 2.1 Headers
- 2.2 Body
- 2.3 device_detail
- 3 Validations
- 4 Service logic
- 5 Response
- 5.1 Response structure
- 5.2 Error codes
Overview
This API method is designed to create Device Dispense via Trembita.
Key points
This web service works asynchronously
This web service is designed for integration with Trembita
Request
URL: min_sp/device_dispenses
Method: POST
Headers
Header | Type | Required |
---|---|---|
Uxp-Client | string | True |
Uxp-Service | string | True |
Uxp-Transaction-Id | string | True |
Body
Element | Type | Description | M/O | |
---|---|---|---|---|
1 | id | uuid | Unique Device Dispense identifier | M |
2 | status | string | | M |
3 | note | string |
| O |
4 | primary_source | boolean | Always set in true | M |
5 | report_origin |
| O | |
6 | based_on | Reference to Device Request | M | |
7 | subject | Reference to Patient | M | |
8 | external_provider | object |
| O |
9 | external_provider.provider_legal_entity_name | string |
| M |
10 | external_provider.provider_legal_entity_edrpou | string |
| M |
11 | details |
| M | |
12 | sell_price | float |
| O |
13 | payment_amount | float |
| O |
14 | when_handed_over | date |
| O |
device_detail
Element | Type | Description | M/O | |
---|---|---|---|---|
1 | device_code | One of should be present: device_code or device_reference | O | |
2 | device_reference | Reference to Device Definition | O | |
3 | quantity |
| M |
Validations
Validate headers
Check that header
Uxp-Client
exists and is not emptyin case of error - generate response with code 400:
$Response.error.type = “bad_request“
$Response.error.code = “1008”
$Response.error.message = “Missed Uxp-Client header”
Check that header
Uxp-Service
exists and is not emptyin case of error - generate response with code 400:
$Response.error.type = “bad_request“
$Response.error.code = “1009”
$Response.error.message = “Missed Uxp-Service header”
Check that header
Uxp-Transaction-Id
exists and is not emptyin case of error - generate response with code 400:
$Response.error.type = “bad_request“
$Response.error.code = “1010”
$Response.error.message = “Missed Uxp-Transaction-Id header”
Check that header
Uxp-Client
contains 4 strings that are separated by/
symbolin case of error - generate response with code 400:
$Response.error.type = “bad_request“
$Response.error.code = “1011”
$Response.error.message = “Invalid Uxp-Client format”
Check that header
Uxp-Service
contains 4 or 5 strings that are separated by/
symbolin case of error - generate response with code 400:
$Response.error.type = “bad_request“
$Response.error.code = “1012”
$Response.error.message = “Invalid Uxp-Service format”
Validate JSON Schema
Validate request according to JSON Schema (validate status=
preperation
orcompleted
, primary_source =true, sell_price and payment_amount are greater than 0(if present))in case of errors generate response with code 422
$Response.error.type = “validation_failed“
$Response.error.code = “1013” “0000013”
$Response.error.message = Request structure error”
$Response.error.invalid = {{json_schema_errors}}
Validate request structure
Validate id
Check there is no Device Dispense with the same ID for this patient in the DB
in case Device Request not found update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1021” “0050021”
$Response.error.message = “Device Dispense with id <id> already exists”
Validate based_on
Search for Device Request where id=$.based_on, patient_id =$.subject, status=active
in case Device Request not found update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1019” “0050019”
$Response.error.message = “Device Request not found”
Check that device_request.intent is
order
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1022” “0050022”
$Response.error.message = “Only device request with intent = 'order' can be dispensed”
If device_code is present in the request check that device code in the Device Dispense is compliant with prescribed device code:
Check device_request.code_reference is not present in the Device Request
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1023” “0050023”
$Response.error.message = “Dispense with device code is not allowed, since prescription is for device or device definition”
Check device_request.code is equal to device_dispense.detail.device_code
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1024” “0050024”
$Response.error.message = “Dispensed device code doesn’t match with prescribed device code”
If device_reference is present in the request check that device reference in the Device Dispense is compliant with prescribed device reference:
Check device_request.code is not present in the Device Request
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1036” “0050036”
$Response.error.message = “Dispense with device reference is not allowed, since prescription is for device code”
Check device_request.code_reference is equal to device_dispense.detail.device_reference
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1037” “0050037”
$Response.error.message = “Dispensed device reference doesn’t match with prescribed device reference”
Check that Device Definition referenced in device_dispense.detail.device_reference is active
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1038” “0050038”
$Response.error.message = “Device Definition is not active”
Check that device_dispense.details.quantity.code matches with device_request.quantity.code(in case device_request.quantity not null)
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1025” “0050025”
$Response.error.message = “Dispensed packaging unit doesn’t match with prescribed packaging unit”
Check that dispensed device quantity is equal or less then remaining_quantity in the Device Request(in case device_request.quantity not null) :
Select all Device Dispenses with following parameters:
based_on is current Device Request
status = completed, preparation
Sum
quantity
in the filtered Device Dispenses as dispensed_quantityCalculate remaining_quantity = requested_quantity- dispensed_quantity
Check that remaining_quantity is greater or equal to device_dispense.details.quantity
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1026” “0050026”
$Response.error.message = “Dispensed quantity must be equal or less then prescribed remaining quantity in Device Request”
Validate Activity and Care Plan (if present in device_request.based_on):
Verify care plan Activity from $.based_on where coding.code=activity:
Check Activity status is
scheduled
orin_progress
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1027” “0050027”
$Response.error.message = “Invalid Activity status”
Verify Care Plan from $.based_on where coding.code=care_plan:
Check Care Plan status is
active
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1028” “0050028”
$Response.error.message = “Invalid Care Plan status”
Check care_plan.period.end(if exist) greater or equal to current date
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1029” “0050029”
$Response.error.message = “Care Plan expired”
Validate subject verification status
Search for Person's merged person
in case empty response returned or person is a master person check person verification status is not equal to
NOT_VERIFIED
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1030” “0050030”
$Response.error.message = “Person is not verified”
else, in case person is a merged person, validate master person verification status is not equal to
NOT_VERIFIED
in case of error update job with code 409:
$Response.error.type = “conflict“
$Response.error.code = “1030” “0050030”
$Response.error.message = “Person is not verified”
Validate external_provider
Check external_provider.provider_legal_entity_edrpou mathes with one of following regexp:
([0-9]{8,10}|[А-ЯЁЇIЄҐ]{2}\d{6})
([0-9]{9,10}|[А-ЯЁЇIЄҐ]{2}\d{6})in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1031” “0050031”
$Response.error.message = “Invalid provider_legal_entity_edrpou format”
In case $.status =
preparation
Check that when_handed_over, sell_price, payment_amount is NOT present
in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1032” “0050032”
$Response.error.message = “Parameters when_handed_over, sell_price, payment_amount are not allowed for Device Dispense in status
preparation
”
Check that details.device_code is present
in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1035” “0050035”
$Response.error.message = “Parameter device_code is required for Device Dispense in status
preparation
”
Check that primary_source is true
in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1040” “0050040”
$Response.error.message = “Parameter primary_source must be set in
true
for Device Dispense in statuspreparation
”
In case $.status =
completed
Check that when_handed_over is present
in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1033” “0050033”
$Response.error.message = “Parameters when_handed_over is required for Device Dispense in status
completed
”
check that when_handed_over is greater or equal to device_request.authored_on and less or equal to current date
in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1034” “0050034”
$Response.error.message = “Invalid dispense period”
In case $.primary_source= false check that $.report_origin is present
in case of error update job with code 422:
$Response.error.type = “validation_failed“
$Response.error.code = “1039” “0050039”
$Response.error.message = “Parameter report_origin is required when primary_source is false”
Service logic
Parse
Uxp-Client
header using pattern<client_instance>/<client_member_class>/<client_member_code>/<client_subsystem_code>
Parse
Uxp-Service
header using patter<service_instance>/<service_member_class>/<service_member_code>/<service_subsystem_code>/<service_service_code>[/<service_service_version>]
<service_service_version> - optional parameter
Save parsed headers (
Uxp-Client
,Uxp-Service
,Uxp-transaction-Id
), request body, response body, job_id to Trembita Integration LayerSave data to device_dispenses collection in MongoDB according to https://e-health-ua.atlassian.net/wiki/spaces/REHABILIT/pages/18430755049/UPD+Device+dispense+data+model
inserted_at = {{current_date_time}}
updated_at = {{current_date_time}}
inserted_by = {{trembita_user_id}}
updated_by = {{trembita_user_id}}
external_performer = {{client_member_code}}(from
Uxp-Client
header)origin_episode_id = device request.context_episode_id (from based_on)
details.quantity.unit. Set description according to quantity code and system
If Device Dispenses status is changed to
completed
and related Device Request has a reference on Activity as device_request.based_on, thenadd reference on the Device Dispense resource to the outcome_reference attribute of the related Activity
if Activity.status is
scheduled
change it toin_progress
If Device Dispenses status is changed to
completed
and there is quantity specified in the Device Request:calculate remaining_quantity of the related Device Request:
Select all Device Dispenses with following parameters:
based_on is current Device Request
status =
completed
Sum quantity in the filtered Device Dispenses as dispensed_qty
Calculate remaining_quantity = device_request.quantity- dispensed_quantity
If remaining_quantity is equal to device_dispense.details.quantity, change status of the related Device Request($.based_on) to
completed
Send
StatusChangeEvent
to Event ManagerUpdate job
Response
Response structure
Job
Element | Type | Description | M/O | |
---|---|---|---|---|
1 | status | string |
| M |
2 | eta | eta |
| O |
3 | links | [link] |
| O |
link
Element | Type | Description | M/O | |
---|---|---|---|---|
1 | entity | string |
| M |
2 | href | string |
| M |
Error codes
Code | Message |
---|---|
1001 | No active person found |
1008 | Missed Uxp-Client header / Invalid Uxp-Client format |
1009 | Missed Uxp-Service header / Invalid Uxp-Service format |
1010 | Missed Uxp-Transaction-Id header |
1011 | Invalid Uxp-Client format |
1012 | Invalid Uxp-Service format |
1013 | Request structure error |
0050019 | Device Request not found |
0050021 | Device Dispense with id <id> already exists |
0050022 | Only device request with intent = 'order' can be dispensed |
0050023 | Dispense with device code is not allowed, since the prescription is for device or device definition |
0050024 | Dispensed device code doesn’t match with prescribed device code |
0050025 | Dispensed packaging unit doesn’t match with prescribed packaging unit |
0050026 | Dispensed quantity must be equal or less then prescribed remaining quantity in Device Request |
0050027 | Invalid Activity status |
0050028 | Invalid Care Plan status |
0050029 | Care Plan expired |
0050030 | Person is not verified |
0050031 | Invalid provider_legal_entity_edrpou format |
0050032 | Parameters when_handed_over, sell_price, payment_amount are not allowed for Device Dispense in status |
0050033 | Required property when_handed_over was not present |
0050034 | Invalid dispense period |
5000 | Internal Server Error |
ЕСОЗ - публічна документація