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

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Purpose

This method is designed to process previously created Medication dispense

Key points

  1. Only authenticated and authorized users of a legal entity who has created Medication dispense can process Medication dispense

  2. Medication dispense can be processed only from ‘NEW' status.

  3. The process should be signed with DS. So, all the Medication dispense data should be submitted.

  4. Invoke Get Medication dispense details by Pharmacy User to obtain previously created Medication dispense. In order to process dispense payment_id (optional) and payment_amount (optional, if medical program has funding sourse != NHS) should be added.

Specification

Link

https://uaehealthapi.docs.apiary.io/#reference/public.-reimbursement/medication-dispense/process-medication-dispense-by-pharmacy-user

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

Resource

/api/pharmacy/medication_dispenses/{{id}}/actions/process

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

Scope

medication_dispense:process

Scope для доступу

Components

ePrescription

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

Microservices

API paragraph not found

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

Protocol type

REST

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

Request type

PATCH

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

Sync/Async

Sync

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

Public/Private/Internal

Public

Logic

  1. Save signed content to media storage

  2. Update Medication dispense data in OPS DB:

    1. set status  =  ‘PROCESSED’

    2. updated_by = user_id

    3. updated_at = now()

  3. Update related Medication request data in OPS DB:

    1. set status  =  ‘COMPLETED’

    2. updated_by = user_id

    3. updated_at = now()

  4. Write changes to event manager (Medication dispense and Medication request)

  5. Change Care plan activity (If related medication request has reference on Care plan, then corresponding care plan activity should be changed in async way after Medication dispense processed. Update activity events invokes using ops.medication_dispense_process table):

    1. Set activity status to in_progress if previous activity status was scheduled 

    2. Check the MD identifier in outcome_reference attribute of the activity:

      1. if not found:

        1. Add reference on the medication dispense resource to the outcome_reference attribute .

        2. If quantity in the activity was set then calculate and set remaining quantity:

          1. select all MD in status PROCESSED related to MR which based on care plan and current activity

          2. calculate dispensed quantity in the current activity as sum of medication_qty in the filtered MD list

          3. calculate remaining quantity by subtracting dispensed quantity from activity quantity

          4. update remaining_quantity value in the activity with calculated value

      2. If found, then skip updating activity (it means that activity has been already updated by event from current MD processing).

Preconditions

If skip_medication_dispense_sign=false, MD should be created

Input parameters

Input parameter

Values

Type

Description

Example

id

String

Medication Dispense Response Identifier. Required.

a89f6a26-4221-4597-a1d2-542d5e40b565

Request structure

