Sha256: 40d66e6c64b7b605e3cc77f8325589969a86f1450d4ef12ccb9ef51726eee1a0

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 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_presence_of :date
      validates_presence_of :clinic

      validates :date, timeliness: { type: :date }
      validates :time, timeliness: { type: :time, allow_blank: true }
      validates :pulse, "renalware/patients/pulse" => 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) }

      def bmi
        return unless weight && height && height > 0
        ((weight / height) / height).round(2)
      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

9 entries across 9 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta12 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta11 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta10 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta9 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta8 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta7 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta6 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta5 app/models/renalware/clinics/clinic_visit.rb
renalware-core-2.0.0.pre.beta4 app/models/renalware/clinics/clinic_visit.rb