Purpose
This process gets divorce acts data from the DRACS registry through Trembita exchange gateway, saves it to dracs_divorce_acts table and prepares them for comparison processes.
Key points
This process uses cron parameter to configure its start time.
This process is used to obtain newest divorce act records as well as older historical divorce acts from DRACS registry.
This process uses Oban job processing library as jobs management tool.
Configuration
Value | Description | Example |
---|---|---|
DRACS_DIVORCE_ACTS_SYNC_SCHEDULE | Cron parameter, represents start time of divorce acts synchronization with DRACS registry process |
|
DRACS_DIVORCE_ACTS_SYNC_PERIOD_START | Start date from which historic divorce acts must be obtained in “yyyy-mm-dd” format |
|
DRACS_DIVORCE_ACTS_STATUS_UPDATE_DAYS | Parameter in days when existing divorce acts must be updated with DRACS registry again |
|
Service logic
1. Define act dates to be synchronized
Check the need to create divorce acts DailySynchronization job according to dracs_divorce_acts_period_updates table (MIMIR db):
Make list of all distinct dates from date in range from DRACS_DIVORCE_ACTS_SYNC_PERIOD_START to now_date() - 1 day
Exclude all dates that has been already updated with updated_at > now() - DRACS_DIVORCE_ACTS_STATUS_UPDATE_DAYS value
Exclude all dates that are currently being updated by divorce acts daily synchronization job in oban_jobs table with state = ‘available’, ‘executing’, ‘retryable’
Create Divorce act DailySynchronization jobs in oban_jobs table for each date in descending order (newer dates should be synchronized first with DRACS registry) from formed list with following arguments (stored in oban_jobs.args field):
args.date_from = ‘date_from_list’
args.date_to = ‘date_from_list’
2. Request data from Trembita
Perform GetDivorceArByRegDatePeriod DRACS method (described https://e-health-ua.atlassian.net/wiki/spaces/DRACS2/pages/17858101249/UPD+DRACS+Trembita+methods#GetDivorceArByRegDatePeriod) with following params:
DateFrom = args.date_from
DateTo = args.date_to
Get ResultData field from method's response and decode it from base64 to get XML file of divorce act records list.
Parse obtained XML file and form a divorce acts list.
3. Save data to MIMIR database
Save each divorce act from the formed list into dracs_divorce_acts table in transaction according to fields matching (located in the table below):
For each divorce act validate duplicates - check existence of divorce act in dracs_divorce_acts table with following conditions:
ar_reg_date = ArRegDate and ar_reg_number = ArRegNumber
in case not found and
ar_op_name = 1 or 4
- insert new divorce act to dracs_divorce_acts table, also add technical data:set id = autogenerate uuid
set inserted_at = now()
set updated_at = now()
set persons_compare_status and parties_compare_status:
to ‘READY’ - if mn_old_surname <> mn_surname or wmn_old_surname <> wmn_surname
to 'PROCESSED' - if mn_old_surname = mn_surname and wmn_old_surname = wmn_surname
set mn_settlement_id from uadresses service using RPC call with following logic:
in case (mn_locality is null or mn_locality_type = ‘Район’) - get settlement_id where settlement_name = mn_district and area_name = mn_region
in case husband_locality is not null - get settlement_id where settlement_name = husband_locality and area_name = husband_region
set wmn_settlement_id from uadresses service using RPC call with following logic:
in case (wmn_locality is null or wmn_locality_type = ‘Район’) - get settlement_id where settlement_name = wmn_district and area_name = wmn_region
in case wmn_locality is not null - get settlement_id where settlement_name = wmn_locality and area_name = wmn_region
in case found:
If
op_date = OP_DATE and ar_op_name = AR_OP_NAME
. So, full duplicate of divorce act already exists, then update dracs_divorce_acts table for found record:set updated_at = now()
Else, divorce act was updated in DRACS registry. Then, check that fields of divorce act in database (according to fields matching, but exclude technical fields
ar_reg_date, ar_reg_number, op_date, ar_op_name
) were updated in DRACS registry:in case at least one field was updated:
save existing record to dracs_divorce_acts_hstr table:
dracs_divorce_act_id = id of current divorce act from dracs_divorce_acts table
dracs_divorce_act_data = full data of current divorce act in jsonb format (without id, inserted_at and updated_at fields)
inserted_at = now()
fully update existing divorce act in dracs_divorce_acts table with new values from DRACS registry, also update technical data:
set persons_compare_status and parties_compare_status fields:
to ‘READY’ - if mn_old_surname <> mn_surname or wmn_old_surname <> wmn_surname and
ar_op_name = 1 or 4
to ‘PROCESSED’ - in another cases
set updated_at = now()
set mn_settlement_id and wmn_settlement_id as were described above.
in case none of the fields were updated:
update dracs_divorce_acts table for found divorce act:
set op_date = OP_DATE from response
set ar_op_name = AR_OP_NAME from response
set updated_at = now()
4. Update verification candidates
Update existing verification candidates according to saved divorce acts list:
in case saved divorce act is cancelled (
ar_op_name = 2 or 3
) or fully updated from DRACS (ar_op_name = 4
and existing act was saved to dracs_divorce_acts_hstr table):Check existence of active verification candidates with the act in the person_verification_candidates table in MPI db (with status = ‘NEW’, entity_type = ‘dracs_divorce_act’ and enitity_id = dracs_divorce_act_id) and in the party_verification_candidates table in PRM db (with status = ‘NEW’, entity_type = ‘dracs_divorce_act’ and entity_id = dracs_divorce_act_id)
in case found:
Deactivate each verification candidate updating following fields in the person_verification_candidates table or party_verification_candidates table:
set status = ‘DEACTIVATED’
set status_reason = 'DIVORCE_ACT_UPDATED'
set updated_at = now()
Check existence of other active verification candidates with the person in the person_verification_candidates table in MPI db (with status = ‘NEW’, entity_type in ‘dracs_marriage_act’, ‘dracs_divorce_act’, ‘dracs_change_name_act’) or with the party in party_verification_candidates in PRM db (with status = ‘NEW’, entity_type in ‘dracs_marriage_act’, ‘dracs_divorce_act’, ‘dracs_change_name_act’) from each deactivated candidate
in case no more active verification candidates found for person or party, update its verification status in person_verifications or party_verifications table:
set dracs_name_change_verification_status = ‘VERIFIED’
set dracs_name_change_verification_reason = ‘AUTO_OFFLINE’
set updated_at = now()
5. Complete the job
Update Divorce acts DailySynchronization job details in oban_jobs table:
set state = completed;
set completed_at = now();
Update or insert into dracs_divorce_acts_period_updates table details for dates that were successfully synchronized with DRACS registry:
set updated_at = now_date();