Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Child pages (Children Display)

Specification 

Apiary

Purpose

...

Child pages (Children Display)

Specification 

Apiary

Purpose

This WS is designed to qualify Medication request (post) - check the ability of using Medication request within the Medication program.

Input parameters (filters)

...

  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)

    in

    _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 the medical program has no setting skip_dispense_division_dls_verify or it is set in false/null validate:

    • Check $.division.dls_verify == true:

      • In case of error - return 409 "

    Division is not verified in DLS"
      • Invalid division dls status"

    else if skip_dispense_division_dls_verify = true, then skip license verification for the division

  5. Check division participates in submitted programs. Validate Provision for each Medical Program:

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

      1. if medical program in the request has funding_source one of NHS, LOCAL

        1. In case of error - return status=INVALID for a program, rejection_reason="Program was configured incorrectly. Either incorrect source of funding or option skip_contract_provision_verify"

      2. provision exist and active for the division:

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

      3. if medical program in the request has funding_source = NHS:

        1. provision relates to the actual reimbursement contract: contract.start_date <= current_date <= contract.end_date, is_active = true, status = VERIFIED, contracts.type==reimbursement, contracts.contractor_legal_entity_id=token.client_id, contracts.medical_program_id==$.medical_program_id

          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. contract is_suspended = false

          1. in case of error - return status=INVALID for a program, rejection_reason="Contract with number <contract_number> is suspended"

      4. if medical program in the request has funding_source = LOCAL, then check medical_program_provision.msp_legal_entity_id = medication_request.legal_entity_id

        1. in case of error - return status=INVALID for a program, rejection_reson = "Medical program can not be provided for the legal entity specified in the medication request"

    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 status=INVALID for a program, rejection_reason = 'Division does not have active licenses to provide the medical program'

...

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

  2. 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)
    

  3. 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 skip_treatment_period variable

            1. in case skip_mnn_in_treatment_period skip_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 skip_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"

...