ЕСОЗ - публічна документація

RC_Rx_[TO BE DEPRECATED] Process Medication Dispense

Purpose

To be deprecated.

This method is designed to process previously created Medication dispense

Key points

  1. Only authenticated and authorized users of legal entity who has created Medication dispense can process Medication dispense

  2. Medication dispense can be process only from ‘NEW' status.

  3. Process should be signed with DS. So, all the Medication dispense data should be submitted.

  4. Invoke RC_Rx_[TO BE DEPRECATED] Get Medication dispense detailsarchived to obtain previously created Medication dispense. In order to process dispense payment_id (optional) and payment_amount should be added.

Specification

Apiary

Authorization

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

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

Validations

Validate digital signature

  • Validate request is signed

    • in case of error - return 400 (“document must be signed by 1 signer but contains 0 signatures”)

  • Validate that DS is valid and not expired

  • Validate that DS belongs to the user

    • Check that DRFO from DS and party.tax_id matches

      • in case of error - return 422 (“Does not match the signer drfo“)

Validate Medication dispense

  • Get Medication dispense identifier from the URL

    • Check Medication dispense exists in DB (OPS)

      • Return 404 ('not_found') in case of error

    • Check Medication dispense belongs to legal entity

      • Return 404 ('not_found') in case of error

Validate User

  • Extract user_id from token

    • Return 404 ('not_found') in case employee didn’t create medication dispense

Validate signed content

  1. Check that signed content is equal to online generated dispense with ids in DB

    1. Do not compare next fields

      • payment_amount

      • payment_id

        • in case error return 422 ("Signed content does not match to previously created dispense")

Validate transition

  • Get status of Medication dispense by $.id in OPS DB. Check that Medication dispense is in status ‘NEW’

    • in case of error - return 409 ("Can't update medication dispense status from {status} to PROCESSED")

For more information look at RC_Rx_Medication dispense status modelarchived

Validate payment_amount

  1. Check that payment_amount should be greater or equal to 0

    1. in case of error - return 422 ("expected the value to be >= 0")

Validate related Medication request

  1. Medication request should be active in order to process medication dispense

    1. is_active = true

    2. status = 'ACTIVE'

      1. In case error - return 409 ("Medication request is not active")

  2. Medication request should not be blocked in order to process medication dispense

    1. is_blocked <> true

      1. In case error - return 409 ("Medication request is blocked")

Check if related medication request has reference on the Care plan - based_on attribute filled. If it has, validate following:

  1. Care plan is not in final status.

    1. In case of error - return 409 error (Care plan is not active)

  2. Corresponding Care plan activity is not in final status.

    1. In case of error - return 409 error (Care plan activity should be scheduled or in_progress)

Service logic

  1. Save signed content to media storage

  2. Update Medication dispense data in OPS DB:

    1. set status  =  ‘PROCESSED’

    2. updated_by = user_id

    3. updated_at = now()

  3. Update related Medication request data in OPS DB:

    1. set status  =  ‘COMPLETED’

    2. updated_by = user_id

    3. updated_at = now()

  4. Write changes to event manager (Medication dispense and Medication request)

  5. Change Care plan activity (If related medication request has reference on Care plan, then corresponding care plan activity should be changed in async way after Medication dispense processed. Update activity events invokes using ops.medication_dispense_process table):

    1. Set activity status to in_progress if previous activity status was scheduled 

    2. Check the MD identifier in outcome_reference attribute of the activity:

      1. if not found:

        1. Add reference on the medication dispense resource to the outcome_reference attribute .

        2. If quantity in the activity was set then calculate and set remaining quantity:

          1. select all MD in status PROCESSED related to MR which based on care plan and current activity

          2. calculate dispensed quantity in the current activity as sum of medication_qty in the filtered MD list

          3. calculate remaining quantity by subtracting dispensed quantity from activity quantity

          4. update remaining_quantity value in the activity with calculated value

      2. If found, then skip updating activity (it means that activity has been already updated by event from current MD processing).

ЕСОЗ - публічна документація