1+ from functools import cached_property
2+
13from django .urls import reverse
24
35from ..core .utils .date_formatting import format_date , format_relative_date , format_time
@@ -42,9 +44,9 @@ def present_secondary_nav(id):
4244
4345
4446class AppointmentPresenter :
45- def __init__ (self , appointment ):
47+ def __init__ (self , appointment , last_known_screening = None ):
4648 self ._appointment = appointment
47- self ._last_known_screening = appointment . screening_episode . previous ()
49+ self ._last_known_screening = last_known_screening
4850
4951 self .allStatuses = AppointmentStatus
5052 self .id = appointment .id
@@ -53,17 +55,18 @@ def __init__(self, appointment):
5355 appointment .screening_episode .participant
5456 )
5557
56- @property
58+ @cached_property
5759 def participant_url (self ):
5860 return self .participant .url
5961
60- @property
62+ @cached_property
6163 def start_time (self ):
6264 return self .clinic_slot .starts_at
6365
64- @property
66+ @cached_property
6567 def current_status (self ):
6668 current_status = self ._appointment .current_status
69+
6770 colour = status_colour (current_status .state )
6871
6972 return {
@@ -73,7 +76,7 @@ def current_status(self):
7376 "is_confirmed" : current_status .state == AppointmentStatus .CONFIRMED ,
7477 }
7578
76- @property
79+ @cached_property
7780 def last_known_screening (self ):
7881 return (
7982 {
@@ -98,17 +101,17 @@ def __init__(self, clinic_slot):
98101
99102 self .clinic_id = self ._clinic .id
100103
101- @property
104+ @cached_property
102105 def clinic_type (self ):
103106 return self ._clinic .get_type_display ().capitalize ()
104107
105- @property
108+ @cached_property
106109 def slot_time_and_clinic_date (self ):
107110 clinic_slot = self ._clinic_slot
108111 clinic = self ._clinic
109112
110113 return f"{ format_time (clinic_slot .starts_at )} ({ clinic_slot .duration_in_minutes } minutes) - { format_date (clinic .starts_at )} ({ format_relative_date (clinic .starts_at )} )"
111114
112- @property
115+ @cached_property
113116 def starts_at (self ):
114117 return format_time (self ._clinic_slot .starts_at )
0 commit comments