@@ -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,64 @@ 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+ is_gillick_competent =
235+ @patient
236+ . gillick_assessments
237+ . order ( created_at : :desc )
238+ . for_session ( @session )
239+ . for_programme ( @programme )
240+ &.first
241+ &.gillick_competent?
242+
243+ if is_gillick_competent
244+ @new_or_existing_contact_options << NewOrExistingContactOption . new (
245+ value : "patient" ,
246+ label : "Child (Gillick competent)"
247+ )
248+ end
249+
250+ parent_relationships =
251+ (
252+ @patient . parent_relationships . includes ( :parent ) +
253+ @patient
254+ . consents
255+ . where ( programme_type : @programme . type )
256+ . filter_map ( &:parent_relationship )
257+ ) . compact . uniq . sort_by ( &:label )
258+
259+ @new_or_existing_contact_options +=
260+ parent_relationships . map do |parent_relationship |
261+ NewOrExistingContactOption . new (
262+ value : parent_relationship . parent . id ,
263+ label : parent_relationship . label_with_parent ,
264+ hint : parent_relationship . parent . contact_label
265+ )
266+ end
267+
268+ @new_or_existing_contact_options << NewOrExistingContactOption . new (
269+ value : "new" ,
270+ label : "Add a new parental contact"
271+ )
272+ end
273+
216274 def includes_triage_step?
217275 current_step . in? ( %i[ triage confirm ] ) && steps . include? ( "triage" )
218276 end
@@ -235,28 +293,6 @@ def set_triage_form
235293 end
236294 end
237295
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-
260296 # Returns:
261297 # {
262298 # question_0: %i[notes response],
0 commit comments