Purpose

This method is designed to process previously created Medication dispense.

...

  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

Page Properties

Link

https://ehealthmisapi1.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

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

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).

...

  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

...

API paragraph not found

Request data validation

Validate digital signature

...

Validate request is signed

...

Jira Legacy
serverSystem Jira
serverIdd9171809-9c5e-36f7-ab17-a56a875b6d19
keyEPRX-773

  • 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 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. Check In case if medical program has funding sourse == NHS check that payment_amount should be 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").

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. 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).

Parameters that are used when processing the request

Configuration parameters

Access to the method is defined by the scope medication_dispense:process. Permission for this scope is determined by the System administrator by configuring scopes in the context of clients and roles.

Dictionaries

Dictionaries

API paragraph not found

...

API paragraph not found

Response structure

See on Apiary

...

Expand
titleResponse example
Code Block
{
  "meta": {
    "code": 200,
    "url": "https://example.com/resource",
    "type": "object",
    "request_id": "req-adasdoijasdojsda6617aeec-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": "Доступні ліки",
        "medical_program_settings": {
          "care_plan_required": true,
          "employee_types_to_create_medication_request": [
            "SPECIALIST",
            "DOCTOR"
          ],
          "skip_mnn_in_treatment_period": true,
          "skip_employee_validation": true,
          "speciality_types_allowed": [
            "ENDOCRINOLOGY",
            "PEDIATRIC_NEUROLOGY"
          ],
          "conditions_icd10_am_allowed": [
            "A00.0",
            "A00.1"
          ],
          "conditions_icpc2_allowed": [
            "A01",
            "A02"
          ],
          "providing_conditions_allowed": [
            "INPATIENT",
            "OUTPATIENT"
          ],
          "medication_request_max_period_day": 90,
          "skip_medication_request_employee_declaration_verify": true,
          "skip_medication_request_legal_entity_declaration_verify": true,
          "multi_medication_dispense_allowed": true,
          "skip_medication_dispense_sign": true,
          "medication_request_notification_disabled": true,
          "skip_contract_provision_verify": true,
          "medication_dispense_period_day": 90
,
       },         "medical_program_change_on_settingsdispense_textallowed": "Some text",true,
          "ispatient_categories_activeallowed": true,[
            "medicationinsulin_dispense_allowed": true,1",
            "medication_dispense_allowed_text": "Some text",insulin_2"
           "medication_request_allowed": true,],
          "medicationlicense_requesttypes_allowed_text": "Some text",[
           "type": "MEDICATIONPHARMACY",
            "fundingPHARMACY_source": "NHS",
DRUGS"
          ]
       "mr_blank_type": "F-1" },
        "inserted_atmedical_program_settings_text": "2017-04-20T19:14:13ZSome text",
        "insertedis_byactive": "e1453f4c-1077-4e85-8c98-c13ffca0063e"true,
        "updatedmedication_dispense_atallowed": "2017-04-20T19:14:13Z"true,
        "updated_bymedication_dispense_allowed_text": "2922a240-63db-404e-b730-09222bfeb2dd"Some text",
        },"medication_request_allowed": true,
        "intentmedication_request_allowed_text": "planSome text",
        "categorytype": "communityMEDICATION",
        "based_on": [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": "care_planactivity"
                }
              ]
            },
            "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
          }
        },
      ],
 {     "context": {
        "identifier": {
            "type": {
              "coding": [
 
              {
 
                "system": "eHealth/resources",
 
                "code": "activityencounter"
                }
              ]
 
          },

           "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"
        }
      },
      "dosage_instruction": [
     }   {
   ],       "contextsequence": 1,
 {         "identifiertext": {
          "type": {
  "0.25mg PO every 6-12 hours as needed for menses from Jan 15-20, 2015.  Do not exceed more than 4mg per day",
          "codingadditional_instruction": [
 
            {
                "systemcoding": "eHealth/resources",[
                "code": "encounter"{
               }   "system": "eHealth/SNOMED/additional_dosage_instructions",
        ]           },
"code": "311504000"
         "value": "9183a36b-4d45-4244-9339-63d81cd08d9c"      }
  }       },     ]
 "dosage_instruction": [         { }
         "sequence": 1],
          "textpatient_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",
          "additional_instructiontiming": [             {

             "codingevent": [
              "2017-04-20T19:14:13Z"
 {                   "system": "eHealth/SNOMED/additional_dosage_instructions"],
                  "code"repeat": "311504000"{
                }
              ]"bounds_duration": {
            }    "value": 10,
     ],           "patient_instructionunit": "0.25mg PO every 6-12 hours as needed for menses from Jan 15-20, 2015.  Do not exceed more than 4mg per day","days",
                "system": "eHealth/ucum/units",
                "timingcode": "d"
{             "event": [ },
              "count"2017-04-20T19:14:13Z": 2,
               ],"count_max": 4,
              "repeatduration": {4,
              "boundsduration_durationmax": {6,
                "valueduration_unit": 10"d",
 
              "unitfrequency": "days"1,
                "systemfrequency_max": "eHealth/ucum/units"2,
                "codeperiod": 4,
"d"               }"period_max": 6,
              "countperiod_unit": 2"d",
              "countday_of_maxweek": [
 4,               "durationmon":
4,               "duration_max": 6],
              "durationtime_of_unit": "d",day": [
                "frequency": 1,2017-04-20T19:14:13Z"
               "frequency_max": 2],
              "periodwhen": 4,[
                "period_maxWAKE":
6,               "period_unit": "d"],
              "day_of_weekoffset": 4
   [         },
       "mon"     "code": {
        ],      "coding": [
       "time_of_day": [        {
        "2017-04-20T19:14:13Z"          "system": "TIMING_ABBREVIATIONS",
   ],               "whencode": ["patient"
                "WAKE"}
              ],
            }
      "offset": 4   },
         },
  "as_needed_boolean": true,
          "codesite": {

             "coding": [
                {
 
                "system": "TIMING_ABBREVIATIONSeHealth/SNOMED/anatomical_structure_administration_site_codes",
                  "code": "patient"
                }
              ]344001"
              }
          },  ]
         "as_needed_boolean": true },
          "siteroute": {
            "coding": [
              {
                "system": "eHealth/SNOMED/anatomical_structure_administration_site_route_codes",
                "code": "34400146713006"
              }
            ]
          },
          "routemethod": {
            "coding": [
              {
                "system": "eHealth/SNOMED/routeadministration_codesmethods",
                "code": "46713006419747000"
              }
            ]
          },
          "method"dose_and_rate": {
            "type": {
              "coding": [
                {
                  "system": "eHealth/SNOMED/administration_methodsdose_and_rate",
                  "code": "419747000'ordered'"
              }  }
          ]    ]
      },           "dose_and_rate": {},
            "typedose_range": {
              "codinglow": [{
                {
 "value": 0,
                "systemunit": "eHealth/dose_and_ratemg",
                  "codesystem": "'ordered'"eHealth/ucum/units",
                }
"code": "mg"
             ] },
           },             "dose_range"high": {
                "lowvalue": {0,
                "valueunit": 0"mg",
                "unitsystem": "mgeHealth/ucum/units",
                "systemcode": "eHealth/ucum/units",mg"
              }
          "code": "mg" },
             },"rate_ratio": {
              "highnumerator": {
                "value": 0,
                "unit": "mg",
                "system": "eHealth/ucum/units",
                "code": "mg"
              }
            },
    
       "rate_ratio": {               "numerator"denominator": {
                "value": 0,
                "unit": "mg",
                "system": "eHealth/ucum/units",
                "code": "mg"
              },
            }
   "denominator": {      },
          "valuemax_dose_per_period": 0,
 {
              "unitnumerator": "mg",
 {
              "systemvalue": "eHealth/ucum/units",
 0,
              "codeunit": "mg",
              }
"system": "eHealth/ucum/units",
           }   "code": "mg"
      },           "max_dose_per_period": {},
             "numeratordenominator": {
              "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
            },
          },
        "denominator  "max_dose_per_administration": {
 
            "value": 0,
              "unit": "mg",
              "system": "eHealth/ucum/units",
              "code": "mg"
      
     }           },
          "max_dose_per_administrationlifetime": {
            "value": 0,
            "unit": "mg",
            "system": "eHealth/ucum/units",
            "code": "mg"
          }
   },     }
      ],
      "max_dose_per_lifetimereject_reason": {
 "Incompatible drugs",
          "value"reject_reason_code": 0"PATIENT_REJECT",
      "is_blocked": false,
      "unitblock_reason": "mgПідозра на фрод",
            "system"block_reason_code": "eHealth/ucum/unitsBLOCK_WRONG_QTY_DRUG",
      "block_legal_entity": {
        "codeid": "mgUUID",
          }
"type": "NHS"
      },
}       ]"priority": "routine",
      "rejectprior_reasonprescription": {
"Incompatible drugs",       "reject_reason_codeidentifier": "PATIENT_REJECT", {
          "is_blockedtype": false,{
            "block_reasoncoding": "Підозра на фрод",[
               "block_reason_code": "WRONG_QTY_DRUG",{
        "priority": "routine",       "prior_prescriptionsystem": {"eHealth/resources",
        "identifier": {       "code": "medication_request"
  "type": {           }
 "coding": [          ]
    {      },
          "systemvalue": "eHealth/resources",9183a36b-4d45-4244-9339-63d81cd08d9c"
        }
      },
     "code": "medicationcontainer_requestdosage": {
        "system": "MEDICATION_UNIT",
   }     "code": "ML",
      ]  "value":  4
      },
     },
    "valuedispensed_at": "9183a36b-4d45-4244-9339-63d81cd08d9c"2017-08-17",
    "dispensed_by": "Іванов Іван Іванович",
}    "party": {
 },
      "container_dosageid": {
"b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
       "systemfirst_name": "MEDICATION_UNITПетро",
        "codelast_name": "MLІванов",
       "second_name": "valueМиколайович":
4    },
  }  "legal_entity": {
 },     "dispensed_atid": "2017-08-17b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
      "dispensed_byname": "ІвановКлініка Іван ІвановичНоунейм",
      "partyshort_name": {"Ноунейм",
      "idpublic_name": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7bКлініка Ноунейм",
      "first_nametype": "ПетроMSP",
      "last_nameedrpou": "Іванов5432345432",
      "second_namestatus": "МиколайовичACTIVE"
    },
    "legal_entitydivision": {
      "id": "b075f148d290f1ee-7f936c54-4fc24b01-b2ec90e6-2d81b19a9b7bd701748f0851",
      "name": "КлінікаБориспільське відділення Клініки Ноунейм",
      "shortlegal_entity_nameid": "Ноунеймd290f1ee",
      "public_nametype": "Клініка НоунеймCLINIC",
      "typestatus": "ACTIVE",
   "MSP"   "mountain_group": false,
      "edrpoudls_id": "54323454322872985",
      "statusdls_verified": "ACTIVE"true
    },
    "divisionmedical_program": {
      "id": "d290f1eec7d52544-6c540bd4-4b014129-90e697b0-d701748f08512d72633e0490",
      "name": "Бориспільське відділення Клініки НоунеймДоступні ліки",
      "legalmedical_entityprogram_idsettings": "d290f1ee", {
        "typecare_plan_required": "CLINIC"true,
      "status  "employee_types_to_create_medication_request": "ACTIVE",
[
     "mountain_group": false,    "SPECIALIST",
  "dls_id": "2872985",       "dls_verifiedDOCTOR":
true     },     "medical_program": {],
        "idskip_mnn_in_treatment_period": "c7d52544-0bd4-4129-97b0-2d72633e0490",true,
        "nameskip_employee_validation": "Доступні ліки",true,
        "medicalspeciality_programtypes_settingsallowed": {[
          "care_plan_required": true,ENDOCRINOLOGY",
          "employee_types_to_create_medication_request": [
 PEDIATRIC_NEUROLOGY"
        ],
        "SPECIALIST",conditions_icd10_am_allowed": [
          "DOCTOR"
 A00.0",
      ],         "skip_mnn_in_treatment_period": true,"A00.1"
         "skip_employee_validation": true],
        "specialityconditions_typesicpc2_allowed": [
          "ENDOCRINOLOGYA01",
          "PEDIATRIC_NEUROLOGYA02"
        ],
        "providing_conditions_icd10_am_allowed": [
          "A00.0INPATIENT",
          "A00.1OUTPATIENT"
        ],
        "conditions_icpc2_allowedmedication_request_max_period_day": [
 90,
        "A01",
          "A02"skip_medication_request_employee_declaration_verify": true,
         ]"skip_medication_request_legal_entity_declaration_verify": true,
        "providingmulti_medication_conditionsdispense_allowed": [true,
          "INPATIENT""skip_medication_dispense_sign": true,
        "medication_request_notification_disabled": true,
"OUTPATIENT"         ]"skip_contract_provision_verify": true,
        "medication_request_maxdispense_period_day": 90,
        "skipmedical_medicationprogram_requestchange_employeeon_declarationdispense_verifyallowed": true,
        "skippatient_medication_request_legal_entity_declaration_verify": true,categories_allowed": [
          "multi_medication_dispense_allowed": true,insulin_1",
          "skip_medication_dispense_sign": trueinsulin_2"
        ],
        "medicationlicense_requesttypes_notification_disabledallowed": true,[
          "skip_contract_provision_verify": true,PHARMACY",
          "medication_dispense_period_day": 90PHARMACY_DRUGS"
        ]
      },
      "medical_program_settings_text": "Some text",
      "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"
  }
}

...

Page Properties

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.

...