@@ -12,6 +12,7 @@ class Sessions::RecordController < ApplicationController
1212
1313 before_action :set_todays_batches , only : :show
1414 before_action :set_programme , except : :show
15+ before_action :set_vaccine_method , except : :show
1516 before_action :set_batches , except : :show
1617
1718 def show
@@ -41,9 +42,8 @@ def show
4142 end
4243
4344 def edit_batch
44- @todays_batch =
45- authorize @batches . find_by ( id : todays_batch_id ( programme : @programme ) ) ,
46- :edit?
45+ id = todays_batch_id ( programme : @programme , vaccine_method : @vaccine_method )
46+ @todays_batch = authorize @batches . find ( id ) , :edit?
4747
4848 render :batch
4949 end
@@ -80,11 +80,16 @@ def set_session
8080 def set_todays_batches
8181 all_batches =
8282 @session . programmes . index_with do |programme |
83- policy_scope ( Batch )
84- . where ( vaccine : @session . vaccines )
85- . not_archived
86- . not_expired
87- . find_by ( id : todays_batch_id ( programme :) )
83+ programme . vaccine_methods . filter_map do |vaccine_method |
84+ id = todays_batch_id ( programme :, vaccine_method :)
85+ next if id . nil?
86+
87+ policy_scope ( Batch )
88+ . where ( vaccine : @session . vaccines )
89+ . not_archived
90+ . not_expired
91+ . find_by ( id :)
92+ end
8893 end
8994
9095 @todays_batches = all_batches . compact
@@ -94,10 +99,17 @@ def set_programme
9499 @programme = policy_scope ( Programme ) . find_by! ( type : params [ :programme_type ] )
95100 end
96101
102+ def set_vaccine_method
103+ @vaccine_method = params [ :vaccine_method ]
104+ end
105+
97106 def set_batches
107+ vaccines =
108+ @session . vaccines . where ( programme : @programme , method : @vaccine_method )
109+
98110 @batches =
99111 policy_scope ( Batch )
100- . where ( vaccine : @session . vaccines . where ( programme : @programme ) )
112+ . where ( vaccine : vaccines )
101113 . not_archived
102114 . not_expired
103115 . order_by_name_and_expiration
0 commit comments