24
24
import java .util .stream .Collectors ;
25
25
import java .util .stream .Stream ;
26
26
import org .ehrbase .openehr .sdk .aql .dto .AqlQuery ;
27
- import org .ehrbase .openehr .sdk .aql .dto .condition .ComparisonOperatorCondition ;
28
- import org .ehrbase .openehr .sdk .aql .dto .condition .LogicalOperatorCondition ;
29
- import org .ehrbase .openehr .sdk .aql .dto .condition .WhereCondition ;
27
+ import org .ehrbase .openehr .sdk .aql .dto .condition .*;
30
28
import org .ehrbase .openehr .sdk .aql .dto .containment .AbstractContainmentExpression ;
31
29
import org .ehrbase .openehr .sdk .aql .dto .containment .Containment ;
32
30
import org .ehrbase .openehr .sdk .aql .dto .containment .ContainmentNotOperator ;
33
31
import org .ehrbase .openehr .sdk .aql .dto .containment .ContainmentSetOperator ;
32
+ import org .ehrbase .openehr .sdk .aql .dto .operand .LikeOperand ;
33
+ import org .ehrbase .openehr .sdk .aql .dto .operand .MatchesOperand ;
34
34
import org .ehrbase .openehr .sdk .aql .dto .operand .Operand ;
35
35
import org .ehrbase .openehr .sdk .aql .dto .operand .QueryParameter ;
36
36
import org .ehrbase .openehr .sdk .aql .dto .path .AndOperatorPredicate ;
@@ -58,13 +58,14 @@ public static String removeParameter(String aql, String parameterName) {
58
58
}
59
59
60
60
private static WhereCondition removeParameter (WhereCondition condition , String parameterName ) {
61
- if (condition instanceof ComparisonOperatorCondition ) {
62
- Operand value = ((ComparisonOperatorCondition ) condition ).getValue ();
63
- if (value instanceof QueryParameter && Objects .equals (((QueryParameter ) value ).getName (), parameterName )) {
61
+ if (condition instanceof ComparisonOperatorCondition comparisonOperatorCondition ) {
62
+ Operand value = comparisonOperatorCondition .getValue ();
63
+ if (value instanceof QueryParameter queryParameter
64
+ && Objects .equals (queryParameter .getName (), parameterName )) {
64
65
return null ;
65
66
}
66
- } else if (condition instanceof LogicalOperatorCondition ) {
67
- List <WhereCondition > values = (( LogicalOperatorCondition ) condition ) .getValues ();
67
+ } else if (condition instanceof LogicalOperatorCondition logicalOperatorCondition ) {
68
+ List <WhereCondition > values = logicalOperatorCondition .getValues ();
68
69
69
70
for (WhereCondition value : new ArrayList <>(values )) {
70
71
values .remove (value );
@@ -80,8 +81,32 @@ private static WhereCondition removeParameter(WhereCondition condition, String p
80
81
return null ;
81
82
} else if (values .size () == 1 ) {
82
83
return values .get (0 );
84
+ }
85
+ } else if (condition instanceof NotCondition notCondition ) {
86
+ var value = removeParameter (notCondition .getConditionDto (), parameterName );
87
+ if (value != null ) {
88
+ notCondition .setConditionDto (value );
83
89
} else {
84
- return condition ;
90
+ return null ;
91
+ }
92
+ } else if (condition instanceof MatchesCondition matchesCondition ) {
93
+ List <MatchesOperand > values = matchesCondition .getValues ();
94
+ values .removeIf (value -> value instanceof QueryParameter queryParameter
95
+ && Objects .equals (queryParameter .getName (), parameterName ));
96
+ if (values .isEmpty ()) {
97
+ return null ;
98
+ }
99
+ } else if (condition instanceof LikeCondition likeCondition ) {
100
+ LikeOperand value = likeCondition .getValue ();
101
+ if (value instanceof QueryParameter queryParameter
102
+ && Objects .equals (queryParameter .getName (), parameterName )) {
103
+ return null ;
104
+ }
105
+ } else if (condition instanceof ExistsCondition ) {
106
+ // doesn't have parameter
107
+ } else {
108
+ if (condition != null ) {
109
+ throw new IllegalStateException ("Unexpected condition: " + condition );
85
110
}
86
111
}
87
112
0 commit comments