ЕСОЗ - публічна документація
DEPRECATED - Create Service Request V2
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 Legal Entity Type
Validate legal entity from token: legal_entities.type should be in me_allowed_transactions_le_types and legal_entities.status =='active'
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"
- Validate code as a Reference(service_group/service)
- Validate that service or group submitted as a code has request_allowed==true
- Validate category, in case service was submitted as a code
- if service.code.identifier.type.coding[].code=="service" than service.code.identifier should reference service from PRM.services where category is empty or equal to service.category
- 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, employee_type=DOCTOR OR SPECIALIST)
- Requester is one of current user's employee
- in case of error return 422 "User is not allowed to create service request for the employee"
- 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 - DEPRECATED - Create Service Request V2#Referencevalidation
- 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"
- Validate code is an existing service or service group that is allowed to be used in service_request
- in case not found or is_active == false return 422 "Service(Service group) not found"
- if request_allowed==false return 422 "Service request is not allowed for this service(service_group)"
- If program was specified, validate it is an existing service program (type=service)
- in case not found or is_active==false return 422 "Program not found"
- in case type!= service return 422 "Invalid program type"
- If program was specified, validate that service(or service_group) is an active member of the program
- Select request_allowed, is_active from PRM.program_services where service_id(or group_id) == $.signed_content.code.identifier.value and program_id=$.program.identifier.value
- if not found or is_active==false return 422 "Service is not included in the program"
- if request_allowed==false return 422 "Service request is not allowed for this service(service_group) in this programm"
- Select request_allowed, is_active from PRM.program_services where service_id(or group_id) == $.signed_content.code.identifier.value and program_id=$.program.identifier.value
- Validate service category is equal to service request category in case service was defined as a code (not a service_group)
- Select category from PRM.services where id = $.code.identifier.value
- if PRM.services.category!=$.category OR PRM.services.category is not NULL return 422 "Service category does not match with service request category"
- if PRM.services.category!=$.category OR PRM.services.category is not NULL return 422 "Service category does not match with service request category"
- Select category from PRM.services where id = $.code.identifier.value
- Validate if patient_id belongs to preperson (has MPI.prepersons record) and service request category = "transfer of care".
- in case of another category for preperson - return 422 (Category of service request is not allowed for prepersons)
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 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
- If program was specified, change program_processing_status to New
Notes
- Валидация данных из supporting info на вхождение в эпизоды, которые выбраны для организации доступов
- Валидация данных из reasonReference на вхождение:
- в эпизод, к которому относится энкаунтер, на основании которого создан реферрал
- в эпизоды, которые выбраны для организации доступов
- Валидация соответствия пациента в рецепте пациенту в энкаунтере, на основании которого создается рецепт
ЕСОЗ - публічна документація