Class: History

Inherits:
ApplicationRecord show all
Defined in:
app/models/history.rb

Overview

This model save the clinical history of the users

Relation

belongs to Audit belongs to User as #doctor belongs to User as #author has one User through Audit has one Category through Audit has one Risk through Audit has one CategoryRisk through Category

Validations

validate presence of #revision_date validate presence of #doctor_id if #require_doctor? validate presence of #author_id validate presence of #status validate inclusion of #status in statuses listed in config/settings.yml

### Before validation #prerequisite

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#div

Instance Attribute Details

#audit_idInteger

Returns reference id for Audit.

Returns:

  • (Integer)

    reference id for Audit



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#author_idInteger

Returns reference id for User as #author.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#bodyString

Returns hystory note.

Returns:

  • (String)

    hystory note



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#cityString

Returns name of related city.

Returns:

  • (String)

    name of related city



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#created_atDatetime

Returns date when the record was created.

Returns:

  • (Datetime)

    date when the record was created



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#doctor_idInteger

Returns reference id for User as #doctor.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#idInteger

Returns the unique identifier for History.

Returns:

  • (Integer)

    the unique identifier for History



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#labString

Returns name of related lab.

Returns:

  • (String)

    name of related lab



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#revision_dateDatetime

Returns Date of the related event.

Returns:

  • (Datetime)

    Date of the related event



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#statusString

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#updated_atDatetime

Returns date when the record was updated.

Returns:

  • (Datetime)

    date when the record was updated



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

Instance Method Details

#auditObject

Returns related Audit.

Returns:

  • (Object)

    related Audit



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#authorObject

Returns related User as author.

Returns:

  • (Object)

    related User as author



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#categoryObject

Returns related Category through Audit.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#category_risksObject

Returns related CategoryRisk through Category.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#deleteFalse

override delete. History can’t be destroyed

Returns:

  • (False)


87
88
89
# File 'app/models/history.rb', line 87

def delete
  false
end

#destroyFalse

override destroy. History can’t be destroyed

Returns:

  • (False)


93
94
95
# File 'app/models/history.rb', line 93

def destroy
  false
end

#doctorObject

Returns related {User) as doctor.

Returns:

  • (Object)

    related {User) as doctor



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#riskObject

Returns related Risk through CategoryRisk.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end

#updateFalse

override update. History can’t be updated

Returns:

  • (False)


81
82
83
# File 'app/models/history.rb', line 81

def update
  false
end

#userObject

Returns related User through Audit.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/history.rb', line 61

class History < ApplicationRecord
  belongs_to :audit
  belongs_to :doctor, class_name: 'User', foreign_key: 'doctor_id', optional: :require_doctor?, inverse_of: :audits
  belongs_to :author, class_name: 'User', foreign_key: 'author_id', optional: false, inverse_of: :audits
  has_one :user, through: :audit
  has_one :category, through: :audit
  has_one :category_risks, through: :category
  has_one :risk, through: :category_risks
  validates :revision_date, presence: true
  validates :doctor_id, presence: true, if: :require_doctor?
  validates :author_id, presence: true
  validates :status, presence: true, inclusion: Settings.history.status
  before_validation :prerequisite

  scope :active, -> { where.not(status: 'change_date_next_visit') }
  scope :between, ->(start_on: Time.zone.now.beginning_of_year, stop_on: Time.zone.now.end_of_year) { where(revision_date: start_on..stop_on) }
  scope :availables, -> { where.not(status: %w[created deleted change_date_next_visit]) }

  # override update. {History} can't be updated
  # @return [False]
  def update
    false
  end

  # override delete. {History} can't be destroyed
  # @return [False]
  def delete
    false
  end

  # override destroy. {History} can't be destroyed
  # @return [False]
  def destroy
    false
  end

  private

  # preset some attributes before validation
  def prerequisite
    self.revision_date = Time.zone.now if revision_date.blank?
    audit.expire = if audit.new_record?
                    revision_date.to_date
                   elsif audit.persisted? && audit.status_was == 'deleted'
                     revision_date.to_date
                   else
                    revision_date.to_date + audit.category.months.month
                   end
    audit.status = status
  end

  # @return [True] if status isn't created or deleted
  def require_doctor?
    %w[created deleted].exclude?(status)
  end
end