Skip to content
Browse files

In progress, all tests pass.

  • Loading branch information...
1 parent 215534b commit b3592c700c8bd772217c5eb423075566af08299a @MikeBlyth committed Jan 17, 2013
View
4 Gemfile
@@ -38,6 +38,10 @@ group :assets do
gem 'bootstrap-sass'
end
+group :test, :development do
+ gem "quiet_assets"
+end
+
group :test do
gem 'annotate'
gem "rspec-rails"
View
3 Gemfile.lock
@@ -156,6 +156,8 @@ GEM
pry (~> 0.9.9)
pry-rails (0.2.2)
pry (>= 0.9.10)
+ quiet_assets (1.0.1)
+ railties (~> 3.1)
rack (1.4.3)
rack-cache (1.2)
rack (>= 0.4)
@@ -278,6 +280,7 @@ DEPENDENCIES
pry
pry-debugger
pry-rails
+ quiet_assets
rails (= 3.2.11)
rspec-rails
ruby-debug
View
9 app/controllers/lab_requests_controller.rb
@@ -16,6 +16,15 @@ def create
end
end
+ # This is a bit unusual for an update controller. Although the lab request has many lab_results,
+ # (which at this point are actually requests for a given lab service), the form only handles the
+ # lab_service_ids and not the lab_result objects themselves, to avoid having to generate a large number
+ # of objects just to allow them to be selected. The form does not even handle the lab_result ids,
+ # only the service ids. This approach might need to be reworked completely
+ # or refactored. Presently, we simply delete all the pending lab_results and add fresh all the
+ # lab services specified in the incoming update form.
+ # The associated lab_result records are added not directly but by inserting their ids into the
+ # params hash in a way that causes them to be created via the accepts_nested_attributes feature.
def update
# selected_services = params.delete(:services)
#binding.pry
View
23 app/controllers/lab_results_controller.rb
@@ -1,7 +1,9 @@
+#require 'std_to_activescaffold_adapter'
class LabResultsController < ApplicationController
active_scaffold :lab_result do |config|
config.columns = [:lab_service, :date, :status, :result, :abnormal, :panic, :comments]
config.columns[:lab_service].clear_link
+ list.sorting = {:date => 'DESC'}
config.columns[:date].inplace_edit = true
config.columns[:status].inplace_edit = true
config.columns[:status].options = {:options => [:pending, :recorded, :QNS, :error]}
@@ -10,5 +12,26 @@ class LabResultsController < ApplicationController
config.columns[:abnormal].inplace_edit = true
config.columns[:panic].inplace_edit = true
config.columns[:comments].inplace_edit = true
+ config.show.link = false
+ config.delete.link = false
+ config.update.link = false
+ # config.update.link.page = true # Note that if the update form is used, it will not work properly with
+ # AS at this point.
end
+
+ def delete_authorized?(record)
+ false
+ end
+# include StdToActivescaffoldAdapter # NB THIS MUST COME *AFTER* THE active_scaffold configuration!
+
+ #def update
+ # @record = LabResult.find params[:id]
+ # if @record.update_attributes(params[:lab_result])
+ # flash[:notice] = 'Lab result updated'
+ # puts "Request referer is #{request.referer}"
+ # redirect_to request.referer
+ # else
+ # render :edit
+ # end
+ #end
end
View
7 app/helpers/lab_requests_helper.rb
@@ -1,12 +1,15 @@
module LabRequestsHelper
def available_labs
- selected = @record.lab_results.map {|r| r.lab_service_id}
+ current_results = @record.lab_results
+ selected = current_results.map {|r| r.lab_service_id}
+ frozen = current_results.select {|r| r.status != 'pending'}.map {|r| r.lab_service_id}
available = {}
LabGroup.all.each do |group|
available[group.name] =
group.lab_services.all.map {|s| {id: s.id, name: s.name, abbrev: s.abbrev,
- selected: selected.include?(s.id)} }
+ selected: selected.include?(s.id),
+ frozen: frozen.include?(s.id)} }
end
available
end
View
3 app/helpers/std_to_activescaffold_adapter.rb
@@ -14,7 +14,7 @@ module StdToActivescaffoldAdapter
# Get model symbol (e.g. :visit) from controller name (e.g. VisitsController)
def my_model_sym
# Override if this doesn't give the right symbol
- @my_model_sym ||= self.class.to_s.sub('Controller','').singularize.downcase.to_sym
+ @my_model_sym ||= self.class.to_s.sub('Controller','').singularize.underscore.to_sym
end
def my_do_update
@@ -27,6 +27,7 @@ def my_do_create
def tweak_params_for_as
params[:record] = params[my_model_sym]
+ return params if params[:record].nil? # ToDo - log a warning
# Convert refs to xxxx_id to xxxx
params[:record].select {|k,v| k =~ /(.*)_id\Z/}.each do |k,v|
params[:record][k[0..-4]] = v
View
2 app/views/lab_results/_select.html.haml
@@ -1,3 +1,3 @@
-= check_box_tag("services[#{service[:id]}]", 1, service[:selected])
+= check_box_tag("services[#{service[:id]}]", 1, service[:selected], disabled: service[:frozen])
= service[:abbrev]
%br

0 comments on commit b3592c7

Please sign in to comment.
Something went wrong with that request. Please try again.