Purpose
This WS allows to link medical data of unidentified person to person in eHealth. Thus it helps person who was unidentified during some period to store all its medical history.
Specification
Service logic
Only authenticated and authorized SPECIALIST or RECEPTIONIST employees can merge prepersons with prepersons.
Prepersons can be merged in EMERGENCY or OUTPATIENT legal entities.
Employee can merge any active preperson to any active person.
To merge person with preperson only their MPI ids needed.
Change status should be logged in the Event manager.
Authentication
Verify the validity of access token
Return 401 in case validation fails
Check user scopes in order to perform this action (scope = 'preperson_merge_request:write')
Return 403 in case invalid scope(s)
Validate request
Validate request using schema (TBD)
Validate legal entity
Check that legal entity is active (status = ACTIVE, SUSPENDED)
Extract client_id from token (token.client_id == legal_entity_id)
Check legal entity status (status = ACTIVE, SUSPENDED)
In case of error - return 409 (Legal entity must be ACTIVE or SUSPENDED)
Validate person
Ensure the person exists
Validate person_id UUID
In case of error - return 422
Find person by id in mpi.persons
In case of error - return 422 (Such person doesn't exist)
Check person status is active
In case of error - return 409 (Person is not active)
Validate preperson
Ensure the preperson exists
Validate preperson_id UUID
In case of error - return 422
Check preperson_id doesn't exist in mpi.persons, but exists in medical_data.patients as patient_id. It means that preperson_id relates to preperson, but not to person.
In case of error - return 422 (Such preperson doesn't exist)
Check preperson status is active in medical_data.patients
In case of error - return 409 (Preperson is not active)
Check if exists another preperson merge requests with status NEW or APPROVED for this preperson
if exists - update status to REJECTED
Validate employee
Extract user_id and legal_entity_id from token and find corresponding employee_id
Check employee status is APPROVED
In case of error - return 422 error (Only active employee can create preperson merge request)
If employee has division - validate it has status ACTIVE
In case of error - return 422 error (Only employee of active divisions can create preperson merge request)
Save object to DB
il.person_requests table
Parameter | Source | Description |
---|---|---|
id | uuid | Autogenerated |
type | string | Set PREPERSON_MERGE_REQUEST for this type of requests. Required |
data | jsonb | Data from the request in json format. Required |
person_mpi_id | Request: person_id | Person identifier in MPI (mpi.persons.id). Required |
preperson_mpi_id | Request: preperson_id | Preperson identifier that corresponds to MPI (returned on create preperson). Required |
status | varchar(50) | Status of the request, required. Set NEW |
merged_pair_id | uuid | Reference to mpi.merged_pairs table when person becomes merged with preperson (on sign). By default is null. |
printout_form | text | Printout form of preperson merge request in html format. By default is null at this step |
legal_entity_id | Request: client_id | Legal entity where request was created. Client_id extracted from token. Required |
channel | string | By default is MIS |
authentication_method_current | jsonb | Person current authentication method. |
inserted_by | uuid | Extract user from token |
inserted_at | timestamp | Get current date-time |
updated_by | uuid | Extract user from token |
updated_at | timestamp | Get current date-time |
Generate verification code
Validate person authentication method in mpi.person_authentication_methods table:
If type is OTP or THIRD_PERSON - Generate verification code as on create patient request process. Except phone number is taken from mpi.person_authentication_methods table.