From e1595b60df8693959e16b055e2f94ac48ceedf36 Mon Sep 17 00:00:00 2001 From: afwilcox Date: Mon, 16 Dec 2024 14:16:10 -0800 Subject: [PATCH 1/3] feat: CEEB Export script --- exports/ceeb_quarterly_case_export.sql | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 exports/ceeb_quarterly_case_export.sql diff --git a/exports/ceeb_quarterly_case_export.sql b/exports/ceeb_quarterly_case_export.sql new file mode 100644 index 00000000..27bf7419 --- /dev/null +++ b/exports/ceeb_quarterly_case_export.sql @@ -0,0 +1,44 @@ +----------------------------------------------------- +-- Quarterly CEEB Case Export query to be run for CEEB statistics +-- see https://github.com/bcgov/nr-compliance-enforcement-cm/wiki/Data-Exports for more information +----------------------------------------------------- +select + le.lead_identifier as "Complaint Identifer", + sc.long_description as "WDR Schedule/IPM Sector Type", + sec.long_description as "Sector/Category", + dc.long_description as "Discharge Type", + ac.long_description as "Action Taken", + TO_CHAR(((act.action_date at time zone 'UTC') at time zone 'PDT'), 'MM/DD/YYYY') as "Date Action Taken", + CASE + WHEN s.site_id is not null THEN 'U' || s.site_id + when ap.authorization_permit_id is not null then ap.authorization_permit_id + ELSE '' + END as "Authorization Number" +from + case_management.lead le +left join case_management.case_file cf on + cf.case_file_guid = le.case_identifier +left join case_management.decision d on + d.case_file_guid = cf.case_file_guid and d.active_ind = 'Y' +left join case_management.schedule_sector_xref ssx on + d.schedule_sector_xref_guid = ssx.schedule_sector_xref_guid and ssx.active_ind = 'Y' +left join case_management.schedule_code sc on + sc.schedule_code = ssx.schedule_code +left join case_management.sector_code sec on + sec.sector_code = ssx.sector_code +left join case_management.discharge_code dc on + dc.discharge_code = d.discharge_code +left join case_management.site s on + s.case_file_guid = cf.case_file_guid and s.active_ind = 'Y' +left join case_management.authorization_permit ap on + ap.case_file_guid = cf.case_file_guid and ap.active_ind = 'Y' +left join case_management.action act on + act.decision_guid = d.decision_guid and act.active_ind = 'Y' +left join case_management.action_type_action_xref atax on + atax.action_type_action_xref_guid = act.action_type_action_xref_guid +left join case_management.action_code ac on + ac.action_code = atax.action_code + where cf.owned_by_agency_code = 'EPO' + and act.action_date BETWEEN 'YYYY-MM-DD' AND 'YYYY-MM-DD' -- replace placeholders with actual values + order by + le.lead_identifier asc \ No newline at end of file From 125ee18b525249e10f0cb3d632bd3041678423d3 Mon Sep 17 00:00:00 2001 From: afwilcox Date: Tue, 17 Dec 2024 08:21:35 -0800 Subject: [PATCH 2/3] chore: comment out fields not requested --- exports/ceeb_quarterly_case_export.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/exports/ceeb_quarterly_case_export.sql b/exports/ceeb_quarterly_case_export.sql index 27bf7419..c56103e8 100644 --- a/exports/ceeb_quarterly_case_export.sql +++ b/exports/ceeb_quarterly_case_export.sql @@ -3,17 +3,17 @@ -- see https://github.com/bcgov/nr-compliance-enforcement-cm/wiki/Data-Exports for more information ----------------------------------------------------- select - le.lead_identifier as "Complaint Identifer", - sc.long_description as "WDR Schedule/IPM Sector Type", + le.lead_identifier as "Record ID", + --sc.long_description as "WDR Schedule/IPM Sector Type", sec.long_description as "Sector/Category", dc.long_description as "Discharge Type", ac.long_description as "Action Taken", - TO_CHAR(((act.action_date at time zone 'UTC') at time zone 'PDT'), 'MM/DD/YYYY') as "Date Action Taken", - CASE - WHEN s.site_id is not null THEN 'U' || s.site_id - when ap.authorization_permit_id is not null then ap.authorization_permit_id - ELSE '' - END as "Authorization Number" + TO_CHAR(((act.action_date at time zone 'UTC') at time zone 'PDT'), 'MM/DD/YYYY') as "Date Action Taken" + --CASE + -- WHEN s.site_id is not null THEN 'U' || s.site_id + -- when ap.authorization_permit_id is not null then ap.authorization_permit_id + -- ELSE '' + --END as "Authorization Number" from case_management.lead le left join case_management.case_file cf on From fd4520fc5bed38c006b87ab4536b10705b64ebdb Mon Sep 17 00:00:00 2001 From: afwilcox Date: Wed, 18 Dec 2024 09:52:35 -0800 Subject: [PATCH 3/3] fix: Updates to export --- exports/ceeb_quarterly_case_export.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exports/ceeb_quarterly_case_export.sql b/exports/ceeb_quarterly_case_export.sql index c56103e8..7abd286b 100644 --- a/exports/ceeb_quarterly_case_export.sql +++ b/exports/ceeb_quarterly_case_export.sql @@ -39,6 +39,6 @@ left join case_management.action_type_action_xref atax on left join case_management.action_code ac on ac.action_code = atax.action_code where cf.owned_by_agency_code = 'EPO' - and act.action_date BETWEEN 'YYYY-MM-DD' AND 'YYYY-MM-DD' -- replace placeholders with actual values + and act.action_date >= CURRENT_DATE - INTERVAL '1 year' order by le.lead_identifier asc \ No newline at end of file