def test_us_nd_infer_supervision_period_previous_period_termination_reason_revocation( self, ) -> None: previous_supervision_period: StateSupervisionPeriod = ( StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", status=StateSupervisionPeriodStatus.UNDER_SUPERVISION, state_code="US_XX", supervising_officer="AGENTX", start_date=date(2018, 2, 20), termination_date=date(2018, 2, 22), termination_reason=StateSupervisionPeriodTerminationReason.REVOCATION, supervision_type=StateSupervisionType.PAROLE, ) ) current_supervision_period: StateSupervisionPeriod = ( StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", status=StateSupervisionPeriodStatus.UNDER_SUPERVISION, state_code="US_XX", supervising_officer="AGENTY", start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_type=StateSupervisionType.PAROLE, ) ) supervision_period_index = PreProcessedSupervisionPeriodIndex( supervision_periods=[ previous_supervision_period, current_supervision_period, ] ) incarceration_period_index = PreProcessedIncarcerationPeriodIndex( incarceration_periods=[], ip_id_to_pfi_subtype={}, ) admission_reason: Optional[ StateSupervisionPeriodAdmissionReason ] = us_nd_infer_supervision_period_admission( current_supervision_period, supervision_period_index, incarceration_period_index, ) self.assertEqual( admission_reason, StateSupervisionPeriodAdmissionReason.COURT_SENTENCE, )
def test_us_nd_infer_supervision_period_admission_return_from_absconsion( self, ) -> None: previous_supervision_period: StateSupervisionPeriod = ( StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", status=StateSupervisionPeriodStatus.UNDER_SUPERVISION, state_code="US_XX", start_date=date(2018, 2, 20), termination_date=date(2018, 2, 22), termination_reason=StateSupervisionPeriodTerminationReason.ABSCONSION, supervision_type=None, ) ) current_supervision_period: StateSupervisionPeriod = ( StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", status=StateSupervisionPeriodStatus.UNDER_SUPERVISION, state_code="US_XX", start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_type=None, ) ) supervision_period_index = PreProcessedSupervisionPeriodIndex( supervision_periods=[ previous_supervision_period, current_supervision_period, ] ) incarceration_period_index = PreProcessedIncarcerationPeriodIndex( incarceration_periods=[], ip_id_to_pfi_subtype={}, ) admission_reason: Optional[ StateSupervisionPeriodAdmissionReason ] = us_nd_infer_supervision_period_admission( current_supervision_period, supervision_period_index, incarceration_period_index, ) self.assertEqual( admission_reason, StateSupervisionPeriodAdmissionReason.RETURN_FROM_ABSCONSION, )
def test_us_nd_infer_supervision_period_admission_conditional_release(self) -> None: previous_incarceration_period: StateIncarcerationPeriod = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1112, external_id="2", incarceration_type=StateIncarcerationType.STATE_PRISON, status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY, state_code="US_ND", facility="PRISON", admission_date=date(2018, 2, 20), admission_reason=StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION, admission_reason_raw_text="Revocation", release_date=date(2018, 2, 21), release_reason=StateIncarcerationPeriodReleaseReason.CONDITIONAL_RELEASE, release_reason_raw_text="NOT A VALID RAW TEXT VALUE", ) current_supervision_period: StateSupervisionPeriod = ( StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", status=StateSupervisionPeriodStatus.UNDER_SUPERVISION, state_code="US_XX", start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_type=None, ) ) supervision_period_index = PreProcessedSupervisionPeriodIndex( supervision_periods=[current_supervision_period] ) incarceration_period_index = PreProcessedIncarcerationPeriodIndex( incarceration_periods=[previous_incarceration_period], ip_id_to_pfi_subtype={1112: None}, ) admission_reason: Optional[ StateSupervisionPeriodAdmissionReason ] = us_nd_infer_supervision_period_admission( current_supervision_period, supervision_period_index, incarceration_period_index, ) self.assertEqual( admission_reason, StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE )
def state_specific_supervision_admission_reason_override( state_code: str, supervision_period: StateSupervisionPeriod, supervision_period_index: PreProcessedSupervisionPeriodIndex, incarceration_period_index: PreProcessedIncarcerationPeriodIndex, ) -> Optional[StateSupervisionPeriodAdmissionReason]: if state_code == "US_ID": return us_id_get_supervision_period_admission_override( supervision_period=supervision_period, supervision_period_index=supervision_period_index, ) if state_code == "US_ND": return us_nd_infer_supervision_period_admission( supervision_period=supervision_period, supervision_period_index=supervision_period_index, incarceration_period_index=incarceration_period_index, ) return supervision_period.admission_reason
def test_us_nd_infer_supervision_period_admission_no_previous_period_parole( self, ) -> None: current_supervision_period: StateSupervisionPeriod = ( StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", status=StateSupervisionPeriodStatus.UNDER_SUPERVISION, state_code="US_XX", start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_type=StateSupervisionType.PAROLE, ) ) supervision_period_index = PreProcessedSupervisionPeriodIndex( supervision_periods=[ current_supervision_period, ] ) incarceration_period_index = PreProcessedIncarcerationPeriodIndex( incarceration_periods=[], ip_id_to_pfi_subtype={}, ) admission_reason: Optional[ StateSupervisionPeriodAdmissionReason ] = us_nd_infer_supervision_period_admission( current_supervision_period, supervision_period_index, incarceration_period_index, ) self.assertEqual( admission_reason, StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE, )