def test_find_program_referrals_assessment_after_referral(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
            referral_date=date(2009, 10, 3))

        assessment_1 = StateAssessment.new_with_defaults(
            state_code='US_CA',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 3, 10))

        assessment_2 = StateAssessment.new_with_defaults(
            state_code='US_CA',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=29,
            assessment_date=date(2009, 10, 4))

        program_assignments = [program_assignment]
        assessments = [assessment_1, assessment_2]
        supervision_periods = []

        program_referrals = identifier.find_program_referrals(
            program_assignments, assessments, supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS)

        self.assertEqual(1, len(program_referrals))

        self.assertEqual([
            ProgramReferralEvent(state_code=program_assignment.state_code,
                                 program_id=program_assignment.program_id,
                                 event_date=program_assignment.referral_date,
                                 assessment_score=33,
                                 assessment_type=StateAssessmentType.ORAS)
        ], program_referrals)
Beispiel #2
0
    def test_find_program_referrals_multiple_assessments(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_XX",
            program_id="PG3",
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            IN_PROGRESS,
        )

        assessment_1 = StateAssessment.new_with_defaults(
            state_code="US_XX",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 3, 10),
        )

        assessment_2 = StateAssessment.new_with_defaults(
            state_code="US_XX",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=29,
            assessment_date=date(2009, 9, 14),
        )

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            status=StateSupervisionPeriodStatus.TERMINATED,
            state_code="US_XX",
            start_date=date(2008, 3, 5),
            termination_date=date(2010, 5, 19),
            termination_reason=StateSupervisionPeriodTerminationReason.
            DISCHARGE,
            supervision_type=StateSupervisionType.PAROLE,
        )

        assessments = [assessment_1, assessment_2]
        supervision_periods = [supervision_period]

        program_referrals = identifier.find_program_referrals(
            program_assignment,
            assessments,
            supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS,
        )

        self.assertListEqual(
            [
                ProgramReferralEvent(
                    state_code=program_assignment.state_code,
                    program_id=program_assignment.program_id,
                    event_date=program_assignment.referral_date,
                    participation_status=program_assignment.
                    participation_status,
                    assessment_score=29,
                    assessment_type=StateAssessmentType.ORAS,
                    supervision_type=supervision_period.supervision_type,
                )
            ],
            program_referrals,
        )
Beispiel #3
0
    def test_find_program_referrals_officer_info(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            DISCHARGED,
        )

        assessment = StateAssessment.new_with_defaults(
            state_code='US_CA',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 7, 10))

        supervision_period = \
            StateSupervisionPeriod.new_with_defaults(
                supervision_period_id=111,
                status=StateSupervisionPeriodStatus.TERMINATED,
                state_code='UT',
                start_date=date(2008, 3, 5),
                termination_date=date(2010, 5, 19),
                termination_reason=
                StateSupervisionPeriodTerminationReason.DISCHARGE,
                supervision_type=StateSupervisionType.PAROLE
            )

        program_assignments = [program_assignment]
        assessments = [assessment]
        supervision_periods = [supervision_period]

        supervision_period_agent_associations = {
            supervision_period.supervision_period_id: {
                'agent_id': 000,
                'agent_external_id': 'OFFICER10',
                'district_external_id': 'DISTRICT8',
                'supervision_period_id':
                supervision_period.supervision_period_id
            }
        }

        program_referrals = identifier.find_program_referrals(
            program_assignments, assessments, supervision_periods,
            supervision_period_agent_associations)

        self.assertEqual(1, len(program_referrals))

        self.assertEqual([
            ProgramReferralEvent(
                state_code=program_assignment.state_code,
                program_id=program_assignment.program_id,
                event_date=program_assignment.referral_date,
                participation_status=program_assignment.participation_status,
                assessment_score=33,
                assessment_type=StateAssessmentType.ORAS,
                supervision_type=supervision_period.supervision_type,
                supervising_officer_external_id='OFFICER10',
                supervising_district_external_id='DISTRICT8')
        ], program_referrals)
Beispiel #4
0
    def test_find_program_participation_events_not_actively_participating(
            self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_XX",
            program_id="PG3",
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            DISCHARGED,
            program_location_id="LOCATION",
            start_date=date(2009, 11, 5),
            discharge_date=date(2009, 11, 8),
        )

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            status=StateSupervisionPeriodStatus.UNDER_SUPERVISION,
            state_code="US_XX",
            start_date=date(1990, 3, 5),
            supervision_type=StateSupervisionType.PAROLE,
        )

        supervision_periods = [supervision_period]

        participation_events = identifier.find_program_participation_events(
            program_assignment, supervision_periods)

        expected_events = [
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                program_id=program_assignment.program_id,
                event_date=program_assignment.start_date,
                is_first_day_in_program=True,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type,
            ),
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                program_id=program_assignment.program_id,
                event_date=program_assignment.start_date +
                relativedelta(days=1),
                is_first_day_in_program=False,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type,
            ),
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                program_id=program_assignment.program_id,
                event_date=program_assignment.start_date +
                relativedelta(days=2),
                is_first_day_in_program=False,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type,
            ),
        ]

        self.assertListEqual(expected_events, participation_events)
Beispiel #5
0
    def test_find_program_events(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
            referral_date=date(2020, 1, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            IN_PROGRESS,
            program_location_id='LOCATION X',
            start_date=date(2020, 1, 1))

        assessment = StateAssessment.new_with_defaults(
            state_code='US_CA',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2019, 7, 10))

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            status=StateSupervisionPeriodStatus.TERMINATED,
            state_code='UT',
            start_date=date(2019, 3, 5),
            supervision_type=StateSupervisionType.PAROLE)

        program_assignments = [program_assignment]
        assessments = [assessment]
        supervision_periods = [supervision_period]

        program_events = identifier.find_program_events(
            program_assignments, assessments, supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS)

        expected_events = [
            ProgramReferralEvent(
                state_code=program_assignment.state_code,
                event_date=program_assignment.referral_date,
                program_id=program_assignment.program_id,
                supervision_type=supervision_period.supervision_type,
                participation_status=program_assignment.participation_status,
                assessment_score=assessment.assessment_score,
                assessment_type=assessment.assessment_type),
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                event_date=program_assignment.start_date,
                program_id=program_assignment.program_id,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type),
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                event_date=program_assignment.start_date +
                relativedelta(days=1),
                program_id=program_assignment.program_id,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type)
        ]

        self.assertListEqual(program_events, expected_events)
    def test_find_program_referrals(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_XX",
            program_id="PG3",
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            IN_PROGRESS,
        )

        assessment = StateAssessment.new_with_defaults(
            state_code="US_XX",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 7, 10),
        )

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=999,
            status=StateSupervisionPeriodStatus.TERMINATED,
            state_code="US_XX",
            start_date=date(2008, 3, 5),
            termination_date=date(2010, 5, 19),
            termination_reason=StateSupervisionPeriodTerminationReason.
            DISCHARGE,
            supervision_type=StateSupervisionType.PAROLE,
            supervision_site="OFFICE_1",
        )

        assessments = [assessment]
        supervision_periods = [supervision_period]

        program_referrals = self.identifier._find_program_referrals(
            program_assignment,
            assessments,
            supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS,
        )

        self.assertListEqual(
            [
                ProgramReferralEvent(
                    state_code=program_assignment.state_code,
                    program_id=program_assignment.program_id,
                    event_date=program_assignment.referral_date,
                    participation_status=program_assignment.
                    participation_status,
                    assessment_score=33,
                    assessment_type=StateAssessmentType.ORAS,
                    supervision_type=supervision_period.supervision_type,
                    supervising_officer_external_id="XXX",
                    supervising_district_external_id="OFFICE_1",
                    level_1_supervision_location_external_id="OFFICE_1",
                )
            ],
            program_referrals,
        )
