Table of Contents

...

Search pending declaration requests

Search persons request in IL_DB.person_requests to prevent requests duplication:

  • if tax_id is not null
Code Block
languagesql
WHERE IL_DB.person_requests.data.tax_id = :($.declaration_requests.person.tax_id)
  AND IL_DB.person_requests.status IN ('NEW', 'APPROVED')

...

Code Block
languagesql
WHERE IL_DB.person_requests.data.documents.number = :($.declaration_requests.person.documents.number)
  AND IL_DB.person_requests.status IN ('NEW', 'APPROVED')


If found person request - don't create person request. Return error "This person already has a person request"

Calculate declaration end/start date

...

  • in case person is found, person_id will be saved to declaration_request, and person has the same authentication_methods.phone_number, we do not count phone numbers and do not compare the phone number with global_parameters.phone_number_auth_limit. So that we can update person, but still can not use phone over limit.
  • In case person is not found
    • Check if (SELECT count(*) from persons where authentication_methods::json->0->>'phone_number'='$.phone_number' and persons.status='active' and is_active=true)<global_parameters.phone_number_auth_limit
      in case error return 422, msg "This phone number is present more then $.global_parameters.phone_number_auth_limit times in the system"

Validate declaration limit

  1. Count all declarations in status active where OPS.declarations.employee_id==$.declaration_request.employee_id
    1.1 If there is an active declaration with the current person, exclude it from the selection in order to let doctor resign declaration with current patient
  2. Count all declaration_requests in status approved where IL.declaration_requests.data($.employee.id) ==$.declaration_request.employee_id
  3. Get all specialities of current doctor
    1. Select speciality from PRM.employees where PRM.employees.party_id == (select PRM.employees.party_id where PRM.employees.id=$.declaration_request.employee_id)
  4. Select config parameter for declarations_limit where speciality == select 3 
  5. Compare the result of selections 1+2 with the lowest config parameter from select 4. In case count (declarations+declaration_requests )> config_parameter, return 409 "The employee has reached the declaration limit"

Validate person authentication phone

USE_DEDUPLICATION_MODEL - is a flag in in ehealth.charts that turn on logic:

If person have confidant_person, then person.auth_phone = person.confident_person.phone

...