Versions Compared

Key

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

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Introduction


Specification

Apiary

Validation

Authorization

  1. Verify the validity of access token

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

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

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

Request validation

DS validation

  1. DS must be valid

  2. The document must be signed by recorder

    1. Select PRM.parties.tax_id from PRM where PRM.parties.id ==( Select  PRM.employees.party_id where PRM.employees.id==$.diagnostic_report.recorded_by.identifier.value)

    2. ds.drfo == select a

      1. in case of error retuert 409 "Document must be signed by the recorder of the diagnostic_report"

  3. Recorder must be a current user

    1. $.diagnostic_report.recorded_by.identifier.value is one of current user's employee

      1.  in case of error return 409 "Document must be sent by the recorder of the diagnostic_report"

Validate Legal Entity Type

Validate legal entity from token: legal_entities.type should be in me_allowed_transactions_le_types and legal_entities.status =='active' 

Diagnostic report validation

  1. Validate diagnostic_report _id is unique for MongoDB.Diagnostic_reports

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

  3. Validate that service, referenced as a code in DR, is active
    Note. For diagnostic_report.code pass only "service", and the "service_group" does not pass

    1. PRM.services.is_active = true where PRM.services.id=$.diagnostic_report.code.identifier.value

      1. in case of errror return 422 "Service is not active"

    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. if request_allowed==false return error 422 "Request is not allowed for this service"

  4. Validate referrals

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

    2. Validate ($.diagnostic_report.based_on OR $.diagnostic_report.paper_referral) or none in request

    3. Validate based on as Reference(Referencevalidation)

    4. Validate paper referral as Object (paper_referral)

    5. 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. 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 used_by_legal_entity==token.client_id or NULL

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

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

      5. check that service_request contains based_on parameter

        1. in case based_on present in service_request

          1. check that care_plan in active status

            1. in case of error return 422 with msg (Refers to care plan with invalid status)

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

            1. in case of error return 422 with msg (Care Plan end date is expired)

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

  5. Validate effective_period as a period (PeriodValidation)

  6. Validate that issued is within acceptable limits

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

      1. in case of error 422 "Issued 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}}" 

  7. Validate recorded_by as Employee (Employeevalidation)

  8. Validate performer.identifier as Employee (Employeevalidation)

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

  10. Validate result_interpreter.identifier as Employee (Employeevalidation)

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

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

  13. Validate division

    1. Validate division as Reference(Referencevalidation)

    2. $division is an existing 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

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

Observation validation

  1. Validate observations ids as  primary keys (Primarykeyvalidation)

  2. Validate that diagnostic_report of ALL observation is a current DR

    1. $.observations[*].diagnostic_report.identifier.value==$.diagnostic_report.id

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

  3. $.observations[*].effective_period validate as Period PeriodValidation

  4. Validate that the date is within acceptable limits

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

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

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

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

  5. Validate performer  as Employeevalidation

  6. Validate $.observations[*].value_period as a Period

  7. Validate component

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

  8. Related care plan validation

    1. in case service request has reference on care plan and diagnostic report has reference on service request check possibility to create diagnostic report depending on service_request[].activity remaining quantity

      1. calculate the quantity of artifacts that are contained in the request and have a link to the service request. Compare remaining_quantity from activity with the quantity of artifacts. Check that difference is greater then or equal to zero

        1. in case of error return 409 "The total amount of the prescribed service quantity exceeds quantity in care plan activity"

Postprocessing
Set managing_organization for submitted observations

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

  2. in case service request has reference on care plan and diagnostic report.based_on was filled set $.diagnostic_report.id to related to $.service_request $.activity[].outcome_reference

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

  4. Update the $ .activity.remaining_quantity parameter by subtracting the quantity of artifacts that have a reference on service request that contains an $.based_on.[]activity