Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sources from schema and consolidate its URL field into caseReference #372

Merged
merged 9 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data-serving/data-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dotenv": "^8.2.0",
"envalid": "^6.0.2",
"express": "^4.17.1",
"express-openapi-validator": "^3.16.2",
"express-openapi-validator": "^3.16.4",
"express-validator": "^6.6.0",
"mongodb": "^3.5.9",
"mongoose": "^5.9.20",
Expand Down
2 changes: 1 addition & 1 deletion data-serving/data-service/schemas/cases.index.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"location.place": "text",
"location.name": "text",
"pathogen.name": "text",
"sources.url": "text"
"caseReference.sourceUrl": "text"
}
43 changes: 20 additions & 23 deletions data-serving/data-service/schemas/cases.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,26 @@
},
"sourceEntryId": {
"bsonType": "string"
}
},
"sourceUrl": {
"bsonType": "string"
},
"additionalSources": {
"bsonType": "array",
"uniqueItems": true,
"items": {
"bsonType": "object",
"additionalProperties": false,
"properties": {
"_id": {
"bsonType": "objectId"
},
"sourceUrl": {
"bsonType": "string"
}
}
}
}
}
},
"demographics": {
Expand Down Expand Up @@ -360,28 +379,6 @@
}
}
},
"sources": {
"bsonType": "array",
"uniqueItems": true,
"items": {
"bsonType": "object",
"additionalProperties": false,
"properties": {
"_id": {
"bsonType": "objectId"
},
"id": {
"bsonType": "string"
},
"url": {
"bsonType": "string"
},
"other": {
"bsonType": "string"
}
}
}
},
"pathogens": {
"bsonType": "array",
"uniqueItems": true,
Expand Down
21 changes: 21 additions & 0 deletions data-serving/data-service/src/model/case-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,30 @@ export const caseReferenceSchema = new mongoose.Schema({
required: true,
},
sourceEntryId: String,
sourceUrl: {
type: String,
required: true,
},
additionalSources: [
{
sourceUrl: String,
},
],
});

export type CaseReferenceDocument = mongoose.Document & {
/** Foreign key to the sources collection. */
sourceId: string;

/** The original id of the case in the source. */
sourceEntryId: string;

/** The URL of the source of the case data at the time of ingestion. */
sourceUrl: string;

additionalSources: [
{
sourceUrl: string;
},
];
};
17 changes: 5 additions & 12 deletions data-serving/data-service/src/model/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
RevisionMetadataDocument,
revisionMetadataSchema,
} from './revision-metadata';
import { SourceDocument, sourceSchema } from './source';
import { TransmissionDocument, transmissionSchema } from './transmission';
import { TravelHistoryDocument, travelHistorySchema } from './travel-history';

Expand All @@ -21,7 +20,10 @@ import mongoose from 'mongoose';

