Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

REST API method / Метод REST API (настанова) (remove the link block before publishing the document)

...

Page Properties
idpage_properties_method_REST API

Document type

Метод REST API

Document title

[Document status] REST API [Назва методу] [ID методу]

Guideline ID

GUI-0011

Author

@

Document version

1

Document status

DRAFT

Date of creation

ХХ.ХХ.ХХХХ (дата фінальної версії документа – RC або PROD)

Date of update

ХХ.ХХ.ХХХХ (дата зміни версії)

Method API ID

API-005-009-002-0178

Microservices (namespace)

IL

Component

Legal Entities

Component ID

COM-005-009

Link на API-специфікацію

https://ehealthmisapi1.docs.apiary.io/#reference/dummy-methods/dummy-for-legal-entity/create/update-legal-entity-v2

Resource

{{host}}/api/v2/legal_entities

Scope

legal_entity:write

Protocol type

REST

Request type

PUT

Sync/Async

Sync

Public/Private

Public

...

  1. Save signed content to media storage.

  2. Get detailed data from EDR for active EDR record of legal entity (described at EDR data validation )

  3. Create or update edr_data record based on logic:

    1. If active EDR record of legal entity exists in edr_data table in PRM DB (edr_data.edr_id = $.id of EDR response), update record in edr_data table with following fields from EDR response:

      1. name = names.display

      2. short_name = names.short

      3. public_name = names.name

      4. legal_form = olf_code

      5. kveds = activity_kinds

      6. registration_address = address

      7. updated_by = consumer_id from MIS API token

      8. updated_at = now()

    2. If active EDR record of legal entity does not exist in edr_data table in PRM DB (edr_data.edr_id = $.id of EDR response), create new record in edr_data table with following fields from EDR response:

      1. id = generate (uuid)

      2. edr_id = id

      3. name = names.display

      4. short_name = names.short

      5. public_name = names.name

      6. legal_form = olf_code

      7. kveds = activity_kinds

      8. registration_address = address

      9. is_active = true

      10. inserted_by = consumer_id from MIS API token

      11. updated_by = consumer_id from MIS API token

      12. inserted_at = now()

      13. updated_at = now()

  4. Generate legal_entity_id that will be used also as client_id

  5. Create new record in legal_entities table in PRM DB according to received request, also add following fields:

    1. id = legal_entity_id

    2. name = edr_data.name from created EDR data record

    3. public_name = edr_data.public_name from created EDR data record

    4. short_name = edr_data.short_name from created EDR data record

    5. status = value according to LEGAL_ENTITY_CREATE_STATUS chart parameter (described at Legal Entities configurable parameters )

    6. is_active = true

    7. inserted_by = consumer_id from MIS API token

    8. updated_by = consumer_id from MIS API token

    9. inserted_at = now()

    10. updated_at = now()

    11. created_by_mis_client_id = client_id from MIS API token

    12. nhs_unverified_at = now()

    13. nhs_verified = false

    14. nhs_reviewed = false

    15. edr_data_id = edr_data.id from created EDR data record

  6. Create new record in licenses table in PRM DB according to received request, also add following fields:

    1. is_primary = true

    2. legal_entity_id = legal_entities.id

    3. is_active = true

    4. inserted_by = consumer_id from MIS API token

    5. updated_by = consumer_id from MIS API token

    6. inserted_at = now()

    7. updated_at = now()

  7. Create employee request for owner according to 1f1fa-1f1e6Create employee request v2

  8. Create client details and connection in MITHRIL DB:

    1. Generate client record using legal_entities.id in MITHRIL DB.

    2. Get consumer_id from MIS API token

    3. Create client connection in MITHRIL DB for client and consumer

  9. Create response with following data

    1. Legal entity, primary license and edr data details

    2. Created employee request id

    3. Client connection details