Beispiel #7
0
    def test_find_program_referrals_no_referral(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
        )

        assessments = []
        supervision_periods = []

        program_referrals = identifier.find_program_referrals(
            program_assignment, assessments, supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS)

        self.assertListEqual([], program_referrals)
    def test_find_program_referrals_multiple_assessments(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
            referral_date=date(2009, 10, 3))

        assessment_1 = StateAssessment.new_with_defaults(
            state_code='US_CA',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 3, 10))

        assessment_2 = StateAssessment.new_with_defaults(
            state_code='US_CA',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=29,
            assessment_date=date(2009, 9, 14))

        supervision_period = \
            StateSupervisionPeriod.new_with_defaults(
                supervision_period_id=111,
                status=StateSupervisionPeriodStatus.TERMINATED,
                state_code='UT',
                start_date=date(2008, 3, 5),
                termination_date=date(2010, 5, 19),
                termination_reason=
                StateSupervisionPeriodTerminationReason.DISCHARGE,
                supervision_type=StateSupervisionType.PAROLE
            )

        program_assignments = [program_assignment]
        assessments = [assessment_1, assessment_2]
        supervision_periods = [supervision_period]

        program_referrals = identifier.find_program_referrals(
            program_assignments, assessments, supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS)

        self.assertEqual(1, len(program_referrals))

        self.assertEqual([
            ProgramReferralEvent(
                state_code=program_assignment.state_code,
                program_id=program_assignment.program_id,
                event_date=program_assignment.referral_date,
                assessment_score=29,
                assessment_type=StateAssessmentType.ORAS,
                supervision_type=supervision_period.supervision_type)
        ], program_referrals)
Beispiel #9
0
    def test_find_program_participation_events_no_start_date(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
            referral_date=date(1999, 10, 3),
            # This program assignment is in progress, but it's missing a required start_date
            participation_status=StateProgramAssignmentParticipationStatus.
            IN_PROGRESS,
            program_location_id='LOCATION')

        supervision_periods = []

        participation_events = identifier.find_program_participation_events(
            program_assignment, supervision_periods)

        self.assertEqual([], participation_events)
Beispiel #10
0
    def test_find_program_referrals_assessment_after_referral(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_XX",
            program_id="PG3",
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            DISCHARGED,
        )

        assessment_1 = StateAssessment.new_with_defaults(
            state_code="US_XX",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 3, 10),
        )

        assessment_2 = StateAssessment.new_with_defaults(
            state_code="US_XX",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=29,
            assessment_date=date(2009, 10, 4),
        )

        assessments = [assessment_1, assessment_2]
        supervision_periods = []

        program_referrals = identifier.find_program_referrals(
            program_assignment,
            assessments,
            supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS,
        )

        self.assertListEqual(
            [
                ProgramReferralEvent(
                    state_code=program_assignment.state_code,
                    program_id=program_assignment.program_id,
                    event_date=program_assignment.referral_date,
                    participation_status=program_assignment.
                    participation_status,
                    assessment_score=33,
                    assessment_type=StateAssessmentType.ORAS,
                )
            ],
            program_referrals,
        )
Beispiel #11
0
    def test_find_program_participation_events_no_discharge_date(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_CA',
            program_id='PG3',
            referral_date=date(1999, 10, 3),
            # This program assignment has a DISCHARGED status, but it's missing a required discharge_date
            participation_status=StateProgramAssignmentParticipationStatus.
            DISCHARGED,
            program_location_id='LOCATION',
            start_date=date(1999, 11, 2))

        supervision_periods = []

        participation_events = identifier.find_program_participation_events(
            program_assignment, supervision_periods)

        self.assertEqual([], participation_events)
Beispiel #12
0
    def test_find_program_referrals_no_referral(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_XX",
            program_id="PG3",
            participation_status=StateProgramAssignmentParticipationStatus.
            PRESENT_WITHOUT_INFO,
        )

        assessments = []
        supervision_periods = []

        program_referrals = identifier.find_program_referrals(
            program_assignment,
            assessments,
            supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS,
        )

        self.assertListEqual([], program_referrals)
Beispiel #13
0
    def test_find_program_participation_events(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_XX',
            program_id='PG3',
            referral_date=date(1999, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.IN_PROGRESS,
            program_location_id='LOCATION',
            start_date=date(1999, 12, 31)
        )

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            status=StateSupervisionPeriodStatus.UNDER_SUPERVISION,
            state_code='US_XX',
            start_date=date(1990, 3, 5),
            supervision_type=StateSupervisionType.PAROLE
        )

        supervision_periods = [supervision_period]

        participation_events = identifier.find_program_participation_events(
            program_assignment, supervision_periods
        )

        expected_events = [ProgramParticipationEvent(
            state_code=program_assignment.state_code,
            program_id=program_assignment.program_id,
            event_date=program_assignment.start_date,
            is_first_day_in_program=True,
            program_location_id=program_assignment.program_location_id,
            supervision_type=supervision_period.supervision_type
        ), ProgramParticipationEvent(
            state_code=program_assignment.state_code,
            program_id=program_assignment.program_id,
            event_date=program_assignment.start_date + relativedelta(days=1),
            is_first_day_in_program=False,
            program_location_id=program_assignment.program_location_id,
            supervision_type=supervision_period.supervision_type
        )]

        self.assertListEqual(expected_events, participation_events)
Beispiel #14
0
    def test_find_program_referrals_multiple_supervisions(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code='US_XX',
            program_id='PG3',
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.PENDING,
        )

        assessment = StateAssessment.new_with_defaults(
            state_code='US_XX',
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 7, 10)
        )

        supervision_period_1 = \
            StateSupervisionPeriod.new_with_defaults(
                supervision_period_id=111,
                status=StateSupervisionPeriodStatus.TERMINATED,
                state_code='US_XX',
                start_date=date(2008, 3, 5),
                termination_date=date(2010, 5, 19),
                termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE,
                supervision_type=StateSupervisionType.PAROLE
            )

        supervision_period_2 = \
            StateSupervisionPeriod.new_with_defaults(
                supervision_period_id=111,
                status=StateSupervisionPeriodStatus.TERMINATED,
                state_code='US_XX',
                start_date=date(2006, 12, 1),
                termination_date=date(2013, 1, 4),
                termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE,
                supervision_type=StateSupervisionType.PROBATION
            )

        assessments = [assessment]
        supervision_periods = [supervision_period_1, supervision_period_2]

        program_referrals = identifier.find_program_referrals(
            program_assignment, assessments, supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS
        )

        self.assertListEqual(
            [
                ProgramReferralEvent(
                    state_code=program_assignment.state_code,
                    program_id=program_assignment.program_id,
                    event_date=program_assignment.referral_date,
                    participation_status=program_assignment.participation_status,
                    assessment_score=33,
                    assessment_type=StateAssessmentType.ORAS,
                    supervision_type=supervision_period_1.supervision_type
                ),
                ProgramReferralEvent(
                    state_code=program_assignment.state_code,
                    program_id=program_assignment.program_id,
                    event_date=program_assignment.referral_date,
                    participation_status=program_assignment.participation_status,
                    assessment_score=33,
                    assessment_type=StateAssessmentType.ORAS,
                    supervision_type=supervision_period_2.supervision_type
                )

            ], program_referrals)
    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',
            hearing_date='2/6/2018',
            report_date='2/8/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),
            hearing_date=datetime.date(year=2018, month=2, day=6),
            report_date=datetime.date(year=2018, month=2, day=8),
            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(
                state_code='US_ND',
                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)
