Пример #1
0
    def test_diversion_probation_after_community_court_ref_investigation(self):
        raw_statuses = [{
            'sentence_external_id': '1324786-20180214-1',
            'sentence_status_external_id': '1324786-20180214-1-1',
            'status_code': '05I5100',
            'status_date': '20180214',
            'status_description': 'New Community Corr Court Ref'
        }, {
            'sentence_external_id': '1324786-20180214-1',
            'sentence_status_external_id': '1324786-20180214-1-2',
            'status_code': '95O5100',
            'status_date': '20180323',
            'status_description': 'Comm Corr Court Ref Closed'
        }, {
            'sentence_external_id': '1324786-20180214-1',
            'sentence_status_external_id': '1324786-20180214-1-3',
            'status_code': '35I2000',
            'status_date': '20180323',
            'status_description': 'Diversion Supv-Revisit'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1324786-20180214-1',
            start_date=datetime.date(year=2018, month=3, day=23))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
Пример #2
0
    def test_prob_rev_codes_not_applicable(self):
        raw_statuses = [{
            'sentence_external_id': '1163420-20180116-1',
            'sentence_status_external_id': '1163420-20180116-1-1',
            'status_code': '15I1000',
            'status_date': '20180116',
            'status_description': 'New Court Probation'
        }, {
            'sentence_external_id': '1163420-20180116-1',
            'sentence_status_external_id': '1163420-20180116-1-3',
            'status_code': '95O2120',
            'status_date': '20180925',
            'status_description': 'Prob Rev-Codes Not Applicable'
        }, {
            'sentence_external_id': '1163420-20180116-1',
            'sentence_status_external_id': '1163420-20180116-1-4',
            'status_code': '35I1000',
            'status_date': '20180925',
            'status_description': 'Court Probation-Revisit'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1163420-20180116-1',
            start_date=datetime.date(year=2014, month=6, day=10))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
Пример #3
0
    def test_resentenced_probation_revisit(self):
        raw_statuses = [{
            'sentence_external_id': '1254438-20130418-2',
            'sentence_status_external_id': '1254438-20130418-2-2',
            'status_code': '25I1000',
            'status_date': '20140610',
            'status_description': 'Court Probation-Addl Charge'
        }, {
            'sentence_external_id': '1254438-20130418-2',
            'sentence_status_external_id': '1254438-20130418-2-8',
            'status_code': '95O1040',
            'status_date': '20170717',
            'status_description': 'Resentenced'
        }, {
            'sentence_external_id': '1254438-20130418-2',
            'sentence_status_external_id': '1254438-20130418-2-9',
            'status_code': '35I1000',
            'status_date': '20170717',
            'status_description': 'Court Probation-Revisit'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1254438-20130418-2',
            start_date=datetime.date(year=2014, month=6, day=10))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
Пример #4
0
    def test_interstate_compact_parole_classified_as_probation(self):
        raw_statuses = [
            {
                'sentence_external_id': '165467-20171227-1',
                'sentence_status_external_id': '165467-20171227-1-1',
                'status_code': '05I5200',
                'status_date': '20171227',
                'status_description': 'New Interstate Compact-Invest'
            },
            {
                'sentence_external_id': '165467-20171227-1',
                'sentence_status_external_id': '165467-20171227-1-2',
                'status_code': '95O5200',
                'status_date': '20180123',
                'status_description': 'Interstate Invest Closed'
            },
            {
                'sentence_external_id': '165467-20171227-1',
                'sentence_status_external_id': '165467-20171227-1-3',
                'status_code': '35I4100',
                'status_date': '20180129',
                'status_description': 'IS Compact-Parole-Revisit'
            },
        ]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='165467-20171227-1',
            start_date=datetime.date(year=2018, month=1, day=29))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
Пример #5
0
    def test_probation_after_investigation_status_list_unsorted(self):
        raw_statuses = [{
            'sentence_external_id': '282443-20180427-1',
            'sentence_status_external_id': '282443-20180427-1-3',
            'status_code': '35I1000',
            'status_date': '20180525',
            'status_description': 'Court Probation-Revisit'
        }, {
            'sentence_external_id': '282443-20180427-1',
            'sentence_status_external_id': '282443-20180427-1-2',
            'status_code': '95O5630',
            'status_date': '20180525',
            'status_description': 'SAR Cancelled by Court'
        }, {
            'sentence_external_id': '282443-20180427-1',
            'sentence_status_external_id': '282443-20180427-1-1',
            'status_code': '05I5600',
            'status_date': '20180427',
            'status_description': 'New Sentencing Assessment'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='282443-20180427-1',
            start_date=datetime.date(year=2018, month=5, day=25))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
Пример #6
0
    def test_create_mo_supervision_sentence(self):
        # Arrange
        raw_sentence_statuses = [{
            'sentence_external_id': '1345495-20190808-1',
            'sentence_status_external_id': '1345495-20190808-1-1',
            'status_code': '15I1000',
            'status_date': '20190808',
            'status_description': 'New Court Probation'
        }]

        sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1345495-20190808-1')

        # Act
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            sentence, raw_sentence_statuses)

        # Assert
        self.assertEqual(us_mo_sentence.base_sentence, sentence)
        self.assertEqual(us_mo_sentence.sentence_statuses, [
            UsMoSentenceStatus(
                sentence_status_external_id='1345495-20190808-1-1',
                sentence_external_id='1345495-20190808-1',
                status_code='15I1000',
                status_date=datetime.date(year=2019, month=8, day=8),
                status_description='New Court Probation')
        ])

        self.assertTrue(isinstance(us_mo_sentence, StateSupervisionSentence))
        self.assertEqual(us_mo_sentence.external_id, sentence.external_id)
    def process(self,
                element,
                us_mo_sentence_statuses_by_sentence,
                *args,
                **kwargs):
        """For the given sentence convert to a state-specific subclass, if necessary.

        Args:
            element: A tuple containing person_id and either a StateSupervisionSentence or a StateIncarcerationSentence

        Yields:
            A tuple containing person_id and the sentence, converted to a state-specific subclass, if necessary
        """
        person_id, sentence = element

        state_specific_sentence = sentence
        if sentence.state_code == 'US_MO':

            sentence_statuses = []
            if sentence.external_id in us_mo_sentence_statuses_by_sentence:
                sentence_statuses = us_mo_sentence_statuses_by_sentence[sentence.external_id]

            if isinstance(sentence, entities.StateSupervisionSentence):
                state_specific_sentence = UsMoSupervisionSentence.from_supervision_sentence(sentence, sentence_statuses)
            elif isinstance(sentence, entities.StateIncarcerationSentence):
                state_specific_sentence = UsMoIncarcerationSentence.from_incarceration_sentence(sentence,
                                                                                                sentence_statuses)
            else:
                raise ValueError(f'Unexpected sentence type: {sentence}')

        yield person_id, state_specific_sentence
Пример #8
0
    def process(self, element, *args, **kwargs):
        """For the sentences of the given person, convert to a state-specific subclass, if necessary.

        Args:
            element: A tuple containing person_id and a dictionary with all of the person's incarceration sentences,
                supervision sentences, and sentence statuses (if applicable)

        Yields:
            For each incarceration and supervision sentence, yields a tuple containing person_id and the sentence,
                converted to a state-specific subclass, if necessary
        """
        person_id, sentences_and_statuses = element

        incarceration_sentences = sentences_and_statuses.get('incarceration_sentences')
        supervision_sentences = sentences_and_statuses.get('supervision_sentences')
        all_sentence_statuses = sentences_and_statuses.get('sentence_statuses')

        us_mo_sentence_statuses_by_sentence: Dict[str, List[Dict[str, str]]] = defaultdict(list)

        if all_sentence_statuses:
            # Build a dictionary that maps each sentence_external_id to a list of dictionaries containing status
            # updates for this sentence
            for status_dict in all_sentence_statuses:
                sentence_external_id = status_dict.get('sentence_external_id')

                if sentence_external_id:
                    us_mo_sentence_statuses_by_sentence[sentence_external_id].append(status_dict)

        for incarceration_sentence in incarceration_sentences:
            state_specific_incarceration_sentence = incarceration_sentence
            if incarceration_sentence.state_code == 'US_MO':

                sentence_statuses = []
                if incarceration_sentence.external_id in us_mo_sentence_statuses_by_sentence:
                    sentence_statuses = us_mo_sentence_statuses_by_sentence[incarceration_sentence.external_id]

                state_specific_incarceration_sentence = UsMoIncarcerationSentence.from_incarceration_sentence(
                    incarceration_sentence, sentence_statuses)

            yield beam.pvalue.TaggedOutput('incarceration_sentences',
                                           (person_id, state_specific_incarceration_sentence))

        for supervision_sentence in supervision_sentences:
            state_specific_supervision_sentence = supervision_sentence
            if supervision_sentence.state_code == 'US_MO':

                sentence_statuses = []
                if supervision_sentence.external_id in us_mo_sentence_statuses_by_sentence:
                    sentence_statuses = us_mo_sentence_statuses_by_sentence[supervision_sentence.external_id]

                state_specific_supervision_sentence = UsMoSupervisionSentence.from_supervision_sentence(
                    supervision_sentence, sentence_statuses)

            yield beam.pvalue.TaggedOutput('supervision_sentences',
                                           (person_id, state_specific_supervision_sentence))
Пример #9
0
    def test_supervision_type_new_probation(self):
        raw_statuses = [{
            'sentence_external_id': '1345495-20190808-1',
            'sentence_status_external_id': '1345495-20190808-1-1',
            'status_code': '15I1000',
            'status_date': '20190808',
            'status_description': 'New Court Probation'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1345495-20190808-1',
            start_date=datetime.date(year=2019, month=8, day=8))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
Пример #10
0
    def test_probation_starts_same_day_as_new_investigation(self):
        raw_statuses = [{
            'sentence_external_id': '1344336-20190703-1',
            'sentence_status_external_id': '1344336-20190703-1-1',
            'status_code': '05I5210',
            'status_date': '20190703',
            'status_description': 'IS Comp-Reporting Instr Given'
        }, {
            'sentence_external_id': '1344336-20190703-1',
            'sentence_status_external_id': '1344336-20190703-1-2',
            'status_code': '95O5210',
            'status_date': '20190716',
            'status_description': 'IS Comp-Report Instruct Closed'
        }, {
            'sentence_external_id': '1344336-20190703-1',
            'sentence_status_external_id': '1344336-20190703-1-3',
            'status_code': '35I5200',
            'status_date': '20190716',
            'status_description': 'IS Compact-Invest-Revisit'
        }, {
            'sentence_external_id': '1344336-20190703-1',
            'sentence_status_external_id': '1344336-20190703-1-4',
            'status_code': '95O5200',
            'status_date': '20190716',
            'status_description': 'Interstate Invest Closed'
        }, {
            'sentence_external_id': '1344336-20190703-1',
            'sentence_status_external_id': '1344336-20190703-1-5',
            'status_code': '35I4000',
            'status_date': '20190716',
            'status_description': 'IS Compact-Prob-Revisit'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1344336-20190703-1',
            start_date=datetime.date(year=2019, month=7, day=16))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)
    def test_ConvertSentenceToStateSpecificType_supervision_sentence_mo(self):
        """Tests that for MO, supervision sentences get converted to UsMoSupervisionSentence."""
        person_id = 456
        supervision_sentence_id = 123

        supervision_sentence = StateSupervisionSentence.new_with_defaults(
            supervision_sentence_id=supervision_sentence_id,
            state_code='US_MO',
            external_id='123-external-id',
            start_date=date(2000, 1, 1),
        )

        expected_sentence = UsMoSupervisionSentence.new_with_defaults(
            supervision_sentence_id=supervision_sentence_id,
            state_code='US_MO',
            external_id='123-external-id',
            start_date=date(2000, 1, 1),
            base_sentence=supervision_sentence,
            sentence_statuses=[self.TEST_CONVERTED_MO_STATUS])

        self.run_test_pipeline(person_id, supervision_sentence,
                               self.TEST_MO_SENTENCE_STATUS_ROWS,
                               expected_sentence)
Пример #12
0
    def test_diversion_probation_after_investigation(self):
        raw_statuses = [{
            'sentence_external_id': '1324786-20180214-1',
            'sentence_status_external_id': '1324786-20180214-1-1',
            'status_code': '05I5500',
            'status_date': '20180214',
            'status_description': 'New Diversion Investigation'
        }, {
            'sentence_external_id': '1324786-20180214-1',
            'sentence_status_external_id': '1324786-20180214-1-2',
            'status_code': '95O5500',
            'status_date': '20180323',
            'status_description': 'Diversion Invest Completed'
        }, {
            'sentence_external_id': '1324786-20180214-1',
            'sentence_status_external_id': '1324786-20180214-1-3',
            'status_code': '35I2000',
            'status_date': '20180323',
            'status_description': 'Diversion Supv-Revisit'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1324786-20180214-1',
            start_date=datetime.date(year=2018, month=3, day=23))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)

        # Also test that we count the person as on probation if we are looking at the exact day they started this
        # supervision.
        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                datetime.date(year=2018, month=3, day=23)),
            StateSupervisionType.PROBATION)
Пример #13
0
    def test_release_to_field_other_sentence(self):
        raw_statuses = [{
            'sentence_external_id': '1328840-20180523-3',
            'sentence_status_external_id': '1328840-20180523-3-2',
            'status_code': '25I1000',
            'status_date': '20180523',
            'status_description': 'Court Probation-Addl Charge'
        }, {
            'sentence_external_id': '1328840-20180523-3',
            'sentence_status_external_id': '1328840-20180523-3-3',
            'status_code': '40I7000',
            'status_date': '20181011',
            'status_description': 'Field Supv to DAI-Oth Sentence'
        }, {
            'sentence_external_id': '1328840-20180523-3',
            'sentence_status_external_id': '1328840-20180523-3-4',
            'status_code': '45O7000',
            'status_date': '20181011',
            'status_description': 'Field to DAI-Other Sentence'
        }, {
            'sentence_external_id': '1328840-20180523-3',
            'sentence_status_external_id': '1328840-20180523-3-5',
            'status_code': '40O7000',
            'status_date': '20181017',
            'status_description': 'Rel to Field-DAI Other Sent'
        }]

        base_sentence = StateSupervisionSentence.new_with_defaults(
            external_id='1328840-20180523-3',
            start_date=datetime.date(year=2014, month=6, day=10))
        us_mo_sentence = UsMoSupervisionSentence.from_supervision_sentence(
            base_sentence, raw_statuses)

        self.assertEqual(
            us_mo_sentence.get_sentence_supervision_type_on_day(
                self.validation_date), StateSupervisionType.PROBATION)