-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat:use dhis2 expression parser #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some inline comments:
boolean: xp.ValueType.BOOLEAN, | ||
date: xp.ValueType.DATE, | ||
number: xp.ValueType.NUMBER, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move auxiliar/helper methods down, so the first we see when opening the file is the class and its public methods.
|
||
export class D2ExpressionParser { | ||
public evaluateRuleEngineCondition( | ||
ruleCondtion: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: ruleCondtion
); | ||
|
||
const programVariables = expressionParser.collectProgramVariablesNames(); | ||
programVariables.forEach(programVariable => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[functional programming / immutability] let's refactor this block to avoid the forEach. We can for example build some from programVariables and concat to the previous ones to build the final variablesMap in one go.
"date", | ||
new Date().toISOString().split("T")[0] | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multi-line expressions like this one are hard to read. Create local variables for intermediate values.
undefined, | ||
undefined, | ||
undefined | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the undefined args, is not adding too much value.
...question, | ||
isVisible: updatedIsVisible, | ||
errors: updatedErrors, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[subjective] The return value is the same except for the value: undefined
. This does not seem accidental repetition, to keep it DRY, move the condition inside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have faced this issue before as well, typescript cannot resolve the type unless the condition is an if else. Is there any other way to resolve this?
I see, things like this happen for union types, not TS's fault, it's normal. Try this approach:
...(question.isVisible !== updatedIsVisible ? { value: undefined } : {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, nice one! It works 👍
@@ -152,100 +152,102 @@ export class QuestionnaireQuestion { | |||
} | |||
|
|||
static updateQuestions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if we have time (probably not...). This is the kind of logic that really benefits from having some tests, as it's not trivial at all and extremely easy to introduce a bug. No need to cover all cases, just a subset that are used in the app and we know to be tricky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will do this if i have time remaining after creation of ppt for meeting.
@@ -45,11 +42,12 @@ export interface QuestionnaireRuleAction { | |||
} | |||
export interface QuestionnaireRule { | |||
id: Id; | |||
condition: string; //condition is parsed with dataelementId e.g: #{dataElementId} == 'Yes' | |||
condition: string; | |||
dataElementIds: Id[]; // all dataElements in condition (there could be mutiple conditions) | |||
teAttributeIds: Id[]; // all trackedEntityAttributes in condition (there could be mutiple conditions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: mutiple
@@ -45,11 +42,12 @@ export interface QuestionnaireRuleAction { | |||
} | |||
export interface QuestionnaireRule { | |||
id: Id; | |||
condition: string; //condition is parsed with dataelementId e.g: #{dataElementId} == 'Yes' | |||
condition: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we need some kind of documentation to know that kind of things we can do in a condition.
updatedSection.isVisible === false && section.isVisible === true | ||
), | ||
}; | ||
if (section.isVisible === false && updatedSection.isVisible === true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When working with boolean, it's more declarative just a
/ !a
|
||
export class D2ExpressionParser { | ||
public evaluateRuleEngineCondition( | ||
ruleCondtion: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some docs somewhere (probably the easiest is a link to DHIS2 documentation) so we know what kind of conditions we can do.
@tokland Ready for re-review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-wise, all good by me.
📌 References
📝 Implementation
📹 Screenshots/Screen capture
testing videos : https://drive.google.com/drive/folders/1BQkuP6o0fi0GxY-cqbTJzlCAj9Ivk7bu?usp=sharing
🔥 Notes to the tester