Skip to content

Commit

Permalink
MAT-8005 saved functions in order as in cql
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu committed Jan 10, 2025
1 parent 7c272fe commit 3e92ab2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const fluentFunctions = [
libraryName: null,
libraryAlias: null,
logic:
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n (Enc E where E.status = 'finished') is not null",
startLine: 0,
comment: null,
},
Expand Down
5 changes: 5 additions & 0 deletions src/CqlBuilderPanel/__mocks__/MockMeasureStoreCql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ for function
// comment 2
define function MyFunctions(encounter1 Encounter, encounter2 Encounter, encounter3 Encounter, encounter4 Encounter):
3
define function "test function not found in builder lookup"():
3
define fluent function "test fluent function not found in builder lookup"(Enc Encounter):
(Enc E where E.status = 'finished') is not null
`;
57 changes: 27 additions & 30 deletions src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,37 @@ export default function FunctionsSection({
? new CqlAntlr(cql).parse().expressionDefinitions
: [];

let functionLookups: FunctionLookup[] =
cqlBuilderLookupsTypes?.functions
?.filter((func) => !func.libraryName)
.map((func) => {
// get the comments for CQL definition from antlr parser expressions
const expression = expressionDefinitions.find(
(expression) => func.logic == expression.text
);
return {
...func,
let functionLookups: FunctionLookup[] = [];
expressionDefinitions?.forEach((expression) => {
if (expression.name === "function") {
const found = cqlBuilderLookupsTypes?.functions?.find(
(funct) => funct.logic === expression.text
);
if (found) {
functionLookups.push({
...found,
comment: expression?.comment,
isFluent: "-",
arguments: getArgumentNames(func.logic),
expressionEditorValue: getExpressionEditorValue(func.logic),
} as FunctionLookup;
}) || [];

functionLookups = functionLookups.concat(
cqlBuilderLookupsTypes?.fluentFunctions
?.filter((func) => !func.libraryName)
.map((func) => {
const expression = expressionDefinitions.find(
(expression) => func.logic == expression.text
);
return {
...func,
arguments: getArgumentNames(found.logic),
expressionEditorValue: getExpressionEditorValue(found.logic),
} as FunctionLookup);
}
} else if (expression.name === "fluent") {
const found = cqlBuilderLookupsTypes?.fluentFunctions?.find(
(funct) => funct.logic === expression.text
);
if (found) {
functionLookups.push({
...found,
comment: expression?.comment,
isFluent: "Yes",
arguments: getArgumentNames(func.logic),
expressionEditorValue: getExpressionEditorValue(func.logic),
} as FunctionLookup;
}) || []
);
functionLookups = _.sortBy(functionLookups, (o) => o.name?.toLowerCase());
arguments: getArgumentNames(found.logic),
expressionEditorValue: getExpressionEditorValue(found.logic),
} as FunctionLookup);
}
}
});

return (
<>
<FunctionSectionNavTabs
Expand Down

0 comments on commit 3e92ab2

Please sign in to comment.