def years_since_last_contact(crec: CRecord, year_min: int) -> Decision: return Decision( name= f"Has {crec.person.first_name} been free of arrest or prosecution for {year_min} years?", value=crec.years_since_last_arrested_or_prosecuted() >= 10, reasoning= f"It has been {crec.years_since_last_arrested_or_prosecuted()} years.")
def expunge_over_70(crecord: CRecord, analysis: dict) -> Tuple[CRecord, dict]: """ Analyze a crecord for expungements if the defendant is over 70. 18 Pa.C.S. 9122(b)(1) provides for expungements of an individual who is 70 or older, and has been free of arrest or prosecution for 10 years following the final release from confinement or supervision. """ conditions = { "age_over_70": crecord.person.age() > 70, "years_since_last_arrested_or_prosecuted": crecord.years_since_last_arrested_or_prosecuted() > 10, "years_since_final_release": crecord.years_since_final_release() > 10, } if all(conditions.values()): conclusion = "Expunge cases" modified_record = CRecord(person=copy.deepcopy(crecord.person), cases=[]) else: conclusion = "No expungements possible" modified_record = crecord analysis.update({ "age_over_70_expungements": { "conditions": conditions, "conclusion": conclusion, } }) return modified_record, analysis
def arrest_free_for_n_years(crec: CRecord, year_min=5) -> Decision: return Decision( name= f"Has {crec.person.first_name} been arrest free and prosecution free for five years?", value=crec.years_since_last_arrested_or_prosecuted() > year_min, reasoning= f"It has been {crec.years_since_last_arrested_or_prosecuted()} since the last arrest or prosecection.", )
def expunge_summary_convictions(crecord: CRecord, analysis: dict) -> Tuple[CRecord, dict]: """ Analyze crecord for expungements of summary convictions. 18 Pa.C.S. 9122(b)(3)(i) and (ii) provide for expungement of summary convictions if the individual has been free of arrest or prosecution for five years following the conviction for the offense. Not available if person got ARD for certain offenses listed in (b.1) TODO excluding ARD offenses from expungements here. TODO grades are often missing. We should tell users we're uncertain. """ conditions = { "arrest_free_five_years": crecord.years_since_last_arrested_or_prosecuted() > 5 } expungements = [] num_charges = 0 num_expungeable_charges = 0 modified_record = CRecord(person=crecord.person) for case in crecord.cases: any_expungements = False expungements_this_case = {"docket_number": case.docket_number} for charge in case.charges: num_charges += 1 if charge.grade.strip() == "S": num_expungeable_charges += 1 expungements_this_case.update({"charge": charge}) any_expungements = True expungements.append(expungements_this_case) if any_expungements is False: modified_record.cases.append(copy.deepcopy(case)) if (not all(conditions.values())) or num_expungeable_charges == 0: conclusion = "No expungements possible" elif all(conditions.values()) and num_charges == num_expungeable_charges: conclusion = "Expunge all cases" else: conclusion = ( f"Expunge {num_expungeable_charges} charges in {len(crecord.cases)} cases" ) analysis.update({ "summary_conviction_expungements": { "conditions": conditions, "conclusion": conclusion, "expungements": expungements if all(conditions.values()) else [], } }) return modified_record, analysis
def expunge_summary_convictions(crecord: CRecord) -> Tuple[CRecord, Decision]: """ Analyze crecord for expungements of summary convictions. 18 Pa.C.S. 9122(b)(3)(i) and (ii) provide for expungement of summary convictions if the individual has been free of arrest or prosecution for five years following the conviction for the offense. Not available if person got ARD for certain offenses listed in (b.1) Returns: The function creates a Decision. The Value of the decision is a list of the Petions that can be generated according to this rule. The Reasoning of the decision is a list of decisions. The first decision is the global requirement for any expungement under this rule. The following decisions are a decision about the expungeability of each case. Each case-decision, contains its own explanation of what charges were or were not expungeable. TODO excluding ARD offenses from expungements here. TODO grades are often missing. We should tell users we're uncertain. """ # Initialize the decision explaining this rule's outcome. It starts with reasoning that includes the # decisions that are conditions of any case being expungeable. conclusion = Decision( name="Expungements for summary convictions.", value=[], reasoning=[ Decision( name= f"Has {crecord.person.first_name} been arrest free and prosecution free for five years?", value=crecord.years_since_last_arrested_or_prosecuted() > 5, reasoning= f"It has been {crecord.years_since_last_arrested_or_prosecuted()} since the last arrest or prosecection." ) ]) # initialize a blank crecord to hold the cases and charges that can't be expunged under this rule. remaining_recordord = CRecord(person=crecord.person) if all(conclusion.reasoning): for case in crecord.cases: # Find expungeable charges in a case. Save a Decision explaining what's expungeable to # the reasoning of the Decision about the whole record. case_d = Decision(name=f"Is {case.docket_number} expungeable?", reasoning=[]) expungeable_case = case.partialcopy( ) # The charges in this case that are expungeable. not_expungeable_case = case.partialcopy( ) # Charges in this case that are not expungeable. for charge in case.charges: charge_d = Decision( name= f"Is this charge for {charge.offense} a summary conviction?", reasoning=[ Decision( name= f"Is this charge for {charge.offense} a summary?", value=charge.grade.strip() == "S", reasoning= f"The charge's grade is {charge.grade.strip()}"), Decision( name= f"Is this charge for {charge.offense} a conviction?", value=charge.is_conviction(), reasoning= f"The charge's disposition {charge.disposition} indicates a conviction" if charge.is_conviction() else f"The charge's disposition {charge.disposition} indicates its not a conviction." ) ]) if all(charge_d.reasoning): expungeable_case.charges.append(charge) charge_d.value = True else: charge_d.value = False not_expungeable_case.charges.append(charge) case_d.reasoning.append(charge_d) # If there are any expungeable charges, add an Expungepent to the Value of the decision about # this whole record. if len(expungeable_case.charges) > 0: case_d.value = True exp = Expungement( client=crecord.person, cases=[expungeable_case], summary_expungement_language= ". The petitioner has been arrest free for more than five years since this summary conviction" ) if len(expungeable_case.charges) == len(case.charges): exp.expungement_type = Expungement.ExpungementTypes.FULL_EXPUNGEMENT else: exp.expungement_type = Expungement.ExpungementTypes.PARTIAL_EXPUNGEMENT conclusion.value.append(exp) if len(not_expungeable_case.charges) > 0: case_d.value = False remaining_recordord.cases.append(not_expungeable_case) conclusion.reasoning.append(case_d)