Versions Compared

Key

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

...

  1. Verify Care plan:

    1. It should be in active status

      1. in case of error - return 409 (message: "Care plan is not active")

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

    2. If it has quantity then calculate remaining quantity:

      1. select all MRR in status NEW which based on current activity

      2. select all MR in statuses ACTIVE, COMPLETED based on current activity

      3. calculate reserved at the moment medication quantity as sum of medication_qty in the filtered MRR  and MR list, including medication_qty from current MRR

      4. calculate remaining quantity by subtracting reserved quantity from activity quantity

      5. Check remaining quantity is greater then or equal to zero

        1. in case of error return 409 "The total amount of the prescribed medication quantity exceeds quantity in care plan activity"

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 409 ("Division is not provide the medical program")

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

      1. in case of error - return 409 ("Medical program provision is not actual for the current date")

Logic for qualify (analyze compliance with programs)

...

Check INNM_dosage compliance for the programs

Applies to the following programs:

  1. Dostupni liky

  2. Netsukrovyy diabet

  3. Insuliny z doplatoyu

  4. Insuliny bezoplatno

  5. Epilepsiya

  6. Rozlady psykhiky ta povedinky

Validation purpose:  There is a list of medications (which links to innm_dosage) which can be used for the program. It must be check whether there is at least one available medication for the innm_dosage for the particular program.

  1. Get info from Medication request  by id in payload, set temp variable object `_MR`

  2. Validate the compatibility of innm with the medication program list 

    1. if data is not found:

      1. add to response: status = INVALID

      2. add to response: rejection_reason = "Innm not on the list of approved innms for program '#{program.name}"

Code Block
IF EXISTS
    (SELECT * FROM program_medications MP
        INNER JOIN medications M
            ON M.id = MP.medication_id
                AND M.type =  BRANDS
        INNER JOIN ingredients I
            ON I.parend_id = M.id
                AND I.is_primary = TRUE
                AND I.medication_child_id = _MR.medication_id
    WHERE MP.medical_program_id == $.id
        AND MP.is_active == TRUE
        AND M.is_active == TRUE)

Check absence a same medication for the programs

...

  1. Dostupni liky

  2. Netsukrovyy diabet

  3. Insuliny z doplatoyu

  4. Insuliny bezoplatno

  5. Epilepsiya

  6. Rozlady psykhiky ta povedinky

Validation purpose: It could be done several dispenses for one medication request per one innm for one patient until sum(medication_dispenses.medication_qty) < medication_request.medication_qty

Example validation: without crossing time

P

 Preconditions # 1

Result validate #1 

 Preconditions #2

Result validate #2 

 Preconditions #3

Result validate #2 

PreQualifyMedicationRequestRequest

No records in 
MedicationRequestRequest 
and in MedicationRequest

OK

Create record in 
MedicationRequestRequest 
or in MedicationRequest

Not valid

Medications request 
dispensed (COMPLETED)

Not valid

QualifyMedicationRequestByID

No records in 
MedicationRequestRequest 
and in MedicationRequest

Not possible

Create record in 
MedicationRequestRequest 
or in MedicationRequest

OK

Medications request 
dispensed (COMPLETED) 

Not valid

  1. For info - status charts: Medication Request Status Chart & Medication Dispense Status Chart

  2. Get `check_innm_id`

    Code Block
    SELECT I.innm_child_id
        FROM ingredients I
    WHERE I.parent_id = _MR.medication_id 
        AND I.is_primary = TRUE
    
  3. Get Medication requests with their linked completed Medication dispense by person_id & innm_id

    Code Block
    SELECT * FROM medication_requests MR    INNER JOIN medication_dispense MD        ON MD.medication_request_id = MR.id             AND MD.status IN (PROCESSED)    INNER JOIN ingredients I        ON I.parent_id = MR.medication_id           -- type = INNM_DOSAGE            AND I.innm_child_id = `check_innm_id`            AND I.is_primary = TRUE    WHERE MR.person_id == _MR.person_id        AND MR.status IN (ACTIVE, COMPLETED)        AND NOT($.started_at> MR.ended_at OR $.ended_at < MR.started_at)
  4. Validate medication request_id

    1. for medication_dispense.medication_request_id !== $.id

      1. Validate exist (IF EXIST ()  - that is any crossing  calculating term (started_at + ended_at) for payload with terms selecting Medication requests with linked Medication dispense (started_at + ended_at)).  

      2. if found 

        1. get $.medical_programs.medical_program_setting by medical_program_id from request

          1. validate skip_mnn_in_treatment_period variable

            1. in case skip_mnn_in_treatment_period == FALSE (or absent) 

              1. validate request according to logic:

                1. add to response: status = INVALID

                2. add to response: rejection_reason = "For the patient at the same term there can be only 1 dispensed medication request per one and the same innm!"

            2. in case skip_mnn_in_treatment_period == TRUE

              1. skip validating frequency of receiving drugs

    2. for medication_dispense.medication_request_id = $.id

      1. Validate medication request qty: sum(medication_dispenses.medication_qty) >= medication_request.medication_qty 

      2. if found

        1. add to response: status = INVALID

        2. add to response: rejection_reason = "Sum of dispense's medication quantity can not be more then medication_request.medication_qty"

...