コード例 #1
0
    def test_associateSvrsWithIps_dontAssociateTheSameSvr(self):
        # Arrange
        svr_1 = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_1,
            revocation_type=StateSupervisionViolationResponseRevocationType.
            REINCARCERATION)
        placeholder_sv = StateSupervisionViolation.new_with_defaults(
            supervision_violation_responses=[svr_1])
        placeholder_sp = StateSupervisionPeriod.new_with_defaults(
            supervision_violation_entries=[placeholder_sv])
        placeholder_ss = StateSupervisionSentence.new_with_defaults(
            supervision_periods=[placeholder_sp])

        ip_1 = StateIncarcerationPeriod.new_with_defaults(
            admission_date=_DATE_2,
            admission_reason=
            StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION)
        ip_2 = StateIncarcerationPeriod.new_with_defaults(
            admission_date=_DATE_4,
            admission_reason=
            StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION)
        placeholder_is = StateIncarcerationSentence.new_with_defaults(
            incarceration_periods=[ip_1, ip_2])
        placeholder_sg = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[placeholder_is],
            supervision_sentences=[placeholder_ss])
        placeholder_person = StatePerson.new_with_defaults(
            sentence_groups=[placeholder_sg])

        expected_svr_1 = attr.evolve(svr_1)
        expected_placeholder_sv = attr.evolve(
            placeholder_sv,
            supervision_violation_responses=[expected_svr_1])
        expected_placeholder_sp = attr.evolve(
            placeholder_sp,
            supervision_violation_entries=[expected_placeholder_sv])
        expected_placeholder_ss = attr.evolve(
            placeholder_ss, supervision_periods=[expected_placeholder_sp])

        expected_ip_1 = attr.evolve(
            ip_1, source_supervision_violation_response=expected_svr_1)
        expected_ip_2 = attr.evolve(ip_2)

        expected_placeholder_is = attr.evolve(
            placeholder_is,
            incarceration_periods=[expected_ip_1, expected_ip_2])
        expected_placeholder_sg = attr.evolve(
            placeholder_sg,
            supervision_sentences=[expected_placeholder_ss],
            incarceration_sentences=[expected_placeholder_is])
        expected_placeholder_person = attr.evolve(
            placeholder_person, sentence_groups=[expected_placeholder_sg])

        # Act
        input_people = \
            converter.convert_entity_people_to_schema_people(
                [placeholder_person])
        associate_revocation_svrs_with_ips(input_people)

        # Assert
        self.assert_people_match(
            [expected_placeholder_person],
            input_people)
コード例 #2
0
    def test_moveIncidentsOntoPeriods(self):
        merged_incarceration_period_1 = \
            StateIncarcerationPeriod.new_with_defaults(
                external_id=_EXTERNAL_ID + '|' + _EXTERNAL_ID_2,
                status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
                facility=_FACILITY, admission_date=_DATE_1,
                admission_reason=
                StateIncarcerationPeriodAdmissionReason.NEW_ADMISSION,
                release_date=_DATE_3,
                release_reason=StateIncarcerationPeriodReleaseReason.TRANSFER)
        merged_incarceration_period_2 = \
            StateIncarcerationPeriod.new_with_defaults(
                external_id=_EXTERNAL_ID_3 + '|' + _EXTERNAL_ID_4,
                status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
                facility=_FACILITY_2, admission_date=_DATE_3,
                admission_reason=
                StateIncarcerationPeriodAdmissionReason.TRANSFER,
                release_date=_DATE_5,
                release_reason=StateIncarcerationPeriodReleaseReason.TRANSFER)
        unmerged_incarceration_period = \
            StateIncarcerationPeriod.new_with_defaults(
                external_id=_EXTERNAL_ID_5,
                status=StateIncarcerationPeriodStatus.IN_CUSTODY,
                facility=_FACILITY_3, admission_date=_DATE_5,
                admission_reason=
                StateIncarcerationPeriodAdmissionReason.TRANSFER)

        incident_1 = StateIncarcerationIncident.new_with_defaults(
            external_id=_EXTERNAL_ID, facility=_FACILITY, incident_date=_DATE_2)
        incident_2 = StateIncarcerationIncident.new_with_defaults(
            external_id=_EXTERNAL_ID_2, facility=_FACILITY_2,
            incident_date=_DATE_4)
        incident_3 = StateIncarcerationIncident.new_with_defaults(
            external_id=_EXTERNAL_ID_3, facility=_FACILITY_4,
            incident_date=_DATE_7)
        placeholder_incarceration_period = \
            StateIncarcerationPeriod.new_with_defaults(
                incarceration_incidents=[incident_1, incident_2, incident_3])

        incarceration_sentence = StateIncarcerationSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            incarceration_periods=[
                merged_incarceration_period_1,
                merged_incarceration_period_2,
                unmerged_incarceration_period])
        placeholder_incarceration_sentence = \
            StateIncarcerationSentence.new_with_defaults(
                external_id=_EXTERNAL_ID_2,
                incarceration_periods=[placeholder_incarceration_period])
        sentence_group = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[incarceration_sentence,
                                     placeholder_incarceration_sentence])

        person = StatePerson.new_with_defaults(sentence_groups=[sentence_group])

        expected_merged_period = attr.evolve(
            merged_incarceration_period_1, incarceration_incidents=[incident_1])
        expected_merged_period_2 = attr.evolve(
            merged_incarceration_period_2, incarceration_incidents=[incident_2])
        expected_unmerged_period = attr.evolve(unmerged_incarceration_period)
        expected_placeholder_period = attr.evolve(
            placeholder_incarceration_period,
            incarceration_incidents=[incident_3])
        expected_sentence = attr.evolve(
            incarceration_sentence,
            incarceration_periods=[
                expected_merged_period,
                expected_merged_period_2,
                expected_unmerged_period])
        expected_placeholder_sentence = attr.evolve(
            placeholder_incarceration_sentence,
            incarceration_periods=[expected_placeholder_period])
        expected_sentence_group = attr.evolve(
            sentence_group, incarceration_sentences=[
                expected_sentence, expected_placeholder_sentence])
        expected_person = attr.evolve(
            person, sentence_groups=[expected_sentence_group])

        move_incidents_onto_periods([person])
        self.assertEqual(expected_person, person)
コード例 #3
0
    def test_associateSvrsWithIps_onlyRevocationTypes(self):
        # Arrange
        svr_1 = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_1,
            revocation_type=StateSupervisionViolationResponseRevocationType.
            REINCARCERATION)
        svr_2 = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_3,
            revocation_type=StateSupervisionViolationResponseRevocationType.
            RETURN_TO_SUPERVISION)
        placeholder_sv = StateSupervisionViolation.new_with_defaults(
            supervision_violation_responses=[svr_1, svr_2])
        placeholder_sp = StateSupervisionPeriod.new_with_defaults(
            supervision_violations=[placeholder_sv])
        placeholder_ss = StateSupervisionSentence.new_with_defaults(
            supervision_periods=[placeholder_sp])

        ip_1 = StateIncarcerationPeriod.new_with_defaults(
            admission_date=_DATE_2,
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            NEW_ADMISSION)
        ip_2 = StateIncarcerationPeriod.new_with_defaults(
            admission_date=_DATE_4,
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PROBATION_REVOCATION)
        placeholder_is = StateIncarcerationSentence.new_with_defaults(
            incarceration_periods=[ip_1, ip_2])
        placeholder_sg = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[placeholder_is],
            supervision_sentences=[placeholder_ss])
        placeholder_person = StatePerson.new_with_defaults(
            sentence_groups=[placeholder_sg])

        expected_svr_1 = attr.evolve(svr_1)
        expected_svr_2 = attr.evolve(svr_2)
        expected_placeholder_sv = attr.evolve(
            placeholder_sv,
            supervision_violation_responses=[expected_svr_1, expected_svr_2])
        expected_placeholder_sp = attr.evolve(
            placeholder_sp, supervision_violations=[expected_placeholder_sv])
        expected_placeholder_ss = attr.evolve(
            placeholder_ss, supervision_periods=[expected_placeholder_sp])

        expected_ip_1 = attr.evolve(ip_1)
        expected_ip_2 = attr.evolve(
            ip_2, source_supervision_violation_response=svr_1)

        expected_placeholder_is = attr.evolve(
            placeholder_is,
            incarceration_periods=[expected_ip_1, expected_ip_2])
        expected_placeholder_sg = attr.evolve(
            placeholder_sg,
            supervision_sentences=[expected_placeholder_ss],
            incarceration_sentences=[expected_placeholder_is])
        expected_placeholder_person = attr.evolve(
            placeholder_person, sentence_groups=[expected_placeholder_sg])

        # Act
        associate_revocation_svrs_with_ips([placeholder_person])

        # Assert
        self.assertEqual(expected_placeholder_person, placeholder_person)
コード例 #4
0
    def test_associateSvrsWithIps(self):
        # Arrange
        ip_1 = StateIncarcerationPeriod.new_with_defaults(
            admission_date=_DATE_1,
            admission_reason=
            StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION)
        ip_2 = StateIncarcerationPeriod.new_with_defaults(
            admission_date=_DATE_2,
            admission_reason=
            StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION)
        placeholder_is = StateIncarcerationSentence.new_with_defaults(
            incarceration_periods=[ip_1, ip_2])

        svr_1 = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_1 - datetime.timedelta(days=1),
            revocation_type=StateSupervisionViolationResponseRevocationType.
            REINCARCERATION)
        svr_2 = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_2 + datetime.timedelta(days=1),
            revocation_type=StateSupervisionViolationResponseRevocationType.
            REINCARCERATION)
        svr_3 = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_2 + datetime.timedelta(days=30),
            revocation_type=StateSupervisionViolationResponseRevocationType.
            RETURN_TO_SUPERVISION)
        placeholder_sv = StateSupervisionViolation.new_with_defaults(
            supervision_violation_responses=[svr_1, svr_2, svr_3])
        placeholder_sp = StateSupervisionPeriod.new_with_defaults(
            supervision_violation_entries=[placeholder_sv])
        placeholder_ss = StateSupervisionSentence.new_with_defaults(
            supervision_periods=[placeholder_sp])

        placeholder_sg = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[placeholder_is],
            supervision_sentences=[placeholder_ss])
        placeholder_person = StatePerson.new_with_defaults(
            sentence_groups=[placeholder_sg])

        external_id = StatePersonExternalId.new_with_defaults(
            external_id=_EXTERNAL_ID)
        person_without_revocation = StatePerson.new_with_defaults(
            external_ids=[external_id])

        expected_svr_1 = attr.evolve(svr_1)
        expected_svr_2 = attr.evolve(svr_2)
        expected_svr_3 = attr.evolve(svr_3)
        expected_placeholder_sv = attr.evolve(
            placeholder_sv,
            supervision_violation_responses=[expected_svr_1, expected_svr_2,
                                             expected_svr_3])
        expected_placeholder_sp = attr.evolve(
            placeholder_sp,
            supervision_violation_entries=[expected_placeholder_sv])
        expected_placeholder_ss = attr.evolve(
            placeholder_ss, supervision_periods=[expected_placeholder_sp])

        expected_ip_1 = attr.evolve(
            ip_1, source_supervision_violation_response=expected_svr_1)
        expected_ip_2 = attr.evolve(
            ip_2, source_supervision_violation_response=expected_svr_2)

        expected_placeholder_is = attr.evolve(
            placeholder_is,
            incarceration_periods=[expected_ip_1, expected_ip_2])
        expected_placeholder_sg = attr.evolve(
            placeholder_sg,
            supervision_sentences=[expected_placeholder_ss],
            incarceration_sentences=[expected_placeholder_is])
        expected_placeholder_person = attr.evolve(
            placeholder_person, sentence_groups=[expected_placeholder_sg])
        expected_person_without_revocation = attr.evolve(
            person_without_revocation)

        # Act
        input_people = \
            converter.convert_entity_people_to_schema_people(
                [person_without_revocation, placeholder_person])
        associate_revocation_svrs_with_ips(input_people)

        # Assert
        self.assert_people_match(
            [expected_person_without_revocation, expected_placeholder_person],
            input_people)
