def test_purpose_for_incarceration_subtype_two_same_day(self) -> None:
        """Tests that the longer shock incarceration length is taken from two parole board actions that happened on
        the same day."""
        parole_board_decision_entry_1 = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_9_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_9_MONTHS,
        )

        parole_board_permanent_decision_1 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry_1],
        )

        parole_board_decision_entry_2 = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_6_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_6_MONTHS,
        )

        parole_board_permanent_decision_2 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry_2],
        )

        commitment_admission_date = date(2020, 1, 1)

        purpose_for_incarceration_subtype = us_pa_incarceration_period_pre_processing_delegate._purpose_for_incarceration_subtype(
            commitment_admission_date,
            None,
            [parole_board_permanent_decision_1, parole_board_permanent_decision_2],
        )

        self.assertEqual(
            SHOCK_INCARCERATION_9_MONTHS, purpose_for_incarceration_subtype
        )

        purpose_for_incarceration_subtype = us_pa_incarceration_period_pre_processing_delegate._purpose_for_incarceration_subtype(
            commitment_admission_date,
            None,
            [parole_board_permanent_decision_2, parole_board_permanent_decision_1],
        )

        self.assertEqual(
            SHOCK_INCARCERATION_9_MONTHS, purpose_for_incarceration_subtype
        )
Exemple #2
0
    def test_get_violation_and_response_history_us_mo_handle_law_technicals(self):
        """Tests that a US_MO violation report with a TECHNICAL type and a LAW condition is not treated like a
        citation with a LAW condition."""
        supervision_violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_MO",
            violation_date=datetime.date(2009, 1, 7),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_MO",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                ),
            ],
            supervision_violated_conditions=[
                StateSupervisionViolatedConditionEntry.new_with_defaults(
                    state_code="US_MO", condition="LAW"
                ),
            ],
        )

        supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults(
            state_code="US_MO",
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
            response_subtype="ITR",
            response_date=datetime.date(2009, 1, 7),
            is_draft=False,
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_MO",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_MO",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                    revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
                ),
            ],
            supervision_violation=supervision_violation,
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date, [supervision_violation_response], UsMoViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.TECHNICAL,
            most_severe_violation_type_subtype=StateSupervisionViolationType.TECHNICAL.value,
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=1,
            violation_history_description="1tech",
            violation_type_frequency_counter=[["LAW", "TECHNICAL"]],
        )

        self.assertEqual(expected_output, violation_history)
Exemple #3
0
    def test_get_violation_and_response_history_with_us_mo_subtype(self):
        supervision_violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_MO",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_MO",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                ),
            ],
            supervision_violated_conditions=[
                StateSupervisionViolatedConditionEntry.new_with_defaults(
                    state_code="US_MO", condition="DRG"
                ),
                StateSupervisionViolatedConditionEntry.new_with_defaults(
                    state_code="US_MO", condition="OTHER"
                ),
            ],
        )

        supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults(
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
            response_subtype="INI",
            state_code="US_MO",
            response_date=datetime.date(2009, 1, 7),
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_MO",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_MO",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                ),
            ],
            supervision_violation=supervision_violation,
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date, [supervision_violation_response], UsMoViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.TECHNICAL,
            most_severe_violation_type_subtype="SUBSTANCE_ABUSE",
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=1,
            violation_history_description="1subs",
            violation_type_frequency_counter=[["SUBSTANCE_ABUSE", "OTHER"]],
        )

        self.assertEqual(expected_output, violation_history)