Example:

 Request example
{
  "signed_medication_dispense": "ewogICAgImlkIjogImIwNzVmMTQ4LTdmOTMtNGZjMi1iMmVjLTJkODFiMTlhOWI3YiIsCiAgICAibWVkaWNhdGlvbl9yZXF1ZXN0IjogewogICAgICAiaWQiOiAiYjA3NWYxNDgtN2Y5My00ZmMyLWIyZWMtMmQ4MWIxOWE5YjdiIiwKICAgICAgInN0YXR1cyI6ICJBQ1RJVkUiLAogICAgICAicmVxdWVzdF9udW1iZXIiOiAiMDAwMC0yNDNQLTFYNTMtRUgzOCIsCiAgICAgICJjcmVhdGVkX2F0IjogIjIwMTctMDgtMTciLAogICAgICAic3RhcnRlZF9hdCI6ICIyMDE3LTA4LTE3IiwKICAgICAgImVuZGVkX2F0IjogIjIwMTctMDktMTYiLAogICAgICAiZGlzcGVuc2VfdmFsaWRfZnJvbSI6ICIyMDE3LTA4LTE3IiwKICAgICAgImRpc3BlbnNlX3ZhbGlkX3RvIjogIjIwMTctMDktMTYiLAogICAgICAicGVyc29uIjogewogICAgICAgICJzaG9ydF9uYW1lIjogItCf0LXRgtGA0L4g0IYuINCGLiIsCiAgICAgICAgImFnZSI6IDM1CiAgICAgIH0sCiAgICAgICJtZWRpY2F0aW9uX2luZm8iOiB7CiAgICAgICAgIm1lZGljYXRpb25faWQiOiAiNGE2M2I4NTgtYzEzOC00OTIxLTkzNDEtYWU5ZTM4NGJjYmQ2IiwKICAgICAgICAibWVkaWNhdGlvbl9uYW1lIjogItCQ0LzRltC+0LTQsNGA0L7QvSAyMDDQvNCzINGC0LDQsdC70LXRgtC60LgiLAogICAgICAgICJmb3JtIjogIlBJTEwiLAogICAgICAgICJkb3NhZ2UiOiB7CiAgICAgICAgICAibnVtZXJhdG9yX3VuaXQiOiAiTUciLAogICAgICAgICAgIm51bWVyYXRvcl92YWx1ZSI6IDIwMCwKICAgICAgICAgICJkZW51bWVyYXRvcl91bml0IjogIlBJTEwiLAogICAgICAgICAgImRlbnVtZXJhdG9yX3ZhbHVlIjogMQogICAgICAgIH0sCiAgICAgICAgImluZ3JlZGllbnRzIjogWwogICAgICAgICAgewogICAgICAgICAgICAiaWQiOiAiMTM0OWE2OTMtNGRiMS00YTNmLTlhYzYtOGMyZjllNTQxOTgyIiwKICAgICAgICAgICAgIm5hbWUiOiAi0IbQvdGB0YPQu9GW0L0g0LTQtdCz0LvRjtC00LXQuiIsCiAgICAgICAgICAgICJuYW1lX29yaWdpbmFsIjogIkluc3VsaW4gZGVnbHVkZWMiLAogICAgICAgICAgICAic2N0aWQiOiAiNTI1NzQwMDMiLAogICAgICAgICAgICAiZG9zYWdlIjogewogICAgICAgICAgICAgICJudW1lcmF0b3JfdW5pdCI6ICJNRyIsCiAgICAgICAgICAgICAgIm51bWVyYXRvcl92YWx1ZSI6IDIwMCwKICAgICAgICAgICAgICAiZGVudW1lcmF0b3JfdW5pdCI6ICJQSUxMIiwKICAgICAgICAgICAgICAiZGVudW1lcmF0b3JfdmFsdWUiOiAxCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgICJpc19wcmltYXJ5IjogdHJ1ZQogICAgICAgICAgfQogICAgICAgIF0sCiAgICAgICAgIm1lZGljYXRpb25fcXR5IjogMTAsCiAgICAgICAgImV4dGVuc2lvbiI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgInVybCI6ICJkb3NhZ2UtY29udGFpbmVyLW51bWVyYXRvciIsCiAgICAgICAgICAgICJ2YWx1ZVF1YW50aXR5IjogewogICAgICAgICAgICAgICJzeXN0ZW0iOiAibWVkaWNhdGlvbl91bml0IiwKICAgICAgICAgICAgICAiY29kZSI6ICJNTCIsCiAgICAgICAgICAgICAgInZhbHVlIjogNAogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgXQogICAgICB9LAogICAgICAibWVkaWNhbF9wcm9ncmFtIjogewogICAgICAgICJpZCI6ICJjN2Q1MjU0NC0wYmQ0LTQxMjktOTdiMC0yZDcyNjMzZTA0OTAiLAogICAgICAgICJuYW1lIjogItCU0L7RgdGC0YPQv9C90ZYg0LvRltC60LgiLAogICAgICAgICJtZWRpY2FsX3Byb2dyYW1fc2V0dGluZ3MiOiB7CiAgICAgICAgICAiY2FyZV9wbGFuX3JlcXVpcmVkIjogdHJ1ZSwKICAgICAgICAgICJlbXBsb3llZV90eXBlc190b19jcmVhdGVfbWVkaWNhdGlvbl9yZXF1ZXN0IjogWwogICAgICAgICAgICAiU1BFQ0lBTElTVCIsCiAgICAgICAgICAgICJET0NUT1IiCiAgICAgICAgICBdLAogICAgICAgICAgInNraXBfbW5uX2luX3RyZWF0bWVudF9wZXJpb2QiOiB0cnVlLAogICAgICAgICAgInNraXBfZW1wbG95ZWVfdmFsaWRhdGlvbiI6IHRydWUsCiAgICAgICAgICAic3BlY2lhbGl0eV90eXBlc19hbGxvd2VkIjogWwogICAgICAgICAgICAiRU5ET0NSSU5PTE9HWSIsCiAgICAgICAgICAgICJQRURJQVRSSUNfTkVVUk9MT0dZIgogICAgICAgICAgXSwKICAgICAgICAgICJjb25kaXRpb25zX2ljZDEwX2FtX2FsbG93ZWQiOiBbCiAgICAgICAgICAgICJBMDAuMCIsCiAgICAgICAgICAgICJBMDAuMSIKICAgICAgICAgIF0sCiAgICAgICAgICAiY29uZGl0aW9uc19pY3BjMl9hbGxvd2VkIjogWwogICAgICAgICAgICAiQTAxIiwKICAgICAgICAgICAgIkEwMiIKICAgICAgICAgIF0sCiAgICAgICAgICAicHJvdmlkaW5nX2NvbmRpdGlvbnNfYWxsb3dlZCI6IFsKICAgICAgICAgICAgIklOUEFUSUVOVCIsCiA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AiTkhTIiwKICAgICAgICAiaW5zZXJ0ZWRfYXQiOiAiMjAxNy0wNC0yMFQxOToxNDoxM1oiLAogICAgICAgICJpbnNlcnRlZF9ieSI6ICJlMTQ1M2Y0Yy0xMDc3LTRlODUtOGM5OC1jMTNmZmNhMDA2M2UiLAogICAgICAgICJ1cGRhdGVkX2F0IjogIjIwMTctMDQtMjBUMTk6MTQ6MTNaIiwKICAgICAgICAidXBkYXRlZF9ieSI6ICIyOTIyYTI0MC02M2RiLTQwNGUtYjczMC0wOTIyMmJmZWIyZGQiCiAgICAgIH0sCiAgICAgICJpbnRlbnQiOiAicGxhbiIsCiAgICAgICJjYXRlZ29yeSI6ICJjb21tdW5pdHkiLAogICAgICAiYmFzZWRfb24iOiBbCiAgICAgICAgewogICAgICAgICAgImlkZW50aWZpZXIiOiB7CiAgICAgICAgICAgICJ0eXBlIjogewogICAgICAgICAgICAgICJjb2RpbmciOiBbCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC9yZXNvdXJjZXMiLAogICAgICAgICAgICAgICAgICAiY29kZSI6ICJjYXJlX3BsYW4iCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgXQogICAgICAgICAgICB9LAogICAgICAgICAgICAidmFsdWUiOiAiOTE4M2EzNmItNGQ0NS00MjQ0LTkzMzktNjNkODFjZDA4ZDljIgogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgewogICAgICAgICAgImlkZW50aWZpZXIiOiB7CiAgICAgICAgICAgICJ0eXBlIjogewogICAgICAgICAgICAgICJjb2RpbmciOiBbCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC9yZXNvdXJjZXMiLAogICAgICAgICAgICAgICAgICAiY29kZSI6ICJhY3Rpdml0eSIKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBdCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgICJ2YWx1ZSI6ICI5MTgzYTM2Yi00ZDQ1LTQyNDQtOTMzOS02M2Q4MWNkMDhkOWMiCiAgICAgICAgICB9CiAgICAgICAgfQogICAgICBdLAogICAgICAiY29udGV4dCI6IHsKICAgICAgICAiaWRlbnRpZmllciI6IHsKICAgICAgICAgICJ0eXBlIjogewogICAgICAgICAgICAiY29kaW5nIjogWwogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC9yZXNvdXJjZXMiLAogICAgICAgICAgICAgICAgImNvZGUiOiAiZW5jb3VudGVyIgogICAgICAgICAgICAgIH0KICAgICAgICAgICAgXQogICAgICAgICAgfSwKICAgICAgICAgICJ2YWx1ZSI6ICI5MTgzYTM2Yi00ZDQ1LTQyNDQtOTMzOS02M2Q4MWNkMDhkOWMiCiAgICAgICAgfQogICAgICB9LAogICAgICAiZG9zYWdlX2luc3RydWN0aW9uIjogWwogICAgICAgIHsKICAgICAgICAgICJzZXF1ZW5jZSI6IDEsCiAgICAgICAgICAidGV4dCI6ICIwLjI1bWcgUE8gZXZlcnkgNi0xMiBob3VycyBhcyBuZWVkZWQgZm9yIG1lbnNlcyBmcm9tIEphbiAxNS0yMCwgMjAxNS4gIERvIG5vdCBleGNlZWQgbW9yZSB0aGFuIDRtZyBwZXIgZGF5IiwKICAgICAgICAgICJhZGRpdGlvbmFsX2luc3RydWN0aW9uIjogWwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgImNvZGluZyI6IFsKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgInN5c3RlbSI6ICJlSGVhbHRoL1NOT01FRC9hZGRpdGlvbmFsX2Rvc2FnZV9pbnN0cnVjdGlvbnMiLAogICAgICAgICAgICAgICAgICAiY29kZSI6ICIzMTE1MDQwMDAiCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgXQogICAgICAgICAgICB9CiAgICAgICAgICBdLAogICAgICAgICAgInBhdGllbnRfaW5zdHJ1Y3Rpb24iOiAiMC4yNW1nIFBPIGV2ZXJ5IDYtMTIgaG91cnMgYXMgbmVlZGVkIGZvciBtZW5zZXMgZnJvbSBKYW4gMTUtMjAsIDIwMTUuICBEbyBub3QgZXhjZWVkIG1vcmUgdGhhbiA0bWcgcGVyIGRheSIsCiAgICAgICAgICAidGltaW5nIjogewogICAgICAgICAgICAiZXZlbnQiOiBbCiAgICAgICAgICAgICAgIjIwMTctMDQtMjBUMTk6MTQ6MTNaIgogICAgICAgICAgICBdLAogICAgICAgICAgICAicmVwZWF0IjogewogICAgICAgICAgICAgICJib3VuZHNfZHVyYXRpb24iOiB7CiAgICAgICAgICAgICAgICAidmFsdWUiOiAxMCwKICAgICAgICAgICAgICAgICJ1bml0IjogImRheXMiLAogICAgICAgICAgICAgICAgInN5c3RlbSI6ICJlSGVhbHRoL3VjdW0vdW5pdHMiLAogICAgICAgICAgICAgICAgImNvZGUiOiAiZCIKICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICJjb3VudCI6IDIsCiAgICAgICAgICAgICAgImNvdW50X21heCI6IDQsCiAgICAgICAgICAgICAgImR1cmF0aW9uIjogNCwKICAgICAgICAgICAgICAiZHVyYXRpb25fbWF4IjogNiwKICAgICAgICAgICAgICAiZHVyYXRpb25fdW5pdCI6ICJkIiwKICAgICAgICAgICAgICAiZnJlcXVlbmN5IjogMSwKICAgICAgICAgICAgICAiZnJlcXVlbmN5X21heCI6IDIsCiAgICAgICAgICAgICAgInBlcmlvZCI6IDQsCiAgICAgICAgICAgICAgInBlcmlvZF9tYXgiOiA2LAogICAgICAgICAgICAgICJwZXJpb2RfdW5pdCI6ICJkIiwKICAgICAgICAgICAgICAiZGF5X29mX3dlZWsiOiBbCiAgICAgICAgICAgICAgICAibW9uIgogICAgICAgICAgICAgIF0sCiAgICAgICAgICAgICAgInRpbWVfb2ZfZGF5IjogWwogICAgICAgICAgICAgICAgIjIwMTctMDQtMjBUMTk6MTQ6MTNaIgogICAgICAgICAgICAgIF0sCiAgICAgICAgICAgICAgIndoZW4iOiBbCiAgICAgICAgICAgICAgICAiV0FLRSIKICAgICAgICAgICAgICBdLAogICAgICAgICAgICAgICJvZmZzZXQiOiA0CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgICJjb2RlIjogewogICAgICAgICAgICAgICJjb2RpbmciOiBbCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiVElNSU5HX0FCQlJFVklBVElPTlMiLAogICAgICAgICAgICAgICAgICAiY29kZSI6ICJwYXRpZW50IgogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIF0KICAgICAgICAgICAgfQogICAgICAgICAgfSwKICAgICAgICAgICJhc19uZWVkZWRfYm9vbGVhbiI6IHRydWUsCiAgICAgICAgICAic2l0ZSI6IHsKICAgICAgICAgICAgImNvZGluZyI6IFsKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAic3lzdGVtIjogImVIZWFsdGgvU05PTUVEL2FuYXRvbWljYWxfc3RydWN0dXJlX2FkbWluaXN0cmF0aW9uX3NpdGVfY29kZXMiLAogICAgICAgICAgICAgICAgImNvZGUiOiAiMzQ0MDAxIgogICAgICAgICAgICAgIH0KICAgICAgICAgICAgXQogICAgICAgICAgfSwKICAgICAgICAgICJyb3V0ZSI6IHsKICAgICAgICAgICAgImNvZGluZyI6IFsKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAic3lzdGVtIjogImVIZWFsdGgvU05PTUVEL3JvdXRlX2NvZGVzIiwKICAgICAgICAgICAgICAgICJjb2RlIjogIjQ2NzEzMDA2IgogICAgICAgICAgICAgIH0KICAgICAgICAgICAgXQogICAgICAgICAgfSwKICAgICAgICAgICJtZXRob2QiOiB7CiAgICAgICAgICAgICJjb2RpbmciOiBbCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgInN5c3RlbSI6ICJlSGVhbHRoL1NOT01FRC9hZG1pbmlzdHJhdGlvbl9tZXRob2RzIiwKICAgICAgICAgICAgICAgICJjb2RlIjogIjQxOTc0NzAwMCIKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIF0KICAgICAgICAgIH0sCiAgICAgICAgICAiZG9zZV9hbmRfcmF0ZSI6IHsKICAgICAgICAgICAgInR5cGUiOiB7CiAgICAgICAgICAgICAgImNvZGluZyI6IFsKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgInN5c3RlbSI6ICJlSGVhbHRoL2Rvc2VfYW5kX3JhdGUiLAogICAgICAgICAgICAgICAgICAiY29kZSI6ICInb3JkZXJlZCciCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgXQogICAgICAgICAgICB9LAogICAgICAgICAgICAiZG9zZV9yYW5nZSI6IHsKICAgICAgICAgICAgICAibG93IjogewogICAgICAgICAgICAgICAgInZhbHVlIjogMCwKICAgICAgICAgICAgICAgICJ1bml0IjogIm1nIiwKICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC91Y3VtL3VuaXRzIiwKICAgICAgICAgICAgICAgICJjb2RlIjogIm1nIgogICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgImhpZ2giOiB7CiAgICAgICAgICAgICAgICAidmFsdWUiOiAwLAogICAgICAgICAgICAgICAgInVuaXQiOiAibWciLAogICAgICAgICAgICAgICAgInN5c3RlbSI6ICJlSGVhbHRoL3VjdW0vdW5pdHMiLAogICAgICAgICAgICAgICAgImNvZGUiOiAibWciCiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LAogICAgICAgICAgICAicmF0ZV9yYXRpbyI6IHsKICAgICAgICAgICAgICAibnVtZXJhdG9yIjogewogICAgICAgICAgICAgICAgInZhbHVlIjogMCwKICAgICAgICAgICAgICAgICJ1bml0IjogIm1nIiwKICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC91Y3VtL3VuaXRzIiwKICAgICAgICAgICAgICAgICJjb2RlIjogIm1nIgogICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgImRlbm9taW5hdG9yIjogewogICAgICAgICAgICAgICAgInZhbHVlIjogMCwKICAgICAgICAgICAgICAgICJ1bml0IjogIm1nIiwKICAgICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC91Y3VtL3VuaXRzIiwKICAgICAgICAgICAgICAgICJjb2RlIjogIm1nIgogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfSwKICAgICAgICAgICJtYXhfZG9zZV9wZXJfcGVyaW9kIjogewogICAgICAgICAgICAibnVtZXJhdG9yIjogewogICAgICAgICAgICAgICJ2YWx1ZSI6IDAsCiAgICAgICAgICAgICAgInVuaXQiOiAibWciLAogICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC91Y3VtL3VuaXRzIiwKICAgICAgICAgICAgICAiY29kZSI6ICJtZyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgImRlbm9taW5hdG9yIjogewogICAgICAgICAgICAgICJ2YWx1ZSI6IDAsCiAgICAgICAgICAgICAgInVuaXQiOiAibWciLAogICAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC91Y3VtL3VuaXRzIiwKICAgICAgICAgICAgICAiY29kZSI6ICJtZyIKICAgICAgICAgICAgfQogICAgICAgICAgfSwKICAgICAgICAgICJtYXhfZG9zZV9wZXJfYWRtaW5pc3RyYXRpb24iOiB7CiAgICAgICAgICAgICJ2YWx1ZSI6IDAsCiAgICAgICAgICAgICJ1bml0IjogIm1nIiwKICAgICAgICAgICAgInN5c3RlbSI6ICJlSGVhbHRoL3VjdW0vdW5pdHMiLAogICAgICAgICAgICAiY29kZSI6ICJtZyIKICAgICAgICAgIH0sCiAgICAgICAgICAibWF4X2Rvc2VfcGVyX2xpZmV0aW1lIjogewogICAgICAgICAgICAidmFsdWUiOiAwLAogICAgICAgICAgICAidW5pdCI6ICJtZyIsCiAgICAgICAgICAgICJzeXN0ZW0iOiAiZUhlYWx0aC91Y3VtL3VuaXRzIiwKICAgICAgICAgICAgImNvZGUiOiAibWciCiAgICAgICAgICB9CiAgICAgICAgfQogICAgICBdLAogICAgICAicmVqZWN0X3JlYXNvbl9jb2RlIjogbnVsbCwKICAgICAgImlzX2Jsb2NrZWQiOiBmYWxzZSwKICAgICAgImJsb2NrX3JlYXNvbiI6ICLQn9GW0LTQvtC30YDQsCDQvdCwINGE0YDQvtC0IiwKICAgICAgImJsb2NrX3JlYXNvbl9jb2RlIjogIldST05HX1FUWV9EUlVHIgogICAgfSwKICAgICJkaXNwZW5zZWRfYXQiOiAiMjAxNy0wOC0xNyIsCiAgICAiZGlzcGVuc2VkX2J5IjogItCG0LLQsNC90L7QsiDQhtCy0LDQvSDQhtCy0LDQvdC+0LLQuNGHIiwKICAgICJwYXJ0eSI6IHsKICAgICAgImlkIjogImIwNzVmMTQ4LTdmOTMtNGZjMi1iMmVjLTJkODFiMTlhOWI3YiIsCiAgICAgICJmaXJzdF9uYW1lIjogItCf0LXRgtGA0L4iLAogICAgICAibGFzdF9uYW1lIjogItCG0LLQsNC90L7QsiIsCiAgICAgICJzZWNvbmRfbmFtZSI6ICLQnNC40LrQvtC70LDQudC+0LLQuNGHIgogICAgfSwKICAgICJsZWdhbF9lbnRpdHkiOiB7CiAgICAgICJpZCI6ICJiMDc1ZjE0OC03ZjkzLTRmYzItYjJlYy0yZDgxYjE5YTliN2IiLAogICAgICAibmFtZSI6ICLQmtC70ZbQvdGW0LrQsCDQndC+0YPQvdC10LnQvCIsCiAgICAgICJzaG9ydF9uYW1lIjogItCd0L7Rg9C90LXQudC8IiwKICAgICAgInB1YmxpY19uYW1lIjogItCa0LvRltC90ZbQutCwINCd0L7Rg9C90LXQudC8IiwKICAgICAgInR5cGUiOiAiTVNQIiwKICAgICAgImVkcnBvdSI6ICI1NDMyMzQ1NDMyIiwKICAgICAgInN0YXR1cyI6ICJBQ1RJVkUiCiAgICB9LAogICAgImRpdmlzaW9uIjogewogICAgICAiaWQiOiAiZDI5MGYxZWUtNmM1NC00YjAxLTkwZT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gICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICAicHJvZ3JhbV9tZWRpY2F0aW9uX2lkIjogIjY0YzA2ZWJjLTAyNjYtNDY0NS04NWYwLTdhNjkwMGQ3ZGZiZSIsCiAgICAgICAgIm1lZGljYXRpb25fcXR5IjogMTAsCiAgICAgICAgInNlbGxfcHJpY2UiOiAxOC42NSwKICAgICAgICAic2VsbF9hbW91bnQiOiAxODYuNSwKICAgICAgICAiZGlzY291bnRfYW1vdW50IjogMTUwLAogICAgICAgICJyZWltYnVyc2VtZW50X2Ftb3VudCI6IDQ1MCwKICAgICAgICAibWVkaWNhdGlvbl8yZF9jb2RlcyI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgIm1lZGljYXRpb25fMmRfY29kZSI6ICIwMTA0ODIwMDA1MTYxNzEzMTcxODEyMDAxMDIyNDMxMTE1IDIxMVhWODJIUFYiCiAgICAgICAgICB9CiAgICAgICAgXQogICAgICB9CiAgICBdLAogICAgInBheW1lbnRfaWQiOiAiMTIzOTgwNCIsCiAgICAicGF5bWVudF9hbW91bnQiOiA1MCwKICAgICJzdGF0dXMiOiAiTkVXIiwKICAgICJpbnNlcnRlZF9hdCI6ICIyMDE3LTA0LTIwVDE5OjE0OjEzWiIsCiAgICAiaW5zZXJ0ZWRfYnkiOiAiZTE0NTNmNGMtMTA3Ny00ZTg1LThjOTgtYzEzZmZjYTAwNjNlIiwKICAgICJ1cGRhdGVkX2F0IjogIjIwMTctMDQtMjBUMTk6MTQ6MTNaIiwKICAgICJ1cGRhdGVkX2J5IjogIjI5MjJhMjQwLTYzZGItNDA0ZS1iNzMwLTA5MjIyYmZlYjJkZCIKICB9",
  "signed_content_encoding": "base64"
}

