-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[US_TN] Summary Sheet + CAF Form Updates (Recidiviz/recidiviz-data#29346
) ## Description of the change This PR makes a series of updates to the opportunity record query for TN Annual Reclass + Custody Level Downgrade as detailed here Recidiviz/recidiviz-data#29105 Some specifics to call out: - There were many references to CellBedAssignment raw data while we work out ingest issues. So I've created a new analyst_data view to pull current facility and unit information and updated references to that in various analyst data views + resident record - There are some new case notes added and some metadata removed. I've tried to comment on those specifics since they may change or break things on the front end - Updates Validation notes: 1. The following query returns 0 rows as expected because all the updated admission dates should be later than the original ones since the original ones are prior to someone entering a TDOC facility ``` WITH sandbox AS ( select person_external_id, admission_date from `recidiviz-123.dsharm20240425_workflows_views.resident_record_materialized`, unnest(all_eligible_opportunities) as all_eligible_opportunities WHERE state_code = 'US_TN' ), main AS ( select person_external_id, admission_date from `recidiviz-123.workflows_views.resident_record_materialized`, unnest(all_eligible_opportunities) as all_eligible_opportunities WHERE state_code = 'US_TN' ) select * from sandbox join main using(person_external_id) where sandbox.admission_date < main.admission_date ``` 2. Eligibility counts dont change for any opp in resident record ``` WITH sandbox AS ( select all_eligible_opportunities, count(*) as sandbox_c from `recidiviz-123.dsharm20240425_workflows_views.resident_record_materialized`, unnest(all_eligible_opportunities) as all_eligible_opportunities group by 1 ), main AS ( select all_eligible_opportunities, count(*) as main_c from `recidiviz-123.dsharm20240425_main_workflows_views.resident_record_materialized`, unnest(all_eligible_opportunities) as all_eligible_opportunities group by 1 ) select * from sandbox join main using(all_eligible_opportunities) where sandbox.sandbox_c != main.main_c ``` 3. Other checks - Q6 metadata should now only have arrays of length 1 or 2 (or null) because we're keeping 2 most recent violations rather than all, which we see when comparing sandbox output to main ``` select ARRAY_LENGTH(JSON_QUERY_ARRAY(form_information_q6_notes)), count(*) from `recidiviz-123.dsharm20240425_main_workflows_views.us_tn_annual_reclassification_review_record_materialized` group by 1 ``` ## Type of change > All pull requests must have at least one of the following labels applied (otherwise the PR will fail): | Label | Description | |----------------------------- |----------------------------------------------------------------------------------------------------------- | | Type: Bug | non-breaking change that fixes an issue | | Type: Feature | non-breaking change that adds functionality | | Type: Breaking Change | fix or feature that would cause existing functionality to not work as expected | | Type: Non-breaking refactor | change addresses some tech debt item or prepares for a later change, but does not change functionality | | Type: Configuration Change | adjusts configuration to achieve some end related to functionality, development, performance, or security | | Type: Dependency Upgrade | upgrades a project dependency - these changes are not included in release notes | ## Related issues Closes Recidiviz/recidiviz-data#29105 ## Checklists ### Development **This box MUST be checked by the submitter prior to merging**: - [x] **Double- and triple-checked that there is no Personally Identifiable Information (PII) being mistakenly added in this pull request** These boxes should be checked by the submitter prior to merging: - [x] Tests have been written to cover the code changed/added as part of this pull request ### Code review These boxes should be checked by reviewers prior to merging: - [ ] This pull request has a descriptive title and information useful to a reviewer - [ ] Potential security implications or infrastructural changes have been considered, if relevant GitOrigin-RevId: 6636f1847328ac5b7f1816eb4304bb5d8fcaaa55
- Loading branch information
Showing
11 changed files
with
263 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
recidiviz/calculator/query/state/views/analyst_data/us_tn/us_tn_cellbed_assignment_raw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Recidiviz - a data platform for criminal justice reform | ||
# Copyright (C) 2024 Recidiviz, Inc. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# ============================================================================= | ||
"""Computes current facility / unit from raw TN data""" | ||
|
||
from recidiviz.big_query.big_query_view import SimpleBigQueryViewBuilder | ||
from recidiviz.calculator.query.state.dataset_config import ANALYST_VIEWS_DATASET | ||
from recidiviz.utils.environment import GCP_PROJECT_STAGING | ||
from recidiviz.utils.metadata import local_project_id_override | ||
|
||
US_TN_CELLBED_ASSIGNMENT_RAW_VIEW_NAME = "us_tn_cellbed_assignment_raw" | ||
|
||
US_TN_CELLBED_ASSIGNMENT_RAW_VIEW_DESCRIPTION = ( | ||
"""Computes current facility / unit from raw TN data""" | ||
) | ||
|
||
US_TN_CELLBED_ASSIGNMENT_RAW_QUERY_TEMPLATE = """ | ||
-- TODO(#24959): Deprecate usage when re-run is over | ||
-- TODO(#27428): Once source of facility ID in TN is reconciled, this can be removed | ||
SELECT | ||
state_code, | ||
person_id, | ||
/* From TN: "The ‘Requested’ location columns contain the new housing assignment | ||
(where the person is being moved to). The ‘Assigned’ columns show the person’s assigned bed | ||
when the new cell bed assignment was entered. Same for the ‘Actual’ columns – this is where he | ||
‘actually’ was when the request was made (this is only different from Assigned when the person | ||
has been moved to another institution temporarily)." Our interpretation of this is that Requested and | ||
Actual work sometimes together and sometimes on a "lag"; Actual should be updated to show the same | ||
thing as Requested, but sometimes it isnt, so we rely on Requested most, then Actual. | ||
For current population, Requested is always hydrated, so the COALESCE is not strictly | ||
needed but is a catch all if Requested is ever missing */ | ||
COALESCE(RequestedSiteID, ActualSiteID, AssignedSiteID) AS facility_id, | ||
COALESCE(RequestedUnitID, ActualUnitID, AssignedUnitID) AS unit_id, | ||
FROM `{project_id}.us_tn_raw_data_up_to_date_views.CellBedAssignment_latest` c | ||
INNER JOIN `{project_id}.normalized_state.state_person_external_id` pei | ||
ON c.OffenderID = pei.external_id | ||
AND pei.state_code = "US_TN" | ||
-- The latest assignment is not always the one with an open assignment. This can occur when someone is assigned to a facility | ||
-- but temporarily sent to another facility (e.g. Special needs facility). Most people only have 1 open assignment, unless | ||
-- they are currently temporarily sent elsewhere (~11 people out of 18k) so we further deduplicate by choosing the latest assignment | ||
WHERE EndDate IS NULL | ||
QUALIFY ROW_NUMBER() OVER(PARTITION BY OffenderID ORDER BY CAST(AssignmentDateTime AS DATETIME) DESC) = 1 | ||
""" | ||
|
||
US_TN_CELLBED_ASSIGNMENT_RAW_VIEW_BUILDER = SimpleBigQueryViewBuilder( | ||
dataset_id=ANALYST_VIEWS_DATASET, | ||
view_id=US_TN_CELLBED_ASSIGNMENT_RAW_VIEW_NAME, | ||
description=US_TN_CELLBED_ASSIGNMENT_RAW_VIEW_DESCRIPTION, | ||
view_query_template=US_TN_CELLBED_ASSIGNMENT_RAW_QUERY_TEMPLATE, | ||
should_materialize=True, | ||
) | ||
|
||
if __name__ == "__main__": | ||
with local_project_id_override(GCP_PROJECT_STAGING): | ||
US_TN_CELLBED_ASSIGNMENT_RAW_VIEW_BUILDER.build_and_print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.