def perform_match_postprocessing( self, matched_persons: List[schema.StatePerson]): """Performs the following ND specific postprocessing on the provided |matched_persons| directly after they have been entity matched: - Move IncarcerationIncidents onto IncarcerationPeriods based on date. - Transform IncarcerationPeriods periods of temporary custody (holds), when appropriate. - Associates SupervisionViolationResponses with IncarcerationPeriods based on date. - Moves supervising_officer from StatePerson onto open SupervisionPeriods. """ logging.info("[Entity matching] Move incidents into periods") move_incidents_onto_periods(matched_persons) logging.info("[Entity matching] Transform incarceration periods into " "holds") update_temporary_holds(matched_persons, self.region) logging.info("[Entity matching] Associate revocation SVRs with IPs") associate_revocation_svrs_with_ips(matched_persons) logging.info('[Entity matching] Moving supervising officer onto open ' 'supervision periods') add_supervising_officer_to_open_supervision_periods(matched_persons)
def perform_match_postprocessing(self, matched_persons: List[schema.StatePerson]): """Performs the following PA specific postprocessing on the provided |matched_persons| directly after they have been entity matched: - Move IncarcerationIncidents onto IncarcerationPeriods based on date. """ logging.info("[Entity matching] Move incidents into periods") move_incidents_onto_periods(matched_persons)
def perform_match_postprocessing(self, matched_persons: List[schema.StatePerson]): """Performs the following PA specific postprocessing on the provided |matched_persons| directly after they have been entity matched: - Move IncarcerationIncidents onto IncarcerationPeriods based on date. """ logging.info("[Entity matching] Move incidents into periods") move_incidents_onto_periods(matched_persons) logging.info('[Entity matching] Move supervision violations onto supervision periods by date.') move_violations_onto_supervision_periods_for_person(matched_persons, self.get_region_code())
def test_moveIncidentsOntoPeriods(self) -> None: merged_incarceration_period_1 = StateIncarcerationPeriod.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID + "|" + _EXTERNAL_ID_2, status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY, facility=_FACILITY, admission_date=_DATE_1, admission_reason=StateIncarcerationPeriodAdmissionReason.NEW_ADMISSION, release_date=_DATE_3, release_reason=StateIncarcerationPeriodReleaseReason.TRANSFER, ) merged_incarceration_period_2 = StateIncarcerationPeriod.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID_3 + "|" + _EXTERNAL_ID_4, status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY, facility=_FACILITY_2, admission_date=_DATE_3, admission_reason=StateIncarcerationPeriodAdmissionReason.TRANSFER, release_date=_DATE_5, release_reason=StateIncarcerationPeriodReleaseReason.TRANSFER, ) unmerged_incarceration_period = StateIncarcerationPeriod.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID_5, status=StateIncarcerationPeriodStatus.IN_CUSTODY, facility=_FACILITY_3, admission_date=_DATE_5, admission_reason=StateIncarcerationPeriodAdmissionReason.TRANSFER, ) incident_1 = StateIncarcerationIncident.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID, facility=_FACILITY, incident_date=_DATE_2, ) incident_2 = StateIncarcerationIncident.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID_2, facility=_FACILITY_2, incident_date=_DATE_4, ) incident_3 = StateIncarcerationIncident.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID_3, facility=_FACILITY_4, incident_date=_DATE_7, ) placeholder_incarceration_period = StateIncarcerationPeriod.new_with_defaults( state_code=_STATE_CODE, incarceration_incidents=[incident_1, incident_2, incident_3], status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) incarceration_sentence = StateIncarcerationSentence.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_periods=[ merged_incarceration_period_1, merged_incarceration_period_2, unmerged_incarceration_period, ], ) placeholder_incarceration_sentence = ( StateIncarcerationSentence.new_with_defaults( state_code=_STATE_CODE, external_id=_EXTERNAL_ID_2, incarceration_periods=[placeholder_incarceration_period], status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) ) sentence_group = StateSentenceGroup.new_with_defaults( state_code=_STATE_CODE, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[ incarceration_sentence, placeholder_incarceration_sentence, ], ) person = StatePerson.new_with_defaults( state_code=_STATE_CODE, sentence_groups=[sentence_group] ) expected_merged_period = attr.evolve( merged_incarceration_period_1, incarceration_incidents=[incident_1] ) expected_merged_period_2 = attr.evolve( merged_incarceration_period_2, incarceration_incidents=[incident_2] ) expected_unmerged_period = attr.evolve(unmerged_incarceration_period) expected_placeholder_period = attr.evolve( placeholder_incarceration_period, incarceration_incidents=[incident_3] ) expected_sentence = attr.evolve( incarceration_sentence, incarceration_periods=[ expected_merged_period, expected_merged_period_2, expected_unmerged_period, ], ) expected_placeholder_sentence = attr.evolve( placeholder_incarceration_sentence, incarceration_periods=[expected_placeholder_period], ) expected_sentence_group = attr.evolve( sentence_group, incarceration_sentences=[expected_sentence, expected_placeholder_sentence], ) expected_person = convert_entity_to_schema_object( attr.evolve(person, sentence_groups=[expected_sentence_group]) ) schema_person = convert_entity_to_schema_object(person) if not isinstance(schema_person, schema.StatePerson): self.fail(f"Expected schema.StatePerson. Found {schema_person}") move_incidents_onto_periods([schema_person]) self.assert_schema_objects_equal(expected_person, schema_person)
def test_moveIncidentsOntoPeriods(self): merged_incarceration_period_1 = \ StateIncarcerationPeriod.new_with_defaults( external_id=_EXTERNAL_ID + '|' + _EXTERNAL_ID_2, status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY, facility=_FACILITY, admission_date=_DATE_1, admission_reason=StateIncarcerationPeriodAdmissionReason.NEW_ADMISSION, release_date=_DATE_3, release_reason=StateIncarcerationPeriodReleaseReason.TRANSFER) merged_incarceration_period_2 = \ StateIncarcerationPeriod.new_with_defaults( external_id=_EXTERNAL_ID_3 + '|' + _EXTERNAL_ID_4, status=StateIncarcerationPeriodStatus.NOT_IN_CUSTODY, facility=_FACILITY_2, admission_date=_DATE_3, admission_reason=StateIncarcerationPeriodAdmissionReason.TRANSFER, release_date=_DATE_5, release_reason=StateIncarcerationPeriodReleaseReason.TRANSFER) unmerged_incarceration_period = \ StateIncarcerationPeriod.new_with_defaults( external_id=_EXTERNAL_ID_5, status=StateIncarcerationPeriodStatus.IN_CUSTODY, facility=_FACILITY_3, admission_date=_DATE_5, admission_reason=StateIncarcerationPeriodAdmissionReason.TRANSFER) incident_1 = StateIncarcerationIncident.new_with_defaults( external_id=_EXTERNAL_ID, facility=_FACILITY, incident_date=_DATE_2) incident_2 = StateIncarcerationIncident.new_with_defaults( external_id=_EXTERNAL_ID_2, facility=_FACILITY_2, incident_date=_DATE_4) incident_3 = StateIncarcerationIncident.new_with_defaults( external_id=_EXTERNAL_ID_3, facility=_FACILITY_4, incident_date=_DATE_7) placeholder_incarceration_period = \ StateIncarcerationPeriod.new_with_defaults( incarceration_incidents=[incident_1, incident_2, incident_3]) incarceration_sentence = StateIncarcerationSentence.new_with_defaults( external_id=_EXTERNAL_ID, incarceration_periods=[ merged_incarceration_period_1, merged_incarceration_period_2, unmerged_incarceration_period ]) placeholder_incarceration_sentence = \ StateIncarcerationSentence.new_with_defaults( external_id=_EXTERNAL_ID_2, incarceration_periods=[placeholder_incarceration_period]) sentence_group = StateSentenceGroup.new_with_defaults( incarceration_sentences=[ incarceration_sentence, placeholder_incarceration_sentence ]) person = StatePerson.new_with_defaults( sentence_groups=[sentence_group]) expected_merged_period = attr.evolve( merged_incarceration_period_1, incarceration_incidents=[incident_1]) expected_merged_period_2 = attr.evolve( merged_incarceration_period_2, incarceration_incidents=[incident_2]) expected_unmerged_period = attr.evolve(unmerged_incarceration_period) expected_placeholder_period = attr.evolve( placeholder_incarceration_period, incarceration_incidents=[incident_3]) expected_sentence = attr.evolve(incarceration_sentence, incarceration_periods=[ expected_merged_period, expected_merged_period_2, expected_unmerged_period ]) expected_placeholder_sentence = attr.evolve( placeholder_incarceration_sentence, incarceration_periods=[expected_placeholder_period]) expected_sentence_group = attr.evolve(sentence_group, incarceration_sentences=[ expected_sentence, expected_placeholder_sentence ]) expected_person = attr.evolve( person, sentence_groups=[expected_sentence_group]) move_incidents_onto_periods([person]) self.assertEqual(expected_person, person)