Sha256: dbcaab049b5b5ef6f73a9cd4783f6ae2dd01419bfc3a201814028915de004de9

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require_dependency "renalware/letters"
require "attr_extras"

module Renalware
  module Clinics
    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

2 entries across 2 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc10 app/models/renalware/clinics/current_observations.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/clinics/current_observations.rb