Class: Query

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Query

Returns a new instance of Query.



7
8
9
10
11
12
13
# File 'lib/ruby_astm/query.rb', line 7

def initialize(args)
	line = args[:line]
	unless line.fields[2].empty?
		fields = line.fields[2].split(/\^/)
		self.sample_id = fields[1].strip
	end
end

Instance Attribute Details

#response ⇒ Object

Returns the value of attribute response.



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

def response
  @response
end

#sample_id ⇒ Object

Returns the value of attribute sample_id.



3
4
5
# File 'lib/ruby_astm/query.rb', line 3

def sample_id
  @sample_id
end

Instance Method Details

#build_response(variables = nil) ⇒ Object

each query will build one patient and one order inside it. the order can have many tests.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_astm/query.rb', line 26

def build_response(variables=nil)
	## so the response is thus incoming.
=begin		
	variables ||= {
		:sequence_number => "0",
		:patient_id => "abcde",
		:specimen_id => self.sample_id,
		:tests => ["TRIG"],
		:priority => "R"
	}	
=end

	## tests are got from the requisitions hash.
	tests = get_tests

	## default sequence number is 0 (THIS MAY LEAD TO PROBLEMS.)
	sequence_number = "0"

	## default patient id:
	patient_id = "abcde#{Time.now.strftime('%b %d, %Y, %H:%M:%S')}"

	patient = Patient.new({:sequence_number => sequence_number, :patient_id => patient_id})
	
	order = Order.new({:sequence_number => patient.sequence_number, :specimen_id => self.sample_id, :tests => tests, :priority => "R"})

	return patient.build_response + order.build_response
	
end

#get_tests ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/ruby_astm/query.rb', line 15

def get_tests
	tests = []
	sample_tests = $redis.hget(Poller::REQUISITIONS_HASH,self.sample_id)
	unless sample_tests.blank?
		tests = JSON.parse(sample_tests)
	end
	tests
end