コード例 #5
0
    def test_get_month_supervision_type_dual(self) -> None:
        # Arrange
        supervision_start = self.end_of_month_date - datetime.timedelta(days=60)
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=1234,
            external_id="sp1",
            state_code="US_MO",
            start_date=supervision_start,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        incarceration_sentence = (
            FakeUsMoIncarcerationSentence.fake_sentence_from_sentence(
                StateIncarcerationSentence.new_with_defaults(
                    external_id="ss1",
                    state_code="US_MO",
                    start_date=supervision_start,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=supervision_start,
                        end_date=self.start_of_next_month_date,
                        supervision_type=StateSupervisionType.PAROLE,
                    ),
                    SupervisionTypeSpan(
                        start_date=self.start_of_next_month_date,
                        end_date=None,
                        supervision_type=None,
                    ),
                ],
            )
        )

        supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
            StateSupervisionSentence.new_with_defaults(
                external_id="ss1",
                state_code="US_MO",
                start_date=supervision_start,
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            ),
            supervision_type_spans=[
                SupervisionTypeSpan(
                    start_date=supervision_start,
                    end_date=self.start_of_next_month_date,
                    supervision_type=StateSupervisionType.PROBATION,
                ),
                SupervisionTypeSpan(
                    start_date=self.start_of_next_month_date,
                    end_date=None,
                    supervision_type=None,
                ),
            ],
        )

        # Act
        supervision_period_supervision_type = us_mo_get_month_supervision_type(
            self.end_of_month_date,
            supervision_sentences=[supervision_sentence],
            incarceration_sentences=[incarceration_sentence],
            supervision_period=supervision_period,
        )

        # Assert
        self.assertEqual(
            supervision_period_supervision_type,
            StateSupervisionPeriodSupervisionType.DUAL,
        )
コード例 #6
0
    def test_usMo_getPreIncarcerationSupervisionType_ignoreOutOfDateSentences(
        self,
    ) -> None:
        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=1,
            admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION,
            external_id="ip1",
            state_code="US_MO",
            admission_date=datetime.date(year=2019, month=9, day=13),
            status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        supervision_sentence_parole = (
            FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
                StateSupervisionSentence.new_with_defaults(
                    state_code="US_MO",
                    supervision_sentence_id=1,
                    external_id="1167633-20171012-2",
                    start_date=datetime.date(2017, 2, 1),
                    supervision_type=StateSupervisionType.PROBATION,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=datetime.date(2017, 2, 1),
                        end_date=None,
                        supervision_type=StateSupervisionType.PAROLE,
                    )
                ],
            )
        )

        old_incarceration_sentence = (
            FakeUsMoIncarcerationSentence.fake_sentence_from_sentence(
                StateIncarcerationSentence.new_with_defaults(
                    state_code="US_MO",
                    incarceration_sentence_id=1,
                    external_id="is1",
                    start_date=datetime.date(2017, 2, 1),
                    completion_date=datetime.date(2017, 3, 4),
                    status=StateSentenceStatus.COMPLETED,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=datetime.date(2017, 2, 1),
                        end_date=datetime.date(2017, 3, 4),
                        supervision_type=StateSupervisionType.PAROLE,
                    ),
                    SupervisionTypeSpan(
                        start_date=datetime.date(2017, 3, 4),
                        end_date=None,
                        supervision_type=None,
                    ),
                ],  # Terminated by revocation date
            )
        )

        self.assertEqual(
            StateSupervisionPeriodSupervisionType.PAROLE,
            us_mo_get_pre_incarceration_supervision_type(
                [old_incarceration_sentence],
                [supervision_sentence_parole],
                incarceration_period,
            ),
        )
コード例 #7
0
    def test_associatedPeriodsWithSentences(self):
        # Arrange
        sp_no_match = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID,
            start_date=_DATE_1,
            termination_date=_DATE_3)

        sp_1 = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID,
            start_date=_DATE_4,
            termination_date=_DATE_6)

        sp_2 = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_2,
            start_date=_DATE_6,
            termination_date=None)

        ip_1 = StateIncarcerationPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID,
            admission_date=_DATE_6,
            release_date=None)

        placeholder_ss = StateSupervisionSentence.new_with_defaults(
            supervision_periods=[sp_no_match, sp_1, sp_2],
            incarceration_periods=[ip_1])

        ss = StateSupervisionSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            start_date=_DATE_4,
            completion_date=None,
            status=StateSentenceStatus.SERVING)
        inc_s = StateIncarcerationSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            start_date=_DATE_3,
            completion_date=_DATE_5,
            status=StateSentenceStatus.COMPLETED)

        sg = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[inc_s],
            supervision_sentences=[ss, placeholder_ss])

        state_person = StatePerson.new_with_defaults(sentence_groups=[sg])

        expected_sp_no_match = attr.evolve(sp_no_match)
        expected_sp_1 = attr.evolve(sp_1)
        expected_sp_2 = attr.evolve(sp_2)
        expected_ip_1 = attr.evolve(ip_1)

        expected_placeholder_ss = attr.evolve(
            placeholder_ss,
            supervision_periods=[expected_sp_no_match],
            incarceration_periods=[])
        expected_inc_s = attr.evolve(inc_s,
                                     supervision_periods=[expected_sp_1],
                                     incarceration_periods=[])
        expected_ss = attr.evolve(
            ss,
            incarceration_periods=[expected_ip_1],
            supervision_periods=[expected_sp_1, expected_sp_2])
        expected_sg = attr.evolve(
            sg,
            supervision_sentences=[expected_ss, expected_placeholder_ss],
            incarceration_sentences=[expected_inc_s])
        expected_person = attr.evolve(state_person,
                                      sentence_groups=[expected_sg])

        # Act
        input_people = converter.convert_entity_people_to_schema_people(
            [state_person])
        move_periods_onto_sentences_by_date(input_people)

        # Assert
        self.assert_people_match([expected_person], input_people)
コード例 #8
0
    def test_most_recent_supervision_type_two_sentences_same_transition_day_one_different(
        self,
    ) -> None:
        # Arrange

        start_date = self.upper_bound_date - datetime.timedelta(days=5)
        transition_date_1 = self.upper_bound_date - datetime.timedelta(days=3)
        transition_date_2 = self.upper_bound_date - datetime.timedelta(days=1)

        incarceration_sentence = (
            FakeUsMoIncarcerationSentence.fake_sentence_from_sentence(
                StateIncarcerationSentence.new_with_defaults(
                    external_id="ss1",
                    state_code="US_MO",
                    start_date=start_date,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=start_date,
                        end_date=transition_date_2,
                        supervision_type=StateSupervisionType.PAROLE,
                    ),
                    SupervisionTypeSpan(
                        start_date=transition_date_2,
                        end_date=None,
                        supervision_type=None,
                    ),
                ],
            )
        )

        supervision_sentence_1 = (
            FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
                StateSupervisionSentence.new_with_defaults(
                    external_id="ss1",
                    state_code="US_MO",
                    start_date=start_date,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=start_date,
                        end_date=transition_date_1,
                        supervision_type=StateSupervisionType.PROBATION,
                    ),
                    SupervisionTypeSpan(
                        start_date=transition_date_1,
                        end_date=None,
                        supervision_type=None,
                    ),
                ],
            )
        )

        supervision_sentence_2 = (
            FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
                StateSupervisionSentence.new_with_defaults(
                    external_id="ss1",
                    state_code="US_MO",
                    start_date=start_date,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=start_date,
                        end_date=transition_date_2,
                        supervision_type=StateSupervisionType.PROBATION,
                    ),
                    SupervisionTypeSpan(
                        start_date=transition_date_2,
                        end_date=None,
                        supervision_type=StateSupervisionType.PAROLE,
                    ),
                ],
            )
        )

        # Act

        supervision_period_supervision_type = us_mo_get_most_recent_supervision_period_supervision_type_before_upper_bound_day(
            upper_bound_exclusive_date=self.upper_bound_date,
            lower_bound_inclusive_date=None,
            supervision_sentences=[supervision_sentence_1, supervision_sentence_2],
            incarceration_sentences=[incarceration_sentence],
        )

        # Assert

        # Since the probation sentence ends before the parole sentence, the last valid supervision type is PAROLE
        self.assertEqual(
            supervision_period_supervision_type,
            StateSupervisionPeriodSupervisionType.PAROLE,
        )
コード例 #9
0
    def test_set_supervision_periods_on_sentences_incarceration(self):
        state_code = "US_XX"
        supervision_period_id_1 = 123
        supervision_period_id_2 = 456

        incarceration_sentence_1 = StateIncarcerationSentence.new_with_defaults(
            state_code=state_code,
            incarceration_sentence_id=123,
            start_date=date(2000, 1, 1),
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            supervision_periods=[
                StateSupervisionPeriod.new_with_defaults(
                    state_code=state_code,
                    status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
                    supervision_period_id=supervision_period_id_1,
                )
            ],
        )

        incarceration_sentence_2 = StateIncarcerationSentence.new_with_defaults(
            state_code=state_code,
            incarceration_sentence_id=567,
            start_date=date(2000, 1, 1),
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            supervision_periods=[
                StateSupervisionPeriod.new_with_defaults(
                    state_code=state_code,
                    status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
                    supervision_period_id=supervision_period_id_2,
                )
            ],
        )

        sp_1 = StateSupervisionPeriod.new_with_defaults(
            state_code=state_code,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
            supervision_period_id=supervision_period_id_1,
            case_type_entries=[
                StateSupervisionCaseTypeEntry.new_with_defaults(
                    state_code=state_code,
                    case_type=StateSupervisionCaseType.DOMESTIC_VIOLENCE,
                )
            ],
        )

        sp_2 = StateSupervisionPeriod.new_with_defaults(
            state_code=state_code,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
            supervision_period_id=supervision_period_id_2,
            case_type_entries=[
                StateSupervisionCaseTypeEntry.new_with_defaults(
                    state_code=state_code,
                    case_type=StateSupervisionCaseType.FAMILY_COURT,
                )
            ],
        )

        person_and_entities = {
            "sentences": [incarceration_sentence_1, incarceration_sentence_2],
            "supervision_periods": [sp_1, sp_2],
        }

        test_pipeline = TestPipeline()

        output = (
            test_pipeline
            | beam.Create([(12345, person_and_entities)])
            | "Set Incarceration and Supervision Sentences on SentenceGroups"
            >> beam.ParDo(
                entity_hydration_utils.SetSupervisionPeriodsOnSentences()))

        updated_sp_1 = attr.evolve(sp_1)
        updated_sp_2 = attr.evolve(sp_2)

        updated_is_1 = attr.evolve(incarceration_sentence_1,
                                   supervision_periods=[updated_sp_1])
        updated_is_2 = attr.evolve(incarceration_sentence_2,
                                   supervision_periods=[updated_sp_2])

        assert_that(
            output,
            equal_to([(12345, updated_is_1), (12345, updated_is_2)]),
        )

        test_pipeline.run()
コード例 #10
0
    def testSetSentencesOnSentenceGroup(self):
        """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the
        StateSentenceGroup."""

        incarceration_sentence_id = 123
        supervision_sentence_id = 456

        hydrated_incarceration_sentence = StateIncarcerationSentence.new_with_defaults(
            incarceration_sentence_id=incarceration_sentence_id,
            start_date=date(2000, 1, 1),
            charges=[StateCharge.new_with_defaults(ncic_code='1234')],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    admission_date=date(2000, 3, 2))
            ])

        hydrated_supervision_sentence = StateSupervisionSentence.new_with_defaults(
            supervision_sentence_id=supervision_sentence_id,
            start_date=date(2000, 1, 1),
            charges=[StateCharge.new_with_defaults(ncic_code='1234')],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    admission_date=date(2000, 3, 2))
            ])

        sentence_group = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[
                StateIncarcerationSentence.new_with_defaults(
                    incarceration_sentence_id=incarceration_sentence_id)
            ],
            supervision_sentences=[
                StateSupervisionSentence.new_with_defaults(
                    supervision_sentence_id=supervision_sentence_id)
            ])

        person_and_entities = ({
            'incarceration_sentences': [hydrated_incarceration_sentence],
            'supervision_sentences': [hydrated_supervision_sentence],
            'sentence_groups': [sentence_group]
        })

        hydrated_incarceration_sentence_with_group = StateIncarcerationSentence.new_with_defaults(
            incarceration_sentence_id=incarceration_sentence_id,
            start_date=date(2000, 1, 1),
            charges=[StateCharge.new_with_defaults(ncic_code='1234')],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    admission_date=date(2000, 3, 2))
            ])

        hydrated_supervision_sentence_with_group = StateSupervisionSentence.new_with_defaults(
            supervision_sentence_id=supervision_sentence_id,
            start_date=date(2000, 1, 1),
            charges=[StateCharge.new_with_defaults(ncic_code='1234')],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    admission_date=date(2000, 3, 2))
            ])

        expected_sentence_group = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[
                hydrated_incarceration_sentence_with_group
            ],
            supervision_sentences=[hydrated_supervision_sentence_with_group])

        hydrated_incarceration_sentence_with_group.sentence_group = expected_sentence_group
        hydrated_supervision_sentence_with_group.sentence_group = expected_sentence_group

        test_pipeline = TestPipeline()

        output = (
            test_pipeline
            | beam.Create([(12345, person_and_entities)])
            |
            'Set Incarceration and Supervision Sentences on SentenceGroups' >>
            beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup()))

        assert_that(output, equal_to([(12345, expected_sentence_group)]))

        test_pipeline.run()
