Versions Compared

Key

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

...

  1. Verify the validity of access token

    1. in case of error return 401 ('Access denied')

  2. Check user scope encounter:write in order to perform this action

    1. in case of error generate 403 response ('Invalid scopes')

Headers

Наприклад:

Content-Type:application/json

...

  1. Validate encounter id as a primary key

  2. Validate that the date is within acceptable limits

    1. $.encounter.date<= current_date

    2. $.encounter.date>=current_date-encounter_max_days_passed

    3. $.encounter.date>=episode.period.start where episode.id=$encounter.episode.identifier.value

      1. in case of error return 422 "Encounter’s date must be equal to or greater than start date of episode"

  3. Validate "episode" is an active episode that belongs to the current patient

    1. $.encounter.episode.identifier.value is one of  ME.patinet{patient_id}.episodes{*}.id

      1. in case of error return 422 "Episode with such ID is not found"

    2. $.encounter.episode.identifier.value is an ID of an Episode that meets the requirements:

      1. ME.patient{patinet_id}.episodes{episode_id}.status = 'active'

        1. in case of error return 422 "Episode is not active"

      2. ME.patient{patinet_id}.episodes{episode_id}.managing_organization==token.client_id

        1. in case of error return 422 "Managing_organization in the episode does not correspond to user`s legal_entity"

  4. Validate "visit" is a visit that belongs to the current patient

    1. $.encounter.visit.identifier.value=$.visit.id  OR  ID of already existing Visit in ME.patient{patient_id}.visit.id

      1. in case of error return 422 "Visit with such ID is not found"

  5. Validate referrals

    1. As a referral it can be referenced electronic (registered in the system) OR paper service request

    2. Validate ($.encounter.incoming_referrals OR $.encounter.paper_referral) or none in request

    3. Validate incoming referrals as  References

    4. Validate paper referral as Object (paper_referral)

    5. Validate incoming referrals that corresponds to $.encounter.incoming_referrals[*].identifier.value have:

      1. ..used_by_legal_entity.identifier.value==token.client_id OR null

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

      2. ..status==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"

      3. ..if program is defined 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

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

  6. Validate performer

    1. $.encounter.performer.identifier.value is an ID of existing employee in PRM.Employees

      1. in case of error return "There is no Employee with such id"

    2. $.encounter.performer.identifier.value  == PRM.Employees.id where (PRM.Employees.status==`active`)

      1. in case of error return "Employee is not active"

    3. $.encounter.performer.identifier.value  == PRM.Employees.id where (PRM.Employees.legal_entity== client_id)

      1. "User can not create encounter for this legal_entity"

    4. validate employee type according to encounter.class - use config file (employee_encounter_classes)

      1. in case error return 422, "Employee.type $type is forbidden for your encounter class"

    5. according to employee.type as stated in employee_encounter_types

      1. in case error return 422, msg "Employee.type $type is forbidden for your encounter type"

  7. division

    1. $.encounter.division.identifier.value must meet the following requirements

      1. PRM.division.status = "ACTIVE"

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

      2. PRM.division.legal_entity= token.client_id

        1. in case of error return 409 "User is not allowed to create encouners for this division"

  8. Validate supporting_info as References

  9. Validate encounter.class  

    1. according to legal_entity.type - use config file (legal_entity_episode_types)

      1. in case error return 409, msg "Encounter.class $class is forbidden for your legal entity type"

    2. according to episode.type - use config file (episode_type_encounter_classes)

      1. in case error return 409, msg "Encounter.class $class is forbidden for your episode type"

    3. according to employee.type as stated in encounter class validations

      1. in case error return 409, msg "Encounter.class $class is forbidden for your employee type"

  10. Validate encounter.type according to encounter.class - use config file encounter_class_encounter_types

    1. in case error return 409, msg "Encounter.type $type is forbidden for your encounter class"

  11. Validate actions 

    1. Validate actions presence according to  encounter class validations

      1. in case error return '422', msg 'TBC'

    2. Defined in the system that corresponds to  encounter class validations

      1. in case error return '422', msg 'TBC'

  12. Validate action_references 
    Note. For encounter.action_references pass only "service", and the "service_group" does not pass

    1. Validate action_references presence according to  encounter class validations

      1. in case error return '422', msg 'At least one of action references, diagnostic reports or procedures should exist in encounter package'

    2. Validate code as a Reference

    3. Validate action_references is in prm.services, has status ACTIVE and is_active = true

      1. in case error return '422', msg 'Service with such ID is not found'

      2. in case error return '422', msg 'Service should be active'

  13.  Validate diagnoses 

    1. Validate conditions as  References

    2. Validate that encounter type= 'intervention'. If not, than:

      1. Validate encounter has exactly one diagnosis where $.encounter.diagnoses[?(@.role.coding[0].code=="primary")]

      2. in case of error return 422 "Encounter must have exactly one primary diagnosis"

    3. Validate condition.id is in DB or in current Encounter package 

    4. Validate that each condition is active (verification_status != entered_in_error)

      1. in case of error return 409 "Conditions in diagnoses must be active"

    5. Validate that primary diagnosis defined in the system that corresponds to  encounter class validations

      1. in case of error "Primary diagnosis should be defined in {$.encounter.diagnoses[*].role.coding[*].system } system"

    6. Validate that rank

      1. Rank value should be integer and >= 1

        1. in case of error return 422 "expected the value to be >= 1"

      2. Rank value should be integer and <= 10

        1. in case of error return 422 "expected the value to be <= 10"

  14. Validate reasons

    1. Validate reasons presence according to  encounter class validations

      1. in case error return 422, msg 'Validation failed. You can find validators description at our API Manifest: Nebo #15 API Manifest · Apiary .', description 'can't be blank.

  15. Validate hospitalization 

    1. Validate hospitalization presence according to  encounter class validations

      1. in case error return 422, msg "Hospitalization block is forbidden for encounter.class = $encounter.class" 

    2. Validate all fields according to schemata

      1. destination

      2. discharge_disposition

      3. pre_admission_identifier

      4. admit_source

      5. re_admission

      6. discharge_department

    3. If encounter.type.code = "discharge" than encounter.hospitalization.admit_source is required, encounter.hospitalization.discharge_disposition is required, encounter.hospitalization.discharge_department is required

      1. in case error return 422, msg "<parameter> is required for encounter.type.code = "discharge"

    4. Validate destination is a valid legal_entity in prm with status is ACTIVE and is_active = true

      1. in case error return 422, "Legal entity is not active"

  16.  Validate patient_id for encounter.type == "patient_identity"

    1. $patient_id should exist in mpi.prepersons.id, have status =='ACTIVE' and is_active = true

      1. in case error return 'TBC', msg 'TBC'

  17. If incoming referrals exists and incoming_referral (service request) category not in ('transfer_of_care', 'hospitalization') and encounter.class in ("AMB", "INPATIENT") and encounter.type <>  "patient_identity" validate service for encounter.actions OR diagnostic_report.code OR procedure.code

    1. If service_requests.code.identifier.value is service, validate $resourse.code.identifier.value = service_requests.code.identifier.value

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

    2. if service_requests.code.identifier.value is service_group, validate $resourse.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 $resourse differ from services in service request's service_group"

    3. Validate $resourse.service.is_active = true

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

  18. Validate patient verification status:

    1. If encounter has incoming referral with valid and active service request, then skip this validation.

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

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

  19. Validate priority

    1. Validate priority presence according to eHealth/encounter_priority

      1. in case error return 409, ""

    2. If encounter.class.code = "INPATIENT", priority is required

      1. in case error return 422, "Priority for encounter is required"

