← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2927: Fix bug: Cannot run CaseAggregationCondition with condition property of ProgramStage- DataElement...

 

------------------------------------------------------------
revno: 2927
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-02-28 11:40:24 +0700
message:
  Fix bug: Cannot run CaseAggregationCondition with condition property of ProgramStage- DataElement as "is null "
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-01-12 02:26:26 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-02-28 04:40:24 +0000
@@ -75,6 +75,8 @@
         + OBJECT_PATIENT_PROPERTY + "|" + OBJECT_PROGRAM_PROPERTY + ")" + SEPARATOR_OBJECT + "([a-zA-Z0-9\\- ]+["
         + SEPARATOR_ID + "[0-9]*]*)" + "\\]";
 
+    private final String IS_NULL = "is null";
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -172,7 +174,7 @@
         Period period )
     {
         String sql = createSQL( aggregationCondition, orgunit, period );
-        
+
         Collection<Integer> patientIds = aggregationConditionStore.executeSQL( sql );
 
         return calValue( patientIds, aggregationCondition.getOperator() );
@@ -210,7 +212,7 @@
 
         String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID
             + "[0-9]+" + SEPARATOR_ID + "[0-9]+" + "\\]";
-        
+
         // ---------------------------------------------------------------------
         // parse expressions
         // ---------------------------------------------------------------------
@@ -236,12 +238,12 @@
             int categoryOptionId = Integer.parseInt( ids[2] );
             DataElementCategory category = categoryService.getDataElementCategory( categoryOptionId );
 
-            matcher.appendReplacement( decription, "[" + programStage.getName() + SEPARATOR_ID +
-                dataElement.getName() + SEPARATOR_ID + category.getName() + "]" );
+            matcher.appendReplacement( decription, "[" + programStage.getName() + SEPARATOR_ID + dataElement.getName()
+                + SEPARATOR_ID + category.getName() + "]" );
         }
 
         matcher.appendTail( decription );
-        
+
         return decription.toString();
     }
 
@@ -316,15 +318,27 @@
                     int dataElementId = Integer.parseInt( ids[1] );
                     int optionComboId = Integer.parseInt( ids[2] );
 
-                    condition = getConditionForDataElement( programStageId, dataElementId, optionComboId, orgunitId,
-                        startDate, endDate );
-                    if ( !expression[i].contains( "+" ) )
+                    String valueToCompare = expression[i].replace( "[" + match + "]", "" ).trim();
+
+                    if ( valueToCompare.equalsIgnoreCase( IS_NULL ) )
                     {
-                        condition += " AND pd.value ";
+                        condition = getConditionForNotDataElement( programStageId, dataElementId, optionComboId,
+                            orgunitId, startDate, endDate );
+
+                        expression[i] = expression[i].replace( valueToCompare, "" );
                     }
                     else
                     {
-                        subConditions.add( condition );
+                        condition = getConditionForDataElement( programStageId, dataElementId, optionComboId,
+                            orgunitId, startDate, endDate );
+                        if ( !expression[i].contains( "+" ) )
+                        {
+                            condition += " AND pd.value ";
+                        }
+                        else
+                        {
+                            subConditions.add( condition );
+                        }
                     }
                 }
 
@@ -407,6 +421,21 @@
         return dataElements;
     }
 
+    private String getConditionForNotDataElement( int programStageId, int dataElementId, int optionComboId, int orgunitId,
+        String startDate, String endDate )
+    {
+        return "SELECT distinct(pi.patientid) FROM programstageinstance as psi "
+            + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid "
+            + "INNER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid "
+            + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid "
+            + "WHERE pd.organisationunitid = " + orgunitId + " AND ps.programstageid = " + programStageId + " "
+            + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' "
+            + "AND ( ( pd.dataelementid != " + dataElementId+ " AND pd.categoryoptioncomboid != " + optionComboId+ "  ) "
+            + "      OR ( pd.dataelementid = " + dataElementId+ "  AND pd.categoryoptioncomboid != " + optionComboId+ " ) "
+            + "      OR ( pd.dataelementid != " + dataElementId+ "  AND pd.categoryoptioncomboid = " + optionComboId+ "  ) )";
+
+    }
+    
     private String getConditionForDataElement( int programStageId, int dataElementId, int optionComboId, int orgunitId,
         String startDate, String endDate )
     {
@@ -492,5 +521,5 @@
 
         return patientIds.size();
     }
-    
+
 }