Table of Contents |
---|
...
- 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
...
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)
- 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 - 583403592
- 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
- If program was specified, validate that doctor is allowed to create service request with the program for the current patient
- Doctor has an active declaration with the patient in current MSP (declaration.legal_entity_id==token.client_id) OR
- Doctor works in the same MSP with doctor that has an active declaration with the patient AND doctors speciality == FAMILY_employee_type=DOCTOR
- in case of error return 409 "Doctor is not allowed to create service request with the program for the patient"
- 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 PRMOR PRM.services.category is not NULL NULL return 422 "Service category does not match with service request category"
- Select category from PRM.services where id = $.code.identifier.value
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"
...
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
- If program was specified, change program_processing_status to New
Notes
- Валидация данных из supporting info на вхождение в эпизоды, которые выбраны для организации доступов
- Валидация данных из reasonReference на вхождение:
- в эпизод, к которому относится энкаунтер, на основании которого создан реферрал
- в эпизоды, которые выбраны для организации доступов
- Валидация соответствия пациента в рецепте пациенту в энкаунтере, на основании которого создается рецепт
...