From 89601f3a5f8ab123f00875d16ab5c6da4e213333 Mon Sep 17 00:00:00 2001 From: saravanpa-aot Date: Thu, 23 May 2024 22:04:54 +0530 Subject: [PATCH] Added exclusion filter for work phases (#2247) * Added filtering by work phase exclusion * Added filtering by work phase exclusion * filter values fixed * Fixed review comments --- .../src/api/reports/anticipated_schedule_report.py | 6 +++++- .../reports/eaReferral/AnticipatedEAOSchedule.tsx | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/epictrack-api/src/api/reports/anticipated_schedule_report.py b/epictrack-api/src/api/reports/anticipated_schedule_report.py index 79d36984b..a5686916f 100644 --- a/epictrack-api/src/api/reports/anticipated_schedule_report.py +++ b/epictrack-api/src/api/reports/anticipated_schedule_report.py @@ -83,7 +83,9 @@ def _fetch_data(self, report_date): next_pecp_query = self._get_next_pcp_query(start_date) referral_event_query = self._get_referral_event_query(start_date) latest_status_updates = self._get_latest_status_update_query() - + exclude_phase_names = [] + if self.filters and "exclude" in self.filters: + exclude_phase_names = self.filters["exclude"] results_qry = ( db.session.query(Work) .join(Event, Event.work_id == Work.id) @@ -132,6 +134,8 @@ def _fetch_data(self, report_date): Work.work_state.in_( [WorkStateEnum.IN_PROGRESS.value, WorkStateEnum.SUSPENDED.value] ), + # Filter out specific WorkPhase names + ~WorkPhase.name.in_(exclude_phase_names) ) .add_columns( PhaseCode.name.label("phase_name"), diff --git a/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx b/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx index 6f8d176d4..f33e03a49 100644 --- a/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx +++ b/epictrack-web/src/components/reports/eaReferral/AnticipatedEAOSchedule.tsx @@ -85,10 +85,16 @@ export default function AnticipatedEAOSchedule() { const downloadPDFReport = React.useCallback(async () => { try { fetchReportData(); + let filtersToSend = {}; + + if (selectedTypes.length > 0) { + filtersToSend = { exclude: selectedTypes }; + } const binaryReponse = await ReportService.downloadPDF( REPORT_TYPE.EA_REFERRAL, { report_date: reportDate, + filters: filtersToSend, } ); const url = window.URL.createObjectURL( @@ -107,7 +113,7 @@ export default function AnticipatedEAOSchedule() { } catch (error) { setResultStatus(RESULT_STATUS.ERROR); } - }, [reportDate, fetchReportData]); + }, [reportDate, fetchReportData, selectedTypes]); const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { setSelectedTab(newValue); @@ -194,7 +200,9 @@ export default function AnticipatedEAOSchedule() { autoFocus multiple value={selectedTypes} - onChange={(e, value) => setSelectedTypes(value)} + onChange={(e, value) => { + setSelectedTypes(value); + }} options={typeFilter} renderInput={(params) => (