Versions Compared

Key

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

...

Using this web service you can submit:

Object

Required

Part of Signed content

Visit

0-1

false

Encounter

1-1

true

Condition

0-*

true

Observation

0-*

true

Allergy intolerance

0-*

true

Immunization

0-*

true

Risk assessment

0-*

true

Device

0-*

true

Medication statement

0-*

true

Medication administration

0-*

true

Diagnostic report

0-*

true

Procedure

0-*

true

Clinical impression

0-*

true

You can send the same request (with the same body) multiple times, but a new job will not be created before previous is not performed.

...

  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 that the period is within acceptable limits

    1. $.encounter.period.start<= current_date

      1. in case of error return 422 "Date must be in past"

    2. $.encounter.period.start>=current_date-encounter_max_days_passed

      1. in case of error return 422 "Date must be greater than {{current_date-encounter_max_days_passed}}"

    3. $.encounter.period.start>=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"

    4. $.encounter.period.end>= $.encounter.period.start

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

  4. 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"

  5. 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"

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

      5. Check if service request quantity is not exhausted as described at https://e-health-ua.atlassian.net/wiki/spaces/EH/pages/17061216257/Submit+Encounter+Package#Related-service-request-validation

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

  8. 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"

  9. Validate supporting_info as References

  10. 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"

  11. 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"

  12. 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'

  13. 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'

      3. Validate that action_references is service with service.category==”counselling” in case encounter.class=”AMB”

        1. in case error return ‘422', msg 'Invalid service category for AMB encounter class'

  14.  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 http://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"

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

  16. 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"

  17.  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'

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

  19. 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"

  20. 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"

...

Encounter class validations

Validation

PHC

AMB

INPATIENT

employees.type

as stated in config file employee_encounter_types

as stated in config file employee_encounter_types

as stated in config file employee_encounter_types

encounter.type

as stated in config file encounter_class_encounter_types

as stated in config file encounter_class_encounter_types

as stated in config file encounter_class_encounter_types

actions

  • at least one required

  • is in dictionary eHealth/ICPC2/actions

is absent in request

is absent in request

diagnoses

diagnoses.primary is a condition with code in dictionary "eHealth/ICPC2/condition_codes"

diagnoses.primary is a condition with code in dictionary "eHealth/ICD10_AM/condition_codes"

diagnoses.primary is a condition with code in dictionary "eHealth/ICD10_AM/condition_codes"

reasons

  • at least one required

  • is in dictionary eHealth/ICPC2/reasons

  • optional (if passed - must be in dictionary eHealth/ICPC2/reasons)

  • optional (if passed - must be in dictionary eHealth/ICPC2/reasons)

hospitalisation

is absent in request

is absent in request

if encounter.type == "discharge" - this block is mandatory

  • discharge_disposition is mandatory

  • discharge_department is mandatory

For other encounter types

  • optional

action_references

is absent in request

if encounter.type == "patient_identity" 

  • no validations

For other encounter types

  • one of must exist:

    1. action_references in encounter

    2. OR diagnostic report in package

    3. OR procedure in package

if encounter.type == "patient_identity" 

  • no validations

For other encounter types

  • one of must exist:

    1. action_references (service.category=counselling) in encounter

    2. OR diagnostic report in package

    3. OR procedure in package

division

 

 

Division must be filled

Validate Conditions

  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"

  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>"

  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>')

  12. Validate primary_source:

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

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

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

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

    • if primary_source = false - skip this check

...

  1. EDP with type == "patient_identity" should have list of special observations. 

  2. Such list can contain limited set of codes, some of them are mandatory

code

M/O

height

M

weight

M

sex

M

stature

O

eye_colour

O

hair_ color

O

hair_length

O

beard

O

mustache

O

clothes

O

peculiarity

O

