Skip to content

Commit 84366e7

Browse files
btposeyfmaddenflxjamesobrooks
committed
Properly translate chapters to query
Jira ticket: CAMS-461 Co-authored-by: Fritz Madden <[email protected]> Co-authored-by: James Brooks <[email protected]> Co-authored-by: Brian Posey <[email protected]>,
1 parent 09d0f66 commit 84366e7

File tree

2 files changed

+98
-33
lines changed

2 files changed

+98
-33
lines changed

backend/functions/lib/adapters/gateways/acms/acms.gateway.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,59 @@ describe('ACMS gateway tests', () => {
8686
},
8787
);
8888

89+
const chapters = [
90+
{ chapter: '9', querySubString: null, inputVariable: '09' },
91+
{ chapter: '11', querySubString: null, inputVariable: '11' },
92+
{ chapter: '12', querySubString: null, inputVariable: '12' },
93+
{ chapter: '13', querySubString: null, inputVariable: '13' },
94+
{ chapter: '15', querySubString: null, inputVariable: '15' },
95+
{ chapter: '7', querySubString: "IN ('7A', '7N')", inputVariable: null },
96+
];
97+
test.each(chapters)('should translate chapter $chapter into query', async (params) => {
98+
const spy = jest
99+
.spyOn(AbstractMssqlClient.prototype, 'executeQuery')
100+
.mockResolvedValueOnce({
101+
success: true,
102+
results: [{ leadCaseCount: 0 }],
103+
message: '',
104+
})
105+
.mockResolvedValue({
106+
success: true,
107+
results: [],
108+
message: '',
109+
});
110+
111+
const predicate: Predicate = {
112+
chapter: params.chapter,
113+
divisionCode: '081',
114+
};
115+
const predicateAndPage: PredicateAndPage = {
116+
...predicate,
117+
pageNumber: 0,
118+
};
119+
120+
const context = await createMockApplicationContext();
121+
const gateway = new AcmsGatewayImpl(context);
122+
await gateway.getPageCount(context, predicate);
123+
await gateway.getLeadCaseIds(context, predicateAndPage);
124+
125+
if (params.inputVariable) {
126+
expect(spy).toHaveBeenCalledWith(
127+
context,
128+
expect.any(String),
129+
expect.arrayContaining([
130+
expect.objectContaining({ name: 'chapter', value: params.inputVariable }),
131+
]),
132+
);
133+
} else {
134+
expect(spy).toHaveBeenCalledWith(
135+
context,
136+
expect.stringContaining(params.querySubString),
137+
expect.any(Array),
138+
);
139+
}
140+
});
141+
89142
test('should get substantive consolidation details from ACMS', async () => {
90143
const leadCaseId = '0000000000';
91144
const databaseResult: AcmsConsolidationChildCase[] = [

backend/functions/lib/adapters/gateways/acms/acms.gateway.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,28 @@ export class AcmsGatewayImpl extends AbstractMssqlClient implements AcmsGateway
2424

2525
async getPageCount(context: ApplicationContext, predicate: Predicate): Promise<number> {
2626
const input: DbTableFieldSpec[] = [];
27+
let query = `
28+
SELECT COUNT(DISTINCT CONSOLIDATED_CASE_NUMBER) AS leadCaseCount
29+
FROM CMMDB
30+
WHERE CASE_DIV = @divisionCode
31+
AND CLOSED_BY_COURT_DATE = '0' OR CLOSED_BY_COURT_DATE > '20170101'
32+
AND CONSOLIDATED_CASE_NUMBER != '0'`;
2733

28-
// TODO: map from string chapters that accept numbers to be two character strings
29-
// 09, 11, 12, 13, 15, 7A, 7N, AC
30-
input.push({
31-
name: 'chapter',
32-
type: mssql.VarChar,
33-
value: predicate.chapter,
34-
});
34+
// Valid ACMS chapters: 09, 11, 12, 13, 15, 7A, 7N, AC
35+
// 'AC' is the predecesor to chapter 15. We are not importing these old cases into CAMS.
36+
// '7A' and '7N' are treated inclusively as chapter 7 cases when importing into CAMS.
37+
// Leading zero padding is added for chapter 9.
38+
39+
if (predicate.chapter === '7') {
40+
query += ` AND CURR_CASE_CHAPT IN ('7A', '7N')`;
41+
} else {
42+
query += ` AND CURR_CASE_CHAPT = @chapter`;
43+
input.push({
44+
name: 'chapter',
45+
type: mssql.VarChar,
46+
value: ('00' + predicate.chapter).slice(-2),
47+
});
48+
}
3549

3650
input.push({
3751
name: 'divisionCode',
@@ -43,14 +57,6 @@ export class AcmsGatewayImpl extends AbstractMssqlClient implements AcmsGateway
4357
leadCaseCount: number;
4458
};
4559

46-
const query = `
47-
SELECT COUNT(DISTINCT CONSOLIDATED_CASE_NUMBER) AS leadCaseCount
48-
FROM CMMDB
49-
WHERE CURR_CASE_CHAPT = @chapter
50-
AND CASE_DIV = @divisionCode
51-
AND CLOSED_BY_COURT_DATE = '0' OR CLOSED_BY_COURT_DATE > '20170101'
52-
AND CONSOLIDATED_CASE_NUMBER != '0'`;
53-
5460
try {
5561
const results = await this.executeQuery<ResultType>(context, query, input);
5662
const result = results.results[0];
@@ -66,14 +72,6 @@ export class AcmsGatewayImpl extends AbstractMssqlClient implements AcmsGateway
6672
): Promise<string[]> {
6773
const input: DbTableFieldSpec[] = [];
6874

69-
// TODO: map from string chapters that accept numbers to be two character strings
70-
// 09, 11, 12, 13, 15, 7A, 7N, AC
71-
input.push({
72-
name: 'chapter',
73-
type: mssql.VarChar,
74-
value: predicateAndPage.chapter,
75-
});
76-
7775
input.push({
7876
name: 'divisionCode',
7977
type: mssql.VarChar,
@@ -92,25 +90,39 @@ export class AcmsGatewayImpl extends AbstractMssqlClient implements AcmsGateway
9290
value: PAGE_SIZE * (predicateAndPage.pageNumber - 1),
9391
});
9492

95-
// RIGHT(CONCAT('000', CAST(CONSOLIDATED_CASE_NUMBER AS VARCHAR)), 10)
96-
const query = `
93+
let query = `
9794
SELECT DISTINCT CONSOLIDATED_CASE_NUMBER AS leadCaseId
9895
FROM CMMDB
99-
WHERE CURR_CASE_CHAPT = @chapter
100-
AND CASE_DIV = @divisionCode
96+
WHERE CASE_DIV = @divisionCode
10197
AND CLOSED_BY_COURT_DATE = '0' OR CLOSED_BY_COURT_DATE > '20170101'
102-
AND CONSOLIDATED_CASE_NUMBER != '0'
103-
ORDER BY CONSOLIDATED_CASE_NUMBER DESC OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
98+
AND CONSOLIDATED_CASE_NUMBER != '0'`;
99+
100+
// Valid ACMS chapters: 09, 11, 12, 13, 15, 7A, 7N, AC
101+
// 'AC' is the predecesor to chapter 15. We are not importing these old cases into CAMS.
102+
// '7A' and '7N' are treated inclusively as chapter 7 cases when importing into CAMS.
103+
// Leading zero padding is added for chapter 9.
104+
105+
if (predicateAndPage.chapter === '7') {
106+
query += ` AND CURR_CASE_CHAPT IN ('7A', '7N')`;
107+
} else {
108+
query += ` AND CURR_CASE_CHAPT = @chapter`;
109+
input.push({
110+
name: 'chapter',
111+
type: mssql.VarChar,
112+
value: ('00' + predicateAndPage.chapter).slice(-2),
113+
});
114+
}
115+
116+
query += ` ORDER BY CONSOLIDATED_CASE_NUMBER DESC OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
104117

105118
type ResultType = {
106119
leadCaseId: string;
107120
};
108121

109122
try {
110-
const results = await this.executeQuery<ResultType>(context, query, input);
111-
// TODO: Fix this.
112-
const theFrackingList = results.results as ResultType[];
113-
return theFrackingList.map((record) => record.leadCaseId);
123+
const { results } = await this.executeQuery<ResultType>(context, query, input);
124+
const leadCaseIdsResults = results as ResultType[];
125+
return leadCaseIdsResults.map((record) => record.leadCaseId);
114126
} catch (originalError) {
115127
throw getCamsError(originalError, MODULE_NAME);
116128
}

0 commit comments

Comments
 (0)