Class: Medivo::Order
- Inherits:
-
LabResource
- Object
- ActiveResource::Base
- LabResource
- Medivo::Order
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- app/models/medivo/order.rb
Direct Known Subclasses
Class Method Summary collapse
-
.find_with_requisition(requsition_id) ⇒ Object
loads the requisition with order.
-
.find_with_results(requsition_id) ⇒ Object
find order and the results as well.
- .get_order(requsition_id) ⇒ Object
-
.pdf_requisition(requsition_id) ⇒ Object
get a lab requisition pdf from requisition id.
-
.pdf_result(requsition_id) ⇒ Object
gets the order, and returns the pdf.
Instance Method Summary collapse
-
#create ⇒ Object
overriding create to capture 404 status and put that in error messages instead of throwing exception.
-
#initialize(attributes = {}, persisted = false) ⇒ Order
constructor
A new instance of Order.
-
#pdf_requisition ⇒ Object
gets the lab requisition pdf.
-
#pdf_result ⇒ Object
NOTE: must use #find_with_results to get the order before you call this method.
- #read_attribute_for_validation(key) ⇒ Object
- #requisition_id ⇒ Object
-
#result_date ⇒ Object
NOTE: must use #find_with_results to get the order before you call this method.
-
#result_for_test(result_lab_code) ⇒ Object
get the result for a particular test result code.
-
#results ⇒ Object
NOTE: must use #find_with_results to get the order before you call this method.
-
#results_summary ⇒ Object
NOTE: must use #find_with_results to get the order before you call this method.
-
#save ⇒ Object
overriding save to return false if it does not save without errors.
- #simulate_result(lab_prefix, test_name, type = 'normal') ⇒ Object
- #to_param ⇒ Object
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
#create ⇒ Object
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_requisition ⇒ Object
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_result ⇒ Object
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_id ⇒ Object
50 51 52 |
# File 'app/models/medivo/order.rb', line 50 def requisition_id requisition_number end |
#result_date ⇒ Object
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
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 |
#results ⇒ Object
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_summary ⇒ Object
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 |
#save ⇒ Object
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
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_param ⇒ Object
46 47 48 |
# File 'app/models/medivo/order.rb', line 46 def to_param requisition_id end |