コード例 #11
0
    def testSetSentencesOnSentenceGroupMultipleSGs(self):
        """Tests that the hydrated StateIncarcerationSentences and
        StateSupervisionSentences are set on the appropriate StateSentenceGroup."""

        incarceration_sentence_id_1 = 123
        incarceration_sentence_id_2 = 456
        supervision_sentence_id = 789

        hydrated_incarceration_sentence_1 = (
            StateIncarcerationSentence.new_with_defaults(
                state_code="US_XX",
                incarceration_sentence_id=incarceration_sentence_id_1,
                start_date=date(2000, 1, 1),
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                charges=[
                    StateCharge.new_with_defaults(
                        state_code="US_XX",
                        status=ChargeStatus.PRESENT_WITHOUT_INFO,
                        ncic_code="1234",
                    )
                ],
            ))

        hydrated_incarceration_sentence_2 = (
            StateIncarcerationSentence.new_with_defaults(
                state_code="US_XX",
                incarceration_sentence_id=incarceration_sentence_id_2,
                start_date=date(2000, 1, 1),
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                charges=[
                    StateCharge.new_with_defaults(
                        state_code="US_XX",
                        status=ChargeStatus.PRESENT_WITHOUT_INFO,
                        ncic_code="5678",
                    )
                ],
                incarceration_periods=[
                    StateIncarcerationPeriod.new_with_defaults(
                        state_code="US_XX",
                        admission_date=date(2000, 3, 2),
                        status=StateIncarcerationPeriodStatus.
                        PRESENT_WITHOUT_INFO,
                    )
                ],
            ))

        hydrated_supervision_sentence = StateSupervisionSentence.new_with_defaults(
            state_code="US_XX",
            supervision_sentence_id=supervision_sentence_id,
            start_date=date(2000, 1, 1),
            charges=[
                StateCharge.new_with_defaults(
                    state_code="US_XX",
                    status=ChargeStatus.PRESENT_WITHOUT_INFO,
                    ncic_code="1234",
                )
            ],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    state_code="US_XX",
                    admission_date=date(2000, 3, 2),
                    status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
                )
            ],
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
        )

        sentence_group_1 = StateSentenceGroup.new_with_defaults(
            state_code="US_XX",
            sentence_group_id=111,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_sentences=[
                StateIncarcerationSentence.new_with_defaults(
                    state_code="US_XX",
                    incarceration_sentence_id=incarceration_sentence_id_1,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                )
            ],
        )

        sentence_group_2 = StateSentenceGroup.new_with_defaults(
            state_code="US_XX",
            sentence_group_id=222,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_sentences=[
                StateIncarcerationSentence.new_with_defaults(
                    state_code="US_XX",
                    incarceration_sentence_id=incarceration_sentence_id_2,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                )
            ],
            supervision_sentences=[
                StateSupervisionSentence.new_with_defaults(
                    state_code="US_XX",
                    supervision_sentence_id=supervision_sentence_id,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                )
            ],
        )

        person_and_entities = {
            "incarceration_sentences": [
                hydrated_incarceration_sentence_1,
                hydrated_incarceration_sentence_2,
            ],
            "supervision_sentences": [hydrated_supervision_sentence],
            "sentence_groups": [sentence_group_1, sentence_group_2],
        }

        hydrated_incarceration_sentence_1_with_group = attr.evolve(
            hydrated_incarceration_sentence_1)

        hydrated_incarceration_sentence_2_with_group = attr.evolve(
            hydrated_incarceration_sentence_2)

        hydrated_supervision_sentence_with_group = attr.evolve(
            hydrated_supervision_sentence)

        expected_sentence_group_1 = attr.evolve(
            sentence_group_1,
            incarceration_sentences=[
                hydrated_incarceration_sentence_1_with_group
            ],
        )

        expected_sentence_group_2 = attr.evolve(
            sentence_group_2,
            incarceration_sentences=[
                hydrated_incarceration_sentence_2_with_group
            ],
            supervision_sentences=[hydrated_supervision_sentence_with_group],
        )

        hydrated_incarceration_sentence_1_with_group.sentence_group = (
            expected_sentence_group_1)
        hydrated_incarceration_sentence_2_with_group.sentence_group = (
            expected_sentence_group_2)
        hydrated_supervision_sentence_with_group.sentence_group = (
            expected_sentence_group_2)

        test_pipeline = TestPipeline()

        output = (
            test_pipeline
            | beam.Create([(12345, person_and_entities)])
            |
            "Set Incarceration and Supervision Sentences on SentenceGroups" >>
            beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup()))

        assert_that(
            output,
            equal_to([(12345, expected_sentence_group_1),
                      (12345, expected_sentence_group_2)]),
        )

        test_pipeline.run()
コード例 #12
0
    def testSetSentencesOnSentenceGroup(self):
        """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the
        StateSentenceGroup."""

        incarceration_sentence_id = 123
        supervision_sentence_id = 456

        hydrated_incarceration_sentence = StateIncarcerationSentence.new_with_defaults(
            state_code="US_XX",
            incarceration_sentence_id=incarceration_sentence_id,
            start_date=date(2000, 1, 1),
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            charges=[
                StateCharge.new_with_defaults(
                    state_code="US_XX",
                    status=ChargeStatus.PRESENT_WITHOUT_INFO,
                    ncic_code="1234",
                )
            ],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    state_code="US_XX",
                    admission_date=date(2000, 3, 2),
                    status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
                )
            ],
        )

        hydrated_supervision_sentence = StateSupervisionSentence.new_with_defaults(
            state_code="US_XX",
            supervision_sentence_id=supervision_sentence_id,
            start_date=date(2000, 1, 1),
            charges=[
                StateCharge.new_with_defaults(
                    state_code="US_XX",
                    status=ChargeStatus.PRESENT_WITHOUT_INFO,
                    ncic_code="1234",
                )
            ],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    state_code="US_XX",
                    admission_date=date(2000, 3, 2),
                    status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
                )
            ],
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
        )

        sentence_group = StateSentenceGroup.new_with_defaults(
            state_code="US_XX",
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_sentences=[
                StateIncarcerationSentence.new_with_defaults(
                    state_code="US_XX",
                    incarceration_sentence_id=incarceration_sentence_id,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                )
            ],
            supervision_sentences=[
                StateSupervisionSentence.new_with_defaults(
                    state_code="US_XX",
                    supervision_sentence_id=supervision_sentence_id,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                )
            ],
        )

        person_and_entities = {
            "incarceration_sentences": [hydrated_incarceration_sentence],
            "supervision_sentences": [hydrated_supervision_sentence],
            "sentence_groups": [sentence_group],
        }

        hydrated_incarceration_sentence_with_group = (
            StateIncarcerationSentence.new_with_defaults(
                state_code="US_XX",
                incarceration_sentence_id=incarceration_sentence_id,
                start_date=date(2000, 1, 1),
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                charges=[
                    StateCharge.new_with_defaults(
                        state_code="US_XX",
                        status=ChargeStatus.PRESENT_WITHOUT_INFO,
                        ncic_code="1234",
                    )
                ],
                incarceration_periods=[
                    StateIncarcerationPeriod.new_with_defaults(
                        state_code="US_XX",
                        admission_date=date(2000, 3, 2),
                        status=StateIncarcerationPeriodStatus.
                        PRESENT_WITHOUT_INFO,
                    )
                ],
            ))

        hydrated_supervision_sentence_with_group = (
            StateSupervisionSentence.new_with_defaults(
                state_code="US_XX",
                supervision_sentence_id=supervision_sentence_id,
                start_date=date(2000, 1, 1),
                charges=[
                    StateCharge.new_with_defaults(
                        state_code="US_XX",
                        status=ChargeStatus.PRESENT_WITHOUT_INFO,
                        ncic_code="1234",
                    )
                ],
                incarceration_periods=[
                    StateIncarcerationPeriod.new_with_defaults(
                        state_code="US_XX",
                        admission_date=date(2000, 3, 2),
                        status=StateIncarcerationPeriodStatus.
                        PRESENT_WITHOUT_INFO,
                    )
                ],
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            ))

        expected_sentence_group = StateSentenceGroup.new_with_defaults(
            state_code="US_XX",
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_sentences=[
                hydrated_incarceration_sentence_with_group
            ],
            supervision_sentences=[hydrated_supervision_sentence_with_group],
        )

        hydrated_incarceration_sentence_with_group.sentence_group = (
            expected_sentence_group)
        hydrated_supervision_sentence_with_group.sentence_group = (
            expected_sentence_group)

        test_pipeline = TestPipeline()

        output = (
            test_pipeline
            | beam.Create([(12345, person_and_entities)])
            |
            "Set Incarceration and Supervision Sentences on SentenceGroups" >>
            beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup()))

        assert_that(output, equal_to([(12345, expected_sentence_group)]))

        test_pipeline.run()
コード例 #13
0
    def testClassifyIncarcerationEvents(self):
        """Tests the ClassifyIncarcerationEvents DoFn."""
        fake_person_id = 12345

        fake_person = StatePerson.new_with_defaults(
            person_id=fake_person_id,
            gender=Gender.MALE,
            birthdate=date(1970, 1, 1),
            residency_status=ResidencyStatus.PERMANENT)

        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=1111,
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            state_code='TX',
            facility='PRISON XX',
            admission_date=date(2010, 11, 20),
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PROBATION_REVOCATION,
            release_date=date(2010, 11, 21),
            release_reason=StateIncarcerationPeriodReleaseReason.
            SENTENCE_SERVED)

        incarceration_sentence = StateIncarcerationSentence.new_with_defaults(
            incarceration_sentence_id=123,
            incarceration_periods=[incarceration_period],
            start_date=date(2009, 2, 9),
            charges=[
                StateCharge.new_with_defaults(ncic_code='5699',
                                              statute='30A123',
                                              offense_date=date(2009, 1, 9))
            ])

        sentence_group = StateSentenceGroup.new_with_defaults(
            sentence_group_id=123,
            incarceration_sentences=[incarceration_sentence])

        incarceration_sentence.sentence_group = sentence_group

        incarceration_period.incarceration_sentences = [incarceration_sentence]

        fake_person_id_to_county_query_result = [{
            'person_id':
            fake_person_id,
            'county_of_residence':
            _COUNTY_OF_RESIDENCE
        }]

        fake_incarceration_period_judicial_district_association_result = \
            {'person_id': fake_person_id, 'incarceration_period_id': 123, 'judicial_district_code': 'NW'}

        incarceration_events = [
            IncarcerationStayEvent(
                admission_reason=incarceration_period.admission_reason,
                admission_reason_raw_text=incarceration_period.
                admission_reason_raw_text,
                supervision_type_at_admission=
                StateSupervisionPeriodSupervisionType.PROBATION,
                state_code=incarceration_period.state_code,
                event_date=incarceration_period.admission_date,
                facility=incarceration_period.facility,
                county_of_residence=_COUNTY_OF_RESIDENCE,
                most_serious_offense_ncic_code='5699',
                most_serious_offense_statute='30A123'),
            IncarcerationAdmissionEvent(
                state_code=incarceration_period.state_code,
                event_date=incarceration_period.admission_date,
                facility=incarceration_period.facility,
                county_of_residence=_COUNTY_OF_RESIDENCE,
                admission_reason=incarceration_period.admission_reason,
                admission_reason_raw_text=incarceration_period.
                admission_reason_raw_text,
                supervision_type_at_admission=
                StateSupervisionPeriodSupervisionType.PROBATION,
            ),
            IncarcerationReleaseEvent(
                state_code=incarceration_period.state_code,
                event_date=incarceration_period.release_date,
                facility=incarceration_period.facility,
                county_of_residence=_COUNTY_OF_RESIDENCE,
                release_reason=incarceration_period.release_reason,
                admission_reason=incarceration_period.admission_reason,
                total_days_incarcerated=(
                    incarceration_period.release_date -
                    incarceration_period.admission_date).days)
        ]

        correct_output = [(fake_person, incarceration_events)]

        test_pipeline = TestPipeline()

        person_id_to_county_kv = (
            test_pipeline
            | "Read person id to county associations from BigQuery" >>
            beam.Create(fake_person_id_to_county_query_result)
            |
            "Convert to KV" >> beam.ParDo(ConvertDictToKVTuple(), 'person_id'))

        person_entities = {
            'person': [fake_person],
            'sentence_groups': [sentence_group],
            'incarceration_period_judicial_district_association':
            [fake_incarceration_period_judicial_district_association_result]
        }

        output = (test_pipeline
                  | beam.Create([(fake_person_id, person_entities)])
                  | 'Identify Incarceration Events' >> beam.ParDo(
                      pipeline.ClassifyIncarcerationEvents(),
                      AsDict(person_id_to_county_kv)))

        assert_that(output, equal_to(correct_output))

        test_pipeline.run()
