Skip to content

Commit

Permalink
Merge branch 'main' into 123-update-dependencies-for-data-servingdata…
Browse files Browse the repository at this point in the history
…-service
  • Loading branch information
stanislaw-zakrzewski committed Jan 14, 2025
2 parents 7b76a4e + 4fb80a3 commit 861082a
Show file tree
Hide file tree
Showing 43 changed files with 780 additions and 409 deletions.
33 changes: 13 additions & 20 deletions data-serving/data-service/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ paths:
$ref: '#/components/responses/500'
components:
schemas:
YesNo:
type: string
enum: ['Y', 'N', '']
BatchUpdateResponse:
description: Response to batch update cases API requests
properties:
Expand Down Expand Up @@ -766,8 +769,7 @@ components:
occupation:
type: string
healthcareWorker:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
location:
$ref: '#/components/schemas/Location'
events:
Expand All @@ -788,8 +790,7 @@ components:
dateOfFirstConsult:
$ref: '#/components/schemas/Date'
hospitalized:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
reasonForHospitalization:
type: string
enum: [monitoring, treatment, unknown]
Expand All @@ -798,18 +799,15 @@ components:
dateDischargeHospital:
$ref: '#/components/schemas/Date'
intensiveCare:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
dateAdmissionICU:
$ref: '#/components/schemas/Date'
dateDischargeICU:
$ref: '#/components/schemas/Date'
homeMonitoring:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
isolated:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
dateIsolation:
$ref: '#/components/schemas/Date'
outcome:
Expand All @@ -825,21 +823,18 @@ components:
type: object
properties:
previousInfection:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
coInfection:
type: string
preexistingCondition:
type: string
pregnancyStatus:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
transmission:
type: object
properties:
contactWithCase:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
contactId:
type: string
contactSetting:
Expand All @@ -854,8 +849,7 @@ components:
type: object
properties:
travelHistory:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
travelHistoryEntry:
$ref: '#/components/schemas/Date'
travelHistoryStart:
Expand All @@ -875,8 +869,7 @@ components:
type: object
properties:
vaccination:
type: string
enum: ['Y', 'N', 'NA']
$ref: '#/components/schemas/YesNo'
vaccineName:
type: string
vaccineDate:
Expand Down
15 changes: 15 additions & 0 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ export class CasesController {
header: false,
columns: this.csvHeaders,
delimiter: delimiter,
cast: {
date: (value: Date) => {
if (value) {
return new Date(value).toISOString().split('T')[0];
}
return value;
},
}
});
res.write(stringifiedCase);
doc = await cursor.next();
Expand Down Expand Up @@ -798,6 +806,13 @@ export class CasesController {
res.status(201).json(result);
} catch (e) {
const err = e as Error;
if (err.name === 'MongoServerError') {
logger.error((e as any).errInfo);
res.status(422).json({
message: (err as any).errInfo,
});
return;
}
if (err instanceof GeocodeNotFoundError) {
res.status(404).json({
message: err.message,
Expand Down
2 changes: 1 addition & 1 deletion data-serving/data-service/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export enum CaseStatus {
export enum YesNo {
Y = 'Y',
N = 'N',
NA = 'NA',
None = '',
}

export enum Role {
Expand Down
65 changes: 39 additions & 26 deletions data-serving/data-service/src/util/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export const removeBlankHeader = (headers: string[]): string[] => {
return headers;
};

export const formatDateWithoutTime = (date: Date | undefined): string => {
if (!date) return '';
return date.toISOString().split('T')[0];
};

export const denormalizeFields = async (
doc: CaseDocument,
): Promise<Partial<CaseDocument>> => {
Expand Down Expand Up @@ -178,9 +183,8 @@ function denormalizeCaseReferenceFields(
additionalSources.push(source.sourceUrl);
}
}
denormalizedData[
'caseReference.additionalSources'
] = additionalSources.join(',');
denormalizedData['caseReference.additionalSources'] =
additionalSources.join(',');
denormalizedData['caseReference.sourceEntryId'] = doc.sourceEntryId || '';
denormalizedData['caseReference.sourceId'] = doc.sourceId || '';
denormalizedData['caseReference.sourceUrl'] = doc.sourceUrl || '';
Expand Down Expand Up @@ -211,38 +215,46 @@ export const denormalizeEventsFields = (
const denormalizedData: Record<string, string> = {};

denormalizedData['events.dateEntry'] = doc.dateEntry
? doc.dateEntry.toDateString()
? formatDateWithoutTime(doc.dateEntry)
: undefined || '';
denormalizedData['events.dateReported'] = doc.dateReported
? doc.dateReported.toDateString()
? formatDateWithoutTime(doc.dateReported)
: undefined || '';
denormalizedData['events.dateOnset'] = doc.dateOnset?.toDateString() || '';
denormalizedData['events.dateConfirmation'] =
doc.dateConfirmation?.toDateString() || '';
denormalizedData['events.dateOnset'] = formatDateWithoutTime(doc.dateOnset);
denormalizedData['events.dateConfirmation'] = formatDateWithoutTime(
doc.dateConfirmation,
);
denormalizedData['events.confirmationMethod'] =
doc.confirmationMethod || '';
denormalizedData['events.dateOfFirstConsult'] =
doc.dateOfFirstConsult?.toDateString() || '';
denormalizedData['events.dateOfFirstConsult'] = formatDateWithoutTime(
doc.dateOfFirstConsult,
);
denormalizedData['events.hospitalized'] = doc.hospitalized || '';
denormalizedData['events.reasonForHospitalization'] =
doc.reasonForHospitalization || '';
denormalizedData['events.dateHospitalization'] =
doc.dateHospitalization?.toDateString() || '';
denormalizedData['events.dateDischargeHospital'] =
doc.dateDischargeHospital?.toDateString() || '';
denormalizedData['events.dateHospitalization'] = formatDateWithoutTime(
doc.dateHospitalization,
);
denormalizedData['events.dateDischargeHospital'] = formatDateWithoutTime(
doc.dateDischargeHospital,
);
denormalizedData['events.intensiveCare'] = doc.intensiveCare || '';
denormalizedData['events.dateAdmissionICU'] =
doc.dateAdmissionICU?.toDateString() || '';
denormalizedData['events.dateDischargeICU'] =
doc.dateDischargeICU?.toDateString() || '';
denormalizedData['events.dateAdmissionICU'] = formatDateWithoutTime(
doc.dateAdmissionICU,
);
denormalizedData['events.dateDischargeICU'] = formatDateWithoutTime(
doc.dateDischargeICU,
);
denormalizedData['events.homeMonitoring'] = doc.homeMonitoring || '';
denormalizedData['events.isolated'] = doc.isolated || '';
denormalizedData['events.dateIsolation'] =
doc.dateIsolation?.toDateString() || '';
denormalizedData['events.dateIsolation'] = formatDateWithoutTime(
doc.dateIsolation,
);
denormalizedData['events.outcome'] = doc.outcome || '';
denormalizedData['events.dateDeath'] = doc.dateDeath?.toDateString() || '';
denormalizedData['events.dateRecovered'] =
doc.dateRecovered?.toDateString() || '';
denormalizedData['events.dateDeath'] = formatDateWithoutTime(doc.dateDeath);
denormalizedData['events.dateRecovered'] = formatDateWithoutTime(
doc.dateRecovered,
);

return denormalizedData;
};
Expand Down Expand Up @@ -334,7 +346,7 @@ function denormalizeTravelHistoryFields(

denormalizedData['travelHistory.travelHistory'] = doc?.travelHistory || '';
denormalizedData['travelHistory.travelHistoryEntry'] =
doc?.travelHistoryEntry?.toDateString() || '';
formatDateWithoutTime(doc?.travelHistoryEntry);
denormalizedData['travelHistory.travelHistoryStart'] =
doc?.travelHistoryStart || '';
denormalizedData['travelHistory.travelHistoryLocation'] =
Expand All @@ -352,8 +364,9 @@ function denormalizeVaccineFields(

denormalizedData['vaccination.vaccination'] = doc?.vaccination || '';
denormalizedData['vaccination.vaccineName'] = doc?.vaccineName || '';
denormalizedData['vaccination.vaccineDate'] =
doc?.vaccineDate?.toDateString() || '';
denormalizedData['vaccination.vaccineDate'] = formatDateWithoutTime(
doc?.vaccineDate,
);
denormalizedData['vaccination.vaccineSideEffects'] =
doc?.vaccineSideEffects || '';

Expand Down
Loading

0 comments on commit 861082a

Please sign in to comment.