const caseSchema = new mongoose.Schema(
{
caseReference: caseReferenceSchema,
caseReference: {
type: caseReferenceSchema,
required: true,
},
demographics: demographicsSchema,
events: {
type: [eventSchema],
Expand All @@ -37,19 +39,11 @@ const caseSchema = new mongoose.Schema(
location: locationSchema,
revisionMetadata: {
type: revisionMetadataSchema,
required: 'Must include revision metadata',
required: true,
},
notes: String,
pathogens: [pathogenSchema],
preexistingConditions: dictionarySchema,
sources: {
type: [sourceSchema],
required: true,
validate: {
validator: (sources: [SourceDocument]) => sources.length > 0,
message: 'Must include one or more sources',
},
},
symptoms: dictionarySchema,
transmission: transmissionSchema,
travelHistory: travelHistorySchema,
Expand Down Expand Up @@ -82,7 +76,6 @@ type CaseDocument = mongoose.Document & {
notes: string;
pathogens: [PathogenDocument];
preexistingConditions: DictionaryDocument;
sources: [SourceDocument];
symptoms: DictionaryDocument;
transmission: TransmissionDocument;
travelHistory: TravelHistoryDocument;
Expand Down
2 changes: 0 additions & 2 deletions data-serving/data-service/src/model/pathogen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { SourceDocument, sourceSchema } from './source';

import mongoose from 'mongoose';
import { positiveIntFieldInfo } from './positive-int';

Expand Down
34 changes: 0 additions & 34 deletions data-serving/data-service/src/model/source.ts

This file was deleted.

12 changes: 10 additions & 2 deletions data-serving/data-service/test/controllers/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ describe('PUT', () => {
const res = await request(app)
.put('/api/cases')
.send({
caseReference: { sourceId: sourceId, sourceEntryId: entryId },
caseReference: {
sourceId: sourceId,
sourceEntryId: entryId,
sourceUrl: 'cdc.gov',
},
notes: newNotes,
})
.expect('Content-Type', /json/)
Expand Down Expand Up @@ -197,7 +201,11 @@ describe('PUT', () => {
return request(app)
.put('/api/cases')
.send({
caseReference: { sourceId: sourceId, sourceEntryId: entryId },
caseReference: {
sourceId: sourceId,
sourceEntryId: entryId,
sourceUrl: 'cdc.gov',
},
location: {},
})
.expect(422);
Expand Down
10 changes: 10 additions & 0 deletions data-serving/data-service/test/model/case-reference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ describe('validate', () => {
expect(e.name).toBe(Error.ValidationError.name);
});
});

it('a caseReference document without sourceUrl is invalid', async () => {
const missingSourceUrl = { ...minimalModel };
delete missingSourceUrl.sourceUrl;

return new CaseReference(missingSourceUrl).validate((e) => {
expect(e.name).toBe(Error.ValidationError.name);
});
});

it('a minimal caseReference document is valid', async () => {
return new CaseReference(minimalModel).validate();
});
Expand Down
13 changes: 8 additions & 5 deletions data-serving/data-service/test/model/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import minimalEvent from './data/event.minimal.json';
import minimalModel from './data/case.minimal.json';

describe('validate', () => {
it('model without sources is invalid', async () => {
return new Case({ ...minimalModel, sources: [] }).validate((e) => {
it('model without caseReference is invalid', async () => {
const noCaseReference = { ...minimalModel };
delete noCaseReference.caseReference;

return new Case({ ...noCaseReference }).validate((e) => {
expect(e.name).toBe(Error.ValidationError.name);
});
});
Expand All @@ -28,10 +31,10 @@ describe('validate', () => {
});

it('model without revision metadata is invalid', async () => {
const noRevisionmetadata = { ...minimalModel };
delete noRevisionmetadata.revisionMetadata;
const noRevisionMetadata = { ...minimalModel };
delete noRevisionMetadata.revisionMetadata;

return new Case(noRevisionmetadata).validate((e) => {
return new Case(noRevisionMetadata).validate((e) => {
expect(e.name).toBe(Error.ValidationError.name);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"sourceId": "sourceId",
"sourceEntryId": "entryId"
"sourceEntryId": "entryId",
"sourceUrl": "cdc.gov",
"additionalSources": [
{
"sourceUrl": "twitter.com/a-tweet"
},
{
"sourceUrl": "news.org/an-article"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"sourceId": "sourceId"
"sourceId": "sourceId",
"sourceUrl": "cdc.gov"
}
11 changes: 10 additions & 1 deletion data-serving/data-service/test/model/data/case.full.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"caseReference": {
"sourceId": "sourceId",
"sourceEntryId": "entryId"
"sourceEntryId": "entryId",
"sourceUrl": "cdc.gov",
"additionalSources": [
{
"sourceUrl": "twitter.com/a-tweet"
},
{
"sourceUrl": "news.org/an-article"
}
]
},
"demographics": {
"ageRange": {
Expand Down
17 changes: 8 additions & 9 deletions data-serving/data-service/test/model/data/case.minimal.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"caseReference": {
"sourceId": "sourceId",
"sourceUrl": "cdc.gov"
},
"events": [
{
"name": "confirmed",
Expand All @@ -8,20 +12,15 @@
}
}
],
"sources": [
{
"url": "cdc.gov"
}
],
"location": {
"country": "China",
"geoResolution": "Country"
},
"revisionMetadata": {
"revisionNumber": 0,
"creationMetadata": {
"curator": "abc123",
"date": "2020-01-03"
}
},
"location": {
"country": "China",
"geoResolution": "Country"
}
}
5 changes: 0 additions & 5 deletions data-serving/data-service/test/model/data/source.full.json

This file was deleted.

3 changes: 0 additions & 3 deletions data-serving/data-service/test/model/data/source.minimal.json

This file was deleted.

43 changes: 0 additions & 43 deletions data-serving/data-service/test/model/source.test.ts

This file was deleted.

Loading