Authorize

  1. Verify the validity of access token

    • in case of error - return 401 (“Invalid access token”) in case of validation fails

  2. Verify that token is not expired

    • in case of error - return 401 (“Invalid access token”)

  3. Check user scopes in order to perform this action (scope = 'medication_dispense:process')

    • return 403 (“Your scope does not allow to access this resource. Missing allowances: medication_dispense:process”) in case of invalid scope(s)

Headers

Content-Type:application/json

Authorization:Bearer c2778f3064753ea70de870a53795f5c9

Request data validation

Validate digital signature

  • Validate request is signed

    • in case of error - return 400 (“document must be signed by 1 signer but contains 0 signatures”)

  • Validate that DS is valid and not expired

  • Validate that DS belongs to the user

    • Check that DRFO from DS and party.tax_id matches

      • in case of error - return 422 (“Does not match the signer drfo“)

    • Check that Last Name from DS and party.last_name matches

      • in case of error - return 422 (“Does not match the signer last name“).

Validate Medication dispense

  • Get Medication dispense identifier from the URL

    • Check Medication dispense exists in DB (OPS)

      • Return 404 ('not_found') in case of error

    • Check Medication dispense belongs to legal entity

      • Return 404 ('not_found') in case of error

Validate User

  • Extract user_id from token

    • Return 404 ('not_found') in case employee didn’t create medication dispense

