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

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Purpose

This process gets birth acts data of specific person from the DRACS registry through Trembita exchange gateway and uses it for further comparison with person and/or confidant person relationship.

Key points

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

  2. This process is used to obtain all active birth acts of specified person from DRACS registry.

  3. This process is used to verify both persons with birth certificate documents as well as confidant person relationships with birth certificate documents.

  4. This process is used for synchoronization for new or updated persons in the system, existing persons in the system that were not synchronized with DRACS birth acts registry, existing persons in the system that were synchronized with DRACS birth acts registry to check that their data is still valid in DRACS birth acts registry.

  5. This process gets limited amount of persons for synchronization with DRACS birth acts registry.

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

Configuration

Value

Description

Example

DRACS_BIRTH_ACTS_PERSONS_SYNCHRONIZATION_SCHEDULE

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

*/3 * * * *

DRACS_BIRTH_ACTS_PERSONS_SYNCHRONIZATION_BATCH_SIZE

Size of Persons list that will be synchronized online with DRACS birth acts registry

100

DRACS_BIRTH_ACTS_PERSON_VALIDATION_PERIOD_DAYS

Represents period in days when the existing person birth certificate data should be validated in DRACS birth acts registry if it still valid

180

DRACS_BIRTH_ACTS_CONFIDANT_PERSON_RELATIONSHIP_VALIDATION_PERIOD_DAYS

Represents period in days when the existing confidant person relatinship with birth certificate data should be validated in DRACS birth acts registry if it still valid

30

Service logic

Step 1. Prepare list of Persons to be synced

Get list of active Persons (status=active, is_active=true) that must be synchronized online with DRACS birth acts registry by following criteria (using logical AND):

  • persons that must be synchronized online with DRACS birth acts registry:

    • mpi.person_verifications.dracs_birth_synced_at <= current_date - DRACS_BIRTH_ACTS_PERSON_VALIDATION_PERIOD_DAYS OR dracs_birth_synced_at is null

    • exclude persons who has dracs_birth_verification_status = IN_REVIEW, NOT_VERIFIED, VERIFICATION_NOT_NEEDED

  • persons whose confidant person relationship must be synchronized online with DRACS birth acts registry:

    • mpi.confidant_person_relationships.dracs_birth_synced_at <= current_date - DRACS_BIRTH_ACTS_CONFIDANT_PERSON_RELATIONSHIP_VALIDATION_PERIOD_DAYS OR dracs_birth_synced_at is null with confidant_person_relationship_documents.type = ‘BIRTH_CERTIFICATE’

    • exclude relationships who has verification_status = IN_REVIEW, NOT_VERIFIED or does not have confidant_person_relationship_documents.type ‘BIRTH_CERTIFICATE’

In case if list is empty - end the process.

In case if list is not empty - sort obtained lists by:

  • person_verifications.dracs_birth_verification_status = VERIFICATION_NEEDED and person_verifications.dracs_birth_verification_reason = ONLINE_TRIGGERED or MANUAL (should be at the top of the list)

  • confidant_person_relationships.verification_status = VERIFICATION_NEEDED and confidant_person_relationships.verification_reason = ONLINE_TRIGGERED (should be at the top of the list)

Limit obtained list with DRACS_BIRTH_ACTS_PERSONS_SYNCHRONIZATION_BATCH_SIZE value from chart params.

Get first person from obtained list.

Step 1.1 Update Person

