Skip to content

Commit

Permalink
Merge pull request #1724 from wittejm/osp-form-has-counties-list
Browse files Browse the repository at this point in the history
updated osp form with new fields:
  • Loading branch information
wittejm committed May 20, 2024
2 parents e0f8d05 + b932708 commit f1c6cab
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
Binary file modified src/backend/expungeservice/files/OSP_Form.pdf
Binary file not shown.
Binary file not shown.
57 changes: 47 additions & 10 deletions src/backend/expungeservice/form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class UserInfo:
state: str
zip_code: str
phone_number: str
counties_with_cases_to_expunge: List[str]
has_eligible_convictions: bool


@dataclass
Expand All @@ -157,6 +159,8 @@ def build(cls, case: Case, user_info_dict: Dict[str, str], sid: str):
case_name=case.summary.name,
has_no_balance=case.summary.balance_due_in_cents == 0,
da_number=case.summary.district_attorney_number,
counties_with_cases_to_expunge=[],
has_eligible_convictions=False,
**user_info_dict,
)

Expand Down Expand Up @@ -233,6 +237,10 @@ def has_contempt_of_court(self) -> bool:
def has_eligible_charges(self) -> bool:
return not self.eligible_charges.empty

@property
def get_has_eligible_convictions(self) -> bool:
return any([charge for charge in self.eligible_charges._charges if charge.convicted])

