Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Version published after converting to the new editor

Table of Contents

...

  1. Extract legal_entity_id (client_id) from token

Validate FK

1. Validate legal_entity_id - legal_entity_id exists

In case error - return 422 error:


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

2. Validate id - dispense.id exists

In case error - return 404 error

Validate context

  1. Only users of legal entity who has created Medication Dispense and NHS Admin can reject Medication Dispense
    1. medication_dispense.legal_entity_id = client_id (context) or client_id (context) (type) in TOKENS_TYPE_ADMIN

In case error - return 403 error (type: forbidden)

Validate status (transition)

  1. Dispense should be active in order to process it
    1. is_active = true
    2. status = 'NEW'

In case error - return 409 error (type: 'invalid_transition', message: 'Can't update medication dispense status from {status} to REJECTED')

Change dispense status

Update dispense status to REJECTED

...