Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/12/08 00:33:53 (7 months ago)
Author:
bwolfe
Message:

Applying patches to logic package and reporting test
Author: tmdugan, mseaton

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/src/api/org/openmrs/logic/db/hibernate/HibernateLogicObsDAO.java

    r4158 r4167  
    6161         
    6262        private Criterion getCriterion(LogicCriteria logicCriteria, Date indexDate) { 
    63                 boolean notOperator = false; 
    6463                Criterion c = null; 
    6564                Operator operator = logicCriteria.getOperator(); 
     
    7776                        c = Restrictions.eq("concept", concept); 
    7877 
    79                         if (notOperator) 
    80                                 c = Restrictions.not(c); 
     78                         
    8179 
    8280                } else if (operator == Operator.BEFORE) { 
    8381                        c = Restrictions.lt("obsDatetime", rightOperand); 
    8482 
    85                         if (notOperator) 
    86                                 c = Restrictions.not(c); 
    87  
    8883                } else if (operator == Operator.AFTER) { 
    8984                        c = Restrictions.gt("obsDatetime", rightOperand); 
    9085 
    91                         if (notOperator) 
    92                                 c = Restrictions.not(c); 
    93  
    94                 } else if (operator == Operator.AND) { 
     86                } else if (operator == Operator.AND||operator == Operator.OR) { 
    9587 
    9688                        Criterion leftCriteria = null; 
     
    10799 
    108100                        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 
    113110                        Criterion rightCriteria = null; 
    114111 
    115                         if (leftOperand instanceof LogicCriteria) { 
    116                                 leftCriteria = this.getCriterion((LogicCriteria) leftOperand, 
    117                                                                  indexDate); 
    118                         } 
    119112                        if (rightOperand instanceof LogicCriteria) { 
    120113                                rightCriteria = this.getCriterion((LogicCriteria) rightOperand, 
     
    122115                        } 
    123116 
    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                        } 
    129120 
    130121                } else if (operator == Operator.CONTAINS) { 
     
    139130                                c = Restrictions.eq("valueCoded", concept); 
    140131 
    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) { 
    142137                                Concept concept = Context.getConceptService() 
    143138                                                         .getConcept((Integer) rightOperand); 
     
    154149                        } else 
    155150                                log.error("Invalid operand value for CONTAINS operation"); 
    156  
    157                         if (notOperator) 
    158                                 c = Restrictions.not(c); 
    159  
    160151                } else if (operator == Operator.EQUALS) { 
    161152                        if (leftOperand instanceof String 
     
    165156                                c = Restrictions.eq("encounter", encounter); 
    166157                        } else if (rightOperand instanceof Float 
    167                                 || rightOperand instanceof Integer) 
     158                                || rightOperand instanceof Integer 
     159                                || rightOperand instanceof Double) 
    168160                                c = Restrictions.eq("valueNumeric", 
    169161                                                    Double.parseDouble(rightOperand 
     
    180172                                log.error("Invalid operand value for EQUALS operation"); 
    181173 
    182                         if (notOperator) 
    183                                 c = Restrictions.not(c); 
    184  
    185174                } else if (operator == Operator.LTE) { 
    186175                        if (rightOperand instanceof Float 
    187                                 || rightOperand instanceof Integer) 
     176                                || rightOperand instanceof Integer 
     177                                || rightOperand instanceof Double) 
    188178                                c = Restrictions.le("valueNumeric", 
    189179                                                    Double.parseDouble(rightOperand 
    190180                                                                                    .toString())); 
    191                         else if (rightOperand instanceof String) 
    192                                 c = Restrictions.le("valueText", 
    193                                                     rightOperand); 
    194181                        else if (rightOperand instanceof Date) 
    195182                                c = Restrictions.le("valueDatetime", 
     
    197184                        else 
    198185                                log.error("Invalid operand value for LESS THAN EQUAL operation"); 
    199  
    200                         if (notOperator) 
    201                                 c = Restrictions.not(c); 
    202186 
    203187                } else if (operator == Operator.GTE) { 
    204188                        if (rightOperand instanceof Float 
    205                                 || rightOperand instanceof Integer) 
     189                                || rightOperand instanceof Integer 
     190                                || rightOperand instanceof Double) 
    206191                                c = Restrictions.ge("valueNumeric", 
    207192                                                    Double.parseDouble(rightOperand 
    208193                                                                                    .toString())); 
    209                         else if (rightOperand instanceof String) 
    210                                 c = Restrictions.ge("valueText", 
    211                                                     rightOperand); 
    212194                        else if (rightOperand instanceof Date) 
    213195                                c = Restrictions.ge("valueDatetime", 
     
    215197                        else 
    216198                                log.error("Invalid operand value for GREATER THAN EQUAL operation"); 
    217  
    218                         if (notOperator) 
    219                                 c = Restrictions.not(c); 
    220199 
    221200                } else if (operator == Operator.LT) { 
    222201                        if (rightOperand instanceof Float 
    223                                 || rightOperand instanceof Integer) 
     202                                || rightOperand instanceof Integer 
     203                                || rightOperand instanceof Double) 
    224204                                c = Restrictions.lt("valueNumeric", 
    225205                                                    Double.parseDouble(rightOperand 
    226206                                                                                    .toString())); 
    227                         else if (rightOperand instanceof String) 
    228                                 c = Restrictions.lt("valueText", 
    229                                                     rightOperand); 
    230207                        else if (rightOperand instanceof Date) 
    231208                                c = Restrictions.lt("valueDatetime", 
     
    233210                        else 
    234211                                log.error("Invalid operand value for LESS THAN operation"); 
    235  
    236                         if (notOperator) 
    237                                 c = Restrictions.not(c); 
    238212 
    239213                } else if (operator == Operator.GT) { 
    240214                        if (rightOperand instanceof Float 
    241                                 || rightOperand instanceof Integer) 
     215                                || rightOperand instanceof Integer 
     216                                || rightOperand instanceof Double) 
    242217                                c = Restrictions.gt("valueNumeric", 
    243218                                                    Double.parseDouble(rightOperand 
    244219                                                                                    .toString())); 
    245                         else if (rightOperand instanceof String) 
    246                                 c = Restrictions.gt("valueText", 
    247                                                     rightOperand); 
    248220                        else if (rightOperand instanceof Date) 
    249221                                c = Restrictions.gt("valueDatetime", 
     
    251223                        else 
    252224                                log.error("Invalid operand value for GREATER THAN operation"); 
    253  
    254                         if (notOperator) 
    255                                 c = Restrictions.not(c); 
    256225 
    257226                } else if (operator == Operator.EXISTS) { 
     
    266235                } else if (operator == Operator.WITHIN 
    267236                        && rightOperand instanceof Duration) { 
     237                         
    268238                        Duration duration = (Duration) rightOperand; 
    269239                        Calendar within = Calendar.getInstance(); 
     
    271241 
    272242                        if (duration.getUnits() == Duration.Units.YEARS) { 
    273                                 within.roll(Calendar.YEAR, -duration.getDuration().intValue()); 
     243                                within.roll(Calendar.YEAR, duration.getDuration().intValue()); 
    274244                        } else if (duration.getUnits() == Duration.Units.MONTHS) { 
    275                                 within.roll(Calendar.MONTH, -duration.getDuration().intValue()); 
     245                                within.roll(Calendar.MONTH, duration.getDuration().intValue()); 
    276246                        } 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() 
    278248                                                                            .intValue()); 
    279249                        } 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() 
    281251                                                                           .intValue()); 
    282252                        } else if (duration.getUnits() == Duration.Units.MINUTES) { 
    283                                 within.roll(Calendar.MINUTE, -duration.getDuration().intValue()); 
     253                                within.roll(Calendar.MINUTE, duration.getDuration().intValue()); 
    284254                        } 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); 
    289259 
    290260                }