def _convert_incarceration_incident( self, ingest_incident: StateIncarcerationIncident ) -> entities.StateIncarcerationIncident: """Converts an ingest_info proto StateIncarcerationIncident to a persistence entity.""" incident_builder = entities.StateIncarcerationIncident.builder() state_incarceration_incident.copy_fields_to_builder( incident_builder, ingest_incident, self.metadata) incident_builder.responding_officer = fn( lambda i: state_agent.convert(self.agents[i], self.metadata), "responding_officer_id", ingest_incident, ) converted_outcomes = [ state_incarceration_incident_outcome.convert( self.incarceration_incident_outcomes[outcome_id], self.metadata) for outcome_id in ingest_incident.state_incarceration_incident_outcome_ids ] incident_builder.incarceration_incident_outcomes = converted_outcomes return incident_builder.build()
def _convert_supervision_violation_response( self, ingest_supervision_violation_response: StateSupervisionViolationResponse ) -> entities.StateSupervisionViolationResponse: """Converts an ingest_info proto StateSupervisionViolationResponse to a persistence entity.""" supervision_violation_response_builder = \ entities.StateSupervisionViolationResponse.builder() state_supervision_violation_response.copy_fields_to_builder( supervision_violation_response_builder, ingest_supervision_violation_response, self.metadata) converted_agents = [ state_agent.convert(self.agents[agent_id], self.metadata) for agent_id in ingest_supervision_violation_response.decision_agent_ids ] supervision_violation_response_builder.decision_agents = \ converted_agents converted_decisions = [ state_supervision_violation_response_decision_entry.convert( self.violation_response_decision_entries[condition_entry_id], self.metadata) for condition_entry_id in ingest_supervision_violation_response. state_supervision_violation_response_decision_entry_ids ] supervision_violation_response_builder.\ supervision_violation_response_decisions = converted_decisions return supervision_violation_response_builder.build()
def _convert_supervision_period( self, ingest_supervision_period: StateSupervisionPeriod) \ -> entities.StateSupervisionPeriod: """Converts an ingest_info proto StateSupervisionPeriod to a persistence entity.""" supervision_period_builder = \ entities.StateSupervisionPeriod.builder() state_supervision_period.copy_fields_to_builder( supervision_period_builder, ingest_supervision_period, self.metadata) supervision_period_builder.supervising_officer = \ fn(lambda i: state_agent.convert(self.agents[i], self.metadata), 'supervising_officer_id', ingest_supervision_period) converted_violations = [ self._convert_supervision_violation( self.supervision_violations[violation_id]) for violation_id in ingest_supervision_period.state_supervision_violation_entry_ids ] supervision_period_builder.supervision_violation_entries = \ converted_violations converted_assessments = [ self._convert_assessment(self.assessments[assessment_id]) for assessment_id in ingest_supervision_period.state_assessment_ids ] supervision_period_builder.assessments = converted_assessments converted_program_assignments = [ self._convert_program_assignment( self.program_assignments[assignment_id]) for assignment_id in ingest_supervision_period.state_program_assignment_ids ] supervision_period_builder.program_assignments = \ converted_program_assignments converted_case_types = [ state_supervision_case_type_entry.convert( self.supervision_case_type_entries[case_type_id], self.metadata) for case_type_id in ingest_supervision_period.state_supervision_case_type_entry_ids ] supervision_period_builder.case_type_entries = converted_case_types converted_contacts = [ self._convert_supervision_contact( self.supervision_contacts[contact_id]) for contact_id in ingest_supervision_period.state_supervision_contact_ids ] supervision_period_builder.supervision_contacts = converted_contacts return supervision_period_builder.build()
def _convert_court_case(self, ingest_court_case: StateCourtCase): court_case_builder = entities.StateCourtCase.builder() state_court_case.copy_fields_to_builder(court_case_builder, ingest_court_case, self.metadata) court_case_builder.judge = \ fn(lambda i: state_agent.convert(self.agents[i], self.metadata), 'judge_id', ingest_court_case) return court_case_builder.build()
def _convert_supervision_contact( self, ingest_contact: StateSupervisionContact ) -> entities.StateSupervisionContact: """Converts an ingest_info proto StateSupervisionContact to a persistence entity.""" contact_builder = entities.StateSupervisionContact.builder() state_supervision_contact.copy_fields_to_builder( contact_builder, ingest_contact, self.metadata) contact_builder.contacted_agent = fn( lambda i: state_agent.convert(self.agents[i], self.metadata), 'contacted_agent_id', ingest_contact) return contact_builder.build()
def _convert_program_assignment(self, ingest_assignment: StateProgramAssignment): """Converts an ingest_info proto StateProgramAssignment to a persistence entity""" program_assignment_builder = entities.StateProgramAssignment.builder() state_program_assignment.copy_fields_to_builder( program_assignment_builder, ingest_assignment, self.metadata) program_assignment_builder.referring_agent = \ fn(lambda i: state_agent.convert(self.agents[i], self.metadata), 'referring_agent_id', ingest_assignment) return program_assignment_builder.build()
def _convert_assessment(self, ingest_assessment: StateAssessment) \ -> entities.StateAssessment: """Converts an ingest_info proto StateAssessment to a persistence entity.""" assessment_builder = entities.StateAssessment.builder() state_assessment.copy_fields_to_builder(assessment_builder, ingest_assessment, self.metadata) assessment_builder.conducting_agent = \ fn(lambda i: state_agent.convert(self.agents[i], self.metadata), 'conducting_agent_id', ingest_assessment) return assessment_builder.build()
def testParseStateAgentNoType(self): # Arrange ingest_agent = ingest_info_pb2.StateAgent(state_agent_id="AGENT_ID", state_code="us_nd") # Act result = state_agent.convert(ingest_agent, _EMPTY_METADATA) # Assert expected_result = entities.StateAgent.new_with_defaults( agent_type=StateAgentType.PRESENT_WITHOUT_INFO, external_id="AGENT_ID", state_code="US_ND", ) self.assertEqual(result, expected_result)
def _convert_parole_decision( self, ingest_parole_decision: StateParoleDecision) \ -> entities.StateParoleDecision: """Converts an ingest_info proto StateParoleDecision to a persistence entity.""" parole_decision_builder = entities.StateParoleDecision.builder() state_parole_decision.copy_fields_to_builder(parole_decision_builder, ingest_parole_decision, self.metadata) converted_agents = [ state_agent.convert(self.agents[agent_id], self.metadata) for agent_id in ingest_parole_decision.decision_agent_ids ] parole_decision_builder.decision_agents = converted_agents return parole_decision_builder.build()
def testParseStateAgent(self): # Arrange ingest_agent = ingest_info_pb2.StateAgent( agent_type="JUDGE", state_agent_id="AGENT_ID", state_code="us_nd", full_name="Judge Joe Brown", ) # Act result = state_agent.convert(ingest_agent, _EMPTY_METADATA) # Assert expected_result = entities.StateAgent( agent_type=StateAgentType.JUDGE, agent_type_raw_text="JUDGE", external_id="AGENT_ID", state_code="US_ND", full_name='{"full_name": "JUDGE JOE BROWN"}', ) self.assertEqual(result, expected_result)
def testParseStateBond(self): # Arrange ingest_bond = ingest_info_pb2.StateAgent( agent_type='JUDGE', state_agent_id='AGENT_ID', state_code='us_nd', full_name='Judge Joe Brown', ) # Act result = state_agent.convert(ingest_bond, _EMPTY_METADATA) # Assert expected_result = entities.StateAgent( agent_type=StateAgentType.JUDGE, agent_type_raw_text='JUDGE', external_id='AGENT_ID', state_code='US_ND', full_name='{"full_name": "JUDGE JOE BROWN"}', ) self.assertEqual(result, expected_result)
def _convert_state_person(self, ingest_state_person: StatePerson) \ -> entities.StatePerson: """Converts an ingest_info proto StatePerson to a persistence entity.""" state_person_builder = entities.StatePerson.builder() state_person.copy_fields_to_builder(state_person_builder, ingest_state_person, self.metadata) converted_aliases = [ state_alias.convert(self.aliases[alias_id], self.metadata) for alias_id in ingest_state_person.state_alias_ids ] state_person_builder.aliases = converted_aliases converted_races = [ state_person_race.convert(self.person_races[race_id], self.metadata) for race_id in ingest_state_person.state_person_race_ids ] state_person_builder.races = converted_races converted_ethnicities = [ state_person_ethnicity.convert( self.person_ethnicities[ethnicity_id], self.metadata) for ethnicity_id in ingest_state_person.state_person_ethnicity_ids ] state_person_builder.ethnicities = converted_ethnicities converted_assessments = [ self._convert_assessment(self.assessments[assessment_id]) for assessment_id in ingest_state_person.state_assessment_ids ] state_person_builder.assessments = converted_assessments converted_program_assignments = [ self._convert_program_assignment( self.program_assignments[assignment_id]) for assignment_id in ingest_state_person.state_program_assignment_ids ] state_person_builder.program_assignments = converted_program_assignments converted_external_ids = [ state_person_external_id.convert( self.person_external_ids[external_id], self.metadata) for external_id in ingest_state_person.state_person_external_ids_ids ] state_person_builder.external_ids = converted_external_ids converted_sentence_groups = [ self._convert_sentence_group( self.sentence_groups[sentence_group_id]) for sentence_group_id in ingest_state_person.state_sentence_group_ids ] state_person_builder.sentence_groups = converted_sentence_groups if ingest_state_person.supervising_officer_id: converted_supervising_officer = state_agent.convert( self.agents[ingest_state_person.supervising_officer_id], self.metadata) state_person_builder.supervising_officer = \ converted_supervising_officer return state_person_builder.build()