Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Purpose

...

Table of Contents

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

...

In case medications are dispensed to patient under specific medical program, program medication id must be provided 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:specific medical program, program medication id must be provided 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:

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

  1. Validate 

medication_request_id - medication_request_id exists

Code Block
{:error, [{%{
        description: "LegalMedication entityrequest not found",
        params: [],
        rule: :invalid
      }, "$.legalmedication_entityrequest_id"}]}
  1. Validate 

medicationparty_request_id - medicationparty_request_id exists

Code Block
{:error, [{%{
        description: "Medication requestParty not found",
        params: [],
        rule: :invalid
      }, "$.medicationparty_request_id"}]}
  1. Validate 

partydivision_id - partydivision_id exists

Code Block
{:error, [{%{
        description: "PartyDivision not found",
        params: [],
        rule: :invalid
      }, "$.partydivision_id"}]}
  1. Validate 

divisionmedical_program_id - divisionmedical_program_id exists

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

...

rule: :invalid
      }, "$.medical_program_id"}]}

5.1 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

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

Validate all medication_id (brand_id) - brand_id exists

Code Block
{:error, [{%{
        description: "Medical programMedication not found",
        params: [],
        rule: :invalid
      }, "$.medical_programdispense_details[:index].medication_id"}]}

5.1 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

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

Validate all medication_id (brand_id) - brand_id exists

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

Validate related Care plan

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. Verify care plan Activity:

    1. It has scheduled, in_progress status

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

...

Validate related Care plan

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. 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 "Division is not verified in DLS"

  4. If chart parameter MEDICAL_PROGRAM_PROVISION_VERIFY, then check division provide each submitted program. For each medical program provision validate:

    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"

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

...

Add record to medication_dispenses

Parameter

Source

Description

id

UUID

Autogenerated

payment_id

NULL

NULL for new records

status

Const: NEW

Always NEW for new records

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

Add records to medication_dispense_details

Parameter

Source

Description

id

UUID

Autogenerated

medication_dispense_id

FK: medication_dispense

reimbursement_amount

Reimbursement