diff --git a/epictrack-api/src/api/reports/anticipated_schedule_report.py b/epictrack-api/src/api/reports/anticipated_schedule_report.py
index f0116394d..3e327a819 100644
--- a/epictrack-api/src/api/reports/anticipated_schedule_report.py
+++ b/epictrack-api/src/api/reports/anticipated_schedule_report.py
@@ -60,7 +60,8 @@ def __init__(self, filters, color_intensity):
"report_description",
"anticipated_decision_date",
"additional_info",
- "ministry_name",
+ "responsible_minister",
+ "ministry",
"referral_date",
"eac_decision_by",
"decision_by",
@@ -86,6 +87,7 @@ def _fetch_data(self, report_date):
start_date = report_date + timedelta(days=-7)
report_date = report_date.astimezone(timezone('US/Pacific'))
staff_decision_by = aliased(Staff)
+ staff_minister = aliased(Staff)
next_pecp_query = self._get_next_pcp_query(start_date)
referral_event_query = self._get_referral_event_query(start_date)
@@ -95,6 +97,7 @@ def _fetch_data(self, report_date):
exclude_phase_names = self.filters["exclude"]
formatted_phase_name = self._get_formatted_phase_name()
ea_type_column = self._get_ea_type_column(formatted_phase_name)
+ responsible_minister_column = self._get_responsible_minister_column(staff_minister)
current_app.logger.debug(f"Executing query for {self.report_title} report")
results_qry = (
@@ -128,6 +131,7 @@ def _fetch_data(self, report_date):
.join(Region, Region.id == Project.region_id_env)
.join(EAAct, EAAct.id == Work.ea_act_id)
.join(Ministry)
+ .outerjoin(staff_minister, Ministry.minister_id == staff_minister.id)
.outerjoin(latest_status_updates, latest_status_updates.c.work_id == Work.id)
.outerjoin(
staff_decision_by, # Join staff alias
@@ -274,7 +278,14 @@ def _fetch_data(self, report_date):
Event.anticipated_date + func.cast(func.concat(Event.number_of_days, " DAYS"), INTERVAL)
).label("anticipated_decision_date"),
latest_status_updates.c.description.label("additional_info"),
- Ministry.name.label("ministry_name"),
+ case(
+ (
+ Ministry.name != "Not Applicable",
+ Ministry.name
+ ),
+ else_=""
+ ).label("ministry"),
+ responsible_minister_column,
(
Event.anticipated_date + func.cast(func.concat(Event.number_of_days, " DAYS"), INTERVAL)
).label("referral_date"),
@@ -431,6 +442,22 @@ def _get_formatted_phase_name(self):
else_=func.concat(func.substring(PhaseCode.name, r"\((.*?)\)"), " Amendment"),
).label("formatted_phase_name")
+ def _get_responsible_minister_column(self, staff_minister):
+ """Returns an expression for the responsible minister"""
+ return case(
+ (
+ Ministry.name != "Not Applicable",
+ case(
+ (
+ func.concat(staff_minister.first_name, staff_minister.last_name) != "",
+ func.concat(staff_minister.first_name, " ", staff_minister.last_name)
+ ),
+ else_=""
+ )
+ ),
+ else_=None,
+ ).label("responsible_minister")
+
def _get_next_pcp_query(self, start_date):
"""Create and return the subquery for next PCP event based on start date"""
pecp_configuration_ids = (
diff --git a/epictrack-api/src/api/reports/report_templates/anticipated_schedule.docx b/epictrack-api/src/api/reports/report_templates/anticipated_schedule.docx
index 25609c891..8c74d7113 100644
Binary files a/epictrack-api/src/api/reports/report_templates/anticipated_schedule.docx and b/epictrack-api/src/api/reports/report_templates/anticipated_schedule.docx differ
diff --git a/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx b/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx
index f20f4577c..f50f912fa 100644
--- a/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx
+++ b/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx
@@ -293,14 +293,29 @@ export default function AnticipatedEAOSchedule() {
EA Type
{item["ea_type"]}
-
-
- Responsible Minister
-
-
- {item["ministry_name"]}
-
-
+ {item["ministry"] && (
+
+ {item["responsible_minister"] ? (
+ <>
+
+ Responsible Minister
+
+
+ {item["responsible_minister"]}
+
+ >
+ ) : (
+ <>
+
+ Responsible Ministry
+
+
+ {item["ministry"]}
+
+ >
+ )}
+
+ )}
Decision to be made by