Sha256: 1c2b70e164c6df19cc712e604404d30f9209a68391e343aaa099dc17db207894

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

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

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.7 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.5 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.4 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.3 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.2 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.1 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/letters/part/clinical_observations.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/letters/part/clinical_observations.rb