Class: Renalware::Feeds::HL7Message

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/models/renalware/feeds/hl7_message.rb

Overview

Responsible for representing an HL7 message. Fields can be queried via chained method calls. For example, accessing the patient identifier field in the PID segment can be accessed by calling:

HL7Message.new(raw_message).patient_identification.internal_id

Defined Under Namespace

Classes: Observation, ObservationRequest, PatientIdentification

Constant Summary collapse

ACTIONS =
{
  "ADT^A28" => :add_person_information,
  "ADT^A31" => :update_person_information,
  "ADT^A08" => :update_admission,
  "ADT^A01" => :admit_patient,
  "ADT^A02" => :transfer_patient,
  "ADT^A03" => :discharge_patient,
  "ADT^A11" => :cancel_admission,
  "MFN^M02" => :add_consultant, # no
  "ADT^A34" => :merge_patient, # no
  "ADT^A13" => :cancel_discharge,
  "ORU^R01" => :add_pathology_observations
}.freeze

Instance Method Summary collapse

Instance Method Details

#actionObject



228
229
230
# File 'app/models/renalware/feeds/hl7_message.rb', line 228

def action
  ACTIONS.fetch(type, :no_matching_command)
end

#event_typeObject



217
218
219
220
# File 'app/models/renalware/feeds/hl7_message.rb', line 217

def event_type
  parts = type.split("^")
  parts.length == 2 && parts.last
end

#gp_codeObject



236
237
238
# File 'app/models/renalware/feeds/hl7_message.rb', line 236

def gp_code
  self[:PD1].e4.split("^")[0] if self[:PD1]
end

#header_idObject



204
205
206
# File 'app/models/renalware/feeds/hl7_message.rb', line 204

def header_id
  self[:MSH].message_control_id
end

#message_typeObject



213
214
215
# File 'app/models/renalware/feeds/hl7_message.rb', line 213

def message_type
  type.split("^").first
end

#observation_requestsObject

There is a problem here is there are < 1 OBR i.e. self could be an array



122
123
124
# File 'app/models/renalware/feeds/hl7_message.rb', line 122

def observation_requests
  Array(self[:OBR]).map { |obr| ObservationRequest.new(obr) }
end

#patient_identificationObject



196
197
198
# File 'app/models/renalware/feeds/hl7_message.rb', line 196

def patient_identification
  PatientIdentification.new(self[:PID])
end

#practice_codeObject



232
233
234
# File 'app/models/renalware/feeds/hl7_message.rb', line 232

def practice_code
  self[:PD1].e3.split("^")[2] if self[:PD1]
end

#to_hl7Object

Adding this so it is part of the interface and we can mock an HL7Message in tests



209
210
211
# File 'app/models/renalware/feeds/hl7_message.rb', line 209

def to_hl7
  super
end

#typeObject



200
201
202
# File 'app/models/renalware/feeds/hl7_message.rb', line 200

def type
  self[:MSH].message_type
end