Skip to content

Commit

Permalink
Add check fields for date (and type where applicable)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmd59 committed Oct 15, 2024
1 parent 5dd85e8 commit b307035
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
16 changes: 12 additions & 4 deletions service/src/util/inputUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ export function checkExpectedResourceType(resourceType: string, expectedResource

export function checkFieldsForCreate(resource: fhir4.Measure | fhir4.Library) {
// base shareable artifact requires url, version, title, status (required by base FHIR), description
if (!resource.url || !resource.version || !resource.title || !resource.description) {
throw new BadRequestError('Created artifacts must have url, version, title, status, and description');
// base publishable artifact requires date and type (for Library)
if (!resource.url || !resource.version || !resource.title || !resource.description || !resource.date) {
throw new BadRequestError('Created artifacts must have url, version, title, status, description, and date');
}
if (resource.resourceType === 'Library' && !resource.type) {
throw new BadRequestError('Created library artifacts must have a type');
}

if (process.env.AUTHORING === 'true') {
Expand Down Expand Up @@ -135,8 +139,12 @@ export function checkFieldsForUpdate(resource: fhir4.Measure | fhir4.Library, ol
throw new BadRequestError('Existing draft resources must stay in draft while revising.');
}
// base shareable artifact requires url, version, title, status (required by base FHIR), description
if (!resource.url || !resource.version || !resource.title || !resource.description) {
throw new BadRequestError('Artifacts must have url, version, title, status, and description');
// base publishable artifact requires date and type (for Library)
if (!resource.url || !resource.version || !resource.title || !resource.description || !resource.date) {
throw new BadRequestError('Artifacts must have url, version, title, status, description, and date');
}
if (resource.resourceType === 'Library' && !resource.type) {
throw new BadRequestError('Created library artifacts must have a type');
}
} else {
throw new BadRequestError(`Cannot update existing resource with status ${oldResource.status}`);
Expand Down
7 changes: 5 additions & 2 deletions service/test/services/BaseService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const VALID_PUT_REQ = {
url: 'http://example.com',
version: '1',
title: 'Sample title',
description: 'Sample description'
description: 'Sample description',
date: '2025-01-01T00:00:00.000Z'
},
request: {
method: 'PUT',
Expand All @@ -123,7 +124,9 @@ const VALID_POST_REQ = {
url: 'http://example.com',
version: '1',
title: 'Sample title',
description: 'Sample description'
description: 'Sample description',
date: '2025-01-01T00:00:00.000Z',
type: { coding: [{ code: 'logic-library' }] }
},
request: {
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion service/test/services/LibraryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ describe('LibraryService', () => {
title: 'updated',
url: 'http://example.com',
version: '1',
description: 'Sample description'
description: 'Sample description',
date: '2025-01-01T00:00:00.000Z'
})
.set('content-type', 'application/json+fhir')
.expect(200)
Expand Down
3 changes: 2 additions & 1 deletion service/test/services/MeasureService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ describe('MeasureService', () => {
title: 'updated',
url: 'http://example.com/exampleId',
version: '1',
description: 'Sample description'
description: 'Sample description',
date: '2025-01-01T00:00:00.000Z'
})
.set('content-type', 'application/json+fhir')
.expect(200)
Expand Down

0 comments on commit b307035

Please sign in to comment.