コード例 #14
0
    def testConvert_FullIngestInfo(self):
        # Arrange
        metadata = IngestMetadata('us_nd',
                                  _JURISDICTION_ID,
                                  _INGEST_TIME,
                                  system_level=SystemLevel.STATE)

        ingest_info = IngestInfo()
        ingest_info.state_agents.add(state_agent_id='AGENT_ID1',
                                     full_name='AGENT WILLIAMS')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID2',
                                     full_name='AGENT HERNANDEZ')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID3',
                                     full_name='AGENT SMITH')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID4',
                                     full_name='AGENT PO')
        ingest_info.state_agents.add(state_agent_id='JUDGE_AGENT_ID_1',
                                     full_name='JUDGE JUDY')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID_PO',
                                     full_name='AGENT PAROLEY')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID_TERM',
                                     full_name='AGENT TERMY',
                                     agent_type='SUPERVISION_OFFICER')
        ingest_info.state_agents.add(
            state_agent_id='AGENT_ID_SUPERVISING',
            full_name='SUPERVISING AGENT',
        )

        # We expect the external_ids coming in to have the format
        # [type]:[external_id]
        ii_person_external_id_1 = US_ND_ELITE + ':' + 'EXTERNAL_ID1'
        ii_person_external_id_2 = US_ND_SID + ':' + 'EXTERNAL_ID2'

        ingest_info.state_people.add(
            state_person_id='PERSON_ID',
            state_person_race_ids=['RACE_ID1', 'RACE_ID2'],
            state_person_ethnicity_ids=['ETHNICITY_ID'],
            state_alias_ids=['ALIAS_ID1', 'ALIAS_ID2'],
            state_person_external_ids_ids=[
                ii_person_external_id_1, ii_person_external_id_2
            ],
            state_assessment_ids=['ASSESSMENT_ID'],
            state_program_assignment_ids=['PROGRAM_ASSIGNMENT_ID'],
            state_sentence_group_ids=['GROUP_ID1', 'GROUP_ID2'],
            supervising_officer_id='AGENT_ID_SUPERVISING',
        )
        ingest_info.state_person_races.add(
            state_person_race_id='RACE_ID1',
            race='WHITE',
        )
        ingest_info.state_person_races.add(state_person_race_id='RACE_ID2',
                                           race='OTHER')
        ingest_info.state_person_ethnicities.add(
            state_person_ethnicity_id='ETHNICITY_ID', ethnicity='HISPANIC')
        ingest_info.state_aliases.add(state_alias_id='ALIAS_ID1',
                                      full_name='LONNY BREAUX')
        ingest_info.state_aliases.add(state_alias_id='ALIAS_ID2',
                                      full_name='FRANK OCEAN')
        ingest_info.state_person_external_ids.add(
            state_person_external_id_id=ii_person_external_id_1,
            id_type=US_ND_ELITE)
        ingest_info.state_person_external_ids.add(
            state_person_external_id_id=ii_person_external_id_2,
            id_type=US_ND_SID)
        ingest_info.state_assessments.add(state_assessment_id='ASSESSMENT_ID',
                                          assessment_class='MENTAL_HEALTH',
                                          conducting_agent_id='AGENT_ID1')
        ingest_info.state_program_assignments.add(
            state_program_assignment_id='PROGRAM_ASSIGNMENT_ID',
            participation_status='DISCHARGED',
            referral_date='2019/02/10',
            start_date='2019/02/11',
            discharge_date='2019/02/12',
            program_id='PROGRAM_ID',
            program_location_id='PROGRAM_LOCATION_ID',
            discharge_reason='COMPLETED',
            referring_agent_id='AGENT_ID4')
        ingest_info.state_sentence_groups.add(
            state_sentence_group_id='GROUP_ID1',
            state_supervision_sentence_ids=['SUPERVISION_SENTENCE_ID1'],
            state_incarceration_sentence_ids=[
                'INCARCERATION_SENTENCE_ID1', 'INCARCERATION_SENTENCE_ID2'
            ])
        ingest_info.state_sentence_groups.add(
            state_sentence_group_id='GROUP_ID2',
            state_supervision_sentence_ids=['SUPERVISION_SENTENCE_ID2'],
            state_fine_ids=['FINE_ID'])
        ingest_info.state_fines.add(state_fine_id='FINE_ID', status='PAID')
        ingest_info.state_supervision_sentences.add(
            state_supervision_sentence_id='SUPERVISION_SENTENCE_ID1',
            state_charge_ids=['CHARGE_ID1', 'CHARGE_ID2'],
            state_supervision_period_ids=['S_PERIOD_ID1'])
        ingest_info.state_supervision_sentences.add(
            state_supervision_sentence_id='SUPERVISION_SENTENCE_ID2',
            state_charge_ids=['CHARGE_ID2'],
            state_supervision_period_ids=['S_PERIOD_ID2'])
        ingest_info.state_incarceration_sentences.add(
            state_incarceration_sentence_id='INCARCERATION_SENTENCE_ID1',
            state_charge_ids=['CHARGE_ID1'],
            state_incarceration_period_ids=['I_PERIOD_ID'])
        ingest_info.state_incarceration_sentences.add(
            state_incarceration_sentence_id='INCARCERATION_SENTENCE_ID2',
            state_charge_ids=['CHARGE_ID2', 'CHARGE_ID3'],
            state_supervision_period_ids=['S_PERIOD_ID3'])
        ingest_info.state_charges.add(
            state_charge_id='CHARGE_ID1',
            state_court_case_id='CASE_ID',
            state_bond_id='BOND_ID',
            classification_type='M',
            classification_subtype='1',
            ncic_code='5006',
        )
        ingest_info.state_charges.add(
            state_charge_id='CHARGE_ID2',
            state_court_case_id='CASE_ID',
            classification_type='M',
            classification_subtype='2',
        )
        ingest_info.state_charges.add(
            state_charge_id='CHARGE_ID3',
            state_court_case_id='CASE_ID',
            classification_type='F',
            classification_subtype='3',
            ncic_code='5006',
            description='Obstruction of investigation',
        )
        ingest_info.state_court_cases.add(
            state_court_case_id='CASE_ID',
            judge_id='JUDGE_AGENT_ID_1',
        )
        ingest_info.state_bonds.add(state_bond_id='BOND_ID', status='POSTED')
        ingest_info.state_supervision_periods.add(
            state_supervision_period_id='S_PERIOD_ID1',
            state_supervision_violation_entry_ids=['VIOLATION_ID'],
            supervision_type='PAROLE',
            supervision_level='MED',
            state_supervision_contact_ids=['SUPERVISION_CONTACT_ID'],
            state_program_assignment_ids=['PROGRAM_ASSIGNMENT_ID'])
        ingest_info.state_supervision_periods.add(
            state_supervision_period_id='S_PERIOD_ID2',
            supervision_type='PAROLE')
        ingest_info.state_supervision_periods.add(
            state_supervision_period_id='S_PERIOD_ID3',
            state_assessment_ids=['ASSESSMENT_ID'],
            supervising_officer_id='AGENT_ID_PO',
            supervision_type='PROBATION',
            state_supervision_case_type_entry_ids=['CASE_TYPE_ID'],
        )
        ingest_info.state_supervision_case_type_entries.add(
            state_supervision_case_type_entry_id='CASE_TYPE_ID',
            case_type='DOMESTIC_VIOLENCE')

        ingest_info.state_incarceration_periods.add(
            state_incarceration_period_id='I_PERIOD_ID',
            state_incarceration_incident_ids=['INCIDENT_ID'],
            state_parole_decision_ids=['DECISION_ID'],
            state_assessment_ids=['ASSESSMENT_ID'],
            state_program_assignment_ids=['PROGRAM_ASSIGNMENT_ID'],
            source_supervision_violation_response_id='RESPONSE_ID')

        ingest_info.state_supervision_violation_type_entries.add(
            state_supervision_violation_type_entry_id='VIOLATION_TYPE_ENTRY_ID',
            violation_type='FELONY',
            state_code='US_ND')

        ingest_info.state_supervision_violated_condition_entries.add(
            state_supervision_violated_condition_entry_id=
            'VIOLATED_CONDITION_ENTRY_ID',
            condition='CURFEW',
            state_code='US_ND')

        ingest_info.state_supervision_violations.add(
            state_supervision_violation_id='VIOLATION_ID',
            state_supervision_violation_response_ids=['RESPONSE_ID'],
            state_supervision_violated_condition_entry_ids=[
                'VIOLATED_CONDITION_ENTRY_ID'
            ],
            state_supervision_violation_type_entry_ids=[
                'VIOLATION_TYPE_ENTRY_ID'
            ],
        )

        ingest_info.state_supervision_violated_condition_entries.add(
            state_supervision_violated_condition_entry_id=
            'VIOLATED_CONDITION_ENTRY_ID',
            condition='CURFEW',
            state_code='US_ND')

        ingest_info.state_supervision_violation_response_decision_entries.add(
            state_supervision_violation_response_decision_entry_id=
            'VIOLATION_RESPONSE_DECISION_ENTRY_ID',
            decision='REVOCATION',
            revocation_type='REINCARCERATION',
            state_code='US_ND')

        ingest_info.state_supervision_violation_responses.add(
            state_supervision_violation_response_id='RESPONSE_ID',
            decision_agent_ids=['AGENT_ID_TERM'],
            state_supervision_violation_response_decision_entry_ids=[
                'VIOLATION_RESPONSE_DECISION_ENTRY_ID'
            ],
            response_type='CITATION')
        ingest_info.state_incarceration_incidents.add(
            state_incarceration_incident_id='INCIDENT_ID',
            incident_type='CONTRABAND',
            responding_officer_id='AGENT_ID2',
            state_incarceration_incident_outcome_ids=['INCIDENT_OUTCOME_ID'],
        )

        ingest_info.state_incarceration_incident_outcomes.add(
            state_incarceration_incident_outcome_id='INCIDENT_OUTCOME_ID',
            outcome_type='GOOD_TIME_LOSS',
            date_effective='2/10/2018',
            state_code='US_ND',
            outcome_description='Good time',
            punishment_length_days='7',
        )
        ingest_info.state_parole_decisions.add(
            state_parole_decision_id='DECISION_ID',
            decision_agent_ids=['AGENT_ID2', 'AGENT_ID3'])
        ingest_info.state_supervision_contacts.add(
            state_supervision_contact_id='SUPERVISION_CONTACT_ID',
            contacted_agent_id='AGENT_ID_PO')

        # Act
        result = self._convert_and_throw_on_errors(ingest_info, metadata)

        # Assert
        supervision_contact = StateSupervisionContact.new_with_defaults(
            external_id='SUPERVISION_CONTACT_ID',
            state_code='US_ND',
            contacted_agent=StateAgent.new_with_defaults(
                external_id='AGENT_ID_PO',
                state_code='US_ND',
                agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                full_name='{"full_name": "AGENT PAROLEY"}'),
        )

        incident_outcome = StateIncarcerationIncidentOutcome.new_with_defaults(
            external_id='INCIDENT_OUTCOME_ID',
            outcome_type=StateIncarcerationIncidentOutcomeType.GOOD_TIME_LOSS,
            outcome_type_raw_text='GOOD_TIME_LOSS',
            date_effective=datetime.date(year=2018, month=2, day=10),
            state_code='US_ND',
            outcome_description='GOOD TIME',
            punishment_length_days=7,
        )

        incident = StateIncarcerationIncident.new_with_defaults(
            external_id='INCIDENT_ID',
            state_code='US_ND',
            incident_type=StateIncarcerationIncidentType.CONTRABAND,
            incident_type_raw_text='CONTRABAND',
            responding_officer=StateAgent.new_with_defaults(
                external_id='AGENT_ID2',
                state_code='US_ND',
                agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                full_name='{"full_name": "AGENT HERNANDEZ"}',
            ),
            incarceration_incident_outcomes=[incident_outcome])

        assessment = StateAssessment.new_with_defaults(
            external_id='ASSESSMENT_ID',
            state_code='US_ND',
            assessment_class=StateAssessmentClass.MENTAL_HEALTH,
            assessment_class_raw_text='MENTAL_HEALTH',
            conducting_agent=StateAgent.new_with_defaults(
                external_id='AGENT_ID1',
                agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                state_code='US_ND',
                full_name='{"full_name": "AGENT WILLIAMS"}',
            ))

        program_assignment = StateProgramAssignment.new_with_defaults(
            external_id='PROGRAM_ASSIGNMENT_ID',
            state_code='US_ND',
            participation_status=StateProgramAssignmentParticipationStatus.
            DISCHARGED,
            participation_status_raw_text='DISCHARGED',
            referral_date=datetime.date(year=2019, month=2, day=10),
            start_date=datetime.date(year=2019, month=2, day=11),
            discharge_date=datetime.date(year=2019, month=2, day=12),
            program_id='PROGRAM_ID',
            program_location_id='PROGRAM_LOCATION_ID',
            discharge_reason=StateProgramAssignmentDischargeReason.COMPLETED,
            discharge_reason_raw_text='COMPLETED',
            referring_agent=StateAgent.new_with_defaults(
                external_id='AGENT_ID4',
                agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                state_code='US_ND',
                full_name='{"full_name": "AGENT PO"}'))

        response = StateSupervisionViolationResponse.new_with_defaults(
            external_id='RESPONSE_ID',
            state_code='US_ND',
            response_type=StateSupervisionViolationResponseType.CITATION,
            response_type_raw_text='CITATION',
            decision_agents=[
                StateAgent.new_with_defaults(
                    external_id='AGENT_ID_TERM',
                    state_code='US_ND',
                    full_name='{"full_name": "AGENT TERMY"}',
                    agent_type=StateAgentType.SUPERVISION_OFFICER,
                    agent_type_raw_text='SUPERVISION_OFFICER',
                )
            ],
            supervision_violation_response_decisions=[
                StateSupervisionViolationResponseDecisionEntry.
                new_with_defaults(
                    state_code='US_ND',
                    decision=StateSupervisionViolationResponseDecision.
                    REVOCATION,
                    decision_raw_text='REVOCATION',
                    revocation_type=
                    StateSupervisionViolationResponseRevocationType.
                    REINCARCERATION,
                    revocation_type_raw_text='REINCARCERATION')
            ])

        violation = StateSupervisionViolation.new_with_defaults(
            external_id='VIOLATION_ID',
            state_code='US_ND',
            supervision_violation_responses=[response],
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code='US_ND',
                    violation_type=StateSupervisionViolationType.FELONY,
                    violation_type_raw_text='FELONY',
                )
            ],
            supervision_violated_conditions=[
                StateSupervisionViolatedConditionEntry.new_with_defaults(
                    state_code='US_ND',
                    condition='CURFEW',
                )
            ])

        court_case = StateCourtCase.new_with_defaults(
            external_id='CASE_ID',
            state_code='US_ND',
            status=StateCourtCaseStatus.PRESENT_WITHOUT_INFO,
            court_type=StateCourtType.PRESENT_WITHOUT_INFO,
            judge=StateAgent.new_with_defaults(
                external_id='JUDGE_AGENT_ID_1',
                state_code='US_ND',
                agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                full_name='{"full_name": "JUDGE JUDY"}',
            ))

        charge_1 = StateCharge.new_with_defaults(
            external_id='CHARGE_ID1',
            classification_type=StateChargeClassificationType.MISDEMEANOR,
            classification_type_raw_text='M',
            classification_subtype='1',
            ncic_code='5006',
            description='FALSE STATEMENT',
            state_code='US_ND',
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            court_case=court_case,
            bond=StateBond.new_with_defaults(external_id='BOND_ID',
                                             state_code='US_ND',
                                             status=BondStatus.POSTED,
                                             status_raw_text='POSTED'))

        charge_2 = StateCharge.new_with_defaults(
            external_id='CHARGE_ID2',
            classification_type=StateChargeClassificationType.MISDEMEANOR,
            classification_type_raw_text='M',
            classification_subtype='2',
            state_code='US_ND',
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            court_case=court_case)

        charge_3 = StateCharge.new_with_defaults(
            external_id='CHARGE_ID3',
            state_code='US_ND',
            classification_type=StateChargeClassificationType.FELONY,
            classification_type_raw_text='F',
            classification_subtype='3',
            ncic_code='5006',
            description='OBSTRUCTION OF INVESTIGATION',
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            court_case=court_case)

        incarceration_sentence_1 = StateIncarcerationSentence.new_with_defaults(
            external_id='INCARCERATION_SENTENCE_ID1',
            state_code='US_ND',
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            charges=[charge_1],
            incarceration_periods=[
                StateIncarcerationPeriod.new_with_defaults(
                    external_id='I_PERIOD_ID',
                    status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
                    incarceration_type=StateIncarcerationType.STATE_PRISON,
                    state_code='US_ND',
                    incarceration_incidents=[incident],
                    program_assignments=[program_assignment],
                    parole_decisions=[
                        StateParoleDecision.new_with_defaults(
                            external_id='DECISION_ID',
                            state_code='US_ND',
                            decision_agents=[
                                StateAgent.new_with_defaults(
                                    external_id='AGENT_ID2',
                                    agent_type=StateAgentType.
                                    PRESENT_WITHOUT_INFO,
                                    state_code='US_ND',
                                    full_name='{"full_name": "AGENT HERNANDEZ"}'
                                ),
                                StateAgent.new_with_defaults(
                                    external_id='AGENT_ID3',
                                    state_code='US_ND',
                                    agent_type=StateAgentType.
                                    PRESENT_WITHOUT_INFO,
                                    full_name='{"full_name": "AGENT SMITH"}')
                            ])
                    ],
                    assessments=[assessment],
                    source_supervision_violation_response=response,
                )
            ])

        incarceration_sentence_2 = StateIncarcerationSentence.new_with_defaults(
            external_id='INCARCERATION_SENTENCE_ID2',
            state_code='US_ND',
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            charges=[charge_2, charge_3],
            supervision_periods=[
                StateSupervisionPeriod.new_with_defaults(
                    external_id='S_PERIOD_ID3',
                    status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
                    state_code='US_ND',
                    supervision_type=StateSupervisionType.PROBATION,
                    supervision_type_raw_text='PROBATION',
                    assessments=[assessment],
                    supervising_officer=StateAgent.new_with_defaults(
                        external_id='AGENT_ID_PO',
                        state_code='US_ND',
                        agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                        full_name='{"full_name": "AGENT PAROLEY"}',
                    ),
                    case_type_entries=[
                        StateSupervisionCaseTypeEntry.new_with_defaults(
                            case_type=StateSupervisionCaseType.
                            DOMESTIC_VIOLENCE,
                            case_type_raw_text='DOMESTIC_VIOLENCE',
                            state_code='US_ND',
                            external_id='CASE_TYPE_ID')
                    ])
            ])

        expected_result = [
            StatePerson.new_with_defaults(
                external_ids=[
                    StatePersonExternalId.new_with_defaults(
                        external_id='EXTERNAL_ID1',
                        state_code='US_ND',
                        id_type=US_ND_ELITE),
                    StatePersonExternalId.new_with_defaults(
                        external_id='EXTERNAL_ID2',
                        state_code='US_ND',
                        id_type=US_ND_SID)
                ],
                races=[
                    StatePersonRace(race=Race.WHITE,
                                    race_raw_text='WHITE',
                                    state_code='US_ND'),
                    StatePersonRace(race=Race.OTHER,
                                    race_raw_text='OTHER',
                                    state_code='US_ND'),
                ],
                ethnicities=[
                    StatePersonEthnicity(ethnicity=Ethnicity.HISPANIC,
                                         ethnicity_raw_text='HISPANIC',
                                         state_code='US_ND')
                ],
                aliases=[
                    StatePersonAlias.new_with_defaults(
                        full_name='{"full_name": "LONNY BREAUX"}',
                        state_code='US_ND'),
                    StatePersonAlias.new_with_defaults(
                        full_name='{"full_name": "FRANK OCEAN"}',
                        state_code='US_ND'),
                ],
                supervising_officer=StateAgent.new_with_defaults(
                    external_id='AGENT_ID_SUPERVISING',
                    state_code='US_ND',
                    agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
                    full_name='{"full_name": "SUPERVISING AGENT"}'),
                assessments=[assessment],
                program_assignments=[program_assignment],
                sentence_groups=[
                    StateSentenceGroup.new_with_defaults(
                        external_id='GROUP_ID1',
                        status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                        state_code='US_ND',
                        supervision_sentences=[
                            StateSupervisionSentence.new_with_defaults(
                                external_id='SUPERVISION_SENTENCE_ID1',
                                state_code='US_ND',
                                status=StateSentenceStatus.
                                PRESENT_WITHOUT_INFO,
                                charges=[charge_1, charge_2],
                                supervision_periods=[
                                    StateSupervisionPeriod.new_with_defaults(
                                        external_id='S_PERIOD_ID1',
                                        status=StateSupervisionPeriodStatus.
                                        PRESENT_WITHOUT_INFO,
                                        supervision_level=StateSupervisionLevel
                                        .MEDIUM,
                                        supervision_level_raw_text='MED',
                                        state_code='US_ND',
                                        supervision_type=StateSupervisionType.
                                        PAROLE,
                                        supervision_type_raw_text='PAROLE',
                                        supervision_violation_entries=[
                                            violation
                                        ],
                                        program_assignments=[
                                            program_assignment
                                        ],
                                        supervision_contacts=[
                                            supervision_contact
                                        ],
                                    )
                                ])
                        ],
                        incarceration_sentences=[
                            incarceration_sentence_1, incarceration_sentence_2
                        ]),
                    StateSentenceGroup.new_with_defaults(
                        external_id='GROUP_ID2',
                        status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                        state_code='US_ND',
                        supervision_sentences=[
                            StateSupervisionSentence.new_with_defaults(
                                external_id='SUPERVISION_SENTENCE_ID2',
                                state_code='US_ND',
                                status=StateSentenceStatus.
                                PRESENT_WITHOUT_INFO,
                                charges=[charge_2],
                                supervision_periods=[
                                    StateSupervisionPeriod.new_with_defaults(
                                        external_id='S_PERIOD_ID2',
                                        status=StateSupervisionPeriodStatus.
                                        PRESENT_WITHOUT_INFO,
                                        state_code='US_ND',
                                        supervision_type=StateSupervisionType.
                                        PAROLE,
                                        supervision_type_raw_text='PAROLE',
                                    )
                                ])
                        ],
                        fines=[
                            StateFine.new_with_defaults(
                                external_id='FINE_ID',
                                state_code='US_ND',
                                status=StateFineStatus.PAID,
                                status_raw_text='PAID')
                        ])
                ])
        ]

        print("\n", expected_result, "\n\n\n", result)

        self.assertCountEqual(expected_result, result)