Beispiel #16
0
    def test_find_program_referrals_officer_info_us_nd(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_ND",
            program_id="PG3",
            referral_date=date(2009, 10, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            DISCHARGED,
        )

        assessment = StateAssessment.new_with_defaults(
            state_code="US_ND",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2009, 7, 10),
        )

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=111,
            status=StateSupervisionPeriodStatus.TERMINATED,
            state_code="US_ND",
            start_date=date(2008, 3, 5),
            termination_date=date(2010, 5, 19),
            termination_reason=StateSupervisionPeriodTerminationReason.
            DISCHARGE,
            supervision_type=StateSupervisionType.PAROLE,
            supervision_site="DISTRICT8",
        )

        assessments = [assessment]
        supervision_periods = [supervision_period]

        supervision_period_agent_associations = {
            supervision_period.supervision_period_id: {
                "agent_id": 000,
                "agent_external_id": "OFFICER10",
                "supervision_period_id":
                supervision_period.supervision_period_id,
            }
        }

        program_referrals = identifier.find_program_referrals(
            program_assignment,
            assessments,
            supervision_periods,
            supervision_period_agent_associations,
        )
        self.maxDiff = None
        self.assertListEqual(
            [
                ProgramReferralEvent(
                    state_code=program_assignment.state_code,
                    program_id=program_assignment.program_id,
                    event_date=program_assignment.referral_date,
                    participation_status=program_assignment.
                    participation_status,
                    assessment_score=33,
                    assessment_type=StateAssessmentType.ORAS,
                    supervision_type=supervision_period.supervision_type,
                    supervising_officer_external_id="OFFICER10",
                    supervising_district_external_id="DISTRICT8",
                    level_1_supervision_location_external_id="DISTRICT8",
                    level_2_supervision_location_external_id=None,
                )
            ],
            program_referrals,
        )
Beispiel #17
0
    def test_find_program_events(self):
        program_assignment = StateProgramAssignment.new_with_defaults(
            state_code="US_XX",
            program_id="PG3",
            referral_date=date(2020, 1, 3),
            participation_status=StateProgramAssignmentParticipationStatus.
            IN_PROGRESS,
            program_location_id="LOCATION X",
            start_date=date(2020, 1, 1),
        )

        assessment = StateAssessment.new_with_defaults(
            state_code="US_XX",
            assessment_type=StateAssessmentType.ORAS,
            assessment_score=33,
            assessment_date=date(2019, 7, 10),
        )

        supervision_period = StateSupervisionPeriod.new_with_defaults(
            supervision_period_id=999,
            status=StateSupervisionPeriodStatus.TERMINATED,
            state_code="US_XX",
            start_date=date(2019, 3, 5),
            termination_date=date(2020, 10, 1),
            supervision_type=StateSupervisionType.PAROLE,
            supervision_site="OFFICE_1",
        )

        program_assignments = [program_assignment]
        assessments = [assessment]
        supervision_periods = [supervision_period]

        program_events = identifier.find_program_events(
            program_assignments,
            assessments,
            supervision_periods,
            DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATION_LIST,
        )

        expected_events = [
            ProgramReferralEvent(
                state_code=program_assignment.state_code,
                event_date=program_assignment.referral_date,
                program_id=program_assignment.program_id,
                supervision_type=supervision_period.supervision_type,
                participation_status=program_assignment.participation_status,
                assessment_score=assessment.assessment_score,
                assessment_type=assessment.assessment_type,
                supervising_officer_external_id="XXX",
                supervising_district_external_id="OFFICE_1",
                level_1_supervision_location_external_id="OFFICE_1",
                level_2_supervision_location_external_id=None,
            ),
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                event_date=program_assignment.start_date,
                is_first_day_in_program=True,
                program_id=program_assignment.program_id,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type,
            ),
            ProgramParticipationEvent(
                state_code=program_assignment.state_code,
                event_date=program_assignment.start_date +
                relativedelta(days=1),
                is_first_day_in_program=False,
                program_id=program_assignment.program_id,
                program_location_id=program_assignment.program_location_id,
                supervision_type=supervision_period.supervision_type,
            ),
        ]

        self.assertListEqual(program_events, expected_events)
    def testConvert_FullIngestInfo(self):
        # Arrange
        metadata = FakeIngestMetadata.for_state(region="us_nd")

        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",
            hearing_date="2/6/2018",
            report_date="2/8/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),
            hearing_date=datetime.date(year=2018, month=2, day=6),
            report_date=datetime.date(year=2018, month=2, day=8),
            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(
                state_code="US_ND",
                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)