Make data pre-estimation for a synchronization:

  1. If a person has no birth certificate document (BIRTH_CERTIFICATE) at all, then update person_verifications record by person_id:

    • dracs_birth_act_id = null

    • dracs_birth_verification_status = VERIFICATION_NOT_NEEDED

    • dracs_birth_verification_reason = INITIAL

    • dracs_birth_verification_comment = null

    • dracs_birth_synced_at = null

    • dracs_birth_unverified_at = null

  2. If a person has more than one active birth certificate document, then update person_verifications record by person_id:

    1. dracs_birth_act_id = null

    2. dracs_birth_verification_status = NOT_VERIFIED

    3. dracs_birth_verification_reason = INITIAL

    4. dracs_birth_verification_comment = null

    5. dracs_birth_synced_at = null

    6. dracs_birth_unverified_at = now()

  3. If persons age > no_self_auth_age global parameter and person has other active document from IDENTITY_DOCUMENT_TYPES config parameter (exclude BIRTH_CERTIFICATE and BIRTH_CERTIFICATE_FOREIGN), then update person_verifications record by person_id:

    1. dracs_birth_act_id = null

    2. dracs_birth_verification_status = VERIFICATION_NOT_NEEDED

    3. dracs_birth_verification_reason = INITIAL

    4. dracs_birth_verification_comment = null

    5. dracs_birth_synced_at = null

    6. dracs_birth_unverified_at = null

If person corresponded to any of the rules above – proceed to Step 6.

If person did not correspond to any of the rules above – proceed to Step 2.

Step 2. Get Person birth acts from DRACS

  1. If person must be verified by DRACS birth acts registry by conditions from Step 1 - update person_verifications table in MPI db for person_id, set values:

    1. dracs_birth_verification_status = ‘IN_REVIEW’

    2. dracs_birth_verification_reason = ‘AUTO_ONLINE’

  2. If confidant person relationship must be verified by DRACS birth acts registry by conditions from Step 1 - ppdate confidant_person_relationships table in MPI db for person_id and relationship_id, set values:

    1. verification_status = ‘IN_REVIEW’

    2. verification_reason = ‘AUTO’

  3. Get persons birth acts - perform GetBirthArByChildNameAndBirthDate DRACS method with following request params:

    1. ChildName = persons.first_name

    2. ChildBirthDate = persons.birth_date

    3. ChildPatronymic = persons.second_name (skip if empty)

    4. ChildSurname = persons.last_name

  4. Get ResultData field from GetBirthArByChildNameAndBirthDate method response and decode it from base64 to get XML file of birth acts list.

    1. in case GetBirthArByChildNameAndBirthDate ResultCode <> 0 or connection error or timeout is occured - check that persons dracs_birth_verification_status = ‘IN_REVIEW’ or confidant person relationship verification status = ‘IN_REVIEW’

      1. if true - rollback it in person_verifications table in MPI db for person_id to previous state

      2. if false - skip this person, go to next person in list.

Step 3. Prepare obtained birth acts

If GetBirthArByChildNameAndBirthDate call in Step 2 was successful and ResultCode = 0, parse obtained XML file and form birth acts list.

Save each birth act from formed list to dracs_birth_acts table in transaction according to fields matching:

 dracs_birth_acts to GetBirthArByChildNameAndBirthDate response fields matching

dracs_birth_acts

GetBirthArByChildNameAndBirthDate

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

father_parent_rights

FatherParentRights

mother_parent_rights

MotherParentRights

child_surname

ChildSurname

child_name

ChildName

child_patronymic

ChildPatronymic

child_sex

ChildSex

сhild_date_birth

ChildDateBirth

child_birth_state

ChildBirthState

child_birth_region

ChildBirthRegion

child_birth_district

ChildBirthDistrict

child_birth_locality_type

ChildBirthLocalityType

сhild_birth_locality

ChildBirthLocality

father_surname

FatherSurname

father_name

FatherName

father_patronymic

FatherPatronymic

father_numident

FatherNumident

father_date_birth

FatherDateBirth

father_citizenship

FatherСitizenship

father_citizenship_another

FatherСitizenshipAnother

father_state

FatherState

father_region

FatherRegion

father_district

FatherDistrict

father_locality_type

FatherLocalityType

father_locality

FatherLocality

father_street

FatherStreet

father_house

FatherHouse

father_building_part

FatherBuildingPart

father_building_part_type

FatherBuildingPartType

father_apartment