...

  1. Validate conditions ids as  primary keys

  2. Validate that context of conditions is a current encounter

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

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

  3. Validate code depending on encounter class

    1. if $.encounter.class = PHC - allowed both eHealth/ICPC2/condition_codes and eHealth/ICD10_AM/condition_codes

    2. if $.encounter.class in (AMB, INPATIENT) - allowed only eHealth/ICD10_AM/condition_codes

  4. Validate code.coding depending on the qty of codes

    1. Maximum one code from one dictionary (eHealth/ICPC2/condition_codes and eHealth/ICD10_AM/condition_codes) is allowed

      1. in case of error return 422 with msg "Only one code from one dictionary is allowed"

  5. Validate that the date is within acceptable limits

    1. $.conditions[*].onset_date <= current_date

      1. in case of error "Onset date must be in past"

    2. $.condition[*].onset_date>=current_date-condition_max_days_passed

      1. in case of error "Onset date must be greater than  {{current_date-condition_max_days_passed}}"

  6. $.conditions[*].onset_date <= current_date

    1. in case of error "Onset date must be in past"

  7. $.conditions[*].asserted_date <= current_date

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

  8. $.conditions[*].evidences[*].detail[*].identifier.value is an ID of existing observation in MedicalEvents.Observations or one of $.observations[*]
    OR $.conditions[*].evidences[*].detail[*].identifier.value is an ID of existing condition in MedicalEvents.Conditions

    1. in case of error 422 "<medical_event> with such id is not found"$.conditions[*].evidences[*].detail[*].identifier.value is an ID of existing observation in MedicalEvents.Observations or one of $.observations[*]

    2. in case of error 409 "Observation with such id is not found"

  9. $.conditions[*].evidences[*].detail[*].identifier.value meet follownig conditions

    1. MedicalEvents.Observation.Patient == patient_id (from url)

      1. Error 409 "Evidence can not reference another patient"

    2. MedicalEvents.Observation.Status != "entered_in_error"

      1. Error 409 "Observation in "entered_in_error" status can not be used as an evidence"

  10. Validate $.conditions[*].evidences[*].detail[*].identifier.value
    for each $.conditions[*].evidences
    check:

    1. MedicalEvents.<MedicalEvent>.Patient == patient_id (from url)

      • Error 422 "<medical_event> with such id is not found"

    2. MedicalEvents.<MedicalEvent>.Status != "entered_in_error"

      • Error 422 "<medical_event> in "entered_in_error" status can not be used as an evidence"

    3. in case if PSYCHIATRY_ICPC2_DIAGNOSES_EVIDENCE_CHECK chart parameter contains $.conditions[*].code.coding.code
      check if at least one item from $.conditions[*].evidences meets requirements: 

      1. check if $.conditions[*].evidences[*].detail[*].identifier.type.coding.code == "condition" 

        • Error 422 "Condition must be entered as an evidence to set condition code <$.conditions[*].code.coding.code>"

      2. MedicalEvents.Condition.Code.Coding array contains at least one of codes from PSYCHIATRY_ICD10_AM_CONDITION_EVIDENCE_ALLOWED chart parameter.

        • Error 422 "Condition can not be used as an evidence to set condition code <$.conditions[*].code.coding.code>"

      3. get Encounter by MedicalEvents.Condition.Context
        get Encounter.Diagnoses[*] with Condition.id 
        check if Encounter.Diagnoses[*].Role is equal to $.encounter.diagnoses[*].role for $.conditions[*].id.

        • Error 422 "Condition can not be set as an evidence with wrong diagnosis role ("<role>")"

  11. Validate asserter.

    1. $.conditions.asserter.identifier.value is an ID of one of users employee 

      1. in case of error return "Employee is not performer of encounter"

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

      1. check if asserter's employee_type == "ASSISTANT" then define allowed conditions from ASSISTANT_EMPLOYEE_CONDITIONS_ALLOWED

        in case condition code is not allowed for the employee_type - return 409 error ('Asserter has no required employee type to set condition code <code>')

      2. check if asserter's employee_type == "MED_COORDINATOR" then define allowed conditions from ICD10_AM_MED_COORDINATOR_EMPLOYEE_CONDITIONS_ALLOWED

        1. in case condition code is not allowed for the employee_type - return 409 error ('Asserter has no required employee type to set condition code <code>')

      3. if primary_source = true and code has eHealth/ICD10_AM/condition_codes dictionary value:

        1. define allowed specialities for ICD10_AM condition code using a set of chart variables ICD10_AM_<SPECIALITY_TYPE>_SPECIALITY_CONDITIONS_ALLOWED

        2. check if asserter's speciality in allowed specialities defined on previous step

          1. in case speciality not allowed for the condition code - return 409 error ('Asserter has no required speciality to set condition code <code>')

...

  1. Validate by json schema

  2. Validate clinical impression id as primary key (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 rules in rule_engine_rules collection

      1. in case any active rules 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 == $.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 (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.end >= 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 with 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 (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 in "entered_in_error" status can not be referenced')

    3. Check that condition belongs to the patient ($.subject)

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

  13. Validate finding

    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)

            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)

        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 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>', …

    2. 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>', …

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"

...

17. in case reference on service request has reference on care plan update $ .activity.remaining_quantity parameter by subtracting the quantity of artifacts that have a reference on service request that contains an $.based_on.[]activity

18. 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

...