Skip to content

Commit

Permalink
Update data service
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw-zakrzewski committed Oct 31, 2024
1 parent b8688b7 commit 43b9dd7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 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
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
25 changes: 13 additions & 12 deletions data-serving/data-service/test/util/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import mongoose from 'mongoose';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { GenomeSequenceDocument } from '../../src/model/genome-sequence';
import { EventsDocument } from '../../src/model/events';
import { YesNo } from '../../src/types/enums';

let mongoServer: MongoMemoryServer;

Expand Down Expand Up @@ -364,7 +365,7 @@ describe('Case', () => {
ageBuckets: [anAgeBucket._id],
gender: 'male',
occupation: 'Anesthesiologist',
healthcareWorker: 'Y',
healthcareWorker: YesNo.Y,
} as DemographicsDocument;

const caseDoc = {
Expand All @@ -391,7 +392,7 @@ describe('Case', () => {
expect(denormalizedCase['demographics.occupation']).toEqual(
'Anesthesiologist',
);
expect(denormalizedCase['demographics.healthcareWorker']).toEqual('Y');
expect(denormalizedCase['demographics.healthcareWorker']).toEqual(YesNo.Y);
});
it('denormalizes events fields', async () => {
const eventsDoc = {
Expand Down Expand Up @@ -503,10 +504,10 @@ describe('Case', () => {
});
it('denormalizes preexisting conditions fields', async () => {
const conditionsDoc = {
previousInfection: 'Y',
previousInfection: YesNo.Y,
coInfection: 'Flu',
preexistingCondition: '',
pregnancyStatus: 'NA',
pregnancyStatus: YesNo.None,
} as PreexistingConditionsDocument;

const caseDoc = {
Expand All @@ -529,7 +530,7 @@ describe('Case', () => {
const denormalizedCase = await denormalizeFields(caseDoc);
expect(
denormalizedCase['preexistingConditions.previousInfection'],
).toEqual('Y');
).toEqual(YesNo.Y);
expect(denormalizedCase['preexistingConditions.coInfection']).toEqual(
'Flu',
);
Expand All @@ -538,11 +539,11 @@ describe('Case', () => {
).toEqual('');
expect(
denormalizedCase['preexistingConditions.pregnancyStatus'],
).toEqual('NA');
).toEqual(YesNo.None);
});
it('denormalizes transmission fields', async () => {
const transmissionDoc = {
contactWithCase: 'Y',
contactWithCase: YesNo.Y,
contactId: 'abc123',
contactSetting: 'setting',
contactAnimal: 'animal',
Expand All @@ -568,7 +569,7 @@ describe('Case', () => {

const denormalizedCase = await denormalizeFields(caseDoc);

expect(denormalizedCase['transmission.contactWithCase']).toEqual('Y');
expect(denormalizedCase['transmission.contactWithCase']).toEqual(YesNo.Y);
expect(denormalizedCase['transmission.contactId']).toEqual('abc123');
expect(denormalizedCase['transmission.contactSetting']).toEqual(
'setting',
Expand All @@ -585,7 +586,7 @@ describe('Case', () => {
});
it('denormalizes travel history fields', async () => {
const travelHistoryDoc = {
travelHistory: 'Y',
travelHistory: YesNo.Y,
travelHistoryEntry: new Date('2020-11-01'),
travelHistoryStart: 'start',
travelHistoryLocation: 'London',
Expand All @@ -610,7 +611,7 @@ describe('Case', () => {

const denormalizedCase = await denormalizeFields(caseDoc);

expect(denormalizedCase['travelHistory.travelHistory']).toEqual('Y');
expect(denormalizedCase['travelHistory.travelHistory']).toEqual(YesNo.Y);
expect(denormalizedCase['travelHistory.travelHistoryEntry']).toEqual(
travelHistoryDoc.travelHistoryEntry.toDateString(),
);
Expand All @@ -626,7 +627,7 @@ describe('Case', () => {
});
it('denormalizes vaccine fields', async () => {
const vaccinationDoc = {
vaccination: 'Y',
vaccination: YesNo.Y,
vaccineName: 'Pfizer',
vaccineDate: new Date('2020-11-01'),
vaccineSideEffects: 'cough',
Expand All @@ -649,7 +650,7 @@ describe('Case', () => {
} as CaseDocument;

const denormalizedCase = await denormalizeFields(caseDoc);
expect(denormalizedCase['vaccination.vaccination']).toEqual('Y');
expect(denormalizedCase['vaccination.vaccination']).toEqual(YesNo.Y);
expect(denormalizedCase['vaccination.vaccineName']).toEqual('Pfizer');
expect(denormalizedCase['vaccination.vaccineDate']).toEqual(
vaccinationDoc.vaccineDate.toDateString(),
Expand Down

0 comments on commit 43b9dd7

Please sign in to comment.