Class: Lab::ProcessLabResultJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/lab/process_lab_result_job.rb

Overview

Push an order to LIMS.

Instance Method Summary collapse

Instance Method Details

#perform(results_obs_id, serializer, result_enter_by) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/lab/process_lab_result_job.rb', line 8

def perform(results_obs_id, serializer, result_enter_by)
  Rails.logger.info("Lab::ProcessLabResultJob: Processing result completion for #{serializer}")
  # set location context for the job based on the order's encounter to ensure proper context for any operations performed in the job
  results_obs = Lab::LabResult.unscoped.includes(:test).find(results_obs_id)
  encounter = Encounter.unscoped.find_by(encounter_id: results_obs.encounter_id)
  Location.current = Location.find(encounter.location_id) if encounter&.location_id
  Lab::ResultsService.process_result_completion(results_obs, serializer, result_enter_by)

  # Publish notification that results have been processed
  ActiveSupport::Notifications.instrument(
    'lab.results_saved',
    patient_id: results_obs.person_id,
    order_id: results_obs.order_id,
    result_id: results_obs.obs_id,
    encounter_id: results_obs.encounter_id,
    timestamp: Time.current
  )
end