Skip to content

Commit

Permalink
Improve performance of combine_coding_and_quantity_values (#241)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Dubrovski <[email protected]>
  • Loading branch information
danieldubrovski and Daniel Dubrovski authored Sep 11, 2023
1 parent c0892bf commit 03b73ee
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/optimizer/plugins/CombineCodingAndQuantityValuesOptimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export default {
const rules: fshrules.Rule[] = def.rules; // <-- this assignment makes TypeScript happier in the next chunk of code
const typeCache: Map<string, fhirtypes.ElementDefinitionType[]> = new Map();

const ruleMap: { [path: string]: { [caretPath: string]: ExportableCaretValueRule } } = {};
rules
.filter(r => r instanceof ExportableCaretValueRule)
.forEach((r: ExportableCaretValueRule) => {
ruleMap[r.path] = ruleMap[r.path] ?? {};
ruleMap[r.path][r.caretPath] = r;
});

rules.forEach(rule => {
if (
rule instanceof ExportableCaretValueRule &&
Expand All @@ -72,18 +80,15 @@ export default {
return;
}

const siblingPaths = [
const siblings = [
`${basePath}.system`,
`${basePath}.display`,
`${basePath}.unit`,
`${basePath}.value`
];
const siblings = rules.filter(
otherRule =>
otherRule instanceof ExportableCaretValueRule &&
rule.path === otherRule.path &&
siblingPaths.includes(otherRule.caretPath)
) as ExportableCaretValueRule[];
]
.map(sibling => ruleMap[rule.path]?.[sibling])
.filter(Boolean);

if (siblings.length) {
const systemSibling = siblings.find(sibling => sibling.caretPath.endsWith('.system'));
const displaySibling = siblings.find(sibling => sibling.caretPath.endsWith('.display'));
Expand Down

0 comments on commit 03b73ee

Please sign in to comment.