FatherApartment

mother_surname

MotherSurname

mother_name

MotherName

mother_patronymic

MotherPatronymic

mother_numident

MotherNumident

mother_date_birth

MotherDateBirth

mother_citizenship

MotherСitizenship

mother_citizenship_another

MotherСitizenshipAnother

mother_state

MotherState

mother_region

MotherRegion

mother_district

MotherDistrict

mother_locality_type

MotherLocalityType

mother_locality

MotherLocality

mother_street

MotherStreet

mother_house

MotherHouse

mother_building_part

MotherBuildingPart

mother_building_part_type

MotherBuildingPartType

mother_apartment

MotherApartment

certificates.cert_status

CertStatus

certificates.cert_serial

CertSerial

certificates.cert_number

CertNumber

certificates.cert_org

CertOrg

certificates.cert_date

CertDate

certificates.cert_repeat

CertRepeat

certificates.cert_serial_number

CertSerialNumber

For each birth act validate duplicates - check existence of birth act in dracs_birth_acts table with following conditions: ar_reg_date = ArRegDate and ar_reg_number = ArRegNumber

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

    1. set id = autogenerate uuid

    2. set inserted_at = now()

    3. set updated_at = now()

  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 birth acts already exists, update dracs_birth_acts table for found record:

      1. set updated_at = now()

    2. in case condition is not met - birth act was updated, check that fields of birth act from 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

      1. in case at least one field was updated

        1. save existing record to dracs_birth_acts_hstr table

          1. dracs_birth_act_id = id of current birth act from dracs_birth_acts table

          2. dracs_birth_act_data = full data of current birth act in jsonb format (without technical fields, use fields matching from table below)

          3. inserted_at = now()

        2. fully update existing birth act in dracs_birth_acts table with new values from DRACS registry

          1. set updated_at = now()

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

        1. op_date = OP_DATE from response

        2. ar_op_name = AR_OP_NAME from response

        3. updated_at = now()

Update existing verification candidates according to the saved birth acts list:

  1. in case saved birth act is cancelled (ar_op_name = 2 or 3) or fully updated from DRACS (ar_op_name = 4 and the existing act was saved to dracs_birth_acts_hstr table) - check the existence of active person verification candidates in person_verification_candidates table in MPI db (with status = ‘NEW’, entity_type = ‘dracs_birth_act’ and entity_id = dracs_birth_act_id) or confidant person relationship verification candidates in confidant_person_relationship_verification_candidates table in MPI db (with status = ‘NEW’, entity_type = ‘dracs_birth_act’ and and entity_id = dracs_birth_act_id)

    1. in case found, deactivate each verification candidate with the following logic:

      1. update the status of the verification candidate in person_verification_candidates or confidant_person_relationship_verification_candidates table:

        1. set status = ‘DEACTIVATED’

        2. set status_reason = 'BIRTH_ACT_UPDATED'

        3. set updated_at = now()

      2. check existence of other active verification candidates for person_id in person_verification_candidates table in MPI db (with status = ‘NEW’ and entity_type = ‘dracs_birth_act’) and active verification candidates for relationship_id in confidant_person_relationship_verification_candidates table in MPI db (with status = ‘NEW’ and entity_type = ‘dracs_birth_act’):

        1. in case no more active verification candidates are found for the person, update its dracs birth verification status in person_verifications table:

          1. set dracs_birth_verification_status = ‘VERIFICATION_NEEDED’

          2. set dracs_birth_verification_status = ‘ONLINE_TRIGGERED’

          3. set dracs_birth_unverified_at = null

          4. set dracs_birth_synced_at = null

          5. set updated_at = now()

        2. in case no more active verification candidates are found for the relationship, update its verification status in confidant_person_relationships table:

          1. set verification_status = ‘VERIFICATION_NEEDED’

          2. set verification_status = ‘ONLINE_TRIGGERED’

          3. set unverified_at = null

          4. set dracs_birth_synced_at = null

          5. set updated_at = now()