Exemple #4
0
    def test_get_violation_and_response_history(self):
        supervision_violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_XX",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                ),
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.FELONY,
                ),
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.ABSCONDED,
                ),
            ],
        )

        supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults(
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
            state_code="US_XX",
            response_date=datetime.date(2009, 1, 7),
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_XX",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_XX",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                ),
            ],
            supervision_violation=supervision_violation,
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date, [supervision_violation_response], UsXxViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.FELONY,
            most_severe_violation_type_subtype=StateSupervisionViolationType.FELONY.value,
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=1,
            violation_history_description="1felony",
            violation_type_frequency_counter=[["TECHNICAL", "FELONY", "ABSCONDED"]],
        )

        self.assertEqual(expected_output, violation_history)
    def test_most_severe_revocation_type_subtype_invalid_type(self):
        parole_board_decision_entry_1 = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text="XXX",
            revocation_type=StateSupervisionViolationResponseRevocationType.
            SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.
            SHOCK_INCARCERATION,
            revocation_type_raw_text="XXX",
        )

        parole_board_permanent_decision_1 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.
            PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType
            .PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[
                parole_board_decision_entry_1
            ],
        )

        parole_board_decision_entry_2 = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_6_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.
            SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.
            SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_6_MONTHS,
        )

        parole_board_permanent_decision_2 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.
            PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType
            .PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[
                parole_board_decision_entry_2
            ],
        )

        revocation_type_subtype = (
            us_pa_revocation_utils._most_severe_revocation_type_subtype([
                parole_board_permanent_decision_1,
                parole_board_permanent_decision_2
            ]))

        self.assertEqual(SHOCK_INCARCERATION_6_MONTHS, revocation_type_subtype)
Exemple #6
0
    def test_get_violation_and_response_history_with_us_pa_subtype_high_technical(self):
        supervision_violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_PA",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_PA",
                    violation_type=StateSupervisionViolationType.ABSCONDED,
                    violation_type_raw_text="H09",
                ),
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_PA",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text="H08",  # High Technical
                ),
            ],
        )

        supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults(
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
            state_code="US_PA",
            response_date=datetime.date(2009, 1, 7),
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_PA",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_PA",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                    revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
                ),
            ],
            supervision_violation=supervision_violation,
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date, [supervision_violation_response], UsPaViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.TECHNICAL,
            most_severe_violation_type_subtype="HIGH_TECH",
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=1,
            violation_history_description="1high_tech",
            violation_type_frequency_counter=[["ABSCONDED", "HIGH_TECH"]],
        )

        self.assertEqual(expected_output, violation_history)
Exemple #7
0
    def test_get_violation_and_response_history_citation_date(self):
        supervision_violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_XX",
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.ABSCONDED,
                ),
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.MISDEMEANOR,
                ),
            ],
        )

        supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults(
            state_code="US_XX",
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.CITATION,
            response_date=datetime.date(2009, 1, 7),
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_XX",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_XX",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                    revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
                ),
            ],
            supervision_violation=supervision_violation,
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date, [supervision_violation_response], UsXxViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.MISDEMEANOR,
            most_severe_violation_type_subtype=StateSupervisionViolationType.MISDEMEANOR.value,
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=1,
            violation_history_description="1misdemeanor",
            violation_type_frequency_counter=[["ABSCONDED", "MISDEMEANOR"]],
        )

        self.assertEqual(expected_output, violation_history)
    def test_purpose_for_incarceration_subtype(self) -> None:
        parole_board_decision_entry_old = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_UNDER_6_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_UNDER_6_MONTHS,
        )

        parole_board_permanent_decision_outside_window = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2018, month=5, day=16),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry_old],
        )

        parole_board_decision_entry_new = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_12_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_12_MONTHS,
        )

        parole_board_permanent_decision_in_window = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry_new],
        )

        commitment_admission_date = date(2020, 1, 1)
        specialized_purpose_for_incarceration_raw_text = "CCIS-46"

        purpose_for_incarceration_subtype = us_pa_incarceration_period_pre_processing_delegate._purpose_for_incarceration_subtype(
            commitment_admission_date,
            specialized_purpose_for_incarceration_raw_text,
            [
                parole_board_permanent_decision_outside_window,
                parole_board_permanent_decision_in_window,
            ],
        )

        self.assertEqual(
            SHOCK_INCARCERATION_12_MONTHS, purpose_for_incarceration_subtype
        )
    def test_revocation_type_subtype_after_revocations(self):
        parole_board_decision_entry = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_UNDER_6_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.
            SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.
            SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_UNDER_6_MONTHS,
        )

        parole_board_permanent_decision_outside_window = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2020, month=5, day=16),
            response_type=StateSupervisionViolationResponseType.
            PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType
            .PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[
                parole_board_decision_entry
            ],
        )

        revocation_admission_date = date(2020, 1, 1)

        revocation_type_subtype = us_pa_revocation_utils._revocation_type_subtype(
            revocation_admission_date,
            None,
            [parole_board_permanent_decision_outside_window],
        )

        self.assertIsNone(revocation_type_subtype)
