Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dexex organize docket sorting (WIP) #5556

Draft
wants to merge 9 commits into
base: staging
Choose a base branch
from
8 changes: 8 additions & 0 deletions __TODO_devex_docket_number_sorting.md.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- Make DocketRecordSortInfo more agnostic (we can use this for anywhere we sort any field), or use the state key idea
- Figure out how to update old docketRecordSort, which I have slowly been doing
- Figure out how to avoid the different sorts we currently have going on as a result of docket number table sorting, which I started to do in generateDocketRecordPdfProxy (we were sorting the docket entries multiple times unnecessarily). It looks like we are passing along docketRecordSort and docketRecordTableSort, sometimes using one and sometimes the other (in fact, the latter was overwriting whatever we did in the former in generateDocketRecordPdfProxy). This is a code smell.
-- Do we need separate state for sorting the table vs. sorting the entries? I suspect not. But why is sessionMetaData by docket number

TODOS lists as DEVEX TODO

X - sortDocketEntryTable should be replaced by the existing sort function, but the existing sort function should use the <T> dynamic type idea of sortDocketEntryTable
52 changes: 0 additions & 52 deletions shared/src/business/entities/cases/Case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,65 +225,13 @@ export class Case extends JoiValidationEntity {
return parseInt(`${yearFiledAdjusted}${sequentialNumberPadded}`);
}

/**
* sorts the given array of cases by docket number
* @param {Array} cases the cases to check for lead case computation
* @returns {Case} the lead Case entity
*/
static sortByDocketNumber<T>(cases: (T & { docketNumber: string })[]): T[] {
return cases.sort((a, b) => {
return Case.docketNumberSort(a.docketNumber, b.docketNumber);
});
}

static docketNumberSort(docketNumberA, docketNumberB) {
return (
(Case.getSortableDocketNumber(docketNumberA) || 0) -
(Case.getSortableDocketNumber(docketNumberB) || 0)
);
}

static sortByDocketNumberAndGroupConsolidatedCases<
T extends { leadDocketNumber?: string; docketNumber: string },
>(cases: T[]): T[] {
let nonMemberCases: T[] = [];
let memberCases: { [key: string]: T[] } = {};

// Create a set of docket numbers for quick lookup
const docketNumbers = new Set(cases.map(c => c.docketNumber));

// Group cases into 1) "top-level" lead or non-member cases and 2) valid non-lead, member cases
for (const c of cases) {
if (
c.leadDocketNumber &&
c.leadDocketNumber !== c.docketNumber &&
docketNumbers.has(c.leadDocketNumber) // Check if the lead case exists; if not, treat this case as a non-member case
) {
(memberCases[c.leadDocketNumber] ||= []).push(c);
} else {
nonMemberCases.push(c);
}
}

// Sort the lead/non-member cases
Case.sortByDocketNumber(nonMemberCases);

// Then, sort and interpolate the non-lead, member cases
const interpolatedCases: T[] = [];
for (const caseItem of nonMemberCases) {
interpolatedCases.push(caseItem);

// Append and sort member cases inline if applicable
if (memberCases[caseItem.docketNumber]) {
interpolatedCases.push(
...Case.sortByDocketNumber(memberCases[caseItem.docketNumber]),
);
}
}

return interpolatedCases;
}

