def test_us_id_case_compliance_on_date(self): supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id='sp1', state_code='US_ID', custodial_authority='US_ID_DOC', start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, supervision_level=StateSupervisionLevel.MEDIUM) case_type = StateSupervisionCaseType.GENERAL assessments = [ StateAssessment.new_with_defaults( state_code='US_ID', assessment_type=StateAssessmentType.LSIR, assessment_score=33, assessment_level=StateAssessmentLevel.HIGH, assessment_date=date(2018, 3, 10)) ] supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 3, 6), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED), StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 4, 6), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED), ] start_of_supervision = supervision_period.start_date compliance_evaluation_date = date(2018, 4, 30) compliance = us_id_case_compliance_on_date( supervision_period, case_type, start_of_supervision, compliance_evaluation_date, assessments, supervision_contacts) self.assertEqual( SupervisionCaseCompliance( date_of_evaluation=compliance_evaluation_date, assessment_count=0, assessment_up_to_date=True, face_to_face_count=1, face_to_face_frequency_sufficient=True), compliance)
def test_home_visit_frequency_sufficient_medium_level(self, ) -> None: """Tests home visit frequency for medium level""" contact_1 = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 3, 8), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, location=StateSupervisionContactLocation.RESIDENCE, ) contact_2 = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2019, 3, 6), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, location=StateSupervisionContactLocation.RESIDENCE, ) start_of_supervision = date(2018, 3, 5) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code="US_ND", start_date=start_of_supervision, termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, supervision_level=StateSupervisionLevel.MEDIUM, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_contacts = [contact_1, contact_2] evaluation_date = start_of_supervision + relativedelta(days=375) us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=start_of_supervision, assessments=[], supervision_contacts=supervision_contacts, ) home_visit_frequency_sufficient = ( us_nd_supervision_compliance._home_visit_frequency_is_sufficient( evaluation_date)) self.assertTrue(home_visit_frequency_sufficient)
def test_face_to_face_frequency_sufficient_contacts_invalid_type(self): supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id='sp1', state_code='US_ID', custodial_authority='US_ID_DOC', start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason.COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.PROBATION, ) supervision_contacts = [StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=supervision_period.start_date, # Only contact is invalid type contact_type=StateSupervisionContactType.WRITTEN_MESSAGE, status=StateSupervisionContactStatus.COMPLETED )] start_of_supervision = supervision_period.start_date compliance_evaluation_date = start_of_supervision\ + relativedelta(days=(NEW_SUPERVISION_CONTACT_DEADLINE_BUSINESS_DAYS + 1)) face_to_face_frequency_sufficient = _face_to_face_contact_frequency_is_sufficient(supervision_period, start_of_supervision, compliance_evaluation_date, supervision_contacts) self.assertFalse(face_to_face_frequency_sufficient)
def test_face_to_face_frequency_sufficient_contacts_medium_level_not_up_to_date(self): supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id='sp1', state_code='US_ID', custodial_authority='US_ID_DOC', start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason.COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.PROBATION, supervision_level=StateSupervisionLevel.MEDIUM ) supervision_contacts = [StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=supervision_period.start_date, contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED )] start_of_supervision = supervision_period.start_date compliance_evaluation_date = start_of_supervision \ + relativedelta(days=(MEDIUM_SUPERVISION_CONTACT_FREQUENCY_DAYS + 10)) face_to_face_frequency_sufficient = _face_to_face_contact_frequency_is_sufficient(supervision_period, start_of_supervision, compliance_evaluation_date, supervision_contacts) self.assertFalse(face_to_face_frequency_sufficient)
def test_face_to_face_frequency_sufficient_contacts_maximum_level_up_to_date_two_contacts(self): supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id='sp1', state_code='US_ID', custodial_authority='US_ID_DOC', start_date=date(2018, 3, 5), termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason.COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason.DISCHARGE, supervision_period_supervision_type=StateSupervisionPeriodSupervisionType.PROBATION, supervision_level=StateSupervisionLevel.MAXIMUM ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=supervision_period.start_date + relativedelta(days=30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED ), StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=supervision_period.start_date + relativedelta(days=40), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED ) ] start_of_supervision = supervision_period.start_date compliance_evaluation_date = start_of_supervision + \ relativedelta(days=50) face_to_face_frequency_sufficient = _face_to_face_contact_frequency_is_sufficient(supervision_period, start_of_supervision, compliance_evaluation_date, supervision_contacts) self.assertTrue(face_to_face_frequency_sufficient)
def test_home_visit_frequency_sufficient_initial_visit_not_at_residence( self, ) -> None: """Tests for when the only contact does not have location RESIDENCE.""" start_of_supervision = date(2018, 3, 5) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code="US_ND", start_date=start_of_supervision, termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, supervision_level=StateSupervisionLevel.MINIMUM, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=start_of_supervision + relativedelta(days=1), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, location=StateSupervisionContactLocation.SUPERVISION_OFFICE, ) ] evaluation_date = start_of_supervision + relativedelta( days=NEW_SUPERVISION_HOME_VISIT_DEADLINE_DAYS + 1) us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=start_of_supervision, assessments=[], supervision_contacts=supervision_contacts, ) home_visit_frequency_sufficient = ( us_nd_supervision_compliance._home_visit_frequency_is_sufficient( evaluation_date)) self.assertFalse(home_visit_frequency_sufficient)
def test_face_to_face_frequency_sufficient_contacts_attempted_general_case( self, ) -> None: """Tests when the only face to face contact is attempted, but not completed.""" start_of_supervision = date(2018, 3, 5) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code="US_ND", start_date=start_of_supervision, termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, supervision_level=StateSupervisionLevel.MAXIMUM, ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=supervision_period.start_date, contact_type=StateSupervisionContactType.FACE_TO_FACE, # Only contact was not completed status=StateSupervisionContactStatus.ATTEMPTED, ) ] evaluation_date = start_of_supervision + relativedelta(days=2) us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=start_of_supervision, assessments=[], supervision_contacts=supervision_contacts, ) face_to_face_frequency_sufficient = ( us_nd_supervision_compliance. _face_to_face_contact_frequency_is_sufficient(evaluation_date)) self.assertFalse(face_to_face_frequency_sufficient)
def test_face_to_face_frequency_sufficient_contacts_before_supervision_start( self, ) -> None: """Tests for when the only face to face contacts is occurs prior to start of supervision.""" start_of_supervision = date(2018, 3, 5) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code="US_ND", start_date=start_of_supervision, termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, supervision_level=StateSupervisionLevel.MINIMUM, ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code="US_ND", # Only contact happened before supervision started contact_date=start_of_supervision - relativedelta(days=100), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) ] evaluation_date = start_of_supervision + relativedelta(days=3) us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=start_of_supervision, assessments=[], supervision_contacts=supervision_contacts, ) face_to_face_frequency_sufficient = ( us_nd_supervision_compliance. _face_to_face_contact_frequency_is_sufficient(evaluation_date)) self.assertFalse(face_to_face_frequency_sufficient)
def generate_supervision_case_compliance( self, start_of_supervision: date, termination_date: date, supervision_level: StateSupervisionLevel, contact_dates: List[date], ) -> UsNdSupervisionCaseCompliance: """Tests face to face contacts for the maximum level case.""" supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code="US_ND", start_date=start_of_supervision, termination_date=termination_date, admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, supervision_level=supervision_level, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=contact_date, contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) for contact_date in contact_dates ] # note that this is outside 30 days but within the next calendar month # so we should be good return UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=start_of_supervision, assessments=[], supervision_contacts=supervision_contacts, )
def test_face_to_face_frequency_sufficient(self) -> None: """Tests for when the face to face contacts is sufficient.""" start_of_supervision = date(2018, 3, 5) # This was a Monday supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code=StateCode.US_ND.value, start_date=start_of_supervision, termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, supervision_level=StateSupervisionLevel.MINIMUM, ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code=StateCode.US_ND.value, contact_date=supervision_period.start_date, contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) ] us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=start_of_supervision, assessments=[], supervision_contacts=supervision_contacts, ) self.assertTrue( us_nd_supervision_compliance. _face_to_face_contact_frequency_is_sufficient( start_of_supervision))
def test_face_to_face_frequency_sufficient(self): # TODO(#5199): Update once face to face logic is implemented. supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code=StateCode.US_ND.value, start_date=date(2018, 3, 5), # This was a Monday termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_contacts = [ StateSupervisionContact.new_with_defaults( state_code=StateCode.US_ND.value, contact_date=supervision_period.start_date, contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) ] start_of_supervision = supervision_period.start_date evaluation_date = start_of_supervision us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=evaluation_date, assessments=[], supervision_contacts=supervision_contacts, ) self.assertIsNone( us_nd_supervision_compliance. _face_to_face_contact_frequency_is_sufficient(evaluation_date))
def test_face_to_face_contacts_in_compliance_month(self): evaluation_date = date(2018, 4, 30) contact_1 = StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 4, 1), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_2 = StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 4, 15), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_3 = StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 4, 30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_out_of_range = StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 3, 30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_incomplete = StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 4, 30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.ATTEMPTED, ) contact_wrong_type = StateSupervisionContact.new_with_defaults( state_code='US_ID', contact_date=date(2018, 4, 30), contact_type=StateSupervisionContactType.WRITTEN_MESSAGE, status=StateSupervisionContactStatus.COMPLETED, ) contacts = [ contact_1, contact_2, contact_3, contact_incomplete, contact_out_of_range, contact_wrong_type ] expected_contacts = [contact_1, contact_2, contact_3] self.assertEqual( len(expected_contacts), _face_to_face_contacts_in_compliance_month(evaluation_date, contacts))
def test_moveContactsOntoSupervisionPeriodsForPerson(self): self.maxDiff = None # Arrange sc_1 = StateSupervisionContact.new_with_defaults(contact_date=_DATE_2) sc_2 = StateSupervisionContact.new_with_defaults(contact_date=_DATE_3) sc_3 = StateSupervisionContact.new_with_defaults(contact_date=_DATE_8) placeholder_sp_ss = StateSupervisionPeriod.new_with_defaults( supervision_contacts=[sc_1, sc_3]) sp_ss = StateSupervisionPeriod.new_with_defaults( external_id=_EXTERNAL_ID, start_date=_DATE_1, termination_date=_DATE_3) sp_2_ss = StateSupervisionPeriod.new_with_defaults( external_id=_EXTERNAL_ID_2, start_date=_DATE_7) ss = StateSupervisionSentence.new_with_defaults( external_id=_EXTERNAL_ID, supervision_periods=[sp_ss, sp_2_ss, placeholder_sp_ss]) placeholder_sp_is = StateSupervisionPeriod.new_with_defaults( supervision_contacts=[sc_2, sc_3]) sp_is = StateSupervisionPeriod.new_with_defaults( external_id=_EXTERNAL_ID_3, start_date=_DATE_2, termination_date=_DATE_3) sp_2_is = StateSupervisionPeriod.new_with_defaults( external_id=_EXTERNAL_ID_4, start_date=_DATE_3, termination_date=_DATE_6) inc_s = StateIncarcerationSentence.new_with_defaults( external_id=_EXTERNAL_ID, supervision_periods=[sp_is, sp_2_is, placeholder_sp_is]) sg = StateSentenceGroup.new_with_defaults( incarceration_sentences=[inc_s]) sg_2 = StateSentenceGroup.new_with_defaults(supervision_sentences=[ss]) state_person = StatePerson.new_with_defaults( sentence_groups=[sg, sg_2]) expected_sc_1 = attr.evolve(sc_1) expected_sc_2 = attr.evolve(sc_2) expected_sc_3 = attr.evolve(sc_3) expected_placeholder_sp_ss = attr.evolve(placeholder_sp_ss, supervision_contacts=[]) expected_sp_ss = attr.evolve(sp_ss, supervision_contacts=[expected_sc_1]) expected_sp_2_ss = attr.evolve(sp_2_ss, supervision_contacts=[expected_sc_3]) expected_ss = attr.evolve(ss, supervision_periods=[ expected_placeholder_sp_ss, expected_sp_ss, expected_sp_2_ss ]) expected_placeholder_sp_is = attr.evolve(placeholder_sp_is, supervision_contacts=[]) expected_sp_is = attr.evolve(sp_is, supervision_contacts=[expected_sc_1]) expected_sp_2_is = attr.evolve(sp_2_is, supervision_contacts=[expected_sc_2]) expected_inc_s = attr.evolve(inc_s, supervision_periods=[ expected_placeholder_sp_is, expected_sp_is, expected_sp_2_is ]) expected_sg = attr.evolve(sg, incarceration_sentences=[expected_inc_s]) expected_sg_2 = attr.evolve(sg_2, supervision_sentences=[expected_ss]) expected_person = attr.evolve( state_person, sentence_groups=[expected_sg, expected_sg_2]) # Act input_people = converter.convert_entity_people_to_schema_people( [state_person]) move_contacts_onto_supervision_periods_for_person( input_people, _STATE_CODE) # Assert self.assert_people_match([expected_person], input_people)
def test_moveContactsOntoSupervisionPeriodsForPerson_contactNoLongerOverlaps( self): # Act sc_ss = StateSupervisionContact.new_with_defaults( supervision_contact_id=_ID, state_code=_STATE_CODE, contact_date=_DATE_4) # This supervision period, which has already been written to the DB, has presumably been updated so that the # date range no longer overlaps with the attached violation (or the violation has been updated). sp_ss = StateSupervisionPeriod.new_with_defaults( supervision_period_id=_ID, external_id=_EXTERNAL_ID, state_code=_STATE_CODE, start_date=_DATE_1, termination_date=_DATE_3, supervision_contacts=[sc_ss]) ss = StateSupervisionSentence.new_with_defaults( supervision_sentence_id=_ID, external_id=_EXTERNAL_ID, state_code=_STATE_CODE, supervision_periods=[sp_ss]) sg = StateSentenceGroup.new_with_defaults(external_id=_EXTERNAL_ID, sentence_group_id=_ID, state_code=_STATE_CODE, supervision_sentences=[ss]) state_person = StatePerson.new_with_defaults(person_id=_ID, sentence_groups=[sg]) expected_sp_ss = attr.evolve(sp_ss, supervision_contacts=[]) expected_ss = attr.evolve(ss, supervision_periods=[expected_sp_ss]) expected_sg = attr.evolve(sg, supervision_sentences=[expected_ss]) expected_sc_ss = attr.evolve(sc_ss) expected_placeholder_sp = StateSupervisionPeriod.new_with_defaults( state_code=_STATE_CODE, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, supervision_contacts=[expected_sc_ss]) expected_placeholder_ss = StateSupervisionSentence.new_with_defaults( state_code=_STATE_CODE, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, supervision_periods=[expected_placeholder_sp]) expected_placeholder_sg = StateSentenceGroup.new_with_defaults( state_code=_STATE_CODE, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, supervision_sentences=[expected_placeholder_ss]) expected_person = attr.evolve( state_person, sentence_groups=[expected_sg, expected_placeholder_sg]) # Act input_people = converter.convert_entity_people_to_schema_people( [state_person]) move_contacts_onto_supervision_periods_for_person( input_people, _STATE_CODE) # Assert self.assert_people_match([expected_person], input_people)
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 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_face_to_face_contacts_in_compliance_month(self) -> None: evaluation_date = date(2018, 4, 30) contact_1 = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 4, 1), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_2 = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 4, 15), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_3 = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 4, 30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_out_of_range = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 3, 30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.COMPLETED, ) contact_incomplete = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 4, 30), contact_type=StateSupervisionContactType.FACE_TO_FACE, status=StateSupervisionContactStatus.ATTEMPTED, ) contact_wrong_type = StateSupervisionContact.new_with_defaults( state_code="US_ND", contact_date=date(2018, 4, 30), contact_type=StateSupervisionContactType.WRITTEN_MESSAGE, status=StateSupervisionContactStatus.COMPLETED, ) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, external_id="sp1", state_code=StateCode.US_ND.value, start_date=date(2018, 3, 5), # This was a Monday termination_date=date(2018, 5, 19), admission_reason=StateSupervisionPeriodAdmissionReason. COURT_SENTENCE, termination_reason=StateSupervisionPeriodTerminationReason. DISCHARGE, supervision_period_supervision_type= StateSupervisionPeriodSupervisionType.PROBATION, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) contacts = [ contact_1, contact_2, contact_3, contact_incomplete, contact_out_of_range, contact_wrong_type, ] expected_contacts = [contact_3] us_nd_supervision_compliance = UsNdSupervisionCaseCompliance( self.person, supervision_period=supervision_period, case_type=StateSupervisionCaseType.GENERAL, start_of_supervision=evaluation_date, assessments=[], supervision_contacts=contacts, ) self.assertEqual( len(expected_contacts), us_nd_supervision_compliance._face_to_face_contacts_on_date( evaluation_date), )