Class: Medivo::Order

Inherits:
LabResource
  • Object
show all
Extended by:
ActiveModel::Callbacks
Defined in:
app/models/medivo/order.rb

Direct Known Subclasses

InsuranceOrder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ Order

Returns a new instance of Order.



19
20
21
22
23
# File 'app/models/medivo/order.rb', line 19

def initialize(attributes = {}, persisted = false)
  super(attributes, persisted)
  self.draw_location = "PSC"
  self.take_tests_same_day = true
end

Class Method Details

.find_with_requisition(requsition_id) ⇒ Object

loads the requisition with order



59
60
61
# File 'app/models/medivo/order.rb', line 59

def self.find_with_requisition(requsition_id)
  find(requsition_id, :params=>{:include=>:requisition})
end

.find_with_results(requsition_id) ⇒ Object

find order and the results as well



75
76
77
# File 'app/models/medivo/order.rb', line 75

def self.find_with_results(requsition_id)
  find(requsition_id, :params=>{:include=>:reconciled_results})
end

.get_order(requsition_id) ⇒ Object



54
55
56
# File 'app/models/medivo/order.rb', line 54

def self.get_order(requsition_id)
  find(requsition_id)
end

.pdf_requisition(requsition_id) ⇒ Object

get a lab requisition pdf from requisition id



69
70
71
# File 'app/models/medivo/order.rb', line 69

def self.pdf_requisition(requsition_id)
  find_with_requisition(requsition_id).pdf_requisition
end

.pdf_result(requsition_id) ⇒ Object

gets the order, and returns the pdf



115
116
117
# File 'app/models/medivo/order.rb', line 115

def self.pdf_result(requsition_id)
  find_with_results(requsition_id).pdf_result
end

Instance Method Details

#createObject

overriding create to capture 404 status and put that in error messages instead of throwing exception



37
38
39
40
41
42
43
44
# File 'app/models/medivo/order.rb', line 37

def create
  run_callbacks(:create)
  super
  @remote_errors = nil
rescue ActiveResource::ConnectionError => e
  @remote_errors = e
  load_remote_errors(e, true)
end

#pdf_requisitionObject

gets the lab requisition pdf



64
65
66
# File 'app/models/medivo/order.rb', line 64

def pdf_requisition
  Base64::decode64(try(:sameday_requisition))
end

#pdf_resultObject

NOTE: must use #find_with_results to get the order before you call this method



109
110
111
# File 'app/models/medivo/order.rb', line 109

def pdf_result
  Base64::decode64(try(:reconciled_results).try(:results_pdf))
end

#read_attribute_for_validation(key) ⇒ Object



25
26
27
# File 'app/models/medivo/order.rb', line 25

def read_attribute_for_validation(key)
  @attributes[key]
end

#requisition_idObject



50
51
52
# File 'app/models/medivo/order.rb', line 50

def requisition_id
  requisition_number
end

#result_dateObject

NOTE: must use #find_with_results to get the order before you call this method



103
104
105
# File 'app/models/medivo/order.rb', line 103

def result_date
  results_summary.try(:collection_date)
end

#result_for_test(result_lab_code) ⇒ Object

get the result for a particular test result code

NOTE: must use #find_with_results to get the order before you call this method

Parameters:

  • result_lab_code


91
92
93
# File 'app/models/medivo/order.rb', line 91

def result_for_test(result_lab_code)
  results.find{|r| r.result_lab_code == result_lab_code}
end

#resultsObject

NOTE: must use #find_with_results to get the order before you call this method



81
82
83
# File 'app/models/medivo/order.rb', line 81

def results
  Array.wrap(try(:reconciled_results).try(:result))
end

#results_summaryObject

NOTE: must use #find_with_results to get the order before you call this method



97
98
99
# File 'app/models/medivo/order.rb', line 97

def results_summary
  try(:reconciled_results).try(:results_summary)
end

#saveObject

overriding save to return false if it does not save without errors



30
31
32
33
# File 'app/models/medivo/order.rb', line 30

def save
  new? ? create : update
  valid?
end

#simulate_result(lab_prefix, test_name, type = 'normal') ⇒ Object

Parameters:

  • lab_prefix (qd, lc)
  • test_name

    name of test like ‘hga1c’ or ‘hepc’

  • type (normal, false_positive, positive, abnormal) (defaults to: 'normal')


124
125
126
127
128
129
130
131
132
133
# File 'app/models/medivo/order.rb', line 124

def simulate_result(lab_prefix, test_name, type='normal')
  unless %w(normal false_positive positive abnormal).include?(type) and
          %w(qd lc).include?(lab_prefix)
    raise "Incorrect Result Type"
  end
  hl7_file = Rails.root.join("lib/hl7/#{lab_prefix}_#{test_name}_#{type}.hl7").to_s
  hl7 = Base64.encode64(File.read(hl7_file))
  body = "<mock><simulate>result</simulate><result><hl7>#{hl7}</hl7></result></mock>"
  post(:mock_order, {}, body)
end

#to_paramObject



46
47
48
# File 'app/models/medivo/order.rb', line 46

def to_param
  requisition_id
end