Purpose
This WS is designed to change status of contract request to NEW by legal entity side. It means that start process from legal entity side is fished and NHS employee can start working if accepted.
Design
TBD
Specification
Validation
Validate token
- Verify the validity of access token
- Return 401 in case validation fails
- Check if token is not expired
- in case error return 401 - "Token is expired"
Validate user
extract user_id from token
extract client_id from token
- Check if user is active
- in case error return 403 - (user is not active)
- check contractor_legal_entity is active
- in case error return 403 - (Client is not active)
- Validate $client_id=contractor_legal_entity_id.
- in case of error return 403 - Client is not allowed to modify contract_request
Validate scopes
- Check user scopes in order to perform this action (scope = 'contract_request:approve')
- Return 403 in case invalid scope(s) "Your scope does not allow to access this resource. Missing allowances: contract_request:approve"
Validate data
- Validate contract request id.
- Check contract_requests.id = $.id
- in case error return 404 ("Contract request with id=$id doesn't exist")
- Check contract_requests.id = $.id
- Validate contract_request.status=DRAFT
- in case error return 409 - "Incorrect status of contract request to modify it"
- Validate contractor_legal_entity_id
- Legal_entities.id = $.contractor_legal_entity_id and Legal_entities.status='ACTIVE',
- in case error return 422 ("Legal entity in contract request should be active")
- Legal_entities.id = $.contractor_legal_entity_id and Legal_entities.status='ACTIVE',
- Validate contractor_owner_id
- Employee is_active=true and status='APPROVED' and employees.legal_entity_id=contractor_legal_entity_id
- in case error return 422, $contractor_owner_id (Contractor owner must be active within current legal entity in contract request)
- Employee is_active=true and status='APPROVED' and employees.legal_entity_id=contractor_legal_entity_id
- Validate contractor_divisions
- 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 divisions belongs to legal_entity and divisions.status='active'
- Validate contractor_employee_divisions
- Employees from employee_divisions has employee_type='DOCTOR', status='APPROVED'
- in case of error return 422 error view $employee ('Employee must be an active DOCTOR')
- Check contractor_employee_divisions.division_id is present in contractor_divisions.id
- in case of error return 422 error $divisions ('The division is not belong to contractor_divisions')
- Check contract_number is null
- in case of error return 422 error view $employee ('Employee can't be updated via Contract Request')
- Employees from employee_divisions has employee_type='DOCTOR', status='APPROVED'
- Validate start_date
- start_date > now()
- in case error return 422 $start_date ("Contract request start date should be in future")
- start_date > now()
Check uploaded documents
- Invoke Media Content Storage to check documents exist.
- In case of error return 422 error ('The documents weren't uploaded')
- 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 parties.tax_id using party_users.party_id by user_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
Response
Save documents to media storage
Signed documents as well as files in PDF format must be saved to media storage.
Save response data to DB
set status='NEW'
Mapping
field | value |
---|---|
updated_by | $.user_id |
updated_at | now() |
status | NEW |
Add to event manager
After status was changed (status = NEW, APPROVED, DECLINED, PENDING_NHS_SIGN, TERMINATED or SIGNED) - add new status to event_manager
field | value |
---|---|
event_type | StatusChangeEvent |
entity_type | Contract_request |
entity_id | $.id |
properties.status. | $.status |
event_time | $.update_at |
changed_by | $.user_id |
inserted_at | now() |
updated_at | now() |