Table of Contents
minLevel1
maxLevel7

Purpose

This method allows to create Composition of all types and categories for a person/pre-person in eHealth.

Used in processes:

2.1. МВН - Створення нового

2.2. МВТН - Створення нового

Specification

...

Link

...

https://app.swaggerhub.com/apis/ehealthua/compositions/2.32.2#/main/createComposition

...

Resource

...

/patients/composition

...

Scope

...

composition:create

...

Components

...

Compositions

...

Using Dictionaries

...

COMPOSITION_CATEGORIES

COMPOSITION_TYPES

COMPOSITION_EVENTS

eHealth/resources

...

Using Microservices

...

API paragraph not found

...

Protocol type

...

REST

...

Request type

...

POST

...

Sync/Async

...

Async

...

Public/Private/Internal

...

Public

Logic

...

Expand
titleSequence:

MIS/Medical employee->Compositions: Create Composition POST/patients/composition
Compositions->Compositions: Check user scopes authorization composition:create
Compositions-->MIS/Medical employee: In case of error HTTP/401
Compositions->Compositions: Async job planning
Compositions->MIS/Medical employee: Async job details
Compositions<->eHealth:data clarification and verification about author, custodsan, diagnosis etc
Compositions->Compositions:Create and save Composition according to the XML template
Compositions->Compositions:Async job Completed
MIS/Medical employee->Compositions: GET/patients/composition/job/{asyncJobId}
Compositions->MIS/Medical employee:Async job completed (conclusionAsyncJobListItem.href)
MIS/Medical employee->Compositions:GET/patients/{patientId}/composition/{compositionId}/episode/{episodeId}/encounter/{encounterId}
Compositions->MIS/Medical employee: Composition in PRELIMINARY status
MIS/Medical employee->MIS/Medical employee:Signs document and gives to patient
MIS/Medical employee->Compositions:Sign Composition PATCH /patients/composition/{compositionId}/sign
Compositions->Compositions:Check user scopes authorization composition:sign
Compositions-->MIS/Medical employee: In case of error HTTP/401
Compositions->MIS/Medical employee: HTTP/200 Async job Created
Compositions<->eHealth:Signature and author validation
Compositions->Compositions:Save object on SWIFT/S3
Compositions->Compositions:Schedule of trigger interactions (DIIA,MJU_DRACZ,ERLN,MPI,Closure)
MIS/Medical employee->Compositions:GET /patients/composition/job/{asyncJobId}
Compositions->MIS/Medical employee:Async job completed (conclusionAsyncJobListItem.href)
MIS/Medical employee->Compositions:GET/patients/{patientId}/composition/{compositionId}/episode/{episodeId}/encounter/{encounterId}
Compositions->MIS/Medical employee:Composition in FINAL status

Dictionaries

COMPOSITION_CATEGORIES

COMPOSITION_TYPES

COMPOSITION_EVENTS

eHealth/resources

Request structure

See on SwaggerHub

Example

...

titleRequest example

...

Table of Contents
minLevel1
maxLevel7

Purpose

This method allows to create Composition of all types and categories for a person/pre-person in eHealth.

Used in processes:

2.1. МВН - Створення нового

2.2. МВТН - Створення нового

Specification

Link

https://app.swaggerhub.com/apis/ehealthua/compositions/2.32.2#/main/createComposition

Resource

/patients/composition

Scope

composition:create

Components

Compositions

Using Dictionaries

COMPOSITION_CATEGORIES

COMPOSITION_TYPES

COMPOSITION_EVENTS

eHealth/resources

Using Microservices

API paragraph not found

Protocol type

REST

Request type

POST

Sync/Async

Async

Public/Private/Internal

Public

Logic

...

Expand
titleSequence:

