Versions Compared

Key

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

Table of Contents

Purpose

...

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)

...

  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:

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


2. Validate medication_request_id - medication_request_id exists

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

3. Validate party_id - party_id exists

Code Block
languageerl
{:error, [{%{
        description: "Party not found",
        params: [],
        rule: :invalid
      }, "$.party_id"}]}

4. Validate division_id - division_id exists

Code Block
languageerl
{:error, [{%{
        description: "Division not found",
        params: [],
        rule: :invalid
      }, "$.division_id"}]}

5. Validate medical_program_id - medical_program_id exists

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

...

  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

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


Validate all medication_id (brand_id) - brand_id exists

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

...

Code Block
languageerl
{
    "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

...

  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. Division should be active and refers to current legal_entity
    • is_active = true
    • status = 'ACTIVE'
    • divisions.legal_entity_id = client_id (context)
  5. 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
    • 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`)
  6. 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)

...

  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

...

  • medication 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. 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

...

Note: The medication_qty with each attempt can be divided only by an integer.

Validate medication

...

quantity

  1. Check that medication_qty on medication dispense should not exceed the sum of medication_qty already dispensed under this medication request.
    • Find existing medication dispenses by its medication_request_id
    • Count the amount of medication_qty dispensed for this medication request
      1. $.medication_dispense.medication_request_id = $.medication_request.id
      2. $.medication_dispense.status = PROCESSED
      3. $.medication_dispense.medication_qty <= sumpreviously processed(medication_dispense_details.medication_qty)

...

Code Block
languageerl
{:error, [{%{
        description: "RequestedNo more medication quantitydispense shouldcould notbe exceeddone thewith sumthis ofmedication already issuedrequest",
        params: [],
        rule: :invalid
      }, "$.dispense_details[:index].medication_qty"}]}

...


Anchor
reimbursement_amount
reimbursement_amount
Get reimbursement amount

...