コード例 #15
0
    def test_moveViolationsOntoSupervisionPeriodsForSentence(self):
        # Arrange
        sv_1 = StateSupervisionViolation.new_with_defaults(
            violation_date=_DATE_2)
        svr = StateSupervisionViolationResponse.new_with_defaults(
            response_date=_DATE_3)
        sv_2 = StateSupervisionViolation.new_with_defaults(
            supervision_violation_responses=[svr])
        sv_3 = StateSupervisionViolation.new_with_defaults(
            violation_date=_DATE_8)

        placeholder_sp_ss = StateSupervisionPeriod.new_with_defaults(
            supervision_violation_entries=[sv_1, sv_3])
        sp_ss = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID,
            start_date=_DATE_1,
            termination_date=_DATE_3)
        sp_2_ss = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_2, start_date=_DATE_7)
        ss = StateSupervisionSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            supervision_periods=[sp_ss, sp_2_ss, placeholder_sp_ss])

        placeholder_sp_is = StateSupervisionPeriod.new_with_defaults(
            supervision_violation_entries=[sv_2, sv_3])
        sp_is = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_3,
            start_date=_DATE_2,
            termination_date=_DATE_3)
        sp_2_is = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_4,
            start_date=_DATE_3,
            termination_date=_DATE_6)
        inc_s = StateIncarcerationSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            supervision_periods=[sp_is, sp_2_is, placeholder_sp_is])

        sg = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[inc_s], supervision_sentences=[ss])

        state_person = StatePerson.new_with_defaults(sentence_groups=[sg])

        expected_sv_1 = attr.evolve(sv_1)
        expected_svr_2 = attr.evolve(svr)
        expected_sv_2 = attr.evolve(
            sv_2, supervision_violation_responses=[expected_svr_2])
        expected_sv_3 = attr.evolve(sv_3)

        expected_placeholder_sp_ss = attr.evolve(
            placeholder_sp_ss, supervision_violation_entries=[])
        expected_sp_ss = attr.evolve(
            sp_ss, supervision_violation_entries=[expected_sv_1])
        expected_sp_2_ss = attr.evolve(
            sp_2_ss, supervision_violation_entries=[expected_sv_3])
        expected_ss = attr.evolve(ss,
                                  supervision_periods=[
                                      expected_placeholder_sp_ss,
                                      expected_sp_ss, expected_sp_2_ss
                                  ])

        expected_placeholder_sp_is = attr.evolve(
            placeholder_sp_is, supervision_violation_entries=[expected_sv_3])
        expected_sp_is = attr.evolve(sp_is, supervision_violation_entries=[])
        expected_sp_2_is = attr.evolve(
            sp_2_is, supervision_violation_entries=[expected_sv_2])
        expected_inc_s = attr.evolve(inc_s,
                                     supervision_periods=[
                                         expected_placeholder_sp_is,
                                         expected_sp_is, expected_sp_2_is
                                     ])
        expected_sg = attr.evolve(sg,
                                  supervision_sentences=[expected_ss],
                                  incarceration_sentences=[expected_inc_s])
        expected_person = attr.evolve(state_person,
                                      sentence_groups=[expected_sg])

        # Act
        input_people = converter.convert_entity_people_to_schema_people(
            [state_person])
        move_violations_onto_supervision_periods_for_sentence(input_people)

        # Assert
        self.assert_people_match([expected_person], input_people)
