Module: Extensions::HL7::Message::InstanceMethods
- Defined in:
- lib/core_ext/message.rb
Instance Method Summary collapse
- #event ⇒ Object
- #hash ⇒ Object
- #obr_list ⇒ Object
- #orc_list ⇒ Object
- #patient ⇒ Object
- #patient_dob ⇒ Object
- #patient_full_name ⇒ Object
- #patient_gender ⇒ Object
- #patient_mrn ⇒ Object
- #patient_visit ⇒ Object
- #providers ⇒ Object
- #sending_application ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
Instance Method Details
#event ⇒ Object
33 34 35 |
# File 'lib/core_ext/message.rb', line 33 def event hash[:message][:content]["MSH"]["messageEvent"] end |
#hash ⇒ Object
80 81 82 |
# File 'lib/core_ext/message.rb', line 80 def hash to_hash end |
#obr_list ⇒ Object
60 61 62 63 |
# File 'lib/core_ext/message.rb', line 60 def obr_list a = hash["message"]["content"]["OBR"]["array"].collect {|obr| ::HL7::Message::Segment.from_hash("OBR", obr)} a.to_enum(:each) end |
#orc_list ⇒ Object
75 76 77 78 |
# File 'lib/core_ext/message.rb', line 75 def orc_list a = hash["message"]["content"]["ORC"]["array"].collect {|orc| ::HL7::Message::Segment.from_hash("ORC", orc)} a.to_enum(:each) end |
#patient ⇒ Object
65 66 67 68 |
# File 'lib/core_ext/message.rb', line 65 def patient patient = hash["message"]["content"]["PID"] ::HL7::Message::Segment.from_hash("PID", patient) 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
56 57 58 |
# File 'lib/core_ext/message.rb', line 56 def patient_gender hash["message"]["content"]["PID"]["sex"] end |
#patient_mrn ⇒ Object
50 51 52 53 54 |
# File 'lib/core_ext/message.rb', line 50 def patient_mrn pid = hash["message"]["content"]["PID"] @pid ||= ::HL7::Message::Segment.from_hash("PID", pid) @pid.mrn end |
#patient_visit ⇒ Object
70 71 72 73 |
# File 'lib/core_ext/message.rb', line 70 def patient_visit patient_visit = hash["message"]["content"]["PV1"] ::HL7::Message::Segment.from_hash("PV1", patient_visit) 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
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/core_ext/message.rb', line 84 def to_hash begin 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"] if last_segment == "ORC" @hash[:message][:content]["ORC"]["array"].last["OBR"] ||= {} @hash[:message][:content]["ORC"]["array"].last["OBR"]["array"] ||= [] @hash[:message][:content]["ORC"]["array"].last["OBR"]["array"] << segment.to_hash else last_segment = segment_name end 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 == "ORC" @hash[:message][:content]["ORC"] ||= {} @hash[:message][:content]["ORC"]["array"] ||= [] @hash[:message][:content]["ORC"]["array"] << segment.to_hash last_segment = segment_name elsif segment_name == "NTE" if last_segment == "OBR" @hash[:message][:content]["OBR"]["array"].last["OBX"] ||= {} @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"] ||= [] if @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"].length>0 @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"].last["notes"] ||= [] @hash[:message][:content]["OBR"]["array"].last["OBX"]["array"].last["notes"] << segment.to_hash end 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 rescue => e puts e. pp e.backtrace[0..10] end end |
#to_json ⇒ Object
139 140 141 142 |
# File 'lib/core_ext/message.rb', line 139 def to_json to_hash @hash.to_json end |