Skip to content

Commit

Permalink
Bucket ages on case download #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Apr 25, 2022
1 parent 4055df0 commit aee42fd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export class CasesController {
doc = await cursor.next();
while (doc != null) {
delete doc.restrictedNotes;
const parsedCase = parseDownloadedCase(doc);
const caseDTO = await dtoFromCase(doc);
const parsedCase = parseDownloadedCase(caseDTO);
const stringifiedCase = stringify([parsedCase], {
header: false,
columns: this.csvHeaders,
Expand Down
4 changes: 2 additions & 2 deletions data-serving/data-service/src/util/case.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaseDocument } from '../model/case';
import { CaseDocument, CaseDTO } from '../model/case';
import { CaseReferenceDocument } from '../model/case-reference';
import { DemographicsDocument } from '../model/demographics';
import { EventDocument } from '../model/event';
Expand Down Expand Up @@ -59,7 +59,7 @@ export const parseCaseEvents = (
/**
* Converts case to fulfill CSV file structure requirements.
*/
export const parseDownloadedCase = (caseDocument: CaseDocument) => {
export const parseDownloadedCase = (caseDocument: CaseDTO) => {
const { demographics, symptoms } = caseDocument;

const parsedDemographics = demographics?.nationalities
Expand Down
25 changes: 25 additions & 0 deletions data-serving/data-service/test/controllers/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,31 @@ describe('POST', () => {
fs.unlinkSync(destination);
});
});
it('should use the age buckets in the download', async () => {
const destination = './test_buckets.csv';
const fileStream = fs.createWriteStream(destination);

const c = new Case(minimalCase);
await c.save();

const responseStream = request(app)
.post('/api/cases/download')
.send({ format: 'csv' })
.expect('Content-Type', 'text/csv')
.expect(200)
.parse(stringParser);

responseStream.pipe(fileStream);
responseStream.on('finish', () => {
const text: string = fs
.readFileSync(destination)
.toString('utf-8');
expect(text).toContain('35');
expect(text).toContain('50');

fs.unlinkSync(destination);
});
});
it('should exclude restricted cases', async () => {
const destination = './test_exclude_restricted_cases.csv';
const fileStream = fs.createWriteStream(destination);
Expand Down
2 changes: 1 addition & 1 deletion data-serving/data-service/test/util/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Case', () => {
demographics: {
nationalities: [],
},
} as CaseDocument);
} as CaseDTO);

expect(res.events).toEqual({
onsetSymptoms: {
Expand Down

0 comments on commit aee42fd

Please sign in to comment.