Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
fix: remove filtered responses from total count (#63)
Browse files Browse the repository at this point in the history
* fix: remove filtered responses from total count

* fix linting issue

* fix NaN tests.

* adjust tests to test for totals and properly filter NaN totals
  • Loading branch information
ssvegaraju authored Sep 13, 2021
1 parent ae9bf78 commit 82b6ff3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/smartHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ describe('authorizeAndFilterReadResponse', () => {
lastUpdated: '2020-11-20T11:10:48.034+00:00',
},
type: 'searchset',
total: 0,
link: [
{
relation: 'self',
Expand All @@ -749,6 +750,7 @@ describe('authorizeAndFilterReadResponse', () => {
const searchAllEntitiesMatch = {
...emptySearchResult,
entry: [createEntry(validPatient), createEntry(validPatientObservation), createEntry(validPatientEncounter)],
total: 3,
};

const searchSomeEntitiesMatch = {
Expand All @@ -760,13 +762,15 @@ describe('authorizeAndFilterReadResponse', () => {
createEntry({ ...validPatientObservation, subject: 'not-you' }),
createEntry(validPatientEncounter),
],
total: 5,
};
const searchNoEntitiesMatch = {
...emptySearchResult,
entry: [
createEntry({ ...validPatient, id: 'not-yours' }),
createEntry({ ...validPatientObservation, subject: 'not-you' }),
],
total: 2,
};
const cases: (string | ReadResponseAuthorizedRequest | boolean | any)[][] = [
[
Expand Down Expand Up @@ -998,7 +1002,7 @@ describe('authorizeAndFilterReadResponse', () => {
readResponse: searchAllEntitiesMatch,
},
true,
{ ...emptySearchResult, entry: [createEntry(validPatientEncounter)] },
{ ...emptySearchResult, entry: [createEntry(validPatientEncounter)], total: 1 },
],
[
'SEARCH: user scope; Practitioner able to search and get ALL results',
Expand Down
10 changes: 8 additions & 2 deletions src/smartHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class SMARTHandler implements Authorization {
const { operation, readResponse } = request;
// If request is a search treat the readResponse as a bundle
if (SEARCH_OPERATIONS.includes(operation)) {
const entries = (readResponse.entry ?? []).filter((entry: { resource: any }) =>
const entries: any[] = (readResponse.entry ?? []).filter((entry: { resource: any }) =>
hasAccessToResource(
fhirUserObject,
patientLaunchContext,
Expand All @@ -329,7 +329,13 @@ export class SMARTHandler implements Authorization {
this.fhirVersion,
),
);
return { ...readResponse, entry: entries };
let numTotal: number = readResponse.total;
if (!numTotal) {
numTotal = entries.length;
} else {
numTotal -= readResponse.entry.length - entries.length;
}
return { ...readResponse, entry: entries, total: numTotal };
}
// If request is != search treat the readResponse as just a resource
if (
Expand Down

0 comments on commit 82b6ff3

Please sign in to comment.