@@ -12,9 +12,9 @@ class DraftConsentsController < ApplicationController
1212
1313 include WizardControllerConcern
1414
15- before_action :set_triage_form , if : :includes_triage_step?
16- before_action :set_parent_options , if : -> { current_step == :who }
1715 before_action :set_back_link_path
16+ before_action :set_new_or_existing_contact_options , if : :is_who_step?
17+ before_action :set_triage_form , if : :includes_triage_step?
1818
1919 def show
2020 authorize Consent , :edit?
@@ -213,6 +213,58 @@ def set_steps
213213 self . steps = @draft_consent . wizard_steps
214214 end
215215
216+ def set_back_link_path
217+ @back_link_path =
218+ if @draft_consent . editing?
219+ wizard_path ( "confirm" )
220+ elsif current_step == @draft_consent . wizard_steps . first
221+ session_patient_programme_path ( @session , @patient , @programme )
222+ else
223+ previous_wizard_path
224+ end
225+ end
226+
227+ def is_who_step? = current_step == :who
228+
229+ NewOrExistingContactOption = Struct . new ( :value , :label , :hint )
230+
231+ def set_new_or_existing_contact_options
232+ @new_or_existing_contact_options = [ ]
233+
234+ if @patient . can_self_consent_after_gillick_assessment? (
235+ location : @session . location ,
236+ programme_type : @programme . type
237+ )
238+ @new_or_existing_contact_options << NewOrExistingContactOption . new (
239+ value : "patient" ,
240+ label : "Child (Gillick competent)"
241+ )
242+ end
243+
244+ parent_relationships =
245+ (
246+ @patient . parent_relationships . includes ( :parent ) +
247+ @patient
248+ . consents
249+ . where ( programme_type : @programme . type )
250+ . filter_map ( &:parent_relationship )
251+ ) . compact . uniq . sort_by ( &:label )
252+
253+ @new_or_existing_contact_options +=
254+ parent_relationships . map do |parent_relationship |
255+ NewOrExistingContactOption . new (
256+ value : parent_relationship . parent . id ,
257+ label : parent_relationship . label_with_parent ,
258+ hint : parent_relationship . parent . contact_label
259+ )
260+ end
261+
262+ @new_or_existing_contact_options << NewOrExistingContactOption . new (
263+ value : "new" ,
264+ label : "Add a new parental contact"
265+ )
266+ end
267+
216268 def includes_triage_step?
217269 current_step . in? ( %i[ triage confirm ] ) && steps . include? ( "triage" )
218270 end
@@ -235,28 +287,6 @@ def set_triage_form
235287 end
236288 end
237289
238- def set_parent_options
239- @parent_options =
240- (
241- @patient . parent_relationships . includes ( :parent ) +
242- @patient
243- . consents
244- . select { it . programme_type == @programme . type }
245- . filter_map ( &:parent_relationship )
246- ) . compact . uniq . sort_by ( &:label )
247- end
248-
249- def set_back_link_path
250- @back_link_path =
251- if @draft_consent . editing?
252- wizard_path ( "confirm" )
253- elsif current_step == @draft_consent . wizard_steps . first
254- session_patient_programme_path ( @session , @patient , @programme )
255- else
256- previous_wizard_path
257- end
258- end
259-
260290 # Returns:
261291 # {
262292 # question_0: %i[notes response],
0 commit comments