def test_identify_most_severe_violation_type(self) -> None: violation = StateSupervisionViolation.new_with_defaults( state_code="US_XX", 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, ), ], ) ( most_severe_violation_type, most_severe_violation_type_subtype, ) = violation_utils.identify_most_severe_violation_type_and_subtype( [violation]) self.assertEqual(most_severe_violation_type, StateSupervisionViolationType.FELONY) self.assertEqual( most_severe_violation_type_subtype, StateSupervisionViolationType.FELONY.value, )
def get_revocation_details( incarceration_period: StateIncarcerationPeriod, supervision_period: Optional[StateSupervisionPeriod], violation_responses: List[StateSupervisionViolationResponse], supervision_period_to_agent_associations: Optional[Dict[int, Dict[Any, Any]]], ) -> RevocationDetails: """Identifies the attributes of the revocation return from the supervision period that was revoked, if available, or the |source_supervision_violation_response| on the |incarceration_period|, if it is available. """ source_violation_type = None supervising_officer_external_id = None level_1_supervision_location_external_id = None level_2_supervision_location_external_id = None if supervision_period and supervision_period_to_agent_associations: ( supervising_officer_external_id, level_1_supervision_location_external_id, level_2_supervision_location_external_id, ) = get_supervising_officer_and_location_info_from_supervision_period( supervision_period, supervision_period_to_agent_associations) source_violation_response = ( incarceration_period.source_supervision_violation_response) if source_violation_response: source_violation = source_violation_response.supervision_violation if source_violation: source_violation_type, _ = identify_most_severe_violation_type_and_subtype( [source_violation]) ( revocation_type, revocation_type_subtype, ) = state_specific_revocation_type_and_subtype( incarceration_period.state_code, incarceration_period, violation_responses, _identify_revocation_type_and_subtype, ) revocation_details_result = RevocationDetails( revocation_type, revocation_type_subtype, source_violation_type, supervising_officer_external_id, level_1_supervision_location_external_id, level_2_supervision_location_external_id, ) return revocation_details_result
def test_identify_most_severe_violation_type_test_all_types(self) -> None: for violation_type in StateSupervisionViolationType: violation = StateSupervisionViolation.new_with_defaults( state_code='US_XX', supervision_violation_types=[ StateSupervisionViolationTypeEntry.new_with_defaults( violation_type=violation_type) ]) most_severe_violation_type, most_severe_violation_type_subtype = \ violation_utils.identify_most_severe_violation_type_and_subtype([violation]) self.assertEqual(most_severe_violation_type, violation_type) self.assertEqual(violation_type.value, most_severe_violation_type_subtype)
def get_source_violation_type(source_supervision_violation_response: Optional[StateSupervisionViolationResponse]) \ -> Optional[StateSupervisionViolationType]: """Returns, where applicable, the type of violation that caused the period of incarceration. If the person returned from supervision, and we know the supervision violation response that caused the return, then this returns the type of violation that prompted this revocation. """ if source_supervision_violation_response: supervision_violation = source_supervision_violation_response.supervision_violation if supervision_violation: violation_type, _ = identify_most_severe_violation_type_and_subtype( [supervision_violation]) return violation_type return None