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

IL.Create/Update Legal Entity

Lucidchart link

Authorize user

  1. Validate MIS API Token
  2. Check MIS scopes legal_entity:write in order to perform this action
    1. In case error - generate 401 response

Digital signature

  1. Validate signature
  2. Extract signer Certificate details
  3. Save Signed Content

Validate Tax ID

  1. Check that EDRPOU in Certificate details exists and not empty
    1. Check that EDRPOU in Certificate details is valid according to ^[0-9]{8,10}$
    2. Check that EDRPOU in Certificate details is equal to EDRPOU in Legal Entity payload
      1. In case validation fails - generate 422 error
  2. If EDRPOU in Certificate details is empty check that DRFO exists and not empty
    1. Check that DRFO in Certificate details is valid according to ^[0-9]{9,10}$
    2. Check that DRFO in Certificate details is equal to EDRPOU in Legal Entity payload
      1. In case validation fails - generate 422 error
  3. In case EDRPOU and DRFO is empty return error 422, msg "EDRPOU and DRFO is empty in digital sign"

Validate Legal Entity request

    1. Validate request using JSON schema
      1. In case validation fails - generate 422 error


Validate KVEDS

Validate KVEDs allowed for registration according to Legal Entity type

  1. If Request: $.type = MSP, check that at least one KVED Request: $.kveds is in KVEDS_ALLOWED_MSP list
  2. If Request: $.type = PHARMACY, check that at least one KVED Request: $.kveds is in KVEDS_ALLOWED_PHARMACY list

Validate owners position

owners positions should be one of the list - env. configuration OWNER_POSITIONS.

At the moment it is - "P1, P2, P3, P32, P4, P6, P5, P18, P19, P22, P23, P24, P25, P26, P229, P230, P231, P232, P233, P234, P235, P236, P240"

At the moment it is - "P1, P2, P3, P32, P4, P6, P5, P18, P19, P22, P23, P24, P25, P26, P229, P230, P231, P232, P233, P234, P235, P236, P240, P257"

EDR Validation

The data provided by MIS during LE registration must matches with the data stored in EDR

General rules

  1. LE must be registered in EDR
  2. LE must be active in EDR
  3. If new LE type is created then no active or suspended LE type should exist in e-Health with same EDRPOU and different edr_id as active record in EDR

Implementation

TBC

Save signed content

Generate RESOURCE_NAME for signed content

Generate RESOURCE_ID for Legal Entity

Invoke Media Content Storage to get upload URL for the document

ParameterSource
action'PUT'
bucket'LEGAL_ENTITIES'
resource_id:RESOURCE_NAME
resource_name:RESOURCE_ID

Upload file via Google Cloud API

Refresh EDR Data

  1. Get detailed data from EDR for active EDR record: call EDR data validation#Getdetailedinformation using id, received on step EDR Validation.
  2. Create or Update record in prm.edr_data for active EDR record data.

Mapping

eHealthEDR
edr_id$.id
name$.names.name
short_name$.names.short
public_name$.names.display
legal_form$.olf_code
kveds$.activity_kinds
registration_address$.address
state$.state

Search Legal Entity using EDRPOU from Signer Certificate

Search Legal Entity in prm.legal_entities using EDRPOU from Signer Certificate where (legal_entities.type =  $.type or legal_entities.type = 'PRIMARY_CARE' if $.type ='MSP') and status = active or suspended

    1. In case record found go to Update Client in Auth
    2. In case record not found go to Generate client and legal entity identifier

Request parameters:

ParameterSourceDescription
EDRPOUSigner certificateExtracted from public signer certificate


Search sample
curl -X GET http://private.domain/api/legal_entities?edrpou=34108665

See Service specification

 Update Client in Auth

Update Redirect URI

Update Legal Entity

Update legal_entities (see Table specs)

  1. Change the record according to received request
    1. Some of the fields must not be changed. This fields must be excluded from PATCH request: EDRPOU, TYPE 
    2. set accreditations = Request: $.medical_services_providers.accreditations
    3. save residence address into legal_entities.residence_address
  2. If nhs_reviewed = true reset it to false