コード例 #16
0
    def test_get_month_supervision_type_sentence_supervision_ends_different_days(
        self,
    ) -> None:
        # Arrange
        supervision_start = self.end_of_month_date - datetime.timedelta(days=60)
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=1234,
            external_id="sp1",
            state_code="US_MO",
            start_date=supervision_start,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        mid_month_date = self.end_of_month_date - datetime.timedelta(days=10)
        second_to_last_month_date = self.end_of_month_date - datetime.timedelta(days=1)
        incarceration_sentence = (
            FakeUsMoIncarcerationSentence.fake_sentence_from_sentence(
                StateIncarcerationSentence.new_with_defaults(
                    external_id="ss1",
                    state_code="US_MO",
                    start_date=supervision_period.start_date,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=supervision_start,
                        end_date=second_to_last_month_date,
                        supervision_type=StateSupervisionType.PAROLE,
                    ),
                    SupervisionTypeSpan(
                        start_date=second_to_last_month_date,
                        end_date=None,
                        supervision_type=None,
                    ),
                ],
            )
        )

        supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
            StateSupervisionSentence.new_with_defaults(
                external_id="ss1",
                state_code="US_MO",
                start_date=supervision_period.start_date,
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            ),
            supervision_type_spans=[
                # Probation sentence starts after parole sentence ends
                SupervisionTypeSpan(
                    start_date=supervision_start,
                    end_date=mid_month_date,
                    supervision_type=StateSupervisionType.PROBATION,
                ),
                SupervisionTypeSpan(
                    start_date=mid_month_date, end_date=None, supervision_type=None
                ),
            ],
        )

        # Act
        supervision_period_supervision_type = us_mo_get_month_supervision_type(
            self.end_of_month_date,
            supervision_sentences=[supervision_sentence],
            incarceration_sentences=[incarceration_sentence],
            supervision_period=supervision_period,
        )

        # Assert

        # Since the probation sentence ends before the parole sentence, the last valid supervision type is PAROLE
        self.assertEqual(
            supervision_period_supervision_type,
            StateSupervisionPeriodSupervisionType.PAROLE,
        )
コード例 #17
0
    def test_moveContactsOntoSupervisionPeriodsForPerson(self):
        self.maxDiff = None
        # Arrange
        sc_1 = StateSupervisionContact.new_with_defaults(contact_date=_DATE_2)
        sc_2 = StateSupervisionContact.new_with_defaults(contact_date=_DATE_3)
        sc_3 = StateSupervisionContact.new_with_defaults(contact_date=_DATE_8)

        placeholder_sp_ss = StateSupervisionPeriod.new_with_defaults(
            supervision_contacts=[sc_1, sc_3])
        sp_ss = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID,
            start_date=_DATE_1,
            termination_date=_DATE_3)
        sp_2_ss = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_2, start_date=_DATE_7)
        ss = StateSupervisionSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            supervision_periods=[sp_ss, sp_2_ss, placeholder_sp_ss])

        placeholder_sp_is = StateSupervisionPeriod.new_with_defaults(
            supervision_contacts=[sc_2, sc_3])
        sp_is = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_3,
            start_date=_DATE_2,
            termination_date=_DATE_3)
        sp_2_is = StateSupervisionPeriod.new_with_defaults(
            external_id=_EXTERNAL_ID_4,
            start_date=_DATE_3,
            termination_date=_DATE_6)
        inc_s = StateIncarcerationSentence.new_with_defaults(
            external_id=_EXTERNAL_ID,
            supervision_periods=[sp_is, sp_2_is, placeholder_sp_is])

        sg = StateSentenceGroup.new_with_defaults(
            incarceration_sentences=[inc_s])
        sg_2 = StateSentenceGroup.new_with_defaults(supervision_sentences=[ss])

        state_person = StatePerson.new_with_defaults(
            sentence_groups=[sg, sg_2])

        expected_sc_1 = attr.evolve(sc_1)
        expected_sc_2 = attr.evolve(sc_2)
        expected_sc_3 = attr.evolve(sc_3)

        expected_placeholder_sp_ss = attr.evolve(placeholder_sp_ss,
                                                 supervision_contacts=[])
        expected_sp_ss = attr.evolve(sp_ss,
                                     supervision_contacts=[expected_sc_1])
        expected_sp_2_ss = attr.evolve(sp_2_ss,
                                       supervision_contacts=[expected_sc_3])
        expected_ss = attr.evolve(ss,
                                  supervision_periods=[
                                      expected_placeholder_sp_ss,
                                      expected_sp_ss, expected_sp_2_ss
                                  ])

        expected_placeholder_sp_is = attr.evolve(placeholder_sp_is,
                                                 supervision_contacts=[])
        expected_sp_is = attr.evolve(sp_is,
                                     supervision_contacts=[expected_sc_1])
        expected_sp_2_is = attr.evolve(sp_2_is,
                                       supervision_contacts=[expected_sc_2])
        expected_inc_s = attr.evolve(inc_s,
                                     supervision_periods=[
                                         expected_placeholder_sp_is,
                                         expected_sp_is, expected_sp_2_is
                                     ])
        expected_sg = attr.evolve(sg, incarceration_sentences=[expected_inc_s])
        expected_sg_2 = attr.evolve(sg_2, supervision_sentences=[expected_ss])

        expected_person = attr.evolve(
            state_person, sentence_groups=[expected_sg, expected_sg_2])

        # Act
        input_people = converter.convert_entity_people_to_schema_people(
            [state_person])
        move_contacts_onto_supervision_periods_for_person(
            input_people, _STATE_CODE)

        # Assert
        self.assert_people_match([expected_person], input_people)
コード例 #18
0
    def test_get_month_supervision_type_parole_transitions_to_probation(self) -> None:
        # Arrange
        start_date = self.end_of_month_date - datetime.timedelta(days=60)
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=1234,
            external_id="sp1",
            state_code="US_MO",
            start_date=start_date,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        parole_end_date_middle_of_month = self.start_of_month_date + datetime.timedelta(
            days=5
        )
        incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence(
            StateIncarcerationSentence.new_with_defaults(
                external_id="ss1",
                state_code="US_MO",
                start_date=start_date,
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            ),
            supervision_type_spans=[
                SupervisionTypeSpan(
                    start_date=start_date,
                    end_date=parole_end_date_middle_of_month,
                    supervision_type=StateSupervisionType.PAROLE,
                ),
                # Parole finishes middle of month
                SupervisionTypeSpan(
                    start_date=parole_end_date_middle_of_month,
                    end_date=None,
                    supervision_type=None,
                ),
            ],
        )

        supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
            StateSupervisionSentence.new_with_defaults(
                external_id="ss1",
                state_code="US_MO",
                start_date=parole_end_date_middle_of_month,
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            ),
            supervision_type_spans=[
                # Probation sentence starts after parole sentence ends
                SupervisionTypeSpan(
                    start_date=parole_end_date_middle_of_month,
                    end_date=None,
                    supervision_type=StateSupervisionType.PROBATION,
                )
            ],
        )

        # Act
        supervision_period_supervision_type = us_mo_get_month_supervision_type(
            self.end_of_month_date,
            supervision_sentences=[supervision_sentence],
            incarceration_sentences=[incarceration_sentence],
            supervision_period=supervision_period,
        )

        # Assert
        self.assertEqual(
            supervision_period_supervision_type,
            StateSupervisionPeriodSupervisionType.PROBATION,
        )
コード例 #19
0
    def test_associateSvrsWithIps_within90Days(self) -> None:
        # Arrange
        svr_1 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=_STATE_CODE,
            response_date=_DATE_2 + datetime.timedelta(days=1),
            revocation_type=StateSupervisionViolationResponseRevocationType.
            REINCARCERATION,
        )
        svr_2 = StateSupervisionViolationResponse.new_with_defaults(
            state_code=_STATE_CODE,
            response_date=_DATE_4 + datetime.timedelta(days=100),
            revocation_type=StateSupervisionViolationResponseRevocationType.
            RETURN_TO_SUPERVISION,
        )
        placeholder_sv = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_responses=[svr_1, svr_2])
        placeholder_sp = StateSupervisionPeriod.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_entries=[placeholder_sv],
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )
        placeholder_ss = StateSupervisionSentence.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_periods=[placeholder_sp],
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
        )

        ip_1 = StateIncarcerationPeriod.new_with_defaults(
            state_code=_STATE_CODE,
            admission_date=_DATE_2,
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PROBATION_REVOCATION,
            status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
        )
        ip_2 = StateIncarcerationPeriod.new_with_defaults(
            state_code=_STATE_CODE,
            admission_date=_DATE_4,
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PROBATION_REVOCATION,
            status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO,
        )
        placeholder_is = StateIncarcerationSentence.new_with_defaults(
            state_code=_STATE_CODE,
            incarceration_periods=[ip_1, ip_2],
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
        )
        placeholder_sg = StateSentenceGroup.new_with_defaults(
            state_code=_STATE_CODE,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_sentences=[placeholder_is],
            supervision_sentences=[placeholder_ss],
        )
        placeholder_person = StatePerson.new_with_defaults(
            state_code=_STATE_CODE, sentence_groups=[placeholder_sg])

        expected_svr_1 = attr.evolve(svr_1)
        expected_svr_2 = attr.evolve(svr_2)
        expected_placeholder_sv = attr.evolve(
            placeholder_sv,
            supervision_violation_responses=[expected_svr_1, expected_svr_2],
        )
        expected_placeholder_sp = attr.evolve(
            placeholder_sp,
            supervision_violation_entries=[expected_placeholder_sv])
        expected_placeholder_ss = attr.evolve(
            placeholder_ss, supervision_periods=[expected_placeholder_sp])

        expected_ip_1 = attr.evolve(
            ip_1, source_supervision_violation_response=expected_svr_1)
        expected_ip_2 = attr.evolve(ip_2)

        expected_placeholder_is = attr.evolve(
            placeholder_is,
            incarceration_periods=[expected_ip_1, expected_ip_2])
        expected_placeholder_sg = attr.evolve(
            placeholder_sg,
            supervision_sentences=[expected_placeholder_ss],
            incarceration_sentences=[expected_placeholder_is],
        )
        expected_placeholder_person = attr.evolve(
            placeholder_person, sentence_groups=[expected_placeholder_sg])

        # Act
        input_people = converter.convert_entity_people_to_schema_people(
            [placeholder_person])
        associate_revocation_svrs_with_ips(input_people)

        # Assert
        self.assert_people_match([expected_placeholder_person], input_people)
コード例 #20
0
    def test_get_month_supervision_type_dual_ends_mid_month(self) -> None:
        # Arrange
        supervision_start = self.end_of_month_date - datetime.timedelta(days=60)
        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=1234,
            external_id="sp1",
            state_code="US_MO",
            start_date=supervision_start,
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )

        second_to_last_month_date = self.end_of_month_date - datetime.timedelta(days=1)
        incarceration_sentence = (
            FakeUsMoIncarcerationSentence.fake_sentence_from_sentence(
                StateIncarcerationSentence.new_with_defaults(
                    external_id="ss1",
                    state_code="US_MO",
                    start_date=supervision_start,
                    status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                ),
                supervision_type_spans=[
                    SupervisionTypeSpan(
                        start_date=supervision_start,
                        end_date=second_to_last_month_date,
                        supervision_type=StateSupervisionType.PAROLE,
                    ),
                    SupervisionTypeSpan(
                        start_date=second_to_last_month_date,
                        end_date=None,
                        supervision_type=None,
                    ),
                ],
            )
        )

        supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence(
            StateSupervisionSentence.new_with_defaults(
                external_id="ss1",
                state_code="US_MO",
                start_date=supervision_start,
                status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            ),
            supervision_type_spans=[
                # Probation sentence starts after parole sentence ends
                SupervisionTypeSpan(
                    start_date=supervision_start,
                    end_date=second_to_last_month_date,
                    supervision_type=StateSupervisionType.PROBATION,
                ),
                SupervisionTypeSpan(
                    start_date=second_to_last_month_date,
                    end_date=None,
                    supervision_type=None,
                ),
            ],
        )

        # Act
        supervision_period_supervision_type = us_mo_get_month_supervision_type(
            self.end_of_month_date,
            supervision_sentences=[supervision_sentence],
            incarceration_sentences=[incarceration_sentence],
            supervision_period=supervision_period,
        )

        # Assert

        # Even though both sentences are terminated before the last day, we still return DUAL
        self.assertEqual(
            supervision_period_supervision_type,
            StateSupervisionPeriodSupervisionType.DUAL,
        )
