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.74 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.73 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.72 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.71 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.70 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.69 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.68 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.67 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.64 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.63 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.62 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.61 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.60 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.58 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.57 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.56 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.55 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.54 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.53 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.52 app/models/renalware/clinics/current_observations.rb