@property
def has_future_eligible_charges(self) -> bool:
return (
Expand Down Expand Up @@ -385,8 +393,15 @@ def __getitem__(self, key):
def extra_mappings(self):
s = self.source_data
if not isinstance(s, CaseResults):
return {}

# Is the OSP Form
osp_fields: Dict[str, object] = {}
for i in range(10):
osp_fields[f"(Court {i+1})"] = f"Circuit Court for {s.counties_with_cases_to_expunge[i]} County" if i<len(s.counties_with_cases_to_expunge) else ""
if s.has_eligible_convictions:
osp_fields["(Include a Conviction Yes)"] = True
else:
osp_fields["(Include a Conviction No)"] = True
return osp_fields
return {
"(FOR THE COUNTY OF)": s.county,
"(Plaintiff)": "State of Oregon",
Expand Down Expand Up @@ -438,6 +453,7 @@ def extra_mappings(self):
class PDF:
BUTTON_TYPE = "/Btn"
BUTTON_ON = PdfName("On")
BUTTON_YES = PdfName("Yes")
TEXT_TYPE = "/Tx"
FONT_FAMILY = "TimesNewRoman"
FONT_SIZE = "10"
Expand Down Expand Up @@ -471,9 +487,12 @@ def set_pdf(self, pdf: PdfReader):
# necessarily "/Yes". If a new form has been made, make sure to check
# which value to use here and redefine BUTTON_ON if needed.
def set_checkbox_on(self, annotation):
assert self.BUTTON_ON in annotation.AP.N.keys()
annotation.V = self.BUTTON_ON
annotation.AS = self.BUTTON_ON
if self.BUTTON_ON in annotation.AP.N.keys():
annotation.V = self.BUTTON_ON
annotation.AS = self.BUTTON_ON
elif self.BUTTON_YES in annotation.AP.N.keys():
annotation.V = self.BUTTON_YES
annotation.AS = self.BUTTON_YES

def set_text_value(self, annotation, value):
new_value = value
Expand Down Expand Up @@ -536,15 +555,16 @@ def validate_initial_state(self):
not_blank_message = lambda elem, type: f"[PDF] PDF {type} not blank: {elem.T} - {elem.V}"

for field in self._pdf.Root.AcroForm.Fields:
assert field.V is None, not_blank_message(field, "field")
assert field.V in [None, "/Off", "()"], not_blank_message(field, "field")

for annotation in self.annotations:
assert annotation.V is None, not_blank_message(annotation, "annotation")
assert annotation.V in [None, "/Off", "()"], not_blank_message(annotation, "annotation")

assert set(self.get_field_dict()) == set(
self.get_annotation_dict()
), "[PDF] PDF fields do not match annotations"


class FormFilling:
OREGON_PDF_NAME = "oregon"
NON_OREGON_PDF_COUNTIES = ["multnomah"]
Expand All @@ -561,14 +581,23 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st

sid = FormFilling._unify_sids(record_summary)

all_case_results = []
has_eligible_convictions = False
for case in record_summary.record.cases:
case_results = CaseResults.build(case, user_information_dict, sid)

if case_results.get_has_eligible_convictions:
has_eligible_convictions = True
all_case_results.append(case_results)
if case_results.is_expungeable_now:
file_info = FormFilling._create_and_write_pdf(case_results, temp_dir)
zip_file.write(*file_info)

osp_file_info = FormFilling._create_and_write_pdf(user_information_dict, temp_dir)
user_information_dict_2: Dict[str, object] = {**user_information_dict}
user_information_dict_2["counties_with_cases_to_expunge"] = FormFilling.counties_with_cases_to_expunge(
all_case_results
)
user_information_dict_2["has_eligible_convictions"] = has_eligible_convictions
osp_file_info = FormFilling._create_and_write_pdf(user_information_dict_2, temp_dir)
zip_file.write(*osp_file_info)
zip_file.close()

Expand Down Expand Up @@ -648,7 +677,7 @@ def _create_pdf(source_data: UserInfo, validate_initial_pdf_state=False) -> PDF:

@staticmethod
def _create_and_write_pdf(
data: Union[Dict[str, str], UserInfo], dir: str, validate_initial_pdf_state=False
data: Union[Dict, UserInfo], dir: str, validate_initial_pdf_state=False
) -> Tuple[str, str]:
if isinstance(data, UserInfo):
source_data = data
Expand All @@ -665,3 +694,11 @@ def _create_and_write_pdf(
pdf.write(write_file_path)

return write_file_path, write_file_name

@staticmethod
def counties_with_cases_to_expunge(all_case_results: List[CaseResults]):
counties: List[str] = []
for case_result in all_case_results:
if case_result.has_eligible_charges and case_result.case.summary.location not in counties:
counties.append(case_result.case.summary.location)
return counties
20 changes: 20 additions & 0 deletions src/backend/tests/fixtures/form_filling_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
court_fields = {
"(Court 1)": "(Circuit Court for Benton County)",
"(Court 2)": "(Circuit Court for Baker County)",
"(Court 3)": "<>",
"(Court 4)": "<>",
"(Court 5)": "<>",
"(Court 6)": "<>",
"(Court 7)": "<>",
"(Court 8)": "<>",
"(Court 9)": "<>",
"(Court 10)": "<>",
"(Include a Conviction Yes)": "/Yes",
"(Include a Conviction No)": "/Off",
}
oregon_john_common_pdf_fields = {
"document_0": {
0: {
Expand Down Expand Up @@ -206,6 +220,7 @@
"(City)": "(Portland)",
"(State)": "(OR)",
"(Zip Code)": "(97222)",
**court_fields,
}
},
}
Expand Down Expand Up @@ -448,6 +463,7 @@
"(City)": "(Portland)",
"(State)": "(OR)",
"(Zip Code)": "(97222)",
**court_fields
}
},
}
Expand Down Expand Up @@ -693,6 +709,7 @@
"(City)": "(Portland)",
"(State)": "(OR)",
"(Zip Code)": "(97222)",
**court_fields
}
},
}
Expand Down Expand Up @@ -761,6 +778,7 @@
"(City)": "(Portland)",
"(State)": "(OR)",
"(Zip Code)": "(97222)",
**court_fields
}
},
}
Expand Down Expand Up @@ -832,6 +850,8 @@
"(City)": "(Portland)",
"(State)": "(OR)",
"(Zip Code)": "(97222)",
**court_fields
}
},
}

8 changes: 6 additions & 2 deletions src/backend/tests/test_form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def assert_pdf_values(pdf: PDF, expected: Dict[str, str]):
for key in set(annotation_dict) - set(expected):
value = annotation_dict[key].V
if annotation_dict[key].FT == PDF.TEXT_TYPE:
assert value is None, key
assert value in [None, "<>"], key
if annotation_dict[key].FT == PDF.BUTTON_TYPE:
assert value != PDF.BUTTON_ON, key

Expand Down Expand Up @@ -310,7 +310,11 @@ def test_user_info_is_placed_in_osp_form(self):
"(State)": "(OR)",
"(Zip Code)": "(97111)",
}
user_info = UserInfo(**user_data)
user_info = UserInfo(
counties_with_cases_to_expunge=[],
has_eligible_convictions=False,
**user_data,
)
pdf = FormFilling._create_pdf(user_info, validate_initial_pdf_state=True)
assert_pdf_values(pdf, expected_values)

Expand Down

0 comments on commit f1c6cab

Please sign in to comment.