MIS/Medical employee->Compositions: Create Composition POST/patients/composition
Compositions->Compositions: Check user scopes authorization composition:create
Compositions-->MIS/Medical employee: In case of error HTTP/401
Compositions->Compositions: Async job planning
Compositions->MIS/Medical employee: Async job details
Compositions<->eHealth:data clarification and verification about author, custodsan, diagnosis etc
Compositions->Compositions:Create and save Composition according to the XML template
Compositions->Compositions:Async job Completed
MIS/Medical employee->Compositions: GET/patients/composition/job/{asyncJobId}
Compositions->MIS/Medical employee:Async job completed (conclusionAsyncJobListItem.href)
MIS/Medical employee->Compositions:GET/patients/{patientId}/composition/{compositionId}/episode/{episodeId}/encounter/{encounterId}
Compositions->MIS/Medical employee: Composition in PRELIMINARY status
MIS/Medical employee->MIS/Medical employee:Signs document and gives to patient
MIS/Medical employee->Compositions:Sign Composition PATCH /patients/composition/{compositionId}/sign
Compositions->Compositions:Check user scopes authorization composition:sign
Compositions-->MIS/Medical employee: In case of error HTTP/401
Compositions->MIS/Medical employee: HTTP/200 Async job Created
Compositions<->eHealth:Signature and author validation
Compositions->Compositions:Save object on SWIFT/S3
Compositions->Compositions:Schedule of trigger interactions (DIIA,MJU_DRACZ,ERLN,MPI,Closure)
MIS/Medical employee->Compositions:GET /patients/composition/job/{asyncJobId}
Compositions->MIS/Medical employee:Async job completed (conclusionAsyncJobListItem.href)
MIS/Medical employee->Compositions:GET/patients/{patientId}/composition/{compositionId}/episode/{episodeId}/encounter/{encounterId}
Compositions->MIS/Medical employee:Composition in FINAL status

Dictionaries

COMPOSITION_CATEGORIES

COMPOSITION_TYPES

COMPOSITION_EVENTS

eHealth/resources

Request structure

See on SwaggerHub

Example

Expand
titleRequest example
Code Block
{
  "category": {
    "coding": [
      {
        "codesystem": "personCOMPOSITION_CATEGORIES",
        "code": "SICKNESS"
}      }
    ]
  },
  "type": {
    "textcoding": "string"[
      {
},        "valuesystem": "52b504c7-0177-4078-834b-52d89154081c"COMPOSITION_TYPES",
    }   }, "code":  "extensionTEMP_DISABILITY":
 [     {}
    ]
 "valueCode": "AUTHORIZE_WITH",
   },
  "event": [
   "valueUuid": "e7ff2eef-712f-4676-960d-6aa16dce2103" {
    },  "code": {
 {       "valueCodecoding": "IS_ACCIDENT",[
      "valueBoolean": true   {
 },     {       "valueCodesystem": "TREATMENTCOMPOSITION_VIOLATIONEVENTS",
            "valueStringcode": "rejectCOMPOSITION_VALIDITY_recommendationPERIOD"
    },     {
 }
        ]
      },
      "period": {
        "start": "2022-10-24T10:45:16Z",
        "valueCode": "TREATMENT_VIOLATION_DATE",
      "valueDate": "2022-10-24"
    },
    {
      "valueCode": "IS_INTOXICATED",
      "valueBoolean": true
    },
    {
      "valueCode": "IS_FOREIGN_TREATMENT",
      "valueBoolean": true
    },
    {
      "valueCode": "IS_FORCE_RENEW",
      "valueBoolean": true
    }
  ]
}

Authorize

Check user scopes in order to perform this action (scope = 'composition:create')

  • return 401 (Unauthorized) in case of invalid scope(s)

Headers

  • Content-Type: application/json

  • Authorization: Bearer {token}

  • api-key: {secret}

Validation data request

prechecks - Initial checks of request input data

...

If “relatesTo” isn’t null:

  1. For Newborn Composition:

    1. Validate that replacement is enabled

      1. In case of error (replacement isn’t enabled) - return 1181 (REPLACEMENT_FLOW_NOT_IMPLEMENTED_YET)

  2. For Temporary Disability Composition:

    1. If Composition.subject=person in current composition, Composition.subject = preperson in indicated composition in relatesTo.target.identifier and composition.status is FINAL, then the Refinement process is initiated

    2. If Composition.status in indicated composition in relatesTo.target.identifier is ENTERED_IN_ERROR and replacement is enabled, then the Raplacement process is initiated

      1. In case of error (replacement isn’t enabled) - return 1181 (REPLACEMENT_FLOW_NOT_IMPLEMENTED_YET)

    3. in other cases - return 1160 (INVALID_REPLACEMENT_ARGUMENT)

For Newborn Composition:

...

Checking for an already created Composition for preperson (“subject” attribute) which are according such requirements: Composition.type is Newborn and Composition.status isn’t ENTERED_IN_ERROR:

  1. In case of existing appropriate Compositions - return 1002 (COMPOSITION_ALREADY_EXISTS_FOR_SUBJECT)

