← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4053: Fixed bug: Validatation-deletion-categoryoptioncombos ( for Patient module ).

 

------------------------------------------------------------
revno: 4053
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-07-01 14:26:42 +0700
message:
  Fixed bug: Validatation-deletion-categoryoptioncombos ( for Patient module ).
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java
  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-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2011-06-24 07:55:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2011-07-01 07:26:42 +0000
@@ -66,5 +66,7 @@
     
     Collection<DataElement> getDataElementsInCondition( String aggregationExpression );
     
+    Collection<DataElementCategoryOptionCombo> getOptionCombosInCondition( String aggregationExpression );
+    
     String getConditionDescription( String condition );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java	2011-06-24 07:55:22 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java	2011-07-01 07:26:42 +0000
@@ -30,6 +30,8 @@
 import java.util.Collection;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 /**
@@ -75,16 +77,43 @@
 
         conditions = aggregationConditionService.getAllCaseAggregationCondition();
 
-        for( CaseAggregationCondition condition : conditions )
-        {
-            Collection<DataElement> dataElements = aggregationConditionService.getDataElementsInCondition( condition.getAggregationExpression() );
+        for ( CaseAggregationCondition condition : conditions )
+        {
+            Collection<DataElement> dataElements = aggregationConditionService.getDataElementsInCondition( condition
+                .getAggregationExpression() );
+
+            if ( dataElements != null && dataElements.contains( dataElement ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean allowDeleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
+    {
+        Collection<CaseAggregationCondition> conditions = aggregationConditionService.getAllCaseAggregationCondition();
+
+        for ( CaseAggregationCondition condition : conditions )
+        {
+            if( categoryCombo.getOptionCombos().contains( condition.getOptionCombo() ) )
+            {
+                return false;
+            }
             
-            if ( dataElements != null && dataElements.contains( dataElement ) )
+            Collection<DataElementCategoryOptionCombo> optionCombos = aggregationConditionService
+                .getOptionCombosInCondition( condition.getAggregationExpression() );
+
+            optionCombos.retainAll( categoryCombo.getOptionCombos() );
+
+            if ( optionCombos != null && optionCombos.size() > 0 )
             {
                 return false;
             }
         }
-        
+
         return true;
     }
 

=== 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-06-24 07:55:22 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-07-01 07:26:42 +0000
@@ -167,7 +167,7 @@
     {
         return aggregationConditionStore.get( dataElement, optionCombo );
     }
-    
+
     @Override
     public Collection<CaseAggregationCondition> getCaseAggregationCondition( DataElement dataElement )
     {
@@ -301,6 +301,39 @@
         return dataElements;
     }
 
+    @Override
+    public Collection<DataElementCategoryOptionCombo> getOptionCombosInCondition( String aggregationExpression )
+    {
+        String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID
+            + "[0-9]+" + SEPARATOR_ID + "[0-9]+" + "\\]";
+
+        Collection<DataElementCategoryOptionCombo> optionCombos = new HashSet<DataElementCategoryOptionCombo>();
+
+        // ---------------------------------------------------------------------
+        // parse expressions
+        // ---------------------------------------------------------------------
+
+        Pattern pattern = Pattern.compile( regExp );
+
+        Matcher matcher = pattern.matcher( aggregationExpression );
+
+        while ( matcher.find() )
+        {
+            String match = matcher.group();
+            match = match.replaceAll( "[\\[\\]]", "" );
+
+            String[] info = match.split( SEPARATOR_OBJECT );
+            String[] ids = info[1].split( SEPARATOR_ID );
+
+            int optionComboId = Integer.parseInt( ids[2] );
+            DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId );
+
+            optionCombos.add( optionCombo );
+        }
+
+        return optionCombos;
+    }
+
     // -------------------------------------------------------------------------
     // Support Methods
     // -------------------------------------------------------------------------
@@ -499,8 +532,8 @@
             + "INNER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid "
             + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid "
             + "INNER JOIN patientattributevalue as pav ON pav.patientid = pi.patientid "
-            + "WHERE pav.patientattributeid = " + attributeId + " " + " AND pd.organisationunitid = " + orgunitId
-            + " " + " AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' "
+            + "WHERE pav.patientattributeid = " + attributeId + " " + " AND pd.organisationunitid = " + orgunitId + " "
+            + " AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' "
             + "AND pav.value ";
     }