Validate Care plan and Activity

It is needed to check if medication request with a program allowed to be created for specified care plan and activity.

If based_on submitted, check field has array with two values of Reference type: one is valid Care plan resource, another - Activity resource.

  1. Verify Care plan:

    1. It should belong to the same person as set in MRR

      1. in case of error return 422 with msg ("Care plan not found")

    2. It should be in active status

  2. Verify submitted Activity:

    1. It belongs to the Care plan.

      1. in case of error return 422 with msg ("Activity not found")

    2. It has activity.detail.kind=medication_request; activity.detail.product_reference=medication_id.

      1. in case of error return 422 with msg ("Invalid activity kind")

    3. It has scheduled, in_progress status

      1. in case of error return 422 with msg ("Invalid activity status")

    4. If it has quantity then calculate remaining quantity:

      1. select all MRR in status NEW which based on current activity

      2. select all MR in statuses ACTIVE, COMPLETED based on current activity

      3. calculate reserved at the moment medication quantity as sum of medication_qty in the filtered MRR  and MR list, including medication_qty from current MRR

      4. calculate remaining quantity by subtracting reserved quantity from activity quantity

      5. Check remaining quantity is greater then or equal to zero

        1. in case of error return 409 "The total amount of the prescribed medication quantity exceeds quantity in care plan activity"

    5. check that medical_program_id equal to $.activity[].program

      1. in case of error return 422 with msg ("Medical program from activity should be equal to medical program from request")

  3. Validate started_at/ended_at of Medication request Request: 

    1. if care plan activity has detail.scheduled_timing.repeat.bounds_period - validate started_at/ended_at within bounds_period

    2. if care plan activity has detail.scheduled_period - validate started_at/ended_at within scheduled_period

    3. else - validate started_at/ended_at within care_plan.period

      1. in the case of started_at/ended_at is not within care_plan.period return 422 with msg  ("Invalid care plan period")

