Class: Order

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Order

Returns a new instance of Order.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_astm/order.rb', line 37

def initialize(args)
	if args[:line]
		line = args[:line]
		if line.fields[2]
			line.fields[2].strip.scan(/(?<specimen_id>[^\^]+)/) { |specimen_id|
				self.id ||= specimen_id
			}
		elsif line.fields[3]
			## 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.tests = args[:tests]
		self.date_time = args[:date_time]
		self.priority = args[:priority]
		self.action_code = args[:action_code]
	end
	self.results = {}
end

Instance Attribute Details

#action_codeObject

action code index (11)



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

def action_code
  @action_code
end

#date_timeObject

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

#idObject

> 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

#priorityObject

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



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

def priority
  @priority
end

#resultsObject

> key : result name.

> value : result object



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

def results
  @results
end

#sequence_numberObject

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_typeObject

index (15)



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

def specimen_type
  @specimen_type
end

#testsObject

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_responseObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ruby_astm/order.rb', line 61

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