diff --git a/migrations/migrations/R__update-insert-complaint-from-staging.sql b/migrations/migrations/R__update-insert-complaint-from-staging.sql index 7dd2d2d43..0b4e8f389 100644 --- a/migrations/migrations/R__update-insert-complaint-from-staging.sql +++ b/migrations/migrations/R__update-insert-complaint-from-staging.sql @@ -152,7 +152,7 @@ OR REPLACE FUNCTION public.insert_complaint_from_staging (_complaint_identifier _webeoc_cos_area_community := complaint_data ->> 'cos_area_community'; _webeoc_cos_reffered_by_lst := complaint_data ->> 'cos_reffered_by_lst'; _cos_reffered_by_txt := left(complaint_data ->> '_cos_reffered_by_txt',120); - _webeoc_identifier := complaint_data ->> 'webeoc_identifier'; + SELECT * FROM PUBLIC.insert_and_return_code( _webeoc_cos_reffered_by_lst, 'reprtdbycd' ) INTO _cos_reffered_by_lst; diff --git a/webeoc/src/types/complaint-type.ts b/webeoc/src/types/complaint-type.ts index 8ae428e26..b1dcfd675 100644 --- a/webeoc/src/types/complaint-type.ts +++ b/webeoc/src/types/complaint-type.ts @@ -69,4 +69,7 @@ export interface Complaint { back_number_of_days: string; back_number_of_hours: string; back_number_of_minutes: string; + flag_COS: string; + flag_AT: string; + flag_UAT: string; } diff --git a/webeoc/src/types/complaint-update-type.ts b/webeoc/src/types/complaint-update-type.ts index c16e56c27..dd76c53fb 100644 --- a/webeoc/src/types/complaint-update-type.ts +++ b/webeoc/src/types/complaint-update-type.ts @@ -39,6 +39,7 @@ export interface ComplaintUpdate { parent_species: string; update_created_by_username: string; update_created_by_position: string; + flag_UPD: string; back_number_of_days: string; back_number_of_hours: string; back_number_of_minutes: string; diff --git a/webeoc/src/webeoc-scheduler/webeoc-scheduler.service.ts b/webeoc/src/webeoc-scheduler/webeoc-scheduler.service.ts index 87e363f78..11150fa83 100644 --- a/webeoc/src/webeoc-scheduler/webeoc-scheduler.service.ts +++ b/webeoc/src/webeoc-scheduler/webeoc-scheduler.service.ts @@ -96,6 +96,38 @@ export class WebEocScheduler { } } + // Filter the complaints to only include complaints with a given flag (indicating the type of data: complaint, update, action taken, etc), or complaints where the violation type is Waste or Pesticide (which + // are complaints needed for CEEB (where the violation type is waste or pesticide, accross all regions) + private _filterComplaints(complaints: any[], flagName: string) { + return complaints.filter((complaint: any) => { + if (flagName === WEBEOC_FLAGS.COMPLAINTS) { + return ( + complaint.flag_COS === "Yes" || + complaint.violation_type === "Waste" || + complaint.violation_type === "Pesticide" + ); + } else if (flagName === WEBEOC_FLAGS.COMPLAINT_UPDATES) { + return ( + complaint.flag_UPD === "Yes" || + complaint.update_violation_type === "Waste" || + complaint.update_violation_type === "Pesticide" + ); + } else if (flagName === WEBEOC_FLAGS.ACTIONS_TAKEN) { + return ( + complaint.flag_AT === "Yes" || + complaint.violation_type === "Waste" || + complaint.violation_type === "Pesticide" + ); + } else if (flagName === WEBEOC_FLAGS.ACTIONS_TAKEN_UPDATES) { + return ( + complaint.flag_UAT === "Yes" || + complaint.violation_type === "Waste" || + complaint.violation_type === "Pesticide" + ); + } + }); + } + private async fetchDataFromWebEOC(urlPath: string, flagName: string): Promise { const dateFilter = this.getDateFilter(); const url = `${process.env.WEBEOC_URL}/${urlPath}`; @@ -105,23 +137,24 @@ export class WebEocScheduler { }, }; + // default filter grabs complaints that are newer than a specific date + const filterItems = [dateFilter]; + + // construct the body of the request const body = { customFilter: { boolean: "and", - items: [ - dateFilter, - { - fieldname: flagName, - operator: "Equals", - fieldvalue: "Yes", - }, - ], + items: filterItems, }, }; try { const response = await axios.post(url, body, config); - return response.data as Complaint[]; + const complaints = response.data; + + const filteredComplaints = this._filterComplaints(complaints, flagName); + + return filteredComplaints; } catch (error) { this.logger.error(`Error fetching data from WebEOC at ${urlPath}:`, error); throw error; @@ -178,20 +211,15 @@ export class WebEocScheduler { const body = { customFilter: { boolean: "and", - items: [ - dateFilter, - { - fieldname: WEBEOC_FLAGS.ACTIONS_TAKEN, - operator: "Equals", - fieldvalue: "Yes", - }, - ], + items: [dateFilter], }, }; try { const response = await axios.post(url, body, config); - return response?.data; + const complaints = response.data as Complaint[]; + const filteredComplaints = this._filterComplaints(complaints, WEBEOC_FLAGS.ACTIONS_TAKEN); + return filteredComplaints; } catch (error) { this.logger.error(`Error fetching data from WebEOC at ${path}:`, error); throw error; @@ -210,20 +238,15 @@ export class WebEocScheduler { const body = { customFilter: { boolean: "and", - items: [ - dateFilter, - { - fieldname: WEBEOC_FLAGS.ACTIONS_TAKEN_UPDATES, - operator: "Equals", - fieldvalue: "Yes", - }, - ], + items: [dateFilter], }, }; try { const response = await axios.post(url, body, config); - return response?.data; + const complaints = response.data as Complaint[]; + const filteredComplaints = this._filterComplaints(complaints, WEBEOC_FLAGS.ACTIONS_TAKEN_UPDATES); + return filteredComplaints; } catch (error) { this.logger.error(`Error fetching data from WebEOC at ${path}:`, error); throw error;