Validate signed content

  1. Check that signed content is equal to online generated dispense with ids in DB

    1. Do not compare:

      • payment_amount field

      • payment_id field

      • medication_request/legal_entity object

      • medication_request/division object

      • medication_request/employee object

      • medication_request/person/id field

      • medication_request/rejected_at field

      • medication_request/rejected_by field

        • in case error return 422 ("Signed content does not match to previously created dispense")

Validate transition

  • Get status of Medication dispense by $.id in OPS DB. Check that Medication dispense is in status ‘NEW’

    • in case of error - return 409 ("Can't update medication dispense status from {status} to PROCESSED")

For more information look at Medication dispense status model

Validate payment_amount

  1. In case if medical program has funding sourse == NHS check that payment_amount is submitted and greater or equal to 0

    1. in case of error - return 422 ("expected the value to be >= 0")

Validate related Medication request

  1. Medication request should be active in order to process medication dispense

    1. is_active = true

    2. status = 'ACTIVE'

      1. In case error - return 409 ("Medication request is not active")

  2. Medication request should not be blocked in order to process medication dispense

    1. is_blocked <> true

      1. In case error - return 409 ("Medication request is blocked")

  3. Medication request should be active in order to process medication dispense

    1. is_active = true

    2. status = 'ACTIVE'

      1. In case of error - return 409 ("Medication request is not active")

  4. Medication request should be up to date

    1. medication_request.dispense_valid_from ≤ now OR medication_request.dispense_valid_to ≥ now

      1. In case of error - return 409 ("Invalid dispense period")

  5. Checking the status of the legal entity where the medication request was issued

    1. status in ('ACTIVE', 'CLOSED', 'REORGANIZED')

      1. In case of error - return 422 ("value is not allowed in enum")