Step 4. Verify Person

Check that person_verifications.dracs_birth_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 birth acts performed, or person should not be synchronized by DRACS birth acts registry):

  • if equals – invoke this Step.

  • if not equal – skip this Step, go to Step 5.

Get only active birth acts with ar_op_name = 1 or 4 and not empty certificates with active records cert_status = 1 from the obtained birth acts list.

In case no active birth acts for a person were found, update person_verifications table in MPI db for person_id, set values:

  • dracs_birth_act_id = null

  • dracs_birth_verification_status = ‘NOT_VERIFIED’

  • dracs_birth_verification_reason = ‘AUTO_NOT_FOUND’

  • dracs_birth_unverified_at = now()

  • dracs_birth_synced_at = now()

  • updated_at = now()

  • updated_by = system_user()

Then proceed to Step 6.

In case active birth acts exist – verify Person data with each active birth act:

  1. Compare Persons data with birth act data using comparison process:

    1. get person_documents.number (with type = BIRTH_CERTIFICATE) from person

    2. get certificates.cert_serial + certificates.cert_number with certificates.cert_status = 1 from birth act

    3. perform normalization of found numbers (remove special symbols, bring to lower register)

    4. compare found document numbers:

      1. if equal for at least one of act:

        1. Update person_verifications table in MPI db for person_id, set values:

          1. dracs_birth_act_id = dracs_birth_acts.id

          2. dracs_birth_verification_status = ‘VERIFIED’

          3. dracs_birth_verification_reason = ‘AUTO_ONLINE’

          4. dracs_birth_synced_at = now()

          5. updated_at = now()

          6. updated_by = system_user()

        2. Skip all other birth acts – go to Step 4.1.

      2. if not equal for all acts:

        1. Update person_verifications table in MPI db for person_id, set values:

          1. dracs_birth_act_id = null

          2. dracs_birth_verification_status = ‘NOT_VERIFIED’

          3. dracs_birth_verification_reason = ‘AUTO_ONLINE’

          4. dracs_birth_unverified_at = now()

          5. dracs_birth_synced_at = now()

          6. updated_at = now()

          7. updated_by = system_user()

        2. Create record in person_verification_candidates table in MPI db for person_id, set values:

          1. id = autogenerate id

          2. person_id = person_id

          3. entity_id = dracs_birth_act_id (for each act)

          4. entity_type = ‘dracs_birth_act’

          5. status = ‘NEW’

          6. inserted_at = now()

          7. updated_at = now()

After all birth acts were compared with Person data – go to Step 4.1.

Step 4.1. Verify Persons confidant person data

Invoke this step if person must be verified by DRACS birth acts registry on Step 4 and person has confidant persons in persons.confidant_person in MPI db and existing confidant persons have documents_relationship with type = BIRTH_CERTIFICATE and person age is lesser than person_full_legal_capacity_age global parameter and person has at least one active birth acts (defined on Step 4).

