Skip to content

Commit

Permalink
update key and use map instead of object
Browse files Browse the repository at this point in the history
  • Loading branch information
BobanL committed Nov 21, 2024
1 parent 2eb853b commit e8a608c
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions containers/ecr-viewer/src/app/view-data/utils/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
UserInvocationTable,
} from "fhirpath";

let evaluateCache: { [key: string]: any } = {};
let evaluateCache: Map<string, any> = new Map();

/**
* Evaluates a FHIRPath expression on the provided FHIR data.
Expand All @@ -31,30 +31,26 @@ export const evaluate = (
userInvocationTable?: UserInvocationTable;
},
): any[] => {
// In case a resource does not have an ID fall back to entire object
const key =
(fhirData?.resourceType === "Bundle"
? "bundle"
: (fhirData?.id ?? JSON.stringify(fhirData))) +
(fhirData?.id ?? JSON.stringify(fhirData)) +
",,,,," +
JSON.stringify(context) +
",,,,," +
JSON.stringify(path);
if (evaluateCache.hasOwnProperty(key)) {
return evaluateCache[key];
if (evaluateCache.has(key)) {
return evaluateCache.get(key);
}
evaluateCache[key] = fhirPathEvaluate(
fhirData,
path,
context,
model,
options,
evaluateCache.set(
key,
fhirPathEvaluate(fhirData, path, context, model, options),
);
return evaluateCache[key];
return evaluateCache.get(key);
};

/**
* Reset the evaluate cache map
*/
export const clearEvaluateCache = () => {
evaluateCache = {};
evaluateCache.clear();
};

0 comments on commit e8a608c

Please sign in to comment.