Purpose
This WS is designed to mark in error previously created Device dispense in case it was entered in error.
Specification
Authorization
Verify the validity of access token
in case of error - return 401 (“Invalid access token”) in case of validation fails
Verify that token is not expired
in case of error - return 401 (“Invalid access token”)
Check user scopes in order to perform this action (scope = 'device_dispense:mark_in_error')
return 403 (“Your scope does not allow to access this resource. Missing allowances: device_dispense:mark_in_error”) in case of invalid scope(s)
Validations
Validate request
Return 422 with the list of validation errors in case validation fails
Validate Legal entity
Extract client_id from token
Check that legal entity:
“type” it has to be 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”
check that Legal Entity (client_id) from token == $.performer_legal_entity.identifier.value of Device Dispense
in case of error return 409 “Device dispense belongs to another legal entity“
Validate digital signature
Validate request is signed
in case of error - return 400 (“Invalid signed content”)
Check 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 transition
Get current device dispense status
Check that status != “entered_in_error” and status != “completed”
in case of error - return 409 error ('Device dispense in status <status> cannot be marked in error')
For more information look at [UPD] Device dispense status model.
Validate status
The target status value must be submitted in the order of display in the signed content (media storage)
Validate $.status is entered-in-error
in case of error - return 422 ("value is not allowed in enum")
Validate status reason
Validate $.status_reason.code is a value from device_dispense_mark_in_error_reasons dictionary
in case of error - return 422 ("value is not allowed in enum")
Validate content
Signed content must match with device dispense in DB in order to be marked in error
Render device dispense from DB
Exclude $status from signed content
Compare rendered device dispense and signed content
In case both object doesn't match - return 422 ('Signed content doesn't match with previously created device dispense')
Service logic
Save signed content to media storage
Update device dispense status to entered-in-error (update also updated_at, updated_by)
Save internal information to corresponding DB
Send
StatusChangeEvent
to the Event Manager