Get first Confidant person from persons.confidant_person and verify it with each active birth act:

  1. Compare Confidant persons documents_relationship data with each birth act data using comparison process:

    1. get documents_relationship.number (with type = BIRTH_CERTIFICATE) from confidant person

    2. get certificates.cert_serial + certificates.cert_number with certificates.cert_status = 1 from birth act

    3. perform normalization of found numbers (remove special symbols, bring to lower register)

    4. compare found numbers:

      1. if at least one act is equal – proceed with all valid acts data to next comparison step

      2. if all acts are not equal – skip this confidant person, if Person does not have other confidant persons – proceed to Step 5

  2. Compare Confidant persons personal data with each birth act data (compared from previous comparison step) using comparison process:

    1. get last_name, first_name, second_name, tax_id and birth_date from confidant person

    2. get father_surname, father_name, father_patronymic, father_numident, father_date_birth, mother_surname, mother_name, mother_patronymic, mother_numident, mother_date_birth from birth act

    3. perform normalization of found fields (remove special symbols, bring to lower register)

    4. compare confidant person with parents by following steps:

      1. compare last_name, first_name, second_name, birth_date with father_surname, father_name, father_patronymic, father_date_birth or mother_surname, mother_name, mother_patronymic, mother_date_birth

        1. if at least one act is equal – compare tax id on the next step

        2. if all acts are not equal – skip this confidant person, if Person does not have other confidant persons – proceed to Step 5.

      2. compare tax_id (if exists) with corresponding father_numident or mother_numident (if exists)

        1. if does not exist or exists and at least one act is equal – proceed with all valid acts data to next comparison step

        2. if not equal – skip this confidant person, if Person does not have other confidant persons – proceed to Step 5

  3. Check compared Confidant persons parent rights from birth acts (compared from previous comparison step):

    1. get father_parent_rights and mother_parent_rights from birth act

    2. check that father_parent_rights <> 183 or mother_parent_rights <> 185 for corresponding confidant person

      1. if father_parent_rights <> 183 or mother_parent_rights <> 185 for Confidant person – proceed to next step

      2. if father_parent_rights = 183 or mother_parent_rights = 185 for any Confidant person – skip this confidant person, if Person does not have other confidant persons – proceed to Step 5

  4. Search for active person using Active person search algorithm with successfully compared confidant person last_name, first_name, second_name and tax_id (if exists)

    1. if tax_id does not exists or search returns ‘No active person found’ or ‘Impossible to clearly identify an active person’ messages – skip this confidant person, if Person does not have other confidant persons – proceed to Step 5

    2. if one active person is found – check that it can be used as confidant person using following validations https://e-health-ua.atlassian.net/wiki/spaces/CSI/pages/17612832814/Create+Confidant+Person+relationship+request#Validate-confidant-person

      1. if no validation fails – create Confidant person relationship as described https://e-health-ua.atlassian.net/wiki/spaces/CSI/pages/17613422651/Approve+Confidant+Person+relationship+request#Create-confidant-person-relationship-(action-%3D-INSERT) here, only set:

        1. verification_status = ‘VERIFIED’

        2. verification_reason = ‘AUTO’

        3. dracs_birth_synced_at = now()

      2. remove confidant person data from persons.confidant_person field

After all birth acts were compared with Confidant persons data – go to Step 5.

Step 5. Verify Confidant person relationships

Check that Person has confidant person relationships with verification_status = IN_REVIEW and verification_reason = AUTO_ONLINE with confidant_person_relationship_documents.type = BIRTH_CERTIFICATE.

  • if relationships exist – invoke this Step.

  • if relationship does not exist – skip this Step, go to Step 6.

Get only active birth acts with ar_op_name = 1 or 4 and not empty certificates with active records cert_status = 1 from the obtained list.

In case no active birth acts for a person were found - update all confidant person relationships for person that should be verified, update confidant_person_relationships table in MPI db for each relationship_id, set values:

  • dracs_birth_act_id = null

  • verification_status = ‘NOT_VERIFIED’

  • verification_reason = ‘AUTO_NOT_FOUND’

  • unverified_at = now()

  • dracs_birth_synced_at = now()

  • updated_at = now()

  • updated_by = system_user()

Then proceed to Step 6.

