Skip to content

Commit

Permalink
[Track-276] AS add responsible minister or responsible ministry (#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolkamps1 authored Dec 5, 2024
1 parent b26c425 commit 03068f9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
31 changes: 29 additions & 2 deletions epictrack-api/src/api/reports/anticipated_schedule_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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 = (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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 = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,29 @@ export default function AnticipatedEAOSchedule() {
<TableCell>EA Type</TableCell>
<TableCell>{item["ea_type"]}</TableCell>
</TableRow>
<TableRow>
<TableCell>
Responsible Minister
</TableCell>
<TableCell>
{item["ministry_name"]}
</TableCell>
</TableRow>
{item["ministry"] && (
<TableRow>
{item["responsible_minister"] ? (
<>
<TableCell>
Responsible Minister
</TableCell>
<TableCell>
{item["responsible_minister"]}
</TableCell>
</>
) : (
<>
<TableCell>
Responsible Ministry
</TableCell>
<TableCell>
{item["ministry"]}
</TableCell>
</>
)}
</TableRow>
)}
<TableRow>
<TableCell>
Decision to be made by
Expand Down

0 comments on commit 03068f9

Please sign in to comment.