Skip to content

Commit

Permalink
feat(util): Adds helper function to parse data from the receipt table
Browse files Browse the repository at this point in the history
This commit introduces a new utility function to efficiently extract data from receipt tables, addressing the limitation of multi-document pages. This enhancement improves the extension's ability to accurately process documents.
  • Loading branch information
ERosendo committed Oct 1, 2024
1 parent 7611f1f commit c562279
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/appellate/appellate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,25 +1181,30 @@ AppellateDelegate.prototype.onDocumentViewSubmit = async function (event) {
let form = document.getElementById(event.data.id);

let title = document.querySelectorAll('strong')[1].innerHTML;
let dataFromTitle = APPELLATE.parseReceiptPageTitle(title);
let pdfData = APPELLATE.parseReceiptPageTitle(title);

if (
dataFromTitle.att_number == 0 &&
this.queryParameters.get('recapAttNum')
) {
dataFromTitle.att_number = this.queryParameters.get('recapAttNum');
// For multi-document pages, the title alone doesn't provide sufficient
// information. Therefore, we need to extract additional data from the
// receipt table to accurately identify the PDF.
// Attempt to parse the necessary data from the receipt table.
if (!pdfData) pdfData = APPELLATE.parseDataFromReceiptTable();

// If we still don't have enough data after parsing the receipt table,
// submit the form without retrieving the file.
if (!pdfData) {
form.submit();
return;
}

if (dataFromTitle.doc_number.length > 9) {
if (pdfData.att_number == 0 && this.queryParameters.get('recapAttNum'))
pdfData.att_number = this.queryParameters.get('recapAttNum');

if (pdfData.doc_number.length > 9) {
// If the number is really big, it's probably a court that uses
// pacer_doc_id instead of regular docket entry numbering.
dataFromTitle.doc_number = PACER.cleanPacerDocId(dataFromTitle.doc_number);
pdfData.doc_number = PACER.cleanPacerDocId(dataFromTitle.doc_number);
}

if (!dataFromTitle) {
form.submit();
return;
}
$('body').css('cursor', 'wait');
let query_string = new URLSearchParams(new FormData(form)).toString();
const resp = await window.fetch(form.action, {
Expand All @@ -1215,7 +1220,7 @@ AppellateDelegate.prototype.onDocumentViewSubmit = async function (event) {
await resp.blob(),
null,
previousPageHtml,
dataFromTitle
pdfData
);
};

Expand Down
18 changes: 18 additions & 0 deletions src/appellate/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,24 @@ let APPELLATE = {
return r;
},

// returns data from the table of the Receipt Page as an object
parseDataFromReceiptTable: () => {
// this method uses regex expressions to match that information from the
// receipt table and returns an object with the following attributes:
// - docket_number
// - doc_number
// - att_number (if applicable).
let search_string = $('td:contains(Case)').text();
let regex =
/Case: (?<docket_number>[^']*), Document: (?<doc_number>\d+)(-(?<att_number>\d+))?/;
let matches = regex.exec(search_string);
// If no matches were found, return null.
if (!matches) return null;
// If an attachment number was not found, set it to 0.
if (!matches.groups.att_number) matches.groups.att_number = 0;
return matches.groups;
},

// Returns an object with the court Id and docket number core extracted from a link to district court
getDatafromDistrictLinkUrl: (url) => {
// Converts links to district courts like:
Expand Down

0 comments on commit c562279

Please sign in to comment.