In case active birth acts for person exist, get first Confidant person relationship by relationship_id that must be verified and verify it with each active birth act:

  1. Compare confidant persons personal data with each birth act data using comparison process:

    1. get confidant persons last_name, first_name, second_name, tax_id and birth_date from persons table in MPI db with persons.id = confidant_person_id

    2. get parents data (father_surname, father_name, father_patronymic, father_numident, father_date_birth, mother_surname, mother_name, mother_patronymic, mother_numident, mother_date_birth) from birth act

    3. perform normalization of found fields (remove special symbols, bring to lower register)

    4. compare confidant person with parents data by following steps:

      1. compare last_name, first_name, second_name, birth_date with father_surname, father_name, father_patronymic, father_date_birth or mother_surname, mother_name, mother_patronymic, mother_date_birth

        1. if not equal for all acts:

          1. Update confidant_person_relationships table in MPI db for relationship_id, set values:

            1. dracs_birth_act_id = null

            2. verification_status = ‘NOT_VERIFIED’

            3. verification_reason = ‘AUTO_INCORRECT_CONFIDANT’

            4. unverified_at = now()

            5. dracs_birth_synced_at = now()

            6. updated_at = now()

            7. updated_by = system_user()

        2. if at least one equal – proceed with all valid acts data to next comparison step

      2. compare tax_id (if exists) with corresponding father_numident or mother_numident (if exists)

        1. if not equal for all acts:

          1. Update confidant_person_relationships table in MPI db for relationship_id, set values:

            1. dracs_birth_act_id = null

            2. verification_status = ‘NOT_VERIFIED’

            3. verification_reason = ‘AUTO_INCORRECT_CONFIDANT’

            4. unverified_at = now()

            5. dracs_birth_synced_at = now()

            6. updated_at = now()

            7. updated_by = system_user()

        2. if at least one equal – proceed with all valid acts data to next comparison step

  2. Check compared Confidant persons parent rights for each remaining acts and corresponding confidant persons:

    1. get father_parent_rights and mother_parent_rights from birth act

    2. check that father_parent_rights <> 183 or mother_parent_rights <> 185 for corresponding confidant person

      1. if equal for all acts:

        1. Update confidant_person_relationships table in MPI db for relationship_id, set values:

          1. dracs_birth_act_id = null

          2. verification_status = ‘NOT_VERIFIED’

          3. verification_reason = ‘AUTO_PARENTAL_RIGHTS_DEPRIVED’

          4. unverified_at = now()

          5. dracs_birth_synced_at = now()

          6. updated_at = now()

          7. updated_by = system_user()

      2. if not equal for at least one act – proceed with all valid acts data to next comparison step

  3. Compare documents_relationship data with each remaining birth acts data using comparison process:

    1. get documents_relationship.number (with type = BIRTH_CERTIFICATE) from confidant_person_relationship_documents table with confidant_person_relationship_id = relationship_id

    2. get certificates.cert_serial + certificates.cert_number with certificates.cert_status = 1 from birth act

    3. perform normalization of found numbers (remove special symbols, bring to lower register)

    4. compare found numbers:

      1. if not equal for all acts:

        1. Update confidant_person_relationships table in MPI db for relationship_id, set values:

          1. dracs_birth_act_id = null

          2. verification_status = ‘NOT_VERIFIED’

          3. verification_reason = ‘AUTO’

          4. unverified_at = now()

          5. dracs_birth_synced_at = now()

          6. updated_at = now()

          7. updated_by = system_user()

        2. Create record in confidant_person_relationship_verification_candidates table in MPI db for relationship_id, set values:

          1. id = autogenerate id

          2. confidant_person_relationship_id = relationship_id

          3. entity_id = dracs_birth_act_id (for each act)

          4. entity_type = ‘dracs_birth_act’

          5. status = ‘NEW’

          6. inserted_at = now()

          7. updated_at = now()

        3. Go to next relationship for Person, if Person does not have other confidant person relationships – proceed to Step 6

      2. if at least one equal – update confidant_person_relationships table in MPI db for relationship_id, set values:

        1. verification_status = ‘VERIFIED’

        2. verification_reason = ‘AUTO’

        3. dracs_birth_act_id = dracs_birth_acts.id

        4. dracs_birth_synced_at = now()

        5. updated_at = now()

        6. updated_by = system_user()

After all birth acts were compared with Confidant person relationships data – go to Step 6.

Step 6. Select next Person

Select the next person from the obtained list and return to Step 2 of the process.

  1. in case no more persons are available - end the process.

  • No labels