コード例 #21
0
ファイル: pipeline_test.py プロジェクト: jazzPouls/pulse-data
    def testClassifyIncarcerationEvents(self):
        """Tests the ClassifyIncarcerationEvents DoFn."""
        fake_person_id = 12345

        fake_person = StatePerson.new_with_defaults(
            state_code="US_XX",
            person_id=fake_person_id,
            gender=Gender.MALE,
            birthdate=date(1970, 1, 1),
            residency_status=ResidencyStatus.PERMANENT,
        )

        incarceration_period = StateIncarcerationPeriod.new_with_defaults(
            incarceration_period_id=1111,
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            state_code="TX",
            facility="PRISON XX",
            admission_date=date(2010, 11, 20),
            admission_reason=StateIncarcerationPeriodAdmissionReason.
            PROBATION_REVOCATION,
            release_date=date(2010, 11, 21),
            release_reason=StateIncarcerationPeriodReleaseReason.
            SENTENCE_SERVED,
            specialized_purpose_for_incarceration=
            StateSpecializedPurposeForIncarceration.PAROLE_BOARD_HOLD,
        )

        incarceration_sentence = StateIncarcerationSentence.new_with_defaults(
            state_code="US_XX",
            incarceration_sentence_id=123,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_periods=[incarceration_period],
            start_date=date(2009, 2, 9),
            charges=[
                StateCharge.new_with_defaults(
                    state_code="US_XX",
                    status=ChargeStatus.PRESENT_WITHOUT_INFO,
                    ncic_code="5699",
                    statute="30A123",
                    offense_date=date(2009, 1, 9),
                )
            ],
        )

        sentence_group = StateSentenceGroup.new_with_defaults(
            state_code="US_XX",
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            sentence_group_id=123,
            incarceration_sentences=[incarceration_sentence],
        )

        incarceration_sentence.sentence_group = sentence_group

        incarceration_period.incarceration_sentences = [incarceration_sentence]

        fake_person_id_to_county_query_result = {
            "person_id": fake_person_id,
            "county_of_residence": _COUNTY_OF_RESIDENCE,
        }

        fake_incarceration_period_judicial_district_association_result = {
            "person_id": fake_person_id,
            "incarceration_period_id": 123,
            "judicial_district_code": "NW",
        }

        incarceration_events = [
            IncarcerationStayEvent(
                admission_reason=incarceration_period.admission_reason,
                admission_reason_raw_text=incarceration_period.
                admission_reason_raw_text,
                supervision_type_at_admission=
                StateSupervisionPeriodSupervisionType.PROBATION,
                state_code=incarceration_period.state_code,
                event_date=incarceration_period.admission_date,
                facility=incarceration_period.facility,
                county_of_residence=_COUNTY_OF_RESIDENCE,
                most_serious_offense_ncic_code="5699",
                most_serious_offense_statute="30A123",
                specialized_purpose_for_incarceration=
                StateSpecializedPurposeForIncarceration.PAROLE_BOARD_HOLD,
            ),
            IncarcerationAdmissionEvent(
                state_code=incarceration_period.state_code,
                event_date=incarceration_period.admission_date,
                facility=incarceration_period.facility,
                county_of_residence=_COUNTY_OF_RESIDENCE,
                admission_reason=incarceration_period.admission_reason,
                admission_reason_raw_text=incarceration_period.
                admission_reason_raw_text,
                supervision_type_at_admission=
                StateSupervisionPeriodSupervisionType.PROBATION,
                specialized_purpose_for_incarceration=
                StateSpecializedPurposeForIncarceration.PAROLE_BOARD_HOLD,
            ),
            IncarcerationReleaseEvent(
                state_code=incarceration_period.state_code,
                event_date=incarceration_period.release_date,
                facility=incarceration_period.facility,
                county_of_residence=_COUNTY_OF_RESIDENCE,
                release_reason=incarceration_period.release_reason,
                admission_reason=incarceration_period.admission_reason,
                total_days_incarcerated=(
                    incarceration_period.release_date -
                    incarceration_period.admission_date).days,
                purpose_for_incarceration=
                StateSpecializedPurposeForIncarceration.PAROLE_BOARD_HOLD,
            ),
        ]

        correct_output = [(fake_person_id, (fake_person, incarceration_events))
                          ]

        test_pipeline = TestPipeline()

        person_entities = {
            "person": [fake_person],
            "sentence_groups": [sentence_group],
            "incarceration_period_judicial_district_association":
            [fake_incarceration_period_judicial_district_association_result],
            "persons_to_recent_county_of_residence":
            [fake_person_id_to_county_query_result],
        }

        output = (test_pipeline
                  | beam.Create([(fake_person_id, person_entities)])
                  | "Identify Incarceration Events" >> beam.ParDo(
                      pipeline.ClassifyIncarcerationEvents()))

        assert_that(output, equal_to(correct_output))

        test_pipeline.run()
コード例 #22
0
    def test_ssvrFlatFieldMatchingWithSomeNullValues(self):
        db_person = generate_person()
        db_supervision_violation_response = \
            generate_supervision_violation_response(
                person=db_person,
                state_code=_US_MO,
                response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION.value,
                response_type_raw_text=StateSupervisionViolationResponseType.PERMANENT_DECISION.value,
                deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD.value,
                deciding_body_type_raw_text=StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD.value,
            )
        db_incarceration_period = \
            generate_incarceration_period(
                person=db_person,
                state_code=_US_MO,
                external_id=_EXTERNAL_ID,
                admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION.value,
                source_supervision_violation_response=db_supervision_violation_response)
        db_incarceration_sentence = generate_incarceration_sentence(
            person=db_person,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value,
            state_code=_US_MO,
            external_id=_EXTERNAL_ID,
            incarceration_periods=[db_incarceration_period])
        db_sentence_group = generate_sentence_group(
            person=db_person,
            state_code=_US_MO,
            external_id=_EXTERNAL_ID_WITH_SUFFIX,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value,
            incarceration_sentences=[db_incarceration_sentence],
            supervision_sentences=[])
        db_external_id = generate_external_id(person=db_person,
                                              state_code=_US_MO,
                                              id_type=_ID_TYPE,
                                              external_id=_EXTERNAL_ID)
        db_person.external_ids = [db_external_id]
        db_person.sentence_groups = [db_sentence_group]

        self._commit_to_db(db_person)

        # Even though this violation response doesn't have a deciding_body_type set, it will not clear the values in
        # db_supervision_violation_response.
        supervision_violation_response = \
            StateSupervisionViolationResponse.new_with_defaults(
                state_code=_US_MO,
                response_type=StateSupervisionViolationResponseType.PERMANENT_DECISION,
                response_type_raw_text=StateSupervisionViolationResponseType.PERMANENT_DECISION.value)
        incarceration_period = \
            StateIncarcerationPeriod.new_with_defaults(
                state_code=_US_MO,
                external_id=_EXTERNAL_ID,
                admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION,
                source_supervision_violation_response=supervision_violation_response)
        incarceration_sentence = StateIncarcerationSentence.new_with_defaults(
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            state_code=_US_MO,
            external_id=_EXTERNAL_ID,
            incarceration_periods=[incarceration_period])
        sentence_group = StateSentenceGroup.new_with_defaults(
            state_code=_US_MO,
            external_id=_EXTERNAL_ID_WITH_SUFFIX,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            incarceration_sentences=[incarceration_sentence],
            supervision_sentences=[])
        external_id = StatePersonExternalId.new_with_defaults(
            state_code=_US_MO, id_type=_ID_TYPE, external_id=_EXTERNAL_ID)
        person = StatePerson.new_with_defaults(
            sentence_groups=[sentence_group], external_ids=[external_id])

        expected_person = self.to_entity(db_person)

        # Act 1 - Match
        session = self._session()
        matched_entities = entity_matching.match(session,
                                                 _US_MO,
                                                 ingested_people=[person])

        self.assert_people_match_pre_and_post_commit([expected_person],
                                                     matched_entities.people,
                                                     session)
        self.assertEqual(0, matched_entities.error_count)
        self.assertEqual(1, matched_entities.total_root_entities)
