Table of Contents |
---|
...
This WS is designed to update list of employees and related divisions which belongs to contract. Update must be done trough through signed content and for batch of employees.
...
- Verify the validity of access token
- in case of error return 401 ('Access denied')
- Check user scope contract:write in order to perform this action
- in case of error generate 401 response ('Invalid scopes')
- Verify the validity of access token
Check employee
Update contract_employees can be done by owner with necessary scopes in equal legal_entity_id and same id as was perviously input in contract.
- Extract legal_entity_id (client_id) from token. Take contract_id.
- Check client_id=contractor.legal_entity_id (contractor_side) - in case of error return 403 Error ('Invalid client id')
- Extract token → users.id → party_users.party_id → employee_id.
- Check employees.employee_id=contractor_owner_id and client_id=employee.legal_entity_id
- In case of error return 422 Error ('Employee is not allowed to sign')
- Extract token → users.id → party_users.party_id → employee_id.
...
Decode content that is encrypted in an electronic digital signature.
Use Digital signature WS. Method checks digital signature and returns result.
Validate DRFO
- Check that DRFO in Certificate details exists and not empty
- in case of error return 422 error ('Invalid DRFO in DS')
- Check that DRFO in Certificate details is equal to DRFO in Party
- Get party.tax_id using user_id from token (user.id→ party_users.party_id → parties.id.tax_id)
- Compare DRFO in Certificate with party.tax_id
- Convert DRFO and TAX_ID to uppercase
- Compare DRFO and TAX_ID as Cyrillic letters
- Convert DRFO to Cyrillic and compare as Cyrillic letters
- In case validation fails - generate 422 error
...
- From user_roles and roles check that user has roles = 'OWNER'
- in case of error return 403 Error ('User is not allowed to this action by role')
- Validate client_id (the owner belong to legal entity)
- in case of error return 403 Error ('User is not allowed to this action by client_id')
Validate request
- Check contract_id exists. In case of error return 404 Error ('Contract with this ID doesn't exist')
- Check contract with $contract_id has status 'VERIFIED'. In case of error return 422 Error ('Not active contract can't be updated')
- Validate contractor_employee_divisions
- Employees from employee_divisions has employee_type='DOCTOR', status='APPROVED', division is not null
- in case of error return 422 error view $employee ('Employee must be active DOCTOR with linked division')
- By contract_id find contractor_legal_entity_id. Check divisions belongs to legal_entity and divisions.status='active'.
- in case of error return 422 error view $divisions ('Division must be active and within current legal_entity')
- Check employee belongs to division
- in case of error return 422 error view $employee ('Employee must be within current division')
- Employees from employee_divisions has employee_type='DOCTOR', status='APPROVED', division is not null
Search current contract_employees by contract id
- Fetch all ops.contract_employees.id by $contract_id and end_date=null. For all such rows set end_date=now()::date
- Insert into ops.contract_employees new batch of employees which were received in request.
- set start_date=now()::date+1
- end_date=null