ЕСОЗ - публічна документація

RC_(CSI-1323)_Sign merge request

Purpose

This WS merges person with preperson after merge request has been signed by employee.

Specification

Apiary

Service logic

  1. Only authenticated and authorized SPECIALIST employees can use this WS.

  2. Usage of this WS allowed in EMERGENCY or OUTPATIENT legal entities.

  3. Employee should sign merge request to link person with preperson.

  4. Only request APPROVED by person can be signed.

  5. The request can be signed only by employee who made the request.

  6. Create objects in DB should be done in one transaction.

  7. Status change of the merge request and preperson should be logged in the Event manager.

  8. Succesfull merge does not create record in MPI.persons table for preperson, but deactivates record in MPI.prepersons and linked document in patient collection (mongo)

  9. Data from the field data_to_be_signed used as request data for sign method.

Authentication

  1. Verify the validity of access token

    1. Return 401 in case validation fails

  2. Check user scopes in order to perform this action (scope = 'merge_request:sign')

    1. Return 403 in case invalid scope(s)

  3. Check the employee has created this merge request. Thus select inserted_by from il.merge_requests of this merge request and compare it with user_id from the token.

  4. Check that client_id from the token maches with il.merge_requests.legal_entity_id

    1. If not match - return 422 error (User doesn’t belong to legal entity where the merge request was created)

Validate digital signature

Validate digital sign as described on sign patient request process

Check signed content

  • Check decoded signed content with previously created on IL.db.

SELECT data FROM merge_requests WHERE id = {:id}

In case if they are not equal - generate 422 error (message: "Signed content does not match the previously created content")

  • Generate data for sign and compare it with information from il.merge_requests.data

In case if they are not equal - generate 422 error (message: "Created content has been changed")

Validate schema

Validate request using schema

Validate merge request

  1. Validate merge request id exists in DB

    1. In case of error - return 404

  2. Check merge request status is APPROVED

    1. In case of error - return 422 (Incorrect status to sign merge request)

Check signed content

  1. Get previously request data from il.merge_requests.data.

  2. Compare it with request data_ to_be_signed field.

    1. In case they are not equal - return 422 error (Signed content does not match the previously created content)

  3. Check patient_signed = true. It means that person signed printout content.

    1. In case of error - return 422 error (Patient must sign merge request form).

Validate legal entity

Validate legal entity as on create merge request process.

Validate person

Validate person as on create merge request process.

Validate confidant person relationship

If authorize_with of merge request is not empty and contains auth method with type = THIRD_PERSON - validate that person from value is an approved confidant for a person from request – exists active and approved confidant person relationship between person from request and person_id from authentication method value (using following logic: Check confidant person relationship with person_id = person from request and confidant_person_id = value from auth method - expected :ok, :approved response)

  • in case of error - return 422 ‘Cannot be confirmed by method with not approved confidant person relationship’

Validate preperson

Validate preperson as on create merge request process, but w/o searching pending merge requests and episodes.

Check if preperson has at least one episode( status!= "entered_in_error")

  1. if no episodes - return 409 (Preperson has no episodes)

Save signed merge request to media storage

  1. Get url for merge request upload.

Parameter

Source

Parameter

Source

action

'GET'

bucket

'MERGE_REQUESTS'

resource_id

: MERGE_REQUEST_ID

resource_name

: MERGE_REQUEST_NAME

timestamp

:TIMESTAMP

  1. Upload signed merge request to media storage.

Create object in DB

mpi.merged_pairstable

Parameter

Source

Description

Parameter

Source

Description

id

uuid

Authogenerated, required.

master_person_id

merge_requests.master_person_id

Identifier of the person in MPI.persons, required

merge_person_id

merge_requests.merge_person_id

Identifier of the preperson in MPI.prepersons, required

inserted_at

timestamp

Get current date-time

updated_at

timestamp

Get current date-time

Update object in DB

  1. il.merge_requeststable

Parameter

Source

Description

Parameter

Source

Description

status

string

Status of the request, required. Set SIGNED

merged_pair_id

uuid

Identifier of merged pair. Get from mpi.merged_pair.id

patient_signed

bool

Evidence that person has signed the merge request. Set from Request, should be true.

updated_by

uuid

Extract user from token

updated_at

timestamp

Get current date-time

  1.  

mpi.prepersonstable

Parameter

Source

Description

Parameter

Source

Description

status

string

Status of the preperson, required. Set inactive

updated_by

uuid

Extract user from token

updated_at

timestamp

Get current date-time

  1.  

patientscollection (mongo, separate job)

Parameter

Source

Description

Parameter

Source

Description

status

string

Status of the preperson, required. Set inactive

updated_by

uuid

Extract user from token

updated_at

timestamp

Get current date-time

 

ЕСОЗ - публічна документація