def generate_full_graph_state_person(set_back_edges: bool) -> entities.StatePerson:
    """Test util for generating a StatePerson that has at least one child of
    each possible Entity type, with all possible edge types defined between
    objects.

    Args:
        set_back_edges: explicitly sets all the back edges on the graph
            that will get automatically filled in when this entity graph is
            written to the DB.

    Returns:
        A test instance of a StatePerson.
    """
    person = entities.StatePerson.new_with_defaults(state_code="us_ca")

    person.external_ids = [
        entities.StatePersonExternalId.new_with_defaults(
            state_code="us_ca",
            external_id="ELITE_ID_123",
            id_type=US_ND_ELITE,
        )
    ]
    person.aliases = [
        entities.StatePersonAlias.new_with_defaults(
            state_code="us_ca",
            full_name="Beyoncé Giselle Knowles",
        ),
        entities.StatePersonAlias.new_with_defaults(
            state_code="us_ca",
            full_name="Beyoncé Giselle Knowles-Carter",
        ),
    ]

    person.races = [
        entities.StatePersonRace.new_with_defaults(
            state_code="us_ca", race=Race.ASIAN, race_raw_text="ASIAN"
        ),
        entities.StatePersonRace.new_with_defaults(
            state_code="us_ca", race=Race.BLACK, race_raw_text="BLACK"
        ),
    ]

    person.ethnicities = [
        entities.StatePersonEthnicity.new_with_defaults(
            state_code="us_ca",
            ethnicity=Ethnicity.NOT_HISPANIC,
            ethnicity_raw_text="NOT HISPANIC",
        )
    ]

    sentence_group = entities.StateSentenceGroup.new_with_defaults(
        external_id="BOOK_ID1234",
        status=StateSentenceStatus.SERVING,
        status_raw_text="SERVING",
        date_imposed=datetime.date(year=2016, month=10, day=14),
        state_code="us_ca",
        county_code="us_ca_san_francisco",
        min_length_days=90,
        max_length_days=120,
    )

    person.sentence_groups = [sentence_group]

    person_supervising_officer = entities.StateAgent.new_with_defaults(
        state_code="us_ca",
        external_id="SUPERVISING_OFFICER_ID",
        full_name="SUPERVISING OFFICER",
        agent_type=StateAgentType.PRESENT_WITHOUT_INFO,
    )
    person.supervising_officer = person_supervising_officer

    incarceration_sentence = entities.StateIncarcerationSentence.new_with_defaults(
        external_id="BOOK_ID1234-1",
        status=StateSentenceStatus.COMPLETED,
        status_raw_text="COMPLETED",
        incarceration_type=StateIncarcerationType.STATE_PRISON,
        incarceration_type_raw_text="PRISON",
        date_imposed=datetime.date(year=2018, month=7, day=3),
        projected_min_release_date=datetime.date(year=2017, month=5, day=14),
        projected_max_release_date=None,
        parole_eligibility_date=datetime.date(year=2018, month=5, day=14),
        state_code="us_ca",
        county_code="us_ca_san_francisco",
        #   - What
        # These will be None if is_life is true
        min_length_days=90,
        max_length_days=900,
        is_life=False,
        is_capital_punishment=False,
        parole_possible=True,
        initial_time_served_days=None,
        good_time_days=10,
        earned_time_days=None,
    )

    supervision_sentence = entities.StateSupervisionSentence.new_with_defaults(
        external_id="BOOK_ID1234-2",
        status=StateSentenceStatus.SERVING,
        status_raw_text="SERVING",
        supervision_type=StateSupervisionType.PAROLE,
        supervision_type_raw_text="PAROLE",
        projected_completion_date=datetime.date(year=2020, month=5, day=14),
        completion_date=None,
        state_code="us_ca",
        min_length_days=None,
        max_length_days=200,
    )

    fine = entities.StateFine.new_with_defaults(
        external_id="BOOK_ID1234-3",
        status=StateFineStatus.UNPAID,
        status_raw_text="UNPAID",
        date_paid=None,
        state_code="us_ca",
        fine_dollars=15000,
    )

    sentence_group.incarceration_sentences = [incarceration_sentence]
    sentence_group.supervision_sentences = [supervision_sentence]
    sentence_group.fines = [fine]

    judge = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.JUDGE,
        state_code="us_ca",
        full_name="JUDGE JUDY",
    )

    court_case = entities.StateCourtCase.new_with_defaults(
        external_id="CASEID456",
        status=StateCourtCaseStatus.EXTERNAL_UNKNOWN,
        date_convicted=datetime.date(year=2018, month=7, day=1),
        next_court_date=datetime.date(year=2019, month=7, day=1),
        state_code="us_ca",
        court_type=StateCourtType.PRESENT_WITHOUT_INFO,
        court_type_raw_text=None,
        court_fee_dollars=150,
        judge=judge,
    )

    bond = entities.StateBond.new_with_defaults(
        external_id="BONDID1456",
        status=BondStatus.POSTED,
        status_raw_text="POSTED",
        bond_type=BondType.CASH,
        bond_type_raw_text="CASH",
        date_paid=datetime.date(year=2015, month=7, day=1),
        state_code="us_ca",
        amount_dollars=45,
        bond_agent="CA BAILBONDSMEN",
    )

    charge = entities.StateCharge.new_with_defaults(
        external_id="CHARGE1_EXTERNAL_ID",
        status=ChargeStatus.CONVICTED,
        status_raw_text="CONVICTED",
        offense_date=datetime.date(year=2003, month=7, day=1),
        date_charged=datetime.date(year=2003, month=8, day=1),
        state_code="us_ca",
        statute="A102.3",
        description="DRUG POSSESSION",
        attempted=True,
        classification_type=StateChargeClassificationType.FELONY,
        classification_type_raw_text="F",
        classification_subtype="A",
        counts=1,
        charge_notes=None,
        court_case=court_case,
        bond=None,
    )

    charge2 = entities.StateCharge.new_with_defaults(
        external_id="CHARGE2_EXTERNAL_ID",
        status=ChargeStatus.CONVICTED,
        status_raw_text="CONVICTED",
        offense_date=datetime.date(year=2003, month=7, day=1),
        date_charged=datetime.date(year=2003, month=8, day=1),
        state_code="us_ca",
        statute="A102.3",
        description="DRUG POSSESSION",
        attempted=True,
        classification_type=StateChargeClassificationType.FELONY,
        classification_type_raw_text="F",
        classification_subtype="B",
        counts=1,
        charge_notes=None,
        court_case=court_case,
        bond=None,
    )

    charge3 = entities.StateCharge.new_with_defaults(
        external_id="CHARGE3_EXTERNAL_ID",
        status=ChargeStatus.DROPPED,
        status_raw_text="DROPPED",
        offense_date=datetime.date(year=2003, month=7, day=1),
        date_charged=datetime.date(year=2003, month=8, day=1),
        state_code="us_ca",
        statute="A102.3",
        description="DRUG POSSESSION",
        attempted=True,
        classification_type=StateChargeClassificationType.FELONY,
        classification_type_raw_text="F",
        classification_subtype="AA",
        counts=1,
        charge_notes=None,
        court_case=court_case,
        bond=None,
    )

    supervision_sentence.charges = [charge, charge2, charge3]
    incarceration_sentence.charges = [charge, charge2, charge3]

    early_discharge_1 = entities.StateEarlyDischarge.new_with_defaults(
        external_id="ed1",
        request_date=datetime.date(year=2001, month=7, day=1),
        decision_date=datetime.date(year=2001, month=7, day=20),
        decision=StateEarlyDischargeDecision.SENTENCE_TERMINATION_GRANTED,
        decision_raw_text="approved",
        deciding_body_type=StateActingBodyType.PAROLE_BOARD,
        deciding_body_type_raw_text="pb",
        requesting_body_type=StateActingBodyType.SENTENCED_PERSON,
        requesting_body_type_raw_text="sentenced_person",
        state_code="us_ca",
        county_code="san_francisco",
    )
    early_discharge_2 = entities.StateEarlyDischarge.new_with_defaults(
        external_id="ed2",
        request_date=datetime.date(year=2002, month=7, day=1),
        decision_date=datetime.date(year=2002, month=7, day=20),
        decision=StateEarlyDischargeDecision.UNSUPERVISED_PROBATION_GRANTED,
        decision_raw_text="conditionally_approved",
        deciding_body_type=StateActingBodyType.COURT,
        deciding_body_type_raw_text="c",
        requesting_body_type=StateActingBodyType.SENTENCED_PERSON,
        requesting_body_type_raw_text="sentenced_person",
        state_code="us_ca",
        county_code="san_francisco",
    )
    early_discharge_3 = entities.StateEarlyDischarge.new_with_defaults(
        external_id="ed3",
        request_date=datetime.date(year=2001, month=1, day=1),
        decision_date=datetime.date(year=2001, month=1, day=20),
        decision=StateEarlyDischargeDecision.REQUEST_DENIED,
        decision_raw_text="denied",
        deciding_body_type=StateActingBodyType.PAROLE_BOARD,
        deciding_body_type_raw_text="pb",
        requesting_body_type=StateActingBodyType.SENTENCED_PERSON,
        requesting_body_type_raw_text="sentenced_person",
        state_code="us_ca",
        county_code="san_francisco",
    )
    supervision_sentence.early_discharges = [early_discharge_1, early_discharge_2]
    incarceration_sentence.early_discharges = [early_discharge_3]

    incarceration_period = entities.StateIncarcerationPeriod.new_with_defaults(
        status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
        status_raw_text="IN CUSTODY",
        incarceration_type=StateIncarcerationType.STATE_PRISON,
        incarceration_type_raw_text=None,
        admission_date=datetime.date(year=2003, month=8, day=1),
        release_date=datetime.date(year=2004, month=8, day=1),
        state_code="us_ca",
        county_code="us_ca_sf",
        facility="ALCATRAZ",
        housing_unit="BLOCK A",
        facility_security_level=StateIncarcerationFacilitySecurityLevel.MAXIMUM,
        facility_security_level_raw_text="MAX",
        admission_reason=StateIncarcerationPeriodAdmissionReason.NEW_ADMISSION,
        admission_reason_raw_text="NEW ADMISSION",
        projected_release_reason=StateIncarcerationPeriodReleaseReason.CONDITIONAL_RELEASE,
        projected_release_reason_raw_text="CONDITIONAL RELEASE",
        release_reason=StateIncarcerationPeriodReleaseReason.CONDITIONAL_RELEASE,
        release_reason_raw_text="CONDITIONAL RELEASE",
    )

    incarceration_sentence.incarceration_periods = [incarceration_period]
    supervision_sentence.incarceration_periods = [incarceration_period]

    incident_responding_officer = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.CORRECTIONAL_OFFICER,
        state_code="us_ca",
        full_name="MR SIR",
    )

    incident_outcome = entities.StateIncarcerationIncidentOutcome.new_with_defaults(
        outcome_type=StateIncarcerationIncidentOutcomeType.WARNING,
        outcome_type_raw_text="WARNING",
        date_effective=datetime.date(year=2003, month=8, day=20),
        state_code="us_ca",
        outcome_description="LOSS OF COMMISSARY",
        punishment_length_days=30,
    )

    incarceration_incident = entities.StateIncarcerationIncident.new_with_defaults(
        incident_type=StateIncarcerationIncidentType.CONTRABAND,
        incident_type_raw_text="CONTRABAND",
        incident_date=datetime.date(year=2003, month=8, day=10),
        state_code="us_ca",
        facility="ALCATRAZ",
        location_within_facility="13B",
        incident_details="Inmate was told to be quiet and would not comply",
        responding_officer=incident_responding_officer,
        incarceration_incident_outcomes=[incident_outcome],
    )

    incarceration_period.incarceration_incidents = [incarceration_incident]

    parole_decision = entities.StateParoleDecision.new_with_defaults(
        decision_date=datetime.date(year=2004, month=7, day=1),
        corrective_action_deadline=None,
        state_code="us_ca",
        decision_outcome=StateParoleDecisionOutcome.PAROLE_GRANTED,
        decision_reasoning="GOOD BEHAVIOR",
        corrective_action=None,
    )

    incarceration_period.parole_decisions = [parole_decision]

    assessment_agent = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code="us_ca",
        full_name="MR SIR",
    )

    assessment1 = entities.StateAssessment.new_with_defaults(
        assessment_class=StateAssessmentClass.RISK,
        assessment_class_raw_text=None,
        assessment_type=StateAssessmentType.LSIR,
        assessment_type_raw_text="LSIR",
        assessment_date=datetime.date(2003, month=8, day=10),
        state_code="us_ca",
        assessment_score=55,
        assessment_level=StateAssessmentLevel.MEDIUM,
        assessment_level_raw_text="MED",
        assessment_metadata="assessment metadata",
        supervision_period=None,
        conducting_agent=assessment_agent,
    )

    incarceration_period.assessments = [assessment1]

    program_assignment_agent = StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code="us_ca",
        full_name='{"full_name": "AGENT PO"}',
    )

    program_assignment = StateProgramAssignment.new_with_defaults(
        external_id="program_assignment_external_id_1",
        state_code="us_ca",
        participation_status=StateProgramAssignmentParticipationStatus.IN_PROGRESS,
        participation_status_raw_text="IN_PROGRESS",
        referral_date=datetime.date(year=2019, month=2, day=10),
        start_date=datetime.date(year=2019, month=2, day=11),
        program_id="program_id",
        program_location_id="program_location_id",
        referring_agent=program_assignment_agent,
    )
    incarceration_period.program_assignments = [program_assignment]

    supervising_officer = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code="us_ca",
        full_name="MS MADAM",
    )

    supervision_case_type_entry = (
        entities.StateSupervisionCaseTypeEntry.new_with_defaults(
            state_code="us_ca",
            case_type=StateSupervisionCaseType.DOMESTIC_VIOLENCE,
            case_type_raw_text="DOMESTIC_VIOLENCE",
        )
    )

    supervision_contact = entities.StateSupervisionContact.new_with_defaults(
        external_id="CONTACT_ID",
        status=StateSupervisionContactStatus.COMPLETED,
        status_raw_text="COMPLETED",
        contact_type=StateSupervisionContactType.FACE_TO_FACE,
        contact_type_raw_text="FACE_TO_FACE",
        contact_date=datetime.date(year=1111, month=1, day=2),
        state_code="us_ca",
        contact_reason=StateSupervisionContactReason.GENERAL_CONTACT,
        contact_reason_raw_text="GENERAL_CONTACT",
        location=StateSupervisionContactLocation.RESIDENCE,
        location_raw_text="RESIDENCE",
        verified_employment=True,
        resulted_in_arrest=False,
        contacted_agent=supervising_officer,
    )

    supervision_period = entities.StateSupervisionPeriod.new_with_defaults(
        status=StateSupervisionPeriodStatus.UNDER_SUPERVISION,
        status_raw_text="UNDER SUPERVISION",
        supervision_type=StateSupervisionType.PAROLE,
        supervision_type_raw_text="PAROLE",
        start_date=datetime.date(year=2004, month=8, day=1),
        termination_date=None,
        state_code="us_ca",
        admission_reason=StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE,
        admission_reason_raw_text="RELEASE",
        termination_reason=None,
        termination_reason_raw_text=None,
        supervision_level=StateSupervisionLevel.EXTERNAL_UNKNOWN,
        supervision_level_raw_text="UNKNOWN",
        conditions="10PM CURFEW",
        supervising_officer=supervising_officer,
        case_type_entries=[supervision_case_type_entry],
        supervision_contacts=[supervision_contact],
    )

    incarceration_sentence.supervision_periods = [supervision_period]
    supervision_sentence.supervision_periods = [supervision_period]

    assessment2 = entities.StateAssessment.new_with_defaults(
        assessment_class=StateAssessmentClass.RISK,
        assessment_class_raw_text=None,
        assessment_type=StateAssessmentType.LSIR,
        assessment_type_raw_text="LSIR",
        assessment_date=datetime.date(2004, month=9, day=10),
        state_code="us_ca",
        assessment_score=10,
        assessment_level=StateAssessmentLevel.LOW,
        assessment_level_raw_text="LOW",
        assessment_metadata="more assessment metadata",
        incarceration_period=None,
        conducting_agent=assessment_agent,
    )
    supervision_period.assessments = [assessment2]

    program_assignment2 = StateProgramAssignment.new_with_defaults(
        external_id="program_assignment_external_id_2",
        state_code="us_ca",
        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=program_assignment_agent,
    )
    supervision_period.program_assignments = [program_assignment2]

    supervision_violation = entities.StateSupervisionViolation.new_with_defaults(
        violation_type=StateSupervisionViolationType.TECHNICAL,
        violation_type_raw_text="TECHNICAL",
        violation_date=datetime.date(year=2004, month=9, day=1),
        state_code="us_ca",
        is_violent=False,
        violated_conditions="MISSED CURFEW",
    )

    supervision_period.supervision_violation_entries = [supervision_violation]

    supervision_officer_agent = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code="us_ca",
        full_name="JOHN SMITH",
    )

    supervision_violation_response = entities.StateSupervisionViolationResponse.new_with_defaults(
        response_type=StateSupervisionViolationResponseType.CITATION,
        response_date=datetime.date(year=2004, month=9, day=2),
        state_code="us_ca",
        decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
        decision_raw_text="CONTINUE",
        revocation_type=None,
        revocation_type_raw_text=None,
        deciding_body_type=StateSupervisionViolationResponseDecidingBodyType.SUPERVISION_OFFICER,
        decision_agents=[supervision_officer_agent],
    )

    supervision_violation.supervision_violation_responses = [
        supervision_violation_response
    ]

    person.assessments.extend(incarceration_period.assessments)
    person.assessments.extend(supervision_period.assessments)
    person.program_assignments.extend(incarceration_period.program_assignments)
    person.program_assignments.extend(supervision_period.program_assignments)

    if set_back_edges:
        person_children: Sequence[Entity] = (
            *person.external_ids,
            *person.races,
            *person.aliases,
            *person.ethnicities,
            *person.sentence_groups,
            *person.assessments,
            *person.program_assignments,
        )
        for child in person_children:
            child.person = person  # type: ignore[attr-defined]

        sentence_group_children: Sequence[Entity] = (
            *sentence_group.incarceration_sentences,
            *sentence_group.supervision_sentences,
            *sentence_group.fines,
        )
        for child in sentence_group_children:
            child.sentence_group = sentence_group  # type: ignore[attr-defined]
            child.person = person  # type: ignore[attr-defined]

        incarceration_sentence_children: Sequence[Entity] = (
            *incarceration_sentence.charges,
            *incarceration_sentence.incarceration_periods,
            *incarceration_sentence.supervision_periods,
            *incarceration_sentence.early_discharges,
        )

        for child in incarceration_sentence_children:
            if hasattr(child, "incarceration_sentences"):
                child.incarceration_sentences = [incarceration_sentence]  # type: ignore[attr-defined]
            else:
                child.incarceration_sentence = incarceration_sentence  # type: ignore[attr-defined]
            child.person = person  # type: ignore[attr-defined]

        supervision_sentence_children: Sequence[Entity] = (
            *supervision_sentence.charges,
            *supervision_sentence.incarceration_periods,
            *supervision_sentence.supervision_periods,
            *supervision_sentence.early_discharges,
        )

        for child in supervision_sentence_children:
            if hasattr(child, "supervision_sentences"):
                child.supervision_sentences = [supervision_sentence]  # type: ignore[attr-defined]
            else:
                child.supervision_sentence = supervision_sentence  # type: ignore[attr-defined]
            child.person = person  # type: ignore[attr-defined]

        court_case.charges = [charge, charge2, charge3]
        court_case.person = person
        bond.charges = [charge, charge2, charge3]
        bond.person = person

        incarceration_period_children: Sequence[Entity] = (
            *incarceration_period.parole_decisions,
            *incarceration_period.assessments,
            *incarceration_period.incarceration_incidents,
            *incarceration_period.program_assignments,
        )

        for child in incarceration_period_children:
            if hasattr(child, "incarceration_periods"):
                child.incarceration_periods = [incarceration_period]  # type: ignore[attr-defined]
            else:
                child.incarceration_period = incarceration_period  # type: ignore[attr-defined]
            child.person = person  # type: ignore[attr-defined]

        incarceration_incident_children: List[
            StateIncarcerationIncidentOutcome
        ] = incarceration_incident.incarceration_incident_outcomes

        for child in incarceration_incident_children:
            child.incarceration_incident = incarceration_incident
            child.person = person

        supervision_period_children: Sequence[Entity] = (
            *supervision_period.supervision_violation_entries,
            *supervision_period.assessments,
            *supervision_period.program_assignments,
            *supervision_period.case_type_entries,
            *supervision_period.supervision_contacts,
        )
        for child in supervision_period_children:
            if hasattr(child, "supervision_periods"):
                child.supervision_periods = [supervision_period]  # type: ignore[attr-defined]
            else:
                child.supervision_period = supervision_period  # type: ignore[attr-defined]
            child.person = person  # type: ignore[attr-defined]

        supervision_violation_response.supervision_violation = supervision_violation
        supervision_violation_response.person = person

    return person
