Skip to content

Commit

Permalink
Merge pull request #14 from MeasureAuthoringTool/feature/MAT-7238-str…
Browse files Browse the repository at this point in the history
…atification-bugs

MAT-7238: refactor how stratification worksheets are created and adde…
  • Loading branch information
nmorasb authored May 24, 2024
2 parents 6b76ec9 + 2b6d0cf commit ea9eed9
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/services/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
TestCaseExcelExportDto,
PopulationDto,
StratificationDto,
GroupedStratificationDto,
} from '@madie/madie-models';

@Injectable()
Expand All @@ -42,22 +41,36 @@ export class ExportService {
index += 1;
});

// collect all the distinct stratifications by stratification name
const stratNames = new Set<string>();
const stratNamesToGroup = {};
testCaseExcelExportDtos.forEach((testCaseExcelExportDto) => {
testCaseExcelExportDto.testCaseExecutionResults.forEach((result) => {
result.stratifications?.forEach((stratification) => {
const stratificationWorksheet = workbook.addWorksheet(
`${index} - ${stratification.stratName}`,
);
this.generateStratificationWorksheet(
stratificationWorksheet,
testCaseExcelExportDto,
stratification,
);
index += 1;
stratNames.add(stratification.stratName);
stratNamesToGroup[stratification.stratName] =
testCaseExcelExportDto.groupId;
});
});
});

// create a worksheet for each stratification
for (const stratName of stratNames) {
const groupId = stratNamesToGroup[stratName];
const stratificationWorksheet = workbook.addWorksheet(
`${index} - ${stratName}`,
);
const testCaseExcelExportDto = testCaseExcelExportDtos.find(
(dto) => dto.groupId === groupId,
);
this.generateStratificationWorksheet(
stratificationWorksheet,
stratName,
testCaseExcelExportDto,
);
index++;
}

// Return final workbook
return workbook.xlsx.writeBuffer() as Promise<Buffer>;
}
Expand Down Expand Up @@ -350,8 +363,8 @@ export class ExportService {

public generateStratificationWorksheet(
worksheet: ExcelJS.Worksheet,
stratName: string,
testCaseGroupDto: TestCaseExcelExportDto,
groupedStratificationDto: GroupedStratificationDto,
) {
let firstRow = [];
let headerRow = [];
Expand All @@ -366,6 +379,15 @@ export class ExportService {
const firstRowData = [];
const headerRowData = [];
const testCaseData = [];
const groupedStratificationDto = result.stratifications?.find(
(s) => s.stratName === stratName,
);
if (
undefined === groupedStratificationDto ||
null === groupedStratificationDto
) {
return;
}

const numValues: number =
groupedStratificationDto.stratificationDtos?.length;
Expand Down

0 comments on commit ea9eed9

Please sign in to comment.