...

  1. Save signed content to media storage

  2. Get detailed data from EDR for active EDR record (described at EDR data validation )

  3. Create or update edr_data record based on logic:

    1. If active EDR record of legal entity exists in edr_data table in PRM DB (edr_data.edr_id = $.id of EDR response) and corresponds to legal entity that is being updated (legal_entities.edr_data_id=edr_data.id), update record in edr_data table with following fields from EDR response:

      1. name = names.display

      2. short_name = names.short

      3. public_name = names.name

      4. legal_form = olf_code

      5. kveds = activity_kinds

      6. registration_address = address

      7. updated_by = consumer_id from MIS API token

      8. updated_at = now()

    2. If active EDR record of legal entity does not exist in edr_data table in PRM DB (edr_data.edr_id = $.id of EDR response), create new record in edr_data table with following fields from EDR response:

      1. id = generate (uuid)

      2. edr_id = id

      3. name = names.display

      4. short_name = names.short

      5. public_name = names.name

      6. legal_form = olf_code

      7. kveds = activity_kinds

      8. registration_address = address

      9. is_active = true

      10. inserted_by = consumer_id from MIS API token

      11. updated_by = consumer_id from MIS API token

      12. inserted_at = now()

      13. updated_at = now()

  4. If edr_data.state is not in ACTIVE_EDR_STATES chart parameter, update legal entity status in legal_entities table (PRM DB):

    1. status = ‘SUSPENDED’

    2. status_reason = 'MANUAL_LEGAL_ENTITY_STATUS_UPDATE'

  5. If legal entity status was changed to SUSPENDED:

    1. terminate related capitation contract requests

    2. suspend related capitation contracts

  6. Update license with following logic:

    1. If $.license_id is null then

      1. Check if any attribute has changed comparing request and licenses data. If any, then:

        1. Update license data in licenses table (PRM DB) according to received request for is_primary license record, additionally:

          1. updated_by = consumer_id from MIS API token

          2. updated_at = now()

        2. For legal entity record in legal_entities related to the primary license, update following parameters in PRM DB:

          1. set nhs_reviewed = false

          2. set nhs_verified = false

          3. set nhs_unverified_at = now()

    2. If $.license_id is not null then skip license update

  7. Update legal_entities data in PRM DB according to received request, also update following fields:

    1. name = edr_data.name from created EDR data record (if edr_data was updated)

    2. public_name = edr_data.public_name from created EDR data record (if edr_data was updated)

    3. short_name = edr_data.short_name from created EDR data record (if edr_data was updated)

    4. updated_by = consumer_id from MIS API token

    5. updated_at = now()

    6. edr_data_id = edr_data.id from created EDR data record (if edr_data was updated)

  8. Create employee request for owner according to 1f1fa-1f1e6Create employee request v2

  9. Update client details and connection in MITHRIL DB:

    1. Get consumer_id from MIS API token

    2. Create new client connection in MITHRIL DB for client and consumer_id

  10. Create response with following data

    1. Legal entity, primary license and edr data details

    2. Created employee request id

    3. Client connection details

  11. Update accreditation with following logic:

    1. if "category": "NO_ACCREDITATION" than check if only required fields are filled, also update following fields:

      1. “issued_date” set null

      2. “expiry_date" set null

      3. “order_date" set null

    2. if it is another category- update all fields with the values ​​they were filled with

Configuration parameters

Description of the configuration parameters that are used when processing a request in the system

Dictionaries

Provides a list of links to dictionaries that are available in ConfluenceN/A

Dictionaries

N/A

Input parameters

Input parameter

Mandatory

Type

Description

Example

1

2

Request structure

See on API-specification

Expand
titleExample
Code Block
languagejson
{
  "signed_legal_entity_request": "...",
  "signed_content_encoding": "base64"
}

Headers

...

Key

...

Value

...

Mandatory

...

Description

...

Example

...

Content-Type

...

application/json

...

M

...

Тип контенту

...

Content-Type:application/json

...

Authorization

...

