This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint for fetching aggregated data
- Loading branch information
Showing
9 changed files
with
248 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import express from 'express'; | ||
|
||
import { CovidReportRepository } from '../repository/CovidReportRepository'; | ||
import { aggregateCovidReports } from '../util/report-aggregator'; | ||
|
||
const router = express.Router(); | ||
const reportRepo = new CovidReportRepository(); | ||
|
||
router.get('/aggregated', async (req, res) => { | ||
const reports = await reportRepo.getLatestCovidReports(); | ||
const aggregated = aggregateCovidReports(reports); | ||
res.send(aggregated); | ||
}); | ||
|
||
router.get('/', (req, res) => { | ||
return res.render('pages/map'); | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { aggregateCovidReports } from './report-aggregator'; | ||
import { | ||
CovidReport, | ||
Sex, | ||
TestResult, | ||
Symptom, | ||
AggregatedCovidReportData | ||
} from '../domain/types'; | ||
|
||
const reports: CovidReport[] = [ | ||
{ | ||
yearOfBirth: '1993', // Deprecated | ||
sex: Sex.MALE, | ||
postalCode: '1234', | ||
hasBeenTested: false, | ||
testedAt: new Date(), // Not in use | ||
symptomStart: '2020-03-02', // YYYY-MM-DD | ||
testResult: TestResult.POSITIVE, | ||
inQuarantine: true, | ||
hasBeenAbroadLastTwoWeeks: true, | ||
symptoms: { | ||
[Symptom.DRY_COUGH]: true, | ||
[Symptom.EXHAUSTION]: false, | ||
[Symptom.FEVER]: false, | ||
[Symptom.HEAVY_BREATHING]: false, | ||
[Symptom.MUSCLE_ACHING]: false, | ||
[Symptom.DIARRHEA]: false, | ||
[Symptom.HEADACHE]: false, | ||
[Symptom.SORE_THROAT]: false | ||
}, | ||
submissionTimestamp: 123123123, | ||
age: '50' | ||
}, | ||
{ | ||
yearOfBirth: '1993', // Deprecated | ||
sex: Sex.MALE, | ||
postalCode: '1234', | ||
hasBeenTested: false, | ||
testedAt: new Date(), // YYYY-MM-DD | ||
symptomStart: '2020-03-02', // YYYY-MM-DD | ||
testResult: undefined, | ||
inQuarantine: false, | ||
hasBeenAbroadLastTwoWeeks: false, | ||
symptoms: { | ||
[Symptom.DRY_COUGH]: true, | ||
[Symptom.EXHAUSTION]: true, | ||
[Symptom.FEVER]: true, | ||
[Symptom.HEAVY_BREATHING]: false, | ||
[Symptom.MUSCLE_ACHING]: false, | ||
[Symptom.DIARRHEA]: false, | ||
[Symptom.HEADACHE]: false, | ||
[Symptom.SORE_THROAT]: false | ||
}, | ||
submissionTimestamp: 123123123, | ||
age: '50' | ||
}, | ||
{ | ||
yearOfBirth: '1993', // Deprecated | ||
sex: Sex.MALE, | ||
postalCode: '1234', | ||
hasBeenTested: false, | ||
testedAt: new Date(), // YYYY-MM-DD | ||
symptomStart: '2020-03-02', // YYYY-MM-DD | ||
testResult: TestResult.PENDING, | ||
inQuarantine: false, | ||
hasBeenAbroadLastTwoWeeks: false, | ||
symptoms: { | ||
[Symptom.DRY_COUGH]: false, | ||
[Symptom.EXHAUSTION]: false, | ||
[Symptom.FEVER]: false, | ||
[Symptom.HEAVY_BREATHING]: false, | ||
[Symptom.MUSCLE_ACHING]: false, | ||
[Symptom.DIARRHEA]: false, | ||
[Symptom.HEADACHE]: false, | ||
[Symptom.SORE_THROAT]: false | ||
}, | ||
submissionTimestamp: 123123123, | ||
age: '50' | ||
}, | ||
{ | ||
yearOfBirth: '1993', // Deprecated | ||
sex: Sex.MALE, | ||
postalCode: '1234', | ||
hasBeenTested: false, | ||
testedAt: new Date(), // YYYY-MM-DD | ||
symptomStart: '2020-03-02', // YYYY-MM-DD | ||
testResult: TestResult.NEGATIVE, | ||
inQuarantine: false, | ||
hasBeenAbroadLastTwoWeeks: false, | ||
symptoms: { | ||
[Symptom.DRY_COUGH]: true, | ||
[Symptom.EXHAUSTION]: false, | ||
[Symptom.FEVER]: false, | ||
[Symptom.HEAVY_BREATHING]: false, | ||
[Symptom.MUSCLE_ACHING]: false, | ||
[Symptom.DIARRHEA]: false, | ||
[Symptom.HEADACHE]: false, | ||
[Symptom.SORE_THROAT]: false | ||
}, | ||
submissionTimestamp: 123123123, | ||
age: '50' | ||
} | ||
]; | ||
|
||
it('should count all correctly', () => { | ||
const aggregated: AggregatedCovidReportData = aggregateCovidReports(reports); | ||
|
||
expect(aggregated.numberOfReports).toBe(4); | ||
expect(aggregated.numberOfPeopleShowingSymptoms).toBe(3); | ||
expect(aggregated.numberOfConfirmedInfected).toBe(1); | ||
expect(aggregated.numberOfTested).toBe(3); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
CovidReport, | ||
AggregatedCovidReportData, | ||
TestResult | ||
} from '../domain/types'; | ||
|
||
const isShowingAtLeastOneSymptom = (report: CovidReport): boolean => { | ||
return Object.values(report.symptoms).filter(value => !!value).length > 0; | ||
}; | ||
|
||
export const aggregateCovidReports = ( | ||
reports: CovidReport[] | ||
): AggregatedCovidReportData => { | ||
const aggredatedData: AggregatedCovidReportData = { | ||
numberOfReports: 0, | ||
numberOfPeopleShowingSymptoms: 0, | ||
numberOfConfirmedInfected: 0, | ||
numberOfTested: 0 | ||
}; | ||
for (const report of reports) { | ||
aggredatedData.numberOfReports += 1; | ||
if (isShowingAtLeastOneSymptom(report)) { | ||
aggredatedData.numberOfPeopleShowingSymptoms += 1; | ||
} | ||
if (report.testResult) { | ||
aggredatedData.numberOfTested += 1; | ||
} | ||
if (report.testResult === TestResult.POSITIVE) { | ||
aggredatedData.numberOfConfirmedInfected += 1; | ||
} | ||
} | ||
return aggredatedData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
preset: 'ts-jest' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.