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

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

Version 1 Next »

Purpose

This method is designed to create hold (reservation) on medication in order to prevent multiple dispenses under the same Medication Request. This hold lasts certain time (configuration parameter MEDICATION_DISPENSE_EXPIRATION) after with it goes to EXPIRED status

  1. Dispense of medication is possible only under Medication Request and during the period specified in Medication Request (dispense_valid_from, dispense_valid_to)

  2. Dispense details - several medications of different manufacturers with the same substance can be dispensed at a time. Total of medication_qty should be less or equal to medication quantity specified in Medication Request

  3. If patient wants to split medication dispense of his medication request into several parts, it is possible to create and process medication dispense of the medication request with the desired medication quantity.

Status Charts (reimbursement)

Specification

Apiary

WS logic

Authorize user

  1. Verify the validity of access token

    1. Return 401 in case validation fails

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

    1. Return 403 in case invalid scope(s)

Validate request

Schema validation

  1. Validate request according to JSON Schema

    • Return 422 with list of validation errors in case validation fails (422 EView)

Validate program medication

In case medications are dispensed to patient under specific medical program, program medication id must be provided by client or calculated by the system

In case program medication id exists in request:

  1. Check that this program medication id relates to provided medical program and relates to provided medication

    1. In case of error - return 422 (Invalid program medication id)

Calculate program medication id if it is absent in request:

  1. Get last program_medication_id related to medical program and medication

    1. In case of error - return 422 (There are no active program medications for this program and medication)

Get legal entity from token

  1. Extract legal_entity_id (client_id) from token

Get Party from token

  1. Extract party_user (user_id) from token.

Validate FK

  1. Validate 

legal_entity_id - legal_entity_id exists

In case error - return 422 error:

{:error, [{%{
        description: "Legal entity not found",
        params: [],
        rule: :invalid
      }, "$.legal_entity_id"}]}

  1. Validate 

medication_request_id - medication_request_id exists

{:error, [{%{
        description: "Medication request not found",
        params: [],
        rule: :invalid
      }, "$.medication_request_id"}]}
  1. Validate 

party_id - party_id exists

{:error, [{%{
        description: "Party not found",
        params: [],
        rule: :invalid
      }, "$.party_id"}]}
  1. Validate 

division_id - division_id exists

{:error, [{%{
        description: "Division not found",
        params: [],
        rule: :invalid
      }, "$.division_id"}]}
  1. Validate 

medical_program_id - medical_program_id exists

{:error, [{%{
        description: "Medical program not found",
        params: [],
        rule: :invalid
      }, "$.medical_program_id"}]}

5.1 Validate there is a contract in PRM.contracts that meets following requirements:

If medication dispense has medical program with setting skip_contract_provision_verify = true, than skip contract validation

Else validate there is a contract in PRM.contracts that meets following requirements:

  1. contracts.type==reimbursement

  2. contracts.status==VERIFIED

  3. Contract dates: start_date <= current_date & end_date >= current_date

  4. contracts.contractor_legal_entity_id=token.client_id

  5. $division_id in contract_divisions

    contracts.medical_program_id==$.medical_program_id

    сontracts.is_suspended ==false

In  case of error 409 - "Program cannot be used - no active contract exists"

Validate all medication_id (brand_id) - brand_id exists

{:error, [{%{
        description: "Medication not found",
        params: [],
        rule: :invalid
      }, "$.dispense_details[:index].medication_id"}]}

Validate code

  1. Check that code in request is equal to code in medication_request (or both is empty)

    1. In case code exists in request - it should match with code in medication_request

      1. Return 401 in case code doesn't match (message = "Incorrect code")

    2. In case code is missing in request - check that code in medication_request is NULL

      1. Return 401 in case code in medication_request is not NULL (message = "Missing or Invalid code")

Validate related Care plan

If (medication_request.based_on is present and not null) AND medical_program is absent:

  1. Verify Care plan:

    1. It should be in active status

      1. in case of error - return 409 (message: "Invalid care plan status")

    2. Care plan's period end (if exist) should be greater than current date or equal.

      1. in case of error - return 409 (message: “Care plan expired“)

  2. Verify care plan Activity:

    1. It has scheduled, in_progress status

      1. in case of error - return 409 (message: "Invalid activity status")

Validate division

