Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeBlyth committed Jan 20, 2013
1 parent 2a9cc6c commit 09e3293
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app/helpers/selectable_items_helper.rb
@@ -1,8 +1,10 @@
require 'pry' require 'pry'
module SelectableItemsHelper module SelectableItemsHelper


def check_boxes(record, section, columns=4) # section is Class name for table to use e.g., Symptom # Set up HTML table containing checkboxes supplied by SectionName.visit_fields, and pre-checked
section_name = section.to_s.underscore.pluralize # according to their status in record.
def check_boxes(record, section_name, columns=4) # section is Class name for table to use e.g., Symptom
section= section_name.singularize.camelize.constantize
fields = section.visit_fields fields = section.visit_fields
return nil if fields.empty? return nil if fields.empty?
rows = ((fields.length + columns -1) / columns).to_i # how many rows rows = ((fields.length + columns -1) / columns).to_i # how many rows
Expand All @@ -25,5 +27,28 @@ def check_boxes(record, section, columns=4) # section is Class name for table t
return content_tag(:table, table_contents) return content_tag(:table, table_contents)
end end


def selections_to_string(record, section_name)
merged = selected(record, section_name)
merged.map do |k,v|
v = v.blank? ? nil : v
[k,v].compact.join(': ')
end.join('; ')
end

# Given a store of features and associated comments, like
# {:headache=>'true', :fever=>'high', :cough => 'true', :headache_comment => 'improving', :fever_comment=>'night sweats'}
# return a hash like
# {:headache=>'improving', :fever=>'high--night sweats', :cough => ''}
def selected(record, section_name)
merged = Hash.new {|h,k| h[k] = ''}
comments, basic = record.send(section_name).partition {|x| x[0] =~ /_comment\Z/}
basic.each do |b|
merged[b[0]] = (b[1] == 'true') ? '' : b[1]
end
comments.each do |comment|
source_key = comment[0][0..-9]
merged[source_key] = [merged[source_key], comment[1]].join ('--')
end
end
end end


0 comments on commit 09e3293

Please sign in to comment.