コード例 #23
0
    def testConvert_FullIngestInfo(self):
        # Arrange
        metadata = IngestMetadata('us_nd',
                                  _JURISDICTION_ID,
                                  _INGEST_TIME,
                                  system_level=SystemLevel.STATE)

        ingest_info = IngestInfo()
        ingest_info.state_agents.add(state_agent_id='AGENT_ID1',
                                     full_name='AGENT WILLIAMS')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID2',
                                     full_name='AGENT HERNANDEZ')
        ingest_info.state_agents.add(state_agent_id='AGENT_ID3',
                                     full_name='AGENT SMITH')
        ingest_info.state_agents.add(state_agent_id='JUDGE_AGENT_ID_1',
                                     full_name='JUDGE JUDY')

        # We expect the external_ids coming in to have the format
        # [type]:[external_id]
        ii_person_external_id_1 = US_ND_ELITE + ':' + 'EXTERNAL_ID1'
        ii_person_external_id_2 = US_ND_SID + ':' + 'EXTERNAL_ID2'

        ingest_info.state_people.add(
            state_person_id='PERSON_ID',
            state_person_race_ids=['RACE_ID1', 'RACE_ID2'],
            state_person_ethnicity_ids=['ETHNICITY_ID'],
            state_alias_ids=['ALIAS_ID1', 'ALIAS_ID2'],
            state_person_external_ids_ids=[
                ii_person_external_id_1, ii_person_external_id_2
            ],
            state_assessment_ids=['ASSESSMENT_ID'],
            state_sentence_group_ids=['GROUP_ID1', 'GROUP_ID2'])
        ingest_info.state_person_races.add(
            state_person_race_id='RACE_ID1',
            race='WHITE',
        )
        ingest_info.state_person_races.add(state_person_race_id='RACE_ID2',
                                           race='OTHER')
        ingest_info.state_person_ethnicities.add(
            state_person_ethnicity_id='ETHNICITY_ID', ethnicity='HISPANIC')
        ingest_info.state_aliases.add(state_alias_id='ALIAS_ID1',
                                      full_name='LONNY BREAUX')
        ingest_info.state_aliases.add(state_alias_id='ALIAS_ID2',
                                      full_name='FRANK OCEAN')
        ingest_info.state_person_external_ids.add(
            state_person_external_id_id=ii_person_external_id_1,
            id_type=US_ND_ELITE)
        ingest_info.state_person_external_ids.add(
            state_person_external_id_id=ii_person_external_id_2,
            id_type=US_ND_SID)
        ingest_info.state_assessments.add(state_assessment_id='ASSESSMENT_ID',
                                          assessment_class='MENTAL_HEALTH',
                                          conducting_agent_id='AGENT_ID1')
        ingest_info.state_sentence_groups.add(
            state_sentence_group_id='GROUP_ID1',
            state_supervision_sentence_ids=['SUPERVISION_SENTENCE_ID1'],
            state_incarceration_sentence_ids=[
                'INCARCERATION_SENTENCE_ID1', 'INCARCERATION_SENTENCE_ID2'
            ])
        ingest_info.state_sentence_groups.add(
            state_sentence_group_id='GROUP_ID2',
            state_supervision_sentence_ids=['SUPERVISION_SENTENCE_ID2'],
            state_fine_ids=['FINE_ID'])
        ingest_info.state_fines.add(state_fine_id='FINE_ID', status='PAID')
        ingest_info.state_supervision_sentences.add(
            state_supervision_sentence_id='SUPERVISION_SENTENCE_ID1',
            state_charge_ids=['CHARGE_ID1', 'CHARGE_ID2'],
            state_supervision_period_ids=['S_PERIOD_ID1'])
        ingest_info.state_supervision_sentences.add(
            state_supervision_sentence_id='SUPERVISION_SENTENCE_ID2',
            state_charge_ids=['CHARGE_ID2'],
            state_supervision_period_ids=['S_PERIOD_ID2'])
        ingest_info.state_incarceration_sentences.add(
            state_incarceration_sentence_id='INCARCERATION_SENTENCE_ID1',
            state_charge_ids=['CHARGE_ID1'],
            state_incarceration_period_ids=['I_PERIOD_ID'])
        ingest_info.state_incarceration_sentences.add(
            state_incarceration_sentence_id='INCARCERATION_SENTENCE_ID2',
            state_charge_ids=['CHARGE_ID2', 'CHARGE_ID3'],
            state_supervision_period_ids=['S_PERIOD_ID3'])
        ingest_info.state_charges.add(
            state_charge_id='CHARGE_ID1',
            state_court_case_id='CASE_ID',
            state_bond_id='BOND_ID',
            classification_type='M',
            classification_subtype='1',
        )
        ingest_info.state_charges.add(
            state_charge_id='CHARGE_ID2',
            state_court_case_id='CASE_ID',
            classification_type='M',
            classification_subtype='2',
        )
        ingest_info.state_charges.add(state_charge_id='CHARGE_ID3',
                                      state_court_case_id='CASE_ID',
                                      classification_type='F',
                                      classification_subtype='3')
        ingest_info.state_court_cases.add(
            state_court_case_id='CASE_ID',
            judge_id='JUDGE_AGENT_ID_1',
        )
        ingest_info.state_bonds.add(state_bond_id='BOND_ID', status='POSTED')
        ingest_info.state_supervision_periods.add(
            state_supervision_period_id='S_PERIOD_ID1',
            state_supervision_violation_ids=['VIOLATION_ID'],
            supervision_type='PAROLE',
            supervision_level='MED')
        ingest_info.state_supervision_periods.add(
            state_supervision_period_id='S_PERIOD_ID2',
            supervision_type='PAROLE')
        ingest_info.state_supervision_periods.add(
            state_supervision_period_id='S_PERIOD_ID3',
            state_assessment_ids=['ASSESSMENT_ID'],
            supervision_type='PROBATION')
        ingest_info.state_incarceration_periods.add(
            state_incarceration_period_id='I_PERIOD_ID',
            state_incarceration_incident_ids=['INCIDENT_ID'],
            state_parole_decision_ids=['DECISION_ID'],
            state_assessment_ids=['ASSESSMENT_ID'],
        )
        ingest_info.state_supervision_violations.add(
            state_supervision_violation_id='VIOLATION_ID',
            state_supervision_violation_response_ids=['RESPONSE_ID'])
        ingest_info.state_supervision_violation_responses.add(
            state_supervision_violation_response_id='RESPONSE_ID',
            response_type='CITATION')
        ingest_info.state_incarceration_incidents.add(
            state_incarceration_incident_id='INCIDENT_ID',
            incident_type='CONTRABAND',
            responding_officer_id='AGENT_ID2',
            state_incarceration_incident_outcome_ids=['INCIDENT_OUTCOME_ID'],
        )

        ingest_info.state_incarceration_incident_outcomes.add(
            state_incarceration_incident_outcome_id='INCIDENT_OUTCOME_ID',
            outcome_type='GOOD_TIME_LOSS',
            date_effective='2/10/2018',
            state_code='US_ND',
            outcome_description='Good time',
            punishment_length_days='7',
        )
        ingest_info.state_parole_decisions.add(
            state_parole_decision_id='DECISION_ID',
            decision_agent_ids=['AGENT_ID2', 'AGENT_ID3'])

        # Act
        result = self._convert_and_throw_on_errors(ingest_info, metadata)

        # Assert
        incident_outcome = StateIncarcerationIncidentOutcome.new_with_defaults(
            external_id='INCIDENT_OUTCOME_ID',
            outcome_type=StateIncarcerationIncidentOutcomeType.GOOD_TIME_LOSS,
            outcome_type_raw_text='GOOD_TIME_LOSS',
            date_effective=datetime.date(year=2018, month=2, day=10),
            state_code='US_ND',
            outcome_description='GOOD TIME',
            punishment_length_days=7,
        )

        incident = StateIncarcerationIncident.new_with_defaults(
            external_id='INCIDENT_ID',
            state_code='US_ND',
            incident_type=StateIncarcerationIncidentType.CONTRABAND,
            incident_type_raw_text='CONTRABAND',
            responding_officer=StateAgent.new_with_defaults(
                external_id='AGENT_ID2',
                state_code='US_ND',
                full_name='{"full_name": "AGENT HERNANDEZ"}',
            ),
            incarceration_incident_outcomes=[incident_outcome])

        assessment = StateAssessment.new_with_defaults(
            external_id='ASSESSMENT_ID',
            state_code='US_ND',
            assessment_class=StateAssessmentClass.MENTAL_HEALTH,
            assessment_class_raw_text='MENTAL_HEALTH',
            conducting_agent=StateAgent.new_with_defaults(
                external_id='AGENT_ID1',
                state_code='US_ND',
                full_name='{"full_name": "AGENT WILLIAMS"}',
            ))

        violation = StateSupervisionViolation.new_with_defaults(
            external_id='VIOLATION_ID',
            state_code='US_ND',
            supervision_violation_responses=[
                StateSupervisionViolationResponse.new_with_defaults(
                    external_id='RESPONSE_ID',
                    state_code='US_ND',
                    response_type=StateSupervisionViolationResponseType.
                    CITATION,
                    response_type_raw_text='CITATION')
            ])

        court_case = StateCourtCase.new_with_defaults(
            external_id='CASE_ID',
            state_code='US_ND',
            status=StateCourtCaseStatus.PRESENT_WITHOUT_INFO,
            court_type=StateCourtType.PRESENT_WITHOUT_INFO,
            judge=StateAgent.new_with_defaults(
                external_id='JUDGE_AGENT_ID_1',
                state_code='US_ND',
                full_name='{"full_name": "JUDGE JUDY"}',
            ))

        charge_1 = StateCharge.new_with_defaults(
            external_id='CHARGE_ID1',
            classification_type=StateChargeClassificationType.MISDEMEANOR,
            classification_type_raw_text='M',
            classification_subtype='1',
            state_code='US_ND',
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            court_case=court_case,
            bond=StateBond.new_with_defaults(external_id='BOND_ID',
                                             state_code='US_ND',
                                             status=BondStatus.POSTED,
                                             status_raw_text='POSTED'))

        charge_2 = StateCharge.new_with_defaults(
            external_id='CHARGE_ID2',
            classification_type=StateChargeClassificationType.MISDEMEANOR,
            classification_type_raw_text='M',
            classification_subtype='2',
            state_code='US_ND',
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            court_case=court_case)

        charge_3 = StateCharge.new_with_defaults(
            external_id='CHARGE_ID3',
            state_code='US_ND',
            classification_type=StateChargeClassificationType.FELONY,
            classification_type_raw_text='F',
            classification_subtype='3',
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            court_case=court_case)

        expected_result = [
            StatePerson.new_with_defaults(
                external_ids=[
                    StatePersonExternalId.new_with_defaults(
                        external_id='EXTERNAL_ID1',
                        state_code='US_ND',
                        id_type=US_ND_ELITE),
                    StatePersonExternalId.new_with_defaults(
                        external_id='EXTERNAL_ID2',
                        state_code='US_ND',
                        id_type=US_ND_SID)
                ],
                races=[
                    StatePersonRace(race=Race.WHITE,
                                    race_raw_text='WHITE',
                                    state_code='US_ND'),
                    StatePersonRace(race=Race.OTHER,
                                    race_raw_text='OTHER',
                                    state_code='US_ND'),
                ],
                ethnicities=[
                    StatePersonEthnicity(ethnicity=Ethnicity.HISPANIC,
                                         ethnicity_raw_text='HISPANIC',
                                         state_code='US_ND')
                ],
                aliases=[
                    StatePersonAlias.new_with_defaults(
                        full_name='{"full_name": "LONNY BREAUX"}',
                        state_code='US_ND'),
                    StatePersonAlias.new_with_defaults(
                        full_name='{"full_name": "FRANK OCEAN"}',
                        state_code='US_ND'),
                ],
                assessments=[assessment],
                sentence_groups=[
                    StateSentenceGroup.new_with_defaults(
                        external_id='GROUP_ID1',
                        status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                        state_code='US_ND',
                        supervision_sentences=[
                            StateSupervisionSentence.new_with_defaults(
                                external_id='SUPERVISION_SENTENCE_ID1',
                                state_code='US_ND',
                                status=StateSentenceStatus.
                                PRESENT_WITHOUT_INFO,
                                charges=[charge_1, charge_2],
                                supervision_periods=[
                                    StateSupervisionPeriod.new_with_defaults(
                                        external_id='S_PERIOD_ID1',
                                        status=StateSupervisionPeriodStatus.
                                        PRESENT_WITHOUT_INFO,
                                        supervision_level=StateSupervisionLevel
                                        .MEDIUM,
                                        supervision_level_raw_text='MED',
                                        state_code='US_ND',
                                        supervision_type=StateSupervisionType.
                                        PAROLE,
                                        supervision_type_raw_text='PAROLE',
                                        supervision_violations=[violation])
                                ])
                        ],
                        incarceration_sentences=[
                            StateIncarcerationSentence.new_with_defaults(
                                external_id='INCARCERATION_SENTENCE_ID1',
                                state_code='US_ND',
                                status=StateSentenceStatus.
                                PRESENT_WITHOUT_INFO,
                                incarceration_type=StateIncarcerationType.
                                STATE_PRISON,
                                charges=[charge_1],
                                incarceration_periods=[
                                    StateIncarcerationPeriod.new_with_defaults(
                                        external_id='I_PERIOD_ID',
                                        status=StateIncarcerationPeriodStatus.
                                        PRESENT_WITHOUT_INFO,
                                        incarceration_type=
                                        StateIncarcerationType.STATE_PRISON,
                                        state_code='US_ND',
                                        incarceration_incidents=[incident],
                                        parole_decisions=[
                                            StateParoleDecision.
                                            new_with_defaults(
                                                external_id='DECISION_ID',
                                                state_code='US_ND',
                                                decision_agents=[
                                                    StateAgent.
                                                    new_with_defaults(
                                                        external_id='AGENT_ID2',
                                                        state_code='US_ND',
                                                        full_name=
                                                        '{"full_name": '
                                                        '"AGENT HERNANDEZ"}'),
                                                    StateAgent.
                                                    new_with_defaults(
                                                        external_id='AGENT_ID3',
                                                        state_code='US_ND',
                                                        full_name=
                                                        '{"full_name": '
                                                        '"AGENT SMITH"}')
                                                ])
                                        ],
                                        assessments=[assessment],
                                    )
                                ]),
                            StateIncarcerationSentence.new_with_defaults(
                                external_id='INCARCERATION_SENTENCE_ID2',
                                state_code='US_ND',
                                status=StateSentenceStatus.
                                PRESENT_WITHOUT_INFO,
                                incarceration_type=StateIncarcerationType.
                                STATE_PRISON,
                                charges=[charge_2, charge_3],
                                supervision_periods=[
                                    StateSupervisionPeriod.new_with_defaults(
                                        external_id='S_PERIOD_ID3',
                                        status=StateSupervisionPeriodStatus.
                                        PRESENT_WITHOUT_INFO,
                                        state_code='US_ND',
                                        supervision_type=StateSupervisionType.
                                        PROBATION,
                                        supervision_type_raw_text='PROBATION',
                                        assessments=[assessment])
                                ])
                        ]),
                    StateSentenceGroup.new_with_defaults(
                        external_id='GROUP_ID2',
                        status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
                        state_code='US_ND',
                        supervision_sentences=[
                            StateSupervisionSentence.new_with_defaults(
                                external_id='SUPERVISION_SENTENCE_ID2',
                                state_code='US_ND',
                                status=StateSentenceStatus.
                                PRESENT_WITHOUT_INFO,
                                charges=[charge_2],
                                supervision_periods=[
                                    StateSupervisionPeriod.new_with_defaults(
                                        external_id='S_PERIOD_ID2',
                                        status=StateSupervisionPeriodStatus.
                                        PRESENT_WITHOUT_INFO,
                                        state_code='US_ND',
                                        supervision_type=StateSupervisionType.
                                        PAROLE,
                                        supervision_type_raw_text='PAROLE',
                                    )
                                ])
                        ],
                        fines=[
                            StateFine.new_with_defaults(
                                external_id='FINE_ID',
                                state_code='US_ND',
                                status=StateFineStatus.PAID,
                                status_raw_text='PAID')
                        ])
                ])
        ]

        print(expected_result, "\n\n\n", result)

        self.assertEqual(result, expected_result)