Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft modeling for timestamped trackables #109 #646

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/app/models/checkin/condition.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class Checkin::Condition
include Mongoid::Document
include Checkin::Trackable
include Checkin::Fiveable

field :condition_id, type: Integer

has_many :ratings, class_name: 'Checkin::Rating', as: :trackable
# TODO: use accepts_nested_attributes_for :ratings ?

validates :condition_id, uniqueness: { scope: :checkin_id }
end
7 changes: 7 additions & 0 deletions backend/app/models/checkin/rating.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Checkin::Rating
include Mongoid::Document
include Checkin::Timeable
include Checkin::Fiveable

belongs_to :trackable, polymorphic: true
end
4 changes: 3 additions & 1 deletion backend/app/models/checkin/symptom.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class Checkin::Symptom
include Mongoid::Document
include Checkin::Trackable
include Checkin::Fiveable

field :symptom_id, type: Integer

has_many :ratings, class_name: 'Checkin::Rating', as: :trackable
# TODO: use accepts_nested_attributes_for :ratings ?

validates :symptom_id, uniqueness: { scope: :checkin_id }
end
8 changes: 8 additions & 0 deletions backend/app/models/checkin/taking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Checkin::Taking
include Mongoid::Document
include Checkin::Timeable

field :dose, type: String

belongs_to :treatment, class_name: 'Checkin::Treatment', index: true
end
9 changes: 9 additions & 0 deletions backend/app/models/checkin/timeable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Checkin::Timeable
extend ActiveSupport::Concern

included do
field :time_of_day, type: Integer # minutes from 00:00
validates :time_of_day, inclusion: { in: (0..1440) }, if: 'time_of_day.present?'
end

end
7 changes: 6 additions & 1 deletion backend/app/models/checkin/treatment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ class Checkin::Treatment
# Fields
#
field :treatment_id, type: Integer
field :value, type: String
field :is_taken, type: Boolean

#
# Relations
#
has_many :takings, class_name: 'Checkin::Taking'
# TODO: use accepts_nested_attributes_for :takings ?

#
# Indexes
#
Expand Down