Exemple #10
0
    def test_get_violation_and_response_history_no_violations(self):
        supervision_violation_response = (
            StateSupervisionViolationResponse.new_with_defaults(
                state_code="US_XX",
                supervision_violation_response_id=_DEFAULT_SSVR_ID,
                response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
                response_date=datetime.date(2009, 1, 7),
                supervision_violation_response_decisions=[
                    StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                        state_code="US_XX",
                        decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                    )
                ],
            )
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date, [supervision_violation_response], UsXxViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=None,
            most_severe_violation_type_subtype=None,
            most_severe_response_decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
            response_count=1,
            violation_history_description=None,
            violation_type_frequency_counter=None,
        )

        self.assertEqual(expected_output, violation_history)
    def test_most_severe_purpose_for_incarceration_subtype(self) -> None:
        parole_board_decision_entry_1 = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_9_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_9_MONTHS,
        )

        parole_board_permanent_decision_1 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry_1],
        )

        parole_board_decision_entry_2 = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_6_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_6_MONTHS,
        )

        parole_board_permanent_decision_2 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2019, month=12, day=30),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry_2],
        )

        (
            purpose_for_incarceration_subtype
        ) = us_pa_incarceration_period_pre_processing_delegate._most_severe_purpose_for_incarceration_subtype(
            [parole_board_permanent_decision_1, parole_board_permanent_decision_2]
        )

        self.assertEqual(
            SHOCK_INCARCERATION_9_MONTHS, purpose_for_incarceration_subtype
        )
    def test_revocation_type_and_subtype_shock_incarceration_RESCR12(self):
        parole_board_decision_entry = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_12_MONTHS,
            decision=StateSupervisionViolationResponseDecision.
            SHOCK_INCARCERATION,
            revocation_type=StateSupervisionViolationResponseRevocationType.
            SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_12_MONTHS,
        )

        parole_board_permanent_decision = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2018, month=5, day=16),
            response_type=StateSupervisionViolationResponseType.
            PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType
            .PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[
                parole_board_decision_entry
            ],
        )

        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=222,
            external_id="ip2",
            state_code=STATE_CODE,
            incarceration_type=StateIncarcerationType.COUNTY_JAIL,
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            admission_date=date(2018, 5, 19),
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PAROLE_REVOCATION,
            specialized_purpose_for_incarceration=
            StateSpecializedPurposeForIncarceration.SHOCK_INCARCERATION,
            # Program 46 indicates a revocation for a 6, 9 or 12 month stay
            specialized_purpose_for_incarceration_raw_text="CCIS-46",
            release_date=date(2019, 3, 3),
            release_reason=StateIncarcerationPeriodReleaseReason.
            SENTENCE_SERVED,
        )

        (
            revocation_type,
            revocation_type_subtype,
        ) = us_pa_revocation_utils.us_pa_revocation_type_and_subtype(
            incarceration_period, [parole_board_permanent_decision])

        self.assertEqual(
            StateSupervisionViolationResponseRevocationType.
            SHOCK_INCARCERATION,
            revocation_type,
        )
        self.assertEqual(SHOCK_INCARCERATION_12_MONTHS,
                         revocation_type_subtype)
    def test_pre_processed_incarceration_periods_shock_incarceration_RESCR(
        self,
    ) -> None:
        parole_board_decision_entry = StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
            state_code=STATE_CODE,
            decision_raw_text=SHOCK_INCARCERATION_UNDER_6_MONTHS,
            revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
            decision=StateSupervisionViolationResponseDecision.SHOCK_INCARCERATION,
            revocation_type_raw_text=SHOCK_INCARCERATION_UNDER_6_MONTHS,
        )

        parole_board_permanent_decision = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2018, month=5, day=16),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry],
        )

        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=222,
            external_id="ip2",
            state_code=STATE_CODE,
            incarceration_type=StateIncarcerationType.COUNTY_JAIL,
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            admission_date=date(2018, 5, 19),
            admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION,
            specialized_purpose_for_incarceration=StateSpecializedPurposeForIncarceration.SHOCK_INCARCERATION,
            # Program 46 indicates a commitment to a 6, 9 or 12 month stay
            specialized_purpose_for_incarceration_raw_text="CCIS-46",
            release_date=date(2019, 3, 3),
            release_reason=StateIncarcerationPeriodReleaseReason.SENTENCE_SERVED,
        )

        updated_period = attr.evolve(
            incarceration_period,
            admission_reason=StateIncarcerationPeriodAdmissionReason.SANCTION_ADMISSION,
        )

        expected_pfi_subtype = SHOCK_INCARCERATION_UNDER_6_MONTHS

        (
            validated_incarceration_periods,
            ip_id_to_pfi_subtype,
        ) = self._pre_processed_incarceration_periods_for_calculations(
            incarceration_periods=[incarceration_period],
            violation_responses=[parole_board_permanent_decision],
        )

        self.assertEqual([updated_period], validated_incarceration_periods)
        self.assertEqual(
            expected_pfi_subtype,
            ip_id_to_pfi_subtype[222],
        )
    def test_pre_processed_incarceration_periods_reincarceration(self) -> None:
        parole_board_decision_entry = (
            StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                state_code=STATE_CODE,
                decision_raw_text="XXX",
            )
        )

        parole_board_permanent_decision = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2018, month=5, day=16),
            response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[parole_board_decision_entry],
        )

        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=222,
            external_id="ip2",
            state_code=STATE_CODE,
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            admission_date=date(2018, 5, 19),
            admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION,
            specialized_purpose_for_incarceration=StateSpecializedPurposeForIncarceration.GENERAL,
            release_date=date(2019, 3, 3),
            release_reason=StateIncarcerationPeriodReleaseReason.SENTENCE_SERVED,
        )

        updated_period = attr.evolve(
            incarceration_period,
        )

        expected_pfi_subtype = None

        (
            validated_incarceration_periods,
            ip_id_to_pfi_subtype,
        ) = self._pre_processed_incarceration_periods_for_calculations(
            incarceration_periods=[incarceration_period],
            violation_responses=[parole_board_permanent_decision],
        )

        self.assertEqual([updated_period], validated_incarceration_periods)
        self.assertEqual(
            expected_pfi_subtype,
            ip_id_to_pfi_subtype[222],
        )
    def test_revocation_type_and_subtype_reincarceration(self):
        parole_board_decision_entry = (
            StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                state_code=STATE_CODE,
                revocation_type_raw_text="XXX",
            ))

        parole_board_permanent_decision = StateSupervisionViolationResponse.new_with_defaults(
            state_code=STATE_CODE,
            response_date=date(year=2018, month=5, day=16),
            response_type=StateSupervisionViolationResponseType.
            PERMANENT_DECISION,
            response_type_raw_text="PERMANENT_DECISION",
            deciding_body_type=StateSupervisionViolationResponseDecidingBodyType
            .PAROLE_BOARD,
            deciding_body_type_raw_text="PAROLE_BOARD",
            supervision_violation_response_decisions=[
                parole_board_decision_entry
            ],
        )

        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=222,
            external_id="ip2",
            state_code=STATE_CODE,
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            admission_date=date(2018, 5, 19),
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PAROLE_REVOCATION,
            specialized_purpose_for_incarceration=
            StateSpecializedPurposeForIncarceration.GENERAL,
            release_date=date(2019, 3, 3),
            release_reason=StateIncarcerationPeriodReleaseReason.
            SENTENCE_SERVED,
        )

        (
            revocation_type,
            revocation_type_subtype,
        ) = us_pa_revocation_utils.us_pa_revocation_type_and_subtype(
            incarceration_period, [parole_board_permanent_decision])

        self.assertEqual(
            StateSupervisionViolationResponseRevocationType.REINCARCERATION,
            revocation_type,
        )
        self.assertIsNone(revocation_type_subtype)
