Class: Renalware::PD::UnifiedPETAdequaciesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- BaseController
- Renalware::PD::UnifiedPETAdequaciesController
- Includes:
- PresenterHelper
- Defined in:
- app/controllers/renalware/pd/unified_pet_adequacies_controller.rb
Overview
PET and Adequacy are two distinct, descrete PD tests. The function of this unified PET + Adequacy controller is to provide the functionality for a user to add the data for both at the same time. This is because a) users tend to regard the tests as ‘lumped-together’ (even though they aren’t), and b) both tests are often done at the same time, so a unified form saves some time and effort.
Note that we never edit a unified PET + Adequacy; as they create separate rows in the db and are separate models, once created they are treated distinctly. This is mainly because the processing of the tests is quicte different. See pet.rb and adequacy.rb for more detail.
Instance Method Summary collapse
-
#adequacy_params ⇒ Object
rubocop:enable Metrics/MethodLength.
- #build_form_object(pet, adequacy) ⇒ Object
- #create ⇒ Object
-
#new ⇒ Object
We use an activbe model form to present a unified model api for the view to display and submit in the #new template.
-
#pet_params ⇒ Object
rubocop:disable Metrics/MethodLength.
- #unified_params ⇒ Object
Methods included from PresenterHelper
Methods inherited from BaseController
Instance Method Details
#adequacy_params ⇒ Object
rubocop:enable Metrics/MethodLength
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/renalware/pd/unified_pet_adequacies_controller.rb', line 78 def adequacy_params params .require(:patient_pd_unified_pet_adequacy) .require(:adequacy) .permit( :patient_id, :performed_on, :height, :weight, :dial_24_vol_in, :dial_24_vol_out, :dial_24_missing, :urine_24_vol, :urine_24_missing ) end |
#build_form_object(pet, adequacy) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/controllers/renalware/pd/unified_pet_adequacies_controller.rb', line 47 def build_form_object(pet, adequacy) UnifiedPETAdequacyForm.new( patient: patient, pet: pet, adequacy: adequacy, **unified_params.to_h.symbolize_keys ) end |
#create ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/renalware/pd/unified_pet_adequacies_controller.rb', line 33 def create Patient, :new? pet = PETResult.new(pet_params) adequacy = AdequacyResult.new(adequacy_params) form = build_form_object(pet, adequacy) if form.valid? form.save_by!(current_user) redirect_to patient_pd_dashboard_path(patient) else render :new, locals: { form: form } end end |
#new ⇒ Object
We use an activbe model form to present a unified model api for the view to display and submit in the #new template.
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/renalware/pd/unified_pet_adequacies_controller.rb', line 23 def new form = UnifiedPETAdequacyForm.new( patient: patient, pet: PETResult.new(patient: patient, performed_on: Date.current), adequacy: AdequacyResult.new(patient: patient, performed_on: Date.current) ) Patient, :index? render locals: { form: form } end |
#pet_params ⇒ Object
rubocop:disable Metrics/MethodLength
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/renalware/pd/unified_pet_adequacies_controller.rb', line 57 def pet_params params .require(:patient_pd_unified_pet_adequacy) .require(:pet) .permit( :patient_id, :performed_on, :test_type, :volume_in, :volume_out, :dextrose_concentration_id, :infusion_time, :drain_time, :overnight_volume_in, :overnight_volume_out, :overnight_dextrose_concentration_id, :overnight_dwell_time ) end |
#unified_params ⇒ Object
95 96 97 98 99 |
# File 'app/controllers/renalware/pd/unified_pet_adequacies_controller.rb', line 95 def unified_params params .require(:patient_pd_unified_pet_adequacy) .permit(:adequacy_missing, :pet_missing) end |