Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
stylenone

...

Config parsing logic:

Workflow:

a. get active config (is_active = true) by type and category (of composition) from [prm].composition

...

*next validations use configs

  1. If composition.extension is not empty and there is an extension with extension.сode = "COMPOSITION_ADDITIONAL_CONDITION_ADMISSION" validate composition type = “DRIVERS

    1. Return 422 (COMPOSITION_ADDITIONAL_CONDITION_ADMISSION extension is not allowed for {{composition_type}} composition type) in case of error

  2. When (36) composition type = “DRIVERS“ and composition.extension is not empty, check that at least one of composition.event.code corresponds to appropriate config - COMPOSITION_EVENT_ADMIT_CODES

  3. Return 422 ("Allow composition status must be Admit when extension is not empty") in case of error

  4. If composition.extension is not empty, check that extension.сode of extension corresponds to appropriate config - COMPOSITION_EXTENSION_ALLOW

    • Return 422 ("Prohibited extension code") in case of error

*new validations

  1. If (42.4) composition.extension is not empty
    AND
    extension.сode = “COMPOSITION_ADDITIONAL_CONDITION_ADMISSION“

    1. check that value in extension.valueCodeableConcept.coding.code is from COMPOSITION_ADDITIONAL_CONDITION_ADMISSION dictionary

      1. Return 422 ('value is not allowed in enum') in case of error

  2. If (42.5) composition.extension is not empty
    AND
    extension.сode = "COMPOSITION_ADDITIONAL_CONDITION_ADMISSION"
    AND
    extension.valueCodeableConcept.extension.valueCodeableConcept.coding.code is not empty

    1. check that value is from the COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_LETTER_DESIGNATIONS dictionary

      1. Return 422 ('value is not allowed in enum') in case of error

  3. If (42.6) composition.extension is not empty
    ANDextension.сode = "COMPOSITION_ADDITIONAL_CONDITION_ADMISSION"
    ANDextension.valueCodeableConcept.extension is not empty
    ANDextension.valueCodeableConcept.extension.code = COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_LETTER_DESIGNATIONS
    check that:

    1. extension.valueCodeableConcept.extension.valueCodeableConcept.coding.code value is in configuration.check array, where configuration.condition.code is equal to extension.valueCodeableConcept.coding.code, configuration - ADDITIONAL_CONDITION_RELATED_LETTER_DESIGNATIONS

      1. Return 422 ('Invalid letter designation for the additional admission condition code') in case of error

  4. Ifcomposition.extension is not empty
    ANDextension.сode = "COMPOSITION_ADDITIONAL_CONDITION_ADMISSION"
    ANDextension.value_codeable_concept.extension is not empty
    ANDextension.value_codeable_concept.extension.code = “COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE"
    check that:

    1. parameter extension.value_codeable_concept.extension.value_decimal is present

      1. Return 422 ("value_decimal must be present for COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE extension") in case of error

    2. extension.value_codeable_concept.coding.code is in config.condition array of COMPOSITION_ADDITIONAL_CONDITION_VALUES
      AND config.check = false

      1. Return 422 ('COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE extension is not allowed for additional admission condition with code {{extension.value_codeable_concept.coding.code}}') in case of error

    3. there is only one extension in extension.value_codeable_concept.extension array with code =“COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE"

      1. Return 422 ("Only one COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE extension is allowed for each additional admission condition") in case of error

  5. If (42.7) composition.extension is not empty
    ANDextension.сode = "COMPOSITION_ADDITIONAL_CONDITION_ADMISSION"
    check config COMPOSITION_ADDITIONAL_CONDITION_VALUES:

    1. If extension.valueCodeableConcept.coding.code is in config.condition array
      ANDconfig.check = true
      THEN

      1. Check that extension.value_codeable_concept.extension is present and extension.value_codeable_concept.extension.code = “COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE"

        1. Return 422 ('Missing required extension COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE for additional admission condition with code {{extension.value_codeable_concept.coding.code}}') in case of error

      2. parameter extension.value_codeable_concept.extension.value_decimal is present for this additional admission condition

        1. Return 422 ("value_decimal must be present for COMPOSITION_ADDITIONAL_CONDITION_ADMISSION_VALUE extension") in case of error

