ЕСОЗ - публічна документація
[DRAFT] Create Service request [API-007-010-001-0307]
https://e-health-ua.atlassian.net/wiki/spaces/EN/pages/17591304241 (remove the link block before publishing the document)
- 1 Properties of a REST API method document
- 2 Purpose
- 3 Logic
- 3.1 Service logic
- 4 Configuration parameters
- 5 Dictionaries
- 6 Input parameters
- 7 Request structure
- 8 Headers
- 9 Request data validation
- 10 Authorize
- 11 Processing
- 12 Response structure examples
- 13 HTTP status codes
- 14 Post-processing processes
- 15 Technical modules where the method is used
Properties of a REST API method document
Document type | Метод REST API |
---|---|
Document title | [Document status] REST API [Назва методу] [ID методу] |
Guideline ID | GUI-0011 |
Author | @ |
Document version | 1 |
Document status | DRAFT |
Date of creation | ХХ.ХХ.ХХХХ (дата фінальної версії документа – RC або PROD) |
Date of update | ХХ.ХХ.ХХХХ (дата зміни версії) |
Method API ID | API-007-010-001-0307 |
Microservices (namespace) | ME |
Component | Service request |
Component ID | COM-007-010 |
Link на API-специфікацію | |
Resource | {{host}}/api/patients/{{patient_id}}/service_requests |
Scope | service_request:write |
Protocol type | REST |
Request type | POST |
Sync/Async | Async(def)/Sync |
Public/Private | Public |
Purpose
This method must be used to register new Service Request in the eHealth.
Logic
This method must be used to register new Service Request in the eHealth. Method receives signed message (pkcs7) that consists of signed content, digital signature and signer public key. All signature fields will be validated (including signer certificate authority). Service will store signed copy of Service Request in Media Content Storage if all checks is passed.
Signed content consists of JSON object with Service Request data.
It can be processed in both sync and async methods depends on Server decision.
Service logic
Generate requisition number (see Human readable requisition number) based on encounter id
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
If quantity was set:
Fill $.quantity.unit as description of corresponding $.quantity.code from $.quantity.system dictionary
Fill $.remaining_quantity = $.quantity.
If the service request is based on activity with quantity:
recalculate and set remaining_quantity for the activity as described RC_REHAB_PreQualify Service Request+
Configuration parameters
Description of the configuration parameters that are used when processing a request in the system
Dictionaries
Service Request Dictionaries and configurable parameters
Input parameters
Input parameter | Mandatory | Type | Description | Example | |
---|---|---|---|---|---|
1 | patient_id |
| String | Unique patient identifier |
|
Request structure
See on Apiary
See on API-specification
Headers
Key | Value | Mandatory | Description | Example | |
---|---|---|---|---|---|
1 | Content-Type | application/json | M | Тип контенту | Content-Type:application/json |
2 | Authorization | Bearer {token} |
|
| Authorization:Bearer {token} |
3 | api-key | {secret} |
|
| api-key: {secret} |
Request data validation
Authorize
Verify the validity of access token
Return 401 ('Unauthorized') in case of validation fails
Verify that token is not expired
in case of error - return 401 ('Unauthorized')
Check user scopes in order to perform this action (scope = 'service_request:write')
Return (403, 'invalid scopes') 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")
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
Ensure that digital signature is valid
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
WHERE pu.user_id = :user_id;
AND e.legal_entity_id = :client_id; |
2.4 Ensure that $.requester.identifier.value matches with user employees
Validate that DS belongs to the requester of encounter Service request
3.1. Determine the party_id associated with requester ($.requester.identifier.value)
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"
Requisition is a common identifier for the group of service requests and it must matches with one of the patient's encounter number
$.requisition must match with patient's encounter number
in case of error return 409 - "Incorrect requisition 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"
in case service was defined as a code (not a service_group) validate service_request.category=service.category from $code.identifier.value
in case error return 422, "Category mismatch"
if category in (hospitalization, transfer_of_care), do not validate service_request.category=service.category from $code.identifier.value
If $.specimens attribute is set, then check the category is in SPECIMEN_SERVICE_REQUEST_ALLOWED_CATEGORIES chart parameter
in case of error - return 422 ("Service request category is not allowed for specimens")
If $.requester_employee has ASSISTANT type, then check the category in ASSISTANT_SERVICE_REQUEST_ALLOWED_CATEGORIES chart parameter
in case of error - return 422 (“Service request category is not allowed for a requester_employee with type ASSISTANT“)
Service request code must refer to a valid dictionary
$.code.identifier.type.coding[*].system == “eHealth/resources”
in case of error return 422 “value is not allowed in enum”
Patient must be active
$.patient.identifier.type.coding[*].system == "eHealth/resources"
$.patient.identifier.type.coding[*].code == "patient"
$.patient.identifier.value refer to active MPI (is_active == true and status == 'active')
check if patients.preperson == true
check PREPERSON_SERVICE_REQUEST_ALLOWED_CATEGORIES (values from dictionary: eHealth/SNOMED/service_request_categories) configuration according allowed categories for prepersons
in case of error return 422 (Category of service request is not allowed for prepersons)
Context must be an active encounter
If focus on specimens is set, then context is optional
$.context.identifier.type.coding[*].system == "eHealth/resources"
$.context.identifier.type.coding[*].code == "encounter"
$.context.identifier.value refer to existing encounter (status == 'finished')
if category = transfer_of_care,
validate encounter.hospitalization.Discharge_Disposition='transfer_general', in case error return 422, "Context is not valid for service request with type $type"
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
in case based_on passed in request
if care plan activity has detail.scheduled_timing.repeat.bounds_period - validate occurence within bounds_period
if care plan activity has detail.scheduled_period - validate occurence within scheduled_period
else - validate occurence within care_plan.period
Authored On is a valid date-time in the past
$.authored_on - ISO date must be less than current date-time
Requester_employee must be active employee within current legal entity
$.requester_employee.identifier.type.coding[*].system == "eHealth/resources"
$.requester_employee.identifier.type.coding[*].code == "employee"
$.requester_employee.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 and employee.type=value from list of employee_types in configuration: ALLOWED_SERVICE_REQUEST_REQUESTER_EMPLOYEE_TYPES )
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"
Requester_legal_enity must be current legal enity
Supporting info must refer to a valid medical events object (Episode of Care, Condition, Observation, Diagnostic report) within specified patient.
$.supporting_info.identifier.type.coding[*].system == "eHealth/resources"
in case of error return 409 "Incorrect supporting info"
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 resources must refer to a valid medical events object (Episode of Care, diagnostic report) within specified patient.
$.permitted_resources.identifier.type.coding[*].system == "eHealth/resources"
$.permitted_resources.identifier.type.coding[*].code == "episode_of_care", “diagnostic_report”
in case of error return 409 "Incorrect permitted resources"
Validate that permitted episodes is not specified in case of category "laboratory_procedure"
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
Note. For service_request.code pass "service", "service_group"in case not found or is_active == false return 422 "Service(Service group) not found"
if request_allowed==false return error 422 "Request is not allowed for this service"
in case based_on passed in request
If service_requests.code.identifier.value is service, validate $based_on[].activity.code.identifier.value = service_requests.code.identifier.value
in case error return 409, "Service in care plan activity differ from service in service request"
If service_requests.code.identifier.value is service_group, validate $based_on[].activity.code.identifier.value = service_requests.code.identifier.value
in case error return 409, "Service group in care plan activity differ from service group in service request"
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"
check if medical_programs.medical_program_settings.care_plan_required == true:
the request should contain a based_on with care plan and activity that contains the same medical program
in case of error return 422 with msg ("Care plan and activity with the same program should be present in request")
check that program present in request
in case of error return 422 with msg ("Program from activity should be present in request")
check that program equal to $.activity[].program
in case of error return 422 with msg ("Program from activity should be equal to program from request")
if program in service request is set check if $.activity[].program is not null
in case of error return error msg (“Program should not be present in request for this activity“)
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"
Validate performer
If focus on specimens is set, then performer is optional
if category = transfer_of_care,
performer is sent, in case error return 422, "performer is mandatory for category `transfer_of_care`"
performer is real LE with status=Active and is_Active=true, in case error, return 422, "performer is not active legal entity"
if category = laboratory_procedure,
performer is optional; if is send - performer is real LE with status=Active and is_Active=true, in case error, return 422, "performer is not active legal entity"
else other category and performer is send return 422 error $.performer.identifier.value “Not allowed for this category“
validate LocationReference
if category = transfer_of_care,
LocationReference is real division with type in (CLINIC, LICENSED_UNIT,AMBULANT_CLINIC,FAP) and status=Active and is_active=true, in case error return 422, "LocationReference is not an active division"
LocationReference division.legal_entity_id=Performer, in case error return 422, "Division does not belong to performer legal entity"
Validate PerformerType
if category = hospitalization
PerformerType is sent, in case error return 422, "PerformerType is mandatory for category hospitalization"
PerformerType is a code from dictionary.SPECIALITY_TYPE and match config file 'SERVICE_REQUEST_HOSPITALIZATION_SPECIALITY_TYPES', in case error return 422, "PerformerType=$PerformerType is forbidden for category hospitalization"
if performer_type value is included in chart variables 'SERVICE_REQUEST_PERFORMER_TYPE_SPECIALITY_TYPES':
define allowed service codes for service_requests.code.identifier.value using a set of chart variables 'SERVICE_REQUEST_<SPECIALITY_TYPE>_PERFORMER_TYPE_CODES', in case of error return 422 “Service does not correspond to performer's speciality for hospitalization“
if category = transfer_of_care
if service codes for service_requests.code.identifier.value using a set of chart variables 'SERVICE_REQUEST_TRANSFER_OF_CARE_<SPECIALITY_TYPE>_PERFORMER_TYPE_CODES', performer_type field is mandatory
in case error return 422, "PerformerType is mandatory"
PerformerType is a code from dictionary.SPECIALITY_TYPE and match config file 'SERVICE_REQUEST_TRANSFER_OF_CARE_SPECIALITY_TYPES', in case error return 422, "PerformerType=$PerformerType is forbidden for category transfer_of_care"
if performer_type value is included in chart variables 'SERVICE_REQUEST_TRANSFER_OF_CARE_PERFORMER_TYPE_SPECIALITY_TYPES':
define allowed service codes for service_requests.code.identifier.value using a set of chart variables 'SERVICE_REQUEST_TRANSFER_OF_CARE_<SPECIALITY_TYPE>_PERFORMER_TYPE_CODES', in case of error return 422 “Service does not correspond to performer's speciality for transfer of care“
else other category and PerformerType is send return 422 error $.performer_type.coding[0].value "Not allowed for category <category>"
Validate quantity as described in PreQualify Service Request
Validate based_on as described in PreQualify Service Request
Validate patient's verification status:
If SR has based_on with valid activity, then skip this validation.
Else check patient's verification_status is not equal to NOT_VERIFIED.
in case of error return 409, "Patient is not verified"
Validate specimens as described at PreQualify Service Request
Validate focus as described at PreQualify Service Request
Processing
Send SMS notification
If patient's default authentication method determined by Determination of a default authentication method and return person's active auth_methods is OTP or third_person.OTP, send SMS to that patient with requisition number
In order to optimize the costs, only one sms should be sent within one encounter. So that send sms only for the first service request for specific encounter
Do NOT send sms in case performer is present
Search for service requests with the same requisition number
if there is at least one service request with such number - do not send sms
if no service requests found - send sms to the patient
Response structure examples
See on Apiary
See on API-specification
HTTP status codes
Response code | HTTP Status code | Message | Internal name | Description | |
---|---|---|---|---|---|
1 | Базові | ||||
2 |
| 201 | Response |
|
|
3 |
| 202 | Response |
|
|
4 |
| 403 | Access denied. Party is not verified |
|
|
5 |
| 403 | Invalid scopes |
|
|
6 |
| 409 |
| Validation failed |
|
7 |
| 409 | Incorrect service request category |
|
|
8 |
| 409 | Incorrect requisition number |
|
|
9 |
| 409 | Incorrect supporting info |
|
|
10 |
| 409 | Incorrect reason reference |
|
|
11 |
| 409 | Incorrect permitted resources |
|
|
12 |
| 409 | Patient is not verified |
|
|
13 |
| 409 | Service request with such id already exists |
|
|
14 |
| 409 | Service in care plan activity differ from service in service request |
|
|
15 |
| 409 | Service group in care plan activity differ from service group in service request |
|
|
16 |
| 422 | Category of service request is not allowed for prepersons |
|
|
17 |
| 422 | Context is not valid for service request with type $type |
|
|
18 |
| 422 | Category mismatch |
|
|
19 |
| 422 | Care plan and activity with the same program should be present in request |
|
|
20 |
| 422 | Division does not belong to performer legal entity |
|
|
21 |
| 422 |
| Validation failed |
|
22 |
| 422 | Expiration date can not be in past |
|
|
23 |
| 422 | Invalid program type |
|
|
24 |
| 422 | Program not found |
|
|
25 |
| 422 | Program from activity should be present in request |
|
|
26 |
| 422 | Program from activity should be equal to program from request |
|
|
27 |
| 422 | PerformerType is mandatory for category hospitalization |
|
|
28 |
| 422 | performer is mandatory for category `transfer_of_care` |
|
|
29 |
| 422 | performer is not active legal entity |
|
|
30 |
| 422 | $.performer.identifier.value “Not allowed for this category“ |
|
|
31 |
| 422 | $.performer_type.coding[0].value "Not allowed for category <category> |
|
|
32 |
| 422 | PerformerType is mandatory |
|
|
33 |
| 422 | PerformerType=$PerformerType is forbidden for category transfer_of_care |
|
|
34 |
| 422 | Request is not allowed for this service |
|
|
35 |
| 422 | Service does not correspond to performer's speciality for hospitalization |
|
|
36 |
| 422 | Service does not correspond to performer's speciality for transfer of care |
|
|
37 |
| 422 | Service is not included in the program |
|
|
38 |
| 422 | Service request is not allowed for this service(service_group) in this program |
|
|
39 |
| 422 | Service request category is not allowed for specimens |
|
|
40 |
| 422 | Service request category is not allowed for a requester_employee with type ASSISTANT |
|
|
41 |
| 422 | Service(Service group) not found |
|
|
42 |
| 422 | User is not allowed to create service request for the employee |
|
|
43 |
| 422 | value is not allowed in enum |
|
|
44 | Специфічні | ||||
45 |
|
|
|
|
|
Post-processing processes
Description of actions performed on data after processing
Technical modules where the method is used
List of pages describing technical modules where the method is used
ЕСОЗ - публічна документація