Module: Extensions::HL7::Message::InstanceMethods
- Defined in:
- lib/core_ext/message.rb
Instance Method Summary collapse
- #event ⇒ Object
- #hash ⇒ Object
- #message_type ⇒ 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
39 40 41 42 43 |
# File 'lib/core_ext/message.rb', line 39 def event msh = hash["message"]["content"]["MSH"] @msh ||= ::HL7::Message::Segment.from_hash("MSH", msh) @msh.to_hash["messageType"]["triggerEvent"] end |
#hash ⇒ Object
88 89 90 |
# File 'lib/core_ext/message.rb', line 88 def hash to_hash end |
#message_type ⇒ Object
33 34 35 36 37 |
# File 'lib/core_ext/message.rb', line 33 def msh = hash["message"]["content"]["MSH"] @msh ||= ::HL7::Message::Segment.from_hash("MSH", msh) @msh.to_hash["messageType"]["messageCode"] end |
#obr_list ⇒ Object
68 69 70 71 |
# File 'lib/core_ext/message.rb', line 68 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
83 84 85 86 |
# File 'lib/core_ext/message.rb', line 83 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
73 74 75 76 |
# File 'lib/core_ext/message.rb', line 73 def patient patient = hash["message"]["content"]["PID"] ::HL7::Message::Segment.from_hash("PID", patient) end |
#patient_dob ⇒ Object
54 55 56 |
# File 'lib/core_ext/message.rb', line 54 def patient_dob Date.parse(hash["message"]["content"]["PID"]["dateTimeBirth"]).strftime("%B %d, %Y") end |
#patient_full_name ⇒ Object
49 50 51 52 |
# File 'lib/core_ext/message.rb', line 49 def patient_full_name name = hash["message"]["content"]["PID"]["patientName"] "#{name["lastName"]}, #{name["firstName"]}#{name["middleInitOrName"].blank? ? "" : " #{name["middleInitOrName"]}"}" end |
#patient_gender ⇒ Object
64 65 66 |
# File 'lib/core_ext/message.rb', line 64 def patient_gender hash["message"]["content"]["PID"]["sex"] end |
#patient_mrn ⇒ Object
58 59 60 61 62 |
# File 'lib/core_ext/message.rb', line 58 def patient_mrn pid = hash["message"]["content"]["PID"] @pid ||= ::HL7::Message::Segment.from_hash("PID", pid) @pid.mrn end |
#patient_visit ⇒ Object
78 79 80 81 |
# File 'lib/core_ext/message.rb', line 78 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
45 46 47 |
# File 'lib/core_ext/message.rb', line 45 def sending_application hash[:message][:content]["MSH"]["sendingApplication"] rescue nil end |
#to_hash ⇒ Object
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 138 139 140 141 142 143 144 145 |
# File 'lib/core_ext/message.rb', line 92 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
147 148 149 150 |
# File 'lib/core_ext/message.rb', line 147 def to_json to_hash @hash.to_json end |