Exemple #16
0
    def test_get_violation_and_response_history_with_us_pa_subtype_multiple_types(self):
        supervision_violation_1 = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=12345,
            state_code="US_PA",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_PA",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text="M05",  # MED_TECH
                ),
            ],
        )

        supervision_violation_2 = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123456,
            state_code="US_PA",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_PA",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text="M05",  # MED_TECH
                ),
            ],
        )

        supervision_violation_3 = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=1234567,
            state_code="US_PA",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_PA",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text="M14",  # SUBSTANCE_ABUSE
                ),
            ],
        )

        supervision_violation_response_1 = StateSupervisionViolationResponse.new_with_defaults(
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
            state_code="US_PA",
            response_date=datetime.date(2009, 1, 7),
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_PA",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_PA",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                    revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
                ),
            ],
            supervision_violation=supervision_violation_1,
        )

        supervision_violation_response_2 = (
            StateSupervisionViolationResponse.new_with_defaults(
                supervision_violation_response_id=1234567,
                response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
                state_code="US_PA",
                response_date=datetime.date(2009, 1, 6),
                supervision_violation=supervision_violation_2,
            )
        )

        supervision_violation_response_3 = (
            StateSupervisionViolationResponse.new_with_defaults(
                supervision_violation_response_id=1234567,
                response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
                state_code="US_PA",
                response_date=datetime.date(2009, 1, 5),
                supervision_violation=supervision_violation_3,
            )
        )

        revocation_date = datetime.date(2009, 2, 13)

        violation_history = violation_utils.get_violation_and_response_history(
            revocation_date,
            [
                supervision_violation_response_3,
                supervision_violation_response_2,
                supervision_violation_response_1,
            ],
            UsPaViolationDelegate(),
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.TECHNICAL,
            most_severe_violation_type_subtype="SUBSTANCE_ABUSE",
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=3,
            violation_history_description="1subs;2med_tech",
            violation_type_frequency_counter=[
                ["SUBSTANCE_ABUSE"],
                ["MED_TECH"],
                ["MED_TECH"],
            ],
        )

        self.assertEqual(expected_output, violation_history)
