Class: History
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- History
- 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
-
#audit_id ⇒ Integer
Reference id for Audit.
- #author_id ⇒ Integer
-
#body ⇒ String
Hystory note.
-
#city ⇒ String
Name of related city.
-
#created_at ⇒ Datetime
Date when the record was created.
- #doctor_id ⇒ Integer
-
#id ⇒ Integer
The unique identifier for History.
-
#lab ⇒ String
Name of related lab.
-
#revision_date ⇒ Datetime
Date of the related event.
- #status ⇒ String
-
#updated_at ⇒ Datetime
Date when the record was updated.
Instance Method Summary collapse
-
#audit ⇒ Object
Related Audit.
-
#author ⇒ Object
Related User as author.
- #category ⇒ Object
-
#category_risks ⇒ Object
Related CategoryRisk through Category.
-
#delete ⇒ False
override delete.
-
#destroy ⇒ False
override destroy.
-
#doctor ⇒ Object
Related {User) as doctor.
-
#risk ⇒ Object
Related Risk through CategoryRisk.
-
#update ⇒ False
override update.
- #user ⇒ Object
Methods inherited from ApplicationRecord
Instance Attribute Details
#audit_id ⇒ Integer
Returns 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_id ⇒ Integer
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 |
#body ⇒ String
Returns 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 |
#city ⇒ String
Returns 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_at ⇒ Datetime
Returns 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_id ⇒ Integer
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 |
#id ⇒ Integer
Returns 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 |
#lab ⇒ String
Returns 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_date ⇒ Datetime
Returns 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 |
#status ⇒ 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_at ⇒ Datetime
Returns 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
#audit ⇒ Object
Returns 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 |
#author ⇒ Object
Returns 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 |
#category ⇒ Object
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_risks ⇒ Object
Returns related CategoryRisk through Category.
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 |
#delete ⇒ False
override delete. History can’t be destroyed
87 88 89 |
# File 'app/models/history.rb', line 87 def delete false end |
#destroy ⇒ False
override destroy. History can’t be destroyed
93 94 95 |
# File 'app/models/history.rb', line 93 def destroy false end |
#doctor ⇒ Object
Returns 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 |
#risk ⇒ Object
Returns related Risk through CategoryRisk.
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 |
#update ⇒ False
override update. History can’t be updated
81 82 83 |
# File 'app/models/history.rb', line 81 def update false end |
#user ⇒ Object
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 |