def testUsIdGetSupervisionPeriodAdmissionOverride_investigationTooFarBack( self): supervision_period_previous = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=1, start_date=self.upper_bound_date - relativedelta(days=100), termination_date=self.upper_bound_date - relativedelta(days=10), termination_reason=StateSupervisionPeriodTerminationReason. TRANSFER_WITHIN_STATE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.INVESTIGATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=2, admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, start_date=supervision_period_previous.termination_date + relativedelta(days=SUPERVISION_TYPE_LOOKBACK_DAYS_LIMIT + 1), supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PAROLE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) idx = SupervisionPeriodIndex(supervision_periods=[ supervision_period, supervision_period_previous ]) found_admission_reason = us_id_get_supervision_period_admission_override( supervision_period=supervision_period, supervision_period_index=idx) self.assertEqual(supervision_period.admission_reason, found_admission_reason)
def testUsIdGetSupervisionPeriodAdmissionOverride_notPrecededByInvestigation( self): supervision_period_previous = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=1, start_date=self.upper_bound_date - relativedelta(days=100), termination_date=self.upper_bound_date - relativedelta(days=10), termination_reason=StateSupervisionPeriodTerminationReason. TRANSFER_WITHIN_STATE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PAROLE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=2, admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, start_date=supervision_period_previous.termination_date, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PAROLE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) idx = SupervisionPeriodIndex(supervision_periods=[ supervision_period, supervision_period_previous ]) found_admission_reason = us_id_get_supervision_period_admission_override( supervision_period=supervision_period, supervision_period_index=idx) self.assertEqual(supervision_period.admission_reason, found_admission_reason)
def test_get_most_recent_previous_supervision_period_first_in_list(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 1), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=111, start_date=date(2010, 10, 1), termination_date=date(2010, 11, 1), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_periods = [supervision_period_1, supervision_period_2] supervision_period_index = SupervisionPeriodIndex( supervision_periods=supervision_periods) self.assertIsNone( supervision_period_index. get_most_recent_previous_supervision_period(supervision_period_1))
def test_supervision_periods_converter_sort_by_admission_reason_court( self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 1, 1), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=222, start_date=date(2000, 1, 1), termination_date=date(2000, 1, 1), admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex( supervision_periods=supervision_periods) sorted_supervision_periods = [ supervision_period_1, supervision_period_2 ] self.assertEqual(sorted_supervision_periods, supervision_period_index.supervision_periods)
def test_supervision_periods_converter_empty_termination_date(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 1, 1), status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=222, start_date=date(2000, 1, 1), status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex( supervision_periods=supervision_periods) sorted_supervision_periods = [ supervision_period_1, supervision_period_2 ] self.assertEqual(sorted_supervision_periods, supervision_period_index.supervision_periods)
def test_supervision_start_dates_by_period_id_no_official_admission(self): # The first supervision period always counts as the official start of supervision supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) expected_output = { supervision_period_1.supervision_period_id: supervision_period_1.start_date, supervision_period_2.supervision_period_id: supervision_period_1.start_date } self.assertEqual(expected_output, supervision_period_index.supervision_start_dates_by_period_id)
def test_supervision_periods_by_termination_month_multiple_years(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 5, 3), admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2020, 10, 3), termination_date=date(2020, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) expected_output = { 2000: { 5: [supervision_period_1] }, 2020: { 10: [supervision_period_2] } } self.assertEqual(expected_output, supervision_period_index.supervision_periods_by_termination_month)
def test_supervision_start_dates_by_period_id(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) expected_output = { supervision_period_1.supervision_period_id: supervision_period_1.start_date, supervision_period_2.supervision_period_id: supervision_period_1.start_date } self.assertEqual(expected_output, supervision_period_index.supervision_start_dates_by_period_id)
def testUsIdGetSupervisionPeriodAdmissionReasonOverride_multiplePeriodsStartOnInvestigationEnd( self, ): supervision_period_previous = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=1, start_date=self.upper_bound_date - relativedelta(days=100), termination_date=self.upper_bound_date - relativedelta(days=10), termination_reason=StateSupervisionPeriodTerminationReason. TRANSFER_WITHIN_STATE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.INVESTIGATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_one_day = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=2, admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, start_date=supervision_period_previous.termination_date, termination_date=supervision_period_previous.termination_date, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.INFORMAL_PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_ongoing = StateSupervisionPeriod.new_with_defaults( state_code="US_ID", supervision_period_id=3, admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, start_date=supervision_period_one_day.termination_date, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PAROLE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) idx = SupervisionPeriodIndex(supervision_periods=[ supervision_period_previous, supervision_period_ongoing, supervision_period_one_day, ]) found_admission_reason_for_one_day = ( us_id_get_supervision_period_admission_override( supervision_period=supervision_period_one_day, supervision_period_index=idx, )) self.assertEqual( StateSupervisionPeriodAdmissionReason.COURT_SENTENCE, found_admission_reason_for_one_day, ) found_admission_reason_for_ongoing = ( us_id_get_supervision_period_admission_override( supervision_period=supervision_period_ongoing, supervision_period_index=idx, )) self.assertEqual( supervision_period_ongoing.admission_reason, found_admission_reason_for_ongoing, )
def test_supervision_start_dates_by_period_id_multiple_absconsion_periods(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE, termination_reason=StateSupervisionPeriodTerminationReason.ABSCONSION ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.ABSCONSION, termination_reason=StateSupervisionPeriodTerminationReason.RETURN_FROM_ABSCONSION ) supervision_period_3 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=333, start_date=date(2000, 10, 12), termination_date=date(2001, 1, 3), admission_reason=StateSupervisionPeriodAdmissionReason.RETURN_FROM_ABSCONSION, termination_reason=StateSupervisionPeriodTerminationReason.ABSCONSION ) supervision_period_4 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=444, start_date=date(2001, 1, 4), termination_date=date(2001, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.ABSCONSION, termination_reason=StateSupervisionPeriodTerminationReason.RETURN_FROM_ABSCONSION ) supervision_periods = [supervision_period_2, supervision_period_4, supervision_period_3, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) expected_output = { supervision_period_1.supervision_period_id: supervision_period_1.start_date, supervision_period_2.supervision_period_id: supervision_period_1.start_date, supervision_period_3.supervision_period_id: supervision_period_1.start_date, supervision_period_4.supervision_period_id: supervision_period_1.start_date } self.assertEqual(expected_output, supervision_period_index.supervision_start_dates_by_period_id)
def test_supervision_start_dates_by_period_id_multiple_official_admissions(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE, termination_reason=StateSupervisionPeriodTerminationReason.TRANSFER_WITHIN_STATE ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE, termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE ) supervision_period_3 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=333, start_date=date(2020, 5, 1), termination_date=date(2020, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason.COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason.TRANSFER_WITHIN_STATE ) supervision_period_4 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=444, start_date=date(2020, 10, 3), termination_date=date(2020, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE, termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE ) supervision_periods = [supervision_period_2, supervision_period_4, supervision_period_3, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) expected_output = { supervision_period_1.supervision_period_id: supervision_period_1.start_date, supervision_period_2.supervision_period_id: supervision_period_1.start_date, supervision_period_3.supervision_period_id: supervision_period_3.start_date, supervision_period_4.supervision_period_id: supervision_period_3.start_date } self.assertEqual(expected_output, supervision_period_index.supervision_start_dates_by_period_id)
def test_supervision_start_dates_by_period_id_not_official_transfer_admissions(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE, termination_reason=StateSupervisionPeriodTerminationReason.TRANSFER_WITHIN_STATE, supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.DUAL ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE, termination_reason=StateSupervisionPeriodTerminationReason.TRANSFER_WITHIN_STATE, supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.PROBATION ) # Transferring from INVESTIGATION to INFORMAL_PROBATION is a new official start of supervision supervision_period_3 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=333, start_date=date(2000, 10, 12), termination_date=date(2001, 1, 3), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE, termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.PAROLE ) supervision_periods = [supervision_period_2, supervision_period_3, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) expected_output = { supervision_period_1.supervision_period_id: supervision_period_1.start_date, supervision_period_2.supervision_period_id: supervision_period_1.start_date, supervision_period_3.supervision_period_id: supervision_period_1.start_date, } self.assertEqual(expected_output, supervision_period_index.supervision_start_dates_by_period_id)
def test_supervision_periods_converter_sort_by_admission_reason_conditional_release(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 1, 1), admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 1, 1), termination_date=date(2000, 1, 1), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) sorted_supervision_periods = [supervision_period_1, supervision_period_2] self.assertEqual(sorted_supervision_periods, supervision_period_index.supervision_periods)
def test_supervision_periods_converter(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 1), admission_reason=StateSupervisionPeriodAdmissionReason.COURT_SENTENCE ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( supervision_period_id=222, start_date=date(2000, 10, 1), termination_date=date(2003, 3, 1), admission_reason=StateSupervisionPeriodAdmissionReason.TRANSFER_WITHIN_STATE ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex(supervision_periods=supervision_periods) sorted_supervision_periods = [supervision_period_1, supervision_period_2] self.assertEqual(sorted_supervision_periods, supervision_period_index.supervision_periods)
def test_supervision_periods_by_termination_month_multiple_months(self): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 5, 3), admission_reason=StateSupervisionPeriodAdmissionReason. CONDITIONAL_RELEASE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_periods = [supervision_period_2, supervision_period_1] supervision_period_index = SupervisionPeriodIndex( supervision_periods=supervision_periods) expected_output = { 2000: { 5: [supervision_period_1], 10: [supervision_period_2] } } self.assertEqual( expected_output, supervision_period_index.supervision_periods_by_termination_month, )
def test_supervision_start_dates_by_period_id_official_transfer_admission_informal_probation( self, ): supervision_period_1 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=111, start_date=date(2000, 1, 1), termination_date=date(2000, 10, 3), admission_reason=StateSupervisionPeriodAdmissionReason. CONDITIONAL_RELEASE, termination_reason=StateSupervisionPeriodTerminationReason. TRANSFER_WITHIN_STATE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.INFORMAL_PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_period_2 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=222, start_date=date(2000, 10, 3), termination_date=date(2000, 10, 11), admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, termination_reason=StateSupervisionPeriodTerminationReason. TRANSFER_WITHIN_STATE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.INFORMAL_PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) # Transferring from INFORMAL_PROBATION to PROBATION is a new official start of supervision supervision_period_3 = StateSupervisionPeriod.new_with_defaults( state_code="US_XX", supervision_period_id=333, start_date=date(2000, 10, 12), termination_date=date(2001, 1, 3), admission_reason=StateSupervisionPeriodAdmissionReason. TRANSFER_WITHIN_STATE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_periods = [ supervision_period_2, supervision_period_3, supervision_period_1, ] supervision_period_index = SupervisionPeriodIndex( supervision_periods=supervision_periods) expected_output = { supervision_period_1.supervision_period_id: supervision_period_1.start_date, supervision_period_2.supervision_period_id: supervision_period_1.start_date, supervision_period_3.supervision_period_id: supervision_period_3.start_date, } self.assertEqual( expected_output, supervision_period_index.supervision_start_dates_by_period_id, )