Exemple #17
0
    def test_get_violation_and_response_history_outside_lookback(self):
        supervision_violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_XX",
            violation_date=datetime.date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                ),
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.FELONY,
                ),
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code="US_XX",
                    violation_type=StateSupervisionViolationType.ABSCONDED,
                ),
            ],
        )

        # This is outside of the lookback window
        supervision_violation_response_before_look_back = (
            StateSupervisionViolationResponse.new_with_defaults(
                supervision_violation_response_id=_DEFAULT_SSVR_ID,
                response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
                state_code="US_XX",
                response_date=datetime.date(2018, 7, 25),
            )
        )

        supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults(
            supervision_violation_response_id=_DEFAULT_SSVR_ID,
            response_type=StateSupervisionViolationResponseType.VIOLATION_REPORT,
            state_code="US_XX",
            response_date=datetime.date(2019, 1, 20),
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_XX",
                    decision=StateSupervisionViolationResponseDecision.REVOCATION,
                    revocation_type=StateSupervisionViolationResponseRevocationType.REINCARCERATION,
                ),
                StateSupervisionViolationResponseDecisionEntry.new_with_defaults(
                    state_code="US_XX",
                    decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
                    revocation_type=StateSupervisionViolationResponseRevocationType.SHOCK_INCARCERATION,
                ),
            ],
            supervision_violation=supervision_violation,
        )

        violation_responses = [
            supervision_violation_response_before_look_back,
            supervision_violation_response,
        ]

        end_date = datetime.date(2019, 9, 5)

        violation_history = violation_utils.get_violation_and_response_history(
            end_date, violation_responses, UsXxViolationDelegate()
        )

        expected_output = violation_utils.ViolationHistory(
            most_severe_violation_type=StateSupervisionViolationType.FELONY,
            most_severe_violation_type_subtype=StateSupervisionViolationType.FELONY.value,
            most_severe_response_decision=StateSupervisionViolationResponseDecision.REVOCATION,
            response_count=1,
            violation_history_description="1felony",
            violation_type_frequency_counter=[["TECHNICAL", "FELONY", "ABSCONDED"]],
        )

        self.assertEqual(expected_output, violation_history)