Purpose
This algorithm is used to create relationship between Confidant Person and Related Person and save it to the table https://e-health-ua.atlassian.net/wiki/spaces/EH/pages/17525997633/RC+MPI#confidant_person_relationships .
This algorithm is currently used by following WS:
TRUSTED PIS. Confidant patient sign-up
PIS. Confidant patient sign-up registration
Sign person request
Key points
This procedure uses dataset data to store relationship between two persons from mpi database to confidant_person_relationships and save documens that prove relationship to confidant_person_relationship_documents.
This procedure can be used in different processes and is not limited to specific process.
Specification
Validate confidant person
Check if confidant_person_id is not already stored as person_id in confidant_person_relationships table
in case of error - return 422 ('Patient who has confidant person can not be used as confidant for other patients')
Validate newness of relationship
Call Check confidant person relationship to check if relationship is already exists
in case of error - return 422 ('Relationship between confidant patient and related patient already exists')
Service logic
Create relationship between two persons to confidant_person_relationships table where:
confidant_person_id = $.confidant_person_id
person_id = $.person_id
is_active = true
verification_status = $.verification_status
verification_reason = $.verification_reason
inserted_by = $.inserted_by
updated_by = $.updated_by
active_to = $.active_to (only if active_to is presented in the input parameters, else - leave field empty)
For each item in the confidant_person_relationship_documents array save it to confidant_person_documents table where:
confidant_person_relationship_id = relationship.id
type = $.confidant_person_relationship_documents[i].type
number = $.confidant_person_relationship_documents[i].number
issued_at = $.confidant_person_relationship_documents[i].issued_at
issued_by = $.confidant_person_relationship_documents[i].issued_by
inserted_by = $.inserted_by
updated_by = $.updated_by