Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Purpose

...

  1. Only authenticated and authorized users with appropriate scope can invoke Create Device Dispense

  2. Device Dispense is created in async way. Successful result of the job should return a link on the created Device Dispense (look at /wiki/spaces/CSI/pages/17467506869 ).

  3. Device Dispense can be created only under active Device Request within valid dispense period

  4. Several devices of different manufacturers with the same code can be dispensed at a time

  5. Multiple dispenses to the same Device Request is not allowed

  6. It is allowed to create Device Dispense for not active or not verified persons (for the same reasons as in the medication reimbursement process)

  7. Via this endpoint Device Dispense can be created only with primary_source = true, meaning that the the source of information about dispense is its performeperformer

Specification

Page Properties
idAPI_Specification

Link

https://ehealthmedicaleventsapi.docs.apiary.io/#reference/device-dispenses/create-device-dispense/create-device-dispense

Посилання на Apiary або Swagger

Resource

/api/patients/{{patient_id}}/device_dispenses

Посилання на ресурс, наприклад: /api/persons/create

Scope

device_dispense:write

Scope для доступу

Components

Devices

Зазначається перелік бізнес компонентів, які використовують цей метод, наприклад: ePrescription

Microservices

Перелік мікросервісів, які використовує метод API, наприклад: Auth, ABAC

Protocol type

REST

Тип протоколу, який використовується запитом, наприклад: SOAP | REST

Request type

POST

Тип запиту API, наприклад: GET, POST, PATCH…

Sync/Async

Async

Метод є синхронним чи асинхронним?

Public/Private/Internal

Public

Потрібно зазначити тип методу за ступенем доступності

Logic

  • Fill in the following fields:

    • status = IN_PROGRESS

    • status_reason = null

    • subject. Set hashed patient_id from URL

    • performer_legal_entity. Set client_id from token

    • quantity.unit. Set description according to quantity code and system

    • inserted_at. Set current date and time

    • updated_at. Set current date and time

    • inserted_by. Set current user from token

    • updated_by. Set current user from token

  • Save data to device_dispenses collection in MongoDB according to /wiki/spaces/CSI/pages/17467572335

  • Send StatusChangeEvent to Event Manager

...

  • Check device (device definition) to be dispensed ($.details.device)

    • Check code ($.details.device.identifier.type.coding.code) = device_definition

      • in case of error - return 422 ('value is not allowed in enum')

    • Get device definition by id ($.details.device.identifier.value)

      • device_definition.is_active = true

        • in case of error - return 422 ('Device definition not found')

    • Check that this device definition is compliant with prescribed device

      • If device request contains reference to a device definition in device_request.code_reference

        • Check that device_definition_id in dispense is equal to device_definition_id in the request

      • If device request contains device_request.code

        • Check that device_definition.classification_type is equal to prescribed device definition code in device request (device_request.code)

      • If device_request.code is of type Reference

        • Check that device_definition_id in dispense is equal to device_definition_id in request

      • in case of error - return 422 ('Dispensed device doesn’t match with prescribed device')

      • If device request contains reference to a device definition in device_request.code_reference, then check device_definition_id in dispense is equal to device_definition_id in the request

      • If device request contains device_request.code, then check device_definition has at least one classification type that is equal to prescribed device definition code in device request (device_request.code)

        • in case of error - return 422 ('Dispensed device doesn’t match with prescribed device')

    • Check that packaging_unit matches with quantity.code of the Device Request

      • in case of error - return 422 (Dispensed packaging unit doesn’t match with prescribed packaging unit)

    • Check the remainder of the division ($.details.quantity.value/device_definition.packaging_count) is equal to 0

      • in case of error - return reject_reason = “The quantity must be divisible to packaging_count of prescribed Device Definition”

...

  • Check device_code to be dispensed ($.details.device_code)

    • Check system($.details.device_code.coding.system) = device_definition_classification_type

      • in case of error - return 422 ('value is not allowed in enum')

    • Get device_code from the dictionary device_definition_classification_type ($.details.device_code.coding.code) and check parameter is_active = true

      • in case of error - return 422 ('Device code not found')

    • Check that code.coding[] array contains only 1 element

      • in case of error - return 422 ('expected a maximum of 1 items but got <actual>')

    • Check that code.coding[].code is an active value from the dictionary specified in code.coding[].system

      • in case of error - return 422 ('Value <code> not found in the dictionary <system>')

    • Check that this device code is compliant with prescribed device code:

      • Check device_request.code_reference is not present in the request

        • return an error 422 ('Dispense with device code is not allowed, since the prescription is for device or device definition ')

      • Check device_request.code is equal to device_dispense.device_code

        • in case of error - return 422 ('Dispensed device code doesn’t match with prescribed device code')

...

  • Validate quantity value

    • If Medical program is specified:

      • Check that dispensed device quantity is equal prescribed quantity in Device Request

        • sum($.details.quantity.value) == device_request.quantity

        • in case of error - return 422 ('Dispensed quantity must be equal to prescribed quantity in Device Request')

    • If Medical program is not specified:

      • Check that dispensed device quantity is equal or less then remaining_quantity in Device Request:

        • Select all Device dispenses in status completed related to the Device request

        • 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_quantity

        • Calculate remaining_quantity = requested_quantity- dispensed_quantity

          • in case of error - return 422 ('Dispensed quantity must be equal or less then prescribed remaining quantity in Device Request')

  • Validate quantity units

    • Check that quantity.code matches with packaging_unit of the device_request

      • in case of error - return 422 (Does not match the packaging unit of the prescribed device)

...

  • This validation must be done only if medical_program is specified in the request($.program)

    • Check that $.verification_code in request is equal to verification_code in device_request

      • In case code exists in request - it should match with code in device_request

        • in case of error - return 403 (message: “Incorrect code“)

Validate primary source

Validate value in the field $.primary_source, Boolean type, required.

  • Check the $.primary_source = true

    • in case of error - return 422 ('value is not allowed in enum')

Service logic

  • Fill in the following fields:

    • status = IN_PROGRESS if there are program specified in the dispense OR

    • status = COMPLETED if no program specified

    • status = IN_PROGRESS

    • status_reason = null

    • subject. Set hashed patient_id from URL

    • performer_legal_entity. Set client_id from token

    • details.quantity.unit. Set description according to quantity code and system

    • details.reimbursement_amount. Set calculated above allowed_reimbursement_amount from program_medication if program is present.

    • inserted_at. Set current date and time

    • updated_at. Set current date and time

    • inserted_by. Set current user from token

    • updated_by. Set current user from token

    • origin_episode_id. Set context_episode_id from device request referenced in based_on

  • If Device dispenses status is changed to completed and related Device request has a reference on an Activity as device_request.based_on, then

    • add the 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

  • If there are no Medical program specified in Device dispense AND there is quantity specified in Device request:

    1. calculate remaining quantity of the related Device request (same as on [UPD] Get Device request details | Service logic):

      1. Select all Device dispenses in status completed related to the Device request

      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.quantity, change status of the related Device request($.based_on) to completed

  • Save data to device_dispenses collection in MongoDB according to RC_[UPD] Device dispense data model https://e-health-ua.atlassian.net/wiki/spaces/EH/pages/18493341807

  • Send StatusChangeEvent to Event Manager

...