ЕСОЗ - публічна документація
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
Validate MIS API Token
Check MIS scopes legal_entity:write in order to perform this action
In case error - generate 401 response
Digital signature
Validate signature
Extract signer Certificate details
Save Signed Content
Validate Tax ID
Check that EDRPOU in Certificate details exists and not empty
Check that EDRPOU in Certificate details is valid according to ^[0-9]{8,10}$
Check that EDRPOU in Certificate details is equal to EDRPOU in Legal Entity payload
In case validation fails - generate 422 error
If EDRPOU in Certificate details is empty check that DRFO exists and not empty
Check that DRFO in Certificate details is valid according to ^[0-9]{9,10}$
Check that DRFO in Certificate details is equal to EDRPOU in Legal Entity payload
In case validation fails - generate 422 error
In case EDRPOU and DRFO is empty return error 422, msg "EDRPOU and DRFO is empty in digital sign"
Validate Legal Entity request
Validate request using JSON schema
In case validation fails - generate 422 error
Validate owner updating
If employee_id is passed in the owner block:
search employee by employee_id (is_active = true)
if not found return error 404, msg "Not found"
check that employee_id correspond to legal_entity from payload
if not correspond or legal entity not exist return 409, msg "Employee_id doesn't correspond to your legal entity")
validate owner data
validate birth_date
if birth_date doesn't match with existing owners birth_date return error 409, msg "birth_date doesn't match"
validate tax_id
if tax_id doesn't match with existing owners tax_id return error 409, msg "tax_id doesn't match"
validate employee_type
employee_type = OWNER
if employee_type with other type return error 409, msg "employee_type doesn't match"
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
LE must be registered in EDR
LE must be active in EDR
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
Apply current validations which depends on license type - TBC (should be taken from code)
Check license according to the schema below
Legal entity types license obligation and corresponding types
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 |
---|---|
action | 'PUT' |
bucket | 'LEGAL_ENTITIES' |
resource_id | :RESOURCE_NAME |
resource_name | :RESOURCE_ID |
Upload file via Google Cloud API
Refresh EDR data
Get detailed data from EDR for active EDR record: call EDR data validation using id, received on step EDR Validation.
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
Create/Update licenses
If $.license_id is not null then
Check if any attribute has changed comparing request and prm.licenses data. If any, then:
For each record in prm.legal_entities related to the license:
If nhs_reviewed = true reset it to false
If nhs_verified = true
reset it to false
set nhs_verified_change_date to current date
Update prm.licenses data according to received request
If $.license_id is null then create new record according to received request
link license and edr_data record
Update legal_entities
Update prm.legal_entities data according to received request
link to the license if license_id is not null
populate updated_by, updated_at
If nhs_reviewed = true reset it to false
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
Invoke Auth API (idempotent PUT) to register new client and generate client secret key
Determine MIS_ID (consumer_id) using api-key
Invoke Put client connection in order to UpSet connection in Mithril for this client and consumer
Create new Legal Entity
Create/Update licenses
If $.license_id is not null then
Check if any attribute has changed comparing request and prm.licenses data. If any, then:
For each record in prm.legal_entities related to the license:
If nhs_reviewed = true reset it to false
If nhs_verified = true
reset it to false
set nhs_verified_change_date to current date
Update prm.licenses data according to received request
If $.license_id is null then create new record according to received request
link license and edr_data record
Populate legal_entities table
Create new record according to received request
Link it to the license
Link it to edr_data record
Set `nhs_reviewed` and `nhs_verified` to false
Set status = active suspended
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 |
---|---|
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 |
ЕСОЗ - публічна документація