Table of Contents | ||
---|---|---|
|
...
Validate encounter id as a primary key (Submit Encounter Data Package | Primary key validation )
Validate that thedateis within acceptable limits$.encounter.date<= current_date$.encounter.date>=current_date-encounter_max_days_passed$.encounter.date>=episode.period.start whereepisode.id=$encounter.episode.identifier.valuein case of error return 422 "Encounter’s date must be equal to or greater than start date of episode"
Validate that the period is within acceptable limits
$.encounter.period.start<= current_date
in case of error return 422 "Date must be in past"
$.encounter.period.start>=current_date-encounter_max_days_passed
in case of error return 422 "Date must be greater than {{current_date-encounter_max_days_passed}}"
$.encounter.period.start>=episode.period.start where episode.id=$encounter.episode.identifier.value
in case of error return 422 "Encounter’s date must be equal to or greater than start date of episode"
$.encounter.period.end <= current_date
in case of error return 422 "End date must be equal to or less than current date"
$.encounter.period.end>= $.encounter.period.start
in case of error return 422 "End date must be greater than start date"
Validate "episode" is an active episode that belongs to the current patient
$.encounter.episode.identifier.value is one of ME.patinet{patient_id}.episodes{*}.id
in case of error return 422 "Episode with such ID is not found"
$.encounter.episode.identifier.value is an ID of an Episode that meets the requirements:
ME.patient{patinet_id}.episodes{episode_id}.status = 'active'
in case of error return 422 "Episode is not active"
ME.patient{patinet_id}.episodes{episode_id}.managing_organization==token.client_id
in case of error return 422 "Managing_organization in the episode does not correspond to user`s legal_entity"
Validate "visit" is a visit that belongs to the current patient
Validate referrals
As a referral it can be referenced electronic (registered in the system) OR paper service request
Validate ($.encounter.incoming_referrals OR $.encounter.paper_referral) or none in request
Validate incoming referrals as References (Submit Encounter Data Package#Referencevalidation)
Validate paper referral as Object (paper_referral)
Validate incoming referrals that corresponds to $.encounter.incoming_referrals[*].identifier.value have:
..used_by_legal_entity.identifier.value==token.client_id OR null
in case of error return 409 "Service request is used by another legal_entity"
..status==active or program_processing_status=in_progress (any status is valid in case program_processing_status= in_progress)
in case of error return 409 "Invalid service request status"
..if program is defined program_processing_status=new, in_queue or in_progress
check that service_request contains based_on parameter
in case based_on present in service_request
verify care_plan:
It should be in active status
Care plan's period end (if exist) should be greater than current date or equal.
verify activity:
It has activity.detail.kind=service_request; activity.detail.product_reference=service_id.
It has scheduled, in_progress status
For an old activities (has no units in quantity) validate remaining_quantity as described at Submit Encounter Data Package#Relatedcareplanvalidation
in case based_on not present in request skip previous validations.
Check if service request quantity is not exhausted as described at related service request validation
Validate performer
$.encounter.performer.identifier.value is an ID of existing employee in PRM.Employees
in case of error return "There is no Employee with such id"
$.encounter.performer.identifier.value == PRM.Employees.id where (PRM.Employees.status==`active`)
in case of error return "Employee is not active"
$.encounter.performer.identifier.value == PRM.Employees.id where (PRM.Employees.legal_entity== client_id)
"User can not create encounter for this legal_entity"
validate employee type according to encounter.class - use config file (employee_encounter_classes)
in case error return 422, "Employee.type $type is forbidden for your encounter class"
according to employee.type as stated in employee_encounter_types
in case error return 422, msg "Employee.type $type is forbidden for your encounter type"
division
$.encounter.division.identifier.value must meet the following requirements
PRM.division.status = "ACTIVE"
in case of error return 409 "Division is not active "
PRM.division.legal_entity= token.client_id
in case of error return 409 "User is not allowed to create encouners for this division"
Validate supporting_info as References (Submit Encounter Data Package#Referencevalidation)
Validate encounter.class
according to legal_entity.type - use config file (legal_entity_encounter_classes)
in case error return 409, msg "Encounter.class $class is forbidden for your legal entity type"
according to episode.type - use config file (episode_type_encounter_classes)
in case error return 409, msg "Encounter.class $class is forbidden for your episode type"
according to employee.type as stated in (employee_encounter_classes)
in case error return 409, msg "Encounter.class $class is forbidden for your employee type"
Validate encounter.type
according to encounter.class - use config file (encounter_class_encounter_types)
in case error return 409, msg "Encounter.type $type is forbidden for your encounter class"
Validate actions
Validate actions presence according to encounter class validations
in case error return '422', msg 'TBC'
Defined in the system that corresponds to encounter class validations
in case error return '422', msg 'TBC'
Validate action_references
Note. For encounter.action_references pass only "service", and the "service_group" does not passValidate action_references presence according to encounter class validations
in case error return '422', msg 'At least one of action references, diagnostic reports or procedures should exist in encounter package'
Validate code as a Reference(Submit Encounter Data Package#Referencevalidation)
Validate action_references is in prm.services, has status ACTIVE and is_active = true
in case error return '422', msg 'Service with such ID is not found'
in case error return '422', msg 'Service should be active'
Validate that action_references is service with service.category==”counselling” in case encounter.class=”AMB”
in case error return ‘422', msg 'Invalid service category for AMB encounter class'
Validate diagnoses
Validate conditions as References (Submit Encounter Data Package#Referencevalidation)
Validate encounter has exactly one diagnosis where $.encounter.diagnoses[?(@.role.coding[0].code=="primary")]
in case of error return 422 "Encounter must have exactly one primary diagnosis"
Validate condition.id is in DB or in current Encounter package
Validate that each condition is active (verification_status != entered_in_error)
in case of error return 409 "Conditions in diagnoses must be active"
Validate that primary diagnosis defined in the system that corresponds to encounter class validations
in case of error "Primary diagnosis should be defined in {$.encounter.diagnoses[*].role.coding[*].system } system"
Validate reasons
Validate reasons presence according to encounter class validations
in case error return '422', msg 'Validation failed. You can find validators description at our API Manifest: http://docs.apimanifest.apiary.io/#introduction/interacting-with-api/errors.', description 'can't be blank.
Validate hospitalization
Validate hospitalization presence according to encounter class validations
in case error return 422, msg "Hospitalization block is forbidden for encounter.class = $encounter.class"
Validate all fields according to schemata
destination
discharge_disposition
pre_admission_identifier
admit_source
re_admission
discharge_department
If encounter.type.code = "discharge" than encounter.hospitalization.admit_source is required, encounter.hospitalization.discharge_disposition is required, encounter.hospitalization.discharge_department is required
in case error return 422, msg "<parameter> is required for encounter.type.code = "discharge"
Validate destination is a valid legal_entity in prm with status is ACTIVE and is_active = true
in case error return 422, "Legal entity is not active"
Validate patient_id for encounter.type == "patient_identity"
$patient_id should exist in mpi.prepersons.id, have status =='ACTIVE' and is_active = true
in case error return 'TBC', msg 'TBC'
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
If service_requests.code.identifier.value is service, validate $resourse.code.identifier.value = service_requests.code.identifier.value
in case error return 409, "Service in $resourse differ from service in service request"
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')
in case error return 409, "Service in $resourse differ from services in service request's service_group"
Validate $resourse.service.is_active = true
in case error return 409, "Service should be active"
If patient is person - validate verification status:
If encounter has incoming referral with service request, then skip this validation.
Else check patient's verification_status is not equal to NOT_VERIFIED.
in case NOT_VERIFIED - return error 409, "Patient is not verified"
...
Validate observations ids as primary keys (Submit Encounter Data Package | Primary key validation )
Validate that context of observation is a current encounter
$.observations[*].context.identifier.value==$.encounter.id
in case of error return "Submitted context is not allowed for the observation"
Validate that the date is within acceptable limits
$.observations[*].issued <= current_time
in case of error return "Issued date must be in past"
$.observations[*].issued>=current_date-observation_max_days_passed
in case of error "Issued must be greater than {{current_date-observation_max_days_passed}}"
Validate performer(asserter)
Validate $.observations[*].components
if $.observations[*].code.coding[*].system is "eHealth/ICF/classifiers":
Check number of component items with $.observations[*].components[*].code.coding[*].system = "eHealth/ICF/qualifiers":
if $.observations[*].code.coding[*].code starts from "b" letter, then components must contain exact 1 item with:
$.observations[*].components[*].code.coding[*].code = "extent_or_magnitude_of_impairment"
in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"
in case of incorrect number of qualifiers - return 422 "Required 1 component, but got <number of items>"
in case value is not active in dictionary - return 422 "Value is not active"
if $.observations[*].code.coding[*].code starts from "s" letter, then components must contain exact 3 items with:
$.observations[*].components[*].code.coding[*].code = "extent_or_magnitude_of_impairment"
$.observations[*].components[*].code.coding[*].code = "nature_of_change_in_body_structure"
$.observations[*].components[*].code.coding[*].code = "anatomical_localization"
in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"
in case of incorrect number of qualifiers - return 422 "Required 3 components, but got <number of items>"
in case value is not active in dictionary - return 422 "Value is not active"
if $.observations[*].code.coding[*].code starts from "d" letter, then components must contain exact 2 items with:
$.observations[*].components[*].code.coding[*].code = "performance"
$.observations[*].components[*].code.coding[*].code = "capacity"
in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"
in case of incorrect number of qualifiers - return 422 "Required 2 components, but got <number of items>"
in case value is not active in dictionary - return 422 "Value is not active"
if $.observations[*].code.coding[*].code starts from "e" letter, then components must contain exact 1 item with:
$.observations[*].components[*].code.coding[*].code = "barrier_or_facilitator"
in case of missing qualifier - return 422 "Missing components with qualifiers <list of missing qualifiers>"
in case of incorrect number of qualifiers - return 422 "Required 1 component, but got <number of items>"
in case value is not active in dictionary - return 422 "Value is not active"
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
in case not present or doesn't correspond - return 422 "Doesn't correspond to $.observations[i].components[i].code"
in case code value is not active in dictionary - return 422 "Value is not active"
if observations[*].categories[0].coding[0].system == "eHealth/ICF/observation_categories" - skip validation of observations[*].value and make this fields optional
else - check that one off this fields present:
Validate$.observations[*].components[*].value_period as a Period
Validate $.observations[*].value_quantity
$.observations[*].value must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
$.observations[*].comparator can take the following values : [">", ">=", "=", "<=", "<"]
in case of error return "value is not allowed in enum"
$.observations[*].unit can take values from dictionary eHealth/ucum/units
in case of error return "value is not allowed in enum"
Validate $.observations[*].value_codeable_concept
$.observations[*].code validate that the code belongs to the dictionary system
in case of error return "Value is not allowed in enum"
Validate $.observations[*].value_boolean
$.observations[*].value_boolean must be boolean type
in case of error return "type mismatch. Expected boolean but got {entered type}"
Validate $.observations[*].value_string
$.observations[*].value_string must be string type
in case of error return "type mismatch. Expected string but got {entered type}"
Validate $.observations[*].value_sampled_data
$.observations[*].data must be string type
in case of error return "type mismatch. Expected string but got {entered type}"
$.observations[*].origin must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
$.observations[*].period must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
$.observations[*].factor must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
$.observations[*].lower_limit must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
$.observations[*].upper_limit must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
$.observations[*].dimensions must be with number type
in case of error return "type mismatch. Expected number but got {entered type}"
Validate $.observations[*].value_range
$.observations[*].low must be with object type
in case of error return "type mismatch. Expected object but got {entered type}"
$.observations[*].high must be with object type
in case of error return "type mismatch. Expected object but got {entered type}"
Validate $.observations[*].value_ratio
$.observations[*].numerator must be with object type
in case of error return "type mismatch. Expected object but got {entered type}"
$.observations[*].denominator must be with object type
in case of error return "type mismatch. Expected object but got {entered type}"
Validate $.observations[*].value_time
$.observations[*].value_time must be with string type
in case of error return "type mismatch. Expected string but got {entered type}"
Validate $.observations[*].value_date_time
$.observations[*].value_date_time must be with string type
in case of error return "type mismatch. Expected string but got {entered type}"
Validate diagnostic report is one of reports in the current package
$.observations[*].diagnostic_report.identifier.value == one of $.diagnostic_report[*].identifier.value
in case of error "Invalid reference"
Validate $.observations[*].reaction_on
check that the appropriate immunizations.status != "entered_in_error"
in case of error return 409 "Immunization with status ‘entered_in_error’ can not be use"
Validate $.observations[*].code
if $.observations.code.coding[*].code value is included in chart variables 'OBSERVATION_CODES_WITH_<VALUE_TYPE>_REQUIRED', <value_type> field is mandatory
in case of error return 422 “This field is required for code = <code>“
if observations[*].code.coding[*].system is "eHealth/ICF/classifiers", then:
Check observations[*].categories[*].coding[*].system should contain "eHealth/ICF/observation_categories"
in case of error return 422 “Code doesn't match observation category“
Check observations[*].components are presented
in case of error return 422 “Components required“
Validate $.observations.code.coding[*].code is active in corresponding dictionary
in case of error return 409, “Value is not active”
Validate $.observations[*].categories
is an array with only one item
in case of error return 422 "Expected a maximum of 1 items but got <number of elements>"
$.observations[*].categories[*].coding[*].system is "eHealth/observation_categories" or "eHealth/ICF/observation_categories"
in case of error return 422 "Value is not allowed in enum"
$.observations[*].categories[*].coding[*].code corresponds to the system
in case of error return 422 "Value <code> not found in the dictionary <$.observations[*].categories[*].coding[*].system>"
Validate $.observations.categories[*].coding[*].code is active in corresponding dictionary
in case of error return 409, “Value is not active”
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:
if category code is functions, then code value should start with "b" letter
if category code is structures, then code value should start with "s" letter
if category code is activities, then code value should start with "d" letter
if category code is environmental, then code value should start with "e" letter
in case of error return 422 “Code doesn't match observation category“
Validate specimen, if submitted:
Check the field is a Reference on a specimen resource
in case of error return 422 “not allowed in enum”
Check it exists in DB or within current package, and belongs to the same patient:
in case of error return 422 "Specimen not found"
Check status:
is available if the specimen was found in the DB
in case of error return 422 "Specimen created before the current package should be available"
is unavailable if the specimen not found in the DB, but in the package
in case of error return 422 "Specimen created in the current package should be unavailable"
Validate device:
Check the field is a Reference on a equipment resource
in case of error return 422 “not allowed in enum”
Validate status is 'ACTIVE' and is_active=true
in case error return 422 “Equipment is not active“
Validate availability_status is 'Available'
in case error return 422 ('Equipment is not available')
Validate is legal_entity_id is Legal entity for performer in Encounter
in case error return 422 ('Equipment does not belong to Legal entity')
If Equipment and Encounter has a division, then validate it is the same Division
in case error return 422 ('Equipment does not belong to division from the encounter')
Validate observations for encounter.type == "patient_identity"
...
Validate diagnostic reports ids as primary keys (Submit Encounter Data Package | Primary key validation )
Validate based_on as Reference(Submit Encounter Data Package#Referencevalidation)
Validate that service_request, referenced as based_on, is
in status is active or program_processing_status=in_progress (any status is valid in case program_processing_status= in_progress)
in case of error return 409 "Invalid service request status"
if program is defined than used_by_legal_entity==token.client_id OR null
in case of error return 409 "Service request is used by another legal_entity"
if program is defined than program_processing_status == new, in_queue or in_progress
check that service_request contains based_on parameter
in case based_on present in service_request
verify care_plan:
It should be in active status
Care plan's period end (if exist) should be greater than current date or equal.
verify activity:
It has activity.detail.kind=service_request; activity.detail.product_reference=service_id.
It has scheduled, in_progress status
For an old activities (has no units in quantity) validate remaining_quantity as described at Submit Encounter Data Package#Relatedcareplanvalidation
in case based_on not present in request skip previous validations.
Check if service request quantity is not exhausted as described at related service request validation
category
Validate that one of diagnostic reports categories corresponds to service category, that is references as code in DR
$.diagnostic_report.category[?]=PRM.services.category where PRM.services.id=$.diagnostic_report.code.identifier.value
in case of error return 422 "None of the diagnostic report categories matches with the service category"
Validate code
Validate code as Reference(Submit Encounter Data Package#Referencevalidation)
If service_requests.code.identifier.value is service, validate $diagnostic_report.code.identifier.value = service_requests.code.identifier.value
in case error return 409, "Service in diagnostic_report differ from service in service request"
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')
in case error return 409, "Service in diagnostic_report differ from services in service request's service_group"
Validate diagnostic_report.service.is_active = true
in case error return 409, "Service should be active"
Validate effective_period as a period (Submit Encounter Data Package#period_validationPeriodValidation)
Validate that issued is within acceptable limits
$.diagnostic_reports[*].issued<= current date_time
in case of error 422 "Asserted date must be in past"
$.diagnostic_reports[*].issued>=current_date-diagnostic_report_max_days_passed
in case of error 422 "Issued must be greater than {{current_date-diagnostic_report_max_days_passed}}"
Validate recorded_by as Employee (Submit Encounter Data Package#Employeevalidation)
Validate encounter
$.diagnostic_reports[*].encounter.identifier.value == $.encounter.id
in case of error 409 "Invalid reference"
Validate performer
as Employee Submit Encounter Data Package#Employeevalidation
according to logic Submit Encounter Data Package#Performer(asserter)validation
Validate managing_organization is a current legal_entity
$.managing_organization.identifier.value==token.client_id
in case of error 409 "Managing organization does not correspond to user's legal entity."
Validate result_interpreter.identifier as Employee (Submit Encounter Data Package#Employeevalidation)
Validate result_interpreter.identifier is an employee with employee_type = DOCTOR or SPECIALIST
Validate only One of the fields is filled:
$.diagnostic_report[*].results_interpreter.reference OR $.diagnostic_report[*].results_interpreter.text
$.diagnostic_report[*].performer.reference OR $.diagnostic_report[*].performer.text
Validate primary_source
If primary_source==true, then
Managing organization MUST be filled
performer.reference MUST be filled
If primary_source==false, then
report_origin must be filled
performer.text may be filled
performer.reference must NOT be filled
results_enterpreter.reference must NOT be filled
If patient is person - validate verification status:
If diagnostic report has based_on with service request, then skip this validation.
Else check patient's verification_status is not equal to NOT_VERIFIED.
in case NOT_VERIFIED - return error 409, "Patient is not verified"
Validate specimens, if submitted:
Check field has array with elements of Reference type on specimen resource
in case of error return 422 “not allowed in enum”
For each specimen check:
Check it exists in DB or within current package, and belongs to the same patient:
in case of error return 422 "Specimen not found"
Check it is present in the only one diagnostic report within the package.
in case of error return 422 "Specimen is already used in another diagnostic report"
Check status:
is available if the specimen found in the DB
in case of error return 422 "Specimen created before the current package should be available"
is unavailable if the specimen not found in the DB, but in the package
in case of error return 422 "Specimen created in the current package should be unavailable"
Validate used_references
Validate used_reference.identifier.type.coding.[0].code is 'equipment'
in case error return 422 "value is not allowed in enum"
Validate used_reference.identifier.type.coding.[0].code is status is 'ACTIVE' and is_active=true
in case error return 422 ('Equipment is not active')
Validate used_reference.identifier.type.coding.[0].code is availability_status is 'Available'
in case error return 422 ('Equipment is not available')
Validate used_reference.identifier.type.coding.[0].code is legal_entity_id is Legal entity for performer in Encounter
in case error return 422 ('Equipment does not belong to Legal entity')
If Equipment and Diagnostic report has a division, then validate it is the same Division
in case error return 422 ('Equipment does not belong to division from diagnostic report')
Validate Procedures
Validate by json schema
Validate procedure id as primary key (Submit Encounter Data Package | Primary key validation )
Validate status
On create procedure status could be completed or not_done. `entered_in_error` could be set on update procedure.
error 422 by json schema
Validate code
Validate code as Reference(Submit Encounter Data Package#Referencevalidation)
Validate procedure.service.is_active = true
in case error return 409, "Service is not active"
Validate that service_request, referenced as based_on, is
check that service_request contains based_on parameter
in case based_on present in service_request
verify care_plan:
It should be in active status
Care plan's period end (if exist) should be greater than current date or equal.
verify activity:
It has activity.detail.kind=service_request; activity.detail.product_reference=service_id.
It has scheduled, in_progress status
For an old activities (has no units in quantity) validate remaining_quantity as described at Submit Encounter Data Package#Relatedcareplanvalidation
in case based_on not present in request skip previous validations.
Check if service request quantity is not exhausted as described at related service request validation
Validate encounter
$.procedure[*].encounter.identifier.value == $.encounter.id
in case error return 409, "Submitted encounter is not allowed for procedure"
Validate performed_period/performed_date_time:
if $.status == "not_done" check that performed_period/performed_date_time fields are not present in request
in case error return 422 entry: "$.performed_period" (or "$.performed_date_time"), rules[0].description: "Must not be present in procedure with status <$.status>"
else, if $.status == "completed":
Check that only one of this parameters present
in case error return 422 "Only one of the parameters must be present"
Validate performed_date_time
performed_date_time is real
in case error return 422, "Performed_date_time in invalid"
performed_date_time <= now
in case error return 422 "Procedure cannot be registered in future"
Validate performed_period
$.performed_period.start<= now
in case of error return 422 "Procedure cannot be registered in future"
$.performed_period.end>= $.performed_period.start
in case of error return 422 "End date must be greater than start date"
performed_period.end <= now
in case error return 422 "Procedure cannot be registered in future"
Validate $.performed_period as required field in case if procedure based on service request with quantity that has code=MINUTE (system=SERVICE_UNIT)
in case of error return 422 "can't be blank"
Validate recorded_by
Validate recorded_by as Reference(Submit Encounter Data Package#Referencevalidation)
$..recorded_by.identifier.value is an ID of existing employee in PRM.employee
in case of error return 422, "Employee with such id is not found"
Validate recorded_by is employee with status='APPROVED' and is_active= true and end_date is null or more than today
in case error return 409, "This action is prohibited for current employee"
Validate employees.legal_entity_id=$managing_organization.identifier.value
in case error return 409, "Employee should be from current legal entity"
Validate asserter
Validate division
Validate division as Reference (Submit Encounter Data Package#Referencevalidation)
$division is an ID in PRM.divisions
in case return 422, "Division with such id is not found"
division.status=ACTIVE and is_active=true
in case error return 409, "Division is not active"
division.legal_entity_id = $client_id or division.legal_entity_id=$managing_organization.identifier.value
in case error return 409, "Division is not in current legal_entity"
Validate managing_organization is a current active legal_entity with proper type
as Reference (Submit Encounter Data Package#Referencevalidation)
$managing_organization is an ID in PRM.legal_entities
in case return 422, "Legal entity with such id is not found"
validate managing_organization status is 'ACTIVE' and is_active=true
in case error return 422 ('Legal entity is not active')
validate legal_entity type is in ('PRIMARY_CARE','MSP','MSP_PHARMACY','MSP_PHARMACY') (use `ME_ALLOWED_TRANSACTIONS_LE_TYPES` from charts)
in case error return 422, "Legal entity with type $legal_entity.type cannot perform procedures"
validate $managing_organization.identifier.value = $client_id
in case of error 409 "Managing organization does not correspond to user's legal entity."
Validate reason_references
Validate reason_reference as a Reference (Submit Encounter Data Package#Referencevalidation)
Validate reason_refernce.identifier.type.coding.[0].code is 'condition' or 'observation'
in case error return 422 "value is not allowed in enum"
Validate reason_refernce.identifier.value is condition or observation not in status ENTERED_IN_ERROR
in case error return 422, "<Medical event resource> in "entered_in_error" status can not be referenced"
Validate outcome
validate outcome as a Reference (Submit Encounter Data Package#Referencevalidation)
validate outcome.coding.object.system is in dictionary eHealth/procedure_outcomes
in case error return 422, "outcome not in dictionary eHealth/procedure_outcomes"
Validate complication_details
validate complication_details as a Reference (Submit Encounter Data Package#Referencevalidation)
validate complication_details.identifier.value refer to condition in the same encounter package
in case error return 422, "complication_details does not correspond to condition in this encounter package"
Validate category
according to the dictionary 'eHealth/procedure_categories' - by schemata
Validate that procedure category corresponds to service category, that is references as code in procedure
$.procedure.category=PRM.services.category where PRM.services.id=$.procedure.code.identifier.value
in case of error return 422 "Procedure category does not match with the service category"
If patient is person - validate verification status:
If procedure has based_on with service request, then skip this validation.
Else check patient verification_status is not equal to NOT_VERIFIED.
in case NOT_VERIFIED - return error 409, "Patient is not verified"
Validate used_codes
Check that the $.used_codes[*].coding[*].code belongs to the dictionary in $.used_codes[*].coding[*].system
in case of error - return 422 "Value is not allowed in enum"
Validate 'used_codes.coding.code' is_active = true
in case error return 409, "Value is not active"
Validate used_references
Validate used_reference.identifier.type.coding.[0].code is 'equipment'
in case error return 422 "value is not allowed in enum"
Validate used_reference.identifier.type.coding.[0].code is status is 'ACTIVE' and is_active=true
in case error return 422 ('Equipment is not active')
Validate used_reference.identifier.type.coding.[0].code is availability_status is 'Available'
in case error return 422 ('Equipment is not available')
Validate used_reference.identifier.type.coding.[0].code is legal_entity_id is Legal entity for performer in Encounter
in case error return 422 ('Equipment does not belong to Legal entity')
If Equipment and Procedure has a division, then validate it is the same Divisioin
in case error return 422 ('Equipment does not belong to division from procedure')
Validate focal_device is an array of objects with action and manipulated attributes, optional. For each element:
Check that $.action is of CodeableConcept type, optional:
Check that $.action.system is
procedure_focal_device_actions
dictionary, requiredin case of error - return 422 ('value is not allowed in enum')
Check that $.action.code comply with $.action.system, required
in case of error - return 422 ('value is not allowed in enum')
Check that $.manipulated is a Reference on Device resource, required
Check that Device exists in the current package or in the DB and belongs to the patient ($.subject)
in case of error - return 422 ('Device not found')
Check that Device has status = active
in case of error - return 422 ('Device is not active')
Validate Clinical impression
...
Validate by json schema
Validate device dispenses ids as primary keys (Submit Encounter Data Package | Primary key validation )
Validate device dispenses's root attributes:
Validate performer, location as described at Create Device dispense | Validate dispense
Validate $.status isCOMPLETED or DECLIEND
else - return 422 ("value is not allowed in enum")
If based_on is present, validate:
Check it references to device_request resource
in case of error - return 422 ('value is not allowed in enum')
Check that device request exists and belongs to the same patient
in case of error - return 422 ('Device request not found')
Сheck that device request is in status 'active'
in case of error - return 409 error ('Device request is not active')
Check that intent specified in Device request is
order
in case of error - return 409 error ('Only device request with intent = 'order' can be dispensed')
Verify care plan Activity as described in Qualify Device request | Validate related Care plan
Check that program in device request is empty (device_requests.program = null)
in case of error - return 409 ('Device request with program can not be referenced')
Verify care plan Activity as described in Qualify Device request | Validate related Care plan
validate when_handed_over
If based_on is present check that when_handed_over is equal or greater then device_request.authored_on
1. in case of error - return 409 error ('when_handed_over date can not be lesser then the authored_on date of the related Device request')
Validate encounter :
Validate encounter references the current encounter, submitted within the same package
$.device_dispenses[*].encounter.identifier.value==$.encounter.id
in case of error return 422 "Device dispense can only reference encounter from the same package"
Validate encounter period fully contains when_handed_over date
$.encounter.period.start<$.device_dispenses[*].when_handed_over and $.encounter.period.end_date>$.device_dispenses[*].when_handed_over
in case of error return 422 "Device dispense when_handed_over date doesn’t match with encounter period”
Validate part_of:
Check it references to procedure resource
in case of error - return 422 ('value is not allowed in enum')
Validate that procedure reference one of procedures, submitted within the same package
in case of error return 422 "Device dispense can only reference procedure from the same package"
Validate that procedure is not in status "entered_in_error" or “not_done”
in case of error - return 422 ("Procedure in <status> status can not be referenced")
Validate supporting_info:
Check it references condition, observation, diagnostic_report, procedure, encounter, episode,device or device_association resource
in case of error - return 422 ('value is not allowed in enum')
Check that {resource} exists and belongs to the same patient, or it is within current package
in case of error - return 422 ('{resource} not found')
Validate that {resource} is not in status "entered_in_error"
in case of error - return 422 ("{resource} in status "entered_in_error" can not be referenced")
Validate $.details.device_code if present:
if based_on is present validate Dispense details as described at Create Device dispense | Validate device
if based_on is NOT present:
Check system($.details.device_code.coding.system) = device_definition_classification_type
in case of error - return 422 ('value is not allowed in enum')
Get device_code from the dictionary
device_definition_classification_type
($.details.device_code.coding.code) and check parameter is_active = truein case of error - return 422 ('value is not allowed in enum')
If reference on Device definition is present in $.details.device:
if based_on is present: Create Device dispense | Validate device_code
if based_on is NOT present
Check code ($.details.device.identifier.type.coding.code) =
device_definition
in case of error - return 422 ('value is not allowed in enum')
Get device definition by id ($.details.device.identifier.value)
device_definition.is_active = true
in case of error - return 422 ('Device definition not found')
Check the remainder of the division ($.details.quantity.value/device_definition.packaging_count) is equal to 0
in case of error - return reject_reason = “The quantity must be divisible to packaging_count of prescribed Device Definition”
If reference on Device is present in $.details.device:
Check that device exists and belongs to the same patient, or it is within current package
in case of error - return 422 ('Device not found')
Validate that device status is in status "active"
in case of error - return 422 ("Only Devices in status "active" can be referenced")
Validate that device.availability_status is “available”
in case of error - return 422 ("Only Devices in availability_status"available" can be referenced")
If based_on is present, validate:
if referenced Device request($.based_on) contains code (device_request.code)
Check that the type in the Device($.details.device) is equal to the code in the Device request($.based_on)
in case of error - return 422 ("Dispensed device doesn’t match with prescribed device")
if referenced Device request($.based_on) contains code_reference (device_request.code_reference)
Check that the definition in the Device($.details.device) is equal to the code_reference in the Device request($.based_on)
in case of error - return 422 ("Dispensed device doesn’t match with prescribed device")
Validate quantity
if based_on is present validate quantity as described at Create Device dispense | Valdate quantity , but also include Device dispenses from the current package in remaining_quantity calculation
else validate quantity.value is an integer bigger than 0
Validate related Care plan
Verify care plan Activity as described in Qualify Device request | Validate related Care plan
Validate Devices
Validate by json schema
Validate device id as a primary key (Submit Encounter Data Package | Primary key validation )
Validate that context of Devices is a current encounter
Check that $.devices[*].context.identifier.value == $.encounter.id
in case of error - return 422 ('Submitted context is not allowed for the device')
Validate identifier is of Identifier type, optional
Check $.identifier.type is of CodeableConcept type, required:
Check that $.type.system is
external_system
dictionary, requiredin case of error - return 422 ('value is not allowed in enum')
Check that $.type.code comply with $.type.system, required
in case of error - return 422 ('value is not allowed in enum')
Check $.identifier.value is of String type, required
Validate definition is a Reference on Device Definition resource, optional
Check that Device Definition exists
in case of error - return 422 ('Device definition not found')
Check that Device Definition is_active
in case of error - return 422 ('Device definition is not active')
Check that classification_type of the Device Definition matches to the $.type
in case of error - return 422 ('Device definition type doesn't match device type')
Validate status is of String type, required
Check it is
active
, according toeHealth/device_statuses
dictionaryin case of error - return 422 ('value is not allowed in enum')
Validate name is an array of objects with type and value attributes, required
Check array contains at least one element
in case of error - return 422 ('expected a minimum of <min> items but got <actual>')
For each element:
Check that $.type is
device_name_type
dictionary, requiredin case of error - return 422 ('value is not allowed in enum')
Check that $.value comply with $.type, required
in case of error - return 422 ('value is not allowed in enum')
Check that there are no duplicated name types within names (
$.name.type
must be unique within$.name
array)in case of error - return 422 ('Values are not unique by 'type')
Validate type is of CodeableConcept type, required:
Check that $.type.system is
device_definition_classification_type
dictionary, requiredin case of error - return 422 ('value is not allowed in enum')
Check that $.type.code comply with $.type.system, required
in case of error - return 422 ('value is not allowed in enum')
Check that $.type.coding.code is in allowed active values from
device_definition_classification_type
dictionary.in case of error - return 422 ('value is not allowed in enum')
Validate property is an array of objects with code and value_[x] attributes, optional. For each element in the array:
Check that value from $.property.code is in allowed active values from
device_properties
dictionary.in case of error - return 422 ('value is not allowed in enum')
Check $.property.value_[x] is one of the following:
value_codeable_concept
,value_quantity
,value_boolean
,value_range
,value_integer
,value_string
in case of value_[x] is missing - return 422 ('At least one of the properties must be present')
in case of more than one value_[x] provided - return 422 ('Only one of the properties must be present')
in case of value_[x] is provided with incorrect type - return 422 ('type mismatch. Expected [x] but got <type>')
Validate parent is a Reference on Device resource, optional. Validate it according to Submit Encounter Data Package#Referencevalidation
Validate recorder is a Reference on Employee resource, required
Check that $.recorder.identifier.value is an id of existing employee in DB (PRM.employees)
in case of error - return 422 ('Employee with such id is not found')
Check that employee has status='APPROVED' and is_active= true and end_date is null or more than today
in case error - return 422 ('This action is prohibited for current employee')
Extract user_id from token. Check that recorder belongs to one of the user’s employee.
in case of error - return 422 ('User is not allowed to register the device for the employee')
Validate manufacture_date is a timestamp, optional
Check it is less than current date
in case of error - return 422 ('Manufacture date must be in the past')
Check if there is at least one related Device Association in the current package, that has status
implanted
orattached
in case of error - return 422 ('No device association with status implanted or attached found for the device within current package')
Validate Device Association
Validate by json schema
Validate device id as a primary key (Submit Encounter Data Package | Primary key validation )
Validate that context of Device Associations is a current encounter
Check that $.device_associations[*].context.identifier.value == $.encounter.id
in case of error - return 422 ('Submitted context is not allowed for the device association')
Validate device is a Reference on Device resource, required
Check that Device exists in the current package or in the DB and belongs to the patient ($.subject)
in case of error - return 422 ('Device not found')
Check Device has a status that is not entered_in_error
in case of error - return 422 ('Device in 'entered_in_error' status can not be referenced')
Validate status is of String type, required
Check it is
implanted
,explanted
,attached
orunattached
according todevice_association_statuses
dictionaryin case of error - return 422 ('value is not allowed in enum')
If $.device in the current package:
Check if current Device Association is the one of two allowed in the package for the Device ($.device).
in case of more then one found - return 422 ('Maximum 2 device associations allowed in the package for the registered device')
Validate found in the package another Device Association in relation to the current Device Association status:
if status is
implanted
, then there is no another Device Associations OR exists only one with status=explanted and its recorded datetime is greater then $.recorded datetime of the current associationin case another association has invalid status - return 422 ('Another device association should be in corresponding status to implanted')
in case explanted has recorded before the implanted - return 422 ('Device association with implanted status should have $.recorded before association with status explanted')
if status is
explanted
, then there exists Device Association in status=implanted for the $.devicein case of error - return 422 ('Device association with implanted status should exist before submitting association with status explanted')
if status is
attached
, then there is no another Device Associations OR exists only one with status=unatached and its recorded datetime is greater then $.recorded datetime of the current associationin case another association has invalid status - return 422 ('Another device association should be in corresponding status to attached')
in case unattached has recorded before the attached - return 422 ('Device association with attached status should have $.recorded before association with status unattached')
if status is
unattached
, then there exists Device Association in status=attached for the $.devicein case of error - return 422 ('Device association with attached status should exist before submitting association with status unattached')
If $.device is already existing in the DB:
Check there is no another Device Associations for the Device ($.device) in the current package
in case of error - return 422 ('Maximum 1 device association allowed in the package for the existing device')
Check current Device Association is not in
implanted
statusin case of error - return 422 ('Device can not be implanted')
Find the last Device Association of the Device ($.device) that is not in eneterd_in_error status using descending ordering by “recorded” field
in case not found - return 422 ('The last device association not found')
Validate the last that is not in eneterd_in_error status Device Association in relation to the current Device Association status:
if status is
explanted
, then the last one hasimplanted
statusin case of error - return 422 ('The last device association must be in implanted status')
if status is
attached
, then the last one hasunattached
statusin case of error - return 422 ('The last device association must be in unattached status')
if status is
unattached
, then the last one hasattached
statusin case of error - return 422 ('The last device association must be in attached status')
Validate body_site is of CodeableConcept type, optional
Check that $.system is
eHealth/body_sites
dictionary, requiredin case of error - return 422 ('value is not allowed in enum')
Check that $.code comply with $.system, required
in case of error - return 422 ('value is not allowed in enum')
Validate recorder is a Reference on Employee resource, required
Check that $.recorder.identifier.value is an id of existing employee in DB (PRM.employees)
in case of error - return 422 ('Employee with such id is not found')
Check that employee has status='APPROVED' and is_active= true and end_date is null or more than today
in case error - return 422 ('This action is prohibited for current employee')
Extract user_id from token. Check that recorder belongs to one of the user’s employee.
in case of error - return 422 ('User is not allowed to register the device for the employee')
Validate association_date is of Date type, optional
Check it is less than or equal to current date
in case of error - return 422 ('Association date must be less than or equal to current date')
Validate recorded is of DateTime type, required
Check it greater then the recorded datetime of the last existing Device Association (if such exists), that is not entered_in_error. Find the last Device Association of the Device ($.device) that is not in 'entered_in_error' status, using descending ordering by the 'recorded' field.
in case of error - return 422 ('Must be greater than recorded datetime of the last device association')
Check it less then or equal to current datetime.
in case of error - return 422 ('Recorded must be less than or equal to current datetime')
Validate Detected Issues
Validate by json schema
Validate Detected Issue's id as a primary key (Submit Encounter Data Package | Primary key validation )
Validate that encounter of Detected Issues is a current encounter
Check that $.detected_issues[*].encounter.identifier.value == $.encounter.id
in case of error - return 422 ('Submitted encounter is not allowed for the detected issue')
Validate status is of String type, required
Check it is
preliminary
ormitigated
, according todetected_issue_statuses
dictionaryin case of error - return 422 ('value is not allowed in enum')
Validate code is of CodeableConcept type, optional
Check that $.system is
detected_issue_codes
dictionary, requiredin case of error - return 422 ('value is not allowed in enum')
Check that $.code comply with $.system, required
in case of error - return 422 ('value is not allowed in enum')
Validate author is a Reference type, required.
Check it references to employee or patient resource
in case of error - return 422 ('value is not allowed in enum')
If author is an employee:
Check it exists in the DB
in case of error - return 422 ('Employee not found')
Check it is active and approved
in case of error - return 422 ('Invalid employee status')
If author is a patient:
Check it is current patient ($.subjectpatient_id is a hashed person_id from URL)
in case of error - return 422 ('In case author is patient it must be the current patient')
Validate implicated is a Reference on Device resource, optional
Check that Device exists in the current package or in the DB and belongs to the patient ($.subjectpatient_id is a hashed person_id from URL)
in case of error - return 422 ('Device not found')
Check Device has a status that is not entered_in_error
in case of error - return 422 ('Device in 'entered_in_error' status can not be referenced')
Validate recorder is a Reference on Employee resource, required
Check that $.recorder.identifier.value is an id of existing employee in DB (PRM.employees)
in case of error - return 422 ('Employee with such id is not found')
Check that employee has status='APPROVED' and is_active= true and end_date is null or more than today
in case error - return 422 ('This action is prohibited for current employee')
Extract user_id from token. Check that recorder belongs to one of the user’s employee.
in case of error - return 422 ('User is not allowed to register the device for the employee')
Validate subject is a Reference on Device resource, required
Check that Device exists in the current package or in the DB and belongs to the patient ($.subjectpatient_id is a hashed person_id from URL)
in case of error - return 422 ('Device not found')
Check Device has a status that is not entered_in_error
in case of error - return 422 ('Device in 'entered_in_error' status can not be referenced')
Validate based_on is a Reference on Detected Issue resource, optional
Check that Detected Issue exists in the current package or in the DB and belongs to the patient ($.patient_id is a hashed person_id from URL)
in case of error - return 422 ('Detected Issue not found')
Check that referenced Detected Issue has the same $.subject
in case of error - return 422 ('Detected Issue has different subject')
Check that referenced Detected Issue is not in entered_in_error status
in case of error - return 422 ('Detected Issue in 'entered_in_error' status can not be referenced')
Primary key validation
Validate that IDs of all submitted entities in the array are unique
validate that $.{collection}[*].id from the payload are all unique among themselves
in case of error return 409 "All primary keys must be unique"
validate there is no entity with such id in the corresponding Medical events collection
in case of error return 422 "{Entity} with such id already exists"
...
Save signed_content to Media Storage
Generate accession_identifier number for each specimen if submitted:
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
Encode and set it into $.accession_identifier attribute
Save data to corresponding collections in DBs
Save link to the signed content to the encounter
Enrich encounter.diagnoses:
select condition.code from Medical Events DB(or from request body) where condition.id==diagnoses[@].condition.identifier.value
set diagnoses[@].code = select 1
Save diagnoses from encounter to episodes.current_diagnoses
ME.patients.episodes.diagnoses = $.encounter.diagnoses
Add a record to the ME.patient.episodes{episode_id}.diagnoses_hstr
date = current_date
evidence = reference to encounter ($.encounter.id)
diagnoses = $.encounter.diagnoses
Set display_value to employees for all submitted objects
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)) as “Select 1“
ME.patients.encounters{encounter_id}.performer.display== Select 1
ME.conditions{condition_id}.asserter.display == Select 1
ME.observations{observation_id}.performer.display == Select 1
ME.patients.immunizations{immunization_id}.performer.display == Select 1
ME.patients.allergy_intolerance{ai_id}.asserter.display == Select 1
ME.patients.medication_statements{ms_id}.asserter.display == Select 1
ME.patients.risk_assessment{rs_id}.asserter.display == Select 1
ME.patients.diagnostic_reports{dr_id}.performer.reference.display == Select 1
ME.patients.diagnostic_reports{dr_id}.recorded_by.reference.display == Select 1
ME.patients.diagnostic_reports{dr_id}.results_interpreter.reference.display == Select 1
ME.clinical_impressions{clinical_impression_id}.assessor.display == Select 1
ME.specimens{specimen_id}.registered_by.reference.display == Select 1
ME.specimens{specimen_id}.collector.reference.display == Select 1, if collector’s type is employee
ME.devices{device_id}.recorder.reference.display == Select 1
ME.device_associations{device_accociation_id}.recorder.reference.display == Select 1
ME.device_issues{device_issue_id}.recorder.reference.display == Select 1
ME.device_issues{device_issue_id}.author.reference.display == Select 1, if author’s type is employee
In case there are reactions ($.observations[?].reaction_on) in the request, update corresponding immunizations with the reactions:
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
Set display_value for legal_entities
ME.patients.diagnostic_reports{dr_id}.managing_organization.display_value
ME.specimens{specimen_id}.managing_organization.display_value
ME.devices{device_id}.recorder_legal_entity.reference.display_value
ME.device_associations{device_association_id}.recorder_legal_entity.reference.display_value
ME.device_issues{device_issue_id}.recorder_legal_entity.reference.display_value
Set managing_organization for submitted observations, conditions, encounter
ME.conditions{cond_id}.managing_organization=token.client_id
ME.observations{observ_id}.managing_organization=token.client_id
ME.encounters{encounter_id}.managing_organization=token.client_id
In case encounter.incoming_referral was filled, set episode_origin to encounter
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))
In case diagnostic_reports.based_on was filled, set episode_origin to diagnostic report
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))
In case encounter.incoming_referral was filled set $.encounter.id to related to $.service_request activity[].outcome_reference
In case procedures.based_on was filled set $.procedures.id to related to $.service_request $.activity[].outcome_reference
In case diagnostic_reports.based_on was filled set $.diagnostic_reports.id to related to $.service_request activity[].outcome_reference
Update $ .activity.status to in_progress if previous activity status was scheduled
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)
Update remaining_quantity in the service request with a value that was calculated in the Related service request section above
If there are at least one record for speciality where speciality_officio = true:
Enrich encounter data with performer speciality:
SELECT speciality -> 'speciality' FROM employees WHERE speciality ->> 'speciality_officio' = 'true' AND id = $.encounter.performer.identifier.value
Set encounter.performer_speciality as CodeableConcept type with system = SPECIALITY_TYPE
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)
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 Specimen status model . Also, set status_reason for a specimen: system = specimen_invalidate_reasons, code = used.
Set following fields for Device Dispense: performer_legal_entity= client_id from token, details.quantity.unit = description according to quantity code and system, origin_episode_id= context_episode_id from device request referenced in based_on, context_episode_id = episode referenced by current encounter )
If the Package contains Device Dispense in status completed, and related Device request has reference on an Activity as a device_request.based_on, then
add reference on the device dispense resource to the outcome_reference attribute of the activity
if Activity.status is
scheduled
change it toin_progress
If the Package contains Device Dispense with related Device request that has a quantity but no medical program:
calculate remaining quantity of the related Device request (same as on [UPD] Get Device request details | Service logic):
Select all Device dispenses with following parameters( including Device dispenses from the current package):
based_on is current Device request
status = completed
Sum
quantity
in the filtered Device dispenses as dispensed_qtyCalculate remaining_quantity = requested_quantity- dispensed_quantity
If remaining_quantity is 0, change status of the related Device request($.based_on) to completed
Set following fields for Devices, Device Associations:
subject is a hashed person_id (from URL)
context_episode_id is an episode identifier from the $.encounter.episode
recorder_legal_entity is a client_id from token
Set following fields for Detected Issues:
patient_id is a hashed person_id (from URL)
context_episode_id is an episode identifier from the $.encounter.episode
recorder_legal_entity is a client_id from token