Sha256: 4a4ec2c02ee980453a2dbab05ed4fcbc41934c38862517d9a0275be41c74a577

Contents?: true

Size: 2 KB

Versions: 12

Compression:

Stored size: 2 KB

Contents

require_dependency "renalware/patients"
require_dependency "renalware/clinics"

module Renalware
  module Clinics
    class ClinicVisit < ApplicationRecord
      self.table_name = :clinic_visits
      has_paper_trail class_name: "Renalware::Clinics::Version"

      include Accountable
      include PatientScope
      extend Enumerize

      belongs_to :patient, touch: true
      belongs_to :clinic
      has_many :clinic_letters

      validates :date, presence: true
      validates :clinic, presence: true

      validates :date, timeliness: { type: :date }
      validates :time, timeliness: { type: :time, allow_blank: true }
      validates :pulse, "renalware/patients/pulse" => true
      validates :height, "renalware/patients/height" => true
      validates :temperature, "renalware/patients/temperature" => true

      enumerize :urine_blood, in: %i(neg trace very_low low medium high)
      enumerize :urine_protein, in: %i(neg trace very_low low medium high)

      scope :ordered, ->{ order(date: :desc, created_at: :desc) }
      scope :most_recent_for_patient, ->(patient) { for_patient(patient).ordered.limit(1) }

      def bmi
        BMI.new(weight: weight, height: height).to_f
      end

      def bp
        return unless systolic_bp.present? && diastolic_bp.present?
        "#{systolic_bp}/#{diastolic_bp}"
      end

      def standing_bp
        return unless standing_systolic_bp.present? && standing_diastolic_bp.present?
        "#{standing_systolic_bp}/#{standing_diastolic_bp}"
      end

      def bp=(val)
        self.systolic_bp, self.diastolic_bp = val.split("/")
      end

      def standing_bp=(val)
        self.standing_systolic_bp, self.standing_diastolic_bp = val.split("/")
      end

      def datetime
        return if date.blank?
        return date.to_datetime if time.blank?
        datetime_from_date_and_time
      end

      private

      def datetime_from_date_and_time
        DateTime.new(date.year, date.month, date.day, time.hour, time.min, 0, time.zone)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.7 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.5 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.4 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.3 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.2 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.1 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/clinics/clinic_visit.rb