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

fix: remove filtered responses from total count #63

Merged
merged 5 commits into from
Sep 13, 2021
Merged
Changes from 2 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
7 changes: 6 additions & 1 deletion 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,6 +329,11 @@ export class SMARTHandler implements Authorization {
this.fhirVersion,
),
);
const totalNumEntriesAfterFilter: number =
rsmayda marked this conversation as resolved.
Show resolved Hide resolved
readResponse.total - (readResponse.entry.length - entries.length);
if (totalNumEntriesAfterFilter < readResponse.total) {
readResponse.total = totalNumEntriesAfterFilter;
}
ssvegaraju marked this conversation as resolved.
Show resolved Hide resolved
return { ...readResponse, entry: entries };
}
// If request is != search treat the readResponse as just a resource
Expand Down