added 260907 version of worker toolkit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
class Search::ForDose < ::Search
|
||||
validates :query, presence: true
|
||||
|
||||
validate :query_must_include_treatment_id
|
||||
def query_must_include_treatment_id
|
||||
return if query[:treatment_id]
|
||||
|
||||
errors.add(:query, "must include treatment_id")
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_by_query
|
||||
q = name.present? ? treatments.where(value: /#{name}/i) : treatments
|
||||
q = q.order_by("checkin.date" => "desc").distinct(:value)
|
||||
q.slice(0..10).map { |value| ::Dose.new(name: value) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def treatments
|
||||
Checkin::Treatment.where(
|
||||
:value.ne => nil, :is_taken => true, :treatment_id => treatment_id
|
||||
)
|
||||
end
|
||||
|
||||
def treatment_id
|
||||
query[:treatment_id].to_i
|
||||
end
|
||||
|
||||
def name
|
||||
text = query[:name]
|
||||
Regexp.escape(text) if text
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class Search::ForFood < ::Search
|
||||
validates :query, presence: true
|
||||
|
||||
protected
|
||||
|
||||
def find_by_query
|
||||
Food.fts(query[:name], MAX_ROWS, user.id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
class Search::ForTopic < ::Search
|
||||
alias_method :super_query, :find_by_query
|
||||
|
||||
protected
|
||||
|
||||
def find_by_query
|
||||
(tags + symptoms + conditions + treatments).sort { |a, b| a.name.underscore <=> b.name.underscore }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
%w[tag symptom condition treatment].each do |trackable|
|
||||
define_method trackable.pluralize do
|
||||
@resource = trackable
|
||||
|
||||
super_query
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user