module Base::StudentMedical
  extend ActiveSupport::Concern

  included do
    self.table_name = 'StudentMed'
    self.primary_key = 'StudentMedID'

    alias_attribute :id, :StudentMedID
    alias_attribute :school_id, :SchoolID
    alias_attribute :student_id, :StudentID
    alias_attribute :updated, :UpdateDT
    alias_attribute :asthma, :Asthma
    alias_attribute :diabetes, :Diabetes
    alias_attribute :seizures, :Seizures
    alias_attribute :deafness, :Hearing
    alias_attribute :sight_impairment, :Sight
    alias_attribute :allergies, :Allergies
    # alias_attribute :others, :Others
    alias_attribute :tylenol, :Tylenol
    alias_attribute :ibuprofen, :Ibuprofen
    alias_attribute :comments, :Comments
    alias_attribute :alerts, :AlertComments
    alias_attribute :medication, :Medication
    # alias_attribute :heart, :Heart
    alias_attribute :add, :AddAdhd
    alias_attribute :bladder, :Bladder
    alias_attribute :sicklecell, :Sicklecell
    alias_attribute :hemophiliac, :Hemophiliac
    alias_attribute :exempt, :Exempt
    alias_attribute :healthy, :Healthy

    before_save :set_alerts_default

    before_create :set_defaults

    private
      def set_alerts_default
        self.alerts = '' unless alerts?
      end

      def set_defaults
        self.UpdateDT = '0000-00-00 00:00:00' unless self.UpdateDT
        self.Others = '' unless self.Others
        self.Comments = '' unless self.Comments
        self.AlertComments = '' unless self.AlertComments
        self.Healthy = 0 unless self.Healthy
      end
  end
end
