Skip to content

Commit

Permalink
[US_IX] Remove folks with sex offender alerts and violent charges fro…
Browse files Browse the repository at this point in the history
…m CRC opps (Recidiviz/recidiviz-data#29170)

## Description of the change

- Sex offenders: I created new state-specific criteria and added it to
all CRC opps.
- Violent offenses: I used a general criteria view and added it to all
CRC opps.

I uploaded this to sandbox (`_hsalas`), and it does slightly reduce the
number of people eligible:
- CRC resident worker: from 2,536 to 1,833
- CRC work-release: 1,768 to 1,248
- XCRC: 277 to 222

## Related issues

Closes Recidiviz/recidiviz-data#5299

## Checklists

### Development

**This box MUST be checked by the submitter prior to merging**:
- [ ] **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:
- [ ] 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: f155107ea2ae89af76c242d1c01f1cfe648b3948
  • Loading branch information
hugosr-r authored and Helper Bot committed May 11, 2024
1 parent b6e65eb commit ed4e2b6
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 6 deletions.
Expand Up @@ -126,12 +126,6 @@
{ix_general_case_notes(where_clause_addition="AND ContactModeDesc = 'Positive'",
criteria_str=INSTITUTIONAL_BEHAVIOR_NOTES_STR)}
UNION ALL
-- Positive [behavior notes]
{ix_general_case_notes(where_clause_addition="AND ContactModeDesc = 'Positive'",
criteria_str=INSTITUTIONAL_BEHAVIOR_NOTES_STR)}
UNION ALL
Expand Down
@@ -0,0 +1,96 @@
# 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/>.
# =============================================================================

"""Defines a criteria view that shows spans of time for
which residents do not have a sex offender alert"""

from recidiviz.calculator.query.sessions_query_fragments import (
create_sub_sessions_with_attributes,
)
from recidiviz.calculator.query.bq_utils import (
nonnull_end_date_clause,
)
from recidiviz.calculator.query.state.dataset_config import NORMALIZED_STATE_DATASET
from recidiviz.common.constants.states import StateCode
from recidiviz.ingest.direct.dataset_config import raw_latest_views_dataset_for_region
from recidiviz.ingest.direct.types.direct_ingest_instance import DirectIngestInstance
from recidiviz.task_eligibility.task_criteria_big_query_view_builder import (
StateSpecificTaskCriteriaBigQueryViewBuilder,
)
from recidiviz.utils.environment import GCP_PROJECT_STAGING
from recidiviz.utils.metadata import local_project_id_override

_CRITERIA_NAME = "US_IX_NO_SEX_OFFENDER_ALERT"

_DESCRIPTION = """Defines a criteria view that shows spans of time for
which residents do not have a sex offender alert"""

_SEX_OFFENDER_CODES = [
"61", # Supervise as Sex offender
"62", # Sex Offender Registration Required
]

_QUERY_TEMPLATE = f"""
WITH sex_offender_alert AS (
SELECT
peid.state_code,
peid.person_id,
SAFE_CAST(LEFT(off.StartDate, 10) AS DATE) AS start_date,
SAFE_CAST(LEFT(off.EndDate, 10) AS DATE) AS end_date,
off.AlertId AS alert_id,
ia.AlertDesc AS alert_description,
FROM `{{project_id}}.{{us_ix_raw_data_up_to_date_dataset}}.ind_Offender_Alert_latest` off
LEFT JOIN `{{project_id}}.{{us_ix_raw_data_up_to_date_dataset}}.ind_Alert_latest` ia
USING(AlertId)
INNER JOIN `{{project_id}}.{{normalized_state_dataset}}.state_person_external_id` peid
ON peid.external_id = off.OffenderId
AND peid.state_code = 'US_IX'
AND peid.id_type = 'US_IX_DOC'
-- Alerts related to sex offenses
WHERE off.AlertId IN {tuple(_SEX_OFFENDER_CODES)}
),
{create_sub_sessions_with_attributes(table_name='sex_offender_alert')}
SELECT
state_code,
person_id,
start_date,
end_date,
False AS meets_criteria,
TO_JSON(STRUCT(STRING_AGG(DISTINCT alert_description) AS latest_alert_descriptions,
STRING_AGG(DISTINCT alert_id) AS latest_alert_ids)) AS reason
FROM sub_sessions_with_attributes
WHERE start_date < {nonnull_end_date_clause('end_date')}
GROUP BY 1,2,3,4"""

VIEW_BUILDER: StateSpecificTaskCriteriaBigQueryViewBuilder = (
StateSpecificTaskCriteriaBigQueryViewBuilder(
criteria_name=_CRITERIA_NAME,
description=_DESCRIPTION,
state_code=StateCode.US_IX,
criteria_spans_query_template=_QUERY_TEMPLATE,
us_ix_raw_data_up_to_date_dataset=raw_latest_views_dataset_for_region(
state_code=StateCode.US_IX, instance=DirectIngestInstance.PRIMARY
),
normalized_state_dataset=NORMALIZED_STATE_DATASET,
meets_criteria_default=True,
)
)

if __name__ == "__main__":
with local_project_id_override(GCP_PROJECT_STAGING):
VIEW_BUILDER.build_and_print()
Expand Up @@ -29,12 +29,14 @@
custody_level_is_minimum,
not_in_treatment_in_prison,
not_serving_for_sexual_offense,
not_serving_for_violent_offense,
)
from recidiviz.task_eligibility.criteria.state_specific.us_ix import (
crc_resident_worker_time_based_criteria,
no_absconsion_escape_and_eluding_police_offenses_within_10_years,
no_detainers_for_xcrc_and_crc,
not_in_crc_facility,
no_sex_offender_alert,
)
from recidiviz.task_eligibility.single_task_eligiblity_spans_view_builder import (
SingleTaskEligibilitySpansBigQueryViewBuilder,
Expand All @@ -60,6 +62,8 @@
not_in_crc_facility.VIEW_BUILDER,
crc_resident_worker_time_based_criteria.VIEW_BUILDER,
not_in_treatment_in_prison.VIEW_BUILDER,
no_sex_offender_alert.VIEW_BUILDER,
not_serving_for_violent_offense.VIEW_BUILDER,
],
completion_event_builder=transfer_to_reentry_center.VIEW_BUILDER,
)
Expand Down
Expand Up @@ -29,12 +29,14 @@
custody_level_is_minimum,
not_in_treatment_in_prison,
not_serving_for_sexual_offense,
not_serving_for_violent_offense,
)
from recidiviz.task_eligibility.criteria.state_specific.us_ix import (
crc_work_release_time_based_criteria,
no_absconsion_escape_and_eluding_police_offenses_within_10_years,
no_detainers_for_xcrc_and_crc,
not_in_crc_facility,
no_sex_offender_alert,
)
from recidiviz.task_eligibility.single_task_eligiblity_spans_view_builder import (
SingleTaskEligibilitySpansBigQueryViewBuilder,
Expand All @@ -61,6 +63,8 @@
not_in_crc_facility.VIEW_BUILDER,
crc_work_release_time_based_criteria.VIEW_BUILDER,
not_in_treatment_in_prison.VIEW_BUILDER,
no_sex_offender_alert.VIEW_BUILDER,
not_serving_for_violent_offense.VIEW_BUILDER,
],
completion_event_builder=granted_work_release.VIEW_BUILDER,
)
Expand Down
Expand Up @@ -28,6 +28,7 @@
from recidiviz.task_eligibility.criteria.general import (
custody_level_is_minimum,
not_serving_for_sexual_offense,
not_serving_for_violent_offense,
)
from recidiviz.task_eligibility.criteria.state_specific.us_ix import (
in_crc_facility_or_pwcc_unit_1,
Expand All @@ -36,6 +37,7 @@
no_absconsion_escape_and_eluding_police_offenses_within_10_years,
no_class_a_or_b_dor_for_6_months,
no_detainers_for_xcrc_and_crc,
no_sex_offender_alert,
)
from recidiviz.task_eligibility.single_task_eligiblity_spans_view_builder import (
SingleTaskEligibilitySpansBigQueryViewBuilder,
Expand All @@ -62,6 +64,8 @@
no_detainers_for_xcrc_and_crc.VIEW_BUILDER,
not_serving_for_sexual_offense.VIEW_BUILDER,
no_absconsion_escape_and_eluding_police_offenses_within_10_years.VIEW_BUILDER,
no_sex_offender_alert.VIEW_BUILDER,
not_serving_for_violent_offense.VIEW_BUILDER,
],
completion_event_builder=release_to_community_confinement_supervision.VIEW_BUILDER,
)
Expand Down
4 changes: 4 additions & 0 deletions recidiviz/view_registry/raw_data_reference_reasons.yaml
Expand Up @@ -219,6 +219,8 @@ US_IX:
ind_Alert:
task_eligibility_criteria_us_ix.no_active_nco: |-
Usage reason unknown. Grandfathered in 04/18/2024.
task_eligibility_criteria_us_ix.no_sex_offender_alert: |-
Sex offender alerts are not ingested.
workflows_views.us_ix_transfer_to_crc_resident_worker_request_record: |-
Usage reason unknown. Grandfathered in 04/18/2024.
workflows_views.us_ix_transfer_to_crc_work_release_request_record: |-
Expand Down Expand Up @@ -269,6 +271,8 @@ US_IX:
ind_Offender_Alert:
task_eligibility_criteria_us_ix.no_active_nco: |-
Usage reason unknown. Grandfathered in 04/18/2024.
task_eligibility_criteria_us_ix.no_sex_offender_alert: |-
Sex offender alerts are not ingested.
workflows_views.us_ix_transfer_to_crc_resident_worker_request_record: |-
Usage reason unknown. Grandfathered in 04/18/2024.
workflows_views.us_ix_transfer_to_crc_work_release_request_record: |-
Expand Down

0 comments on commit ed4e2b6

Please sign in to comment.