Purpose
This process gets certificates data of specific person from the DRACS registry through Trembita exchange gateway and uses it for further comparison with person.
Key points
This process uses cron parameter to configure its start time.
This process is used to obtain all cerificates of specified type of person from DRACS registry.
This process is used to verify persons legal capacity (by documents with type MARRIAGE_CERTIFICATE, DIVORCE_CERTIFICATE).
This process gets limited amount of persons for synchronization with DRACS certificates registry.
This process uses Oban job processing library as jobs management tool.
Configuration
Value | Description | Example |
---|---|---|
DRACS_CERTIFICATES_PERSONS_SYNCHRONIZATION_SCHEDULE | Cron parameter, represents start time of Persons synchronization with DRACS certificates registry process |
|
DRACS_CERTIFICATES_PERSONS_SYNCHRONIZATION_BATCH_SIZE | Size of Persons list that will be synchronized online with DRACS certificates registry |
|
Service logic
Step 1. Prepare list of Persons to be synced
Get the list of active Persons (status=active, is_active=true) who meet the following criteria:
mpi.person_verifications.legal_capacity_verification_status = VERIFICATION_NEEDED and legal_capacity_verification_reason = ONLINE_TRIGGERED
Order selected records in descending way by person_verifications.updated_at
Update person_verifications record by person_id:
legal_capacity_verification_status = IN_REVIEW
legal_capacity_verification_reason = AUTO_ONLINE
Step 1.1. Update Person
Make data pre-estimation for a synchronization:
If a person has no certificate document that can be synched (MARRIAGE_CERTIFICATE or DIVORCE_CERTIFICATE) at all, then update person_verifications record by person_id:
legal_capacity_verification_status = VERIFICATION_NOT_NEEDED
legal_capacity_verification_reason = AUTO_DATA_ABSENT
legal_capacity_entity_id = null
legal_capacity_entity_type = null
legal_capacity_unverified_at = null
If a person has both legal capacity documents that can be synched (MARRIAGE_CERTIFICATE and DIVORCE_CERTIFICATE), then use legal capacity document with greater issued_at date for corresponding steps
if both documents have the same issued_at date - use DIVORCE_CERTIFICATE data for the corresponding steps;
If a person has legal capacity document that can be synched (MARRIAGE_CERTIFICATE or DIVORCE_CERTIFICATE) but document number can not be parsed into separate
serial
andnumber
fields using rules: number – get only digits from the end of the documents.number, serials – get everything else from documents.number (without digits for number), then update person_verifications record by person_id:legal_capacity_verification_status = NOT_VERIFIED
legal_capacity_verification_reason = AUTO_INCORRECT_DATA
legal_capacity_entity_id = null
legal_capacity_entity_type = null
legal_capacity_unverified_at = now()
Step 2. Get Person certificate from DRACS
Check person’s certificate – invoke RPC call with third-party GetCertByNumRoleNames service using the following request params:
ByParam - based on persons legal capacity document:
if person has MARRIAGE_CERTIFICATE = set 4
if person has DIVORCE_CERTIFICATE = set 5
Role - based on persons gender and legal capacity document:
if persons gender in FEMALE and person has MARRIAGE_CERTIFICATE = set 2
if persons gender is MALE and person has MARRIAGE_CERTIFICATE = set 3
if persons gender in FEMALE and person has DIVORCE_CERTIFICATE = set 6
if persons gender is MALE and person has DIVORCE_CERTIFICATE = set 5
CertNumber = get only digits from the end of the documents.number
CertSerial = get everything else from documents.number (without digits for CertNumber)
Surname = mpi.persons.last_name
Name = mpi.persons.first_name
Patronymic = mpi.persons.second_name (skip if empty)
Step 3. Prepare obtained certificates
If GetCertByNumRoleNames call in Step 2 was successful and ResultCode = 0, parse obtained XML file and form certs list.
Get only active certificates (with CertStatus = 1
), skip records with any other status.
If marriage certs were requested (ByParam = 4), save each cert from formed list to dracs_marriage_certs table in transaction according to fields matching:
For each certificate validate duplicates - check existence of marriage certificate in dracs_marriage_certs table with following conditions: cert_serial = CertSerial and cert_number = CertNumber and cert_status = CertStatus and ar_numb = AR_NUMB and ar_composedate = AR_COMPOSEDATE
in case not found - insert new marriage certificate record to dracs_marriage_certs table, also add technical data:
set id = autogenerate uuid
set inserted_at = now()
set updated_at = now()
in case found - do not insert marriage certificate, use existing record for next steps.
If divorce certs were requested (ByParam = 5), save each cert from formed list to dracs_divorce_certs table in transaction according to fields matching:
For each certificate validate duplicates - check existence of divorce certificate in dracs_divorce_certs table with following conditions: cert_serial = CertSerial and cert_number = CertNumber and cert_status = CertStatus and ar_numb = AR_NUMB and ar_composedate = AR_COMPOSEDATE
in case not found - insert new divorce certificate record to dracs_divorce_certs table, also add technical data:
set id = autogenerate uuid
set inserted_at = now()
set updated_at = now()
in case found - do not insert divorce certificate, use existing record for next steps.
Step 3.1. Technical error returned
In case GetCertByNumRoleNames ResultCode <> 0 or connection error or timeout is occured - check that persons legal_capacity_verification_status = ‘IN_REVIEW’
if true - rollback it in person_verifications table in MPI db for person_id to previous state
if false - skip this person, go to next person in list.
Step 4. Verify Persons legal capacity
Check that person_verifications.legal_capacity_verification_status equals to IN_REVIEW (because if changed to any other status, then its mean that person record has been changed while current sync with DRACS certificates performed, or person should not be synchronized by DRACS certificates):
if equals – invoke this Step.
if not equal – skip this Step, go to Step 5.
In case no active marriage or divorce certificate for a person was found, update person_verifications table in MPI db for person_id, set values:
legal_capacity_verification_status = NOT_VERIFIED
legal_capacity_verification_reason = AUTO_NOT_FOUND
legal_capacity_entity_id = null
legal_capacity_entity_type = null
legal_capacity_unverified_at = now()
In case active marriage or divorce certificate for a person was found:
Update person_verifications table in MPI db for person_id, set values:
legal_capacity_verification_status = VERIFIED
legal_capacity_verification_reason = AUTO_ONLINE
legal_capacity_entity_id = dracs_marriage_certs.id or dracs_divorce_certs.id
legal_capacity_entity_type = ‘dracs_marriage_cert’ or ‘dracs_divorce_cert’
legal_capacity_unverified_at = null
Deactivate all existing confidant person relationships for person_id:
Deactivate all records in https://e-health-ua.atlassian.net/wiki/spaces/CSI/pages/17613422609/IL#confidant_person_relationship_requests table where person_id =
person.id
and status = NEW, set values:status = CANCELLED
updated_at = now()
updated_by = system user_id
Deactivate all records in https://e-health-ua.atlassian.net/wiki/spaces/CSI/pages/17613488166/MPI#confidant_person_relationships table where person_id =
person.id
and is_active = true. Set:active_to = now()
updated_at = now()
updated_by = system user_id
For each relationship from previous step - deactivate person authentication methods with type = THIRD_PERSON and value =
confidant_person_relationships.confidant_person_id
, set values:ended_at = now()
updated_at = now()
updated_by = system user_id
Step 5. Select next Person
Select the next person from the obtained list and return to Step 2 of the process.
in case no more persons are available - end the process.