Class: Lab::VoidOrderJob

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

Instance Method Summary collapse

Instance Method Details

#perform(order_id) ⇒ Object



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

def perform(order_id)
  Rails.logger.info("Voiding order ##{order_id} in LIMS")

  User.current = Lab::Lims::Utils.lab_user
  # Set location from order's encounter to ensure proper context
  order = Lab::LabOrder.unscoped.find(order_id)
  encounter = Encounter.unscoped.find_by(encounter_id: order.encounter_id)
  Location.current = Location.find(encounter.location_id) if encounter&.location_id
  Location.current ||= Location.find_by_name('ART clinic')

  worker = Lab::Lims::PushWorker.new(Lab::Lims::ApiFactory.create_api)
  worker.push_order(order)

  # Publish notification that order has been voided
  ActiveSupport::Notifications.instrument(
    'lab.order_voided',
    patient_id: order.patient_id,
    order_id: order.order_id,
    timestamp: Time.current
  )
end