Class: Order

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_astm/order.rb

Direct Known Subclasses

Hl7Order

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Order

Returns a new instance of Order.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ruby_astm/order.rb', line 76

def initialize(args)
	set_id(args)
	set_priority(args)
	set_sequence_number(args)
	set_tests(args)
	set_specimen_type(args)
	set_date_time(args)
	set_priority(args)
	set_action_Code(args)
=begin		
	if args[:line]
		line = args[:line]
		if !line.fields[2].strip.blank?
			line.fields[2].strip.scan(/(?<specimen_id>[^\^]+)/) { |specimen_id|
				self.id ||= specimen_id
			}
		elsif !line.fields[3].strip.blank?
			## for the sysmex xn-550 this is the regex.
			line.fields[3].strip.scan(/(?<tube_rack>\d+\^)+(?<patient_id>.+)\^/) { |tube_rack,patient_id|  self.id = patient_id.strip}
		end
	else
		self.sequence_number = args[:sequence_number]
		self.tests = args[:tests]
		self.id = args[:specimen_id]
		self.specimen_type = args[:specimen_type]
		self.date_time = args[:date_time]
		self.priority = args[:priority]
		self.action_code = args[:action_code]
	end
=end
	self.results = {}
end

Instance Attribute Details

#action_code ⇒ Object

action code index (11)



35
36
37
# File 'lib/ruby_astm/order.rb', line 35

def action_code
  @action_code
end

#date_time ⇒ Object

the date and time of collection index (7)



31
32
33
# File 'lib/ruby_astm/order.rb', line 31

def date_time
  @date_time
end

#id ⇒ Object

=> patient id. => should match the specimen id that comes into the query. index (2)



5
6
7
# File 'lib/ruby_astm/order.rb', line 5

def id
  @id
end

#priority ⇒ Object

the order type, like stat, routine etc. index (5)



27
28
29
# File 'lib/ruby_astm/order.rb', line 27

def priority
  @priority
end

#results ⇒ Object

=> key : result name. => value : result object



13
14
15
# File 'lib/ruby_astm/order.rb', line 13

def results
  @results
end

#sequence_number ⇒ Object

this should be same as the one for patient. index (1)



9
10
11
# File 'lib/ruby_astm/order.rb', line 9

def sequence_number
  @sequence_number
end

#specimen_type ⇒ Object

index (15)



22
23
24
# File 'lib/ruby_astm/order.rb', line 22

def specimen_type
  @specimen_type
end

#tests ⇒ Object

the list of tests that need to be performed. each should be prefixed by three carets index (4)



18
19
20
# File 'lib/ruby_astm/order.rb', line 18

def tests
  @tests
end

Instance Method Details

#build_response ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ruby_astm/order.rb', line 109

def build_response
	
	raise "provide a sequence number" if self.sequence_number.blank?
	raise "provide a specimen id" if self.id.blank?
	#raise "provide a list of tests" if self.tests.blank?
	raise "provide a test priority" if self.priority.blank?
	
	if self.specimen_type.blank?
		#puts "no specimen type has been provided, sending SERUM"
	end

	"O|#{self.sequence_number}|#{self.id}^01||^^^#{self.tests.join('`^^^')}|#{self.priority}||#{Time.now.strftime("%Y%m%d%H%M%S")}||||N||||#{self.specimen_type || 'SERUM'}\r"
end

#set_action_Code(args) ⇒ Object



72
73
74
# File 'lib/ruby_astm/order.rb', line 72

def set_action_Code(args)
	self.action_code = args[:args]
end

#set_date_time(args) ⇒ Object



64
65
66
# File 'lib/ruby_astm/order.rb', line 64

def set_date_time(args)		
	self.date_time = args[:date_time]
end

#set_id(args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_astm/order.rb', line 37

def set_id(args)
	if line = args[:line]
		if !line.fields[2].strip.blank?
			line.fields[2].strip.scan(/(?<specimen_id>[^\^]+)/) { |specimen_id|
				self.id ||= specimen_id
			}
		elsif !line.fields[3].strip.blank?
			## for the sysmex xn-550 this is the regex.
			line.fields[3].strip.scan(/(?<tube_rack>\d+\^)+(?<patient_id>.+)\^/) { |tube_rack,patient_id|  self.id = patient_id.strip}
		end
	else
		self.id = args[:specimen_id]
	end
end

#set_priority(args) ⇒ Object



68
69
70
# File 'lib/ruby_astm/order.rb', line 68

def set_priority(args)
	self.priority = args[:priority]
end

#set_sequence_number(args) ⇒ Object



52
53
54
# File 'lib/ruby_astm/order.rb', line 52

def set_sequence_number(args)
	self.sequence_number = args[:sequence_number]
end

#set_specimen_type(args) ⇒ Object



60
61
62
# File 'lib/ruby_astm/order.rb', line 60

def set_specimen_type(args)
	self.specimen_type = args[:specimen_type]
end

#set_tests(args) ⇒ Object



56
57
58
# File 'lib/ruby_astm/order.rb', line 56

def set_tests(args)
	self.tests = args[:tests]
end