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

Update Contract Employees

Purpose

This WS is designed to update employees and related divisions which belongs to contract. Update must be done through signed content and for each employee separately.

With each next update previous version for employee in contract (key=contract_id+employee_id+division_id) is deactivated and next version is active starting from update date. 

Specification

Update Employee Divisions


Input parameters

Through signed content it is possible to

  • add new employee to contract
  • update existing employee within active contract
  • deactivate  existing employee within active contract - in this case must be signed parameter `is_active=false`

The key to find current active employee in contract and deactivate it  -  $contract_id + $employee_id +$division_id and end_date=null. For such row set end_date=now()::date.

Request example to add/update employee:

Update employee
{
 "employee_id": "09106b70-18b0-4726-b0ed-6bda1369fd52",
 "staff_units": 1,
 "declaration_limit": 45000,
 "division_id": "6eb6123a-b3ce-4d27-ad3a-f6e3fb3ef1a1"
}


Request example to deactivate employee:

Update employee
{
 "employee_id": "09106b70-18b0-4726-b0ed-6bda1369fd52",
 "division_id": "6eb6123a-b3ce-4d27-ad3a-f6e3fb3ef1a1",
 "is_active": false
}


Authorize

    1. Verify the validity of access token
      1. in case of error return 401 ('Access denied')
    2. Check user scope contract:write in order to perform this action
      1. in case of error generate 401 response ('Invalid scopes')

Check employee

Update contract_employees can be done by employee with necessary scopes in equal legal_entity_id as was perviously input in contract.

  1. Extract legal_entity_id (client_id) from token. Take contract_id.
  2. Check client_id=contractor.legal_entity_id (contractor_side) - in case of error return 403 Error ('Invalid client id')

Digital signature

Decode content that is encrypted in an electronic digital signature.
Use Digital signature WS. Method checks digital signature and returns result.

Validate DRFO

  1. Check that DRFO in Certificate details exists and not empty
    1. in case of error return 422 error ('Invalid DRFO in DS')
  2. Check that DRFO in Certificate details is equal to DRFO in Party
    1. Get party.tax_id using user_id from token (user.id→ party_users.party_id → parties.id.tax_id)
    2. Compare DRFO in Certificate with party.tax_id
      1. Convert DRFO and TAX_ID to uppercase
      2. Compare DRFO and TAX_ID as Cyrillic letters
      3. Convert DRFO to Cyrillic and compare as Cyrillic letters
    3. In case validation fails - generate 422 error

Validate request

  1. Check contract_id exists. In case of error return 404 Error ('Contract with this ID doesn't exist')
  2. Check contract with  $contract_id has status 'VERIFIED'. In case of error return 409 Error ('Not active contract can't be updated')
  3. In case of Update/ADD new employee validate employee and division
    1. Employee from employee_divisions has employee_type='DOCTOR', status='APPROVED'
      1. in case of error return 422  error view $employee ('Employee must be an active DOCTOR')
    2. By contract_id find contractor_legal_entity_id. Check employee belongs to legal entity.
      1. in case of error return 422  error view $employee ('Employee must be within current legal_entity')
    3. By contract_id find contractor_legal_entity_id. Check divisions belongs to legal_entity and divisions.status='active'. 
      1. in case of error return 422  error view $divisions ('Division must be active and within current legal_entity')
    4. Check divisions belongs to contractor_divisions. Find contract_divisions by contract_id and end_date=null
      1.  in case of error return 422  error view $employee  ('Division is not in contract')
  4. In case of Deactivation current employee validate employee and division:
    1. Check divisions belongs to legal_entity
      1. in case of error return 422  error view $divisions ('Division must be within current legal_entity')
    2. Check employee belongs to legal entity
      1. in case of error return 422  error view $employee ('Employee must be within current legal_entity')
    3. Check there is ACTIVE employee ( $contract_id + $employee_id +$division_id and end_date=null)
      1. in case of error return $employee ('Invalid employee_id to deactivate')

Search current contract_employees by contract id

  1. Fetch  ops.contract_employees.id by $contract_id + $employee_id +$division_id and end_date=null. For such row set end_date=now()::date
  2. Insert into ops.contract_employees new employee which was received in request.
    1. set start_date=now()::date+time
    2. end_date=null




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