Beispiel #20
0
def generate_full_graph_state_person(
        set_back_edges: bool) -> entities.StatePerson:
    """Test util for generating a StatePerson that has at least one child of
    each possible Entity type, with all possible edge types defined between
    objects.

    Args:
        set_back_edges: explicitly sets all the back edges on the graph
            that will get automatically filled in when this entity graph is
            written to the DB.

    Returns:
        A test instance of a StatePerson.
    """
    person = entities.StatePerson.new_with_defaults()

    person.external_ids = [
        entities.StatePersonExternalId.new_with_defaults(
            state_code='us_ca',
            external_id='ELITE_ID_123',
            id_type=US_ND_ELITE,
        )
    ]
    person.aliases = [
        entities.StatePersonAlias.new_with_defaults(
            state_code='us_ca',
            full_name='Beyoncé Giselle Knowles',
        ),
        entities.StatePersonAlias.new_with_defaults(
            state_code='us_ca',
            full_name='Beyoncé Giselle Knowles-Carter',
        )
    ]

    person.races = [
        entities.StatePersonRace.new_with_defaults(
            state_code='us_ca',
            race=Race.ASIAN,
            race_raw_text='ASIAN'
        ),
        entities.StatePersonRace.new_with_defaults(
            state_code='us_ca',
            race=Race.BLACK,
            race_raw_text='BLACK'
        )
    ]

    person.ethnicities = [
        entities.StatePersonEthnicity.new_with_defaults(
            state_code='us_ca',
            ethnicity=Ethnicity.NOT_HISPANIC,
            ethnicity_raw_text='NOT HISPANIC'
        )
    ]

    sentence_group = entities.StateSentenceGroup.new_with_defaults(
        external_id='BOOK_ID1234',
        status=StateSentenceStatus.SERVING,
        status_raw_text='SERVING',
        date_imposed=datetime.date(year=2016, month=10, day=14),
        state_code='us_ca',
        county_code='us_ca_san_francisco',
        min_length_days=90,
        max_length_days=120,
    )

    person.sentence_groups = [sentence_group]

    person_supervising_officer = entities.StateAgent.new_with_defaults(
        external_id='SUPERVISING_OFFICER_ID',
        full_name='SUPERVISING OFFICER',
    )
    person.supervising_officer = person_supervising_officer

    incarceration_sentence = \
        entities.StateIncarcerationSentence.new_with_defaults(
            external_id='BOOK_ID1234-1',
            status=StateSentenceStatus.COMPLETED,
            status_raw_text='COMPLETED',
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            incarceration_type_raw_text='PRISON',
            date_imposed=datetime.date(year=2018, month=7, day=3),
            projected_min_release_date=
            datetime.date(year=2017, month=5, day=14),
            projected_max_release_date=None,
            parole_eligibility_date=
            datetime.date(year=2018, month=5, day=14),
            state_code='us_ca',
            county_code='us_ca_san_francisco',

            #   - What
            # These will be None if is_life is true
            min_length_days=90,
            max_length_days=900,
            is_life=False,
            is_capital_punishment=False,
            parole_possible=True,
            initial_time_served_days=None,
            good_time_days=10,
            earned_time_days=None,
        )

    supervision_sentence = \
        entities.StateSupervisionSentence.new_with_defaults(
            external_id='BOOK_ID1234-2',
            status=StateSentenceStatus.SERVING,
            status_raw_text='SERVING',
            supervision_type=StateSupervisionType.PAROLE,
            supervision_type_raw_text='PAROLE',
            projected_completion_date=
            datetime.date(year=2020, month=5, day=14),
            completion_date=None,
            state_code='us_ca',
            min_length_days=None,
            max_length_days=200,
        )

    fine = entities.StateFine.new_with_defaults(
        external_id='BOOK_ID1234-3',
        status=StateFineStatus.UNPAID,
        status_raw_text='UNPAID',
        date_paid=None,
        state_code='us_ca',
        fine_dollars=15000,
    )

    sentence_group.incarceration_sentences = [incarceration_sentence]
    sentence_group.supervision_sentences = [supervision_sentence]
    sentence_group.fines = [fine]

    judge = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.JUDGE,
        state_code='us_ca',
        full_name='JUDGE JUDY',
    )

    court_case = entities.StateCourtCase.new_with_defaults(
        external_id='CASEID456',
        status=StateCourtCaseStatus.EXTERNAL_UNKNOWN,
        date_convicted=datetime.date(year=2018, month=7, day=1),
        next_court_date=datetime.date(year=2019, month=7, day=1),
        state_code='us_ca',
        court_type=
        StateCourtType.PRESENT_WITHOUT_INFO,
        court_type_raw_text=None,
        court_fee_dollars=150,
        judge=judge,
    )

    bond = entities.StateBond.new_with_defaults(
        external_id='BONDID1456',
        status=BondStatus.POSTED,
        status_raw_text='POSTED',
        bond_type=BondType.CASH,
        bond_type_raw_text='CASH',
        date_paid=datetime.date(year=2015, month=7, day=1),
        state_code='us_ca',
        amount_dollars=45,
        bond_agent='CA BAILBONDSMEN',
    )

    charge = entities.StateCharge.new_with_defaults(
        external_id='CHARGE1_EXTERNAL_ID',
        status=ChargeStatus.CONVICTED,
        status_raw_text='CONVICTED',
        offense_date=datetime.date(year=2003, month=7, day=1),
        date_charged=datetime.date(year=2003, month=8, day=1),
        state_code='us_ca',
        statute='A102.3',
        description='DRUG POSSESSION',
        attempted=True,
        classification_type=StateChargeClassificationType.FELONY,
        classification_type_raw_text='F',
        classification_subtype='A',
        counts=1,
        charge_notes=None,
        court_case=court_case,
        bond=None,
    )

    charge2 = entities.StateCharge.new_with_defaults(
        external_id='CHARGE2_EXTERNAL_ID',
        status=ChargeStatus.CONVICTED,
        status_raw_text='CONVICTED',
        offense_date=datetime.date(year=2003, month=7, day=1),
        date_charged=datetime.date(year=2003, month=8, day=1),
        state_code='us_ca',
        statute='A102.3',
        description='DRUG POSSESSION',
        attempted=True,
        classification_type=StateChargeClassificationType.FELONY,
        classification_type_raw_text='F',
        classification_subtype='B',
        counts=1,
        charge_notes=None,
        court_case=court_case,
        bond=None,
    )

    charge3 = entities.StateCharge.new_with_defaults(
        external_id='CHARGE3_EXTERNAL_ID',
        status=ChargeStatus.DROPPED,
        status_raw_text='DROPPED',
        offense_date=datetime.date(year=2003, month=7, day=1),
        date_charged=datetime.date(year=2003, month=8, day=1),
        state_code='us_ca',
        statute='A102.3',
        description='DRUG POSSESSION',
        attempted=True,
        classification_type=StateChargeClassificationType.FELONY,
        classification_type_raw_text='F',
        classification_subtype='AA',
        counts=1,
        charge_notes=None,
        court_case=court_case,
        bond=None,
    )

    supervision_sentence.charges = [charge, charge2, charge3]
    incarceration_sentence.charges = [charge, charge2, charge3]

    early_discharge_1 = entities.StateEarlyDischarge.new_with_defaults(
        external_id='ed1',
        request_date=datetime.date(year=2001, month=7, day=1),
        decision_date=datetime.date(year=2001, month=7, day=20),
        decision=StateEarlyDischargeDecision.SENTENCE_TERMINATION_GRANTED,
        decision_raw_text='approved',
        deciding_body_type=StateActingBodyType.PAROLE_BOARD,
        deciding_body_type_raw_text='pb',
        requesting_body_type=StateActingBodyType.SENTENCED_PERSON,
        requesting_body_type_raw_text='sentenced_person',
        state_code='us_ca',
        county_code='san_francisco')
    early_discharge_2 = entities.StateEarlyDischarge.new_with_defaults(
        external_id='ed2',
        request_date=datetime.date(year=2002, month=7, day=1),
        decision_date=datetime.date(year=2002, month=7, day=20),
        decision=StateEarlyDischargeDecision.UNSUPERVISED_PROBATION_GRANTED,
        decision_raw_text='conditionally_approved',
        deciding_body_type=StateActingBodyType.COURT,
        deciding_body_type_raw_text='c',
        requesting_body_type=StateActingBodyType.SENTENCED_PERSON,
        requesting_body_type_raw_text='sentenced_person',
        state_code='us_ca',
        county_code='san_francisco')
    early_discharge_3 = entities.StateEarlyDischarge.new_with_defaults(
        external_id='ed3',
        request_date=datetime.date(year=2001, month=1, day=1),
        decision_date=datetime.date(year=2001, month=1, day=20),
        decision=StateEarlyDischargeDecision.REQUEST_DENIED,
        decision_raw_text='denied',
        deciding_body_type=StateActingBodyType.PAROLE_BOARD,
        deciding_body_type_raw_text='pb',
        requesting_body_type=StateActingBodyType.SENTENCED_PERSON,
        requesting_body_type_raw_text='sentenced_person',
        state_code='us_ca',
        county_code='san_francisco')
    supervision_sentence.early_discharges = [early_discharge_1, early_discharge_2]
    incarceration_sentence.early_discharges = [early_discharge_3]

    incarceration_period = \
        entities.StateIncarcerationPeriod.new_with_defaults(
            status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY,
            status_raw_text='IN CUSTODY',
            incarceration_type=StateIncarcerationType.STATE_PRISON,
            incarceration_type_raw_text=None,
            admission_date=datetime.date(year=2003, month=8, day=1),
            release_date=datetime.date(year=2004, month=8, day=1),
            state_code='us_ca',
            county_code='us_ca_sf',
            facility='ALCATRAZ',
            housing_unit='BLOCK A',
            facility_security_level=
            StateIncarcerationFacilitySecurityLevel.MAXIMUM,
            facility_security_level_raw_text='MAX',
            admission_reason=
            StateIncarcerationPeriodAdmissionReason.NEW_ADMISSION,
            admission_reason_raw_text='NEW ADMISSION',
            projected_release_reason=
            StateIncarcerationPeriodReleaseReason.CONDITIONAL_RELEASE,
            projected_release_reason_raw_text='CONDITIONAL RELEASE',
            release_reason=
            StateIncarcerationPeriodReleaseReason.CONDITIONAL_RELEASE,
            release_reason_raw_text='CONDITIONAL RELEASE',
        )

    incarceration_sentence.incarceration_periods = [incarceration_period]
    supervision_sentence.incarceration_periods = [incarceration_period]

    incident_responding_officer = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.CORRECTIONAL_OFFICER,
        state_code='us_ca',
        full_name='MR SIR',
    )

    incident_outcome = \
        entities.StateIncarcerationIncidentOutcome.new_with_defaults(
            outcome_type=StateIncarcerationIncidentOutcomeType.WARNING,
            outcome_type_raw_text='WARNING',
            date_effective=datetime.date(year=2003, month=8, day=20),
            state_code='us_ca',
            outcome_description='LOSS OF COMMISSARY',
            punishment_length_days=30,
        )

    incarceration_incident = \
        entities.StateIncarcerationIncident.new_with_defaults(
            incident_type=StateIncarcerationIncidentType.CONTRABAND,
            incident_type_raw_text='CONTRABAND',
            incident_date=datetime.date(year=2003, month=8, day=10),
            state_code='us_ca',
            facility='ALCATRAZ',
            location_within_facility='13B',
            incident_details='Inmate was told to be quiet and would not comply',
            responding_officer=incident_responding_officer,
            incarceration_incident_outcomes=[incident_outcome],
        )

    incarceration_period.incarceration_incidents = [incarceration_incident]

    parole_decision = entities.StateParoleDecision.new_with_defaults(
        decision_date=datetime.date(year=2004, month=7, day=1),
        corrective_action_deadline=None,
        state_code='us_ca',
        decision_outcome=StateParoleDecisionOutcome.PAROLE_GRANTED,
        decision_reasoning='GOOD BEHAVIOR',
        corrective_action=None,
    )

    incarceration_period.parole_decisions = [parole_decision]

    assessment_agent = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code='us_ca',
        full_name='MR SIR',
    )

    assessment1 = entities.StateAssessment.new_with_defaults(
        assessment_class=StateAssessmentClass.RISK,
        assessment_class_raw_text=None,
        assessment_type=StateAssessmentType.LSIR,
        assessment_type_raw_text='LSIR',
        assessment_date=datetime.date(2003, month=8, day=10),
        state_code='us_ca',
        assessment_score=55,
        assessment_level=StateAssessmentLevel.MEDIUM,
        assessment_level_raw_text='MED',
        assessment_metadata='assessment metadata',
        supervision_period=None,
        conducting_agent=assessment_agent,
    )

    incarceration_period.assessments = [assessment1]

    program_assignment_agent = StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code='us_ca',
        full_name='{"full_name": "AGENT PO"}')

    program_assignment = StateProgramAssignment.new_with_defaults(
        external_id='program_assignment_external_id_1',
        state_code='us_ca',
        participation_status=
        StateProgramAssignmentParticipationStatus.IN_PROGRESS,
        participation_status_raw_text='IN_PROGRESS',
        referral_date=datetime.date(year=2019, month=2, day=10),
        start_date=datetime.date(year=2019, month=2, day=11),
        program_id='program_id',
        program_location_id='program_location_id',
        referring_agent=program_assignment_agent
    )
    incarceration_period.program_assignments = [program_assignment]

    supervising_officer = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code='us_ca',
        full_name='MS MADAM',
    )

    supervision_case_type_entry = \
        entities.StateSupervisionCaseTypeEntry.new_with_defaults(
            state_code='us_ca',
            case_type=StateSupervisionCaseType.DOMESTIC_VIOLENCE,
            case_type_raw_text='DOMESTIC_VIOLENCE')

    supervision_contact = entities.StateSupervisionContact.new_with_defaults(
        external_id='CONTACT_ID',
        status=StateSupervisionContactStatus.COMPLETED,
        status_raw_text='COMPLETED',
        contact_type=StateSupervisionContactType.FACE_TO_FACE,
        contact_type_raw_text='FACE_TO_FACE',
        contact_date=datetime.date(year=1111, month=1, day=2),
        state_code='us_ca',
        contact_reason=StateSupervisionContactReason.GENERAL_CONTACT,
        contact_reason_raw_text='GENERAL_CONTACT',
        location=StateSupervisionContactLocation.RESIDENCE,
        location_raw_text='RESIDENCE',
        verified_employment=True,
        resulted_in_arrest=False,
        contacted_agent=supervising_officer,
    )

    supervision_period = entities.StateSupervisionPeriod.new_with_defaults(
        status=StateSupervisionPeriodStatus.UNDER_SUPERVISION,
        status_raw_text='UNDER SUPERVISION',
        supervision_type=StateSupervisionType.PAROLE,
        supervision_type_raw_text='PAROLE',
        start_date=datetime.date(year=2004, month=8, day=1),
        termination_date=None,
        state_code='us_ca',
        admission_reason=
        StateSupervisionPeriodAdmissionReason.CONDITIONAL_RELEASE,
        admission_reason_raw_text='RELEASE',
        termination_reason=None,
        termination_reason_raw_text=None,
        supervision_level=StateSupervisionLevel.EXTERNAL_UNKNOWN,
        supervision_level_raw_text='UNKNOWN',
        conditions='10PM CURFEW',
        supervising_officer=supervising_officer,
        case_type_entries=[supervision_case_type_entry],
        supervision_contacts=[supervision_contact],
    )

    incarceration_sentence.supervision_periods = [supervision_period]
    supervision_sentence.supervision_periods = [supervision_period]

    assessment2 = entities.StateAssessment.new_with_defaults(
        assessment_class=StateAssessmentClass.RISK,
        assessment_class_raw_text=None,
        assessment_type=StateAssessmentType.LSIR,
        assessment_type_raw_text='LSIR',
        assessment_date=datetime.date(2004, month=9, day=10),
        state_code='us_ca',
        assessment_score=10,
        assessment_level=StateAssessmentLevel.LOW,
        assessment_level_raw_text='LOW',
        assessment_metadata='more assessment metadata',
        incarceration_period=None,
        conducting_agent=assessment_agent,
    )
    supervision_period.assessments = [assessment2]

    program_assignment2 = StateProgramAssignment.new_with_defaults(
        external_id='program_assignment_external_id_2',
        state_code='us_ca',
        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=program_assignment_agent
    )
    supervision_period.program_assignments = [program_assignment2]

    supervision_violation = \
        entities.StateSupervisionViolation.new_with_defaults(
            violation_type=StateSupervisionViolationType.TECHNICAL,
            violation_type_raw_text='TECHNICAL',
            violation_date=datetime.date(year=2004, month=9, day=1),
            state_code='us_ca',
            is_violent=False,
            violated_conditions='MISSED CURFEW',
        )

    supervision_period.supervision_violation_entries = [supervision_violation]

    supervision_officer_agent = entities.StateAgent.new_with_defaults(
        agent_type=StateAgentType.SUPERVISION_OFFICER,
        state_code='us_ca',
        full_name='JOHN SMITH',
    )

    supervision_violation_response = \
        entities.StateSupervisionViolationResponse.new_with_defaults(
            response_type=StateSupervisionViolationResponseType.CITATION,
            response_date=datetime.date(year=2004, month=9, day=2),
            state_code='us_ca',
            decision=StateSupervisionViolationResponseDecision.CONTINUANCE,
            decision_raw_text='CONTINUE',
            revocation_type=None,
            revocation_type_raw_text=None,
            deciding_body_type=
            StateSupervisionViolationResponseDecidingBodyType.
            SUPERVISION_OFFICER,
            decision_agents=[supervision_officer_agent]
        )

    supervision_violation.supervision_violation_responses = \
        [supervision_violation_response]

    person.assessments.extend(incarceration_period.assessments)
    person.assessments.extend(supervision_period.assessments)
    person.program_assignments.extend(incarceration_period.program_assignments)
    person.program_assignments.extend(supervision_period.program_assignments)

    if set_back_edges:

        person_children: List[Entity] = (
            person.external_ids + person.races +  # type: ignore
            person.aliases + person.ethnicities +  # type: ignore
            person.sentence_groups + person.assessments +  # type: ignore
            person.program_assignments  # type: ignore
        )
        for child in person_children:
            child.person = person  # type: ignore

        sentence_group_children: List[Entity] = (
            sentence_group.incarceration_sentences +  # type: ignore
            sentence_group.supervision_sentences +  # type: ignore
            sentence_group.fines  # type: ignore
        )
        for child in sentence_group_children:
            child.sentence_group = sentence_group  # type: ignore
            child.person = person  # type: ignore

        incarceration_sentence_children = (
            incarceration_sentence.charges +  # type: ignore
            incarceration_sentence.incarceration_periods +  # type: ignore
            incarceration_sentence.supervision_periods +  # type: ignore
            incarceration_sentence.early_discharges  # type: ignore
        )

        for child in incarceration_sentence_children:
            if hasattr(child, 'incarceration_sentences'):
                child.incarceration_sentences = [incarceration_sentence]
            else:
                child.incarceration_sentence = incarceration_sentence  # type: ignore
            child.person = person

        supervision_sentence_children = (
            supervision_sentence.charges +  # type: ignore
            supervision_sentence.incarceration_periods +  # type: ignore
            supervision_sentence.supervision_periods +  # type: ignore
            supervision_sentence.early_discharges  # type: ignore
        )

        for child in supervision_sentence_children:
            if hasattr(child, 'supervision_sentences'):
                child.supervision_sentences = [supervision_sentence]
            else:
                child.supervision_sentence = supervision_sentence  # type: ignore
            child.person = person

        court_case.charges = [charge, charge2, charge3]
        court_case.person = person
        bond.charges = [charge, charge2, charge3]
        bond.person = person

        incarceration_period_children = (
            incarceration_period.parole_decisions +  # type: ignore
            incarceration_period.assessments +  # type: ignore
            incarceration_period.incarceration_incidents +  # type: ignore
            incarceration_period.program_assignments  # type: ignore
        )

        for child in incarceration_period_children:
            if hasattr(child, 'incarceration_periods'):
                child.incarceration_periods = [incarceration_period]  # type: ignore
            else:
                child.incarceration_period = incarceration_period
            child.person = person

        # pylint:disable=not-an-iterable
        incarceration_incident_children = incarceration_incident.incarceration_incident_outcomes

        for child in incarceration_incident_children:
            child.incarceration_incident = incarceration_incident
            child.person = person

        supervision_period_children = (
            supervision_period.supervision_violation_entries +  # type: ignore
            supervision_period.assessments +  # type: ignore
            supervision_period.program_assignments +  # type: ignore
            supervision_period.case_type_entries +  # type: ignore
            supervision_period.supervision_contacts  # type: ignore
        )
        for child in supervision_period_children:
            if hasattr(child, 'supervision_periods'):
                child.supervision_periods = [supervision_period]
            else:
                child.supervision_period = supervision_period  # type: ignore
            child.person = person

        supervision_violation_response.supervision_violation = \
            supervision_violation
        supervision_violation_response.person = person

    return person