Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CEEB exports #112

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions exports/ceeb_quarterly_case_export.sql
Original file line number Diff line number Diff line change
@@ -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 "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"
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 >= CURRENT_DATE - INTERVAL '1 year'
order by
le.lead_identifier asc