Skip to content

Commit 447edc7

Browse files
Only send needed JSON, not whole dump
Built from https://projects.suffolklitlab.org/EfileProxyServer/rest_guide/ and a bit more looking through the source code to confirm what values are required (easier after SuffolkLITLab/EfileProxyServer#387).
1 parent 1fca30c commit 447edc7

1 file changed

Lines changed: 138 additions & 44 deletions

File tree

docassemble/EFSPIntegration/efm_client.py

Lines changed: 138 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _give_data_url(bundle: ALDocumentBundle, key: str = "final") -> None:
8282
"http://localhost/",
8383
"http://" + get_config("external hostname") + "/",
8484
)
85-
attachment.page_court = attachment_pdf.num_pages()
85+
attachment.page_count = attachment_pdf.num_pages()
8686
else:
8787
doc_pdf = doc.as_pdf(key)
8888
doc.data_url = doc_pdf.url_for(external=True, temporary=True)
@@ -108,52 +108,146 @@ def _get_all_vars(bundle: ALDocumentBundle, key: str = "final") -> Dict:
108108
"""Strips out some extra big variables that we don't need to serialize and send across the network"""
109109
_give_data_url(bundle, key=key)
110110
all_vars_dict = all_variables()
111-
vars_to_pop = set(
112-
[
113-
"trial_court_resp",
114-
"x",
115-
"trial_court_options",
116-
"found_case",
117-
"selected_existing_case",
118-
"multi_user",
119-
"url_args",
120-
"nav",
121-
"allow_cron",
122-
"speak_text",
123-
"filing_type_options",
124-
"filing_type_map",
125-
"party_type_options",
126-
"available_efile_courts",
127-
"case_category_map",
128-
"full_court_info",
129-
"tyler_login_resp",
130-
"case_type_map",
131-
"all_courts",
132-
"al_user_bundle",
133-
"court_emails",
134-
"party_type_map",
135-
"case_search",
136-
"subdoc",
137-
"target_case",
138-
"menu_items",
139-
"device_local",
140-
"session_local",
141-
]
142-
)
143-
for var in vars_to_pop:
144-
all_vars_dict.pop(var, None)
145111

146-
all_vars_dict = _remove_all_da_emptys(all_vars_dict)
112+
to_send_dict = {}
113+
# TODO: mark any of the below as required, ask for them now!
114+
for key in (
115+
"efile_case_category",
116+
"efile_case_type",
117+
"efile_case_subtype",
118+
"previous_case_id",
119+
"docket_number",
120+
"user_preferred_language",
121+
"user_started_case",
122+
"user_role",
123+
"comments_to_clerk",
124+
"tyler_payment_id",
125+
"return_date",
126+
"amount_in_controversy",
127+
"out_of_state",
128+
"filer_type",
129+
"max_fee_amount",
130+
"procedure_remedy",
131+
"damage_amount",
132+
"is_contested_case",
133+
"email_confirmation_subject",
134+
"email_confirmation_contents",
135+
"acceptance_subject",
136+
"acceptance_contents",
137+
"rejected_subject",
138+
"rejected_contents",
139+
"neutral_subject",
140+
"neutral_contents",
141+
):
142+
to_send_dict[key] = all_vars_dict.get(key)
143+
144+
# Simple lists or dicts (i.e. not people or filings)
145+
for key in (
146+
"attorney_ids",
147+
"party_to_attorneys",
148+
"service_contacts",
149+
"lower_court_case",
150+
"trial_court",
151+
"cross_references",
152+
):
153+
to_send_dict[key] = all_vars_dict.get(key)
154+
155+
def person_convert(person):
156+
new_person = {
157+
person_key: person.get(person_key)
158+
for person_key in (
159+
"mobile_number",
160+
"phone_number",
161+
"email",
162+
"party_type",
163+
"prefered_language",
164+
"gender",
165+
"date_of_birth",
166+
"person_type",
167+
"is_form_filler",
168+
"name",
169+
"tyler_id",
170+
"is_new",
171+
)
172+
}
173+
old_address = person.get("address") or {}
174+
new_person["address"] = {
175+
key: old_address.get(key)
176+
for key in ("address", "unit", "city", "state", "country", "county")
177+
}
178+
return new_person
179+
180+
# The people
181+
for key in (
182+
"users",
183+
"other_parties",
184+
):
185+
people = all_vars_dict.get(key)
186+
people_list = people.get("elements")
187+
new_people_list = []
188+
for person in people_list:
189+
new_person = person_convert(person)
190+
new_people_list.append(new_person)
191+
to_send_dict[key] = new_people_list
192+
193+
if "lead_contact" in all_vars_dict:
194+
to_send_dict["lead_contact"] = person_convert(
195+
all_vars_dict.get("lead_contact") or {}
196+
)
197+
198+
court_bundle = all_vars_dict.get("al_court_bundle")
199+
bundle_list = court_bundle.get("elements")
200+
new_bundle_list = []
201+
ATTACHMENT_KEYS = [
202+
"document_type",
203+
"filing_component",
204+
"filename",
205+
"document_description",
206+
"data_url",
207+
"proxy_enabled",
208+
"page_count",
209+
]
210+
for doc in bundle_list:
211+
if doc.get("proxy_enabled"):
212+
new_doc = {
213+
doc_key: doc.get(doc_key)
214+
for doc_key in (
215+
"proxy_enabled",
216+
"filing_type",
217+
"motion_type",
218+
"optional_services",
219+
"due_date",
220+
"filing_description",
221+
"reference_number",
222+
"filing_attorney",
223+
"filing_comment",
224+
"courtesy_copies",
225+
"preliminary_copies",
226+
"filing_parties",
227+
"filing_action",
228+
"tyler_merge_attachments",
229+
)
230+
}
231+
for maybe_key in ATTACHMENT_KEYS:
232+
if maybe_key in doc:
233+
new_doc[maybe_key] = doc.get(maybe_key)
234+
235+
new_doc["elements"] = []
236+
for old_elem in doc.get("elements") or []:
237+
if old_elem.get("proxy_enabled"):
238+
new_doc["elements"].append(
239+
{
240+
elem_key: old_elem.get(elem_key)
241+
for elem_key in ATTACHMENT_KEYS
242+
}
243+
)
244+
new_bundle_list.append(new_doc)
147245

148-
for doc in all_vars_dict.get("al_court_bundle", {}).get("elements", []):
149-
doc.pop("optional_service_options", None)
150-
doc.pop("document_type_options", None)
151-
doc.pop("document_type_map", None)
152-
doc.pop("filing_component_map", None)
153-
doc.pop("filing_component_options", None)
154-
doc.pop("optional_service_map", None)
246+
to_send_dict["al_court_bundle"] = new_bundle_list
155247

156-
return all_vars_dict
248+
# TODO: needed?
249+
to_send_dict = _remove_all_da_emptys(to_send_dict)
250+
return to_send_dict
157251

158252

159253
class ProxyConnection(EfspConnection):

0 commit comments

Comments
 (0)