Example #1
0
 def testUsIdGetSupervisionPeriodAdmissionOverride_investigationTooFarBack(
     self,
 ) -> None:
     previous_termination_date = self.upper_bound_date - relativedelta(days=10)
     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=previous_termination_date,
         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=previous_termination_date
         + relativedelta(days=SUPERVISION_TYPE_LOOKBACK_DAYS_LIMIT + 1),
         supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.PAROLE,
         status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
     )
     idx = PreProcessedSupervisionPeriodIndex(
         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 _pre_processed_incarceration_periods_for_calculations(
        incarceration_periods: List[StateIncarcerationPeriod],
        supervision_periods: Optional[List[StateSupervisionPeriod]] = None,
        violation_responses: Optional[List[StateSupervisionViolationResponse]] = None,
        collapse_transfers: bool = True,
        overwrite_facility_information_in_transfers: bool = True,
        earliest_death_date: Optional[date] = None,
    ) -> Tuple[List[StateIncarcerationPeriod], Dict[int, Optional[str]]]:
        sp_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=supervision_periods or [],
        )

        violation_responses = violation_responses or []

        ip_pre_processing_manager = IncarcerationPreProcessingManager(
            incarceration_periods=incarceration_periods,
            delegate=UsPaIncarcerationPreProcessingDelegate(),
            pre_processed_supervision_period_index=sp_index,
            violation_responses=violation_responses,
            earliest_death_date=earliest_death_date,
        )

        ip_index = ip_pre_processing_manager.pre_processed_incarceration_period_index_for_calculations(
            collapse_transfers=collapse_transfers,
            overwrite_facility_information_in_transfers=overwrite_facility_information_in_transfers,
        )

        return ip_index.incarceration_periods, ip_index.ip_id_to_pfi_subtype
    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 = PreProcessedSupervisionPeriodIndex(
            supervision_periods=standard_date_sort_for_supervision_periods(
                supervision_periods))

        self.assertIsNone(
            supervision_period_index.
            get_most_recent_previous_supervision_period(supervision_period_1))
Example #4
0
 def testUsIdGetSupervisionPeriodAdmissionOverride_notPrecededByInvestigation(
     self,
 ) -> None:
     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 = PreProcessedSupervisionPeriodIndex(
         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)
Example #5
0
    def _pre_processed_incarceration_periods_for_calculations(
        incarceration_periods: List[StateIncarcerationPeriod],
        supervision_periods: Optional[List[StateSupervisionPeriod]] = None,
        collapse_transfers: bool = True,
        overwrite_facility_information_in_transfers: bool = True,
        earliest_death_date: Optional[date] = None,
    ) -> List[StateIncarcerationPeriod]:
        # IP pre-processing for US_ND does not rely on violation responses
        violation_responses: Optional[
            List[StateSupervisionViolationResponse]] = []

        sp_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=supervision_periods or [], )

        ip_pre_processing_manager = IncarcerationPreProcessingManager(
            incarceration_periods=incarceration_periods,
            delegate=UsNdIncarcerationPreProcessingDelegate(),
            pre_processed_supervision_period_index=sp_index,
            violation_responses=violation_responses,
            earliest_death_date=earliest_death_date,
        )

        return ip_pre_processing_manager.pre_processed_incarceration_period_index_for_calculations(
            collapse_transfers=collapse_transfers,
            overwrite_facility_information_in_transfers=
            overwrite_facility_information_in_transfers,
        ).incarceration_periods
Example #6
0
    def _test_us_nd_pre_commitment_supervision_period(
        admission_date: date,
        admission_reason: StateIncarcerationPeriodAdmissionReason,
        supervision_periods: List[StateSupervisionPeriod],
    ) -> Optional[StateSupervisionPeriod]:
        ip = StateIncarcerationPeriod.new_with_defaults(
            state_code="US_ND",
            incarceration_period_id=111,
            status=StateIncarcerationPeriodStatus.IN_CUSTODY,
            admission_date=admission_date,
            admission_reason=admission_reason,
        )

        incarceration_periods = [ip]

        return _get_commitment_from_supervision_supervision_period(
            incarceration_period=ip,
            commitment_from_supervision_delegate=
            UsNdCommitmentFromSupervisionDelegate(),
            supervision_period_index=PreProcessedSupervisionPeriodIndex(
                supervision_periods),
            incarceration_period_index=PreProcessedIncarcerationPeriodIndex(
                incarceration_periods=incarceration_periods,
                ip_id_to_pfi_subtype={
                    ip.incarceration_period_id: None
                    for ip in incarceration_periods
                    if ip.incarceration_period_id
                },
            ),
        )
