def test_rule_expunge_over_70(example_crecord): example_crecord.person.date_of_birth = date(1920, 1, 1) example_crecord.cases[0].arrest_date = date(1970, 1, 1) example_crecord.cases[0].charges[0].sentences = [ Sentence(sentence_date=date.today(), sentence_type="Confinement", sentence_period="90 days", sentence_length=SentenceLength.from_tuples(("90", "day"), ("90", "day"))) ] remaining_recordord, analysis = ruledefs.expunge_over_70(example_crecord) assert analysis.value == [] assert [bool(d) for d in analysis.reasoning] == [True, True, False] assert len(remaining_recordord.cases) == len(example_crecord.cases) example_crecord.cases[0].charges[0].sentences[0] = Sentence( sentence_date=date(1980, 1, 1), sentence_type="Confinement", sentence_period="90 days", sentence_length=SentenceLength.from_tuples(("90", "day"), ("90", "day"))) remaining_recordord, analysis = ruledefs.expunge_over_70(example_crecord) assert isinstance(analysis.value[0], Expungement) # The modified record has removed the cases this rule wants to expunge. assert len(remaining_recordord.cases) < len(example_crecord.cases)
def test_rule_expunge_over_70(example_crecord): example_crecord.person.date_of_birth = date(1920, 1, 1) example_crecord.cases[0].arrest_date = date(1970, 1, 1) example_crecord.cases[0].charges[0].sentences = [Sentence( sentence_date = date.today(), sentence_type = "Confinement", sentence_period = "90 days", sentence_length = SentenceLength(("90","day"), ("90","day")) )] modified_record, analysis = ruledefs.expunge_over_70(example_crecord, dict()) assert analysis["age_over_70_expungements"]["conclusion"] == "No expungements possible" assert analysis["age_over_70_expungements"]["conditions"]["years_since_final_release"] == False assert len(modified_record.cases) == len(example_crecord.cases) example_crecord.cases[0].charges[0].sentences[0] = Sentence( sentence_date = date(1980, 1, 1), sentence_type = "Confinement", sentence_period = "90 days", sentence_length = SentenceLength(("90","day"), ("90","day")) ) modified_record, analysis = ruledefs.expunge_over_70(example_crecord, dict()) assert analysis["age_over_70_expungements"]["conclusion"] == "Expunge cases" analysis["age_over_70_expungements"]["conditions"]["years_since_final_release"] == True # The modified record has removed the cases this rule wants to expunge. assert len(modified_record.cases) < len(example_crecord.cases)
def get_sentences(stree: etree) -> List[Sentence]: """Find the sentences in a sequence (as an xml tree) from a disposition section of a docket. """ sequence_date = xpath_date_or_blank(stree, "//action_date") sentences = stree.xpath("//sentence_info") sentences = [ Sentence(sentence_date=sequence_date, sentence_type=xpath_or_blank(s, "//program"), sentence_period="...", sentence_length=SentenceLength( min_time=( s.xpath("//sentence_length/min_length/time")[0].text, s.xpath("//sentence_length/min_length/unit")[0].text), max_time=( s.xpath("//sentence_length/min_length/time")[0].text, s.xpath("//sentence_length/min_length/unit")[0].text), )) for s in sentences ] return sentences
def example_sentencelength(): return SentenceLength.from_tuples( min_time=("10", "Year"), max_time=("25", "Year") )
def get_cp_cases(summary_xml: etree.Element) -> List: """ Return a list of the cases described in this Summary sheet. """ cases = [] case_elements = summary_xml.xpath("//case") for case in case_elements: closed_sequences = case.xpath(".//closed_sequence") closed_charges = [] for seq in closed_sequences: charge = Charge( offense=text_or_blank(seq.find("description")), statute=text_or_blank(seq.find("statute")), grade=text_or_blank(seq.find("grade")), disposition=text_or_blank(seq.find("sequence_disposition")), disposition_date=None, sentences=[], ) for sentence in seq.xpath(".//sentencing_info"): charge.sentences.append( Sentence( sentence_date=date_or_none(sentence.find("sentence_date")), sentence_type=text_or_blank(sentence.find("sentence_type")), sentence_period=text_or_blank( sentence.find("program_period") ), sentence_length=SentenceLength.from_tuples( min_time=( text_or_blank( sentence.find("sentence_length/min_length/time") ), text_or_blank( sentence.find("sentence_length/min_length/unit") ), ), max_time=( text_or_blank( sentence.find("sentence_length/max_length/time") ), text_or_blank( sentence.find("sentence_length/max_length/unit") ), ), ), ) ) closed_charges.append(charge) open_sequences = case.xpath(".//open_sequence") open_charges = [] for seq in open_sequences: charge = Charge( offense=text_or_blank(seq.find("description")), statute=text_or_blank(seq.find("statute")), grade=text_or_blank(seq.find("grade")), disposition=text_or_blank(seq.find("sequence_disposition")), disposition_date=None, sentences=[], ) for sentence in seq.xpath(".//sentencing_info"): charge.sentences.append( Sentence( sentence_date=date_or_none(sentence.find("sentence_date")), sentence_type=text_or_blank(sentence.find("sentence_type")), sentence_period=text_or_blank( sentence.find("program_period") ), sentence_length=SentenceLength.from_tuples( min_time=( text_or_blank( sentence.find("sentence_length/min_length/time") ), text_or_blank( sentence.find("sentence_length/min_length/unit") ), ), max_time=( text_or_blank( sentence.find("sentence_length/max_length/time") ), text_or_blank( sentence.find("sentence_length/max_length/unit") ), ), ), ) ) open_charges.append(charge) new_case = Case( status=text_or_blank(case.getparent().getparent()), county=text_or_blank(case.getparent().find("county")), docket_number=text_or_blank(case.find("case_basics/docket_num")), otn=text_or_blank(case.find("case_basics/otn_num")), dc=text_or_blank(case.find("case_basics/dc_num")), charges=closed_charges + open_charges, total_fines=None, # a summary docket never has info about this. fines_paid=None, arrest_date=date_or_none( either(case.find("arrest_disp_actions/arrest_disp/arrest_date"), case.find("arrest_disp_actions/arrest_trial/arrest_date")) ), disposition_date=date_or_none( case.find("arrest_disp_actions/arrest_disp/disp_date") ), judge=text_or_blank(case.find("arrest_disp_actions/arrest_disp/disp_judge")), ) # In Summaries, the Disposition Date is set on a Case, but it is set on a Charge in Dockets. # So when processing a Summary sheet, if there is a date on the Case, the Charges should # inherit the date on the case. for charge in new_case.charges: if new_case.disposition_date is not None: charge.disposition_date = new_case.disposition_date cases.append(new_case) return cases
def get_cp_cases(summary_xml: etree.Element) -> List: """ Return a list of the cases described in this Summary sheet. """ cases = [] case_elements = summary_xml.xpath("//case") for case in case_elements: closed_sequences = case.xpath(".//closed_sequence") closed_charges = [] for seq in closed_sequences: charge = Charge( offense=text_or_blank(seq.find("description")), statute=text_or_blank(seq.find("statute")), grade=text_or_blank(seq.find("grade")), disposition=text_or_blank(seq.find("sequence_disposition")), sentences=[], ) for sentence in seq.xpath(".//sentencing_info"): charge.sentences.append( Sentence( sentence_date=date_or_none( sentence.find("sentence_date")), sentence_type=text_or_blank( sentence.find("sentence_type")), sentence_period=text_or_blank( sentence.find("program_period")), sentence_length=SentenceLength( min_time=( text_or_blank( sentence.find( "sentence_length/min_length/time")), text_or_blank( sentence.find( "sentence_length/min_length/unit")), ), max_time=( text_or_blank( sentence.find( "sentence_length/max_length/time")), text_or_blank( sentence.find( "sentence_length/max_length/unit")), ), ), )) closed_charges.append(charge) open_sequences = case.xpath(".//open_sequence") open_charges = [] for seq in open_sequences: charge = Charge( offense=text_or_blank(seq.find("description")), statute=text_or_blank(seq.find("statute")), grade=text_or_blank(seq.find("grade")), disposition=text_or_blank(seq.find("sequence_disposition")), sentences=[], ) for sentence in seq.xpath(".//sentencing_info"): charge.sentences.append( Sentence( sentence_date=date_or_none( sentence.find("sentence_date")), sentence_type=text_or_blank( sentence.find("sentence_type")), sentence_period=text_or_blank( sentence.find("program_period")), sentence_length=SentenceLength( min_time=( text_or_blank( sentence.find( "sentence_length/min_length/time")), text_or_blank( sentence.find( "sentence_length/min_length/unit")), ), max_time=( text_or_blank( sentence.find( "sentence_length/max_length/time")), text_or_blank( sentence.find( "sentence_length/max_length/unit")), ), ), )) open_charges.append(charge) cases.append( Case( status=text_or_blank(case.getparent().getparent()), county=text_or_blank(case.getparent().find("county")), docket_number=text_or_blank( case.find("case_basics/docket_num")), otn=text_or_blank(case.find("case_basics/otn_num")), dc=text_or_blank(case.find("case_basics/dc_num")), charges=closed_charges + open_charges, fines_and_costs= None, # a summary docket never has info about this. arrest_date=date_or_none( case.find("arrest_and_disp/arrest_date")), disposition_date=date_or_none( case.find("arrest_and_disp/disp_date")), judge=text_or_blank(case.find("arrest_and_disp/disp_judge")), )) return cases