- Timestamp:
- 05/12/08 00:33:53 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/trunk/src/api/org/openmrs/logic/db/hibernate/HibernateLogicObsDAO.java
r4158 r4167 61 61 62 62 private Criterion getCriterion(LogicCriteria logicCriteria, Date indexDate) { 63 boolean notOperator = false;64 63 Criterion c = null; 65 64 Operator operator = logicCriteria.getOperator(); … … 77 76 c = Restrictions.eq("concept", concept); 78 77 79 if (notOperator) 80 c = Restrictions.not(c); 78 81 79 82 80 } else if (operator == Operator.BEFORE) { 83 81 c = Restrictions.lt("obsDatetime", rightOperand); 84 82 85 if (notOperator)86 c = Restrictions.not(c);87 88 83 } else if (operator == Operator.AFTER) { 89 84 c = Restrictions.gt("obsDatetime", rightOperand); 90 85 91 if (notOperator) 92 c = Restrictions.not(c); 93 94 } else if (operator == Operator.AND) { 86 } else if (operator == Operator.AND||operator == Operator.OR) { 95 87 96 88 Criterion leftCriteria = null; … … 107 99 108 100 if (leftCriteria != null && rightCriteria != null) { 109 c = Restrictions.and(leftCriteria, rightCriteria); 110 } 111 } else if (operator == Operator.OR) { 112 Criterion leftCriteria = null; 101 if(operator == Operator.AND){ 102 c = Restrictions.and(leftCriteria, rightCriteria); 103 } 104 if(operator == Operator.OR){ 105 c = Restrictions.or(leftCriteria, rightCriteria); 106 } 107 } 108 } else if (operator == Operator.NOT) { 109 113 110 Criterion rightCriteria = null; 114 111 115 if (leftOperand instanceof LogicCriteria) {116 leftCriteria = this.getCriterion((LogicCriteria) leftOperand,117 indexDate);118 }119 112 if (rightOperand instanceof LogicCriteria) { 120 113 rightCriteria = this.getCriterion((LogicCriteria) rightOperand, … … 122 115 } 123 116 124 if (leftCriteria != null && rightCriteria != null) { 125 c = Restrictions.or(leftCriteria, rightCriteria); 126 } 127 } else if (operator == Operator.NOT) { 128 notOperator = !notOperator; 117 if (rightCriteria != null) { 118 c = Restrictions.not(rightCriteria); 119 } 129 120 130 121 } else if (operator == Operator.CONTAINS) { … … 139 130 c = Restrictions.eq("valueCoded", concept); 140 131 141 } else if (rightOperand instanceof Integer) { 132 } if (rightOperand instanceof Double) { 133 Concept concept = Context.getConceptService() 134 .getConcept(((Double) rightOperand).intValue()); 135 c = Restrictions.eq("valueCoded", concept); 136 }else if (rightOperand instanceof Integer) { 142 137 Concept concept = Context.getConceptService() 143 138 .getConcept((Integer) rightOperand); … … 154 149 } else 155 150 log.error("Invalid operand value for CONTAINS operation"); 156 157 if (notOperator)158 c = Restrictions.not(c);159 160 151 } else if (operator == Operator.EQUALS) { 161 152 if (leftOperand instanceof String … … 165 156 c = Restrictions.eq("encounter", encounter); 166 157 } else if (rightOperand instanceof Float 167 || rightOperand instanceof Integer) 158 || rightOperand instanceof Integer 159 || rightOperand instanceof Double) 168 160 c = Restrictions.eq("valueNumeric", 169 161 Double.parseDouble(rightOperand … … 180 172 log.error("Invalid operand value for EQUALS operation"); 181 173 182 if (notOperator)183 c = Restrictions.not(c);184 185 174 } else if (operator == Operator.LTE) { 186 175 if (rightOperand instanceof Float 187 || rightOperand instanceof Integer) 176 || rightOperand instanceof Integer 177 || rightOperand instanceof Double) 188 178 c = Restrictions.le("valueNumeric", 189 179 Double.parseDouble(rightOperand 190 180 .toString())); 191 else if (rightOperand instanceof String)192 c = Restrictions.le("valueText",193 rightOperand);194 181 else if (rightOperand instanceof Date) 195 182 c = Restrictions.le("valueDatetime", … … 197 184 else 198 185 log.error("Invalid operand value for LESS THAN EQUAL operation"); 199 200 if (notOperator)201 c = Restrictions.not(c);202 186 203 187 } else if (operator == Operator.GTE) { 204 188 if (rightOperand instanceof Float 205 || rightOperand instanceof Integer) 189 || rightOperand instanceof Integer 190 || rightOperand instanceof Double) 206 191 c = Restrictions.ge("valueNumeric", 207 192 Double.parseDouble(rightOperand 208 193 .toString())); 209 else if (rightOperand instanceof String)210 c = Restrictions.ge("valueText",211 rightOperand);212 194 else if (rightOperand instanceof Date) 213 195 c = Restrictions.ge("valueDatetime", … … 215 197 else 216 198 log.error("Invalid operand value for GREATER THAN EQUAL operation"); 217 218 if (notOperator)219 c = Restrictions.not(c);220 199 221 200 } else if (operator == Operator.LT) { 222 201 if (rightOperand instanceof Float 223 || rightOperand instanceof Integer) 202 || rightOperand instanceof Integer 203 || rightOperand instanceof Double) 224 204 c = Restrictions.lt("valueNumeric", 225 205 Double.parseDouble(rightOperand 226 206 .toString())); 227 else if (rightOperand instanceof String)228 c = Restrictions.lt("valueText",229 rightOperand);230 207 else if (rightOperand instanceof Date) 231 208 c = Restrictions.lt("valueDatetime", … … 233 210 else 234 211 log.error("Invalid operand value for LESS THAN operation"); 235 236 if (notOperator)237 c = Restrictions.not(c);238 212 239 213 } else if (operator == Operator.GT) { 240 214 if (rightOperand instanceof Float 241 || rightOperand instanceof Integer) 215 || rightOperand instanceof Integer 216 || rightOperand instanceof Double) 242 217 c = Restrictions.gt("valueNumeric", 243 218 Double.parseDouble(rightOperand 244 219 .toString())); 245 else if (rightOperand instanceof String)246 c = Restrictions.gt("valueText",247 rightOperand);248 220 else if (rightOperand instanceof Date) 249 221 c = Restrictions.gt("valueDatetime", … … 251 223 else 252 224 log.error("Invalid operand value for GREATER THAN operation"); 253 254 if (notOperator)255 c = Restrictions.not(c);256 225 257 226 } else if (operator == Operator.EXISTS) { … … 266 235 } else if (operator == Operator.WITHIN 267 236 && rightOperand instanceof Duration) { 237 268 238 Duration duration = (Duration) rightOperand; 269 239 Calendar within = Calendar.getInstance(); … … 271 241 272 242 if (duration.getUnits() == Duration.Units.YEARS) { 273 within.roll(Calendar.YEAR, -duration.getDuration().intValue());243 within.roll(Calendar.YEAR, duration.getDuration().intValue()); 274 244 } else if (duration.getUnits() == Duration.Units.MONTHS) { 275 within.roll(Calendar.MONTH, -duration.getDuration().intValue());245 within.roll(Calendar.MONTH, duration.getDuration().intValue()); 276 246 } else if (duration.getUnits() == Duration.Units.WEEKS) { 277 within.roll(Calendar.WEEK_OF_YEAR, -duration.getDuration()247 within.roll(Calendar.WEEK_OF_YEAR, duration.getDuration() 278 248 .intValue()); 279 249 } else if (duration.getUnits() == Duration.Units.DAYS) { 280 within.roll(Calendar.DAY_OF_YEAR, -duration.getDuration()250 within.roll(Calendar.DAY_OF_YEAR, duration.getDuration() 281 251 .intValue()); 282 252 } else if (duration.getUnits() == Duration.Units.MINUTES) { 283 within.roll(Calendar.MINUTE, -duration.getDuration().intValue());253 within.roll(Calendar.MINUTE, duration.getDuration().intValue()); 284 254 } else if (duration.getUnits() == Duration.Units.SECONDS) { 285 within.roll(Calendar.SECOND, -duration.getDuration().intValue());286 } 287 288 c = Restrictions. ge("obsDatetime", within.getTime());255 within.roll(Calendar.SECOND, duration.getDuration().intValue()); 256 } 257 258 c = Restrictions.between("obsDatetime", indexDate, within); 289 259 290 260 }