Sha256: 209e31dadd745ebef39df36b935e252cb9405263e9b7080352cce485f16d6a3c

Contents?: true

Size: 1.36 KB

Versions: 84

Compression:

Stored size: 1.36 KB

Contents

require_dependency "renalware/letters"

module Renalware
  module Clinics
    module MostRecentMeasurementScopes
      extend ActiveSupport::Concern

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

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

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

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

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

        # Returns [date, [systolic_bp, diastolic_bp]]
        def most_recent_blood_pressure_for(patient)
          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]

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

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
renalware-core-2.0.87 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.86 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.85 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.84 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.83 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.82 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.81 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.80 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.79 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.78 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.77 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.76 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.75 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.74 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.73 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.72 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.71 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.70 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.69 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead
renalware-core-2.0.68 app/models/concerns/renalware/clinics/most_recent_measurement_scopes.rb.dead