From 3e92ab2a7127fb8020ce37a46c92486a6ce3206b Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Fri, 10 Jan 2025 07:13:53 -0600 Subject: [PATCH] MAT-8005 saved functions in order as in cql --- .../__mocks__/MockCqlBuilderLookupsTypes.ts | 2 +- .../__mocks__/MockMeasureStoreCql.tsx | 5 ++ .../functionsSection/FunctionsSection.tsx | 57 +++++++++---------- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/CqlBuilderPanel/__mocks__/MockCqlBuilderLookupsTypes.ts b/src/CqlBuilderPanel/__mocks__/MockCqlBuilderLookupsTypes.ts index 0ac2e914..bb7a63f3 100644 --- a/src/CqlBuilderPanel/__mocks__/MockCqlBuilderLookupsTypes.ts +++ b/src/CqlBuilderPanel/__mocks__/MockCqlBuilderLookupsTypes.ts @@ -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, }, diff --git a/src/CqlBuilderPanel/__mocks__/MockMeasureStoreCql.tsx b/src/CqlBuilderPanel/__mocks__/MockMeasureStoreCql.tsx index c00f51ef..1b5c2f5d 100644 --- a/src/CqlBuilderPanel/__mocks__/MockMeasureStoreCql.tsx +++ b/src/CqlBuilderPanel/__mocks__/MockMeasureStoreCql.tsx @@ -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 `; diff --git a/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx b/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx index ad7458ae..0ab72c09 100644 --- a/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx +++ b/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx @@ -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 ( <>