Beispiel #1
0
def find_program_events(
    program_assignments: List[StateProgramAssignment],
    assessments: List[StateAssessment],
    supervision_periods: List[StateSupervisionPeriod],
    supervision_period_to_agent_association: List[Dict[str, Any]],
) -> List[ProgramEvent]:
    """Finds instances of interaction with a program.

    Identifies instances of being referred to a program and actively participating in a program.

    Args:
        - program_assignments: All of the person's StateProgramAssignments
        - assessments: All of the person's recorded StateAssessments
        - supervision_periods: All of the person's supervision_periods
        - supervision_period_to_agent_associations: dictionary associating StateSupervisionPeriod ids to information
            about the corresponding StateAgent

    Returns:
        A list of ProgramEvents for the person.
    """
    # TODO(#2855): Bring in supervision and incarceration sentences to infer the supervision type on supervision
    #  periods that don't have a set supervision type
    program_events: List[ProgramEvent] = []

    if not program_assignments:
        return program_events

    supervision_period_to_agent_associations = list_of_dicts_to_dict_with_keys(
        supervision_period_to_agent_association,
        StateSupervisionPeriod.get_class_id_name(),
    )

    state_code = get_single_state_code(program_assignments)

    should_drop_federal_and_other_country = (
        filter_out_federal_and_other_country_supervision_periods(state_code)
    )

    supervision_periods = prepare_supervision_periods_for_calculations(
        supervision_periods,
        drop_federal_and_other_country_supervision_periods=should_drop_federal_and_other_country,
    )

    for program_assignment in program_assignments:
        program_referrals = find_program_referrals(
            program_assignment,
            assessments,
            supervision_periods,
            supervision_period_to_agent_associations,
        )

        program_events.extend(program_referrals)

        program_participation_events = find_program_participation_events(
            program_assignment, supervision_periods
        )

        program_events.extend(program_participation_events)

    return program_events
    def test_prepare_supervision_periods_for_calculations_unset_future_release_dates(
        self, ):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            status=StateSupervisionPeriodStatus.UNDER_SUPERVISION,
            state_code="US_ND",
            start_date=date(1990, 1, 1),
            termination_date=date(2007, 12, 31),
            termination_reason=StateSupervisionPeriodTerminationReason.
            DISCHARGE,
        )

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_federal_and_other_country_supervision_periods=False,
        )

        updated_period = StateSupervisionPeriod.new_with_defaults(
            status=StateSupervisionPeriodStatus.UNDER_SUPERVISION,
            state_code="US_ND",
            start_date=date(1990, 1, 1),
            admission_reason=StateSupervisionPeriodAdmissionReason.
            INTERNAL_UNKNOWN,
            termination_date=None,
            termination_reason=None,
        )

        self.assertEqual([updated_period], updated_periods)
Beispiel #3
0
    def test_prepare_supervision_periods_for_calculations_placeholder(self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            state_code='US_XX',
        )

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_non_state_custodial_authority_periods=False)
        self.assertEqual([], updated_periods)
Beispiel #4
0
    def test_prepare_supervision_periods_for_calculations(self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            state_code='US_ND',
            start_date=date(2006, 1, 1),
            termination_date=date(2007, 12, 31))

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_non_state_custodial_authority_periods=False)

        self.assertEqual([supervision_period], updated_periods)
Beispiel #5
0
    def test_prepare_supervision_periods_for_calculations_usID_unsetType(self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            state_code='US_ID',
            start_date=date(2006, 1, 1),
            termination_date=date(2007, 12, 31),
            custodial_authority='US_ID_DOC',
            supervision_period_supervision_type=None)

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_non_state_custodial_authority_periods=True)
        self.assertEqual([supervision_period], updated_periods)
    def test_prepare_supervision_periods_for_calculations_placeholder(self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            state_code="US_XX",
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_federal_and_other_country_supervision_periods=False,
        )
        self.assertEqual([], updated_periods)
Beispiel #7
0
def find_program_events(
    program_assignments: List[StateProgramAssignment],
    assessments: List[StateAssessment],
    supervision_periods: List[StateSupervisionPeriod],
    supervision_period_to_agent_associations: Dict[int, Dict[Any, Any]]
) -> List[ProgramEvent]:
    """Finds instances of interaction with a program.

    Identifies instances of being referred to a program and actively participating in a program.

    Args:
        - program_assignments: All of the person's StateProgramAssignments
        - assessments: All of the person's recorded StateAssessments
        - supervision_periods: All of the person's supervision_periods
        - supervision_period_to_agent_associations: dictionary associating StateSupervisionPeriod ids to information
            about the corresponding StateAgent

    Returns:
        A list of ProgramEvents for the person.
    """
    # TODO(#2855): Bring in supervision and incarceration sentences to infer the supervision type on supervision
    #  periods that don't have a set supervision type
    program_events: List[ProgramEvent] = []

    if not program_assignments:
        return program_events

    state_code = get_single_state_code(program_assignments)

    should_drop_non_state_custodial_authority_periods = \
        only_state_custodial_authority_in_supervision_population(state_code)

    supervision_periods = prepare_supervision_periods_for_calculations(
        supervision_periods,
        drop_non_state_custodial_authority_periods=
        should_drop_non_state_custodial_authority_periods)

    for program_assignment in program_assignments:
        program_referrals = find_program_referrals(
            program_assignment, assessments, supervision_periods,
            supervision_period_to_agent_associations)

        program_events.extend(program_referrals)

        program_participation_events = find_program_participation_events(
            program_assignment, supervision_periods)

        program_events.extend(program_participation_events)

    return program_events
Beispiel #8
0
    def test_prepare_supervision_periods_for_calculations_usID_dropNonDOC(
            self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            state_code='US_ID',
            start_date=date(2006, 1, 1),
            termination_date=date(2007, 12, 31),
            custodial_authority='ALABAMA',  # Not the state's DOC authority
            supervision_period_supervision_type=
            StateSupervisionPeriodSupervisionType.PROBATION)

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_non_state_custodial_authority_periods=True)
        self.assertEqual([], updated_periods)
    def test_prepare_supervision_periods_for_calculations(self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            state_code="US_ND",
            start_date=date(2006, 1, 1),
            termination_date=date(2007, 12, 31),
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_federal_and_other_country_supervision_periods=False,
        )

        self.assertEqual([supervision_period], updated_periods)
    def test_prepare_supervision_periods_for_calculations_usID_drop_other_country(
            self):
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            state_code="US_ID",
            start_date=date(2006, 1, 1),
            termination_date=date(2007, 12, 31),
            custodial_authority=StateCustodialAuthority.
            OTHER_COUNTRY,  # Not the state's authority
            supervision_period_supervision_type=
            StateSupervisionPeriodSupervisionType.PROBATION,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        updated_periods = prepare_supervision_periods_for_calculations(
            [supervision_period],
            drop_federal_and_other_country_supervision_periods=True,
        )

        self.assertEqual([], updated_periods)