Check if related medication request has reference on the Care plan - based_on attribute filled. If it has, validate following:

  1. Care plan is not in final status.

    1. In case of error - return 409 error (Care plan is not active)

  2. If end_date Care plan is present then it should be less than or equal than todays date

    1. In case of error - return 409 ("Care plan expired")

  3. Corresponding Care plan activity is not in final status.

    1. In case of error - return 409 error (Care plan activity should be scheduled or in_progress)

Response structure

Example:

 Response example
"meta": {
    "code": 200,
    "url": "https://example.com/resource",
    "type": "object",
    "request_id": "6617aeec-15e2-4d6f-b9bd-53559c358f97#17810"
  },
  "data": {
    "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
    "medication_request": {
      "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
      "status": "ACTIVE",
      "request_number": "0000-243P-1X53-EH38",
      "created_at": "2017-08-17",
      "started_at": "2017-08-17",
      "ended_at": "2017-09-16",
      "dispense_valid_from": "2017-08-17",
      "dispense_valid_to": "2017-09-16",
      "person": {
        "short_name": "Петро І. І.",
        "age": 35
      },
      "medication_info": {
        "medication_id": "4a63b858-c138-4921-9341-ae9e384bcbd6",
        "medication_name": "Аміодарон 200мг таблетки",
        "form": "PILL",
        "dosage": {
          "numerator_unit": "MG",
          "numerator_value": 200,
          "denumerator_unit": "PILL",
          "denumerator_value": 1
        },
        "ingredients": [
          {
            "id": "1349a693-4db1-4a3f-9ac6-8c2f9e541982",
            "name": "Інсулін деглюдек",
            "name_original": "Insulin degludec",
            "sctid": "52574003",
            "dosage": {
              "numerator_unit": "MG",
              "numerator_value": 200,
              "denumerator_unit": "PILL",
              "denumerator_value": 1
            },
            "is_primary": true
          }
        ],
        "medication_qty": 10.34
      },
      "medical_program": {
        "id": "c7d52544-0bd4-4129-97b0-2d72633e0490",
        "name": "Доступні ліки",
        "is_active": true,
        "medication_dispense_allowed": true,
        "medication_dispense_allowed_text": "Some text",
        "medication_request_allowed": true,
        "medication_request_allowed_text": "Some text",
        "type": "MEDICATION",
        "funding_source": "NHS",
        "mr_blank_type": "F-1",
        "inserted_at": "2017-04-20T19:14:13Z",
        "inserted_by": "e1453f4c-1077-4e85-8c98-c13ffca0063e",
        "updated_at": "2017-04-20T19:14:13Z",
        "updated_by": "2922a240-63db-404e-b730-09222bfeb2dd"
      },
      "intent": "plan",
      "category": "community",
      "based_on": [
        {
          "identifier": {
            "type": {
              "coding": [
                {
                  "system": "eHealth/resources",
                  "code": "care_plan"
                }
              ]
            },
            "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
          }
        },
        {
          "identifier": {
            "type": {
              "coding": [
                {
                  "system": "eHealth/resources",
                  "code": "activity"
                }
              ]
            },
            "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
          }
        }
      ],
      "context": {
        "identifier": {
          "type": {
            "coding": [
              {
                "system": "eHealth/resources",
                "code": "encounter"
              }
            ]
          },
          "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
        }
      },
      "dosage_instruction": [
        {
          "sequence": 1,
          "text": "0.25mg PO every 6-12 hours as needed for menses from Jan 15-20, 2015.  Do not exceed more than 4mg per day",
          "additional_instruction": [
            {
              "coding": [
                {
                  "system": "eHealth/SNOMED/additional_dosage_instructions",
                  "code": "311504000"
                }
              ]
            }
          ],
          "patient_instruction": "0.25mg PO every 6-12 hours as needed for menses from Jan 15-20, 2015.  Do not exceed more than 4mg per day",
          "timing": {
            "event": [
              "2017-04-20T19:14:13Z"
            ],
            "repeat": {
              "bounds_duration": {
                "value": 10,
                "unit": "days",
                "system": "eHealth/ucum/units",
                "code": "d"
              },
              "count": 2,
              "count_max": 4,
              "duration": 4,
              "duration_max": 6,
              "duration_unit": "d",
              "frequency": 1,
              "frequency_max": 2,
              "period": 4,
              "period_max": 6,
              "period_unit": "d",
              "day_of_week": [
                "mon"
              ],
              "time_of_day": [
                "2017-04-20T19:14:13Z"
              ],
              "when": [
                "WAKE"
              ],
              "offset": 4
            },
            "code": {
              "coding": [
                {
                  "system": "TIMING_ABBREVIATIONS",
                  "code": "patient"
                }
              ]
            }
          },
          "as_needed_boolean": true,
          "site": {
            "coding": [
              {
                "system": "eHealth/SNOMED/anatomical_structure_administration_site_codes",
                "code": "344001"
              }
            ]
          },
          "route": {
            "coding": [
              {
                "system": "eHealth/SNOMED/route_codes",
                "code": "46713006"
              }
            ]
          },
          "method": {
            "coding": [
              {
                "system": "eHealth/SNOMED/administration_methods",
                "code": "419747000"
              }
            ]
          },
          "dose_and_rate": {
            "type": {
              "coding": [
                {
                  "system": "eHealth/dose_and_rate",
                  "code": "'ordered'"
                }
              ]
            },
            "dose_range": {
              "low": {
                "value": 0,
                "unit": "mg",
                "system": "eHealth/ucum/units",
                "code": "mg"
              },
              "high": {
                "value": 0,
                "unit": "mg",
                "system": "eHealth/ucum/units",
                "code": "mg"
              }
            },
            "rate_ratio": {
              "numerator": {
                "value": 0,
                "unit": "mg",
                "system": "eHealth/ucum/units",
                "code": "mg"
              },
              "denominator": {
                "value": 0,
                "unit": "mg",
                "system": "eHealth/ucum/units",
                "code": "mg"
              }
            }
          },
          "max_dose_per_period": {
            "numerator": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            },
            "denominator": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            }
          },
          "max_dose_per_administration": {
            "value": 0,
            "unit": "mg",
            "system": "eHealth/ucum/units",
            "code": "mg"
          },
          "max_dose_per_lifetime": {
            "value": 0,
            "unit": "mg",
            "system": "eHealth/ucum/units",
            "code": "mg"
          }
        }
      ],
      "reject_reason": "Incompatible drugs",
      "reject_reason_code": "PATIENT_REJECT",
      "is_blocked": false,
      "block_reason": "Підозра на фрод",
      "block_reason_code": "BLOCK_WRONG_QTY_DRUG",
      "block_legal_entity": {
        "id": "UUID",
        "type": "NHS"
      },
      "priority": "routine",
      "prior_prescription": {
        "identifier": {
          "type": {
            "coding": [
              {
                "system": "eHealth/resources",
                "code": "medication_request"
              }
            ]
          },
          "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
        }
      },
      "container_dosage": {
        "system": "MEDICATION_UNIT",
        "code": "ML",
        "value": 4
      }
    },
    "dispensed_at": "2017-08-17",
    "dispensed_by": "Іванов Іван Іванович",
    "party": {
      "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
      "first_name": "Петро",
      "last_name": "Іванов",
      "second_name": "Миколайович"
    },
    "legal_entity": {
      "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
      "name": "Клініка Ноунейм",
      "short_name": "Ноунейм",
      "public_name": "Клініка Ноунейм",
      "type": "MSP",
      "edrpou": "5432345432",
      "status": "ACTIVE"
    },
    "division": {
      "id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
      "name": "Бориспільське відділення Клініки Ноунейм",
      "legal_entity_id": "d290f1ee",
      "type": "CLINIC",
      "status": "ACTIVE",
      "mountain_group": false,
      "dls_id": "2872985",
      "dls_verified": true
    },
    "medical_program": {
      "id": "c7d52544-0bd4-4129-97b0-2d72633e0490",
      "name": "Доступні ліки",
      "is_active": true,
      "medication_dispense_allowed": true,
      "medication_dispense_allowed_text": "Some text",
      "medication_request_allowed": true,
      "medication_request_allowed_text": "Some text",
      "type": "MEDICATION",
      "funding_source": "NHS",
      "mr_blank_type": "F-1",
      "inserted_at": "2017-04-20T19:14:13Z",
      "inserted_by": "e1453f4c-1077-4e85-8c98-c13ffca0063e",
      "updated_at": "2017-04-20T19:14:13Z",
      "updated_by": "2922a240-63db-404e-b730-09222bfeb2dd"
    },
    "details": [
      {
        "medication": {
          "name": "Амідарон",
          "type": "MEDICATION",
          "manufacturer": {
            "name": "ПАТ \"Київський вітамінний завод\"",
            "country": "UA"
          },
          "form": "PILL",
          "container": {
            "numerator_unit": "PILL",
            "numerator_value": 1,
            "denumerator_unit": "PILL",
            "denumerator_value": 1
          },
          "form_pharm": "DISPERSIBLE_TABLET",
          "drlz_sku_id": "0404466792737630283703997321"
        },
        "program_medication_id": "64c06ebc-0266-4645-85f0-7a6900d7dfbe",
        "medication_qty": 0,
        "sell_price": 18.65,
        "sell_amount": 186.5,
        "discount_amount": 150,
        "reimbursement_amount": 450,
        "medication_2d_codes": [
          {
            "medication_2d_code": "0104820005161713171812001022431115 211XV82HPV"
          }
        ]
      }
    ],
    "payment_id": "1239804",
    "payment_amount": 50,
    "status": "NEW",
    "inserted_at": "2017-04-20T19:14:13Z",
    "inserted_by": "e1453f4c-1077-4e85-8c98-c13ffca0063e",
    "updated_at": "2017-04-20T19:14:13Z",
    "updated_by": "2922a240-63db-404e-b730-09222bfeb2dd"
  }