If division_id submitted:

  1. Validate division is active

    1. in case of error - return 409 ("Division is not active")

  2. Validate division belongs to user's legal entity

    1. in case of error - return 409 ("Division does not belong to user's legal entity")

  3. If chart parameter DISPENSE_DIVISION_DLS_VERIFY is on, then validate division is DLS verified (dls_verified=true)

    1. in case of error - return 409 "Invalid division dls status"

  4. If chart parameter MEDICAL_PROGRAM_PROVISION_VERIFY, then check division provide each submitted program. For each Medical Program Provision validate following:

    1. If the medical program has no setting skip_contract_provision_verify or it is equal to false/null: 

      1. it is exist and active:

        1. in case of error - return status=INVALID for a program, rejection_reason= "Division does not provide the medical program"

      2. it relates to the actual reimbursement contract: contract.start_date <= current_date <= contract.end_date, is_active = true, status = VERIFIED.

        1. in case of error - return status=INVALID for a program, rejection_reason="Medical program provision is not related to any actual contract for the current date"

    2. else if skip_contract_provision_verify = true, then skip provision verification for the medical program

Qualify medication request

Important: This validation must be done only if medical_program exists in request

  1. Check that medication request is valid and available for dispense

    1. Invoke Qualify method

    2. Use medication_requests.medical_program_id as program for qualify

    3. Check that program_medication_id is in Qualify response

Dispense prohibited

Medication request is prohibited for dispense in case $.data[?(@.program_id=medication_requests.medical_program_id)].status = 'INVALID' or program_medication_id is absent in qualify response

{
    "meta": {
        "url": "http://dev.ehealth.world/api/medication_requests/ed56699a-4a6d-427c-9b93-33a4a8d0b7b0/actions/qualify",
        "type": "list",
        "request_id": "unrbcrs34t0cinqpe8fb6nu7oem17qim",
        "code": 200
    },
    "data": [
        {
            "status": "INVALID",
            "rejection_reason": "For the patient at the same term there can be only 1 dispensed medication request per one and the same innm!",
            "program_name": "Доступні ліки",
            "program_id": "3c7d7a7f-82c2-4f5c-806e-f1f5b55164a2",
            "participants": []
        }
    ]
}

In case of error - return 409 error (message = "Medication request can not be dispensed. Invoke qualify medication request API to get detailed info")

Dispense is allowed

Medication request is allowed for dispense in case $.data[?(@.program_id=medication_requests.medical_program_id)].status = 'VALID' and program_medication_id is present in qualify response

{
    "meta": {
        "url": "http://dev.ehealth.world/api/medication_requests/ed56699a-4a6d-427c-9b93-33a4a8d0b7b0/actions/qualify",
        "type": "list",
        "request_id": "unrbcrs34t0cinqpe8fb6nu7oem17qim",
        "code": 200
    },
    "data": [
        {
            "status": "VALID",
            "program_name": "Доступні ліки",
            "program_id": "3c7d7a7f-82c2-4f5c-806e-f1f5b55164a2",
            "participants": []
        }
    ]
}

Validate statuses

  1. Legal entity should be active in order to dispense medication

    • is_active = true

    • status = 'ACTIVE'

    • type in pharmacy_allowed_transactions_le_types

      mis_verified = `VERIFIED`

  2. Medication request should be active in order to dispense medication

    • is_active = true

    • status = 'ACTIVE'

    • started_at <= current_date() and ended_at >= current_date()

  3. Party should refer to active employee in current legal_entity

    • employees.is_active = true

    • employees.status = 'APPROVED'

    • employees.legal_entity_id = client_id (context)

  4. Medical Program should be active in order to dispense medication under this program and the same as medical program in medication request

    • is_active = true

    • If medication_requests.medical_program_id was set, then check request.medical_program_id = medication_requests.medical_program_id

      • in case of error return 409 Error (`Medical program in dispense doesn't match the one in medication request`)

  5. Medication (brand) medication should be active

    1. medications.is_active = true

    2. medications.type = 'BRAND'

    3. ingredients.medication_child_id = medication_request.medication_id and ingredients.is_primary = true

    4. medication_id exists in program_medications (is_active = true)

Validate dispense period

  1. Check that dispense date is in period specified in Medication Request

    • dispense_valid_from <= current_date()

      dispense_valid_to >= current_date()

Check other Medication Dispenses

  1. Check all connected medication dispenses

  • sum of medication_qty of all connected medication dispenses < medication_request.medication_qty

  • medictaion dispenses status in ('NEW', 'PROCESSED')

In case of error - return 403 error (message = "No more medication dispense could be done with this medication request")