Bearer c2778f3064753ea70de870a53795f5c9

...

M

...

Перевірка користувача

...

Authorization:Bearer c2778f3064753ea70de870a53795f5c9

...

Headers

Request data validation

Authorize

...

  • Validate decoded input data is signed

    • in case of error - return 422 (“document must contain 1 signature and 0 stamps but contains 0 signatures and 0 stamps”)

  • Check DS is valid and not expired

  • Check that Last Name from DS and Owner last_name from request matches

    • in case of error - return 422 (“Does not match the signer last name“)

  • If EDRPOU in Certificate details exists and not empty

    • Check that EDRPOU in Certificate details is valid according to ([0-9]{8,10}|[А-ЯЁЇIЄҐ]{2}\d{6}) regular expression

      • in case of error - return 422 (“string does not match pattern")

    • Check that EDRPOU in Certificate details is equal to $.edrpou in payload

      • in case of error - return 422 (“EDRPOU does not match legal_entity edrpou“)

  • If EDRPOU in Certificate details is empty and if DRFO in Certificate detailsexists and not empty

    • Check that DRFO in Certificate details is valid according to ([0-9]{9,10}|[А-ЯЁЇIЄҐ]{2}\d{6}) regular expression

      • in case of error - return 422 (“string does not match pattern")

    • Check that DRFO in Certificate details is equal to $.edrpou in payload

      • in case of error - return 422 (“DRFO does not match signer drfo“)

  • If EDRPOU and DRFO in Certificate details are empty - return 422 (“EDRPOU and DRFO is empty in digital sign“)

...

Validate owner

Validate tax_id

  • If $.owner.no_tax_id does not exists in request or exists and equals false, check that $.owner.tax_id is valid according to ^[0-9]{10}$ regular expression

    • in case of error - return 422 (“invalid tax_id value“)

  • If $.owner.no_tax_id equals true, check that $.owner.tax_id is valid according to ([0-9]{9}|[А-ЯЁЇIЄҐ]{2}\d{6}) regular expression

    • in case of error - return 422 (“invalid tax_id value”)

Validate birth date

  • Check that $.owner.birth_date is greater than MIN_BIRTH_DATE chart parameter

    • in case of error - return 422 (“invalid birth_date value”)

  • Check that owners age is greater than MIN_AGE chart parameter

    • in case of error - return 422 (“invalid birth_date value”)

...

  • Check that employee with id = $.owner.employee_id exists in PRM DB

    • in case of error - return 422 (“Employee not found“)

  • Check that employee with id = $.owner.employee_id corresponds to Legal entity from payload

    • in case of error - return 409 (“Employee doesn't belong to your legal entity“)

  • Check that employee with id = $.owner.employee_id is an employee with employee_type = ‘OWNER’ or ‘PHARMACY_OWNER’

    • in case of error - return 409 (“Invalid employee type”)

  • Check that employee with id = $.owner.employee_id is an employee with status = ‘APPROVED’ and is_active = true

    • in case of error - return 409 (“Invalid employee status“)

  • Check $.owner.tax_id from request is equal to parties.tax_id for $.owner.employee_id

    • in case of error - return 409 (“tax_id doesn't match“)

  • Check $.owner.tax_id from request is not empty if parties.tax_id for $.owner.employee_id is not empty:

    • in case of error - return 422 (“required property tax_id was not present“)

  • Check $.owner.birth_date from request is equal to parties.birth_date of $.owner.employee_id

    • in case of error - return 409 (“birth_date doesn't match“)

  • If parties.no_tax_id for $.owner.employee_id is true check $.owner.tax_id from request:

    • $.owner.tax_id is valid according to ([0-9]{9}|[А-ЯЁЇIЄҐ]{2}\d{6}) regular expression

      • in case of error - return 422 (“string does not match pattern \"^([0-9]{9,10}|[А-ЯЁЇIЄҐ]{2}\\d{6})$\"”)

Validate legal entity with EDR

...

Check license according to the schema below.

License from request must be validated with related primary license (licenses.is_primary=true where licenses.legal_entity_id=legal_entities.id).

...

Check if license is needed for legal entity type is performed based on LEGAL_ENTITY_<LEGAL_ENTITY_TYPE>_PRIMARY_LICENSE_TYPES chart parameter (described at Legal Entities configurable parameters )

Processing

Save signed content

...

Response structure examples

See on API-specification

Expand
titleExample
Code Block
languagejson
{
  "meta": {
    "code": 200,
    "url": "https://example.com/resource",
    "type": "object",
    "request_id": "req-adasdoijasdojsda"
  },
  "data": {
    "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
    "edr": {
      "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
      "name": "Клініка Ноунейм",
      "short_name": "Ноунейм",
      "public_name": "Ноунейм",
      "legal_form": "140",
      "edrpou": "54323454",
      "kveds": [
        {
          "name": "Діяльність лікарняних закладів",
          "code": "86.10",
          "is_primary": true
        }
      ],
      "registration_address": {
        "zip": "02090",
        "country": "УКРАЇНА",
        "address": "Волинська обл., місто Луцьк ВУЛИЦЯ КОНЯКІНА буд. 14 кв. 144",
        "parts": {
          "atu": "Волинська обл., місто Луцьк",
          "atu_code": "0710100000",
          "street": "ВУЛИЦЯ КОНЯКІНА",
          "house_type": "буд.",
          "house": "14",
          "building_type": "null",
          "building": "``",
          "num_type": "кв.",
          "num": "144"
        }
      },
      "state": 1
    },
    "edrpou": "32323454",
    "type": "PRIMARY_CARE",
    "residence_address": {
      "type": "RESIDENCE",
      "country": "UA",
      "area": "Житомирська",
      "region": "Бердичівський",
      "settlement": "Київ",
      "settlement_type": "CITY",
      "settlement_id": "b075f148",
      "street_type": "STREET",
      "street": "вул. Ніжинська",
      "building": "15",
      "apartment": "23",
      "zip": "02090"
    },
    "phones": [
      {
        "type": "MOBILE",
        "number": "+380503410870"
      }
    ],
    "email": "email@example.com",
    "website": "www.msp.com.ua",
    "receiver_funds_code": "12345",
    "beneficiary": "Борисов Борис Борисович",
    "accreditation": {
      "category": "SECOND",
      "issued_date": "2017-02-28",
      "expiry_date": "2017-02-28",
      "order_no": "fd123443",
      "order_date": "2017-02-28"
    },
    "license": {
      "id": "b075f148-7f93-4fc2-b2ec-2d81b19a9b7b",
      "type": "MSP",
      "license_number": "fd123443",
      "issued_by": "Кваліфікацйна комісія",
      "issued_date": "2017-02-28",
      "expiry_date": "2017-02-28",
      "active_from_date": "2017-02-28",
      "what_licensed": "реалізація наркотичних засобів",
      "order_no": "ВА43234"
    },
    "archive": [
      {
        "date": "2017-02-28",
        "place": "вул. Грушевського 15"
      }
    ],
    "public_offer": {
      "consent_text": "Consent text",
      "consent": true
    },
    "status": "ACTIVE",
    "nhs_verified": false,
    "nhs_reviewed": false,
    "nhs_comment": "comment"
  },
  "urgent": {
    "security": {
      "secret_key": "secret_key",
      "client_id": "client_id",
      "redirect_uri": "redirect_uri"
    },
    "employee_request_id": "d098aee7-5ab3-4a24-a6ba-811f9cf94c6d"
  }
}

...

Post-processing processes

Description of actions performed on data after processingN/A

Technical modules where the method is used

List of pages describing technical modules where the method is usedN/A

Page Properties Report
headingsID ТМ, Статус
cqllabel = "tr-mis"

...