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



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

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

#event_typeObject



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

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

#gp_codeObject



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

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

#header_idObject



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

def header_id
  self[:MSH].message_control_id
end

#message_typeObject



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

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



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

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

#patient_identificationObject



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

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

#practice_codeObject



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

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



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

def to_hl7
  super
end

#typeObject



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

def type
  self[:MSH].message_type
end