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

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 28 Next »


Specification

Schemas:

legalEntities.graphql

legalEntityMergeJobs.graphql

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

Input parameters

Input is signed data in PKCS7 format. The data must be unpacked and validated using Json Schema.

Fields to sign:

field
type
merged_from_legal_entityiduuidrequired

namestringrequired

edrpoustringrequired
merged_to_legal_entityididrequired

namestringrequired

edrpoustringrequired
reason
sringrequired

Authorize

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

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. 

  1. Get client_id from token. Find prm.legal_entities by client_id
    1. Check EDRPOU matches prm.legal_entities.EDRPOU
      1. Check if  EDRPOU in Certificate details exists and not empty
        1. Check if  Certificate_details.EDRPOU=prm.legal_entities.EDRPOU
      2. In case validation fails - generate 422 error
  2. Get parties.tax_id using party_users.party_id by user_id.
    1. 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
    2. In case validation fails - generate 422 error

Verify role

Extract from token:

  1. Validate client_id (is_blocked=false)
    1. in case of error return 403 Error ('Client is blocked')
  2. Check client_id is active
    • in case error return 403 - ('Client is not active')

Validate request

  1. Validate merged_to legal_entity
    1. Check legal entity exists and status='active' 
      1. in case of error return 409  error view $merged_to.id ('Merged to legal entity must be active')
    2. 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
      1. in case of error return 409  error view $merged_to.id ('Merged to legal entity is in the process of reorganisation itself')
    3. Validate merged_to.name from request=prm.legal_entites.$merged_to.id.name
      1. in case of error return 422  error view $merged_to.name ('Invalid legal entity name')
    4. Validate merged_to.edrpou from request=prm.legal_entites.$merged_to.id.edrpou
      1. in case of error return 422  error view $merged_to.edrpou ('Invalid legal entity edrpou')
  2. Validate merged_from legal_entity
    1. Check merged from legal entity exists and status='active' or 'suspended'
      1. in case of error return 409  error view $merged_from.id ('Merged from legal entity must be active or suspended')
    2. 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
      1. in case of error return 409  error view $merged_from.id ('Merged from legal entity is already in the process of reorganisation')
    3. Validate merged from legal_entity.name from request=prm.legal_entites.$merged_from.id.name
      1. in case of error return 422  error view $merged_from.name ('Invalid legal entity name')
    4. Validate merged from legal_entity.edrpou from request=prm.legal_entites.$merged_from.id.edrpou
      1. in case of error return 422  error view $merged_from.edrpou ('Invalid legal entity edrpou')
    5. Validate merged_to_legal_entity.id<>merged_from_legal_entity.id
      1. in case of error return 422  error view ('Legator and successor legal entities must be different')
  3. Validate merged_to.legal_entity_type and merged_from.legal_entity_type. Valid type transitions see in the table below.
    1. in case of error return 422  error view ('Invalid legal entity type')

Valid type transitions for legal entities

merged_frommerged_to
MSPPRIMARY_CARE, MSP
MSP_PHARMACYMSP_PHARMACY
PHARMACYPHARMACY
PRIMARY_CAREPRIMARY_CARE, MSP
OUTPATIENTOUTPATIENT
EMERGENCYEMERGENCY

Response

In response can be received validation error or the job will be started.

Create job 

Async job must be created and started (scope to get job - legal_entity_merge_job:read)

Job has next structure

fieldtypeM/Odescription 
idUUIDMjob ID
statusenum
  • PENDING
  • ERROR
  • PROCESSED
Mjob status
started_atTIMESTAMPMthe time when job was started
ended_atTIMESTAMPOthe time when job was ended (if any)
merged_from_legal_entityjsonbM
merged_to_legal_entityjsonbM


The job must do next steps:

Save signed content to media storage

  1. Get url for request upload.

    Parameter
    Source
    action'GET'
    bucket'RELATED_LEGAL_ENTITIES'
    resource_id: RELATED_LEGAL_ENTITIES_ID
    resource_name: CREATE_RELATED_LEGAL_ENTITIES
    timestamp:TIMESTAMP
  2. Upload signed content to media storage


Search employees (employee_type='DOCTOR')

  1. 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.speciality

    1. In 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

fieldvalue
statusTERMINATED
reasonauto_reorganization
updated_atnow()
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

fieldvalue
update_atnow()
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


fieldvalue
idgenerate id
merged_from_id$merged_from.id
merged_to_id$merged_to.id
is_activetrue
reason$reason
inserted_atnow()
inserted_by$user_id
  • No labels