Validate Immunizations

  1. Validate immunizations ids as  primary keys

  2. Validate primary_source

    1. in case primary_source == true

      1. $..performer must be filled

        1. in case of error return 422 with msg "performer must be present if primary_source is true"

      2. $..report_origin must be absent

        1. in case of error return 422 with msg "Only one of the parameters must be present"

      3. check not_given parameter

        1. in case not_given == false

          1. $..explanation.reasons, $..manufacturer, $..lot_number, $..expiration_date, $..dose_quantity.value, $..dose_quantity.unit, $..dose_quantity.code, $..site, $..route, $..vaccination_protocols.dose_sequence, $..vaccination_protocols.authority, $..vaccination_protocols.series, $..vaccination_protocols.series_doses, $..vaccination_protocols.target_diseases must be filled (inclusive with those that are mandatory according to the apiary)

            1. in case of error return 422 with msg "<reasons|manufacturer|lot_number|expiration_date|value|unit|code|site|route|dose_sequence|authority|series|series_doses|target_diseases> must be present if primary_source is true and not_given is false"

          2. $..explanation.reasons_not_given must be absent

            1. in case of error return 422 with msg "Only one of the parameters must be present"

        2. in case not_given == true

          1. $..explanation.reasons_not_given, $..vaccination_protocols.dose_sequence, $..vaccination_protocols.authority, $..vaccination_protocols.series, $..vaccination_protocols.series_doses, $..vaccination_protocols.target_diseases must be filled (inclusive with those that are mandatory according to the apiary)

            1. in case of error return 422 with msg "<reasons_not_given|dose_sequence|authority|series|series_doses|target_diseases> must be present if primary_source and not_given is true"

          2. $..explanation.reasons must be absent

            1. in case of error return 422 with msg "Only one of the parameters must be present"

    2. in case primary_source == false

      1. $..report_origin must be filled

        1. in case of error return 422 with msg "report_origin must be present if primary_source is false"

      2. $..performer must be absent

        1. in case of error return 422 with msg "Only one of the parameters must be present"

      3. check not_given parameter

        1. in case not_given == true return error 422 with msg "Only completed immunizations can be filled if primary_source is false and not_given is true"

        2. in case not_given == false

          1. $..explanation.reasons, $..dose_quantity.value, $..dose_quantity.unit, $..vaccination_protocols.authority, $..vaccination_protocols.target_diseases must be filled (inclusive with those that are mandatory according to the apiary)

            1. in case of error return 422 with msg "<reasons|value|unit|authority|target_diseases> must be present if primary_source and not_given is false"

          2. if vaccination_protocols.authority == MoH $..vaccination_protocols.dose_sequence, vaccination_protocols.series, vaccination_protocols.series_doses must be filled

            1. in case of error return 422 with msg "<dose_sequence|series|series_doses> must be present if primary_source and not_given is false"

          3. $..explanation.reasons_not_given must be absent

            1. in case of error return 422 with msg "Only one of the parameters must be present"

          4. $..manufacturer must be optional

  3. Validate that context of immunizations is a current encounter

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

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

  4. Validate that the date is within acceptable limits

    1. $.immunizations[*].date <= current_time

      1. in case of error "Date must be in past"

    2. $.immunizations[*].date>=current_date-immunization_max_days_passed

      1. in case of error "Date must be greater than  {{current_date-immunization_max_days_passed}}"

  5. Validate performer according to the Rule 

  6. Validate that observation submitted as a detail of reaction is an existing observation that belongs to the current patient

    1. $.immunizations[*].reactions[*].detail.identifier.value is an ID of existing observation in ME.observations where (ME.observations.patient_id==patient_id from url) OR one of $.observations[*].id

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

...

  1. Validate diagnostic reports ids as primary keys

  2. Validate based_on as Reference

  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

      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

    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

  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 conclusion_code:

    1. $.diagnostic_reports[*].conclusion_code.coding[*].code validate that the code belongs to the dictionary system 'eHealth/ICD10_AM/condition_codes'

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

    2. Check that there is only one code in conclusion_code.coding array

      1. if more - return error "Only one code from one dictionary is allowed"

  9. Validate recorded_by as Employee

  10. Validate encounter

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

      1. in case of error 409 "Invalid reference"

  11. Validate performer:

    1. as Employee

    2. according to logic Performer(asserter) validation

  12. 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."

  13. Validate result_interpreter.identifier as Employee

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

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

  16. Validate primary_source

    1. If primary_source==true, then

      1. Managing organization MUST be filled

      2. performer.reference MUST be filled

    2. If primary_source==false, then

      1. report_origin must be filled

      2. performer.reference must NOT be filled

      3. results_enterpreter.reference must NOT be filled

  17. Validate patient verification status:

    1. If diagnostic report has based_on 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"

...

  1. Validate by json schema

  2. Validate procedure id as primary ke

  3. Validate status

    1. On create procedure status could be completed or not_done. `entered_in_error` could be set on update procedure.

      1. error 422 by json schema

  4. Validate code

    1. Validate code as Reference

    2. Validate procedure.service.is_active = true

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

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

  6. Validate encounter

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

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

  7. Validate performed_period/performed_date_time:

    1. if $.status == "not_done" check that  performed_period/performed_date_time fields are not present in request

      1. in case error return 422 entry: "$.performed_period" (or "$.performed_date_time"), rules[0].description: "Must not be present in procedure with status <$.status>"

    2. else, if $.status == "completed":

      1. Check that only one of this parameters present

        1. in case error return 422 "Only one of the parameters must be present"

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

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

    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

    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

    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 (Reference)

    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, "Observation in "entered_in_error" status can not be referenced" if observation, else - "Condition is canceled"

  13. Validate outcome

    1. validate outcome as a Reference 

    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 

    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. Validate patient verification status:

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

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

      1. in case of error return 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. 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

 

HTTP status codes

HTTP status code

Message

What caused the error

202

Response

 

401

Access denied

 

403

Invalid scopes

 

404

Patient not found

 

409

 

Validation error

422

 

Validation error