Purpose
This WS is design to create relationship for reorganized legal entities by NHS admin using DS. Before the request is created new LE must be created (in case if needed) and employee from old legal entity must be registered in the new one. After that NHS admin must set relationship via signed content. After basic validation
Specification
Schemas:
Logic
API paragraph not found
Input parameters
Input is signed data in PKCS7 format. The data must be unpacked and validated using Json Schema.
Fields to sign:
Input parameter | Values | Type | Description | Example |
---|---|---|---|---|
merged_from_legal_entity | id | uuid | required | |
name | string | required | ||
edrpou | string | required | ||
merged_to_legal_entity | id | id | required | |
name | string | required | ||
edrpou | string | required | ||
reason | sring | required |
Request structure
API paragraph not found
Authorize
Verify the validity of access token
in case of error return 401 ('Access denied')
Check user scope legal_entity:merge in order to perform this action
in case of error generate 401 response ('Invalid scopes')
Headers
API paragraph not found
Request data validation
Validate Digital signature
Decode content that is encrypted in an electronic digital signature.
Use Digital signature WS. Method checks digital signature and returns result.
We need to check DS.
Get client_id from token. Find prm.legal_entities by client_id
Check EDRPOU matches prm.legal_entities.EDRPOU
Check if EDRPOU in Certificate details exists and not empty
Check if Certificate_details.EDRPOU=prm.legal_entities.EDRPOU
In case validation fails - generate 422 error
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
Verify role
Extract from token:
Validate client_id (is_blocked=false)
in case of error return 403 Error ('Client is blocked')
Check client_id is active
in case error return 403 - ('Client is not active')
Validate request
Validate merged_to legal_entity
Check legal entity exists and status='active'
in case of error return 409 error view $merged_to.id ('Merged to legal entity must be active')
Validate merged_to legal entity is not an active merged_from legal entity (select * from related_legal_entities where merged_from_id=$merged_to_id and is_active=true) returns empty result
in case of error return 409 error view $merged_to.id ('Merged to legal entity is in the process of reorganisation itself')
Validate merged_to.name from request=prm.legal_entites.$merged_to.id.name
in case of error return 422 error view $merged_to.name ('Invalid legal entity name')
Validate merged_to.edrpou from request=prm.legal_entites.$merged_to.id.edrpou
in case of error return 422 error view $merged_to.edrpou ('Invalid legal entity edrpou')
Validate merged_from legal_entity
Check merged from legal entity exists and status='active' or 'suspended'
in case of error return 409 error view $merged_from.id ('Merged from legal entity must be active or suspended')
Validate merged from legal entity is not in the process of reorganization (select * from related_legal_entities where merged_from_id=$merged_from_id and is_active=true) returns empty result
in case of error return 409 error view $merged_from.id ('Merged from legal entity is already in the process of reorganisation')
Validate merged from legal_entity.name from request=prm.legal_entites.$merged_from.id.name
in case of error return 422 error view $merged_from.name ('Invalid legal entity name')
Validate merged from legal_entity.edrpou from request=prm.legal_entites.$merged_from.id.edrpou
in case of error return 422 error view $merged_from.edrpou ('Invalid legal entity edrpou')
Validate merged_to_legal_entity.id<>merged_from_legal_entity.id
in case of error return 422 error view ('Legator and successor legal entities must be different')
Validate merged_to.legal_entity_type and merged_from.legal_entity_type. Valid type transitions see in the table below.
in case of error return 422 error view ('Invalid legal entity type')
Valid type transitions for legal entities
merged_from | merged_to |
---|---|
MSP | PRIMARY_CARE, MSP |
MSP_PHARMACY | MSP_PHARMACY |
PHARMACY | PHARMACY |
PRIMARY_CARE | PRIMARY_CARE, MSP |
OUTPATIENT | OUTPATIENT |
EMERGENCY | EMERGENCY |
Processing
Create job
Async job must be created and started (scope to get job - legal_entity_merge_job:read)
Job has next structure
field | type | M/O | description |
---|---|---|---|
id | UUID | M | job ID |
status | enum
| M | job status |
started_at | TIMESTAMP | M | the time when job was started |
ended_at | TIMESTAMP | O | the time when job was ended (if any) |
merged_from_legal_entity | jsonb | M | |
merged_to_legal_entity | jsonb | M |
The job must do next steps:
Save signed content to media storage
Get url for request upload.
ParameterSourceaction 'GET' bucket 'RELATED_LEGAL_ENTITIES' resource_id : RELATED_LEGAL_ENTITIES_ID resource_name : CREATE_RELATED_LEGAL_ENTITIES timestamp :TIMESTAMP Upload signed content to media storage
Search employees (employee_type='DOCTOR')
For each employee with type DOCTOR from merged from legal_entity take employee.speciality_officio and employee.party
select id as merged_from_employee_id, speciality.speciality, party_id from employees where legal_entity_id=$merged_from_id and employee_type='DOCTOR' and status='APPROVED'
and check whether exist at least one employee with same speciality_officio in merged_to_legal_entity
select id from employees where legal_entity_id=$merged_to_id and employee_type='DOCTOR' and status='APPROVED' and party_id=$party_id and speciality.speciality=$speciality.specialityIn case there is no such employee in merged_to_legal_entity change employee's status='DISMISSED' and set `status_reason`='auto_merge_legal_entity' from merged_from legal_entity.
Search declarations
1. For employees which weren't registered in merged_to legal_entity (employees which status were changed to DISMISSED
during search) find active declarations.
For found declarations by employee_id set
field | value |
---|---|
status | TERMINATED |
reason | auto_reorganization |
updated_at | now() |
updated_by | $user_id |
Update client type for request
Find MITHRIL.clients.id=$merged_from legal_entity.id and update: set MSP_Limited if LE type is MSP or PRIMARY_CARE, EMERGENCY, OUTPATIENT, PHARMACY, MSP_Pharmacy
field | value |
---|---|
update_at | now() |
client_type_id | $MSP_LIMITED_ID(3770c4b3-05cd-42d9-8e15-233b193aee86) |
Update merged_from legal entity status
Set merged_from legal entity status to 'reorganised'
Save request
Insert record to PRM.RELATED_LEGAL_ENTITIES
field | value |
---|---|
id | generate id |
merged_from_id | $merged_from.id |
merged_to_id | $merged_to.id |
is_active | true |
reason | $reason |
inserted_at | now() |
inserted_by | $user_id |
Response structure
In response can be received validation error or the job will be started.
Post-processing processes
API paragraph not found
HTTP status codes
API paragraph not found