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 3 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,15 @@ 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] || {};
cmoesel marked this conversation as resolved.
Show resolved Hide resolved
ruleMap[r.path][r.caretPath] = ruleMap[r.path][r.caretPath] || [];
cmoesel marked this conversation as resolved.
Show resolved Hide resolved
ruleMap[r.path][r.caretPath].push(r);
cmoesel marked this conversation as resolved.
Show resolved Hide resolved
});

rules.forEach(rule => {
if (
rule instanceof ExportableCaretValueRule &&
Expand All @@ -72,18 +81,14 @@ 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[];
]
.filter(sibling => ruleMap[rule.path] && ruleMap[rule.path][sibling]?.length)
cmoesel marked this conversation as resolved.
Show resolved Hide resolved
.map(sibling => ruleMap[rule.path][sibling][0]);
if (siblings.length) {
const systemSibling = siblings.find(sibling => sibling.caretPath.endsWith('.system'));
const displaySibling = siblings.find(sibling => sibling.caretPath.endsWith('.display'));
Expand Down
Loading