Class: Renalware::Pathology::ObservationRequestsAttributesBuilder
- Inherits:
-
Object
- Object
- Renalware::Pathology::ObservationRequestsAttributesBuilder
- 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.
-
We create any missing *_description or measurement_unit rows - ie if a new OBR ‘ABC’ arrives
-
from the lab and we have not seen it before, we create a corresponding
-
observation_request_description first. Likewise for previously unseen OBX codes we will
-
create a new observation_description in realtime. If a OBC has a unit we have not seen before eg MW (Megawatts!) we create that also. In this way the pathology ‘metadata’ is keep up to date based on what the lab/send.
Note 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
-
#initialize(hl7_message, logger = Delayed::Worker.logger) ⇒ ObservationRequestsAttributesBuilder
constructor
hl7_message is an HL7Message (a decorator around an ::HL7::Message).
-
#parse ⇒ Object
Return an array of observation request attributes (with a nested array of child observation attributes) for each OBR in the HL7 message.
- #renalware_patient? ⇒ Boolean
Constructor Details
#initialize(hl7_message, logger = Delayed::Worker.logger) ⇒ ObservationRequestsAttributesBuilder
hl7_message is an HL7Message (a decorator around an ::HL7::Message)
27 28 29 30 |
# File 'app/models/renalware/pathology/observation_requests_attributes_builder.rb', line 27 def initialize(, logger = Delayed::Worker.logger) = @logger = logger end |
Instance Method Details
#parse ⇒ Object
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.
35 36 37 38 39 40 41 42 |
# File 'app/models/renalware/pathology/observation_requests_attributes_builder.rb', line 35 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
44 45 46 |
# File 'app/models/renalware/pathology/observation_requests_attributes_builder.rb', line 44 def renalware_patient? Patient.exists?(local_patient_id: internal_id) end |