ЕСОЗ - публічна документація
RC_Create Device request
Purpose
This WS is designed to create Device Request
Key points
Only authenticated and authorized users with appropriate scope can invoke Create Device Request
Device Request is created in async way. Successful result of the job should return a link on the created Device Request (look at https://e-health-ua.atlassian.net/wiki/spaces/CSI/pages/17467310277/Get+Device+request+details ).
Device Request should be signed with DS. Signed content stores in the media storage.
All validations within Device request attributes should be executed by internal call of PreQualify Device request function
Device Request can be created for a person only
Medical program is optional in the Device Request
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 and client scopes in order to perform this action (scope = 'device_request:write')
return 403 (“Your scope does not allow to access this resource. Missing allowances: device_request:write”) in case of invalid scope(s)
If BLOCK_UNVERIFIED_PARTY_USERS is true, then check party's data match following condition: verification_status != NOT_VERIFIED or (verification_status = NOT_VERIFIED and updated_at > current_date - UNVERIFIED_PARTY_PERIOD_DAYS_ALLOWED):
in case not match - return 403 ("Access denied. Party is not verified")
If BLOCK_DECEASED_PARTY_USERS is true, check that party is not deceased (party_verification record does not equal to: dracs_death_verification_status = VERIFIED and dracs_death_verification_reason = MANUAL_CONFIRMED):
in case of error - return 403 ("Access denied. Party is deceased")
Validate digital signature
Validate request is signed
in case of error - return 400 (“document must be signed by 1 signer but contains 0 signatures”)
Check DS is valid and not expired
Validate that DS belongs to the requester
Check that DRFO from DS and party.tax_id matches
in case of error - return 422 (“Does not match the signer drfo“)
Validate legal entity
Extract client_id from token
Check legal entity status is ACTIVE
In case of error - return 409 ('client_id refers to legal entity that is not active')
Check legal entity type in ME_ALLOWED_TRANSACTIONS_LE_TYPES config parameter
in case of error - return 409 ('client_id refers to legal entity with type that is not allowed to create medical events transactions')
Validate Patient
Get Patient identifier from the URL
Check it exists in persons table (MPI)
Return 404 ('not found') in case of error
Validate person status is active
in case of error - return 409 ('Patient is not active')
Validate person's verification_status is not equal to NOT_VERIFIED.
in case NOT_VERIFIED - return error 409 ("Patient is not verified")
Validate request
Validate request using schema.
Invoke validations described at RC_PreQualify Device request | Validate Device requestarchived
If Device Request has a medical program, then in addition execute validations described at RC_PreQualify Device request | Validate Medical programsarchived
Service logic
Save signed content to media storage, in bucket pointed in MEDIA_STORAGE_DEVICE_REQUEST_BUCKET chart parameter
Fill in the following fields:
requisition. Generate requisition number as described at Human readable Medication request number , but based on the Device Request identifier and put it in the field.
signed_content_links. Add string item in the array with a link on saved content in media storage
status = ACTIVE
status_reason = null
subject. Set hashed patient_id from URL
requester_legal_entity. Set client_id from token
quantity.unit. Set description according to quantity code and system
dispense_valid_to. Set (current_date + dispense_period_day) if medical program was set and it has dispense_period_day setting. Otherwise, set device_dispense_period global parameter.
verification_code. Generate random 4-digit code
context_episode_id. Set episode from the $.encounter
inserted_at. Set current date and time
updated_at. Set current date and time
inserted_by. Set current user from token
updated_by. Set current user from token
Send verification code:
Determine patient's default authentication method as described at Determination of a default authentication method and return person's active auth_methods :
if OTP defined, then generate text according to TEMPLATE_SMS_FOR_CREATE_DEVICE_REQUEST and send SMS with verification_code
if OFFLINE defined - return verification_code in the
urgent
block of the response (if Create was processed synchronously).
Save data to device_requests collection in MongoDB according to RC_Device request data modelarchived
Send
StatusChangeEvent
to Event Manager
ЕСОЗ - публічна документація