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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ruby_astm/query.rb', line 45

def initialize(args)
	line = args[:line]
	unless line.fields[2].empty?
		## do the gsub for roche type.
		## if not successfuul, then parse for one.
		puts "line fields is:"
		puts line.fields[2].to_s
		line.fields[2].scan(/\^{2}(?<sample_id>[A-Za-z0-9]+)\^(?<sequence_number>[0-9]+)\^(?<carrier_number>[a-zA-Z0-9]+)\^(?<position_number>[0-9]+)\^{2}(?<sample_type>[a-zA-Z0-9]+)\^(?<container_type>[a-zA-Z0-9]+)/) { |sample_id,sequence_number,carrier_number,position_number,sample_type,container_type|  

			self.sequence_number = sequence_number
			self.sample_ids = [sample_id]
			self.carrier_number = carrier_number
			self.position_number = position_number
			self.sample_type = sample_type
			self.container_type = container_type
		}

		puts "sequence_number: #{self.sequence_number}, sample id: #{self.sample_id}, carrier number: #{self.carrier_number}, position_number: #{self.position_number}, sample_type: #{self.sample_type}, container_type: #{self.container_type}" 

		fields = line.fields[2].split(/\^/)
		
		parse_field_for_sample_id(fields,1) if self.container_type.blank?
			

	end
end

Instance Attribute Details

#carrier_numberObject

Returns the value of attribute carrier_number.



20
21
22
# File 'lib/ruby_astm/query.rb', line 20

def carrier_number
  @carrier_number
end

#container_typeObject

Returns the value of attribute container_type.



26
27
28
# File 'lib/ruby_astm/query.rb', line 26

def container_type
  @container_type
end

#position_numberObject

Returns the value of attribute position_number.



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

def position_number
  @position_number
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#sample_idObject

Returns the value of attribute sample_id.



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

def sample_id
  @sample_id
end

#sample_idsObject

Returns the value of attribute sample_ids.



7
8
9
# File 'lib/ruby_astm/query.rb', line 7

def sample_ids
  @sample_ids
end

#sample_typeObject

Returns the value of attribute sample_type.



24
25
26
# File 'lib/ruby_astm/query.rb', line 24

def sample_type
  @sample_type
end

#sequence_numberObject

FIELDS SPECIFIC TO ROCHE E411



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

def sequence_number
  @sequence_number
end

Instance Method Details

#build_response(options = {}) ⇒ Object

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



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
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ruby_astm/query.rb', line 83

def build_response(options={})
	
	responses = []

	one_response = ''

	puts "sample ids are:"
	puts self.sample_ids

	return responses unless sample_ids

	self.sample_ids.each_with_index {|sid,key|
		puts "doing sample id: #{sid}"
		## tests are got from the requisitions hash.
		tests = get_tests(sid)
		puts "tests are: #{tests}"
		## default sequence number is 0 (THIS MAY LEAD TO PROBLEMS.)
		sequence_number = "#{key.to_s}"

		## default patient id:
		patient_id = "abcde#{Time.now.to_i.to_s}"
		
		patient = Patient.new({:sequence_number => sequence_number, :patient_id => patient_id})
		
		order = Order.new({:sequence_number => patient.sequence_number, :specimen_id => sid, :tests => tests, :priority => "R"})

		responses << (patient.build_response(options) + order.build_response(options.merge({sequence_number: self.sequence_number, carrier_number: self.carrier_number, position_number: self.position_number, sample_type: self.sample_type, container_type: self.container_type})))

	}

	puts "responses are:"
	puts responses.to_s

	return responses
	
end

#get_tests(sample_id) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/ruby_astm/query.rb', line 72

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

#parse_field_for_sample_id(fields, index) ⇒ Object

ROCHE SPECIFIC FIELDS END.



36
37
38
39
40
41
42
43
# File 'lib/ruby_astm/query.rb', line 36

def parse_field_for_sample_id(fields,index)
	return false if fields[index].blank?
	return false if fields[index].strip.blank?
	
	self.sample_ids = fields[index].strip.split(/\'/)

	return true
end