def process(self, element, supervision_period_to_agent_associations): """Identifies instances of referrals to a program.""" _, person_entities = element # Get the StateProgramAssignments as a list program_assignments = \ list(person_entities['program_assignments']) # Get the StateAssessments as a list assessments = list(person_entities['assessments']) # Get the StateSupervisionPeriods as a list supervision_periods = list(person_entities['supervision_periods']) # Get the StatePerson person = one(person_entities['person']) # Find the ProgramEvents from the StateProgramAssignments program_events = \ identifier.find_program_events( program_assignments, assessments, supervision_periods, supervision_period_to_agent_associations) if not program_events: logging.info( "No valid program events for person with id: %d. Excluding them from the " "calculations.", person.person_id) else: yield (person, program_events)
def test_find_program_events(self): program_assignment = StateProgramAssignment.new_with_defaults( state_code='US_CA', program_id='PG3', referral_date=date(2020, 1, 3), participation_status=StateProgramAssignmentParticipationStatus. IN_PROGRESS, program_location_id='LOCATION X', start_date=date(2020, 1, 1)) assessment = StateAssessment.new_with_defaults( state_code='US_CA', assessment_type=StateAssessmentType.ORAS, assessment_score=33, assessment_date=date(2019, 7, 10)) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=111, status=StateSupervisionPeriodStatus.TERMINATED, state_code='UT', start_date=date(2019, 3, 5), supervision_type=StateSupervisionType.PAROLE) program_assignments = [program_assignment] assessments = [assessment] supervision_periods = [supervision_period] program_events = identifier.find_program_events( program_assignments, assessments, supervision_periods, DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS) expected_events = [ ProgramReferralEvent( state_code=program_assignment.state_code, event_date=program_assignment.referral_date, program_id=program_assignment.program_id, supervision_type=supervision_period.supervision_type, participation_status=program_assignment.participation_status, assessment_score=assessment.assessment_score, assessment_type=assessment.assessment_type), ProgramParticipationEvent( state_code=program_assignment.state_code, event_date=program_assignment.start_date, program_id=program_assignment.program_id, program_location_id=program_assignment.program_location_id, supervision_type=supervision_period.supervision_type), ProgramParticipationEvent( state_code=program_assignment.state_code, event_date=program_assignment.start_date + relativedelta(days=1), program_id=program_assignment.program_id, program_location_id=program_assignment.program_location_id, supervision_type=supervision_period.supervision_type) ] self.assertListEqual(program_events, expected_events)
def process(self, element): """Identifies instances of referrals to a program.""" _, person_entities = element person, kwargs = person_and_kwargs_for_identifier(person_entities) # Find the ProgramEvents from the StateProgramAssignments program_events = identifier.find_program_events(**kwargs) if not program_events: logging.info( "No valid program events for person with id: %d. Excluding them from the " "calculations.", person.person_id, ) else: yield person.person_id, (person, program_events)
def process(self, element, supervision_period_to_agent_associations): """Identifies instances of referrals to a program.""" _, person_entities = element person, kwargs = person_and_kwargs_for_identifier(person_entities) # Add this arguments to the keyword args for the identifier kwargs[ 'supervision_period_to_agent_associations'] = supervision_period_to_agent_associations # Find the ProgramEvents from the StateProgramAssignments program_events = \ identifier.find_program_events(**kwargs) if not program_events: logging.info( "No valid program events for person with id: %d. Excluding them from the " "calculations.", person.person_id) else: yield (person, program_events)
def test_find_program_events_no_program_assignments(self): program_events = identifier.find_program_events( [], [], [], DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATIONS ) self.assertEqual([], program_events)
def test_find_program_events(self): program_assignment = StateProgramAssignment.new_with_defaults( state_code="US_XX", program_id="PG3", referral_date=date(2020, 1, 3), participation_status=StateProgramAssignmentParticipationStatus. IN_PROGRESS, program_location_id="LOCATION X", start_date=date(2020, 1, 1), ) assessment = StateAssessment.new_with_defaults( state_code="US_XX", assessment_type=StateAssessmentType.ORAS, assessment_score=33, assessment_date=date(2019, 7, 10), ) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=999, status=StateSupervisionPeriodStatus.TERMINATED, state_code="US_XX", start_date=date(2019, 3, 5), termination_date=date(2020, 10, 1), supervision_type=StateSupervisionType.PAROLE, supervision_site="OFFICE_1", ) program_assignments = [program_assignment] assessments = [assessment] supervision_periods = [supervision_period] program_events = identifier.find_program_events( program_assignments, assessments, supervision_periods, DEFAULT_SUPERVISION_PERIOD_AGENT_ASSOCIATION_LIST, ) expected_events = [ ProgramReferralEvent( state_code=program_assignment.state_code, event_date=program_assignment.referral_date, program_id=program_assignment.program_id, supervision_type=supervision_period.supervision_type, participation_status=program_assignment.participation_status, assessment_score=assessment.assessment_score, assessment_type=assessment.assessment_type, supervising_officer_external_id="XXX", supervising_district_external_id="OFFICE_1", level_1_supervision_location_external_id="OFFICE_1", level_2_supervision_location_external_id=None, ), ProgramParticipationEvent( state_code=program_assignment.state_code, event_date=program_assignment.start_date, is_first_day_in_program=True, program_id=program_assignment.program_id, program_location_id=program_assignment.program_location_id, supervision_type=supervision_period.supervision_type, ), ProgramParticipationEvent( state_code=program_assignment.state_code, event_date=program_assignment.start_date + relativedelta(days=1), is_first_day_in_program=False, program_id=program_assignment.program_id, program_location_id=program_assignment.program_location_id, supervision_type=supervision_period.supervision_type, ), ] self.assertListEqual(program_events, expected_events)