Class: Query
- Inherits:
-
Object
- Object
- Query
- Defined in:
- lib/ruby_astm/query.rb
Instance Attribute Summary collapse
-
#carrier_number ⇒ Object
Returns the value of attribute carrier_number.
-
#container_type ⇒ Object
Returns the value of attribute container_type.
-
#position_number ⇒ Object
Returns the value of attribute position_number.
-
#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.
-
#sample_type ⇒ Object
Returns the value of attribute sample_type.
-
#sequence_number ⇒ Object
FIELDS SPECIFIC TO ROCHE E411.
Instance Method Summary collapse
-
#build_response(options = {}) ⇒ 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.
-
#parse_field_for_sample_id(fields, index) ⇒ Object
ROCHE SPECIFIC FIELDS END.
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_number ⇒ Object
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_type ⇒ Object
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_number ⇒ Object
Returns the value of attribute position_number.
22 23 24 |
# File 'lib/ruby_astm/query.rb', line 22 def position_number @position_number end |
#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 |
#sample_type ⇒ Object
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_number ⇒ Object
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(={}) 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() + order.build_response(.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 |