Purpose
This method is designed to reject previously created Medication Dispense.
Specification
Logic
Preconditions
No
Global and configurable parameters
No
Input parameters
Input parameter | Values | Type | Description | Example |
---|---|---|---|---|
id | String | Required |
Filters
No
Request structure
API paragraph not found
Authorize
Verify the validity of access token
Return 401 in case validation fails
Check user scopes in order to perform this action (scope = 'medication_dispense:reject')
Return 403 in case invalid scope(s)
Headers
Content-Type:application/json
Validate request
Get legal entity from token
Extract legal_entity_id (client_id) from token
Validate FK
Validate
legal_entity_id - legal_entity_id exists
In case error - return 422 error:
{:error, [{%{ description: "Legal entity not found", params: [], rule: :invalid }, "$.legal_entity_id"}]}
Validate
id - dispense.id exists
In case error - return 404 error
Request data validation
Validate context
Only users of legal entity who has created Medication Dispense and NHS Admin can reject Medication Dispense
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)
Dispense should be active in order to process it
is_active = true
status = 'NEW'
In case error - return 409 error (type: 'invalid_transition', message: 'Can't update medication dispense status from {status} to REJECTED')
Parameters that are used when processing the request
Configuration parameters
Access to the method is defined by the scope medication_dispense:reject. Permission for this scope is determined by the System administrator by configuring scopes in the context of clients and roles.
Dictionaries
API paragraph not found
Processing
Change dispense status
Update dispense status to REJECTED
Parameter | Source | Description |
---|---|---|
payment_id | Request: $.payment_id or NULL | If payment_id exists in request - update record with payment_id |
status | Const: REJECTED | |
updated_at | Timestamp: now() | Get current date-time |
updated_by | Token: user_id | Extract user from token |
Response structure
See on Apiary
Example:
Post-processing processes
No
HTTP status codes
HTTP status code | Message | What caused the error |
---|---|---|
200 | Response |
|
401 | Invalid access token |
|
403 | Error |
|
404 | Error | dispense.id doesn`t exist |
409 | Error | Can't update medication dispense status from {status} to REJECTED |
422 | Error | Legal entity not found |
Backward compatibility
API paragraph not found