Versions Compared

Key

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

...

  1. Validate observations ids as  primary keys (Submit Encounter Data Package#Primarykeyvalidation)

  2. Validate that context of observation is a current encounter

    1. $.observations[*].context.identifier.value==$.encounter.id

      1. in case of error return "Submitted context is not allowed for the observation"

  3. Validate that the date is within acceptable limits

    1. $.observations[*].issued <= current_time

      1. in case of error return "Issued date must be in past"

    2. $.observations[*].issued>=current_date-observation_max_days_passed

      1. in case of error "Issued must be greater than  {{current_date-observation_max_days_passed}}"

  4. Validate performer(asserter)

  5. Validate $.observations[*].components

    1.  if $.observations[*].code.coding[*].system is "eHealth/ICF/classifiers":

      1. Check number of component items with $.observations[*].components[*].code.coding[*].system = "eHealth/ICF/qualifiers": 

        1. if $.observations[*].code.coding[*].code starts from "b" letter, then components must contain exact 1 item with:

          1. $.observations[*].components[*].code.coding[*].code = "extent_or_magnitude_of_impairment" 

            1. in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"

            2. in case of incorrect number of qualifiers - return 422 "Required 1 component, but got <number of items>"

            3. in case value is not active in dictionary - return 422 "Value is not active"

        2. if $.observations[*].code.coding[*].code starts from "s" letter, then components must contain exact 3 items with:

          1. $.observations[*].components[*].code.coding[*].code = "extent_or_magnitude_of_impairment"

          2. $.observations[*].components[*].code.coding[*].code = "nature_of_change_in_body_structure"

          3. $.observations[*].components[*].code.coding[*].code = "anatomical_localization"

            1. in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"

            2. in case of incorrect number of qualifiers - return 422 "Required 3 components, but got <number of items>"

            3. in case value is not active in dictionary - return 422 "Value is not active"

        3. if $.observations[*].code.coding[*].code starts from "d" letter, then components must contain exact 2 items with:

          1. $.observations[*].components[*].code.coding[*].code = "performance"

          2. $.observations[*].components[*].code.coding[*].code = "capacity"

            1. in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"

            2. in case of incorrect number of qualifiers - return 422 "Required 2 components, but got <number of items>"

            3. in case value is not active in dictionary - return 422 "Value is not active"

        4. if $.observations[*].code.coding[*].code starts from "e" letter, then components must contain exact 1 item with:

          1. $.observations[*].components[*].code.coding[*].code = "barrier_or_facilitator"

            1. in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"

            2. in case of incorrect number of qualifiers - return 422 "Required 1 component, but got <number of items>"

            3. in case value is not active in dictionary - return 422 "Value is not active"

      2. Check $.observations[*].components[*].value_codeable_concept is present in each item with $.observations[*].components[*].code.coding[*].system = "eHealth/ICF/qualifiers" and  $.observations[*].components[*].value_codeable_concept.coding[*].system corresponds to $.observations[*].components[*].code.coding[*].code

        1. in case not present or doesn't correspond -  return 422 "Doesn't correspond to $.observations[i].components[i].code"

        2. in case code value is not active in dictionary - return 422 "Value is not active"

  6. if observations[*].categories[0].coding[0].system == "eHealth/ICF/observation_categories" - skip validation of observations[*].value and make this fields optional

    1. else - check that one off this fields present:

      1. Validate$.observations[*].components[*].value_period as a Period

      2. Validate $.observations[*].value_quantity

        1. $.observations[*].value must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

        2. $.observations[*].comparator can take the following values : [">", ">=", "=", "<=", "<"]

          1. in case of error return "value is not allowed in enum"

        3. $.observations[*].unit can take values from dictionary eHealth/ucum/units 

          1. in case of error return "value is not allowed in enum"

      3. Validate $.observations[*].value_codeable_concept

        1. $.observations[*].code validate that the code belongs to the dictionary system

          1. in case of error return "Value is not allowed in enum"

      4. Validate $.observations[*].value_boolean

        1. $.observations[*].value_boolean must be boolean type

          1. in case of error return "type mismatch. Expected boolean but got {entered type}"

      5. Validate $.observations[*].value_string

        1. $.observations[*].value_string must be string type

          1. in case of error return "type mismatch. Expected string but got {entered type}"

      6. Validate $.observations[*].value_sampled_data

        1. $.observations[*].data must be string type

          1. in case of error return "type mismatch. Expected string but got {entered type}"

        2. $.observations[*].origin must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

        3. $.observations[*].period must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

        4. $.observations[*].factor must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

        5. $.observations[*].lower_limit must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

        6. $.observations[*].upper_limit must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

        7. $.observations[*].dimensions must be with number type

          1. in case of error return "type mismatch. Expected number but got {entered type}"

      7. Validate $.observations[*].value_range

        1. $.observations[*].low must be with object type

          1. in case of error return "type mismatch. Expected object but got {entered type}"

        2. $.observations[*].high must be with object type

          1. in case of error return "type mismatch. Expected object but got {entered type}"

      8. Validate $.observations[*].value_ratio

        1. $.observations[*].numerator must be with object type

          1. in case of error return "type mismatch. Expected object but got {entered type}"

        2. $.observations[*].denominator must be with object type

          1. in case of error return "type mismatch. Expected object but got {entered type}"

      9. Validate $.observations[*].value_time

        1. $.observations[*].value_time must be with string type

          1. in case of error return "type mismatch. Expected string but got {entered type}"

      10. Validate $.observations[*].value_date_time

        1. $.observations[*].value_date_time must be with string type

          1. in case of error return "type mismatch. Expected string but got {entered type}"

  7. Validate diagnostic report is one of reports in the current package

    1. $.observations[*].diagnostic_report.identifier.value == one of $.diagnostic_report[*].identifier.value

      1. in case of error "Invalid reference"

  8. Validate $.observations[*].reaction_on

    1. check that the appropriate immunizations.status != "entered_in_error"

      1. in case of error return 409 "Immunization with status ‘entered_in_error’ can not be use"

  9. Validate $.observations[*].code

    1. if $.observations.code.coding[*].code value is included in chart variables 'OBSERVATION_CODES_WITH_<VALUE_TYPE>_REQUIRED', <value_type> field is mandatory

      1.  in case of error return 422 “This field is required for code = <code>“

    2. if observations[*].code.coding[*].system is "eHealth/ICF/classifiers", then:

      1. Check observations[*].categories[*].coding[*].system should contain "eHealth/ICF/observation_categories"

        1. in case of error return 422 “Code doesn't match observation category“

      2. Check observations[*].components are presented

        1. in case of error return 422 “Components required“

    3. Validate $.observations.code.coding[*].code is active in corresponding dictionary

      1. in case of error return 409, “Value is not active”

  10. Validate $.observations[*].categories

    1. is an array with only one item

      1. in case of error return 422 "Expected a maximum of 1 items but got <number of elements>"

    2. $.observations[*].categories[*].coding[*].system is "eHealth/observation_categories" or "eHealth/ICF/observation_categories" 

      1. in case of error return 422 "Value is not allowed in enum"

    3. $.observations[*].categories[*].coding[*].code corresponds to the system

      1. in case of error return 422 "Value <code> not found in the dictionary <$.observations[*].categories[*].coding[*].system>"

    4. Validate $.observations.categories[*].coding[*].code is active in corresponding dictionary

      1. in case of error return 409, “Value is not active”

    5. If $.observations[*].categories[*].coding[*].system = "eHealth/ICF/observation_categories", then $.observations[*].code should be filled from "eHealth/ICF/classifiers" dictionary. Also, check $.observations[*].categories[*].coding[*].code value match following $.observations[*].code.coding[*].code value:

      1. if category code is functions, then code value should start with "b" letter

      2. if category code is structures, then code value should start with "s" letter

      3. if category code is activities, then code value should start with "d" letter

      4. if category code is environmental, then code value should start with "e" letter 

        1. in case of error return 422 “Code doesn't match observation category“

  11. Validate specimen, if submitted:

    1. Check the field is a Reference on a specimen resource

      1. in case of error return 422 “not allowed in enum”

    2. Check it exists in DB or within current package, and belongs to the same patient:

      1. in case of error return 422 "Specimen not found"

    3. Check status:

      1. is available if the specimen was found in the DB

        1. in case of error return 422 "Specimen created before the current package should be available"

      2. is unavailable if the specimen not found in the DB, but in the package

        1. in case of error return 422 "Specimen created in the current package should be unavailable"

Validate observations for encounter.type == "patient_identity" 

...

  1. Validate diagnostic reports ids as primary keys (Submit Encounter Data Package#Primarykeyvalidation)

  2. Validate based_on as Reference(Submit Encounter Data Package#Referencevalidation)

  3. Validate that service_request, referenced as based_on, is

    1. in status is active or program_processing_status=in_progress (any status is valid in case program_processing_status= in_progress)

      1. in case of error return 409 "Invalid service request status"

    2. if program is defined than used_by_legal_entity==token.client_id OR null

      1. in case of error return 409 "Service request is used by another legal_entity"

    3. if program is defined than program_processing_status == new, in_queue or in_progress

    4. check that service_request contains based_on parameter

      1. in case based_on present in service_request

        1. verify care_plan:

          1. It should be in active status

          2. Care plan's period end (if exist) should be greater than current date or equal.

        2. verify activity:

          1. It has activity.detail.kind=service_request; activity.detail.product_reference=service_id. 

          2. It has scheduled, in_progress status

          3. For an old activities (has no units in quantity) validate remaining_quantity as described at Submit Encounter Data Package#Relatedcareplanvalidation

      2. in case based_on not present in request skip previous validations.

    5. Check if service request quantity is not exhausted as described at related service request validation

  4. category

    1. Validate that one of diagnostic reports categories corresponds to service category, that is references as code in DR

      1. $.diagnostic_report.category[?]=PRM.services.category where PRM.services.id=$.diagnostic_report.code.identifier.value

        1. in case of error return 422 "None of the diagnostic report categories matches with the service category"

  5. Validate code

    1. Validate code as Reference(Submit Encounter Data Package#Referencevalidation)

    2. If service_requests.code.identifier.value is service, validate $diagnostic_report.code.identifier.value = service_requests.code.identifier.value

      1. in case error return 409, "Service in diagnostic_report differ from service in service request"

    3. if service_requests.code.identifier.value is service_group, validate $diagnostic_report.code.identifier.value in (SELECT service_id from service_inclusions where service_group_id='service_requests.code.identifier.value')

      1. in case error return 409, "Service in diagnostic_report differ from services in service request's service_group"

    4. Validate diagnostic_report.service.is_active = true

      1. in case error return 409, "Service should be active"

  6. Validate effective_period as a period (Submit Encounter Data Package#period_validationPeriodValidation)

  7. Validate that issued is within acceptable limits

    1. $.diagnostic_reports[*].issued<= current date_time

      1. in case of error 422 "Asserted date  must be in past"

    2. $.diagnostic_reports[*].issued>=current_date-diagnostic_report_max_days_passed

      1. in case of error 422 "Issued must be greater than  {{current_date-diagnostic_report_max_days_passed}}" 

  8. Validate recorded_by as Employee (Submit Encounter Data Package#Employeevalidation)

  9. Validate encounter

    1. $.diagnostic_reports[*].encounter.identifier.value == $.http://encounter.id

      1. in case of error 409 "Invalid reference"

  10. Validate performer

    1.  as Employee Submit Encounter Data Package#Employeevalidation

    2. according to logic Submit Encounter Data Package#Performer(asserter)validation

  11. Validate managing_organization is a current legal_entity

    1. $.managing_organization.identifier.value==token.client_id

      1. in case of error 409 "Managing organization does not correspond to user's legal entity."

  12. Validate result_interpreter.identifier as Employee (Submit Encounter Data Package#Employeevalidation)

  13. Validate result_interpreter.identifier is an employee with employee_type = DOCTOR or SPECIALIST

  14. Validate only One of the fields is filled:

    1. $.diagnostic_report[*].results_interpreter.reference OR $.diagnostic_report[*].results_interpreter.text

    2. $.diagnostic_report[*].performer.reference OR $.diagnostic_report[*].performer.text

  15. Validate primary_source

    1. If primary_source==true, then

      1. Managing organization MUST be filled

    2. If primary_source==false, then

      1. report_origin OR performer.text must be filled

      2. performer.reference must NOT be filled

      3. results_enterpreter.reference must NOT be filled

  16. If patient is person - validate verification status:

    1. If diagnostic report has based_on with service request, then skip this validation.

    2. Else check patient's verification_status is not equal to NOT_VERIFIED.

      1. in case NOT_VERIFIED - return error 409, "Patient is not verified"

  17. Validate specimens, if submitted:

    1. Check field has array with elements of Reference type on specimen resource

      1. in case of error return 422 “not allowed in enum”

    2. For each specimen check:

      1. Check it exists in DB or within current package, and belongs to the same patient:

        1. in case of error return 422 "Specimen not found"

      2. Check it is present in the only one diagnostic report within the package.

        1. in case of error return 422 "Specimen is already used in another diagnostic report"

      3. Check status:

        1. is available if the specimen found in the DB

          1. in case of error return 422 "Specimen created before the current package should be available"

        2. is unavailable if the specimen not found in the DB, but in the package

          1. in case of error return 422 "Specimen created in the current package should be unavailable"

Validate Procedures

  1. Validate by json schema

  2. Validate procedure id as primary key (Submit Encounter Data Package#Primarykeyvalidation)

  3. Validate code

    1. Validate code as Reference(Submit Encounter Data Package#Referencevalidation)

    2. Validate procedure.service.is_active = true

      1. in case error return 409, "Service is not active"

  4. Validate that service_request, referenced as based_on, is

    1. check that service_request contains based_on parameter

      1. in case based_on present in service_request

        1. verify care_plan:

          1. It should be in active status

          2. Care plan's period end (if exist) should be greater than current date or equal.

        2. verify activity:

          1. It has activity.detail.kind=service_request; activity.detail.product_reference=service_id. 

          2. It has scheduled, in_progress status

          3. For an old activities (has no units in quantity) validate remaining_quantity as described at Submit Encounter Data Package#Relatedcareplanvalidation

      2. in case based_on not present in request skip previous validations.

    2. Check if service request quantity is not exhausted as described at related service request validation

  5. Validate encounter

    1. $.procedure[*].encounter.identifier.value == $.encounter.id

      1. in case error return 409, "Submitted encounter is not allowed for procedure"

  6. Validate performed_date_time

    1.  performed_date_time is real

      1. in case error return 422, "Performed_date_time in invalid"

    2. performed_date_time <= now

      1. in case error return 422 "Procedure cannot be registered in future"

  7. Validate performed_period

    1. $.performed_period.start<= now

      1. in case of error return 422 "Procedure cannot be registered in future"

    2. $.performed_period.end>= $.performed_period.start

      1. in case of error return 422 "End date must be greater than start date"

    3. performed_period.end <= now

      1. in case error return 422 "Procedure cannot be registered in future"

    4. Validate $.performed_period as required field in case if procedure based on service request with quantity that has code=MINUTE (system=SERVICE_UNIT)

      1. in case of error return 422 "can't be blank"

  8. Validate recorded_by

    1. Validate recorded_by as Reference(Submit Encounter Data Package#Referencevalidation)

    2. $..recorded_by.identifier.value is an ID of existing employee in PRM.employee

      1. in case of error  return 422, "Employee with such id is not found"

    3. Validate recorded_by is employee with status='APPROVED' and is_active= true and end_date is null or more than today

      1. in case error return 409, "This action is prohibited for current employee" 

    4. Validate employees.legal_entity_id=$managing_organization.identifier.value

      1. in case error return 409, "Employee should be from current legal entity"

  9. Validate asserter

  10. Validate division

    1. Validate division as Reference (Submit Encounter Data Package#Referencevalidation)

    2. $division is an ID in PRM.divisions

      1. in case return 422, "Division with such id is not found"

    3. division.status=ACTIVE and is_active=true

      1. in case error return 409, "Division is not active"

    4. division.legal_entity_id = $client_id or division.legal_entity_id=$managing_organization.identifier.value

      1. in case error return 409, "Division is not in current legal_entity"

  11. Validate managing_organization is a current active legal_entity with proper type

    1.  as Reference (Submit Encounter Data Package#Referencevalidation)

    2. $managing_organization is an ID in PRM.legal_entities

      1. in case return 422, "Legal entity with such id is not found"

    3. validate managing_organization status is 'ACTIVE' and is_active=true

      1. in case error return 422 ('Legal entity is not active')

    4. validate legal_entity type is in ('PRIMARY_CARE','MSP','MSP_PHARMACY','MSP_PHARMACY') (use `ME_ALLOWED_TRANSACTIONS_LE_TYPES` from charts)

      1. in case error return 422, "Legal entity with type $legal_entity.type cannot perform procedures"

    5. validate $managing_organization.identifier.value = $client_id

      1. in case of error 409 "Managing organization does not correspond to user's legal entity."

  12. Validate reason_references

    1. Validate reason_reference as a Reference (Submit Encounter Data Package#Referencevalidation)

    2. Validate reason_refernce.identifier.type.coding.[0].code is 'condition' or 'observation'

      1. in case error return 422 "value is not allowed in enum"

    3. Validate reason_refernce.identifier.value is condition or observation not in status ENTERED_IN_ERROR

      1. in case error return 422, "<Medical event resource> in "entered_in_error" status can not be referenced"

  13. Validate outcome

    1. validate outcome as a Reference (Submit Encounter Data Package#Referencevalidation)

    2. validate outcome.coding.object.system is in dictionary eHealth/procedure_outcomes

      1. in case error return 422, "outcome not in dictionary eHealth/procedure_outcomes"

  14. Validate complication_details

    1. validate complication_details as a Reference (Submit Encounter Data Package#Referencevalidation)

    2. validate complication_details.identifier.value refer to condition in the same encounter package

      1. in case error return 422, "complication_details does not correspond to condition in this encounter package"

  15. Validate category

    1. according to the dictionary 'eHealth/procedure_categories' - by schemata

    2. Validate that procedure category corresponds to service category, that is references as code in procedure

      1. $.procedure.category=PRM.services.category where PRM.services.id=$.procedure.code.identifier.value

        1. in case of error return 422 "Procedure category does not match with the service category"

  16. If patient is person - validate verification status:

    1. If procedure has based_on with service request, then skip this validation.

    2. Else check patient verification_status is not equal to NOT_VERIFIED.

      1. in case NOT_VERIFIED - return error 409, "Patient is not verified"

  17. Validate used_codes

    1. Check that the $.used_codes[*].coding[*].code belongs to the dictionary in $.used_codes[*].coding[*].system

      1. in case of error - return 422 "Value is not allowed in enum"

    2. Validate 'used_codes.coding.code'  is_active = true

      1. in case error return 409, "Value is not active"

...

  1. Validate by json schema

  2. Validate clinical impression id as primary key (Submit Encounter Data Package#Primarykeyvalidation)

  3. Validate status

    1. Check that the code belongs to the dictionary system (eHealth/clinical_impression_statuses)

      • in case of error - return 422 ('value is not allowed in enum')

    2. Check it has value = completed

      • in case of error - return 422 ('value is not allowed in enum')

  4. Validate code

    1. Check that the code belongs to the dictionary system (eHealth/clinical_impression_patient_categories)

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

    2. Validate code.coding depending on the qty of codes. Maximum one code is allowed

      1. in case of error - return 422 ('Only one code is allowed')

    3. Check by code.coding[0].code and code.coding[0].system active rule in rule_engine_rules collection

      1. in case no active rule present - check request only with following validations

      2. in case rule present in collection - check request with following validations and with additional from rule engine rule

  5. Validate description

    1. Check that value with string type

      1. in case of error - return 422 ('type mismatch. Expected string but got {entered type}')

  6. Validate encounter

    1. Check the value is valid reference on encounter resource

      • Check that value is an object with references of type encounter

        • in case of error - return 422 ('value is not allowed in enum')

    2. Check the value is valid reference on encounter resource

      • Check that $.clinical_impressions[*].encounter.identifier.value == $.http://encounter.id

        1. in case error - return 422 ('Invalid reference')

  7. Validate effective_period and effective_date_time:

    1. Validate that at least one of the parameters are present

      • in case of error - return 422 ('At least one of the parameters must be present')

  8. Validate effective_period as a period (Submit Encounter Data Package#PeriodValidation)

    1. Validate value in the field $.effective_period

      • Check that $.effective_period.start <= encounter.date

        • in case of error - return 422 ('Start date must be in the past')

      • Check that $.effective_period.end >= $.effective_period.start

        • in case of error - return 422 ('End date must be greater than or equal the start date')

    2. Validate that $.effective_period.end is within acceptible limits

      • Check that $.effective_period.end <= current_time

        • in case of error - return 422 ('Date must be in past')

      • Check that $.effective_period.start >= current_date-clinical_impression_max_days_passed

        • in case of error - return 422 ('Date must be greater than {{current_date-clinical_impression_max_days_passed}}')

  9. Validate effective_date_time

    1. Check that field $.effective_date_time is string type

      1. in case of error - return 422 ('type mismatch. Expected string but got {entered type}')

    2. Check that field $.effective_date_time <= current_time

      1. in case of error - return 422 ('Date must be in past')

    3. Check that field $.effective_date_time >= current_date-clinical_impression_max_days_passed

      1. in case of error - return 422 ('Date must be greater than {{current_date-clinical_impression_max_days_passed}}')

  10. Validate assessor

    1. Validate assessor as Reference(Submit Encounter Data Package#Referencevalidation)

      1. $.assessor.identifier.value is an ID of existing employee in PRM.employee

        1. in case of error - return 422 ('Employee with such id is not found')

    2. Validate assessor is employee with status='APPROVED' and is_active= true and end_date is null or more than today

      1. in case of error - return 422 ('Invalid employee status')

  11. Validate previous

    1. Check the value is valid reference on clinical impression resource

      • Check that value is an object with references of type clinical_impression

        • in case of error - return 422 ('value is not allowed in enum')

      • Check that clinical impression is active (status is not entered_in_error)

        • in case of error - return 422 ('Clinical impression in "entered_in_error" status can not be referenced')

      • Check that clinical impression belongs to patient ($.subject)

        • in case of error - return 422 ('Clinical impression with such id is not found')

  12. Validate problems

    1. Check that value is an array with references of type condition

      • in case of error - return 422 ('value is not allowed in enum')

    2. Check that each condition is active (verification_status is not entered_in_error)

      1. in case of error - return 422 ('Condition is canceled')

    3. Check that condition belongs to the patient ($.subject) or exists in the current encounter package

      1. in case of error - return 422 ('Condition with such id is not found')

  13. Validate findings

    1. Check that value is an array with objects

      1. Validate item_reference

        1. Check that value is an object with reference of resource condition, observation (further <Medical event resource>)

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

        2. Check that <Medical event resource> is active (status is not entered_in_error)

          1. in case of error - return 422 ('<Medical event resource> in "entered_in_error" status can not be referenced')

        3. Check that each reference:

          1. is valid ME of defined type above

          2. belongs to the patient ($.subject) or exists in the current encounter package

            1. in case of error - return 422 (<Medical event resource> with such ID is not found')

        4. In case some resources present in active rule, check that they correspond to configured rule

          1. Check that value is an object with reference of resource condition, observation (further <Medical event resource>)

            1. in case of error - return 422 'entry': '$.clinical_impressions[0].code', 'entry_type': 'json_data_property', 'rules': [{'description': '<description_text of the failed rule>, rule: <number of failed rule>', …

      2. Validate basis

        1. Check that value with string type

          1. in case of error - return 422 ('type mismatch. Expected string but got {entered type}')

  14. Validate supporting_info

    1. Check that value is an array with references of type episode_of_care, procedure, diagnostic report, encounter (further <Medical event resource>)

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

    2. Check that <Medical event resource> is active (status is not entered_in_error)

      1. in case of error - return 422 ('<Medical event resource> in "entered_in_error" status can not be referenced')

    3. Check that each reference:

      1. is valid ME of defined type above

      2. belongs to the patient ($.subject) or exists in the current encounter package (procedure, diagnotic report)

        1. in case of error - return 422 (<Medical event resource> with such ID is not found')

    4. In case some resources present in active rule, check that they correspond to configured rule

      1. in case of error - return 422 'entry': '$.clinical_impressions[0].code', 'entry_type': 'json_data_property', 'rules': [{'description': '<description_text of the failed rule>, rule: <number of failed rule>', …

  15. Validate note

    1. Check that value with string type

      1. in case of error - return 422 ('type mismatch. Expected string but got {entered type}')

  16. Validate patient

    1. In case patient params present in active rule, get them through subject and check that they correspond to configured rule

      1. in case of error - return 422 'entry': '$.clinical_impressions[0].code', 'entry_type': 'json_data_property', 'rules': [{'description': '<description_text of the failed rule>, rule: <number of failed rule>', …

    2. In case medication dispense data presents in active rule, get medication dispense data in patient context (through subject) and check that it correspond to configured rule

      1. in case of error - return 422 'entry': '$.clinical_impressions[0].code', 'entry_type': 'json_data_property', 'rules': [{'description': '<description_text of the failed rule>, rule: <number of failed rule>', …

Validate Specimen

  1. Validate by json schema

  2. Validate specimens ids as  primary keys (Submit Encounter Data Package#Primarykeyvalidation)

  3. Validate that context of specimen is a current encounter

    1. $.specimens[*].context.identifier.value==$.encounter.id

      1. in case of error return 422 "Submitted context is not allowed for the specimen"

  4. Validate specimen's root attributes:

    1. Validate requests, type, condition, registered_by, managing_organization as described at Create Specimen: Validate specimen

    2. Validate parent as described at Create Specimen: Validate specimen, but also check it within current package

    3. Validate status:

      1. Check the value is available or unavailable, according to the specimen_statuses dictionary 

        1. in case of error return 422 "value is not allowed in enum"

      2. Specimen is unavailable if there is at least one entity that references specimen (Observations where ($.observations[*].specimen.reference == specimen.id) or Diagnostic Reports where ($.diagnostic_reports[*].specimen.reference == specimen.id))

        1. in case of error return 422 "Specimen that is not referenced in Observation or Diagnostic Report must be in 'available' status"

  5. Validate collection attributes:

    1. Validate collector, collected, quantity, duration, method, body_site, fasting status as described at Create Specimen: Validate collection

    2. Validate procedure in the field $.collection.procedure, Reference type, optional

      • Check it references to procedure resource

        • in case of error - return 422 ('value is not allowed in enum')

      • Check that procedure exists in the DB and belongs to the patient, or it is within current package

        • in case of error - return 422 ('Procedure not found')

      • Validate that entity is not in status "entered_in_error"

        • in case of error - return 422 ("Entity in status "entered_in_error" can not be referenced")

  6. Validate container attributes as described at Create specimen: Validate container

  7. Validate received_time as described at Process Specimen: Validate received datetime

    1. received_time must be empty if there are no other entities that reference specimen (NO Observations where ($.observations[*].specimen.reference == specimen.id) and NO Diagnostic Reports where ($.diagnostic_reports[*].specimen.reference == specimen.id))

      1. in case of error return 422 "received_time must not be set for available specimen"

  8. Validate status_reason:

    1. is set to codeable concept with system = specimen_invalidate_reasons and code = used, if the specimen status is unavailable (i.e. at least one entity that references specimen).

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

    2. is empty, if the specimen status is available.

      1. in case of error return 422 ('Status reason must not be set for available specimen')

Primary key validation

  1. Validate that IDs of all submitted entities in the array are unique

    1. validate that $.{collection}[*].id from the payload are all unique among themselves

      1. in case of error return 409 "All primary keys must be unique"  

    2. validate there is no entity with such id in the corresponding Medical events collection

      1. in case of error return 422 "{Entity} with such id already exists"

...

  1. Save signed_content to Media Storage

  2. Save data to corresponding collections in DBs

  3. Save link to the signed content to the encounter

  4. Enrich encounter.diagnoses:

    1. select condition.code from Medical Events DB(or from request body)  where condition.id ==diagnoses[@].condition.identifier.value 

    2. set diagnoses[@].code = select 1

  5. Save diagnoses from encounter to episodes.current_diagnoses

    1. ME.patients.episodes.diagnoses = $.encounter.diagnoses 

  6. Add a record to the ME.patient.episodes{episode_id}.diagnoses_hstr

    1. date = current_date

    2. evidence = reference to encounter  ($.encounter.id )

    3. diagnoses = $.encounter.diagnoses

  7. Generate accession_identifier number:

    1. Generate requisition number (see Human readable requisition number) based on the specimen id. Note: requisition number should be unique for each specimen and should not match with number of another entities. So, if generated number match to existing in DB - it should be regenerated

    2. Encode and set it into $.accession_identifier attribute 

  8. Set display_value to employees for all submitted objects

    1. Select PRM.parties.first_name, PRM.parties.second_name, PRM.parties.last_name from PRM.parties where (PRM.parties.id == (Select PRM.employees.party_id from  PRM.employees where PRM.employees.id== $.care_manager.identifier.value))

    2. ME.patients.encounters{encounter_id}.performer.display== Select 1

    3. ME.conditions{condition_id}.asserter.display == Select 1

    4. ME.observations{observation_id}.performer.display == Select 1

    5. ME.patients.immunizations{immunization_id}.performer.display == Select 1

    6. ME.patients.allergy_intolerance{ai_id}.asserter.display == Select 1

    7. ME.patients.devices{device_id}.asserter.display == Select 1

    8. ME.patients.medication_statements{ms_id}.asserter.display == Select 1

    9. ME.patients.risk_assessment{rs_id}.asserter.display == Select 1

    10. ME.patients.diagnostic_reports{dr_id}.performer.reference.display == Select 1

    11. ME.patients.diagnostic_reports{dr_id}.recorded_by.reference.display == Select 1

    12. ME.patients.diagnostic_reports{dr_id}.results_interpreter.reference.display == Select 1

    13. ME.clinical_impressions{clinical_impression_id}.assessor.display == Select 1

    14. ME.specimens{specimen_id}.registered_by.reference.display == Select 1

    15. ME.specimens{specimen_id}.collector.reference.display == Select 1, if collector type is employee 

  9. In case there are reactions ($.observations[?].reaction_on) in the request, update corresponding immunizations with the reactions:

    1. Set in ME.patient.immunization.reaction.detail $.observation.id as a reference
      note: $.observations[?].reaction_on should not be saved in observation, only in corresponding immunization

  10. Set display_value for legal_entities

    1. ME.patients.diagnostic_reports{dr_id}.managing_organization.display_value

    2. ME.specimens{specimen_id}.managing_organization.display_value

  11. Set managing_organization for submitted observations, conditions, encounter

    1. ME.conditions{cond_id}.managing_organization=token.client_id

    2. ME.observations{observ_id}.managing_organization=token.client_id

    3. ME.encounters{encounter_id}.managing_organization=token.client_id

  12. In case encounter.incoming_referral was filled, set episode_origin to encounter

    1. Select episode where id== (select ME.encounter.episode.identifier.value where encounter.id ==(select ME.service_requests.context.identifier.value where id==$.encounter.incoming_referral.identifier.value))

  13. In case diagnostic_reports.based_on was filled, set episode_origin to diagnostic report

    1. Select episode where id== (select ME.encounter.episode.identifier.value where encounter.id ==(select ME.service_requests.context.identifier.value where id==$.diagnostic_reports.based_on.identifier.value))

  14. In case encounter.incoming_referral was filled set $.encounter.id to related to $.service_request activity[].outcome_reference

  15. In case procedures.based_on was filled set $.procedures.id to related to $.service_request $.activity[].outcome_reference

  16. In case diagnostic_reports.based_on was filled set $.diagnostic_reports.id to related to $.service_request activity[].outcome_reference

  17. Update $ .activity.status to in_progress if previous activity status was scheduled

  18. Update the $ .activity.remaining_quantity parameter by the value achieved at Submit Encounter Data Package#Relatedcareplanvalidation above (for an old activities only that has no quantity units)

  19. Update remaining_quantity in the service request with a value that was calculated in the Related service request section above

  20. If there are at least one record for speciality where speciality_officio = true:

    1. Enrich encounter data with performer speciality:

      1. SELECT speciality -> 'speciality' FROM employees WHERE speciality ->> 'speciality_officio' = 'true' AND id = $.encounter.performer.identifier.value

      2.  Set encounter.performer_speciality as CodeableConcept type with system = SPECIALITY_TYPE

  21. In case encounter.clinical_impression was filled set $.context_episode_id to clinical_impressions data model (encounters.context.[].episode.value=clinical_impression.context_episode_id)

  22. If any available specimen, that has already stored in DB, is referenced in Observation or Diagnostic Report - change its (Specimen) status to unavailable in DB according to https://e-health-ua.atlassian.net/wiki/spaces/EH/pages/17629118869 . Also, set status_reason for a specimen: system = specimen_invalidate_reasons, code = used.

  23. Set origin_episode (if $.based_on in request and $.based_on.service_request.context != null) for Diagnostic Report:

    1. origin_episode is an object from the $.service_request.context.episode

  24. Set origin_episode (if $.based_on in request and $.based_on.service_request.context != null) for Procedure:

    1. origin_episode is an object from the $.service_request.context.episode

HTTP status codes

HTTP status code

Message

What caused the error

401

Access denied

 

403

Access denied. Party is deceased

 

403

Access denied. Party is not verified

 

403

Invalid scopes

 

409

<ME type> cannot be measured in <quantity.code's value>

 

409

Asserter has no required employee type to set condition code <code>

 

409

Asserter has no required speciality to set condition code <code>'

 

409

Division is not active

 

409

Division is not in current legal_entity

 

409

Employee should be from current legal entity

 

409

Encounter.class $class is forbidden for your employee type

 

409

Encounter.class $class is forbidden for your episode type

 

409

Encounter.class $class is forbidden for your legal entity type

 

409

Encounter.type $type is forbidden for your encounter class

 

409

medication request is not active

 

409

Medication request started at should be in the past

 

409

medication request was made for another person

 

409

Patient is not verified

 

409

Procedure/Medication administration is not active

 

409

Reason reference should be active

 

409

Reason reference was made for another person

 

409

Service in $resourse differ from service in service request

 

409

Service in $resourse differ from services in service request's service_group

 

409

Service in diagnostic_report differ from service in service request

 

409

Service in diagnostic_report differ from services in service request's service_group

 

409

Service is not active

 

409

Service should be active

 

409

Submitted encounter is not allowed for procedure

 

409

This action is prohibited for current employee

 

409

Value is not active

 

409 

All primary keys must be unique

 

409 

Conditions in diagnoses must be active

 

409 

Division is not active 

 

409 

Employee not found

 

409 

Immunization with status ‘entered_in_error’ can not be use

 

409 

Invalid reference

 

409 

Invalid service request status

 

409 

Managing organization does not correspond to user's legal entity.

 

409 

Patient is not active

 

409 

Procedure/Medication administration was made for another person

 

409 

Service request is used by another legal_entity

 

409 

Submitted employee is not an active employee from current legal entity

 

409 

The total amount of medical events exceeds quantity in related service request with <id>

 

409 

User is not allowed to create encouners for this division

 

422

 “Components required“

 

422

<Medical event resource> in  entered_in_error  status can not be referenced

 

422

<parameter> is required for encounter.type.code = discharge

 

422

At least one of action references, diagnostic reports or procedures should exist in encounter package

 

422

complication_details does not correspond to condition in this encounter package

 

422

Condition|Observation|DiagnosticReport with such id is not found

 

422

Division with such id is not found

 

422

Employee with such id is not found

 

422

Employee.type $type is forbidden for your encounter class

 

422

Employee.type $type is forbidden for your encounter type

 

422

End date must be greater than the start date

 

422

entered_in_error  status can not be referenced'

 

422

Entity in status  entered_in_error   can not be referenced

 

422

Hospitalization block is forbidden for encounter.class = $encounter.class

 

422

Legal entity is not active

 

422

Legal entity with such id is not found

 

422

Legal entity with type $legal_entity.type cannot perform procedures

 

422

Medication should be of type brand

 

422

Medication should correspond to the one in request

 

422

Only one code from one dictionary is allowed

 

422

outcome not in dictionary eHealth/procedure_outcomes

 

422

Performed_date_time in invalid

 

422

performed_date_time should be in the past

 

422

Procedure with such id is not found

 

422

Service should be active'

 

422

Start date must be in past

 

422

This field is required for code = <code>“

 

422

Validation failed

 

422

Visit with such id already exists

 

422 

{Entity} with such id already exists

 

422 

“Code doesn't match observation category“

 

422 

“not allowed in enum”

 

422 

<Medical event resource> with such ID is not found'

 

422 

Asserted date  must be in past

 

422 

'At least one of the parameters must be present'

 

422 

can't be blank

 

422 

'Clinical impression with such id is not found'

 

422 

'Condition is canceled'

 

422 

'Condition with such id is not found'

 

422 

Could not reference entity in status entered_in_error

 

422 

'Date must be greater than {{current_date-clinical_impression_max_days_passed}}'

 

422 

Date must be greater than {{current_date-encounter_max_days_passed}}

 

422 

Date must be in past

 

422 

Doesn't correspond to $.observations[i].components[i].code

 

422 

Encounter must have exactly one primary diagnosis

 

422 

Encounter’s date must be equal to or greater than start date of episode

 

422 

'End date must be greater than or equal the start date'

 

422 

End date must be greater than start date

 

422 

Episode is not active

 

422 

Episode with such ID is not found

 

422 

Expected a maximum of 1 items but got <number of elements>

 

422 

'Invalid employee status'

 

422 

'Invalid reference'

 

422 

Issued must be greater than  {{current_date-diagnostic_report_max_days_passed}}

 

422 

'Legal entity is not active'

 

422 

Managing_organization in the episode does not correspond to user`s legal_entity

 

422 

Missing components with qualifiers <list of missing qualifiers>

 

422 

None of the diagnostic report categories matches with the service category

 

422 

'Only one code is allowed'

 

422 

Procedure cannot be registered in future

 

422 

Procedure category does not match with the service category

 

422 

'Procedure not found'

 

422 

received_time must not be set for available specimen

 

422 

Required 1 component, but got <number of items>

 

422 

Required 2 components, but got <number of items>

 

422 

Required 3 components, but got <number of items>

 

422 

Specimen created before the current package should be available

 

422 

Specimen created in the current package should be unavailable

 

422 

Specimen is already used in another diagnostic report

 

422 

Specimen not found

 

422 

Specimen that is not referenced in Observation or Diagnostic Report must be in 'available' status

 

422 

'Start date must be in the past'

 

422 

'Status reason must not be set for available specimen'

 

422 

Submitted context is not allowed for the specimen

 

422 

There is no observation with such id

 

422 

There is no {$..identifier.type.coding[0].code} with such id

 

422 

'type mismatch. Expected string but got {entered type}'

 

422 

Value <code> not found in the dictionary <$.observations[*].categories[*].coding[*].system>

 

422 

Value is not active

 

422 

Value is not allowed in enum

 

422 

Visit with such ID is not found

 

422 

<medical_event> with such id is not found

 

422 

'Employee with such id is not found'

 

 

Asserted date must be greater than  {{current_date-device_max_days_passed}}

 

 

Asserted date must be greater than  {{current_date-medication statement_max_days_passed}}

 

 

Asserted date must be greater than  {{current_date-risk_assessment_max_days_passed}}

 

 

Date must be greater than  {{current_date-immunization_max_days_passed}}

 

 

Employee is not active

 

 

Employee is not performer of encounter

 

 

End date of visit must be filled

 

 

Issued date must be in past

 

 

Issued must be greater than  {{current_date-observation_max_days_passed}}

 

 

Last occurrence must be in past

 

 

Onset date must be greater than  {{current_date-condition_max_days_passed}}

 

 

Onset date must be in past

 

 

Onset date time must be greater than  {{current_date-allergy_intolerance_max_days_passed}}

 

 

Onset date time must be in past

 

 

Performer (asserter) must be filled

 

 

Report_origin can not be submitted in case primary_source is true

 

 

Report_origin must be filled

 

 

Submitted code is not allowed for this field

 

 

Submitted context is not allowed for the allergy_intolerances

 

 

Submitted context is not allowed for the condition

 

 

Submitted context is not allowed for the device

 

 

Submitted context is not allowed for the immunization

 

 

Submitted context is not allowed for the medication administration

 

 

Submitted context is not allowed for the medication statement

 

 

Submitted context is not allowed for the observation

 

 

Submitted context is not allowed for the risk_assessments

 

 

Submitted system is not allowed for this field

 

 

There is no Employee with such id

 

 

type mismatch. Expected number but got {entered type}

 

 

type mismatch. Expected object but got {entered type}

 

 

type mismatch. Expected string but got {entered type}

 

 

type mismatch. Expected boolean but got {entered type}