...

end": "2022-10-28T10:45:16Z"
      }
    }
  ],
  "subject": {
    "type": {
      "coding": [
        {
          "system": "eHealth/resources",
          "code": "person"
        }
      ],
      "text": "string"
    },
    "value": "52b504c7-0177-4078-834b-52d89154081c"
  },
  "encounter": {
    "type": {
      "coding": [
        {
          "system": "eHealth/resources",
          "code": "encounter"
        }
      ],
      "text": "string"
    },
    "value": "e39ee5ae-2644-4f04-8e64-bb359866e907"
  },
  "author": {
    "type": {
      "coding": [
        {
          "system": "eHealth/resources",
          "code": "employee"
        }
      ],
      "text": "string"
    },
    "value": "43cc2161-1c2b-481b-a618-77e35817f850"
  },
  "section": {
    "focus": {
      "type": {
        "coding": [
          {
            "system": "eHealth/resources",
            "code": "person"
          }
        ],
        "text": "string"
      },
      "value": "52b504c7-0177-4078-834b-52d89154081c"
    }
  },
  "extension": [
    {
      "valueCode": "AUTHORIZE_WITH",
      "valueUuid": "e7ff2eef-712f-4676-960d-6aa16dce2103"
    },
    {
      "valueCode": "IS_ACCIDENT",
      "valueBoolean": true
    },
    {
      "valueCode": "TREATMENT_VIOLATION",
      "valueString": "reject_recommendation"
    },
    {
      "valueCode": "TREATMENT_VIOLATION_DATE",
      "valueDate": "2022-10-24"
    },
    {
      "valueCode": "IS_INTOXICATED",
      "valueBoolean": true
    },
    {
      "valueCode": "IS_FOREIGN_TREATMENT",
      "valueBoolean": true
    },
    {
      "valueCode": "IS_FORCE_RENEW",
      "valueBoolean": true
    }
  ]
}

Authorize

Check user scopes in order to perform this action (scope = 'composition:create')

  • return 401 (Unauthorized) in case of invalid scope(s)

Headers

  • Content-Type: application/json

  • Authorization: Bearer {token}

  • api-key: {secret}

