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

RC_[NEW] [Trembita API] Update Device Dispense

Overview

This API method is designed to update Device Dispense's information when it becomes completed.

Request

URL: min_sp/device_dispenses/actions/update

Method: PATCH

Headers

Header

Type

Required

Header

Type

Required

Uxp-Client

string

True

Uxp-Service

string

True

Uxp-Transaction-Id

string

True

Body

 Element

Type

Description

M/O

 Element

Type

Description

M/O

1

id

uuid

Unique Device Dispense identifier

M

2

subject

{Reference}

Reference to Patient

M

3

status

string

Always set in cancelled

M

4

payment_amount

float

Must be greater than 0

O

5

when_handed_over

date

 

M

Validations

Validate headers

  1. Check that header Uxp-Client exists and is not empty

    1. in case of error - generate response with code 400:

      • $Response.error.type = “bad_request“

      • $Response.error.code = “1008”

      • $Response.error.message = “Missed Uxp-Client header”

  2. Check that header Uxp-Service exists and is not empty

    1. in case of error - generate response with code 400:

      • $Response.error.type = “bad_request“

      • $Response.error.code = “1009”

      • $Response.error.message = “Missed Uxp-Service header”

  3. Check that header Uxp-Transaction-Id exists and is not empty

    1. in 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”

  4. Check that header Uxp-Client contains 4 strings that are separated by / symbol

    1. in case of error - generate response with code 400:

      • $Response.error.type = “bad_request“

      • $Response.error.code = “1011”

      • $Response.error.message = “Invalid Uxp-Client format”

  5. Check that header Uxp-Service contains 4 or 5 strings that are separated by / symbol

    1. in 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

  1. Validate request according to JSON Schema (validate status= completed, sell_price and payment_amount are greater than 0)

    1. in case of errors generate response with code 422

      1. $Response.error.type = “validation_failed“

      2. $Response.error.code = “1013” “0000013”

      3. $Response.error.message = “Request structure error”

      4. $Response.error.invalid = {{json_schema_errors}}

Validate Device Dispense existence

  1. Check that Device Dispense with submitted id exists for submitted Patient

    1. in case of errors return code 422

      1. $Response.error.type = “validation_failed“

      2. $Response.error.code = “1014” “0060014”

      3. $Response.error.message = “Device Dispense not found”

Validate external performer

  1. Parse Uxp-Client header using pattern <client_instance>/<client_member_class>/<client_member_code>/<client_subsystem_code>

  2. Check that device_dispense.external_performer = {{client_member_code}}(from Uxp-Client header)

    1. in case of an error update job with code 409

      1. $Response.error.type = “conflict“

      2. $Response.error.code = “1015” “0060015”

      3. $Response.error.message = “Can not complete Device Dispense created by another legal entity”

Validate subject verification status

  1. Search for Person's merged person

    1. in case empty response returned or person is a master person check person verification status is not equal to NOT_VERIFIED

      1. in case of error update job with code 409:

        1. $Response.error.type = “conflict“

        2. $Response.error.code = “1030” “0060030”

        3. $Response.error.message = “Person is not verified” 

    2. else, in case person is a merged person, validate master person verification status is not equal to NOT_VERIFIED

      1. in case of error update job with code 409:

        1. $Response.error.type = “conflict“

        2. $Response.error.code = “1030” “0060030”

        3. $Response.error.message = “Person is not verified”

Validate transition

  1. Check that device_dispense.status = preparation

    1. in case of an error update job with code 422

      1. $Response.error.type = “validation_failed“

      2. $Response.error.code = “1016” “0060016”

      3. $Response.error.message = “Device Dispense in status <status> cannot be completed”

For more information look at https://e-health-ua.atlassian.net/wiki/spaces/REHABILIT/pages/18431246460/UPD+Device+dispense+status+model.

Validate request

  1. Check that when_handed_over is greater or equal to device_request.authored_on and less or equal to current date

    1. in case of error update job with code 422:

      1. $Response.error.type = “validation_failed“

      2. $Response.error.code = “1017” “0060017”

      3. $Response.error.message = “Invalid dispense period”

  2. Check that device_request.status is active

    1. in case of error update job with code 422:

      1. $Response.error.type = “validation_failed“

      2. $Response.error.code = “0060019”

      3. $Response.error.message = “Device Request is not active”

Service logic

  1. Parse Uxp-Client header using pattern <client_instance>/<client_member_class>/<client_member_code>/<client_subsystem_code>

  2. Parse Uxp-Service header using patter <service_instance>/<service_member_class>/<service_member_code>/<service_subsystem_code>/<service_service_code>[/<service_service_version>]

    1. <service_service_version> - optional parameter

  3. Save parsed headers (Uxp-Client, Uxp-Service, Uxp-transaction-Id), request body, response body, job_id to Trembita Integration Layer

  4. Update Device Dispense

    1. updated_at = {{current_date_time}}

    2. updated_by = {{trembita_user_id}}

    3. status = completed

    4. when_handed_over = request.when_handed_over

    5. payment_amount = request.payment_amount

    6. sell_price = request.sell_price

  5. If related Device Request has a reference on Activity as device_request.based_on, then

    • add reference on the Device Dispense resource to the outcome_reference attribute of the related Activity

    • if Activity.status is scheduled change it to in_progress

  6. If there is quantity specified in the Device Request:

    1. calculate remaining_quantity of the related Device Request:

      1. Select all Device Dispenses with following parameters:

        • based_on is current Device Request

        • status = completed

      2. Sum quantity in the filtered Device Dispenses as dispensed_qty

      3. Calculate remaining_quantity = device_request.quantity- dispensed_quantity

    2. If remaining_quantity is equal to device_dispense.details.quantity, change status of the related Device Request($.based_on) to completed

  7. Send StatusChangeEvent to Event Manager

  8. Update job

Response

Job

 Element

Type

Description

M/O

 Element

Type

Description

M/O

1

status

string

 

M

2

eta

eta

 

O

3

links

[link]

 

O

link

 Element

Type

Description

M/O

 Element

Type

Description

M/O

1

entity

string

 

M

2

href

string

 

M

Error codes

Code

Message

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

0060014

Device Dispense not found

0060015

Can not complete Device Dispense created by another legal entity

0060016

Device Dispense in status <status> cannot be completed

0060017

Invalid dispense period

0060018

Person is not verified

0060019

Device Request is not active

 

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