Class: Renalware::Pathology::ObservationRequestsAttributesBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/pathology/observation_requests_attributes_builder.rb

Overview

Responsible for transforming an HL7 message payload into a params hash that can be persisted by ObservationRequest. Note:

  • A message can have multiple observation_requests, each with its own observations.

  • This class could be removed and a Builder class used to create the database models directly - this would remove the extra level of indirection that this class introduces.

Constant Summary collapse

DEFAULT_REQUESTOR_NAME =
"UNKNOWN"

Instance Method Summary collapse

Constructor Details

#initialize(hl7_message, logger = Delayed::Worker.logger) ⇒ ObservationRequestsAttributesBuilder

hl7_message is an HL7Message (a decorator around an ::HL7::Message)



20
21
22
23
# File 'app/models/renalware/pathology/observation_requests_attributes_builder.rb', line 20

def initialize(hl7_message, logger = Delayed::Worker.logger)
  @hl7_message = hl7_message
  @logger = logger
end

Instance Method Details

#parseObject

Return an array of observation request attributes (with a nested array of child observation attributes) for each OBR in the HL7 message. The resulting array will be used to create the corresponding database records.



28
29
30
31
32
33
34
35
# File 'app/models/renalware/pathology/observation_requests_attributes_builder.rb', line 28

def parse
  if renalware_patient?
    build_patient_params
  else
    logger.debug("Did not process pathology for #{internal_id}: not a renalware patient")
    nil
  end
end

#renalware_patient?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/renalware/pathology/observation_requests_attributes_builder.rb', line 37

def renalware_patient?
  Patient.exists?(local_patient_id: internal_id)
end