Validation data request

  1. prechecks - Initial checks of request input data

    1. Check for “encounter.value” attribute:

      1. If another Composition with the same type and category in the "Final" status has the same encounter.value - return 1127 (FINAL_COMPOSITION_FOR_ENCOUNTER_ALREADY_EXISTS)

    2. If “relatesTo” isn’t null:

      1. For Newborn Composition:

        1. Validate that replacement is enabled

          1. In case of error (replacement isn’t enabled) - return 1181 (REPLACEMENT_FLOW_NOT_IMPLEMENTED_YET)

      2. For Temporary Disability Composition:

        1. If Composition.subject=person in current composition, Composition.subject = preperson in indicated composition in relatesTo.target.identifier and composition.status is FINAL, then the Refinement process is initiated

        2. If Composition.status in indicated composition in relatesTo.target.identifier is ENTERED_IN_ERROR and replacement is enabled, then the Raplacement process is initiated

          1. In case of error (replacement isn’t enabled) - return 1181 (REPLACEMENT_FLOW_NOT_IMPLEMENTED_YET)

        3. in other cases - return 1160 (INVALID_REPLACEMENT_ARGUMENT)

    3. For Newborn Composition:

      1. Checking for an already created Composition for preperson (“subject” attribute) which are according such requirements: Composition.type is Newborn and Composition.status isn’t ENTERED_IN_ERROR:

        1. In case of existing appropriate Compositions - return 1002 (COMPOSITION_ALREADY_EXISTS_FOR_SUBJECT)

      2. If in item b. was initiated Replacement flow:

        1. Checking the Composition.type in current Composition and Composition.type indicated in relatesTo.target.identifier

          1. In case of difference - return 1146 (CANT_REPLACE_DIFFERENT_TYPE)

        2. Check if the indicated Composition is last in the chain:

          1. In case of error (indicated Composition isn’t last in the chain) - return 1153 (CANT_AMEND_IS_APPENDED)

        3. Check if the indicated Composition has ENTERED_IN_ERROR status:

          1. In case of error (indicated Composition hasn’t ENTERED_IN_ERROR status) - return 1148 (CANT_REPLACE_IS_APPENDED)

        4. Check if the indicated Composition was canceled with Replacement’s reason

          1. In case of right Replacement’s reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_REPLACEMENT_CANCEL_TIMEOUT_NEWBORN. In case of error - return 1039 (INVALID_PERIOD)

          2. In case of common cancelation reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_PERIOD_START_NEWBORN. In case of error - return 1039 (INVALID_PERIOD)

    4. For Temporary Disability Composition:

      1. If in item b. was initiated Replacement flow:

        1. Checking the Composition.type in current Composition and Composition.type indicated in relatesTo.target.identifier

          1. In case of difference - return 1146 (CANT_REPLACE_DIFFERENT_TYPE)

        2. Check if the indicated Composition is last in the chain:

          1. In case of error (indicated Composition isn’t last in the chain) - return 1153 (CANT_AMEND_IS_APPENDED)

        3. Check if the indicated Composition has ENTERED_IN_ERROR status:

          1. In case of error (indicated Composition hasn’t ENTERED_IN_ERROR status) - return 1148 (CANT_REPLACE_IS_APPENDED)

        4. Check if the indicated Composition was canceled with Replacement’s reason

          1. In case of right Replacement’s reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_REPLACEMENT_CANCEL_TIMEOUT_NEWBORNDISABILITY. In case of error - return 1039 (INVALID_PERIOD)

          2. In case of common cancelation reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_PERIOD_START_NEWBORNDISABILITY. In case of error - return 1039 (INVALID_PERIOD)

      For Temporary Disability Composition
        1. Check “event.period.start” attribute for the possibility to specify in the future:

          1. If

        in item a. was initiated Replacement flow:
        1. Checking the Composition.type in current Composition and Composition.type indicated in relatesTo.target.identifier

          1. In case of difference - return 1146 (CANT_REPLACE_DIFFERENT_TYPE)

        2. Check if the indicated Composition is last in the chain:

          1. In case of error (indicated Composition isn’t last in the chain) - return 1153 (CANT_AMEND_IS_APPENDED)

        3. Check if the indicated Composition has ENTERED_IN_ERROR status:

          1. In case of error (indicated Composition hasn’t ENTERED_IN_ERROR status) - return 1148 (CANT_REPLACE_IS_APPENDED)

        4. Check if the indicated Composition was canceled with Replacement’s reason

          1. In case of right Replacement’s reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_REPLACEMENT_CANCEL_TIMEOUT_DISABILITY. event.period.start is specified in the future and it's not PREGNANCY category - return 1039 (INVALID_PERIOD)

        5. Check the time difference between the start date (event.period.start) and the task creation date:

          1. If the difference is more than allowed - return 1040 (PERIOD_TOLERANCE_EXCEEDED)

        6. Check for TREATMENT_VIOLATION_DATE extension:

          1. If TREATMENT_VIOLATION_DATE is outside the period of incapacity (event.period.start - event.period.stop) - return 1172 (TREATMENT_VIOLATION_DATE_OUT_OF_BOUNDS)

      1. If in item a. wasn’t initiated Replacement flow:

        1. In case of IS_FORCE_RENEW=true - the function completes it's execution and does not perform further checks

        2. Check for IS_FOREIGN_TREATMENT extension:

          1. If extension IS_FOREIGN_TREATMENT= true - checks 3 and 4 don’t perform

        3. Check of maximum length of one link of a medical opinion (disabilitySingleSpanFilter)

          1. In case of error - return 1039 (INVALID_PERIOD)In case of common cancelation reason - check validity period of Composition according to the configuration parameter EMAL_FILTER_PERIOD_START_DISABILITY. , 1031 (DURATION_SINGLE_PERIOD_TOO_LONG)

        4. Check for event.period.start attribute (periodStartFilter)

          1. In case of error - return 1039 (INVALID_PERIOD)

        f in item a. wasn’t initiated Replacement flow:

        1. In case of IS_FORCE_RENEW=true
          1. ), 1040 (PERIOD_TOLERANCE_EXCEEDED)

        2. Search for previous compositions with the same type and category as in the request, overlapping with the period of validity for this composition for at least 1 day

          1. If previous compositions wasn’t found - the function completes it'

          s execution and does not perform further checksCheck of maximum length of one link of a medical opinion (disabilitySingleSpanFilter)
          1. s execution

          2. If previous compositions was found - check validity period of compositions

            1. In case of error - return

            1039 (INVALID_PERIOD), 1031 (DURATION_SINGLE_PERIOD_TOO_LONG)
          Check for event.period.start attribute (periodStartFilter
            1. 1143 (NEW_START_DATE_IS_BEFORE_PREVIOUS_START_DATE), 1103(SAME_END_DATE_FOR_NEW_AND_EXISTING_COMPOSITION)

        3. Check for the maximum total length of the validity period (disabilityTotalSpanFilter)

          1. In case of error - return 1039 (INVALID_PERIOD), 1040 1032 (DURATION_TOTAL_PERIOD_TOLERANCETOO_EXCEEDEDLONG)

        4. Search for previous compositions with the same type and category as in the request, overlapping with the period of validity for this composition for at least 1 day

          1. If previous compositions wasn’t found - the function completes it's execution

          2. If previous compositions was found - check validity period of compositions

            1. In case of error - return 1143 (NEW_START_DATE_IS_BEFORE_PREVIOUS_START_DATE), 1103(SAME_END_DATE_FOR_NEW_AND_EXISTING_COMPOSITION)

        5. Check for the maximum total length of the validity period (disabilityTotalSpanFilter)

          In case of error - return 1039 (INVALID_PERIOD), 1032 (DURATION_TOTAL_PERIOD_TOO_LONG
      2. Additional checks for PREGNANCY category:

        1. If event.period.start <= taskCreated - the procedure begins to create a New Pregnancy Composition

          1. Check for “relatesTo” attribute:

            1. If it’s not null - return 1218 (NEW_PREGNANCY_COMPOSITION_CANT_HAVE_RELATIONSHIPS)

          2. Check for the length of the period of incapacity:

            1. If it’s not match with value in EMAL_VALIDATION_PREGNANCY_NEW_COMPOSITION_ALLOWED_PERIODS - return 1219 (NEW_PREGNANCY_COMPOSITION_INVALID_PERIOD)

          3. Check for “event.period.start” attribute:

            1. If event.period.start > taskCreated - return 1220 (NEW_PREGNANCY_COMPOSITION_INVALID_PERIOD_STARTS_IN_FUTURE)

        2. If event.period.start > taskCreated - the procedure begins to create a Prolongation for Previous Pregnancy Composition (appendingPregnancyComposition)

  2. Encounter Processing - Receiving and processing medical records (Encounter)

    1. Search for Encounter using the RPC call by ME service encounter_by_id

      1. In case of error - return 1016 (ENCOUNTER_NOT_FOUND)

    2. Check for Composition.author (CompositionAuthorFilter)

      1. If Composition.author.value does not match with Encounter.performer.identier.value and Composition.author.type.coding does not match with Encounter.performer.identier.type.coding - return 1030 (INVALID_ENCOUNTER_PERFORMER)

    3. Check for Encounter.type (EncounterTypeFilter)

      1. If Encounter.status isn’t “finished" - return 1037 (INVALID_ENCOUNTER_STATUS)

      2. If Encounter.type.code does not match with value in EMAL_FILTER_ENCOUNTER_TYPE_DISABILITY, EMAL_FILTER_ENCOUNTER_TYPE_NEWBORN - return 1038 (ENCOUNTER_TYPE_DISALLOWED_FOR_COMPOSITION_TYPE)

    4. Check for Encounter.Diagnose(encounterDiagnosesFilter)

      1. If no primary diagnosis was found - return 1034 (NO_PRIMARY_DIAGNOSIS)

      2. If a few primary diagnosis was found - return 1035 (MULTIPLE_PRIMARY_DIAGNOSES)

    5. Check for allowed values of Encounter.diagnoses[].code.code.

      1. In case of error - return 1036 (PRIMARY_DIAGNOSIS_NOT_ALLOWED)

    6. Check for allowed Encounter.date

      1. If Encounter.date does not match with value in EMAL_VALIDATION_ENCOUNTER_MAX_AGE_DAYS_BY_CATEGORY - return 1183 (INVALID_ENCOUNTER_DATE)

  3. Employee Processing - Receiving and processing Employee record (Composition.author)

    1. Search and check for Composition.author by id in IL with method employee_by_id

      1. In case of error - return 1015 (EMPLOYEE_NOT_FOUND)

    2. Check for Author.speciality (doctorSpecialityFilter)

      1. In case of error - return 1133 (NO_SPECIALIST_SPECIFIED), 1033 (DOCTOR_LACKS_SPECIALITY)

    3. Check for Composition.author

      1. If employee.status does not match with value in EMAL_VALIDATION_AUTHOR_ACTIVE_STATUS_VALUE - return 1165 (INVALID_AUTHOR_STATUS)

      2. If employee.type does not match with value in EMAL_VALIDATION_AUTHOR_CATEGORIES_BY_TYPE - return 1166 (INVALID_AUTHOR_TYPE)

      3. If employee.position does not match with value in EMAL_VALIDATION_AUTHOR_CATEGORIES_BY_POSITION - return 1167 (INVALID_AUTHOR_POSITION)

      4. If specialist.specialities або doctor.specialities with speciality_officio=true does not match with value in EMAL_VALIDATION_AUTHOR_CATEGORIES_BY_SPECIALITY_OFFICIO - return 1168 (INVALID_AUTHOR_SPECIALITY_OFFICIAL)

      5. If specialist.specialities or doctor.specialities with speciality_officio=false or null does not match with value in EMAL_VALIDATION_AUTHOR_CATEGORIES_BY_SPECIALITY - 1169 (INVALID_AUTHOR_SPECIALITY)

  4. Division Processing - Receiving and processing Division record (Employee Division)

    1. Check for Encounter.division

      1. If Encounter.division does not match with value in EMAL_FILTER_DIVISION_REQUIREMENTS_DISABILITY, EMAL_FILTER_DIVISION_REQUIREMENTS_NEWBORN - return 1089 (DIVISION_IS_REQUIRED)

      2. Search for Encounter.division by id in IL with method division_by_id

        1. In case of error - return 1012 (DIVISION_ENTITY_NOT_FOUND)

  5. Legal Entity Processing - Receiving and processing Legal Entity record (Employee Legal Entity)

    1. Search for Legal Entity by id with RPC method legal_entity_by_id

      1. In case of error - return 1011 (LEGAL_ENTITY_NOT_FOUND)

    2. Check for Custodian

      1. If legal_entity.type does not match with value in EMAL_VALIDATION_CUSTODIAN_CATEGORIES_BY_TYPE - return 1162 (INVALID_CUSTODIAN_TYPE)

      2. If legal_entity.status does not match with value in EMAL_VALIDATION_CUSTODIAN_ALLOWED_STATUSES_DISABILITY and EMAL_VALIDATION_CUSTODIAN_ALLOWED_STATUSES_NEWBORN - return 1164 (STATUS_NOT_ALLOWED_FOR_CUSTODIAN)

  6. Subject Processing - Receiving and processing Subject record

    1. Getting a record about the Composition's patient by id with RPC method get_preperson_by_id if subject.type.coding.code = preperson or get_person_by_id if subject.type.coding.code = person and Composition.type is Temporary Disability

      1. In case of error - return 1013 (BAD_SUBJECT_CODING), 1014 (SUBJECT_NOT_FOUND), 1112 (SUBJECT_IS_NOT_ACTIVE)

    2. For Newborn Composition:

      1. Check for preperson.birth_date

        1. In case of error (date of birth of the patient is not indicated) - return 1113 (NO_SUBJECT_PREPERSON_BIRTH_DATE)

      2. Check for Composition.event.period.start

        1. If Composition.event.period.start does not match with preperson.birth_date - return 1115 (SUBJECT_PREPERSON_BIRTH_DATE_MISMATCH)

      3. If preperson.gender is null - return 1114 (NO_SUBJECT_PREPERSON_GENDER)

    3. Сheck for presence of age restrictions in the configuration parameter for the person

      1. In case of error - return 1128 (AGE_NOT_ALLOWED)

    4. Сhecks for subject.type.coding.code = person

      1. If attribute subject.status is absent - return 1082 (INVALID_NEWBORN_SUBJECT) or 1086 (INVALID_DISABILITY_SUBJECT)

      2. If subject.type.code does not match with value in EMAL_VALIDATION_SUBJECT_CATEGORIES_BY_TYPE - return 1082 (INVALID_NEWBORN_SUBJECT) or 1086 (INVALID_DISABILITY_SUBJECT)

      3. If subject.status does not match with value in EMAL_VALIDATION_SUBJECT_ALLOWED_STATUSES_BY_CATEGORY - return 1082 (INVALID_NEWBORN_SUBJECT) or 1086 (INVALID_DISABILITY_SUBJECT)

      4. If verification_status does not match with value in EMAL_VALIDATION_SUBJECT_ALLOWED_VERIFICATION_STATUSES_BY_CATEGORY or it doesn't specified - return 1082 (INVALID_NEWBORN_SUBJECT) or 1086 (INVALID_DISABILITY_SUBJECT)

      5. Check for subject age

        1. If age of the person does not match with value in EMAL_VALIDATION_SUBJECT_ALLOWED_AGES_BY_CATEGORY - return 1082 (INVALID_NEWBORN_SUBJECT) or 1086 (INVALID_DISABILITY_SUBJECT)

    5. For Newborn Composition:

      1. If subject.type.coding.code isn’t preperson - return 1082 (INVALID_NEWBORN_SUBJECT)

      2. If date in “NEWBORN_BIRTH_DATE” does not match with value in preperson.birth_date - return 1173 (INVALID_NEWBORN_BIRTH_DATE_EXTENSION_VALUE)

      3. If date in "NEWBORN_BIRTH_DATE" does not match with value in composition.event.perion.start - return 1173 (INVALID_NEWBORN_BIRTH_DATE_EXTENSION_VALUE)

      4. If gender in "NEWBORN_SEX" does not match with value in preperson.gender - return 1174 (INVALID_NEWBORN_SEX_EXTENSION_VALUE)

  7. Focus Processing - Receiving and processing Focus record

    1. For Newborn Composition:

      1. If focus.type.coding.code isn’t person - return BAD_FOCUS_CODING(1009)

    2. Getting a record about the Composition's patient by id with RPC method get_preperson_by_id if focus.type.coding.code = preperson or get_person_by_id if focus.type.coding.code = person and Composition.type is Temporary Disability

      1. In case of error - return 1009 (BAD_FOCUS_CODING), 1010 (FOCUS_NOT_FOUND), 1111 (FOCUS_IS_NOT_ACTIVE)

    3. Getting a record about the Composition.focus’s authorization methods by id with RPC method get_auth_methods.

      1. If authorization method is expired such method isn't not used

      2. If specified authorization method wasn't found - return 1171 (FOCUS_AUTH_NOT_SPECIFIED)

    4. Check for tax_id

      1. In case of error - return 1080 (INVALID_FOCUS)

    5. Check for focus.type.coding.code = person

      1. If document.type does not match with value in EMAL_ERLN_CREATE_RECORD_JOB_DOCUMENT_TYPE_CODES - return 10916 (IDENTIFICATION_FAILED_DOCUMENT_ABSENT)

      2. Check for gender restriction in the configuration parameter for the person

        1. In case of error - return 1126 (GENDER_NOT_ALLOWED)

      3. If focus.status does not match with value in EMAL_VALIDATION_FOCUS_ALLOWED_STATUSES_BY_CATEGORY - return 1080 (INVALID_FOCUS)

      4. If focus.type.code does not match with value in EMAL_VALIDATION_FOCUS_CATEGORIES_BY_TYPE - return 1080 (INVALID_FOCUS)

      5. If focus.documen_type does not match with value in EMAL_VALIDATION_FOCUS_DOCUMENTS_BY_CATEGORY - return 1080 (INVALID_FOCUS)

      6. If verification_status does not match with value in EMAL_VALIDATION_FOCUS_ALLOWED_VERIFICATION_STATUSES_BY_CATEGORY or it doesn't specified - return 1080 (INVALID_FOCUS)

      7. If focus gender does not match with value in EMAL_VALIDATION_FOCUS_GENDERS_BY_CATEGORY - return 1080 (INVALID_FOCUS)

      8. Check for focus age

        1. If age of the person does not match with value in EMAL_VALIDATION_FOCUS_ALLOWED_AGES_BY_CATEGORY - return 1080 (INVALID_FOCUS)

  8. getSmsPhoneNumber - Receiving phone number for sending SMS about creation of composition

    1. This procedure is performed if extension “AUTHORIZE_WITH” was specified in the request. In other cases, the procedure is not performed

      1. search for a person's authorization method by RPC call to the MPI service get_auth_method

        1. If phone number was found - this number is saving for future SMS sending

        2. If phone number wasn't found - return 1017 (PHONE_NOT_FOUND)

  9. Saving the record of the Сomposition into database

  10. Task status updating in DONE

...