Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

REST API method / Метод REST API (настанова) (remove the link block before publishing the document)

...

Page Properties
idpage_properties_method_REST API

Document type

Метод REST API

Document title

[Document status] REST API [Назва методу] [ID методу]

Guideline ID

GUI-0011

Author

@

Document version

1

Document status

DRAFT

Date of creation

ХХ.ХХ.ХХХХ (дата фінальної версії документа – RC або PROD)

Date of update

ХХ.ХХ.ХХХХ (дата зміни версії)

Method API ID

API-001-001-001-0001

Microservices (namespace)

IL

Component

ePrescription

Component ID

COM-005-008

Link на API-специфікацію

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

Resource

{{host}}/api/pharmacy/medication_dispenses

Scope

medication_dispense:create

Protocol type

REST

Request type

POST

Sync/Async

Sync

Public/Private

Public

...

  1. 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.1. Call Process Medication Dispense by Pharmacy User process, but without validation of the previously created (NEW) medication dispense, digital sign and storage signed content to the bucket.

...

  1. Medication Request should be Сreated by MSP

  2. Medication Request should be found and qualified by pharmacist

Configuration parameters

Description of the configuration parameters that are used when processing a request in the system

Dictionaries

Provides a list of links to dictionaries that are available in Confluence

Input parameters

...

parameters

Input parameter

Mandatory

Type

Description

Example

1

code

O

String

-

314

...

  1. Validate request according to JSON Schema

    • Check presence of extra parameters

      • In case of error - return 422 ('schema does not allow additional properties')

    • Check presence of required parameters

      • In case of error - return 422 ('required property %{property} was not present')

    • Check note length (optional, nullable) - it must be no longer than 1000 characters

      • In case of error - return 422 ('expected value to have a maximum length of 1000 but was {actual length}')

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:write')

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

  4. If BLOCK_UNVERIFIED_PARTY_USERS is true, then check party's data match following condition: verification_status != NOT_VERIFIED or (verification_status = NOT_VERIFIED and updated_at <= current_date - UNVERIFIED_PARTY_PERIOD_DAYS_ALLOWED):

    • in case not match - return 403 ("Access denied. Party is not verified")

Validate Legal entity

  • Extract client_id from token

  • Check legal entity status is ACTIVE

    • In case of error - return 422 ('Legal entity is not active')

  • Check legal entity type in MEDICATION_DISPENSE_LEGAL_ENTITY_TYPES config parameter

    • in case of error - return 409 ('Invalid legal entity type')

Validate Division

Division must have active pharmacy license in order to dispense medications

  1. Validate division is exist

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

  2. Validate division is active

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

  3. Validate division belongs to user's legal entity

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

  4. If chart parameter DISPENSE_DIVISION_DLS_VERIFY is on, then validate division is DLS verified

    1. check that division.dls_verified = true

      1. in case of error - return 409 ('Invalid division dls status')

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

  6. Get license_types_allowed parameter from settings of medical program from request $.medical_program_id:

    1. if it is exists and not empty, get list of all license types from parameter.
      Check that division has active healthcare services with following parameters:

      1. legal_entity_id = client_id from access token

      2. division_id = division_id from request

      3. status = 'ACTIVE'

      4. licensed_healthcare_service.status = 'ACTIVE'

      5. healthcare_service.license_id is not null and licenses.type = value from license_types_allowed parameter

        1. in case of error - return 409 ('Division must have active licenses to dispense medication request')

Validate Medication request

  1. Check that medication_request_id is exist

    1. in case of error - return 422 ('Medication request not found')

  2. Check intent specified in Medication request equal to order

    1. in case of error - return 409 error ('Medication request with intent PLAN cannot be dispensed')

  3. Сheck that Medication request is_active = true and status == 'ACTIVE'

    1. in case of error - return 409 error ('Medication request is not active')

  4. Check that Medication request not blocked (medication_requests.is_blocked = false or NULL)

    1. medication_requests.is_blocked = false or NULL

    2. medication_requests.blocked_to <= now() (datetime) or NULL

      1. in case of error - return 409 error ('Medication request is blocked')

  5. Check that dispense date is in period specified in Medication request (dispense_valid_from >= current_date() and dispense_valid_to <= current_date())

    1. in case of error - return 409 error ('Invalid dispense period')

  6. Check if medication_request.based_on is present and not null AND medication_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")

