ЕСОЗ - публічна документація

Death acts synchronization with DRACS registry_EN

Purpose

This process gets death acts data from the DRACS registry through Trembita exchange gateway, saves it to dracs_death_acts table and prepares them for comparison processes.

Key points

  1. This process uses cron parameter to configure its start time.

  2. This process is used to obtain newest death act records as well as older historical death acts from DRACS registry.

  3. This process uses Oban job processing library as jobs management tool.

Configuration

Value

Description

Example

Value

Description

Example

DRACS_DEATH_ACTS_SYNC_SCHEDULE

Cron parameter, represents start time of death acts synchronization with DRACS registry process

0 2 * * *

DRACS_DEATH_ACTS_SYNC_PERIOD_START

Start date from which historic death acts must be obtained in “yyyy-mm-dd” format

2022-01-01

DRACS_DEATH_ACTS_STATUS_UPDATE_DAYS

Parameter in days when existing death acts must be updated with DRACS registry again

60

Service logic

  1. Check the need to create DailySynchronization job for interval between DRACS_DEATH_ACTS_SYNC_PERIOD_START and now_date() - 1 day:

    1. Make list of all distinct dates from date in DRACS_DEATH_ACTS_SYNC_PERIOD_START to now_date() - 1 day

    2. Get all dates that are already updated from dracs_death_acts_period_updates with updated_at > now() - DRACS_DEATH_ACTS_STATUS_UPDATE_DAYS value

    3. Get all dates that are currently being updated by daily synchronization job in oban_jobs table with state = ‘available’, ‘executing’, ‘retryable’

    4. Compare three lists and form list of dates that must be synchronized with DRACS registry

    5. Create DailySynchronization jobs in oban_jobs table for each day in descending order (newer dates should be synchronized first with DRACS registry) from formed list with following arguments (stored in oban_jobs.args field):

      1. date_from = ‘date_from_list’

      2. date_to = ‘date_from_list’

Daily synchronization job logic

  1. Perform GetDeathArByRegDatePeriod DRACS method (described atDRACS Trembita methods | GetDeathArByRegDatePeriod) with following params:

    1. DateFrom = args.date_from

    2. DateTo = args.date_to

  2. Get ResultData field from methods response and decode it from base64 to get XML file of death act records list.

  3. Parse obtained XML file and form death acts list.

  4. Save each death act from formed list to dracs_death_acts table in transaction according to fields matching (located in the table below)

  5. For each death act validate duplicates - check existence of death act in dracs_death_acts table with following conditions: ar_reg_date = ArRegDate and ar_reg_number = ArRegNumber

    1. in case not found - insert new death act to dracs_death_acts table, also add technical data:

      1. set id = autogenerate uuid

      2. set inserted_at = now()

      3. set updated_at = now()

      4. set persons_compare_status = ‘READY’

      5. set parties_compare_status = ‘READY'

      6. set settlement_id from uadresses service using RPC call with following logic:

        1. in case locality is null or locality_type = ‘Район’ - get settlement_id where settlement_name = district and area_name = region

        2. in case locality is not null - get settlement_id where settlement_name = locality and area_name = region

    2. in case found - check that condition op_date = OP_DATE and ar_op_name = AR_OP_NAME is also met for found record

      1. in case condition is met - full duplicate of death acts already exists, update dracs_death_acts table for found record:

        1. set updated_at = now()

      2. in case condition is not met - death act was updated in DRACS registry, check that fields of death act in database (reg_numb, compose_date, compose_org, is_restore, name, surname, patronymic, date_birth, birth_state, birth_region, birth_district, birth_locality_type, birth_locality, sex, numident, date_death, state, region, district, locality_type, locality, street, house, apartment, doc_seizes) were updated in DRACS registry

        1. in case at least one field was updated

          1. save existing record to dracs_death_acts_hstr table

            1. dracs_death_act_id = id of current death act from dracs_death_acts table

            2. dracs_death_act_data = full data of current death act in jsonb format (without id, inserted_at and updated_at fields)

            3. inserted_at = now()

          2. fully update existing death act in dracs_death_acts table with new values from DRACS registry, also update technical data:

            1. set persons_compare_status = ‘READY’

            2. set parties_compare_status = ‘READY'

            3. set updated_at = now()

            4. set settlement_id from uadresses service using RPC call with following logic:

              1. in case locality is null - get settlement_id where settlement_name = district

              2. in case locality is not null - get settlement_id where settlement_name = locality and region_name = district

        2. in case none of the fields were updated - update dracs_death_acts table for found death act:

          1. set op_date = OP_DATE from response

          2. set ar_op_name = AR_OP_NAME from response

          3. set updated_at = now()

  6. Update existing verification candidates according to saved death acts list:

    1. in case saved death act is cancelled (ar_op_name = 2 or 3) or fully updated from DRACS (ar_op_name = 4and existing act was saved to dracs_death_acts_hstr table) - check existence of active verification candidates in MPI db (with person_verification_candidates.status = ‘NEW’, person_verification_candidates.enitity_type = ‘death_act’ and person_verification_candidates.enitity_id = dracs_death_act_id) and in PRM db (with party_verification_candidates.status = ‘NEW’, party_verification_candidates.enitity_type = ‘death_act’ and party_verification_candidates.enitity_id = dracs_death_act_id)

      1. in case found

        1. deactivate verification candidates:

          1. set status = ‘DEACTIVATED’

          2. set status_reason = 'DEATH_ACT_UPDATED'

          3. set updated_at = now()

        2. update persons and parties compare status for death acts with ar_op_name = 2 or 3

          1. set persons_compare_status = ‘PROCESSED’

          2. set parties_compare_status = ‘PROCESSED'

      2. in case not found

        1. update persons and parties compare status for death acts with ar_op_name = 2 or 3

          1. set persons_compare_status = ‘PROCESSED’

          2. set parties_compare_status = ‘PROCESSED'

  7. Update DailySynchronization job details in oban_jobs table:

    1. set state = completed;

    2. set completed_at = now();

  8. Update or insert into dracs_death_acts_period_updates details for dates that were successfully synchronized with DRACS registry:

    1. set updated_at = now_date();

dracs_death_acts

ArServiceAnswer

dracs_death_acts

ArServiceAnswer

ar_reg_date

ArRegDate

ar_reg_number

ArRegNumber

op_date

OP_DATE

ar_op_name

AR_OP_NAME

reg_numb

RegNumb

compose_date

СomposeDate

compose_org

ComposeOrg

is_restore

IS_RESTORE

name

Name

surname

Surname

patronymic

Patronymic

date_birth

DateBirth

birth_state

BirthState

birth_region

BirthRegion

birth_district

BirthDistrict

birth_locality_type

BirthLocalityType

birth_locality

BirthLocality

sex

Sex

numident

Numident

date_death

DateDeath

state

State

region

Region

district

District

locality_type

LocalityType

locality

Locality

street

Street

house

House

apartment

Apartment

doc_seizes.doc_type

DOC_SEIZES / DOC_SEIZE / DocType

doc_seizes.doc_name

DOC_SEIZES / DOC_SEIZE / DocName

doc_seizes.series_numb

DOC_SEIZES / DOC_SEIZE / SERIES_NUMB

doc_seizes.doc_date

DOC_SEIZES / DOC_SEIZE / DocDate

doc_seizes.doc_org_name

DOC_SEIZES / DOC_SEIZE / DocOrgName

ЕСОЗ - публічна документація