Table of Contents |
---|
...
Get person_id from URL
Validate person status is active (status = ‘active' & is_active = 'true’)
in case of error - return 404 ('Person is not found')
If persons age is greater then no_self_registration_age global parameter, but less then person_full_legal_capacity_age global parameter, check that person does not have document with type from PERSON_LEGAL_CAPACITY_DOCUMENT_TYPES config parameter or person has document with type from PERSON_LEGAL_CAPACITY_DOCUMENT_TYPES config parameter and legal_capacity_verification_status <> VERIFIED or VERIFICATION_NOT_NEEDED
in case of error - return 422 ('Confidant can not be submitted for person who has document that proves legal capacity')
Validate request
Validate JSON Schema
...
Validate person confidants limit
Count relationships from https://e-health-ua.atlassian.net/wiki/spaces/CSIEH/pages/17613488166724729917/MPI#confidant_person_relationships table where person_id is equal to $.person_id AND is_active=true AND active_to > now() or null
Check if count from previous step is less than person_with_third_person_limit config parameter
in case of error - return 422 ('Limit of confidant persons with this person is exhausted')
...
Check if
$.confidant_person_relationship.confidant_person_id
is not equal to person_id from URLin case of error - return 422 ('Persons can not be submited as confidants for themselves')
Check if
$.confidant_person_relationship.confidant_person_id
exists in persons table (MPI DB) with status = active and is_active = truein case of error - return 422 ('Confidant person is not found')
Check if confidant person does not already exist as confidant for person using following process /wiki/spaces/CSI/pages/17667883028 with
person_id
= person from URL andconfidant_person_id
= $.confidant_person_id from request - expected:error, :not_found
responsein case of error - return 422 ('Relationship between confidant person and person already exists')
Check if confidant person itself shouldn’t be authorized by confidant - so it doesn’t correspond to following rules:
confidant persons age < no_self_registration_age global parameter;
confidant persons age between no_self_registration_age and person_full_legal_capacity_age global parameters and person does not have document with type from PERSON_LEGAL_CAPACITY_DOCUMENT_TYPES config parameter or person has document with type from PERSON_LEGAL_CAPACITY_DOCUMENT_TYPES config parameter and legal_capacity_verification_status <> VERIFIED or VERIFICATION_NOT_NEEDED;
confidant persons age > person_full_legal_capacity_age global parameter and exists at least one active and approved confidant person relationship for person (using following process /wiki/spaces/CSI/pages/17667883028 with
person_id
=$.confidant_person_id
from request - expected:ok, :approved
response)confidant person has at least one confidant person in persons.confidant_person array
in case of error - return 422 ('Person with incorrect age or with active confidant person relationship can not be submitted as confidant')
Check if confidant person cumulative verification status is not in NOT_ALLOWED_CONFIDANT_PERSON_VERIFICATION_STATUSES config parameter
in case of error - return 422 ('Person with cumulative verification status <person.verification_status> can not be submitted as confidant')
Check if confidant person has active authentication method with type = OTP where ended_at is equal to or greater than today`s date
in case of error - return 422 ('Confidant person must have active authentication method with type 'OTP' where ended_at is equal to or greater than current date.')
...
Validate documents
issued_at
dateCheck that issued_at <= now()
in case of error - return 422 ('Document issued date should be in the past')
Check that issued_at => person.birth_date
in case of error - return 422 ('Document issued date should greater than person.birth_date')
Validate document
active_to
dateCheck that active_to > now()
in case error - return 422 ('Document active_to date should be in future')
Validate document
type
according to DOCUMENT_RELATIONSHIP_TYPEdictionaryIn case of error - return 422 ('value is not allowed in enum')
Check that there are no duplicated document
type
values in requestin case of error - return 422 ('Values are not unique by 'type'.')
Validate document
number
according to regexp (as part of JSON Schema validation)BIRTH_CERTIFICATE -
^((?![ЫЪЭЁыъэё@%&$^#`~:,.*|}{?!])[A-ZА-ЯҐЇІЄ0-9№\\/()-]){2,25}$
In case of error - return 422 error ('string does not match pattern') with the corresponding regexp
Check that document
number
length < 255in case of error - return 422 ('expected value to have a maximum length of 255 but was <<document_number_length>>')
If document type contains BIRTH_CERTIFICATE or BIRTH_CERTIFICATE_FOREIGN values, check that persons age < person_full_legal_capacity_age global parameter
in case of error - return 422 ('Invalid relationship document type for person in such age')
Service logic
Search active confidant person relationship requests
To prevent overlimit and duplication of requests, search for active requests in https://e-health-ua.atlassian.net/wiki/spaces/CSIEH/pages/17613422609724271171/IL#confidant_person_relationship_requests table with person_id = person_id from URL and status = NEW.
...
Create new relationship request
Create new record to https://e-health-ua.atlassian.net/wiki/spaces/CSIEH/pages/17613422609724271171/IL#confidant_person_relationship_requests table, set values:
id = autogenerate uuid
person_id = person_id from URL
confidant_person_id =
$.confidant_person_id
confidant_person_relationship = methods request
status = NEW
action = INSERT
channel = MIS
authentication_method_current
type = OTP
phone_number = phone_number from confidant persons active auth method with type = OTP
inserted_by = user_id (from token)
inserted_at = now()
updated_by = user_id (from token)
updated_at = now()
documents_relationship = generated links for documents upload (if needed)
...