Sha256: 8af4707126c50e4b88a3c4c942a85f0124a13b9ce7e2973297b0ecf29cf9c1ef

Contents?: true

Size: 1.24 KB

Versions: 35

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "renalware/letters/part"

module Renalware
  module Letters
    class Part::ClinicalObservations < Part
      include Renalware::AttributeNameHelper
      OBSERVATION_ATTRS = %i(bp weight height bmi urine_blood urine_protein).freeze
      OBSERVATION_UNITS = { weight: :kg, height: :m }.freeze
      delegate(*OBSERVATION_ATTRS, to: :event)
      delegate :any?, to: :observations

      def each_observation
        observations.each do |arr|
          label, result, unit_of_measurement = arr
          yield(label, result, unit_of_measurement)
        end
      end

      def to_partial_path
        "renalware/letters/parts/clinical_observations"
      end

      private

      def observations
        OBSERVATION_ATTRS.each_with_object([]) do |observation, arr|
          value = send(observation)
          next if value.blank?
          arr << [
            label_for(observation),
            enum_text_or_raw_value_for(value),
            OBSERVATION_UNITS[observation]
          ]
        end
      end

      def label_for(observation)
        attr_name(Renalware::Clinics::ClinicVisit, observation)
      end

      def enum_text_or_raw_value_for(value)
        value.try(:text) || value
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.45 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.44 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.43 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.42 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.41 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.40 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.39 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.38 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.37 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.36 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.35 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.34 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.33 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.32 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.31 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.30 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.28 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.27 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.26 app/models/renalware/letters/part/clinical_observations.rb