Skip to content

Commit

Permalink
create transaction response bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
lmd59 committed Oct 15, 2024
1 parent 9e6e8a2 commit edd45da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions service/src/services/LibraryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
createLibraryPackageBundle,
createPaginationLinks,
createSearchsetBundle,
createSummarySearchsetBundle
createSummarySearchsetBundle,
createTransactionResponseBundle
} from '../util/bundleUtils';
import { BadRequestError, ResourceNotFoundError } from '../util/errorUtils';
import { getMongoQueryFromRequest } from '../util/queryUtils';
Expand Down Expand Up @@ -231,7 +232,7 @@ export class LibraryService implements Service<CRMIShareableLibrary> {
const newDeletes = await batchDelete([library, ...children], archiveOrWithdraw);

// we want to return a Bundle containing the deleted artifacts
return createBatchResponseBundle(newDeletes);
return createTransactionResponseBundle(newDeletes);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions service/src/services/MeasureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
createPaginationLinks,
createMeasurePackageBundle,
createSearchsetBundle,
createSummarySearchsetBundle
createSummarySearchsetBundle,
createTransactionResponseBundle
} from '../util/bundleUtils';
import { BadRequestError, ResourceNotFoundError } from '../util/errorUtils';
import { getMongoQueryFromRequest } from '../util/queryUtils';
Expand Down Expand Up @@ -235,7 +236,7 @@ export class MeasureService implements Service<CRMIShareableMeasure> {
const newDeletes = await batchDelete([measure, ...children], archiveOrWithdraw);

// we want to return a Bundle containing the deleted artifacts
return createBatchResponseBundle(newDeletes);
return createTransactionResponseBundle(newDeletes);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions service/src/util/bundleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ export function createBatchResponseBundle<T extends FhirArtifact>(entries: T[]):
};
}

export function createTransactionResponseBundle<T extends FhirArtifact>(entries: T[]): fhir4.Bundle<T> {
return {
resourceType: 'Bundle',
meta: { lastUpdated: new Date().toISOString() },
id: v4(),
type: 'transaction-response',
total: entries.length,
entry: entries.map(e => ({ resource: e }))
};
}

/**
*
* Takes in a number of FHIR resources and creates a FHIR searchset Bundle without entries
Expand Down

0 comments on commit edd45da

Please sign in to comment.