Example #7
0
    def testUsIdGetSupervisionPeriodAdmissionReasonOverride_multiplePeriodsStartOnInvestigationEnd(
        self,
    ) -> None:
        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 = PreProcessedSupervisionPeriodIndex(
            supervision_periods=[
                supervision_period_previous,
                supervision_period_one_day,
                supervision_period_ongoing,
            ]
        )
        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_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 test_supervision_periods_by_termination_month_multiple_years(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(2020, 10, 3),
            termination_date=date(2020, 10, 11),
            admission_reason=StateSupervisionPeriodAdmissionReason.
            TRANSFER_WITHIN_STATE,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_periods = [supervision_period_2, supervision_period_1]

        supervision_period_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=standard_date_sort_for_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_no_official_admission(self):
        # The first supervision period always counts as the official start of supervision
        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.
            TRANSFER_WITHIN_STATE,
            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 = PreProcessedSupervisionPeriodIndex(
            supervision_periods=standard_date_sort_for_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,
        )
Example #13
0
    def _test_get_commitment_from_supervision_details(
        incarceration_period: StateIncarcerationPeriod,
        supervision_periods: Optional[List[StateSupervisionPeriod]] = None,
        incarceration_period_index: Optional[
            PreProcessedIncarcerationPeriodIndex] = None,
        supervision_period_to_agent_associations: Optional[Dict[int, Dict[
            Any, Any]]] = None,
    ):
        """Helper function for testing get_commitment_from_supervision_details."""
        supervision_period_to_agent_associations = (
            supervision_period_to_agent_associations
            or DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS)
        incarceration_period_index = (
            incarceration_period_index or PreProcessedIncarcerationPeriodIndex(
                incarceration_periods=[incarceration_period],
                ip_id_to_pfi_subtype=({
                    incarceration_period.incarceration_period_id:
                    None
                } if incarceration_period.incarceration_period_id else {}),
            ))

        supervision_period_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=(supervision_periods or []))

        return commitment_from_supervision_utils.get_commitment_from_supervision_details(
            incarceration_period=incarceration_period,
            incarceration_period_index=incarceration_period_index,
            supervision_period_index=supervision_period_index,
            # No state-agnostic tests require the sentences
            incarceration_sentences=[],
            supervision_sentences=[],
            commitment_from_supervision_delegate=
            UsXxCommitmentFromSupervisionDelegate(),
            supervision_period_to_agent_associations=
            supervision_period_to_agent_associations,
            state_specific_officer_and_location_info_from_supervision_period_fn
            =get_state_specific_supervising_officer_and_location_info_function(
                incarceration_period.state_code),
        )
    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,
        )
    def test_supervision_start_dates_by_period_id_multiple_official_admissions(
            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,
            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.
            DISCHARGE,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_period_3 = StateSupervisionPeriod.new_with_defaults(
            state_code="US_XX",
            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,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_period_4 = StateSupervisionPeriod.new_with_defaults(
            state_code="US_XX",
            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,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_periods = [
            supervision_period_2,
            supervision_period_4,
            supervision_period_3,
            supervision_period_1,
        ]

        supervision_period_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=standard_date_sort_for_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(
            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.DUAL,
            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.PROBATION,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        # Transferring from INVESTIGATION to INFORMAL_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.PAROLE,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_periods = [
            supervision_period_2,
            supervision_period_3,
            supervision_period_1,
        ]

        supervision_period_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=standard_date_sort_for_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_start_dates_by_period_id_multiple_absconsion_periods(
            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.
            ABSCONSION,
            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.ABSCONSION,
            termination_reason=StateSupervisionPeriodTerminationReason.
            RETURN_FROM_ABSCONSION,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        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.
            RETURN_FROM_ABSCONSION,
            termination_reason=StateSupervisionPeriodTerminationReason.
            ABSCONSION,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_period_4 = StateSupervisionPeriod.new_with_defaults(
            state_code="US_XX",
            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,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_periods = [
            supervision_period_2,
            supervision_period_4,
            supervision_period_3,
            supervision_period_1,
        ]

        supervision_period_index = PreProcessedSupervisionPeriodIndex(
            supervision_periods=standard_date_sort_for_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,
        )