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

IL.Create/Update Legal Entity V2 - Old

General

Key features and main differences from previous edition:

  • legal entity types and licenses are created/updated one by one, i.e. one legal entity type and one license are accepted in one call

  • medical_services_providers structure is removed, accreditation parameter is moved to edr_legal_entities table

  • legal entity type calculation rules are removed

  • validation and merge of kveds step is removed

  • mithrill AuthAPI call is changed

  • mis verification is removed

  • suspend contract on name change is removed

  • owner employee can be updated 

Lucidchart link

Service logic

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.  

    1. Validate request using JSON schema

      1. In case validation fails - generate 422 error

Validate owner updating

  1. If employee_id is passed in the owner block:

    1. search employee by employee_id (is_active = true)

      1. if not found return error 404, msg "Not found"

    2. check that employee_id correspond to legal_entity from payload

      1. if not correspond or legal entity not exist return 409, msg "Employee_id doesn't correspond to your legal entity")

    3. validate owner data

      1. validate birth_date

        1. if birth_date doesn't match with existing owners birth_date return error 409, msg "birth_date doesn't match"

      2. validate tax_id

        1. if tax_id doesn't match with existing owners tax_id return error 409, msg "tax_id doesn't match"

    4. validate employee_type

      1. employee_type = OWNER 

        1. if employee_type with other type return error 409, msg "employee_type doesn't match"

  2. if employee_id isn't passed in the payload need to create employee request with owners data

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, P257, P237, P238, P239, P247, P249"

Validate employee type

if $.employee_id is not null check that employee exists in DB and has type OWNER

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

Validate license

  1. Apply current validations which depends on license type - TBC (should be taken from code)

  2. Check license according to the schema below


Legal entity types license obligation and corresponding types



Legal Entity type

License needed

License type

Legal Entity type

License needed

License type

PRIMARY_CARE

Y

MSP

OUTPATIENT

Y

MSP

EMERGENCY

Y

MSP

PHARMACY

Y

PHARMACY

MIS

N



NHS

N





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

Parameter

Source

Parameter

Source

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 using id, received on step EDR Validation.

  2. Create or Update record in prm.edr_data for active EDR record data.

Search Legal Entity using EDRPOU from Signer Certificate

Search Legal Entity in prm.legal_entities using EDRPOU from Signer Certificate where legal_entities.type = Request: $.type and status = active or suspended

If Legal Entity not found go to Generate client and legal entity identifier

If Legal Entity found go to Update Client in Auth

 Update Client in Auth

Update Redirect URI

Update Legal Entity

See Service specification

Create/Update licenses

  1. If $.license_id is not null then

    1. Check if any attribute has changed comparing request and prm.licenses data. If any, 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_verified_change_date to current date

    2.  Update prm.licenses data according to received request

  2.  If $.license_id is null then create new record according to received request

    1. link license and edr_data record

Update legal_entities

  1. Update prm.legal_entities data according to received request

    1. link to the license if license_id is not null 

    2. populate updated_by, updated_at

  2. If nhs_reviewed = true reset it to false

  3. If nhs_verified = true reset it to false and set nhs_verified_change_date to current date

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

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"

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

See Service specification

Create/Update licenses

  1. If $.license_id is not null then

    1. Check if any attribute has changed comparing request and prm.licenses data. If any, 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_verified_change_date to current date

    2.  Update prm.licenses data according to received request

  2.  If $.license_id is null then create new record according to received request

    1. link license and edr_data record

Populate legal_entities table

  1. Create new record according to received request

    1. Link it to the license

    2. Link it to edr_data record

  2. Set  `nhs_reviewed` and `nhs_verified` to false

  3. Set status = active suspended

  4. Set nhs_verified_change_date to current date

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 

Data sources which are using during creation of prm.legal_entities

Register employee

create or update new employee request with employee_type == 'OWNER'

Init IL.Create employee request

Mapping

Parameter

Source

Parameter

Source

employee_id

Request: $.employee_id

legal_entity_id

Generated previously

employee_type

Const: OWNER

position

Request: $.owner.position

status

Const: ACTIVE

start_date

now()

party

Request: $.owner









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