← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16285: Extended AggQueryBuilder to support QtyValidated; Fixes-Tariffvalue; Totals

 

------------------------------------------------------------
revno: 16285
committer: Bharath chbharathk@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-07-30 12:58:29 +0100
message:
  Extended AggQueryBuilder to support QtyValidated; Fixes-Tariffvalue;Totals
modified:
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/AddAggregationQueryAction.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/RunAggregationQueryAction.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/Lookup.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueService.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueStore.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/dataentry/LoadDataEntryFormAction.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPBFAggregationService.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultTariffDataValueService.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateTariffDataValueStore.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateUtilizationRateStore.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/quality/dataentry/GetOrganisationUnitForMaxAction.java
  local/in/dhis-web-maintenance-rbf/src/main/webapp/dhis-web-maintenance-rbf/loadDataEntryForm.vm


--
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 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/AddAggregationQueryAction.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/AddAggregationQueryAction.java	2014-04-26 11:27:06 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/AddAggregationQueryAction.java	2014-07-30 11:58:29 +0000
@@ -121,6 +121,14 @@
 
             aggregationConditionService.addCaseAggregationCondition( condition );    
         }
+        else if( aggType.equals( Lookup.PBF_AGG_TYPE_QUANTITY_VALIDATED ) )
+        {
+            String query = "NONE";            
+            
+            CaseAggregationCondition condition = new CaseAggregationCondition( dataElement.getName(), aggType, query, dataElement, dataElementCategoryService.getDefaultDataElementCategoryOptionCombo() );
+
+            aggregationConditionService.addCaseAggregationCondition( condition );    
+        }
 
         /*if ( aggType.equals( Lookup.CCEI_AGG_TYPE_STORAGE_CAPACITY ) )
         {

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/RunAggregationQueryAction.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/RunAggregationQueryAction.java	2014-04-26 11:27:06 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/aggregation/action/RunAggregationQueryAction.java	2014-07-30 11:58:29 +0000
@@ -175,6 +175,7 @@
         Period period = new Period();
         
         period = PeriodType.getPeriodFromIsoString( selectedPeriodId );
+        period = periodService.reloadPeriod( period );
         
         if( period != null )
         {
@@ -240,6 +241,21 @@
 
                 aggregationResultMap.putAll( defaultPBFAggregationService.calculateOverallUnadjustedPBFAmount( periods, dataElement, orgUnits, dataSetId ) );
             }
+            else if( condition.getOperator().equals( Lookup.PBF_AGG_TYPE_QUANTITY_VALIDATED ) )
+            {
+                Set<OrganisationUnit> orgUnits = new HashSet<OrganisationUnit>();
+                
+                orgUnits.addAll( orgUnitList );
+                
+                List<Period> periods = new ArrayList<Period>();
+                
+                //periods.add( getCurrentPeriod( dataSet.getPeriodType(), new Date() ) );
+                
+                periods.add( period );
+
+                aggregationResultMap.putAll( defaultPBFAggregationService.calculateQuantityValidated( periods, orgUnits ) );
+                
+            }
             
             dataElements.add( dataElement );
         }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/Lookup.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/Lookup.java	2014-04-26 11:27:06 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/Lookup.java	2014-07-30 11:58:29 +0000
@@ -21,6 +21,7 @@
     
     public static final String PBF_AGG_TYPE_OVERALL_QUALITY_SCORE = "OVERALL QUALITY SCORE";
     public static final String PBF_AGG_TYPE_OVERALL_UNADJUSTED_PBF_AMOUNT = "OVERALL UNADJUSTED PBF AMOUNT";
+    public static final String PBF_AGG_TYPE_QUANTITY_VALIDATED = "QUANTITY VALIDATED";
     
     public static final String ORGUNITID_BY_COMMA = "ORGUNITID_BY_COMMA";
     public static final String PERIODID_BY_COMMA = "PERIODID_BY_COMMA";

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueService.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueService.java	2014-05-31 13:40:53 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueService.java	2014-07-30 11:58:29 +0000
@@ -3,6 +3,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
+import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
@@ -51,4 +52,5 @@
     
     String getTariffDataValue( Integer orgunitgroupId, Integer organisationUnitId, Integer dataSetId, Integer dataElementId, String date );
 
+    Set<Integer> getOrgUnitGroupsByDataset( Integer dataSetId, String orgUnitIds );
 }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueStore.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueStore.java	2014-05-31 13:40:53 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/TariffDataValueStore.java	2014-07-30 11:58:29 +0000
@@ -3,6 +3,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
+import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
@@ -50,4 +51,6 @@
     
     String getTariffDataValue( Integer orgunitgroupId, Integer organisationUnitId, Integer dataSetId, Integer dataElementId, String date );
     
+    Set<Integer> getOrgUnitGroupsByDataset( Integer dataSetId, String orgUnitIds );
+    
 }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/dataentry/LoadDataEntryFormAction.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/dataentry/LoadDataEntryFormAction.java	2014-07-28 09:27:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/dataentry/LoadDataEntryFormAction.java	2014-07-30 11:58:29 +0000
@@ -358,7 +358,7 @@
             tariff_setting_authority = (int) tariff_authority.getValue();
         }
 
-        OrganisationUnitGroup orgUnitGroup = findPBFOrgUnitGroupforTariff( organisationUnit );
+        
         
         List<OrganisationUnit> orgUnitBranch = organisationUnitService.getOrganisationUnitBranch( organisationUnit.getId() );
         String orgUnitBranchIds = "-1";
@@ -367,6 +367,7 @@
             orgUnitBranchIds += "," + orgUnit.getId();
         }
         
+        OrganisationUnitGroup orgUnitGroup = findPBFOrgUnitGroupforTariff( organisationUnit, dataSet.getId(), orgUnitBranchIds );
         if( orgUnitGroup != null )
         {
             tariffDataValueMap.putAll( tariffDataValueService.getTariffDataValues( orgUnitGroup, orgUnitBranchIds, dataSet, period ) );
@@ -388,7 +389,7 @@
         for ( PBFDataValue pbfDataValue : pbfDataValues )
         {
             DataElement de = pbfDataValue.getDataElement();
-            if ( pbfDataValue.getTariffAmount() == null )
+            if ( pbfDataValue.getTariffAmount() == null || pbfDataValue.getTariffAmount().toString().trim().equals( "" ) )
             {
                 Double tariffAmount = tariffDataValueMap.get( de.getId() );
                 if ( tariffAmount != null )
@@ -529,13 +530,23 @@
         return SUCCESS;
     }
 
-    public OrganisationUnitGroup findPBFOrgUnitGroupforTariff( OrganisationUnit organisationUnit )
+    public OrganisationUnitGroup findPBFOrgUnitGroupforTariff( OrganisationUnit organisationUnit, Integer dataSetId, String orgUnitIds )
     {
-    	Constant tariff_authority = constantService.getConstantByName( TARIFF_SETTING_AUTHORITY );
-    	
-    	OrganisationUnitGroupSet orgUnitGroupSet = orgUnitGroupService.getOrganisationUnitGroupSet( (int) tariff_authority.getValue() );
-    	
-    	OrganisationUnitGroup orgUnitGroup = organisationUnit.getGroupInGroupSet( orgUnitGroupSet );
+        Set<Integer> orgUnitGroupIds = tariffDataValueService.getOrgUnitGroupsByDataset( dataSetId, orgUnitIds );
+        
+        OrganisationUnitGroup orgUnitGroup = null;
+        if( orgUnitGroupIds != null && orgUnitGroupIds.size() > 0 )
+        {
+             orgUnitGroup = orgUnitGroupService.getOrganisationUnitGroup( orgUnitGroupIds.iterator().next() );
+        }
+        else
+        {        
+            Constant tariff_authority = constantService.getConstantByName( TARIFF_SETTING_AUTHORITY );
+        	
+            OrganisationUnitGroupSet orgUnitGroupSet = orgUnitGroupService.getOrganisationUnitGroupSet( (int) tariff_authority.getValue() );
+        	
+            orgUnitGroup = organisationUnit.getGroupInGroupSet( orgUnitGroupSet );
+        }
     	
     	return orgUnitGroup;
     }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPBFAggregationService.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPBFAggregationService.java	2014-05-31 13:40:53 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPBFAggregationService.java	2014-07-30 11:58:29 +0000
@@ -204,7 +204,65 @@
         
         return aggregationResultMap;
     }
-    
+
+    public Map<String, Double> calculateQuantityValidated( List<Period> periods, Set<OrganisationUnit> orgUnits )
+    {
+        Map<String, Double> aggregationResultMap = new HashMap<String, Double>();
+        
+        try
+        {
+            String query = "SELECT organisationunitid, dataelementid, periodid, qtyvalidated FROM pbfdatavalue " +
+                            " WHERE " + 
+                                " periodid IN ( "+ Lookup.PERIODID_BY_COMMA +" ) AND "+
+                                " organisationunitid IN ( " + Lookup.ORGUNITID_BY_COMMA + " ) ";
+            
+            //System.out.println( "Query Before Replace : --" +  orgUnits.size() + " -- "+  query  );
+            
+            if( periods != null && periods.size() > 0 )
+            {
+                Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers( Period.class, periods ) );
+                String periodsByComma = getCommaDelimitedString( periodIds );
+                query = query.replace( Lookup.PERIODID_BY_COMMA, periodsByComma );
+            }
+            else
+            {
+                query = query.replace( Lookup.PERIODID_BY_COMMA, "-1" );
+            }
+            
+            if( orgUnits != null && orgUnits.size() > 0 )
+            {
+                Collection<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class, orgUnits ) );
+                String orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+                query = query.replace( Lookup.ORGUNITID_BY_COMMA, orgUnitIdsByComma );
+            }
+            else
+            {
+                query = query.replace( Lookup.ORGUNITID_BY_COMMA, "-1" );
+            }
+            
+            //System.out.println( "Query After Replace : --" +  query );
+            
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer orgUnitId = rs.getInt( 1 );
+                Integer dataElementId = rs.getInt( 2 );
+                Integer periodId = rs.getInt( 3 );
+                Double qtyValidated = rs.getDouble( 4 );
+                if( qtyValidated != null )
+                {
+                    aggregationResultMap.put( orgUnitId+":"+dataElementId+":"+periodId, qtyValidated );
+                }
+            }
+        }
+        catch( Exception e )
+        {
+            System.out.println("Exception :"+ e.getMessage() );
+        }
+        
+        return aggregationResultMap;
+    }
+
     public Double calculateOverallUnadjustedPBFAmount( Period period, OrganisationUnit orgUnit, DataSet dataSet )
     {
         Double overAllAdjustedAmt = null;

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultTariffDataValueService.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultTariffDataValueService.java	2014-05-31 13:40:53 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultTariffDataValueService.java	2014-07-30 11:58:29 +0000
@@ -3,6 +3,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
+import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
@@ -131,4 +132,9 @@
     {
         return tariffDataValueStore.getTariffDataValue( orgunitgroupId, organisationUnitId, dataSetId, dataElementId, date );
     }
+    
+    public Set<Integer> getOrgUnitGroupsByDataset( Integer dataSetId, String orgUnitIds )
+    {
+        return tariffDataValueStore.getOrgUnitGroupsByDataset( dataSetId, orgUnitIds );
+    }
 }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateTariffDataValueStore.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateTariffDataValueStore.java	2014-05-31 13:40:53 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateTariffDataValueStore.java	2014-07-30 11:58:29 +0000
@@ -4,7 +4,9 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.hibernate.Criteria;
 import org.hibernate.Session;
@@ -296,16 +298,17 @@
                                             " where '" + curPeriod + "'  between date(td.startdate) and date(td.enddate) " +
                                                 " and orgunitgroupid in ( " + orgUnitGroup.getId() + ") " +
                                                 " and datasetid in ( " +dataSet.getId() + ") "+
+                                                " and organisationunitid in ("+ orgUnitBranchIds +") "+
                                                 " )asd "+
                                                 " group by asd.dataelementid,asd.orgunitgroupid,datasetid " +
                                                 " )sag1 " +
                                                 " inner join tariffdatavalue td on td.dataelementid=sag1.dataelementid " +
                                                 " where td.orgunitgroupid=sag1.orgunitgroupid " + 
                                                 " and td.datasetid=sag1.datasetid " +
-                                                " and sag1.level=td.orgunitlevelid " +
-                                                " and td.organisationunitid in ("+ orgUnitBranchIds +") ";
+                                                " and sag1.level=td.orgunitlevelid ";
+                                                //" and td.organisationunitid in ("+ orgUnitBranchIds +") ";
             
-            //System.out.println("Query: " + query );
+            System.out.println("Query: " + query );
             SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
             while ( rs.next() )
             {
@@ -323,6 +326,33 @@
         return tariffDataValueMap;
     }
     
+    public Set<Integer> getOrgUnitGroupsByDataset( Integer dataSetId, String orgUnitIds )
+    {
+        Set<Integer> orgUnitGroupIds = new HashSet<Integer>();
+        
+        try
+        {
+            String query = "select orgunitgroupid from tariffdatavalue " + 
+                            " WHERE " +
+                                " datasetid = " + dataSetId + " AND " +
+                                " organisationunitid IN (" + orgUnitIds + ")";
+            
+            System.out.println( query );
+            
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+            while( rs.next() )
+            {
+                orgUnitGroupIds.add( rs.getInt( 1 ) );
+            }
+        }
+        catch( Exception e )
+        {
+            System.out.println("In getOrgUnitGroupsByDataset Exception :"+ e.getMessage() );            
+        }
+        
+        return orgUnitGroupIds;
+    }
     public String getTariffDataValue( Integer orgunitgroupId, Integer dataSetId, Integer dataElementId, String date )
     {
         String value = null;

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateUtilizationRateStore.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateUtilizationRateStore.java	2014-07-28 09:27:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernateUtilizationRateStore.java	2014-07-30 11:58:29 +0000
@@ -141,6 +141,11 @@
                 Double tariff = rs.getDouble( 4 );
                 
                 String value = startRange + ":" + endRange + ":" + tariff;
+                String tempVal = utilizationRatesMap.get( dataElementId );
+                if( tempVal != null )
+                {
+                    value = tempVal +"#" + value;
+                }                    
                 utilizationRatesMap.put( dataElementId, value );
                 //System.out.println( dataElementId + " : " + value );
             }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/quality/dataentry/GetOrganisationUnitForMaxAction.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/quality/dataentry/GetOrganisationUnitForMaxAction.java	2014-07-17 13:15:11 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/quality/dataentry/GetOrganisationUnitForMaxAction.java	2014-07-30 11:58:29 +0000
@@ -92,8 +92,7 @@
     {
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
 
-        OrganisationUnitGroup orgUnitGroup = orgUnitGroupService.getOrganisationUnitGroup( Integer
-            .parseInt( orgUnitGroupId ) );
+        OrganisationUnitGroup orgUnitGroup = orgUnitGroupService.getOrganisationUnitGroup( Integer.parseInt( orgUnitGroupId ) );
 
         List<Lookup> lookups = new ArrayList<Lookup>( lookupService.getAllLookupsByType( Lookup.DS_QUALITY_TYPE ) );
 

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/webapp/dhis-web-maintenance-rbf/loadDataEntryForm.vm'
--- local/in/dhis-web-maintenance-rbf/src/main/webapp/dhis-web-maintenance-rbf/loadDataEntryForm.vm	2014-07-28 09:27:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/webapp/dhis-web-maintenance-rbf/loadDataEntryForm.vm	2014-07-30 11:58:29 +0000
@@ -40,6 +40,11 @@
         <option value="$utilizationRateDataElement.id">$utilizationRateDataElement.name</option>
     #end
 </select>
+<select id="pbfDataElementLB" size="10" style="display:none" >
+    #foreach($dataElement in $dataElements )
+        <option value="$dataElement.id">$dataElement.name</option>
+    #end
+</select>
 
 <input type="hidden" id='totalDataElementId' name = 'totalDataElementId' value="$!totalDataElementId" />
 
@@ -246,10 +251,7 @@
                     }
                     
                     calVal();
-                    
-                    $('input').on('keyup', function() {
-                      calVal();
-                    });
+                                        
             	</script>
 			
 			#end
@@ -335,12 +337,18 @@
 					
 					$('#total_'+dataElementId).val(total);
 					
-					allTotal = allTotal + total;
-					
-					$('#all-total').val(allTotal);
-					
-					saveTotalValueInDataValue();
-					
+					var tempPBFDataElements = document.getElementById("pbfDataElementLB");			
+					var allTotal1 = 0.0;
+					for ( i=0; i < tempPBFDataElements.length; i++ )
+					{                
+						var tempDataElementId = tempPBFDataElements.options[i].value;
+						var tempTotal = parseFloat($('#total_'+tempDataElementId).val());
+						allTotal1 = allTotal1 + tempTotal;
+					}								
+			
+					$('#all-total').val(allTotal1);
+					
+					saveTotalValueInDataValue();					
 					
                 }