Class: Query
- Inherits:
-
Object
- Object
- Query
- Defined in:
- lib/ruby_astm/query.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
-
#sample_id ⇒ Object
Returns the value of attribute sample_id.
-
#sample_ids ⇒ Object
Returns the value of attribute sample_ids.
Instance Method Summary collapse
-
#build_response(variables = nil) ⇒ Object
each query will build one patient and one order inside it.
- #get_tests(sample_id) ⇒ Object
-
#initialize(args) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(args) ⇒ Query
Returns a new instance of Query.
9 10 11 12 13 14 15 16 |
# File 'lib/ruby_astm/query.rb', line 9 def initialize(args) line = args[:line] unless line.fields[2].empty? fields = line.fields[2].split(/\^/) sample_id = fields[1].strip self.sample_ids = sample_id.split(/\`/) 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 |
#sample_ids ⇒ Object
Returns the value of attribute sample_ids.
7 8 9 |
# File 'lib/ruby_astm/query.rb', line 7 def sample_ids @sample_ids 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.
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 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_astm/query.rb', line 29 def build_response(variables=nil) responses = [] one_response = '' puts "sample ids are:" puts self.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 + order.build_response) } puts "responses are:" puts responses.to_s return responses end |
#get_tests(sample_id) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ruby_astm/query.rb', line 18 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 |