Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve perofrmance of combine_coding_and_quantity_values #241

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Changes from all 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
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