Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
add data from newly added questions to API-responses and CSV-export, f…
Browse files Browse the repository at this point in the history
…ixes #254
  • Loading branch information
fossecode committed Mar 23, 2020
1 parent 4ce4f17 commit b549e6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions app/routes/api-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
TestResult,
Symptoms,
CovidReport,
Symptom
Symptom,
SmokingHabit,
IsolationStatus
} from '../domain/types';

const router = express.Router();
Expand Down Expand Up @@ -52,11 +54,15 @@ interface ExposedCovidReport {
symptoms: Symptoms;
submissionDate: string; // YYYY-MM-DD
age: string;
bodyTemperature?: string;
smokingHabit?: SmokingHabit;
isolationStatus?: IsolationStatus;
diagnosedWithOtherConditions?: boolean;
}

type ZeroOrOne = 0 | 1;

const toZeroOrOne = (bool: boolean): ZeroOrOne => (bool ? 1 : 0);
const toZeroOrOne = (bool?: boolean): ZeroOrOne => (bool ? 1 : 0);

interface ExposedCovidReportCSV extends Record<Symptom, ZeroOrOne> {
profileId: number;
Expand All @@ -68,6 +74,10 @@ interface ExposedCovidReportCSV extends Record<Symptom, ZeroOrOne> {
testResult?: TestResult;
symptomStart?: string; // YYYY-MM-DD
submissionDate: string;
bodyTemperature?: string;
smokingHabit?: SmokingHabit;
isolationStatus?: IsolationStatus;
diagnosedWithOtherConditions?: ZeroOrOne;
}

const toISODate = (submissionTimestamp: number): string =>
Expand All @@ -82,7 +92,11 @@ const reportToExposedFormat = (report: CovidReport): ExposedCovidReport => ({
symptomStart: report.symptomStart,
testResult: report.testResult,
symptoms: report.symptoms,
submissionDate: toISODate(report.submissionTimestamp)
submissionDate: toISODate(report.submissionTimestamp),
bodyTemperature: report.bodyTemperature,
smokingHabit: report.smokingHabit,
isolationStatus: report.isolationStatus,
diagnosedWithOtherConditions: report.diagnosedWithOtherConditions
});

const extractSymptomsAsZeroOrOne = (
Expand Down Expand Up @@ -119,6 +133,12 @@ const reportToExposedCsvFormat = (
symptomStart: report.symptomStart,
testResult: report.testResult,
submissionDate: toISODate(report.submissionTimestamp),
bodyTemperature: report.bodyTemperature,
smokingHabit: report.smokingHabit,
isolationStatus: report.isolationStatus,
diagnosedWithOtherConditions: toZeroOrOne(
report.diagnosedWithOtherConditions
),
...extractSymptomsAsZeroOrOne(report.symptoms)
});

Expand Down
2 changes: 1 addition & 1 deletion app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ app.set('views', [

app.use(urls.submitReport, reportRoutes);
app.use(urls.map, mapRoutes);
app.use(urls.map, apiRoutes);
app.use(urls.api, apiRoutes);
app.use(urls.statistics, statisticsRoutes);
app.use('/', variousRoutes);

Expand Down

0 comments on commit b549e6e

Please sign in to comment.