Table of Contents |
---|
Purpose
This WS allows to create Care plan with activities for a single patient.
...
Only authenticated and authorized DOCTOR or SPECIALIST with appropriate speciality pointed in config can create a Care plan.
Care plan can be created from MSP, PRIMARY_CARE or OUTPATIENT legal entity.
Care plan can be created for persons and prepersons.
Care plan should be signed with DS.
Care plan creates in async way as all MEs.
Activities are added to a Care plan using Create Care Plan activities method. Thus, Care plan is being initially created without activities.
...
Get patient_id from URL
Validate person\preperson status is active
in case of error - return 409 ('Person is not active')
Validate person'sverification_status is not equal to NOT_VERIFIED.
in case of error return 409, "Patient is not verified"
Hash patient_id and store into the field $.subject
...
Extract user_id from token. Check that author belongs to one of the user’s employee.
in case of error - return 422 ('User is not allowed to create care plan for the employee')
Check that author is an active and approved employee and related to the legal entity (client_id from token).
in case of error - return 403 ('Access denied')
Check author’s employee type:
if SPECIALIST:
Сheck it has at least one employee role that:
is active and has active status
refers to healthcare service with providing_conditions=$.terms_of_service value
in case of error - return 422 ('Employee does not have active role that correspond to the submitted terms of service')
If DOCTOR, then no additional validations needed
Check author’s speciality (speciality_officio == true) pointed in config for a corresponding care plan category.
in case of error - return 409 (“Invalid employee speciality”)
...
Check the value is valid reference on encounter resource
Check encounter is active (status is not entered_in_error)
in case of error - return 422 ('Encounter in "entered_in_error" status can not be referenced')
Check encounter belongs to patient ($.subject)
in case of error - return 422 ('Encounter with such id is not found')
Validate primary diagnosis Condition in the Encounter:
Check condition codes is in allowed condition code list for the care plan’s category (chart variables in config)
in case of error - return 422 ('Primary diagnosis condition code and care plan category mismatch')
Check the condition system/codes has strict match with the value in the Addresses field
in case of error - return 422 ('Primary diagnosis condition codes do not match with codes in addresses') in case condition code in addresses is not the same as in the encounter diagnosis.
Validate Episode related to the Encounter:
exists
in case of error - return 422 ('Encounter refers to episode that does not exist')
is active
in case of error - return 422 ('Encounter refers to episode that is not active')
it’s managing organization matches with author’s legal entity (client_id)
in case of error - return 422 ('Encounter is from another legal entity')
...
Validate value in the field $.inform_with, if if submitted:
If $.auth_method_id is specified
Check authentication method:
is exist in MPI.person_authentication_method
is belong to patient (MPI.person_authentication_method.person_id = $.patient_id)
is active (MPI.person_authentication_method.ended_at > now() and MPI.person_authentication_method.is_active = true)
in case of any validations fails generate error: 422, "Authentication method doesn't exist, is inactive is inactive or does not belong to this person"
If Create Care Plan doesn't have this field, then choose that method which is returned from mpi as
...
Generate requisition number (see Human readable requisition number) based on the care plan id
Set care plan attribute $.requisition
...
Save signed content to media storage
Save data to care_plans collection in DB according to https://e-health-ua.atlassian.net/wiki/spaces/MRIN/pages/1957363797/Care+plan+data+model+EN
Save link from media storage to the $.signed_content_links field in care plans collection
Create job and return it’s id.
...
If patient not a preperson and his 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.
...