Module: Extensions::HL7::Message::InstanceMethods

Defined in:
lib/core_ext/message.rb

Instance Method Summary collapse

Instance Method Details

#event ⇒ Object



33
34
35
# File 'lib/core_ext/message.rb', line 33

def event
  hash[:message][:content]["EVN"]
end

#hash ⇒ Object



59
60
61
# File 'lib/core_ext/message.rb', line 59

def hash 
  to_hash
end

#obr_list ⇒ Object



54
55
56
57
# File 'lib/core_ext/message.rb', line 54

def obr_list
  a = hash["message"]["content"]["OBR"]["array"].collect {|obr| ::HL7::Message::Segment.from_hash("OBR", obr)}
  a.to_enum(:each)
end

#patient_dob ⇒ Object



46
47
48
# File 'lib/core_ext/message.rb', line 46

def patient_dob
  Date.parse(hash["message"]["content"]["PID"]["dateTimeBirth"]).strftime("%B %d, %Y")
end

#patient_full_name ⇒ Object



41
42
43
44
# File 'lib/core_ext/message.rb', line 41

def patient_full_name
  name = hash["message"]["content"]["PID"]["patientName"]
  "#{name["lastName"]}, #{name["firstName"]}#{name["middleInitOrName"].blank? ? "" : " #{name["middleInitOrName"]}"}"
end

#patient_gender ⇒ Object



50
51
52
# File 'lib/core_ext/message.rb', line 50

def patient_gender
  hash["message"]["content"]["PID"]["sex"]
end

#providers ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/core_ext/message.rb', line 12

def providers
  providers = []

  if self[:OBR]
    obrs = self[:OBR].is_a?(Array) ? self[:OBR] : [self[:OBR]]
    obrs.each do |obr|
      providers << {hash: obr.ordering_provider_hash, segment: obr}
    end
  end

  if self[:PV1]
    pv1 = self[:PV1]
    providers << {hash: pv1.admitting_provider_hash, segment: self[:PV1]}
    providers << {hash: pv1.attending_provider_hash, segment: self[:PV1]}
    providers << {hash: pv1.consulting_provider_hash, segment: self[:PV1]}
    providers << {hash: pv1.referring_provider_hash, segment: self[:PV1]}
  end

  providers
end

#sending_application ⇒ Object



37
38
39
# File 'lib/core_ext/message.rb', line 37

def sending_application
  hash[:message][:content]["MSH"]["sendingApplication"] rescue nil
end

#to_hash ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/core_ext/message.rb', line 63

def to_hash
  return @hash unless @hash.blank?
  @hash ||= HashWithIndifferentAccess.new
  @hash[:message] = {content: {}}

  last_segment = nil
  self.each do |segment|
    segment_name = segment.segment_name
    if segment_name == "OBR"
      @hash[:message][:content][segment_name.to_sym] ||= {}
      @hash[:message][:content][segment_name.to_sym]["array"] ||= []
      @hash[:message][:content][segment_name.to_sym]["array"] << segment.to_hash

      @hash[:message][:content][segment_name.to_sym]["array"]

      last_segment = segment_name
    elsif segment_name == "OBX"
      if last_segment == "OBR"
        @hash[:message][:content]["OBR"]["array"].last[segment_name] ||= {}
        @hash[:message][:content]["OBR"]["array"].last[segment_name]["array"] ||= []
        @hash[:message][:content]["OBR"]["array"].last[segment_name]["array"] << segment.to_hash
      end
    elsif segment_name == "NTE"
      if last_segment == "OBR"
        @hash[:message][:content]["OBR"]["array"].last["OBX"] ||= {}
        @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"] ||= []
        @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"].last["notes"] ||= [] if @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"].length>0
        @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"].last["notes"] << segment.to_hash
      end
    else
      @hash[:message][:content][segment_name.to_sym] = segment.to_hash
    end
    @hash[:message][:content]["EVN"] = @hash[:message][:content]["MSH"]["messageEvent"] if segment_name == "MSH"
  end

  @hash
end

#to_json ⇒ Object



101
102
103
104
# File 'lib/core_ext/message.rb', line 101

def to_json
  to_hash
  @hash.to_json
end