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

RC-[UPD] Stop Device dispense

Purpose

This method is designed to stop previously created Device dispense

Key points

  1. Only authenticated and authorized users of legal entity who has created Device dispense can stop Device dispense

  2. Medication dispense can be rejected only from ‘IN_PROGRESS' status.

  3. Method executes in async way only.

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 = 'device_dispense:stop')

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

Validations

Validate Legal entity

  1. Extract client_id from token

    • Check that “type” in me_allowed_transactions_le_types config parameter

      • in case of error return 409 “Invalid LegalEntity type“

    • exists and has status = active

      • in case of error return 409 “client_id refers to legal entity that is not active”

Validate Device dispense

  • Get Device dispense identifier from the URL

    • Check Device dispense exists in device_dispenses (MongoDB)

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

    • Check Device dispense belongs to legal entity

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

Validate transition

Only device dispense in in_progress status can be stopped

  1. Get current device dispense status

    1. Check that status in ('in_progress')

      1. in case of error - return 409 error ('Device dispense in status %status% cannot be stopped')

For more information look at RC-[UPD] Device dispense status modelarchived.

Service logic

  1. Update Device dispense data in device_dispenses (MongoDB):

    1. set status  =  ‘stopped’

    2. updated_by = user_id

    3. updated_at = now()

  2. Send StatusChangeEvent to Event Manager

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