Introduction
Specification
Validations
Authorization
- Verify the validity of access token
- in case of error return 401 ('Access denied')
- Check user scope service_request:write in order to perform this action
- in case of error generate 403 response ('Invalid scopes')
Validate digital signature
Decode content that is encrypted in an electronic digital signature.
Use Digital signature WS. Method checks digital signature and returns result.
See service specification
1. Ensure that digital signature is valid
2. Validate that requester of service request is a current user
2.1. Get token metadata
- Extract user_id, client_id, client_type
2.2. Determine the party_id associated with this user_id
SELECT pu.party_id FROM party_users pu WHERE pu.user_id = :user_id;
2.3. Determine employees related to this party_id in current MSP
SELECT e.id FROM employees e WHERE e.party_id = :party_id AND e.legal_entity_id = :client_id;
2.4 Ensure that $.requester.identifier.value matches with user employees
3. Validate that DS belongs to the requester of encounter
3.1. Determine the party_id associated with requester ($.requester.identifier.value)
SELECT p.tax_id FROM employees e, parties p WHERE e.party_id = p.id AND e.id = :requester;
Validate request using JSON Schema
Return 422 with the list of validation errors in case validation fails
Validate service request
- Validate that service request ID is unique
- $.id must be unique
- in case of error return 409 - "Service request with such id already exists"
- $.id must be unique
- Requisition is a common identifier for the group of service requests and it must matches with one of the patient's episode of care number
- $.requisition must match with patient's episode of care number
- in case of error return 409 - "Incorrect requisition number"
- $.requisition must match with patient's episode of care number
- Service request category must refer to a valid dictionary
- $.category.coding[*].system == "ehealth/SNOMED/service_request_categories"
- in case of error return 409 "Incorrect service request category"
- $.category.coding[*].system == "ehealth/SNOMED/service_request_categories"
- Procedure code must refer to a valid dictionary
- $.code.coding[*].system == "ehealth/SNOMED/procedure_codes"
- in case of error return 409 "Incorrect procedure code"
- $.code.coding[*].system == "ehealth/SNOMED/procedure_codes"
- Context must be an active encounter
- $.context.identifier.type.coding[*].system == "eHealth/resources"
- $.context.identifier.type.coding[*].code == "encounter"
- $.context.identifier.value refer to existing encounter (status == 'finished')
- Occurence is a valid date-time in the future
- $.occurrenceDateTime
- $.occurrence_date_time - ISO date must be greater current date-time
- $.occurrencePeriod.start
- $.occurrence_period.start - ISO date must be greater than current date-time
- $.occurrence_period.end - ISO date must be greater than current date-time and greater than $.occurrencePeriod.start
- $.occurrenceDateTime
- Authored On is a valid date-time in the past
- $.authored_on - ISO date must be less than current date-time
- Requester must be active employee within current legal entity
- $.requester.identifier.type.coding[*].system == "eHealth/resources"
- $.requester.identifier.type.coding[*].code == "employee"
- $.requester.identifier.value refer to active employee within current legal entity (employee.status == approved and employee.is_active == true and employee.legal_entity_id == token.client_id)
- Performer type must refer to a valid dictionary
- $.performer_type.coding[*].system == "ehealth/SNOMED/service_request_performer_roles"
- in case of error return 409 "Incorrect service request category"
- $.performer_type.coding[*].system == "ehealth/SNOMED/service_request_performer_roles"
- Supporting info must refer to a valid medical events object (Episode of Care) within specified patient.
- $.supporting_info.identifier.type.coding[*].system == "eHealth/resources"
- in case of error return 409 "Incorrect supporting info"
- $.supporting_info.identifier.type.coding[*].system == "eHealth/resources"
- Reason reference must refer to a valid medical events object (Observation, Condition) within specified patient.
- $.reason_reference.identifier.type.coding[*].system == "eHealth/resources"
- $.reason_reference.identifier.type.coding[*].code in ("condition", "observation")
- in case of error return 409 "Incorrect reason reference"
- Permitted Episode of care must refer to a valid medical events object (Episode of Care) within specified patient.
- $.permitted_episodes.identifier.type.coding[*].system == "eHealth/resources"
- $.permitted_episodes.identifier.type.coding[*].code == "episode_of_care"
- in case of error return 409 "Incorrect reason reference"
- Validate permited peisodes as references - Create Service Request V2
- Validate that permitted episodes is not specified in case of category "laboratory"
- in case of error 422 "Permitted episodes are not allowed for laboratory category of service request"
- Validate expiration_date is in future
- in case of error return 422 "Expiration date can not be in past"
Reference validation
- Validate that $..identifier.value is an existing value from $..identifier.type.coding[0].code collection in DB and it belongs to the patient
- in case of errror return 422 "There is no {$..identifier.type.coding[0].code} with such id"
- Validate that this entity is not in status entered_in error
- in case of errror return 422 "Could not reference entity in status entered_in_error"
Example:
1 2 3 4 5 6 7 8 9 10 11 12 | "identifier" : { "type" : { "coding" : [ { "system" : "eHealth/resources" , "code" : "episode_of_care" } ] }, "value" : "9183a36b-4d45-4244-9339-63d81cd08d9c" } } |
In this case validate that "9183a36b-4d45-4244-9339-63d81cd08d9c" is an existing episode_of_care
from patients collection and it is not entered_in_error.
Service logic
- Generate requisition number (see Human readable Service request requisition number)
- Save signed content to media storage
- Save data to corresponding collection in DB
- Save link to the signed content in service request storage
Notes
- Валидация данных из supporting info на вхождение в эпизоды, которые выбраны для организации доступов
- Валидация данных из reasonReference на вхождение:
- в эпизод, к которому относится энкаунтер, на основании которого создан реферрал
- в эпизоды, которые выбраны для организации доступов
- Валидация соответствия пациента в рецепте пациенту в энкаунтере, на основании которого создается рецепт