...

  1. Check that medical_program_id is exist

    1. in case of error - return 422 ('Medical program not found')

  2. Сheck that medical_program_id is_active = true and status == 'ACTIVE'

    1. in case of error - return 422 error ('Medication request is not active')

  3. Check if medical program has setting medical_program_change_on_dispense_allowed parameter from settings of medical program from medication request:

    1. if it is false (absent), medical program in dispense must be the same as medical program in medication request (request.medical_program_id = medication_requests.medical_program_id)

      1. in case of error - return 409 ('Medical program in dispense doesn't match the one in medication request')

  4. Check if medical program has setting skip_contract_provision_verify = true, than skip contract validation

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

      6. contracts.medical_program_id==$.medical_program_id

      7. сontracts.is_suspended == false

    2. in case of error - return 409 ('Program cannot be used - no active contract exists')

...

  1. Check that code in request is equal to code in medication_request

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

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

Validate Medication dispenses

  1. Check all connected medication dispenses:

    1. there isn't medictaion dispenses with the 'NEW' status

      1. in case of error - return 422 "Medication dispense in status NEW already exist."

Validate Dispense details

  1. Check that medical_program_id is exist and active

  2. Check that medication exists and is active

    1. medications.is_active = true

    2. medications.type is ‘BRAND' or ‘INNM_DOSAGE'

    3. if medications.type = 'BRAND'

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

    4. if medications.type = 'INNM_DOSAGE'

      1. dispense_details.medication_id = medication_request.medication_id

    5. check dispensed_at

      1. if funding_source = "NHS" then dispensed_at = date.now()

        • in case of error - return 422 ('For Medical program with funding_source = "%{funding_source}" medication dispense dispensed_at must be equal to current date')

      2. else if funding_source != "NHS" then dispensed_at <= date.now()

        • in case of error - return 422 ('For Medical program with funding_source = "%{funding_source}" medication dispense dispensed_at must be equal to or less than current date')

...

Validate Medication multiplicity

This validation must be done only in case when medication dispensed to patient as brand. In case of extemporaneous medications this validation must be skipped

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

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

      1. in case of error (if at least one of medication don't pass verification) - return 422 error ('Requested medication brand quantity is not a multiplier of package minimal quantity')

...

  1. Define reimbursement_type (get from program_medications by program_medication_id).

  2. Validate percentage discount price.
    Check if reimbursement_type == percentage and percentage_reimbursement_amount = 0
    (the way how to calculate percentage_reimbursement_amount is following:
    percentage_reimbursement_amount = sell_price (from request) * percentage_discount (from program_medications) /100)

    • In case if discount_amount != 0 - return 422 ('Requested discount price must be equal to 0')

    • Else (if discount_amount = 0)  - finish validation (do not validate 3, 4)

  3. Validate allowed reimbursement amount.
    Check that requested discount price is less or equal to allowed reimbursement amount for the requested medication quantity
    (the way how to calculate allowed reimbursement amount is below.
    for type == percentage use percentage_reimbursement_amount, for fixed = use reimbursement_amount from program_medications):
      There are two different formulas depending on medication type to be dispensed

    1. If medication.type = ‘BRAND’:

      1. discount_amount <= reimbursement_amount * (medication_qty/package_qty)

    2. If medication.type = ‘INNM_DOSAGE’:

      1. discount_amount <= reimbursement_amount * medication_qty

  4. Validate the ratio of discount price to reimbursement amount.
    Check that the ratio of requested discount price to allowed reimbursement amount is more or equal to allowed rule (including deviation) for the requested medication quantity
    (the way how to calculate allowed reimbursement amount is below.
    for type = percentage use percentage_reimbursement_amount, for fixed - use reimbursement_amount from program_medications):
          There are two different formulas depending on medication type to be dispensed

    1. If medication.type = ‘BRAND’:

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

    2. If medication.type = ‘INNM_DOSAGE’:

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

  5. In case of error - return 422 ('The ratio of requested discount price to allowed reimbursement amount must be greater or equal to <1 - deviation>')

...

  • Check that medication_2d_codes array contains at least one element (array is not empty)

    • in case of error - return 422 ('Expected a minimum of %{min} items but got %{actual}')

  • For all objects in array check that string 'medication_2d_code' is not null or empty

    • in case of error - return 422 ('Not allowed to save empty 2d code')

Processing

A list of processes related to receiving, changing or transmitting data according to the logic defined in the REST API

Response structure examples

...

Post-processing processes

No

Technical modules where the method is used

...