Validate medication quantity

  1. Get multi_medication_dispense_allowed parameter from medical program settings:

    1. if it is true - check that requested medication quantity less or equal to medication quantity in Medication Request

      1. sum(:medication_qty) <= medication_request.medication_qty

        1. in case of error - return 422 "Dispensed medication quantity must be lower or equal to medication quantity in Medication Request. Available quantity is #{available_qty}"

    2. if it is false (absent) - check that requested medication quantity equal to medication quantity in Medication Request

      1. medication_qty = medication_request.medication_qty 

        1. in case of error - return 422 "Dispensed medication quantity must be equal to medication quantity in Medication Request"

Validate medication multiplicity

  1. Check that requested medication quantity in dispense for all medications is multiplier of package_min_qty for this medications.id

    •  Mod($medication_qty, medications.package_min_qty) = 0

In case of error (if at least one of medication don't pass verification) - return 422 error

{:error, [{%{
        description: "Requested medication brand quantity is not a multiplier of package minimal quantity",
        params: [],
        rule: :invalid
      }, "$.dispense_details[:index].medication_qty"}]}

Validate medication discount amount

Note: There are two different validation rules depending on medication package quantity and min quantity

If min quantity is equal to package quantity - there shouldn't be any tolerance during calculation. 

Validation 1: Min package quantity is equal to package quantity

  1. Check that requested discount price is equal to allowed reimbursement amount for the requested medication quantity (the way how to calculate allowed reimbursement amount is below)

  • discount_amount <= reimbursement_amount * (medication_qty/package_qty)

Validation 2: Min package quantity is not equal to package quantity

  1. Check that requested discount price less or equal to allowed reimbursement amount (including deviation) for the requested medication quantity (the way how to calculate allowed reimbursement amount is below)

  • 1 > = discount_amount/ (((reimbursement_amount/package_qty)*medication_qty)) >= 1 - deviation

In case of error - return 422 error

{:error, [{%{
        description: "Requested discount price doesn't not satisfy allowed reimbursement amount",
        params: [],
        rule: :invalid
      }, "$.dispense_details[:index].discount_amount"}]}

Get reimbursement amount

There are two types of calculation of reimbursement amount:

  • FIXED - reimbursement rate defined here for package_qty without any calculations 

    EXTERNAL - reimbursement rate or amount should be calculated via API external call

Important: Only FIXED type is allowed during first phase

  1. Get reimbursement amount for this medication_id according to medical_program_id

    1. Determine calculation channel (FIXED, EXTERNAL)

    2. Calculate reimbursement amount for the requested quantity of medications:

      1. Get the reimbursement_amount from program_medications.reimbursement.reimbursement_amount (for the package)

      2. Based on it,  package_min_qty and requested medication_qty calculate the ratio and allowed reimbursement amount ((reimbursement_amount/package_qty)*medication_qty)

Service logic

  1. Get skip_medication_dispense_sign from medical program settings.

  2. If skip_medication_dispense_sign = false or absent:

    2.1. Check payment_id, payment_amount is absent in the request.

  • in case if present - return 422 with path: $.<field_name>  and message "schema does not allow additional properties"

      2.2. Add record to medication_dispenses table:

Parameter

Source

Description

id

UUID

Autogenerated

payment_id

NULL

NULL for new records

payment_amount

NULL

NULL for new records.

status

Const: NEW

NEW skip_medication_dispense_sign = false

See: Status Charts (reimbursement)

is_active

Const: TRUE

Alwayls TRUE for new records

inserted_at

Timestamp: now()

Get current date-time

inserted_by

Token: user_id

Extract user from token

updated_at

Timestamp: now()

Get current date-time

updated_by

Token: user_id

Extract user from token

       2.3. Add records to medication_dispense_details table:

Parameter

Source

Description

id

UUID

Autogenerated

medication_dispense_id

FK: medication_dispense

reimbursement_amount

Reimbursement

3. If skip_medication_dispense_sign =

true:

      3.1. Check if payment_amount in the request.

  • in case is absent - return 422 with path: $.payment_amount and message "required property payment_amount was not present"

      3.2. Call Process Medication Dispense process, but without validation of digital sign and storage signed content to the bucket.

      3.3. Add records as described on steps 2.2-2.3, but with following differences: 

             medication_dispenses table

Parameter

Source

Description

payment_id

Request: payment_id

optional parameter

payment_amount

Request: payment_amount

required parameter

status

Const: PROCESSED

PROCESSED skip_medication_dispense_sign = true
See: 

Status Charts (reimbursement)

  • No labels