@@ -42,10 +42,10 @@ class AppPatientSessionSearchResultCardComponent < ViewComponent::Base
42
42
end
43
43
end
44
44
45
- if context != :patient_specific_direction && ( note = patient_session . latest_note )
45
+ if context != :patient_specific_direction && latest_note
46
46
summary_list . with_row do |row |
47
47
row . with_key { "Notes" }
48
- row . with_value { render note_to_log_event ( note ) }
48
+ row . with_value { render note_to_log_event ( latest_note ) }
49
49
end
50
50
end
51
51
end %>
@@ -59,7 +59,7 @@ class AppPatientSessionSearchResultCardComponent < ViewComponent::Base
59
59
<% end %>
60
60
ERB
61
61
62
- def initialize ( patient_session , context :, programmes : [ ] )
62
+ def initialize ( patient : , session : , context :, programmes : [ ] )
63
63
unless context . in? (
64
64
%i[
65
65
patients
@@ -73,10 +73,8 @@ def initialize(patient_session, context:, programmes: [])
73
73
raise "Unknown context: #{ context } "
74
74
end
75
75
76
- @patient_session = patient_session
77
- @patient = patient_session . patient
78
- @session = patient_session . session
79
-
76
+ @patient = patient
77
+ @session = session
80
78
@context = context
81
79
82
80
@programmes =
@@ -89,7 +87,7 @@ def initialize(patient_session, context:, programmes: [])
89
87
90
88
private
91
89
92
- attr_reader :patient_session , : patient, :session , :context , :programmes
90
+ attr_reader :patient , :session , :context , :programmes
93
91
94
92
delegate :govuk_button_to ,
95
93
:govuk_summary_list ,
@@ -283,6 +281,14 @@ def patient_specific_direction_status_tag
283
281
}
284
282
end
285
283
284
+ def latest_note
285
+ patient
286
+ . notes
287
+ . sort_by ( &:created_at )
288
+ . reverse
289
+ . find { it . session_id == session . id }
290
+ end
291
+
286
292
def note_to_log_event ( note )
287
293
truncated_body = note . body . truncate_words ( 80 , omission : "…" )
288
294
0 commit comments