Processing

  1. Save signed content to media storage

  2. Update Medication dispense data in OPS DB:

    1. set status  =  ‘PROCESSED’

    2. updated_by = user_id

    3. updated_at = now()

  3. Update related Medication request data in OPS DB:

    1. set status  =  ‘COMPLETED’

    2. updated_by = user_id

    3. updated_at = now()

  4. Write changes to event manager (Medication dispense and Medication request)

  5. Change Care plan activity (If related medication request has reference on Care plan, then corresponding care plan activity should be changed after Medication dispense processed):

    1. Set activity status to in_progress if previous activity status was scheduled 

    2. Check the MD identifier in outcome_reference attribute of the activity:

      1. if not found:

        1. Add reference on the medication dispense resource to the outcome_reference attribute .

        2. If quantity in the activity was set - validate $.activity.details.remaining_quantity_type:

          1. if $.activity.details.remaining_quantity_type = for_request than:

            1. select all MRR in status NEW which based on current activity

            2. select all MR in statuses ACTIVE based on current activity

            3. select all MD (medication dispenses) in status PROCESSED related to the Medication requests which are in status COMPLETE, REJECTED, EXPIRED

            4. calculate:

              1. reserved_qty as sum of medication_qty in the filtered MRR  and MR list

              2. dispensed_qty as sum of medication_qty in the filtered MD list

            5. calculate and update remaining quantity by subtracting reserved_quantity and dispensed_qty from activity quantity

          2. if $.activity.details.remaining_quantity_type = for_use than:

            1. select all MD in status PROCESSED related to MR which based on care plan and current activity

            2. calculate dispensed quantity in the current activity as sum of medication_qty in the filtered MD list

            3. calculate remaining quantity by subtracting dispensed quantity from activity quantity

            4. update remaining_quantity value in the activity with calculated value

      2. If found, then skip updating activity (it means that activity has been already updated by event from current MD processing).

HTTP status codes

HTTP status code

Message

What caused the error

200

Response

 

400

Document must be signed by 1 signer but contains 0 signatures

401

Invalid access token

 

403

Your scope does not allow to access this resource. Missing allowances: medication_dispense:process

 

409

  • Can't update medication dispense status from {status} to PROCESSED.

  • Medication request is not active.

  • Medication request is blocked.

  • Care plan is not active.

  • Care plan activity should be scheduled or in_progress.

 

422

  • Does not match the signer drfo.

  • Does not match the signer last name

  • Signed content does not match to previously created dispense.

  • Expected the value to be >= 0.

  • No labels