Class: Header

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

Direct Known Subclasses

Hl7Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Header

Returns a new instance of Header.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_astm/header.rb', line 21

def initialize(args)
  self.patients = []
  self.queries = []
  self.response_sent = false
  if line = args[:line]
    set_machine_name(args)
    set_protocol(args)
  else
    super
  end
end

Instance Attribute Details

#machine_name ⇒ Object

Returns the value of attribute machine_name.



2
3
4
# File 'lib/ruby_astm/header.rb', line 2

def machine_name
  @machine_name
end

#patients ⇒ Object

Returns the value of attribute patients.



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

def patients
  @patients
end

#protocol ⇒ Object

Returns the value of attribute protocol.



6
7
8
# File 'lib/ruby_astm/header.rb', line 6

def protocol
  @protocol
end

#queries ⇒ Object

Returns the value of attribute queries.



4
5
6
# File 'lib/ruby_astm/header.rb', line 4

def queries
  @queries
end

#response_sent ⇒ Object

Returns the value of attribute response_sent.



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

def response_sent
  @response_sent
end

Instance Method Details

#build_responses ⇒ Object

used to respond to queries. @return response_to_query : response to the header query.



50
51
52
53
54
55
56
57
# File 'lib/ruby_astm/header.rb', line 50

def build_responses
  responses = self.queries.map {|query|
    header_response = "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
    query.response = header_response + query.build_response
    query.response
  }
  responses
end

#commit ⇒ Object

pushes each patient into a redis list called "patients"



43
44
45
46
# File 'lib/ruby_astm/header.rb', line 43

def commit
  self.patients.map{|patient| $redis.lpush("patients",patient.to_json)}
  puts JSON.pretty_generate(JSON.parse(self.to_json))
end

#is_astm? ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/ruby_astm/header.rb', line 8

def is_astm?
  self.protocol == "ASTM"
end

#is_hl7? ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ruby_astm/header.rb', line 12

def is_hl7?
  self.protocol == "HL7"
end

#set_machine_name(args) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/ruby_astm/header.rb', line 33

def set_machine_name(args)
  if line = args[:line]
    unless line.fields[4].empty?
      fields = line.fields[4].split(/\^/)
      self.machine_name = fields[0].strip
    end
  end
end

#set_protocol(args) ⇒ Object



17
18
19
# File 'lib/ruby_astm/header.rb', line 17

def set_protocol(args)
  self.protocol = "ASTM"
end

#to_json ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ruby_astm/header.rb', line 59

def to_json
    hash = {}
    self.instance_variables.each do |x|
        hash[x] = self.instance_variable_get x
    end
    return hash.to_json
end