11# frozen_string_literal: true
22
33class AppChildSummaryComponent < ViewComponent ::Base
4- def initialize ( child , show_parents : false , change_links : { } , remove_links : { } )
4+ def initialize (
5+ child ,
6+ current_team : nil ,
7+ show_parents : false ,
8+ show_school_and_year_group : true ,
9+ change_links : { } ,
10+ remove_links : { }
11+ )
512 super
613
714 @child = child
15+ @current_team = current_team
816 @show_parents = show_parents
17+ @show_school_and_year_group = show_school_and_year_group
918 @change_links = change_links
1019 @remove_links = remove_links
1120 end
@@ -25,6 +34,14 @@ def call
2534 )
2635 end
2736 end
37+
38+ if archive_reason
39+ summary_list . with_row do |row |
40+ row . with_key { "Archive reason" }
41+ row . with_value { format_archive_reason }
42+ end
43+ end
44+
2845 summary_list . with_row do |row |
2946 row . with_key { "Full name" }
3047 row . with_value { format_full_name }
@@ -57,14 +74,16 @@ def call
5774 row . with_value { format_address }
5875 end
5976 end
60- summary_list . with_row do |row |
61- row . with_key { "School" }
62- row . with_value { format_school }
63- end
64- if @child . respond_to? ( :year_group )
77+ if @show_school_and_year_group
6578 summary_list . with_row do |row |
66- row . with_key { "Year group" }
67- row . with_value { format_year_group }
79+ row . with_key { "School" }
80+ row . with_value { format_school }
81+ end
82+ if @child . respond_to? ( :year_group )
83+ summary_list . with_row do |row |
84+ row . with_key { "Year group" }
85+ row . with_value { format_year_group }
86+ end
6887 end
6988 end
7089 if ( gp_practice = @child . try ( :gp_practice ) )
@@ -112,10 +131,27 @@ def call
112131
113132 def academic_year = AcademicYear . current
114133
134+ def archive_reason
135+ @archive_reason ||=
136+ if @current_team
137+ ArchiveReason . find_by ( team : @current_team , patient : @child )
138+ end
139+ end
140+
115141 def format_nhs_number
116142 highlight_if ( helpers . patient_nhs_number ( @child ) , @child . nhs_number_changed? )
117143 end
118144
145+ def format_archive_reason
146+ type_string = archive_reason . human_enum_name ( :type )
147+
148+ if archive_reason . other?
149+ "#{ type_string } : #{ archive_reason . other_details } "
150+ else
151+ type_string
152+ end
153+ end
154+
119155 def format_full_name
120156 highlight_if (
121157 @child . full_name ,
0 commit comments