Sha256: ad599c6a02dae8ea2e1957567e180fce32bac62bb153bb2fdd1a0c6e04abe2db

Contents?: true

Size: 1.59 KB

Versions: 139

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/letters"
require "attr_extras"

module Renalware
  module Clinics
    # TODO: Move this to a view?
    class CurrentObservations
      NULL_DATE = nil
      pattr_initialize :patient

      Observation = Struct.new(:date, :measurement)

      # Returns [date, weight]
      def weight
        @weight ||= begin
          result = ClinicVisit
                    .most_recent_for_patient(patient)
                    .where("weight is not null")
                    .pluck(:date, :weight).first || []

          Observation.new(result.first, result.last)
        end
      end

      # Returns [date, height]
      def height
        @height ||= begin
          result = ClinicVisit
                    .most_recent_for_patient(patient)
                    .where("height is not null")
                    .pluck(:date, :height).first || []

          Observation.new(result.first, result.last)
        end
      end

      # Returns [date, [systolic_bp, diastolic_bp]]
      def blood_pressure
        @blood_pressure ||= begin
          result = ClinicVisit
                    .most_recent_for_patient(patient)
                    .where("systolic_bp is not null and diastolic_bp is not null")
                    .pluck(:date, :systolic_bp, :diastolic_bp).first || [nil, nil, nil]

          Observation.new(result[0], [result[1], result[2]])
        end
      end

      def bmi
        bmi = BMI.new(
          height: height.measurement,
          weight: weight.measurement
        )
        Observation.new(NULL_DATE, bmi.to_f)
      end
    end
  end
end

Version data entries

139 entries across 139 versions & 1 rubygems

Version Path
renalware-core-2.0.159 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.158 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.157 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.156 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.155 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.153 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.152 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.151 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.149 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.148 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.147 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.146 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.145 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.144 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.143 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.142 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.141 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.140 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.139 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.138 app/models/renalware/clinics/current_observations.rb