Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Purpose
This process gets marriage acts data from the DRACS registry through Trembita exchange gateway, saves it to dracs_marriage_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 marriage act records as well as older historical marriage acts from DRACS registry.
This process uses Oban job processing library as jobs management tool.
Configuration
Value | Description | Example |
---|---|---|
DRACS_MARRIAGE_ACTS_SYNC_SCHEDULE | Cron parameter, represents start time of marriage acts synchronization with DRACS registry process |
|
DRACS_MARRIAGE_ACTS_SYNC_PERIOD_START | Start date from which historic marriage acts must be obtained in “yyyy-mm-dd” format |
|
DRACS_MARRIAGE_ACTS_STATUS_UPDATE_DAYS | Parameter in days when existing marriage acts must be updated with DRACS registry again |
|
Service logic
1. Define act dates to be synchronized
Check the need to create marriage acts DailySynchronization job according to dracs_marriage_acts_period_updates table (MIMIR db):
Make list of all distinct dates from date in range from DRACS_MARRIAGE_ACTS_SYNC_PERIOD_START to now_date() - 1 day
Exclude all dates that has been already updated with updated_at > now() - DRACS_MARRIAGE_ACTS_STATUS_UPDATE_DAYS value
Exclude all dates that are currently being updated by marriage acts daily synchronization job in oban_jobs table with state = ‘available’, ‘executing’, ‘retryable’
Create Marriage 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 GetMarriageArByRegDatePeriod DRACS method (described at https://e-health-ua.atlassian.net/wiki/spaces/DRACS2EH/pages/1785810124918201706498/UPD+RC_DRACS+Trembita+methods#GetMarriageArByRegDatePeriod+methods+DRACS+2.0#GetMarriageArByRegDatePeriod ) 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 marriage act records list.
Parse obtained XML file and form a marriage acts list.
3. Save data to MIMIR database
Save each marriage act from the formed list into dracs_marriage_acts table in transaction according to fields matching (located in the table below):
...
For each marriage act validate duplicates - check existence of marriage act in dracs_marriage_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 marriage act to dracs_marriage_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 husband_old_surname <> husband_surname or wife_old_surname <> wife_surname, and these fields are not empty
to 'PROCESSED' - if husband_old_surname = husband_surname and wife_old_surname = wife_surname
set husband_settlement_id from uadresses service using RPC call with following logic:
in case (husband_locality is null or husband_locality_type = ‘Район’) - get settlement_id where settlement_name = husband_district and area_name = husband_region
in case husband_locality is not null - get settlement_id where settlement_name = husband_locality and area_name = husband_region
set wife_settlement_id from uadresses service using RPC call with following logic:
in case (wife_locality is null or wife_locality_type = ‘Район’) - get settlement_id where settlement_name = wife_district and area_name = wife_region
in case wife_locality is not null - get settlement_id where settlement_name = wife_locality and area_name = wife_region
in case found:
If
op_date = OP_DATE and ar_op_name = AR_OP_NAME
. So, full duplicate of marriage act already exists, then update dracs_marriage_actstablefor found record:set updated_at = now()
Else, marriage act was updated in DRACS registry. Then, check that fields of marriage 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_marriage_acts_hstr table:
dracs_marriage_act_id = id of current marriage act from dracs_marriage_actstable
dracs_marriage_act_data = full data of current marriage act in jsonb format (without id, inserted_at and updated_at fields)
inserted_at = now()
fully update existing marriage act in dracs_marriage_acts table with new values from DRACS registry, also update technical data:
set persons_compare_status and parties_compare_status fields:
to ‘READY’ - if husband_old_surname <> husband_surname or wife_old_surname <> wife_surname and
ar_op_name = 1 or 4
(surname fields are not empty)to ‘PROCESSED’ - in another cases
set updated_at = now()
set husband_settlement_id and wife_settlement_id as were described above.
in case none of the fields were updated:
update dracs_marriage_actstablefor found marriage 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 marriage acts list:
in case saved marriage 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_marriage_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_marriage_act’ and enitity_id = dracs_marriage_act_id) and in the party_verification_candidates table in PRM db (with status = ‘NEW’, entity_type = ‘dracs_marriage_act’ and entity_id = dracs_marriage_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 = 'MARRIAGE_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 Marriage acts DailySynchronization job details in oban_jobs table:
set state = completed;
set completed_at = now();
Update or insert into dracs_marriage_acts_period_updates table details for dates that were successfully synchronized with DRACS registry:
set updated_at = now_date();