Update licenses (see Table specs)

  1. Search for a record in prm.licenses for current legal entity  
    1. Check if any attribute has changed comparing request and prm data. If yes, then:
      1. For each record in prm.legal_entities related to the license:
        1. If nhs_reviewed = true reset it to false
        2. If nhs_verified = true
          1. reset it to false
          2. set `nhs_unverified_at`  to current date
    2. Update license data according to the request

See Service specification

Update LE official name

Extract official name from Digital signature. 

  • Update `legal_entities.public_name` in prm with official name from Digital signature
  • Update `clients.name` in mithril with official name from Digital signature 

Update Contract Request

  1. Find contract requests related to current legal entity in status = NEW, APPROVED, PENDING_NHS_SIGN, NHS_SIGNED, set status = 'TERMINATED', status_reason "Legal Entity Data has changed"

Reset flags

Update Contract

In case Legal Entity already exists in DB we need to check whether next fields weren't changed:

  • name
  • addresses (any field in array)
  • status

Compare fields in prm.legal_entities and in request. In case any of the fields above were changed

find contracts by contractor_legal_entity_id=$legal_entities.id  and status='VERIFIED'. Set ops.contracts.is_suspended=true

 Generate client and legal entity identifier

Generate UUID as client identifier and legal entity identifier

Create client and connection in Auth

  1. Invoke Auth API (idempotent PUT) to register new client and generate client secret key
  2. Determine MIS_ID (consumer_id) using api-key
  3. Invoke Put client connection in order to UpSet connection in Mithril for this client and consumer

Create new Legal Entity

Populate licenses table (see Table specs)

  1. select licenses.id from prm.licenses where type = $.type and id in (select license_id from legal_entities where edr_data_id in (select id from edr_data where edr_id = active edr id))
    1. If record found then
      1. check if any attribute has changed comparing request and prm data. If yes, then:
        1. For each record in prm.legal_entities related to the license:
          1. If nhs_reviewed = true reset it to false
          2. If nhs_verified = true
            1. reset it to false
            2. set `nhs_unverified_at` to current date
      2. Update license data according to the request
    2. if record not found then create new record:
      1. set 'licenses.type' = MSP if Request: $.type = MSP 
      2. set 'licenses.type' = PHARMACY if Request: $.type = PHARMACY
      3. set 'licenses.is_active' = true and populate inserted_by, inserted_at, updated_by, updated_at fields
      4. set issued_by, issued_date, expiry_date, active_from_date, what_licensed, order_no according to Request: $.medical_services_providers.licenses data
      5. Link created record and edr_data record 

Populate legal_entities table (see Table specs)

  1. Create new record according to received request 
    1. Link created record and edr_data record
    2. Link created record and license 
    3. set accreditations = Request: $.medical_services_providers.accreditations
    4. save registration_address separately
    5. set nhs_verified, nhs_reviewed to false
    6. set `nhs_unverified_at` to current date
    7. set status = active suspended

See Service specification

Save LE official name

Extract official name from Digital signature. 

  • Save LE official name to prm DB = legal_entities.public_name 
  • Save LE official name to mithril DB = clients.name 

Check UKR_MED_REGISTRY

Manual verification is not required if Legal Entity is in Registry

    1. Search EDRPOU in UKR_MED_REGISTRY with corresponding type

See Service specification

Set Legal Entity mis_verified to VERIFIED

Set mis_verified to VERIFIED for PRM.legal_entity if Legal Entity is in Registry

Request parameters:

ParameterSourceDescription
idCreate new Legal Entity, Search Legal Entity using Tax ID from Signer Certificate

mis_verified

Const: VERIFIEDConstant value


Set Legal Entity mis_verified to NOT_VERIFIED

Set mis_verified to NOT_VERIFIED for PRM.legal_entity  if Legal Entity is not in Registry

Request parameters:

ParameterSourceDescription
idCreate new MSP, Search MSP using Tax ID from Signer Certificate
mis_verifiedConst: NOT_VERIFIEDConstant value


Register new employee

Init IL.Create employee request

Determine employee_type

If legal_entity_types.type == MSP:
	Employee_type = OWNER
If legal_entity_types.type == PHARMACY:
	Employee_type = PHARMACY_OWNER


Mapping

ParameterSource
legal_entity_idGenerated previously legal_entities.id

employee_type

Variable: Employee_type

position

Request: $.owner.position

status

Const: PENDING_VERIFICATION

start_date

now()

party

Request: $.owner

Except: $.owner.position




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