Skip to content

Commit

Permalink
bundle transaction checks and capability statement
Browse files Browse the repository at this point in the history
  • Loading branch information
lmd59 committed Jun 13, 2024
1 parent a154fef commit d4a55ee
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
20 changes: 20 additions & 0 deletions service/src/config/capabilityStatementResources.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
],
"code": "update",
"documentation": "Update allows authoring workflows to update existing libraries in _draft_ (**revise**) status, add comments to existing libraries (**review** and **approve**), and **release** or **retire** a library."
},
{
"extension" : [
{
"url" : "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation",
"valueCode" : "SHALL"
}
],
"code" : "delete",
"documentation" : "Delete allows authoring workflows to **withdraw** _draft_ libraries or **archive** _retired_ libraries."
}
],
"searchParam": [
Expand Down Expand Up @@ -207,6 +217,16 @@
],
"code": "update",
"documentation": "Update allows authoring workflows to update existing measures in _draft_ (**revise**) status, add comments to existing measures (**review** and **approve**), and **release** or **retire** a measure."
},
{
"extension" : [
{
"url" : "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation",
"valueCode" : "SHALL"
}
],
"code" : "delete",
"documentation" : "Delete allows authoring workflows to **withdraw** _draft_ measures or **archive** _retired_ measures."
}
],
"searchParam": [
Expand Down
30 changes: 13 additions & 17 deletions service/src/services/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { loggers, constants, resolveSchema } from '@projecttacoma/node-fhir-server-core';
import { BadRequestError } from '../util/errorUtils';
import { checkContentTypeHeader } from '../util/inputUtils';
import { checkContentTypeHeader, checkFieldsForCreate, checkFieldsForUpdate } from '../util/inputUtils';
import { v4 as uuidv4 } from 'uuid';
import { createResource, updateResource } from '../db/dbOperations';
import { createResource, findResourceById, updateResource } from '../db/dbOperations';
import path from 'path';
import { DetailedEntry, addIsOwnedExtension, addLibraryIsOwned, replaceReferences } from '../util/baseUtils';

Expand Down Expand Up @@ -73,23 +73,10 @@ async function uploadResourcesFromBundle(entries: DetailedEntry[]) {
* Inserts Library or Measure resources from Bundle into the database through create or update.
*/
async function insertBundleResources(entry: DetailedEntry) {
// TODO: make updates here for AUHTHORING/PUBLISHABLE
if (entry.resource?.resourceType === 'Library' || entry.resource?.resourceType === 'Measure') {
if (entry.resource.status != 'active') {
entry.resource.status = 'active';
entry.outcome = {
resourceType: 'OperationOutcome',
issue: [
{
severity: 'warning',
code: 'value', // code from: https://build.fhir.org/valueset-issue-type.html
details: { text: 'Artifact status has been coerced to active to meet server specifications' },
expression: [`${entry.resource.resourceType}.status`]
}
]
};
}

if (entry.isPost) {
checkFieldsForCreate(entry.resource);
entry.resource.id = uuidv4();
const { id } = await createResource(entry.resource, entry.resource.resourceType);
if (id != null) {
Expand All @@ -98,6 +85,15 @@ async function insertBundleResources(entry: DetailedEntry) {
}
} else {
if (entry.resource.id) {
const oldResource = (await findResourceById(
entry.resource.id,
entry.resource.resourceType
)) as fhir4.Library | null;
if (oldResource) {
checkFieldsForUpdate(entry.resource, oldResource);
} else {
checkFieldsForCreate(entry.resource);
}
const { id, created } = await updateResource(entry.resource.id, entry.resource, entry.resource.resourceType);
if (created === true) {
entry.status = 201;
Expand Down
2 changes: 1 addition & 1 deletion service/src/services/LibraryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class LibraryService implements Service<fhir4.Library> {
* result of sending a DELETE request to {BASE_URL}/4_0_1/Library/{id}
* deletes the library with the passed in id if it exists in the database
*/
async remove(args: RequestArgs, { req }: RequestCtx) {
async remove(args: RequestArgs) {
const resource = (await findResourceById(args.id, 'Library')) as fhir4.Library | null;
if (!resource) {
throw new ResourceNotFoundError(`Existing resource not found with id ${args.id}`);
Expand Down
2 changes: 1 addition & 1 deletion service/src/services/MeasureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class MeasureService implements Service<fhir4.Measure> {
* result of sending a DELETE request to {BASE_URL}/4_0_1/Library/{id}
* deletes the library with the passed in id if it exists in the database
*/
async remove(args: RequestArgs, { req }: RequestCtx) {
async remove(args: RequestArgs) {
const resource = (await findResourceById(args.id, 'Measure')) as fhir4.Measure | null;
if (!resource) {
throw new ResourceNotFoundError(`Existing resource not found with id ${args.id}`);
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 @@ -96,7 +96,8 @@ const VALID_PUT_REQ = {
resource: {
resourceType: 'Measure',
id: 'test-measure',
library: ['Library/test-library']
library: ['Library/test-library'],
status: 'draft'
},
request: {
method: 'PUT',
Expand All @@ -113,7 +114,8 @@ const VALID_POST_REQ = {
{
resource: {
resourceType: 'Library',
id: 'test-library'
id: 'test-library',
status: 'draft'
},
request: {
method: 'POST',
Expand All @@ -126,6 +128,7 @@ const VALID_POST_REQ = {
describe('BaseService', () => {
beforeAll(async () => {
server = initialize(serverConfig, app);
process.env.AUTHORING = 'true';
return setupTestDatabase([]);
});

Expand Down

0 comments on commit d4a55ee

Please sign in to comment.