Example #1
0
def test_case(example_sentence):
    char = Charge(
        "Eating w/ mouth open",
        "M2",
        "14 section 23",
        "Guilty Plea",
        sentences=[example_sentence])
    case = Case(
        status="Open",
        county="Erie",
        docket_number="12-CP-02",
        otn="112000111",
        dc="11222",
        charges=[char],
        total_fines=200,
        fines_paid=1,
        judge="Smooth Operator",
        judge_address="1234 Other St., PA",
        disposition_date=None,
        arrest_date=None,
        complaint_date=None,
        affiant="Sheriff Smelly",
        arresting_agency="Upsidedown County",
        arresting_agency_address="1234 Main St., PA",
    )
    assert case.status == "Open"
Example #2
0
 def from_dict(dct: dict) -> Expungement:
     dct.update({
         "attorney": Attorney.from_dict(dct["attorney"]),
         "client": Person.from_dict(dct["client"]),
         "cases": [Case.from_dict(c) for c in dct["cases"]],
     })
     return Expungement(**dct)
Example #3
0
def test_order_cases_by_last_action(example_case):
    # sorting when a case has no last_action puts the case with no action
    # at the top.
    case2 = Case(
        status="Open",
        county="Erie",
        docket_number="12-CP-01",
        otn="112000111",
        dc="11222",
        charges=[example_case],
        total_fines=200,
        fines_paid=1,
        judge="Smooth Operator",
        judge_address="1234 Other st.",
        disposition_date=date(2019,1,1),
        arrest_date=None,
        complaint_date=date(2018,2,1),
        arresting_agency="Happy County",
        arresting_agency_address="1234 Main St.",
        affiant="Officer Happy"
    )
    s = sorted([example_case, case2], key=Case.order_cases_by_last_action)
    s[0] == case2

    example_case.arrest_date = date(2019,2,1)
    s = sorted([example_case, case2], key=Case.order_cases_by_last_action)
    s[1] == case2
Example #4
0
def example_case(example_charge):
    return Case(status="Open",
                county="Erie",
                docket_number="12-MC-01",
                otn="112000111",
                dc="11222",
                charges=[example_charge],
                fines_and_costs=200,
                arrest_date=None,
                disposition_date=None,
                judge="Judge Jimmy Hendrix")
Example #5
0
 def from_dict(dct: dict) -> Optional[CRecord]:
     try:
         try:
             person = Person.from_dict(dct["person"])
         except:
             person = None
         try:
             cases = [Case.from_dict(c) for c in dct["cases"]]
         except:
             cases = []
         return CRecord(person=person, cases=cases)
     except:
         return None
Example #6
0
def example_case(example_charge):
    return Case(
        status="Open",
        county="Erie",
        docket_number="12-MC-01",
        otn="112000111",
        dc="11222",
        charges=[example_charge],
        total_fines=200,
        fines_paid=100,
        arrest_date=None,
        complaint_date=None,
        disposition_date=None,
        judge="Judge Jimmy Hendrix",
        judge_address="1234 Judge St.,",
        affiant="Officer Bland",
        arresting_agency_address="1234 Grey St.",
        arresting_agency="Monochrome County PD."
    )
Example #7
0
def get_md_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:
        # in mdj summaries, there's only one "charge" element, not different "open" and "closed" elements.
        # And there are no sentences recorded.
        md_charges = []
        md_charge_elems = case.xpath(".//charge")
        for charge in md_charge_elems:
            charge = Charge(
                offense=text_or_blank(charge.find("description")),
                statute=text_or_blank(charge.find("statute")),
                grade=text_or_blank(charge.find("grade")),
                disposition=text_or_blank(charge.find("disposition")),
                sentences=[],
            )
            md_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=md_charges,
                total_fines=None,  # a summary docket never has info about this.
                fines_paid=None,
                arrest_date=date_or_none(
                    case.find("arrest_disp_actions/arrest_disp/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")),
            )
        )
    return cases
Example #8
0
def test_from_dict(example_case):
    assert Case.from_dict({"invalid": "stuff"}) is None
    ser = to_serializable(example_case)
    c2 = Case.from_dict(ser)
    assert c2.docket_number == example_case.docket_number
Example #9
0
def get_case(stree: etree) -> Case:
    """
    Extract a list of Cases from the xml of a docket that has been parsed into sections.

    Returns and empty Case on failure.

    Args:
         stree: xml tree of a docket, parsed into a header and some number of sections
    
    Returns:
        a Cases object. 
    
    """
    county = xpath_or_blank(stree, "/docket/header/court_name/county")
    docket_number = xpath_or_blank(stree, "/docket/header/docket_number")
    otn = xpath_or_blank(stree, "//section[@name='section_case_info']//otn")
    dc = xpath_or_blank(stree, "//section[@name='section_case_info']//dc")
    judge = xpath_or_blank(
        stree, "//section[@name='section_case_info']//judge_assigned")
    affiant = xpath_or_blank(stree, "//arresting_officer")
    arresting_agency = xpath_or_blank(stree, "//arresting_agency")
    complaint_date = xpath_date_or_blank(
        stree, "//section[@name='section_status_info']//complaint_date")
    arrest_date = xpath_date_or_blank(
        stree, "//section[@name='section_status_info']//arrest_date")
    status = xpath_or_blank(
        stree, "//section[@name='section_status_info']//case_status")

    # If the case's status is Closed, find the disposition date by finding the last status event date.
    # TODO I'm not sure this is the right date. Is the 'disposition date' the date the case status changed to
    #       Completed, or the date of "Sentenced/Penalty Imposed"
    if re.search("close", status, re.IGNORECASE):
        disposition_date = xpath_date_or_blank(
            stree,
            "//section[@name='section_status_info']//status_event[1]/status_date"
        )
        #try:
        #    disposition_date = datetime.strptime(disposition_date, r"%m/%d/%Y")
        #except ValueError:
        #    #logging.error(f"disposition date {disposition_date} did not parse.")
        #    disposition_date = None
    else:
        disposition_date = None

    # fines and costs
    total_fines = str_to_money(
        xpath_or_blank(
            stree,
            "//section[@name='section_case_financal_info']/case_financial_info/grand_toals/assessed"
        ))
    fines_paid = str_to_money(
        xpath_or_blank(
            stree,
            "//section[@name='section_case_financial_info']/case_financial_info/grant_totals/payments"
        ))
    # charges
    charges = get_charges(stree)

    return Case(status=status,
                county=county,
                docket_number=docket_number,
                otn=otn,
                dc=dc,
                charges=charges,
                total_fines=total_fines,
                fines_paid=fines_paid,
                arrest_date=arrest_date,
                disposition_date=disposition_date,
                judge=judge,
                affiant=affiant,
                arresting_agency=arresting_agency,
                complaint_date=complaint_date)
Example #10
0
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
Example #11
0
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