10. Relates to

New composition can replace previously created composition in case when employee add some new information or change patient data. In this case employee fill parameter “relates_to” - reference on previously composition. Get previously created composition identifier from Composition.relates_to and execute next validations:

...

  1. Check composition.Attester.mode.coding.system = "eHealth/composition_attester_modes""COMPOSITION_ATTESTER_MODES"
    & composition.attester.mode.coding.code is a value from dictionary eHealth/composition_attester_modes COMPOSITION_ATTESTER_MODES

  2. Check (18) that attester of composition work in same LE as custodian parameter: сomposition.attester legal_entity_id = composition.custodian

    • Return 422 ("Attester of composition must work in same LE as custodian") in case of error

  3. Check (19) that attester employee is in active status

    • Return 422 ('Attester is not active') in case of error

  4. Check (19.1) that composition.attester array has only one item

    • Return 422 ("Only one attester for composition must be submitted") in case of error

  5. Extract (21) user_id from token. Check that attester belongs to the employee user who sign composition.

    • Return 422 ('Attester id doesn’t belongs to employee id from token') in case of error

...

  1. When (39) composition type = “DRIVERS“ and composition.event.code = "DRIVERS_GROUP1_ADMIT" or "DRIVERS_GROUP2_ADMIT" - composition.event.period.start and composition.event.period.end is required

    • Return 422 ("Event period start and period end is required") in case of error

  2. When (40) composition type = “DRIVERS“ and composition.event.code = "DRIVERS_GROUP1_DENY" or "DRIVERS_GROUP2_DENY" - composition.event.period.start is required and composition.event.period.end must be empty

    • Return 422 ("Event period start is required and event period end must be empty") in case of error

  3. When (40.1) composition type = “ADOPTION“ and composition.event.code = "ADOPTION_ADOPTER_INELIGIBLE" or "ADOPTION_ADOPTER_RELATIVE_INELIGIBLE" - composition.event.period.start is required and composition.event.period.end must be empty

    Return 422 ("Event period start is required and event period end must be empty") in case of error

  4. Check (38.1) all event.code must be unique. In case when composition has more than one event

    • Return 422 ("Event codes must be unique") in case of error

  5. Check (37.1) that composition.event.code corresponds to appropriate dictionary - COMPOSITION_EVENTS

    • Return 422 ('value is not allowed in enum") in case of error

...

  1. When (25) composition type = “DRIVERS“ check that event.period (event.period.end - event.period.start) less than duration (depending on person age and composition event.code). Base on config - COMPOSITION_EVENT_PERIOD_DURATION
    Calculating logic:
    composition.event.period.end - composition.event.period.start < config.check value

    • Return 422 ("Composition event period duration must be less than <check.value> <check.units>") in case of error

  2. Check (38) all composition.event.code in composition - it must corresponds to appropriate config and match with at least one combination of statuses - COMPOSITION_EVENT_CODE
    examples:
    if composition category = “DRIVERS_GROUP1“ check what composition.event.code must be:
    "DRIVERS_GROUP1_ADMIT"
    OR
    "DRIVERS_GROUP1_DENY" and “DRIVERS_GROUP2_DENY“

    if composition category = “DRIVERS_GROUP2“ check that composition.event.code match with one of combination:
    “DRIVERS_GROUP1_ADMIT“ and “DRIVERS_GROUP2_DENY“
    OR
    “DRIVERS_GROUP1_ADMIT“ and “DRIVERS_GROUP2_ADMIT“
    OR
    “DRIVERS_GROUP1_DENY“ and “DRIVERS_GROUP2_DENY“

    if composition category = “ADOPTERS“ check that composition.event.code match with one of combination:
    ”ELIGIBLE”
    OR
    ”INELIGIBLE”

    • Return 422 ("Invalid event code for current composition category") in case of error

  3. Check (28.1) that composition.event.period.start < composition.event.period.end

    • Return 422 ("Period end of event must be later than event start period") in case of error

...

  1. Check (43) count of medical records in composition.section.entry <= then value from config - COMPOSITION_SECTION_ENTRY_LIMIT.

    • Return 422 ("Limit of medical records for this composition type and category must be less or equal <RECORDS_LIMIT>") in case of error

  2. Check (41) codes for all records from composition.section.entry where resource.type = "observation" on prohibited values for composition (all records not include prohibited codes), depends on event codes which included in config - COMPOSITION_SECTION_ENTRY_PROHIBITED_CODES where config.resource_type = "observation"

    • Return 422 ("Prohibited observation code - <code> in section.entry for current composition") in case of error

  3. Check (41.1) codes for all records from composition.section.entry where resource.type = "condition" on prohibited values for composition (all records not include prohibited codes), depends on event codes which included in config - COMPOSITION_SECTION_ENTRY_PROHIBITED_CODES where config.resource_type = "condition"

    • Return 422 ("Prohibited condition code - <code> in section.entry for current composition") in case of error

  4. Check (42) codes for all records from composition.section.entry where resource.type = "observation" on required values for composition (at least one record composition entry must contain) which depends on section.code wich included in config - COMPOSITION_SECTION_ENTRY_REQUIRED_CODES where config.resource_type = "observation"

    • Return 422 ("Empty required codes in section.entry for current composition") in case of error

  5. Check (42.1) codes for all records from composition.section.entrywhere resource.type = "condition" on required values for composition (at least one record composition entry must contain) which depends on section.code wich included in config - COMPOSITION_SECTION_ENTRY_REQUIRED_CODES where config.resource_type = "condition"

    • Return 422 ("Empty required codes in section entry for current composition") in case of error

  6. Check (44 + 45) existing in composition required and optional sections codes which depends on section.code - COMPOSITION_SECTION_CONFIG
    Logic description:
    Find all config.code where parameter config.mandatory = true and compare all codes to composition.section.[n].code. In case when config has nested sections but parameter mandatory = false - don't compare codes to nested sections.
    Logic description:

    • in case when object from config or config.sections.[n] have mandatory = true but composition.section.code or composition.section.section.[n].code hasn’t same value in config.code or config.sections.[n].code - return error

    • in case when composition.section.code has code wich hasn’t config.code - return error

    • Return 422 ("Invalid section content. Mandatory section {{code}} is missed") in case of error with empty required fields

  7. Check (45.1) section codes for nested sections hierarchy from config which depends on config - COMPOSITION_SECTION_CONFIG
    Logic description:
    Check that all values from composition.section.code equal to config.code from config.sections on the same nested level where config.sectionAllowed = true

    • in case when value from composition.section.code hasn’t same values with nested config.code (from config.sections) or composition.section.code has codes wich doesn’t exist in config.code (from config.sections) - return error Return 422 ("Invalid section hierarchy for nested section") in case of error with empty required fields

    examples
    success case:
    Composition - composition.section.code = MAIN, nested section - composition.section.section.code = PEDIATRIST
    Config - config.sectionAllowed = true, config.code = MAIN, config.section.code = PEDIATRIST
    error case 1:
    Composition - composition.section.code = MAIN, nested section - composition.section.section.code = NURSING
    Config - config.sectionAllowed = true, config.code = MAIN, config.section.code = PEDIATRIST
    error case 2:
    Composition - composition.section.code = MAIN, nested section - composition.section.section.code = PEDIATRIST
    Config - config.sectionAllowed = true, config.code = MAIN, config.section.code = PEDIATRIST + config.section.code = MAIN

  8. Check (45.2) section content for all sections which depends on section code - COMPOSITION_SECTION_CONFIG

    1. Configuration parameters description:

      • if sectionAllowed = true current section can contain nested sections

      • if isEmpty = true current section can contain emptyReason parameter instead of entry array

      • if containsResources = true current section can contain entry and orderBy parameters

    2. Validate section content:

      1. Check that current section contains just one AND only one of:

        1. nested section parameter

        2. emptyReason parameter

        3. entry parameter

        4. in case of error an error return 422 ("Section {{section_code}} must contain one AND only one of: nested section, emptyReason or entry")

      2. In case section contains entry parameter check that containsResources = true

        1. in case containsResources = false return 422 ("Section {{section_code}} can not contain entry")

      3. In case section contains emptyReason check that isEmpty = true

        1. in case isEmpty = false return 422 ("Section {{section_code}} can not contain emptyReason")

      4. In case section contains nested section check that sectionAllowed = true

        1. in case sectionAllowed = false return 422 ("Section {{section_code}} can not contain nested section")

  9. Check (46) nesting level of sections <= the allowed limit - COMPOSITION_SECTION_NESTING_LEVEL

    • Return 422 ("Prohibited nested level for composition section") in case of error

  10. Check (47) count of section <= than value from - COMPOSITION_SECTION_COUNT_LIMIT

    • Return 422 ("Prohibited amount of composition section") in case of error

...

  1. Check (48) composition.section.title

    1. Check that composition.section.title is not empty.

    2. Also check value from COMPOSITION_SECTION_TITLE_MANUAL_FILL config (depends on composition.section.code)

      1. if config.value = "true" (or section with same code doesn't exist) - don’t validate composition.section.title

      2. else if value = "false"

        1. get display value from COMPOSITION_SECTION_CODES dictionary where key=composition.section.code

        2. check composition.section.title = display

    3. Return 422 ("Invalid title for composition.section") in case of error

  2. Check (48.1) that section code (composition.section.code) corresponds to appropriate dictionary - COMPOSITION_SECTION_CODES

    • Return 422 ("Section code value is not allowed in enum") in case of error

  3. Check (48.2) that section order by parameter (composition.section.orderby) corresponds to appropriate dictionary - COMPOSITION_SECTION_ORDERBY

    • Return 422 ("Section order by value is not allowed in enum") in case of error

  4. Check (48.3) that empty reason (composition.section.emptyreason) corresponds to appropriate config - COMPOSITION_SECTION_EMPTY_REASON. In case when composition.section.emptyreason is not empty

    • Return 422 ("Empty reason value is not allowed in enum") in case of error

  5. Check (50) that person from all records in composition.section.entry the same as composition.subject (or merged person in mpi.merged_person)

    • Return 422 ("Person from section.entry must be the same as composition.subject or composition.section.focus") in case of error

  6. Check (54) that author position from section.author based on config - COMPOSITION_SECTION_AUTHOR_POSITION for selected section.code

    • Return 422 ("Section author position does not allow") in case of error

  7. Check (55) that author speciality from section.author based on config - COMPOSITION_SECTION_AUTHOR_SPECIALITY for selected section.code

    • Return 422 ("Section author speciality does not allow to create such composition") in case of error

  8. Check (55.1) that author main speciality (employee.accreditation.speciality_officio = true ) from section.authorbased on based on config - COMPOSITION_SECTION_AUTHOR_MAIN_SPECIALITY

    • Return 422 ("Section author main speciality does not allow to create such composition") in case of error

  9. Check (56) count of resources from composition.section.entry selected section.code - COMPOSITION_SECTION_SECTION_ENTRY_LIMIT

    • Return 422 ("Max count of resources in section.entry - <count>") in case of error

  10. Check (56.1) that the resource type of the resource in composition.section.entry is allowed by config COMPOSITION_SECTION_SECTION_ENTRY_RESOURCESfor this section.code and event.code

    • Return 422 ("Resource type is not allowed in this section for this event code") in case of error

...

  1. Check (64) that referenced encounter (if entry has resource with this type) from composition.section.entry has type based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TYPE where resource_type = "encounter"

    • Return 422 ("Invalid referenced encounter type in section.entry") in case of error

  2. Check (65) that referenced encounter (if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_STATUS

    • Return 422 ("Invalid referenced encounter status in section.entry") in case of error

  3. Check (66) that referenced encounter (if entry has resource with this type) from composition.section.entry has class (class.coding.code and class.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_ENCOUNTER_CLASS

    • Return 422 ("Invalid referenced encounter class in section.entry") in case of error

  4. Check (67) that different from sign composition date and referenced encounter (if entry has resource with this type) period.end or date (depending on which parameter is filled) in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_PERIOD_END:
    min >= composition.date - encounter.period.end or encounter.date<= max
    or
    min >= composition.date - encounter.period.end or encounter.date (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and referenced encounter (in section.entry) end date must be from <min> to <max>") in case of error

...

  1. Check (67.1) that referenced care plan (if entry has resource with this type) from composition.section.entry has category based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CATEGORY

    • Return 422 ("Invalid category in referenced care plan at section.entry") in case of error

  2. Check (68) that referenced care plan (if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_STATUS

    • Return 422 ("Invalid referenced care plan status in section.entry") in case of error

  3. Check (70) that different from sign composition date and referenced care plan (if entry has resource with this type)period.start in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_PERIOD_START:
    min >= composition.date - care_plan.period.start <= max
    or
    min >= composition.date - care_plan.period.start (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and referenced care plan start date must be from <min> to <max>") in case of error

...

  1. Check (77) that referenced condition (if entry has resource with this type) from composition.section.entry has code (at least one item in code.coding array (code.coding.code and code.coding.system)) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CODE where resource_type = "condition"

    • Return 422 ("Invalid referenced condition code.coding in section.entry") in case of error

  2. Check (78) that referenced condition (if entry has resource with this type) from composition.section.entry has clinical_status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_STATUS

    • Return 422 ("Invalid referenced condition clinical_status in section.entry") in case of error

  3. Check (79) that referenced condition (if entry has resource with this type) from composition.section.entry has verification_status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_CONDITION_VERIFICATION_STATUS

    • Return 422 ("Invalid referenced condition verification_status in section.entry") in case of error

  4. Check (80) that different from sign composition date and referenced condition (if entry has resource with this type) asserted_date in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "condition" and action = "asserted":
    min >= composition.date - condition.asserted_date <= max
    or
    min >= composition.date - condition.asserted_date (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and referenced condition asserted date must be from <min> to <max>") in case of error

  5. Check (81) that different from sign composition date and referenced condition (if entry has resource with this type) onset_date in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "condition" and action = "onset":
    min >= composition.date - condition.onset_date <= max
    or
    min >= composition.date - condition.onset_date (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and referenced condition onset date must be from <min> to <max>") in case of error

...

  1. Check (82) that referenced observation (if entry has resource with this type) from composition.section.entry has code (code.coding.code and code.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CODE where resource_type = "observation"

    • Return 422 ("Invalid code in referenced observation at section.entry") in case of error

  2. Check (83) that referenced observation (if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_STATUS

    • Return 422 ("Invalid referenced observation status in section.entry") in case of error

  3. Check (84) that referenced observation (if entry has resource with this type) from composition.section.entry has category based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CATEGORY

    • Return 422 ("Invalid category in referenced observation at section.entry") in case of error

  4. Check (85) that different from sign composition date and referenced observation (if entry has resource with this type) issued in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "observation" and action = "issued":
    min >= composition.date - observation.issued <= max
    or
    min >= composition.date - observation.issued (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and referenced observation issued date must be from <min> to <max>") in case of error

    • Return 422 ("Invalid referenced observation date in section.entry") in case of error

  5. Check (86) that different from sign composition date and referenced observation (if entry has resource with this type) between min and max (depends on section code):
    if observation has filled effective_period.end in composition.section.entry calculate:
    min >= composition.date - observation.effective_period.end <= max
    or
    min >= composition.date - observation.effective_period.end (in case when config has only one parameter)
    Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_PERIOD_END where resource_type = "observation"
    if observation has filled effective_date_time in composition.section.entry calculate:
    min >= composition.date - observation.effective_date_time <= max
    or
    min >= composition.date - observation.effective_date_time (in case when config has only one parameter)
    Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "observation" and action = "effective"

    • Return 422 ("Difference between sign composition date and referenced observation date must be from <min> to <max>") in case of error

...

  1. Check (90) that referenced immunization (if entry has resource with this type) from composition.section.entry has explanation.reason_not_given (explanattion.reason_not_given.coding.code and explanation.reason_not_given.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_IMMUNIZATION_EXPLANATION_REASON_NOT_GIVEN

    • Return 422 ("Invalid referenced immunization explanation reason not given in section.entry") in case of error

  2. Check (91) that referenced immunization (if entry has resource with this type) from composition.section.entry has explanation.reason (explanattion.reason.coding.code and explanation.reason.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_IMMUNIZATION_EXPLANATION_REASON

    • Return 422 ("Invalid referenced immunization explanation reason in section.entry") in case of error

  3. Check (92) that referenced immunization (if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_STATUS

    • Return 422 ("Invalid referenced immunization status in section.entry") in case of error

  4. Check (93) that referenced immunization (if entry has resource with this type) from composition.section.entry has vaccine_code (vaccine_code.coding.code and vaccine_code.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CODE where resource_type = "immunization"

    • Return 422 ("Invalid vaccine code in referenced immunization at section.entry") in case of error

  5. Check (94) that referenced immunization (if entry has resource with this type) from composition.section.entry has report_origin (report_origin.coding.code and report_origin.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_IMMUNIZATION_REPORT_ORIGIN

    • Return 422 ("Invalid referenced immunization report origin in section.entry") in case of error

  6. Check (95) that different from sign composition date and referenced immunization (if entry has resource with this type) date in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "immunization" and action = "date":
    min >= composition.date - immunization.date <= max
    or
    min >= composition.date - immunization.date (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and referenced immunization date must be from <min> to <max>") in case of error

...

  1. Check (122) that referenced employee (if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_EMPLOYEE_STATUS

    • Return 422 ("Invalid referenced employee status in section.entry") in case of error

  2. Check (123) that referenced employee (if entry has resource with this type) from composition.section.entry has position based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_EMPLOYEE_POSITION

    • Return 422 ("Invalid referenced employee position in section.entry") in case of error

  3. Check (124) that referenced employee (if entry has resource with this type) from composition.section.entry has speciality based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_EMPLOYEE_SPECIALITY

    • Return 422 ("Invalid referenced employee speciality in section.entry") in case of error

  4. Check (124.1) that referenced employee (if entry has resource with this type) from composition.section.entry has main speciality (employee.accreditation.speciality_officio = true ) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_EMPLOYEE_MAIN_SPECIALITY

    • Return 422 ("Invalid referenced employee main speciality in section.entry") in case of error

  5. Check (125) that referenced employee (if entry has resource with this type) from composition.section.entry has type based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_EMPLOYEE_TYPE

    • Return 422 ("Invalid referenced employee type in section.entry") in case of error

  6. Check (126) that different from sign composition date and referenced employee (if entry has resource with this type) start working date - start_date in composition.section.entry between min and max (depends on section code). Base on config - COMPOSITION_SECTION_SECTION_ENTRY_DEVICE_DISPENSE_WHEN_HANDED_OVER:
    min >= composition.date - employee.start_date <= max
    or
    min >= composition.date - employee.start_date (in case when config has only one parameter)

    • Return 422 ("Difference between sign composition date and employee start working date must be from <min> to <max>") in case of error

Referenced Medication Dispense

Validate resources where ResourceType = “medication_dispense”

*next validations use configs

  1. Check that referenced Medication Dispense(if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCEEMPLOYEE_STATUS

    • Return 422 ("Invalid referenced Medication Dispense status in section.entry") in case of error

  2. Check that the difference between composition.date and medication_dispense.dispensed_at is between min and max (depends on section code) specified in config COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "medication_dispense" and action = "dispensed_at":
    min >= composition.date - medication_dispense.dispensed_at <= max
    or
    min >= composition.date - medication_dispense.dispensed_at (in case when config has only one parameter)

    • Return 422 ("Difference between sign Composition date and referenced Medication Dispense dispensed_at date must be from <min> to <max>") in case of error

Referenced Device Request

Validate resources where ResourceType = “device_request”

*next validations use configs

  1. Check that referenced Device Request(if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCEEMPLOYEE_STATUS

    • Return 422 ("Invalid referenced Device Request status in section.entry") in case of error

  2. Check that referenced Device Request (if entry has resource with this type) from composition.section.entry has code.identifier (code.identifier.type.coding.code and code.identifier.type.coding.system) based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CODE where resource_type = "device_request"

    • Return 422 ("Invalid code identifier in referenced Device Request at section.entry") in case of error

  3. Check that difference between composition.date and device_request.date.period.start in composition.section.entry between min and max (depending on Composition type, category and section code) specified in configuration COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_PERIOD_START:
    min >= composition.date - device_request.period.start <= max
    or
    min >= composition.date - device_request.period.start (in case when config has only one parameter)

    • Return 422 ("Difference between sign Composition date and referenced Device Request start date must be from <min> to <max>") in case of error

Referenced Device Dispense

Validate resources where ResourceType = “device_dispense”

*next validations use configs

  1. Check that referenced Device Dispense(if entry has resource with this type) from composition.section.entry has status based on dictionary which depends on section.code - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCEEMPLOYEE_STATUS

    • Return 422 ("Invalid referenced Device Dispense status in section.entry") in case of error

  2. Check that the difference between composition.date and device_dispense.when_handed_over is between min and max (depends on section code) specified in config COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = “device_dispense" and action = "when_handed_over":
    min >= composition.date - device_dispense.when_handed_over <= max
    or
    min >= composition.date - device_dispense.when_handed_over (in case when config has only one parameter)

    • Return 422 ("Difference between sign Composition date and referenced Device Dispense when_handed_over date must be from <min> to <max>") in case of error

Referenced Clinical Impression

Validate resources where ResourceType = “clinical_impression”

*next validations use configs

  1. If Clinical Impression is referenced in composition.section.entry check that it has status that is allowed by COMPOSITION_SECTION_SECTION_ENTRY_RESOURCEEMPLOYEE_STATUS configuration

    • Return 422 ("Invalid referenced Clinical Impression status in section.entry") in case of error

  2. If Clinical Impression is referenced in composition.section.entry check that it has code.identifier (code.identifier.type.coding.code and code.identifier.type.coding.system) that is allowed by COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_CODE configuration where resource_type = "clinical_impression"

    • Return 422 ("Invalid code identifier in referenced Clinical Impression at section.entry") in case of error

  3. If Clinical Impression is referenced in composition.section.entry check that difference between Composition sign date and Clinical Impression date is between min and max (depends on section code):

    if Clinical Impression has filled effective_period.end calculate:
    min >= composition.date - clinical_impression.effective_period.end <= max
    or
    min >= composition.date - clinical_impression.effective_period.end (in case when config has only one parameter)
    Based on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_PERIOD_END where resource_type = "clinical_impression"

    if Clinical Impression has filled effective_date_time in composition.section.entry calculate:
    min >= composition.date - clinical_impression.effective_date_time <= max
    or
    min >= composition.date - clinical_impression.effective_date_time (in case when config has only one parameter)
    Based on config - COMPOSITION_SECTION_SECTION_ENTRY_RESOURCE_TERM where resource_type = "clinical_impression" and action = "effective"

    • Return 422 ("Difference between sign Composition date and referenced Clinical Impression date must be from <min> to <max>") in case of error

Service logic

  1. Save signed content to media storage, in the bucket pointed in MEDIA_STORAGE_COMPOSITION_BUCKET chart parameter

  2. Set subject with hashed mpi identifier from URL

  3. Get encounter where id = Composition.encounter.identifier.value

    1. Set Composition.context_episode_id = encounter.episode

  4. Save data to compositions collection in DB according to composition data model

  5. Save link from media storage to the $.signed_content_links field in compositions collection

  6. Create job and return it’s id.

  7. If $.authorize_with is submitted send SMS to patient with composition number via template CREATE_{{COMPOSITION_TYPE}}_COMPOSITION_SMS_TEMPLATE. Use $.authorize_with as patient’s authentication method

...