/**
* return the lead case for the given set of cases based on createdAt
* (does NOT evaluate leadDocketNumber)
Expand Down
14 changes: 5 additions & 9 deletions shared/src/business/test/createTestApplicationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ import { bulkIndexRecords } from '@web-api/persistence/elasticsearch/bulkIndexRe
import { calculateDaysElapsedSinceLastStatusChange } from '@shared/business/utilities/calculateDaysElapsedSinceLastStatusChange';
import { caseStatusWithTrialInformation } from '@shared/business/utilities/caseStatusWithTrialInformation';
import { combineTwoPdfs } from '@shared/business/utilities/documentGenerators/combineTwoPdfs';
import {
compareCasesByDocketNumber,
formatCaseForTrialSession,
getFormattedTrialSessionDetails,
} from '@shared/business/utilities/trialSession/getFormattedTrialSessionDetails';
import {
compareISODateStrings,
compareStrings,
Expand All @@ -60,8 +55,11 @@ import {
formatCase,
formatDocketEntry,
getFormattedCaseDetail,
sortDocketEntries,
} from '@shared/business/utilities/getFormattedCaseDetail';
import {
formatCaseForTrialSession,
getFormattedTrialSessionDetails,
} from '@shared/business/utilities/trialSession/getFormattedTrialSessionDetails';
import { formatDollars } from '@shared/business/utilities/formatDollars';
import {
formatJudgeName,
Expand Down Expand Up @@ -117,6 +115,7 @@ import { setNoticesForCalendaredTrialSessionInteractor } from '@shared/proxies/t
import { setPdfFormFields } from '@web-api/business/useCaseHelper/pdf/setPdfFormFields';
import { setServiceIndicatorsForCase } from '@shared/business/utilities/setServiceIndicatorsForCase';
import { setupPdfDocument } from '@shared/business/utilities/setupPdfDocument';
import { sortDocketEntries } from '@shared/business/utilities/sorting/docketEntrySorting';
import { unsealDocketEntryInteractor } from '@web-api/business/useCases/docketEntry/unsealDocketEntryInteractor';
import { updateCase } from '@web-api/persistence/dynamo/cases/updateCase';
import { updateCaseAndAssociations } from '@web-api/business/useCaseHelper/caseAssociation/updateCaseAndAssociations';
Expand Down Expand Up @@ -207,9 +206,6 @@ export const createTestApplicationContext = () => {
.mockImplementation(caseStatusWithTrialInformation),
checkDate: jest.fn().mockImplementation(DateHandler.checkDate),
combineTwoPdfs: jest.fn().mockImplementation(combineTwoPdfs),
compareCasesByDocketNumber: jest
.fn()
.mockImplementation(compareCasesByDocketNumber),
compareISODateStrings: jest.fn().mockImplementation(compareISODateStrings),
compareStrings: jest.fn().mockImplementation(compareStrings),
copyPagesAndAppendToTargetPdf: jest
Expand Down
14 changes: 7 additions & 7 deletions shared/src/business/useCases/getCasesForUserInteractor.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
Case,
isClosed,
isLeadCase,
userIsDirectlyAssociated,
} from '../entities/cases/Case';
import { PaymentStatusTypes } from '@shared/business/entities/EntityConstants';
import { UnauthorizedError } from '@web-api/errors/errors';
import {
UnknownAuthUser,
isAuthUser,
} from '@shared/business/entities/authUser/AuthUser';
import { compareISODateStrings } from '../utilities/sortFunctions';
import {
isClosed,
isLeadCase,
userIsDirectlyAssociated,
} from '../entities/cases/Case';
import { partition, uniqBy } from 'lodash';
import { sortByDocketNumber } from '@shared/business/utilities/sorting/caseSorting';

interface UserCaseDTO {
caseCaption: string;
Expand Down Expand Up @@ -145,7 +145,7 @@ async function fetchConsolidatedGroupsAndNest({
return {
...aCase,
consolidatedCases: aCase.consolidatedCases.length
? Case.sortByDocketNumber(aCase.consolidatedCases)
? sortByDocketNumber(aCase.consolidatedCases)
: undefined,
};
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Case, isClosed } from '../entities/cases/Case';
import { PractitionerCaseDetail } from '@web-client/presenter/state';
import {
ROLE_PERMISSIONS,
Expand All @@ -8,7 +7,9 @@ import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { formatCase } from '@shared/business/utilities/getFormattedCaseDetail';
import { isClosed } from '../entities/cases/Case';
import { partition } from 'lodash';
import { sortByDocketNumber } from '@shared/business/utilities/sorting/caseSorting';

export const getPractitionerCasesInteractor = async (
applicationContext: ServerApplicationContext,
Expand Down Expand Up @@ -59,7 +60,7 @@ export const getPractitionerCasesInteractor = async (
});

const [closedCases, openCases] = partition(
Case.sortByDocketNumber(caseDetails).reverse(),
sortByDocketNumber(caseDetails).reverse(),
theCase => isClosed(theCase),
);

Expand Down

This file was deleted.

Loading
Loading