def test_person_has_multiple_external_ids_of_the_same_type(self): person = StatePerson.new_with_defaults( state_code="US_XX", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) # Wrong ID type person_external_id_exclude = StatePersonExternalId.new_with_defaults( external_id="0123", id_type="US_PA_PBPP", state_code="US_PA") # Lowest value of the two 'US_PA_CONT' ids - pick this one person_external_id_include = StatePersonExternalId.new_with_defaults( external_id="1234", id_type="US_PA_CONT", state_code="US_PA") # Other 'US_PA_CONT' should be picked person_external_id_exclude_2 = StatePersonExternalId.new_with_defaults( external_id="2345", id_type="US_PA_CONT", state_code="US_PA") person.external_ids = [ person_external_id_exclude, person_external_id_include, person_external_id_exclude_2, ] external_id = calculator_utils.person_external_id_to_include( INCLUDED_PIPELINES[0], person_external_id_include.state_code, person) self.assertEqual(external_id, person_external_id_include.external_id)
def test_add_person_characteristics_IncludeExternalId(self): person = StatePerson.new_with_defaults( state_code="US_XX", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[StatePersonRace.new_with_defaults(state_code="US_XX", )], ethnicities=[ StatePersonEthnicity.new_with_defaults(state_code="US_XX", ) ], external_ids=[ StatePersonExternalId.new_with_defaults(external_id="DOC1341", id_type="US_XX_DOC", state_code="US_XX"), StatePersonExternalId.new_with_defaults(external_id="SID9889", id_type="US_XX_SID", state_code="US_XX"), ], ) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, "test_pipeline") expected_output = { "age_bucket": "25-29", "gender": Gender.FEMALE, "person_id": person.person_id, "person_external_id": "DOC1341", } self.assertEqual(updated_characteristics, expected_output)
def test_produce_incarceration_metrics_secondary_person_external_id(self): person = StatePerson.new_with_defaults( state_code="US_XX", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[ StatePersonRace.new_with_defaults(state_code="US_XX", race=Race.WHITE) ], ethnicities=[ StatePersonEthnicity.new_with_defaults( state_code="US_XX", ethnicity=Ethnicity.NOT_HISPANIC) ], external_ids=[ StatePersonExternalId.new_with_defaults(external_id="DOC1341", id_type="US_XX_DOC", state_code="US_XX"), StatePersonExternalId.new_with_defaults(external_id="SID9889", id_type="US_XX_SID", state_code="US_XX"), ], ) incarceration_events = [ IncarcerationCommitmentFromSupervisionAdmissionEvent( state_code="US_XX", event_date=date(2000, 3, 12), facility="FACILITY X", county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.PAROLE_REVOCATION, admission_reason_raw_text="PAROLE_REVOCATION", specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON, supervision_type=StateSupervisionPeriodSupervisionType.PAROLE, ), ] metrics = self.metric_producer.produce_metrics( person=person, identifier_events=incarceration_events, metric_inclusions=ALL_METRICS_INCLUSIONS_DICT, calculation_end_month=None, calculation_month_count=-1, person_metadata=_DEFAULT_PERSON_METADATA, pipeline_job_id=PIPELINE_JOB_ID, pipeline_type=self.pipeline_config.pipeline_type, ) expected_count = self.expected_metrics_count(incarceration_events) self.assertEqual(expected_count, len(metrics)) for metric in metrics: self.assertEqual("DOC1341", metric.person_external_id) if isinstance(metric, IncarcerationCommitmentFromSupervisionMetric): self.assertEqual("SID9889", metric.secondary_person_external_id)
def test_getExternalIdsOfCls(self): supervision_sentence = StateSupervisionSentence.new_with_defaults( external_id=_EXTERNAL_ID) supervision_sentence_2 = attr.evolve(supervision_sentence, external_id=_EXTERNAL_ID_2) supervision_sentence_3 = attr.evolve(supervision_sentence, external_id=_EXTERNAL_ID_3) sentence_group = StateSentenceGroup.new_with_defaults( external_id=_EXTERNAL_ID, supervision_sentences=[ supervision_sentence, supervision_sentence_2 ]) sentence_group_2 = StateSentenceGroup.new_with_defaults( external_id=_EXTERNAL_ID_2, supervision_sentences=[ supervision_sentence_2, supervision_sentence_3 ]) external_id = StatePersonExternalId.new_with_defaults( external_id=_EXTERNAL_ID) person = StatePerson.new_with_defaults( external_ids=[external_id], sentence_groups=[sentence_group, sentence_group_2]) self.assertCountEqual([_EXTERNAL_ID, _EXTERNAL_ID_2, _EXTERNAL_ID_3], get_external_ids_of_cls( [person], StateSupervisionSentence)) self.assertCountEqual([_EXTERNAL_ID, _EXTERNAL_ID_2], get_external_ids_of_cls([person], StateSentenceGroup)) self.assertCountEqual([_EXTERNAL_ID], get_external_ids_of_cls([person], StatePerson))
def test_person_has_external_ids_from_multiple_states(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) person_external_id_1 = StatePersonExternalId.new_with_defaults( external_id='SID10928', id_type='US_ND_SID', state_code='US_ND') person_external_id_2 = StatePersonExternalId.new_with_defaults( external_id='SID1341', id_type='US_MO_DOC', state_code='US_MO') person.external_ids = [person_external_id_1, person_external_id_2] with self.assertRaises(ValueError): _ = calculator_utils.person_external_id_to_include( INCLUDED_PIPELINES[0], person_external_id_2.state_code, person)
def test_add_person_characteristics_IncludeExternalId(self): person = StatePerson.new_with_defaults( state_code='US_MO', person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[StatePersonRace.new_with_defaults()], ethnicities=[StatePersonEthnicity.new_with_defaults()], external_ids=[ StatePersonExternalId.new_with_defaults(external_id='SID1341', id_type='US_MO_DOC', state_code='US_MO') ]) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, 'supervision') expected_output = { 'age_bucket': '25-29', 'gender': Gender.FEMALE, 'person_id': person.person_id, 'person_external_id': 'SID1341' } self.assertEqual(updated_characteristics, expected_output)
def test_isPlaceholder_personWithExternalId(self): sentence_group = StateSentenceGroup.new_with_defaults( state_code=_STATE_CODE) person = StatePerson.new_with_defaults(sentence_groups=[sentence_group]) self.assertTrue(is_placeholder(person)) person.external_ids.append( StatePersonExternalId.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID, id_type=_ID_TYPE)) self.assertFalse(is_placeholder(person))
def test_person_external_id_to_include_multiple(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) person_external_id_exclude = StatePersonExternalId.new_with_defaults( external_id='SID10928', id_type='US_ND_SID', state_code='US_ND') person_external_id_include = StatePersonExternalId.new_with_defaults( external_id='SID1341', id_type='US_MO_DOC', state_code='US_MO') person.external_ids = [ person_external_id_exclude, person_external_id_include ] external_id = calculator_utils.person_external_id_to_include( INCLUDED_PIPELINES[0], person) self.assertEqual(external_id, person_external_id_include.external_id)
def test_getExternalIdsOfCls_emptyExternalId_raises(self): sentence_group = StateSentenceGroup.new_with_defaults( external_id=_EXTERNAL_ID) sentence_group_2 = StateSentenceGroup.new_with_defaults() external_id = StatePersonExternalId.new_with_defaults( external_id=_EXTERNAL_ID) person = StatePerson.new_with_defaults( external_ids=[external_id], sentence_groups=[sentence_group, sentence_group_2]) with pytest.raises(EntityMatchingError): get_external_ids_of_cls([person], StateSentenceGroup)
def test_person_external_id_to_include_no_results(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) person_external_id = StatePersonExternalId.new_with_defaults( external_id='SID10928', id_type='US_ND_SID', state_code='US_ND') person.external_ids = [person_external_id] for pipeline_type in INCLUDED_PIPELINES: external_id = calculator_utils.person_external_id_to_include( pipeline_type, person_external_id.state_code, person) self.assertIsNone(external_id)
def test_isMatch_statePerson(self): external_id = StatePersonExternalId.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID) external_id_different = attr.evolve(external_id, external_id=_EXTERNAL_ID_2) person = StatePerson.new_with_defaults(full_name='name', external_ids=[external_id]) person_another = StatePerson.new_with_defaults( full_name='name_2', external_ids=[external_id]) self.assertTrue( _is_match(ingested_entity=person, db_entity=person_another)) person_another.external_ids = [external_id_different] self.assertFalse( _is_match(ingested_entity=person, db_entity=person_another))
def test_person_external_id_to_include(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) person_external_id = StatePersonExternalId.new_with_defaults( external_id='SID1341', id_type='US_MO_DOC', state_code='US_MO') person.external_ids = [person_external_id] for pipeline_type in INCLUDED_PIPELINES: external_id = calculator_utils.person_external_id_to_include( pipeline_type, person) self.assertEqual(external_id, person_external_id.external_id)
def test_isMatch_statePersonExternalId_stateCode(self): external_id = StatePersonExternalId.new_with_defaults( person_external_id_id=_ID, state_code=_STATE_CODE, id_type=_ID_TYPE, external_id=_EXTERNAL_ID) external_id_different = attr.evolve(external_id, person_external_id_id=None) self.assertTrue( _is_match(ingested_entity=external_id, db_entity=external_id_different)) external_id.state_code = _STATE_CODE_ANOTHER self.assertFalse( _is_match(ingested_entity=external_id, db_entity=external_id_different))
def test_associateSvrsWithIps(self): # Arrange svr_1 = StateSupervisionViolationResponse.new_with_defaults( response_date=_DATE_1, revocation_type=StateSupervisionViolationResponseRevocationType. REINCARCERATION) svr_2 = StateSupervisionViolationResponse.new_with_defaults( response_date=_DATE_3, revocation_type=StateSupervisionViolationResponseRevocationType. REINCARCERATION) svr_3 = StateSupervisionViolationResponse.new_with_defaults( response_date=_DATE_5, revocation_type=StateSupervisionViolationResponseRevocationType. RETURN_TO_SUPERVISION) placeholder_sv = StateSupervisionViolation.new_with_defaults( supervision_violation_responses=[svr_1, svr_2, svr_3]) placeholder_sp = StateSupervisionPeriod.new_with_defaults( supervision_violations=[placeholder_sv]) placeholder_ss = StateSupervisionSentence.new_with_defaults( supervision_periods=[placeholder_sp]) ip_1 = StateIncarcerationPeriod.new_with_defaults( admission_date=_DATE_2, admission_reason=StateIncarcerationPeriodAdmissionReason. PROBATION_REVOCATION) ip_2 = StateIncarcerationPeriod.new_with_defaults( admission_date=_DATE_4, admission_reason=StateIncarcerationPeriodAdmissionReason. PROBATION_REVOCATION) placeholder_is = StateIncarcerationSentence.new_with_defaults( incarceration_periods=[ip_1, ip_2]) placeholder_sg = StateSentenceGroup.new_with_defaults( incarceration_sentences=[placeholder_is], supervision_sentences=[placeholder_ss]) placeholder_person = StatePerson.new_with_defaults( sentence_groups=[placeholder_sg]) external_id = StatePersonExternalId.new_with_defaults( external_id=_EXTERNAL_ID) person_without_revocation = StatePerson.new_with_defaults( external_ids=[external_id]) expected_svr_1 = attr.evolve(svr_1) expected_svr_2 = attr.evolve(svr_2) expected_svr_3 = attr.evolve(svr_3) expected_placeholder_sv = attr.evolve(placeholder_sv, supervision_violation_responses=[ expected_svr_1, expected_svr_2, expected_svr_3 ]) expected_placeholder_sp = attr.evolve( placeholder_sp, supervision_violations=[expected_placeholder_sv]) expected_placeholder_ss = attr.evolve( placeholder_ss, supervision_periods=[expected_placeholder_sp]) expected_ip_1 = attr.evolve( ip_1, source_supervision_violation_response=svr_1) expected_ip_2 = attr.evolve( ip_2, source_supervision_violation_response=svr_2) expected_placeholder_is = attr.evolve( placeholder_is, incarceration_periods=[expected_ip_1, expected_ip_2]) expected_placeholder_sg = attr.evolve( placeholder_sg, supervision_sentences=[expected_placeholder_ss], incarceration_sentences=[expected_placeholder_is]) expected_placeholder_person = attr.evolve( placeholder_person, sentence_groups=[expected_placeholder_sg]) expected_person_without_revocation = attr.evolve( person_without_revocation) # Act associate_revocation_svrs_with_ips( [person_without_revocation, placeholder_person]) # Assert self.assertEqual(expected_person_without_revocation, person_without_revocation) self.assertEqual(expected_placeholder_person, placeholder_person)
def test_runMatch_supervisionPeriodDateChangesSoItDoesNotMatchSentenceOrViolations( self): # Arrange db_supervising_officer = generate_agent( agent_id=_ID, external_id=_EXTERNAL_ID, state_code=_US_MO, agent_type=StateAgentType.SUPERVISION_OFFICER.value) db_person = generate_person(person_id=_ID, supervising_officer=db_supervising_officer) db_external_id = generate_external_id(person_external_id_id=_ID, external_id=_EXTERNAL_ID, state_code=_US_MO, id_type=_ID_TYPE) # Violation has been date matched to the open supervision period db_supervision_violation = generate_supervision_violation( person=db_person, state_code=_US_MO, supervision_violation_id=_ID, external_id=_EXTERNAL_ID, violation_date=_DATE_4) db_supervision_period_open = generate_supervision_period( person=db_person, supervision_period_id=_ID_2, external_id=_EXTERNAL_ID_2, start_date=_DATE_2, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO.value, state_code=_US_MO, supervising_officer=db_supervising_officer, supervision_violation_entries=[db_supervision_violation]) db_supervision_sentence = generate_supervision_sentence( person=db_person, external_id=_EXTERNAL_ID, supervision_sentence_id=_ID, state_code=_US_MO, start_date=_DATE_1, supervision_periods=[db_supervision_period_open]) db_sentence_group = generate_sentence_group( external_id=_EXTERNAL_ID, sentence_group_id=_ID, state_code=_US_MO, supervision_sentences=[db_supervision_sentence]) db_person.external_ids = [db_external_id] db_person.sentence_groups = [db_sentence_group] self._commit_to_db(db_person) supervsion_period_updated = StateSupervisionPeriod.new_with_defaults( state_code=_US_MO, external_id=db_supervision_period_open.external_id, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, start_date=_DATE_2, termination_date=_DATE_3, ) placeholder_supervision_sentence = StateSupervisionSentence.new_with_defaults( state_code=_US_MO, supervision_periods=[supervsion_period_updated]) sentence_group = StateSentenceGroup.new_with_defaults( external_id=db_sentence_group.external_id, state_code=_US_MO, supervision_sentences=[placeholder_supervision_sentence]) external_id = StatePersonExternalId.new_with_defaults( external_id=db_external_id.external_id, state_code=_US_MO, id_type=db_external_id.id_type) person = StatePerson.new_with_defaults( external_ids=[external_id], sentence_groups=[sentence_group]) expected_person = attr.evolve(self.to_entity(db_person)) expected_sentence = expected_person.sentence_groups[ 0].supervision_sentences[0] expected_original_supervision_period = expected_sentence.supervision_periods[ 0] # Violation is moved off of the supervision period (it no longer matches) and the termination date is updated expected_original_supervision_period.supervision_violation_entries = [] expected_original_supervision_period.termination_date = _DATE_3 # A placeholder periods is created to hold the existing supervision violation expected_new_placeholder_supervision_period = StateSupervisionPeriod.new_with_defaults( state_code=_US_MO, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, supervision_violation_entries=[ self.to_entity(db_supervision_violation) ]) expected_sentence.supervision_periods.append( expected_new_placeholder_supervision_period) # Act session = self._session() matched_entities = entity_matching.match(session, _US_MO, ingested_people=[person]) # Assert self.assert_people_match_pre_and_post_commit([expected_person], matched_entities.people, session, debug=True) self.assert_no_errors(matched_entities) self.assertEqual(1, matched_entities.total_root_entities)
def test_removeSeosFromSupervisionViolation(self): supervision_violation_response = \ StateSupervisionViolationResponse.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX) supervision_violation = StateSupervisionViolation.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX, supervision_violation_responses=[supervision_violation_response]) placeholder_supervision_period = \ StateSupervisionPeriod.new_with_defaults( state_code=_US_MO, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, supervision_violation_entries=[supervision_violation]) supervision_sentence = StateSupervisionSentence.new_with_defaults( status=StateSentenceStatus.PRESENT_WITHOUT_INFO, state_code=_US_MO, external_id=_EXTERNAL_ID, supervision_periods=[placeholder_supervision_period]) sentence_group = StateSentenceGroup.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[], supervision_sentences=[supervision_sentence]) external_id = StatePersonExternalId.new_with_defaults( state_code=_US_MO, id_type=_ID_TYPE, external_id=_EXTERNAL_ID) person = StatePerson.new_with_defaults( sentence_groups=[sentence_group], external_ids=[external_id]) updated_external_id = _EXTERNAL_ID expected_supervision_violation_response = attr.evolve( supervision_violation_response, external_id=updated_external_id) expected_supervision_violation = attr.evolve( supervision_violation, external_id=updated_external_id, supervision_violation_responses=[ expected_supervision_violation_response ]) expected_placeholder_supervision_period = attr.evolve( placeholder_supervision_period, supervision_violation_entries=[expected_supervision_violation]) expected_supervision_sentence = attr.evolve( supervision_sentence, supervision_periods=[expected_placeholder_supervision_period]) expected_sentence_group = attr.evolve( sentence_group, supervision_sentences=[expected_supervision_sentence]) expected_external_id = attr.evolve(external_id) expected_person = attr.evolve( person, external_ids=[expected_external_id], sentence_groups=[expected_sentence_group]) # Act 1 - Match session = self._session() matched_entities = entity_matching.match(session, _US_MO, ingested_people=[person]) self.assert_people_match_pre_and_post_commit([expected_person], matched_entities.people, session) self.assertEqual(0, matched_entities.error_count) self.assertEqual(1, matched_entities.total_root_entities)
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 test_state_threeSentenceGroups_persistsTwoBelowThreshold( self, mock_get_matcher): """Ensure that the number of errors is below the ND specific threshold""" mock_get_matcher.return_value = _PatchedStateEntityMatcher( region_code=STATE_CODE, erroring_class=schema.StateSentenceGroup, erroring_external_ids=[SENTENCE_GROUP_ID], ) # Set the ENTITY_MATCHING_THRESHOLD to 0, such that we can verify that the forty percent threshold for # ENTITY_MATCHING_THRESHOLD is dictated by the state-specific override in # STATE_CODE_TO_ENTITY_MATCHING_THRESHOLD_FORTY_PERCENT. STATE_ERROR_THRESHOLDS_WITH_FORTY_PERCENT_RATIOS[ ENTITY_MATCHING_THRESHOLD] = 0 # Arrange ingest_info = IngestInfo() ingest_info.state_people.add( state_person_id="1_GENERATE", state_sentence_group_ids=[SENTENCE_GROUP_ID, SENTENCE_GROUP_ID_2], ) ingest_info.state_people.add( state_person_id="2_GENERATE", state_sentence_group_ids=[SENTENCE_GROUP_ID_3]) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID, county_code=COUNTY_CODE) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID_2, county_code=COUNTY_CODE) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID_3, county_code=COUNTY_CODE) db_person = schema.StatePerson(person_id=ID, full_name=FULL_NAME_1, state_code=STATE_CODE) db_sentence_group = schema.StateSentenceGroup( sentence_group_id=ID, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID, state_code=STATE_CODE, ) db_sentence_group_2 = schema.StateSentenceGroup( sentence_group_id=ID_2, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_2, state_code=STATE_CODE, ) db_external_id = schema.StatePersonExternalId( person_external_id_id=ID, state_code=STATE_CODE, external_id=EXTERNAL_ID, id_type=ID_TYPE, ) db_person.sentence_groups = [db_sentence_group, db_sentence_group_2] db_person.external_ids = [db_external_id] db_person_2 = schema.StatePerson(person_id=ID_2, full_name=FULL_NAME_1, state_code=STATE_CODE) db_sentence_group_3 = schema.StateSentenceGroup( sentence_group_id=ID_3, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_3, state_code=STATE_CODE, ) db_external_id_2 = schema.StatePersonExternalId( person_external_id_id=ID_2, state_code=STATE_CODE, external_id=EXTERNAL_ID_2, id_type=ID_TYPE, ) db_person_2.external_ids = [db_external_id_2] db_person_2.sentence_groups = [db_sentence_group_3] session = SessionFactory.for_schema_base(StateBase) session.add(db_person) session.add(db_person_2) session.commit() expected_person = StatePerson.new_with_defaults( person_id=ID, full_name=FULL_NAME_1, external_ids=[], sentence_groups=[], state_code=STATE_CODE, ) expected_external_id = StatePersonExternalId.new_with_defaults( person_external_id_id=ID, state_code=STATE_CODE, external_id=EXTERNAL_ID, id_type=ID_TYPE, person=expected_person, ) # No county code because errors during match expected_sentence_group = StateSentenceGroup.new_with_defaults( sentence_group_id=ID, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID, state_code=STATE_CODE, person=expected_person, ) expected_sentence_group_2 = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_2, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_2, state_code=STATE_CODE, county_code=COUNTY_CODE, person=expected_person, ) expected_person.external_ids = [expected_external_id] expected_person.sentence_groups = [ expected_sentence_group, expected_sentence_group_2, ] expected_person_2 = StatePerson.new_with_defaults( person_id=ID_2, full_name=FULL_NAME_1, state_code=STATE_CODE) expected_external_id_2 = StatePersonExternalId.new_with_defaults( person_external_id_id=ID_2, state_code=STATE_CODE, external_id=EXTERNAL_ID_2, id_type=ID_TYPE, person=expected_person_2, ) expected_sentence_group_3 = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_3, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_3, state_code=STATE_CODE, county_code=COUNTY_CODE, person=expected_person_2, ) expected_person_2.sentence_groups = [expected_sentence_group_3] expected_person_2.external_ids = [expected_external_id_2] # Act persistence.write(ingest_info, DEFAULT_METADATA) session = SessionFactory.for_schema_base(StateBase) persons = dao.read_people(session) # Assert self.assertEqual( [expected_person, expected_person_2], converter.convert_schema_objects_to_entity(persons), )
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)
def test_ssvrFlatFieldMatchingWithSomeNullValues(self) -> None: db_person = generate_person(state_code=_US_MO) db_supervision_violation_response = generate_supervision_violation_response( person=db_person, state_code=_US_MO, response_type=StateSupervisionViolationResponseType. PERMANENT_DECISION.value, response_type_raw_text=StateSupervisionViolationResponseType. PERMANENT_DECISION.value, deciding_body_type=StateSupervisionViolationResponseDecidingBodyType .PAROLE_BOARD.value, deciding_body_type_raw_text= StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD. value, ) db_incarceration_period = generate_incarceration_period( person=db_person, state_code=_US_MO, external_id=_EXTERNAL_ID, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION.value, source_supervision_violation_response= db_supervision_violation_response, ) db_incarceration_sentence = generate_incarceration_sentence( person=db_person, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, state_code=_US_MO, external_id=_EXTERNAL_ID, incarceration_periods=[db_incarceration_period], ) db_sentence_group = generate_sentence_group( person=db_person, state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, incarceration_sentences=[db_incarceration_sentence], supervision_sentences=[], ) db_external_id = generate_external_id( person=db_person, state_code=_US_MO, id_type=_ID_TYPE, external_id=_EXTERNAL_ID, ) db_person.external_ids = [db_external_id] db_person.sentence_groups = [db_sentence_group] self._commit_to_db(db_person) # Even though this violation response doesn't have a deciding_body_type set, it will not clear the values in # db_supervision_violation_response. supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults( state_code=_US_MO, response_type=StateSupervisionViolationResponseType. PERMANENT_DECISION, response_type_raw_text=StateSupervisionViolationResponseType. PERMANENT_DECISION.value, ) incarceration_period = StateIncarcerationPeriod.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, source_supervision_violation_response= supervision_violation_response, status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) incarceration_sentence = StateIncarcerationSentence.new_with_defaults( status=StateSentenceStatus.PRESENT_WITHOUT_INFO, state_code=_US_MO, external_id=_EXTERNAL_ID, incarceration_periods=[incarceration_period], ) sentence_group = StateSentenceGroup.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[incarceration_sentence], supervision_sentences=[], ) external_id = StatePersonExternalId.new_with_defaults( state_code=_US_MO, id_type=_ID_TYPE, external_id=_EXTERNAL_ID) person = StatePerson.new_with_defaults( sentence_groups=[sentence_group], external_ids=[external_id], state_code=_US_MO, ) expected_person = self.to_entity(db_person) # Act 1 - Match session = self._session() matched_entities = entity_matching.match(session, _US_MO, ingested_people=[person]) self.assert_people_match_pre_and_post_commit([expected_person], matched_entities.people, session) self.assertEqual(0, matched_entities.error_count) self.assertEqual(1, matched_entities.total_root_entities)
def test_state_threeSentenceGroups_dontPersistAboveThreshold(self): # Arrange ingest_info = IngestInfo() ingest_info.state_people.add( state_person_id='1_GENERATE', state_sentence_group_ids=[SENTENCE_GROUP_ID, SENTENCE_GROUP_ID_2]) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID, county_code=COUNTY_CODE) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID_2, county_code=COUNTY_CODE) db_person = schema.StatePerson(person_id=ID, full_name=FULL_NAME_1) db_sentence_group = schema.StateSentenceGroup( sentence_group_id=ID, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID, state_code=REGION_CODE) db_sentence_group_2 = schema.StateSentenceGroup( sentence_group_id=ID_2, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_2, state_code=REGION_CODE) db_sentence_group_2_dup = schema.StateSentenceGroup( sentence_group_id=ID_3, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_2, state_code=REGION_CODE) db_external_id = schema.StatePersonExternalId(person_external_id_id=ID, state_code=REGION_CODE, external_id=EXTERNAL_ID, id_type=ID_TYPE) db_person.sentence_groups = [ db_sentence_group, db_sentence_group_2, db_sentence_group_2_dup ] db_person.external_ids = [db_external_id] expected_person = StatePerson.new_with_defaults(person_id=ID, full_name=FULL_NAME_1, external_ids=[], sentence_groups=[]) expected_external_id = StatePersonExternalId.new_with_defaults( person_external_id_id=ID, state_code=REGION_CODE, external_id=EXTERNAL_ID, id_type=ID_TYPE, person=expected_person) expected_person.external_ids = [expected_external_id] # No updates expected_sentence_group = StateSentenceGroup.new_with_defaults( sentence_group_id=ID, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID, state_code=REGION_CODE, person=expected_person) expected_sentence_group_2 = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_2, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_2, state_code=REGION_CODE, person=expected_person) expected_sentence_group_2_dup = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_3, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_2, state_code=REGION_CODE, person=expected_person) expected_person.sentence_groups = [ expected_sentence_group, expected_sentence_group_2, expected_sentence_group_2_dup ] session = SessionFactory.for_schema_base(StateBase) session.add(db_person) session.commit() # Act persistence.write(ingest_info, DEFAULT_METADATA) session = SessionFactory.for_schema_base(StateBase) persons = dao.read_people(session) # Assert self.assertEqual([expected_person], persons)
def test_state_threeSentenceGroups_persistsTwoBelowThreshold(self): # Arrange ingest_info = IngestInfo() ingest_info.state_people.add(state_person_id='1_GENERATE', state_sentence_group_ids=[ SENTENCE_GROUP_ID, SENTENCE_GROUP_ID_2, SENTENCE_GROUP_ID_3 ]) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID, county_code=COUNTY_CODE) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID_2, county_code=COUNTY_CODE) ingest_info.state_sentence_groups.add( state_sentence_group_id=SENTENCE_GROUP_ID_3, county_code=COUNTY_CODE) db_person = schema.StatePerson(person_id=ID, full_name=FULL_NAME_1) db_sentence_group = schema.StateSentenceGroup( sentence_group_id=ID, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID, state_code=REGION_CODE) db_sentence_group_2 = schema.StateSentenceGroup( sentence_group_id=ID_2, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_2, state_code=REGION_CODE) db_sentence_group_3 = schema.StateSentenceGroup( sentence_group_id=ID_3, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_3, state_code=REGION_CODE) db_external_id = schema.StatePersonExternalId(person_external_id_id=ID, state_code=REGION_CODE, external_id=EXTERNAL_ID, id_type=ID_TYPE) db_person.sentence_groups = [ db_sentence_group, db_sentence_group_2, db_sentence_group_3 ] db_person.external_ids = [db_external_id] db_person_2 = schema.StatePerson(person_id=ID_2, full_name=FULL_NAME_1) db_sentence_group_3_dup = schema.StateSentenceGroup( sentence_group_id=ID_4, status=StateSentenceStatus.EXTERNAL_UNKNOWN.value, external_id=SENTENCE_GROUP_ID_3, state_code=REGION_CODE) db_external_id_2 = schema.StatePersonExternalId( person_external_id_id=ID_2, state_code=REGION_CODE, external_id=EXTERNAL_ID_2, id_type=ID_TYPE) db_person_2.sentence_groups = [db_sentence_group_3_dup] db_person_2.external_ids = [db_external_id_2] expected_person = StatePerson.new_with_defaults(person_id=ID, full_name=FULL_NAME_1, external_ids=[], sentence_groups=[]) expected_external_id = StatePersonExternalId.new_with_defaults( person_external_id_id=ID, state_code=REGION_CODE, external_id=EXTERNAL_ID, id_type=ID_TYPE, person=expected_person) expected_sentence_group = StateSentenceGroup.new_with_defaults( sentence_group_id=ID, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID, state_code=REGION_CODE, county_code=COUNTY_CODE, person=expected_person) expected_sentence_group_2 = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_2, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_2, state_code=REGION_CODE, county_code=COUNTY_CODE, person=expected_person) # No county code because errors during match expected_sentence_group_3 = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_3, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_3, state_code=REGION_CODE, person=expected_person) expected_person.external_ids = [expected_external_id] expected_person.sentence_groups = [ expected_sentence_group, expected_sentence_group_2, expected_sentence_group_3 ] expected_person_2 = StatePerson.new_with_defaults( person_id=ID_2, full_name=FULL_NAME_1) expected_external_id_2 = StatePersonExternalId.new_with_defaults( person_external_id_id=ID_2, state_code=REGION_CODE, external_id=EXTERNAL_ID_2, id_type=ID_TYPE, person=expected_person_2) # No county code because unmatched expected_sentence_group_3_dup = StateSentenceGroup.new_with_defaults( sentence_group_id=ID_4, status=StateSentenceStatus.EXTERNAL_UNKNOWN, external_id=SENTENCE_GROUP_ID_3, state_code=REGION_CODE, person=expected_person_2) expected_person_2.sentence_groups = [expected_sentence_group_3_dup] expected_person_2.external_ids = [expected_external_id_2] session = SessionFactory.for_schema_base(StateBase) session.add(db_person) session.add(db_person_2) session.commit() # Act persistence.write(ingest_info, DEFAULT_METADATA) session = SessionFactory.for_schema_base(StateBase) persons = dao.read_people(session) # Assert self.assertEqual([expected_person, expected_person_2], converter.convert_schema_objects_to_entity(persons))
def test_ssvrFlatFieldMatchingRevocationTypeChanges(self) -> None: db_person = generate_person(state_code=_US_MO) db_supervision_violation_response = generate_supervision_violation_response( person=db_person, state_code=_US_MO, response_type=StateSupervisionViolationResponseType. PERMANENT_DECISION.value, response_type_raw_text=StateSupervisionViolationResponseType. PERMANENT_DECISION.value, deciding_body_type=StateSupervisionViolationResponseDecidingBodyType .PAROLE_BOARD.value, deciding_body_type_raw_text= StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD. value, revocation_type=StateSupervisionViolationResponseRevocationType. REINCARCERATION.value, revocation_type_raw_text="S", ) db_incarceration_period = generate_incarceration_period( person=db_person, state_code=_US_MO, external_id=_EXTERNAL_ID, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION.value, source_supervision_violation_response= db_supervision_violation_response, ) db_incarceration_sentence = generate_incarceration_sentence( person=db_person, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, state_code=_US_MO, external_id=_EXTERNAL_ID, incarceration_periods=[db_incarceration_period], ) db_sentence_group = generate_sentence_group( person=db_person, state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, incarceration_sentences=[db_incarceration_sentence], supervision_sentences=[], ) db_external_id = generate_external_id( person=db_person, state_code=_US_MO, id_type=_ID_TYPE, external_id=_EXTERNAL_ID, ) db_person.external_ids = [db_external_id] db_person.sentence_groups = [db_sentence_group] self._commit_to_db(db_person) # Even though the revocation type has changed, we still allow a match supervision_violation_response = StateSupervisionViolationResponse.new_with_defaults( state_code=_US_MO, response_type=StateSupervisionViolationResponseType. PERMANENT_DECISION, response_type_raw_text=StateSupervisionViolationResponseType. PERMANENT_DECISION.value, deciding_body_type=StateSupervisionViolationResponseDecidingBodyType .PAROLE_BOARD, deciding_body_type_raw_text= StateSupervisionViolationResponseDecidingBodyType.PAROLE_BOARD. value, revocation_type=StateSupervisionViolationResponseRevocationType. TREATMENT_IN_PRISON, revocation_type_raw_text="L", ) incarceration_period = StateIncarcerationPeriod.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, source_supervision_violation_response= supervision_violation_response, status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) incarceration_sentence = StateIncarcerationSentence.new_with_defaults( status=StateSentenceStatus.PRESENT_WITHOUT_INFO, state_code=_US_MO, external_id=_EXTERNAL_ID, incarceration_periods=[incarceration_period], ) sentence_group = StateSentenceGroup.new_with_defaults( state_code=_US_MO, external_id=_EXTERNAL_ID_WITH_SUFFIX, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[incarceration_sentence], supervision_sentences=[], ) external_id = StatePersonExternalId.new_with_defaults( state_code=_US_MO, id_type=_ID_TYPE, external_id=_EXTERNAL_ID) person = StatePerson.new_with_defaults( sentence_groups=[sentence_group], external_ids=[external_id], state_code=_US_MO, ) expected_person = self.to_entity(db_person) expected_ip = (expected_person.sentence_groups[0]. incarceration_sentences[0].incarceration_periods[0]) expected_ssvr = expected_ip.source_supervision_violation_response expected_ssvr.revocation_type = ( StateSupervisionViolationResponseRevocationType.TREATMENT_IN_PRISON ) expected_ssvr.revocation_type_raw_text = "L" # Act 1 - Match session = self._session() matched_entities = entity_matching.match(session, _US_MO, ingested_people=[person]) self.assert_people_match_pre_and_post_commit([expected_person], matched_entities.people, session) self.assertEqual(0, matched_entities.error_count) self.assertEqual(1, matched_entities.total_root_entities)
def test_associateSvrsWithIps(self): # Arrange ip_1 = StateIncarcerationPeriod.new_with_defaults( admission_date=_DATE_1, admission_reason= StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION) ip_2 = StateIncarcerationPeriod.new_with_defaults( admission_date=_DATE_2, admission_reason= StateIncarcerationPeriodAdmissionReason.PROBATION_REVOCATION) placeholder_is = StateIncarcerationSentence.new_with_defaults( incarceration_periods=[ip_1, ip_2]) svr_1 = StateSupervisionViolationResponse.new_with_defaults( response_date=_DATE_1 - datetime.timedelta(days=1), revocation_type=StateSupervisionViolationResponseRevocationType. REINCARCERATION) svr_2 = StateSupervisionViolationResponse.new_with_defaults( response_date=_DATE_2 + datetime.timedelta(days=1), revocation_type=StateSupervisionViolationResponseRevocationType. REINCARCERATION) svr_3 = StateSupervisionViolationResponse.new_with_defaults( response_date=_DATE_2 + datetime.timedelta(days=30), revocation_type=StateSupervisionViolationResponseRevocationType. RETURN_TO_SUPERVISION) placeholder_sv = StateSupervisionViolation.new_with_defaults( supervision_violation_responses=[svr_1, svr_2, svr_3]) placeholder_sp = StateSupervisionPeriod.new_with_defaults( supervision_violation_entries=[placeholder_sv]) placeholder_ss = StateSupervisionSentence.new_with_defaults( supervision_periods=[placeholder_sp]) placeholder_sg = StateSentenceGroup.new_with_defaults( incarceration_sentences=[placeholder_is], supervision_sentences=[placeholder_ss]) placeholder_person = StatePerson.new_with_defaults( sentence_groups=[placeholder_sg]) external_id = StatePersonExternalId.new_with_defaults( external_id=_EXTERNAL_ID) person_without_revocation = StatePerson.new_with_defaults( external_ids=[external_id]) expected_svr_1 = attr.evolve(svr_1) expected_svr_2 = attr.evolve(svr_2) expected_svr_3 = attr.evolve(svr_3) expected_placeholder_sv = attr.evolve( placeholder_sv, supervision_violation_responses=[expected_svr_1, expected_svr_2, expected_svr_3]) expected_placeholder_sp = attr.evolve( placeholder_sp, supervision_violation_entries=[expected_placeholder_sv]) expected_placeholder_ss = attr.evolve( placeholder_ss, supervision_periods=[expected_placeholder_sp]) expected_ip_1 = attr.evolve( ip_1, source_supervision_violation_response=expected_svr_1) expected_ip_2 = attr.evolve( ip_2, source_supervision_violation_response=expected_svr_2) expected_placeholder_is = attr.evolve( placeholder_is, incarceration_periods=[expected_ip_1, expected_ip_2]) expected_placeholder_sg = attr.evolve( placeholder_sg, supervision_sentences=[expected_placeholder_ss], incarceration_sentences=[expected_placeholder_is]) expected_placeholder_person = attr.evolve( placeholder_person, sentence_groups=[expected_placeholder_sg]) expected_person_without_revocation = attr.evolve( person_without_revocation) # Act input_people = \ converter.convert_entity_people_to_schema_people( [person_without_revocation, placeholder_person]) associate_revocation_svrs_with_ips(input_people) # Assert self.assert_people_match( [expected_person_without_revocation, expected_placeholder_person], input_people)
def testConvert_FullIngestInfo(self): # Arrange metadata = IngestMetadata('us_nd', _JURISDICTION_ID, _INGEST_TIME, system_level=SystemLevel.STATE) ingest_info = IngestInfo() ingest_info.state_agents.add(state_agent_id='AGENT_ID1', full_name='AGENT WILLIAMS') ingest_info.state_agents.add(state_agent_id='AGENT_ID2', full_name='AGENT HERNANDEZ') ingest_info.state_agents.add(state_agent_id='AGENT_ID3', full_name='AGENT SMITH') ingest_info.state_agents.add(state_agent_id='JUDGE_AGENT_ID_1', full_name='JUDGE JUDY') # We expect the external_ids coming in to have the format # [type]:[external_id] ii_person_external_id_1 = US_ND_ELITE + ':' + 'EXTERNAL_ID1' ii_person_external_id_2 = US_ND_SID + ':' + 'EXTERNAL_ID2' ingest_info.state_people.add( state_person_id='PERSON_ID', state_person_race_ids=['RACE_ID1', 'RACE_ID2'], state_person_ethnicity_ids=['ETHNICITY_ID'], state_alias_ids=['ALIAS_ID1', 'ALIAS_ID2'], state_person_external_ids_ids=[ ii_person_external_id_1, ii_person_external_id_2 ], state_assessment_ids=['ASSESSMENT_ID'], state_sentence_group_ids=['GROUP_ID1', 'GROUP_ID2']) ingest_info.state_person_races.add( state_person_race_id='RACE_ID1', race='WHITE', ) ingest_info.state_person_races.add(state_person_race_id='RACE_ID2', race='OTHER') ingest_info.state_person_ethnicities.add( state_person_ethnicity_id='ETHNICITY_ID', ethnicity='HISPANIC') ingest_info.state_aliases.add(state_alias_id='ALIAS_ID1', full_name='LONNY BREAUX') ingest_info.state_aliases.add(state_alias_id='ALIAS_ID2', full_name='FRANK OCEAN') ingest_info.state_person_external_ids.add( state_person_external_id_id=ii_person_external_id_1, id_type=US_ND_ELITE) ingest_info.state_person_external_ids.add( state_person_external_id_id=ii_person_external_id_2, id_type=US_ND_SID) ingest_info.state_assessments.add(state_assessment_id='ASSESSMENT_ID', assessment_class='MENTAL_HEALTH', conducting_agent_id='AGENT_ID1') ingest_info.state_sentence_groups.add( state_sentence_group_id='GROUP_ID1', state_supervision_sentence_ids=['SUPERVISION_SENTENCE_ID1'], state_incarceration_sentence_ids=[ 'INCARCERATION_SENTENCE_ID1', 'INCARCERATION_SENTENCE_ID2' ]) ingest_info.state_sentence_groups.add( state_sentence_group_id='GROUP_ID2', state_supervision_sentence_ids=['SUPERVISION_SENTENCE_ID2'], state_fine_ids=['FINE_ID']) ingest_info.state_fines.add(state_fine_id='FINE_ID', status='PAID') ingest_info.state_supervision_sentences.add( state_supervision_sentence_id='SUPERVISION_SENTENCE_ID1', state_charge_ids=['CHARGE_ID1', 'CHARGE_ID2'], state_supervision_period_ids=['S_PERIOD_ID1']) ingest_info.state_supervision_sentences.add( state_supervision_sentence_id='SUPERVISION_SENTENCE_ID2', state_charge_ids=['CHARGE_ID2'], state_supervision_period_ids=['S_PERIOD_ID2']) ingest_info.state_incarceration_sentences.add( state_incarceration_sentence_id='INCARCERATION_SENTENCE_ID1', state_charge_ids=['CHARGE_ID1'], state_incarceration_period_ids=['I_PERIOD_ID']) ingest_info.state_incarceration_sentences.add( state_incarceration_sentence_id='INCARCERATION_SENTENCE_ID2', state_charge_ids=['CHARGE_ID2', 'CHARGE_ID3'], state_supervision_period_ids=['S_PERIOD_ID3']) ingest_info.state_charges.add( state_charge_id='CHARGE_ID1', state_court_case_id='CASE_ID', state_bond_id='BOND_ID', classification_type='M', classification_subtype='1', ) ingest_info.state_charges.add( state_charge_id='CHARGE_ID2', state_court_case_id='CASE_ID', classification_type='M', classification_subtype='2', ) ingest_info.state_charges.add(state_charge_id='CHARGE_ID3', state_court_case_id='CASE_ID', classification_type='F', classification_subtype='3') ingest_info.state_court_cases.add( state_court_case_id='CASE_ID', judge_id='JUDGE_AGENT_ID_1', ) ingest_info.state_bonds.add(state_bond_id='BOND_ID', status='POSTED') ingest_info.state_supervision_periods.add( state_supervision_period_id='S_PERIOD_ID1', state_supervision_violation_ids=['VIOLATION_ID'], supervision_type='PAROLE', supervision_level='MED') ingest_info.state_supervision_periods.add( state_supervision_period_id='S_PERIOD_ID2', supervision_type='PAROLE') ingest_info.state_supervision_periods.add( state_supervision_period_id='S_PERIOD_ID3', state_assessment_ids=['ASSESSMENT_ID'], supervision_type='PROBATION') ingest_info.state_incarceration_periods.add( state_incarceration_period_id='I_PERIOD_ID', state_incarceration_incident_ids=['INCIDENT_ID'], state_parole_decision_ids=['DECISION_ID'], state_assessment_ids=['ASSESSMENT_ID'], ) ingest_info.state_supervision_violations.add( state_supervision_violation_id='VIOLATION_ID', state_supervision_violation_response_ids=['RESPONSE_ID']) ingest_info.state_supervision_violation_responses.add( state_supervision_violation_response_id='RESPONSE_ID', response_type='CITATION') ingest_info.state_incarceration_incidents.add( state_incarceration_incident_id='INCIDENT_ID', incident_type='CONTRABAND', responding_officer_id='AGENT_ID2', state_incarceration_incident_outcome_ids=['INCIDENT_OUTCOME_ID'], ) ingest_info.state_incarceration_incident_outcomes.add( state_incarceration_incident_outcome_id='INCIDENT_OUTCOME_ID', outcome_type='GOOD_TIME_LOSS', date_effective='2/10/2018', state_code='US_ND', outcome_description='Good time', punishment_length_days='7', ) ingest_info.state_parole_decisions.add( state_parole_decision_id='DECISION_ID', decision_agent_ids=['AGENT_ID2', 'AGENT_ID3']) # Act result = self._convert_and_throw_on_errors(ingest_info, metadata) # Assert incident_outcome = StateIncarcerationIncidentOutcome.new_with_defaults( external_id='INCIDENT_OUTCOME_ID', outcome_type=StateIncarcerationIncidentOutcomeType.GOOD_TIME_LOSS, outcome_type_raw_text='GOOD_TIME_LOSS', date_effective=datetime.date(year=2018, month=2, day=10), state_code='US_ND', outcome_description='GOOD TIME', punishment_length_days=7, ) incident = StateIncarcerationIncident.new_with_defaults( external_id='INCIDENT_ID', state_code='US_ND', incident_type=StateIncarcerationIncidentType.CONTRABAND, incident_type_raw_text='CONTRABAND', responding_officer=StateAgent.new_with_defaults( external_id='AGENT_ID2', state_code='US_ND', full_name='{"full_name": "AGENT HERNANDEZ"}', ), incarceration_incident_outcomes=[incident_outcome]) assessment = StateAssessment.new_with_defaults( external_id='ASSESSMENT_ID', state_code='US_ND', assessment_class=StateAssessmentClass.MENTAL_HEALTH, assessment_class_raw_text='MENTAL_HEALTH', conducting_agent=StateAgent.new_with_defaults( external_id='AGENT_ID1', state_code='US_ND', full_name='{"full_name": "AGENT WILLIAMS"}', )) violation = StateSupervisionViolation.new_with_defaults( external_id='VIOLATION_ID', state_code='US_ND', supervision_violation_responses=[ StateSupervisionViolationResponse.new_with_defaults( external_id='RESPONSE_ID', state_code='US_ND', response_type=StateSupervisionViolationResponseType. CITATION, response_type_raw_text='CITATION') ]) court_case = StateCourtCase.new_with_defaults( external_id='CASE_ID', state_code='US_ND', status=StateCourtCaseStatus.PRESENT_WITHOUT_INFO, court_type=StateCourtType.PRESENT_WITHOUT_INFO, judge=StateAgent.new_with_defaults( external_id='JUDGE_AGENT_ID_1', state_code='US_ND', full_name='{"full_name": "JUDGE JUDY"}', )) charge_1 = StateCharge.new_with_defaults( external_id='CHARGE_ID1', classification_type=StateChargeClassificationType.MISDEMEANOR, classification_type_raw_text='M', classification_subtype='1', state_code='US_ND', status=ChargeStatus.PRESENT_WITHOUT_INFO, court_case=court_case, bond=StateBond.new_with_defaults(external_id='BOND_ID', state_code='US_ND', status=BondStatus.POSTED, status_raw_text='POSTED')) charge_2 = StateCharge.new_with_defaults( external_id='CHARGE_ID2', classification_type=StateChargeClassificationType.MISDEMEANOR, classification_type_raw_text='M', classification_subtype='2', state_code='US_ND', status=ChargeStatus.PRESENT_WITHOUT_INFO, court_case=court_case) charge_3 = StateCharge.new_with_defaults( external_id='CHARGE_ID3', state_code='US_ND', classification_type=StateChargeClassificationType.FELONY, classification_type_raw_text='F', classification_subtype='3', status=ChargeStatus.PRESENT_WITHOUT_INFO, court_case=court_case) expected_result = [ StatePerson.new_with_defaults( external_ids=[ StatePersonExternalId.new_with_defaults( external_id='EXTERNAL_ID1', state_code='US_ND', id_type=US_ND_ELITE), StatePersonExternalId.new_with_defaults( external_id='EXTERNAL_ID2', state_code='US_ND', id_type=US_ND_SID) ], races=[ StatePersonRace(race=Race.WHITE, race_raw_text='WHITE', state_code='US_ND'), StatePersonRace(race=Race.OTHER, race_raw_text='OTHER', state_code='US_ND'), ], ethnicities=[ StatePersonEthnicity(ethnicity=Ethnicity.HISPANIC, ethnicity_raw_text='HISPANIC', state_code='US_ND') ], aliases=[ StatePersonAlias.new_with_defaults( full_name='{"full_name": "LONNY BREAUX"}', state_code='US_ND'), StatePersonAlias.new_with_defaults( full_name='{"full_name": "FRANK OCEAN"}', state_code='US_ND'), ], assessments=[assessment], sentence_groups=[ StateSentenceGroup.new_with_defaults( external_id='GROUP_ID1', status=StateSentenceStatus.PRESENT_WITHOUT_INFO, state_code='US_ND', supervision_sentences=[ StateSupervisionSentence.new_with_defaults( external_id='SUPERVISION_SENTENCE_ID1', state_code='US_ND', status=StateSentenceStatus. PRESENT_WITHOUT_INFO, charges=[charge_1, charge_2], supervision_periods=[ StateSupervisionPeriod.new_with_defaults( external_id='S_PERIOD_ID1', status=StateSupervisionPeriodStatus. PRESENT_WITHOUT_INFO, supervision_level=StateSupervisionLevel .MEDIUM, supervision_level_raw_text='MED', state_code='US_ND', supervision_type=StateSupervisionType. PAROLE, supervision_type_raw_text='PAROLE', supervision_violations=[violation]) ]) ], incarceration_sentences=[ StateIncarcerationSentence.new_with_defaults( external_id='INCARCERATION_SENTENCE_ID1', state_code='US_ND', status=StateSentenceStatus. PRESENT_WITHOUT_INFO, incarceration_type=StateIncarcerationType. STATE_PRISON, charges=[charge_1], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( external_id='I_PERIOD_ID', status=StateIncarcerationPeriodStatus. PRESENT_WITHOUT_INFO, incarceration_type= StateIncarcerationType.STATE_PRISON, state_code='US_ND', incarceration_incidents=[incident], parole_decisions=[ StateParoleDecision. new_with_defaults( external_id='DECISION_ID', state_code='US_ND', decision_agents=[ StateAgent. new_with_defaults( external_id='AGENT_ID2', state_code='US_ND', full_name= '{"full_name": ' '"AGENT HERNANDEZ"}'), StateAgent. new_with_defaults( external_id='AGENT_ID3', state_code='US_ND', full_name= '{"full_name": ' '"AGENT SMITH"}') ]) ], assessments=[assessment], ) ]), StateIncarcerationSentence.new_with_defaults( external_id='INCARCERATION_SENTENCE_ID2', state_code='US_ND', status=StateSentenceStatus. PRESENT_WITHOUT_INFO, incarceration_type=StateIncarcerationType. STATE_PRISON, charges=[charge_2, charge_3], supervision_periods=[ StateSupervisionPeriod.new_with_defaults( external_id='S_PERIOD_ID3', status=StateSupervisionPeriodStatus. PRESENT_WITHOUT_INFO, state_code='US_ND', supervision_type=StateSupervisionType. PROBATION, supervision_type_raw_text='PROBATION', assessments=[assessment]) ]) ]), StateSentenceGroup.new_with_defaults( external_id='GROUP_ID2', status=StateSentenceStatus.PRESENT_WITHOUT_INFO, state_code='US_ND', supervision_sentences=[ StateSupervisionSentence.new_with_defaults( external_id='SUPERVISION_SENTENCE_ID2', state_code='US_ND', status=StateSentenceStatus. PRESENT_WITHOUT_INFO, charges=[charge_2], supervision_periods=[ StateSupervisionPeriod.new_with_defaults( external_id='S_PERIOD_ID2', status=StateSupervisionPeriodStatus. PRESENT_WITHOUT_INFO, state_code='US_ND', supervision_type=StateSupervisionType. PAROLE, supervision_type_raw_text='PAROLE', ) ]) ], fines=[ StateFine.new_with_defaults( external_id='FINE_ID', state_code='US_ND', status=StateFineStatus.PAID, status_raw_text='PAID') ]) ]) ] print(expected_result, "\n\n\n", result) self.assertEqual(result, expected_result)