-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into MAT-7935
- Loading branch information
Showing
14 changed files
with
795 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/CqlBuilderPanel/functionsSection/EditFunctionDialog.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from "react"; | ||
import { parseArgumentsFromLogicString } from "./EditFunctionDialog"; | ||
|
||
describe("parseArgumentsFromLogicString", () => { | ||
test("Can parse out empty arguments", () => { | ||
const logicString = `define function "Empty Arguments" (): true`; | ||
const result = parseArgumentsFromLogicString(logicString); | ||
expect(result).toEqual([]); | ||
}); | ||
test("Can parse out multiple arguments", () => { | ||
const logicString2 = `define function "Function name here" (arg1 "Integer", arg2 "Integer", arg3 "Date"):\n true`; | ||
const result = parseArgumentsFromLogicString(logicString2); | ||
|
||
expect(result).toEqual([ | ||
{ argumentName: "arg1", dataType: "Integer" }, | ||
{ argumentName: "arg2", dataType: "Integer" }, | ||
{ argumentName: "arg3", dataType: "Date" }, | ||
]); | ||
}); | ||
test("Can parse out arguments with commas embedded in dataType", () => { | ||
const logicString3 = `define fluent function "Numerator Observation"(Encounter "Encounter, Performed" ): | ||
duration in hours of Encounter.relevantPeriod`; | ||
const result = parseArgumentsFromLogicString(logicString3); | ||
expect(result).toEqual([ | ||
{ argumentName: "Encounter", dataType: "Encounter, Performed" }, | ||
]); | ||
}); | ||
}); |
89 changes: 89 additions & 0 deletions
89
src/CqlBuilderPanel/functionsSection/EditFunctionDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from "react"; | ||
import { MadieDialog } from "@madie/madie-design-system/dist/react"; | ||
import FunctionBuilder from "./functionBuilder/FunctionBuilder"; | ||
|
||
interface PropTypes { | ||
open: boolean; | ||
onClose: () => void; | ||
cqlBuilderLookupsTypes?: any; | ||
funct?: any; | ||
setEditFunctionDialogOpen: Function; | ||
handleApplyFunction: Function; | ||
handleFunctionEdit: Function; | ||
} | ||
|
||
export const parseArgumentsFromLogicString = (logicString) => { | ||
// `s` flag for multiline content | ||
const argumentListRegex = /\(([^)]*)\)/s; | ||
const match = logicString.match(argumentListRegex); | ||
|
||
// Nobody in parenthesis | ||
if (!match) { | ||
return []; | ||
} | ||
|
||
const argumentsString = match[1].trim(); | ||
// no args | ||
if (!argumentsString) { | ||
return []; | ||
} | ||
|
||
// Regex to match argument and data type pairs | ||
const argumentRegex = /([\w]+)\s+"([^"]+)"/g; | ||
const results = []; | ||
|
||
let argumentMatch; | ||
while ((argumentMatch = argumentRegex.exec(argumentsString)) !== null) { | ||
const [, argumentName, dataType] = argumentMatch; | ||
results.push({ argumentName, dataType }); | ||
} | ||
return results; | ||
}; | ||
|
||
const EditFunctionDialog = ({ | ||
funct, | ||
handleFunctionEdit, | ||
onClose, | ||
open, | ||
setEditFunctionDialogOpen, | ||
cqlBuilderLookupsTypes, | ||
handleApplyFunction, | ||
}: PropTypes) => { | ||
// a property is passed called argument names that does not seem to work for anything with commas. | ||
// the following is regex to grab arguments and dataTypes using a matcher and add them to the function to edit. | ||
|
||
const updatedFunction = { | ||
...funct, | ||
fluentFunction: funct?.isFluent === true ? true : false, | ||
functionsArguments: parseArgumentsFromLogicString( | ||
funct?.logic ? funct?.logic : "" | ||
), | ||
expressionEditorValue: funct?.logic, | ||
}; | ||
|
||
return ( | ||
<MadieDialog | ||
title="Edit" | ||
dialogProps={{ | ||
open, | ||
onClose: onClose, | ||
fullWidth: true, | ||
maxWidth: "md", | ||
"data-testid": "edit-parameter-dialog", | ||
}} | ||
> | ||
<FunctionBuilder | ||
cqlBuilderLookupsTypes={cqlBuilderLookupsTypes} | ||
canEdit={true} | ||
handleApplyFunction={handleApplyFunction} | ||
funct={updatedFunction} | ||
operation="edit" | ||
handleFunctionEdit={handleFunctionEdit} | ||
onClose={onClose} | ||
setEditFunctionDialogOpen={setEditFunctionDialogOpen} | ||
/> | ||
</MadieDialog> | ||
); | ||
}; | ||
|
||
export default EditFunctionDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.