Class: Audit
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Audit
- Defined in:
- app/models/audit.rb
Overview
This model manage the user’s medical check for a risk
Relation
-
belongs to User
-
belongs to Category
-
has one History (is the last history entry)
-
has many History
-
has many Meeting
Validations
-
Validate presence of User relation
-
Validate presence of Category relation
-
Validate presence of :status
-
Validate presence of :expire
Default scope
where.not(status: 0)
Instance Attribute Summary collapse
-
#category_id ⇒ Integer
Reference id of Category, can’t be null.
-
#created_at ⇒ Datetime
Date when the record was created.
-
#expire ⇒ Date
Expire date for the Audit.
-
#status ⇒ String
Possible statuses: * deleted: 0, * created: 1, * suitable: 2, * suitable_prescription_temporary: 3, * suitable_prescription_permanent: 4, * unsuitable_temporary: 5, * unsuitable_permanent: 6.
-
#updated_at ⇒ Datetime
Date when the record was updated.
-
#user_id ⇒ Integer
Reference id of User, can’t be Null.
Class Method Summary collapse
-
.expire_beetween(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) ⇒ Array
select all Audit inside a period.
-
.expired(date: Date.today.end_of_month) ⇒ Array
Select all Audit expired in a date.
-
.get_calendar(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) ⇒ Array
specific query for make a calendar.
Instance Method Summary collapse
-
#delete ⇒ Object
For security reason is an alias of #destroy.
-
#destroy ⇒ False
Override default destroy end return everytime false.
-
#expired? ⇒ Boolean
True if Audit is expired.
-
#state ⇒ Object
is an alias of history relation.
-
#status_class ⇒ String
Based on #expired? response ‘expired’ o ‘active’.
Methods inherited from ApplicationRecord
Instance Attribute Details
#category_id ⇒ Integer
Returns reference id of Category, can’t be null.
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
#created_at ⇒ Datetime
Returns date when the record was created.
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
#expire ⇒ Date
Returns expire date for the Audit.
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
#status ⇒ String
Possible statuses:
-
deleted: 0,
-
created: 1,
-
suitable: 2,
-
suitable_prescription_temporary: 3,
-
suitable_prescription_permanent: 4,
-
unsuitable_temporary: 5,
-
unsuitable_permanent: 6
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
#updated_at ⇒ Datetime
Returns date when the record was updated.
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
#user_id ⇒ Integer
Returns reference id of User, can’t be Null.
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
Class Method Details
.expire_beetween(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) ⇒ Array
select all Audit inside a period
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
.expired(date: Date.today.end_of_month) ⇒ Array
Select all Audit expired in a date
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
.get_calendar(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) ⇒ Array
specific query for make a calendar
54 55 56 57 58 59 60 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 |
# File 'app/models/audit.rb', line 54 class Audit < ApplicationRecord belongs_to :user belongs_to :category has_many :histories, dependent: :destroy has_one :history, -> { order created_at: :desc }, class_name: 'History', foreign_key: :audit_id, inverse_of: :audit has_many :meetings, dependent: :destroy has_many :events, through: :meetings, dependent: :destroy store_accessor :metadata, :author, :revision_date validates :user_id, presence: true validates :category_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :status, presence: true validates :expire, presence: true enum status: { deleted: 0, created: 1, suitable: 2, suitable_prescription_temporary: 3, suitable_prescription_permanent: 4, unsuitable_temporary: 5, unsuitable_permanent: 6 } default_scope { where.not(status: 0) } scope :ordered_by_category_title, -> { joins(:category).order('categories.title') } scope :expire_beetween, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { where(expire: start_at..stop_at) } scope :expired, ->(date: Time.zone.today.end_of_month) { where('expire <= ?', date) } scope :get_calendar, ->(start_at = Time.zone.now.to_date, stop_at = Time.zone.now.to_date) { expire_beetween(start_at, stop_at).select('expire as expire', 'Count(Distinct audits.user_id) as count').group('expire').order('expire') } accepts_nested_attributes_for :histories, allow_destroy: false, limit: 1 # is an alias of history relation # @return [Object] return last {Audit}'s {History} def state history end # For security reason is an alias of {destroy} def delete destroy end # Override default destroy end return everytime false. {Audit} record cannot be destroyed # @return [False] def destroy false end # @return [String] based on {expired?} response 'expired' o 'active' def status_class expired? ? 'expired' : 'active' end # @return [Boolean] true if {Audit} is expired def expired? expire <= Time.zone.now end end |
Instance Method Details
#delete ⇒ Object
For security reason is an alias of #destroy
94 95 96 |
# File 'app/models/audit.rb', line 94 def delete destroy end |
#destroy ⇒ False
Override default destroy end return everytime false. Audit record cannot be destroyed
100 101 102 |
# File 'app/models/audit.rb', line 100 def destroy false end |
#expired? ⇒ Boolean
Returns true if Audit is expired.
110 111 112 |
# File 'app/models/audit.rb', line 110 def expired? expire <= Time.zone.now end |
#state ⇒ Object
is an alias of history relation
89 90 91 |
# File 'app/models/audit.rb', line 89 def state history end |
#status_class ⇒ String
Returns based on #expired? response ‘expired’ o ‘active’.
105 106 107 |
# File 'app/models/audit.rb', line 105 def status_class expired? ? 'expired' : 'active' end |