← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14725: Workinprogress: PBF Adjustment Functionality

 

------------------------------------------------------------
revno: 14725
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-07 13:32:43 +0100
message:
  Workinprogress: PBF Adjustment Functionality
modified:
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueService.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueStore.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFAggregationService.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFDataValueService.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernatePBFDataValueStore.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernateTariffDataValueStore.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentAction.java
  local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml


--
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-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java	2014-04-02 16:32:50 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java	2014-04-07 12:32:43 +0000
@@ -7,6 +7,9 @@
 @SuppressWarnings("serial")
 public class Lookup extends BaseNameableObject implements Serializable
 {
+    public final static String PAYMENT_ADJUSTMENT_AMOUNT_DE = "PAYMENT_ADJUSTMENT_AMOUNT_DE";
+    public final static String TARIFF_SETTING_AUTHORITY = "TARIFF_SETTING_AUTHORITY";
+
     public static final String DS_PBF_TYPE = "DS_PBF_TYPE";    
     public static final String DS_QUALITY_TYPE = "DS_QUALITY_TYPE";
     public static final String DS_PAYMENT_TYPE = "DS_PAYMENT_TYPE";

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueService.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueService.java	2014-01-07 17:56:19 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueService.java	2014-04-07 12:32:43 +0000
@@ -1,25 +1,28 @@
 package org.hisp.dhis.pbf.api;
 
 import java.util.Collection;
+import java.util.Map;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 
-public interface PBFDataValueService 
+public interface PBFDataValueService
 {
 
-	String ID = PBFDataValueService.class.getName();
-	
+    String ID = PBFDataValueService.class.getName();
+
     void addPBFDataValue( PBFDataValue pbfDataValue );
-    
+
     void updatePBFDataValue( PBFDataValue pbfDataValue );
-    
+
     void deletePBFDataValue( PBFDataValue pbfDataValue );
-    
+
     PBFDataValue getPBFDataValue( OrganisationUnit organisationUnit, DataSet dataSet, Period period, DataElement dataElement );
-    
+
     Collection<PBFDataValue> getPBFDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    
+    Map<Integer, Double> getPBFDataValues( String orgUnitIds, DataSet dataSet, String periodIds );
 
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueStore.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueStore.java	2014-01-07 17:56:19 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueStore.java	2014-04-07 12:32:43 +0000
@@ -1,23 +1,26 @@
 package org.hisp.dhis.pbf.api;
 
 import java.util.Collection;
+import java.util.Map;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 
-public interface PBFDataValueStore 
+public interface PBFDataValueStore
 {
-	String ID = PBFDataValueStore.class.getName();
-	
+    String ID = PBFDataValueStore.class.getName();
+
     void addPBFDataValue( PBFDataValue pbfDataValue );
-    
+
     void updatePBFDataValue( PBFDataValue pbfDataValue );
-    
+
     void deletePBFDataValue( PBFDataValue pbfDataValue );
-    
+
     PBFDataValue getPBFDataValue( OrganisationUnit organisationUnit, DataSet dataSet, Period period, DataElement dataElement );
-    
+
     Collection<PBFDataValue> getPBFDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    
+    Map<Integer, Double> getPBFDataValues( String orgUnitIds, DataSet dataSet, String periodIds );
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFAggregationService.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFAggregationService.java	2014-03-14 11:22:16 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFAggregationService.java	2014-04-07 12:32:43 +0000
@@ -204,6 +204,72 @@
         return aggregationResultMap;
     }
     
+    
+    public Double calculateOverallQualityScore( Period period, Set<OrganisationUnit> orgUnits, Integer dataSetId, int maxScoreOrgUnitId )
+    {
+        Double overallQualityScore = 0.0;
+        
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+        
+        try
+        {
+            Double maxScore = 0.0;
+            String query = "SELECT dataelementid, (SUM(value) * "+orgUnits.size() +") FROM qualitymaxvalue " +
+                                " WHERE " +
+                                    " startdate <='"+ simpleDateFormat.format( period.getStartDate() ) +"' AND "+
+                                    " enddate >='"+ simpleDateFormat.format( period.getEndDate() ) +"' AND " +
+                                    " organisationunitid = "+ maxScoreOrgUnitId +" AND "+
+                                    " datasetid = " + dataSetId +" AND " +
+                                    " GROUP BY dataelementid";                                
+
+            //System.out.println( query );
+                
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer deId = rs.getInt( 1 );
+                Double value = rs.getDouble( 2 );
+                maxScore += value;
+            }                
+            
+            Collection<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class, orgUnits ) );
+            String orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+            
+            query = "SELECT SUM( CAST ( value AS NUMERIC ) ) FROM datavalue dv "+ 
+                                " INNER JOIN datasetmembers dsm on dsm.dataelementid = dv.dataelementid " +
+                                " WHERE " +
+                                    " dv.periodid = " + period.getId() + " AND "+
+                                    " dv.sourceid IN ("+ orgUnitIdsByComma +") AND " +
+                                    " dsm.datasetid = " + dataSetId;
+            
+            //System.out.println( query );
+            Double qualityScore = 0.0;
+            SqlRowSet rs1 = jdbcTemplate.queryForRowSet( query );
+            if ( rs1.next() )
+            {
+                qualityScore = rs1.getDouble( 1 );
+            }
+            
+            try
+            {
+                if( maxScore != 0.0 )
+                {
+                    overallQualityScore = ( qualityScore / maxScore ) * 100.0;
+                }
+            }
+            catch( Exception e )
+            {
+                
+            }
+        }
+        catch( Exception e )
+        {
+            System.out.println("Exception : "+ e.getMessage() );
+        }
+        
+        return overallQualityScore;
+    }
+
  
     public String importData( Map<String, Double> aggregationResultMap )
     {

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFDataValueService.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFDataValueService.java	2014-01-07 17:56:19 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFDataValueService.java	2014-04-07 12:32:43 +0000
@@ -1,6 +1,7 @@
 package org.hisp.dhis.pbf.impl;
 
 import java.util.Collection;
+import java.util.Map;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
@@ -12,50 +13,60 @@
 import org.springframework.transaction.annotation.Transactional;
 
 @Transactional
-public class DefaultPBFDataValueService implements PBFDataValueService
+public class DefaultPBFDataValueService
+    implements PBFDataValueService
 {
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
 
-	private PBFDataValueStore pbfDataValueStore;
+    private PBFDataValueStore pbfDataValueStore;
 
-	public void setPbfDataValueStore(PBFDataValueStore pbfDataValueStore) 
-	{
-		this.pbfDataValueStore = pbfDataValueStore;
-	}
+    public void setPbfDataValueStore( PBFDataValueStore pbfDataValueStore )
+    {
+        this.pbfDataValueStore = pbfDataValueStore;
+    }
 
     // -------------------------------------------------------------------------
     // PBFDataValue
     // -------------------------------------------------------------------------
 
-	@Override
-	public void addPBFDataValue(PBFDataValue pbfDataValue) 
-	{
-		pbfDataValueStore.addPBFDataValue( pbfDataValue );
-	}
-
-	@Override
-	public void updatePBFDataValue(PBFDataValue pbfDataValue) 
-	{
-		pbfDataValueStore.updatePBFDataValue(pbfDataValue);		
-	}
-
-	@Override
-	public void deletePBFDataValue(PBFDataValue pbfDataValue) 
-	{
-		pbfDataValueStore.deletePBFDataValue(pbfDataValue);		
-	}
-
-	@Override
-	public Collection<PBFDataValue> getPBFDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period) 
-	{
-		return pbfDataValueStore.getPBFDataValues(organisationUnit, dataSet, period);
-	}
-
-	@Override
-	public PBFDataValue getPBFDataValue( OrganisationUnit organisationUnit, DataSet dataSet, Period period, DataElement dataElement ) 
-	{
-		return pbfDataValueStore.getPBFDataValue( organisationUnit, dataSet, period, dataElement );
-	}
+    @Override
+    public void addPBFDataValue( PBFDataValue pbfDataValue )
+    {
+        pbfDataValueStore.addPBFDataValue( pbfDataValue );
+    }
+
+    @Override
+    public void updatePBFDataValue( PBFDataValue pbfDataValue )
+    {
+        pbfDataValueStore.updatePBFDataValue( pbfDataValue );
+    }
+
+    @Override
+    public void deletePBFDataValue( PBFDataValue pbfDataValue )
+    {
+        pbfDataValueStore.deletePBFDataValue( pbfDataValue );
+    }
+
+    @Override
+    public Collection<PBFDataValue> getPBFDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        return pbfDataValueStore.getPBFDataValues( organisationUnit, dataSet, period );
+    }
+
+    @Override
+    public PBFDataValue getPBFDataValue( OrganisationUnit organisationUnit, DataSet dataSet, Period period,
+        DataElement dataElement )
+    {
+        return pbfDataValueStore.getPBFDataValue( organisationUnit, dataSet, period, dataElement );
+    }
+    
+    @Override
+    public Map<Integer, Double> getPBFDataValues( String orgUnitIds, DataSet dataSet, String periodIds )
+    {
+        return pbfDataValueStore.getPBFDataValues( orgUnitIds, dataSet, periodIds );
+    }
+
+
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernatePBFDataValueStore.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernatePBFDataValueStore.java	2014-01-07 17:56:19 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernatePBFDataValueStore.java	2014-04-07 12:32:43 +0000
@@ -1,7 +1,10 @@
 package org.hisp.dhis.pbf.impl;
 
+import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.hibernate.Criteria;
 import org.hibernate.Session;
@@ -14,6 +17,8 @@
 import org.hisp.dhis.pbf.api.PBFDataValueStore;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodStore;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
 
 public class HibernatePBFDataValueStore implements PBFDataValueStore
 {
@@ -36,43 +41,49 @@
         this.periodStore = periodStore;
     }
 
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+    
     // -------------------------------------------------------------------------
     // PBFDataValue
     // -------------------------------------------------------------------------
 
-	@Override
-	public void addPBFDataValue( PBFDataValue pbfDataValue ) 
-	{
-		pbfDataValue.setPeriod( periodStore.reloadForceAddPeriod( pbfDataValue.getPeriod() ) );
+    @Override
+    public void addPBFDataValue( PBFDataValue pbfDataValue ) 
+    {
+	pbfDataValue.setPeriod( periodStore.reloadForceAddPeriod( pbfDataValue.getPeriod() ) );
 
         Session session = sessionFactory.getCurrentSession();
 
         session.save( pbfDataValue );
-	}
+    }
 
-	@Override
-	public void updatePBFDataValue( PBFDataValue pbfDataValue ) 
-	{
-		pbfDataValue.setPeriod( periodStore.reloadForceAddPeriod( pbfDataValue.getPeriod() ) );
+    @Override
+    public void updatePBFDataValue( PBFDataValue pbfDataValue ) 
+    {
+	pbfDataValue.setPeriod( periodStore.reloadForceAddPeriod( pbfDataValue.getPeriod() ) );
 
         Session session = sessionFactory.getCurrentSession();
 
         session.update( pbfDataValue );
-	}
+    }
 
-	@Override
-	public void deletePBFDataValue( PBFDataValue pbfDataValue ) 
-	{
+    @Override
+    public void deletePBFDataValue( PBFDataValue pbfDataValue ) 
+    {
         Session session = sessionFactory.getCurrentSession();
 
         session.delete( pbfDataValue );
-	}
-
-
-	@Override
-	public PBFDataValue getPBFDataValue( OrganisationUnit organisationUnit, DataSet dataSet, Period period, DataElement dataElement ) 
-	{
-		Period storedPeriod = periodStore.reloadPeriod( period );
+    }
+
+    @Override
+    public PBFDataValue getPBFDataValue( OrganisationUnit organisationUnit, DataSet dataSet, Period period, DataElement dataElement ) 
+    {
+	Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -88,12 +99,12 @@
         criteria.add( Restrictions.eq( "dataElement", dataElement ) );
 
         return ( PBFDataValue ) criteria.uniqueResult();
-	}
+    }
 
-	@Override
-	public Collection<PBFDataValue> getPBFDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) 
-	{
-		Period storedPeriod = periodStore.reloadPeriod( period );
+    @Override
+    public Collection<PBFDataValue> getPBFDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) 
+    {
+        Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -108,6 +119,34 @@
         criteria.add( Restrictions.eq( "dataSet", dataSet ) );
 
         return criteria.list();
-	}
+    }
 
+    public Map<Integer, Double> getPBFDataValues( String orgUnitIds, DataSet dataSet, String periodIds )
+    {
+        Map<Integer, Double> pbfDataValueMap = new HashMap<Integer, Double>();
+        
+        try
+        {
+            String query = "SELECT dataelementid, SUM( CAST( qtyvalidated AS NUMERIC) ) FROM pbfdatavalue " +                                
+                                " WHERE " + 
+                                    " organisationunitid IN (" + orgUnitIds + ") AND " +
+                                    " datasetid = "+ dataSet.getId() + " AND " +
+                                    " periodid IN (" + periodIds + ") " +
+                                    " GROUP BY dataelementid";
+                
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer dataElementId = rs.getInt( 1 );
+                Double value = rs.getDouble( 2 );
+                pbfDataValueMap.put( dataElementId, value );
+            }
+        }
+        catch( Exception e )
+        {
+            System.out.println("In getTariffDataValues Exception :"+ e.getMessage() );
+        }
+        
+        return pbfDataValueMap;
+    }
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernateTariffDataValueStore.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernateTariffDataValueStore.java	2014-01-18 12:25:59 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernateTariffDataValueStore.java	2014-04-07 12:32:43 +0000
@@ -150,5 +150,4 @@
         
         return tariffDataValueMap;
     }
-
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentAction.java	2014-04-05 12:21:33 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentAction.java	2014-04-07 12:32:43 +0000
@@ -1,8 +1,16 @@
 package org.hisp.dhis.pbf.payment.action;
 
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
+import org.hisp.dhis.constant.Constant;
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -12,7 +20,9 @@
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.pbf.api.Lookup;
 import org.hisp.dhis.pbf.api.LookupService;
+import org.hisp.dhis.pbf.api.PBFDataValueService;
 import org.hisp.dhis.pbf.api.QualityMaxValueService;
 import org.hisp.dhis.pbf.api.TariffDataValueService;
 import org.hisp.dhis.period.Period;
@@ -41,6 +51,9 @@
     private DataValueService dataValueService;
 
     @Autowired
+    private PBFDataValueService pbfDataValueService;
+    
+    @Autowired
     private TariffDataValueService tariffDataValueService;
 
     @Autowired
@@ -61,6 +74,19 @@
     // -------------------------------------------------------------------------
     // Input / Output
     // -------------------------------------------------------------------------
+    private Map<Integer, Double> pbfQtyMap = new HashMap<Integer, Double>();
+
+    public Map<Integer, Double> getPbfQtyMap()
+    {
+        return pbfQtyMap;
+    }
+
+    private Map<Integer, Double> pbfTariffMap = new HashMap<Integer, Double>();
+
+    public Map<Integer, Double> getPbfTariffMap()
+    {
+        return pbfTariffMap;
+    }
 
     private String orgUnitId;
 
@@ -96,22 +122,60 @@
         
         Period period = PeriodType.getPeriodFromIsoString( periodIso );
         
-        
-        //----------------------------------------------
+        period = periodService.reloadPeriod( period );
+        
+        Set<Period> periods = new HashSet<Period>( periodService.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ) );
+        Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers( Period.class, periods ) );
+        String periodIdsByComma = getCommaDelimitedString( periodIds );
+        
+        Set<DataElement> dataElements = new HashSet<DataElement>( selDataSet.getDataElements() );
+        
+        Set<OrganisationUnit> pbfQtyOrgUnits = new HashSet<OrganisationUnit>();
+        pbfQtyOrgUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( selOrgUnit.getId() ) );
+        pbfQtyOrgUnits.retainAll( selDataSet.getSources() );
+        Collection<Integer> orgUnitIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class, pbfQtyOrgUnits ) );
+        String orgUnitIdsByComma = getCommaDelimitedString( orgUnitIds );
+        
+        //--------------------------------------------------------
         // Quantity Calculation
-        //----------------------------------------------
-        
-        Map<DataElement, Double> pbfQtyMap = new HashMap<DataElement, Double>();
-        
-        //-------------------------------------------------
+        //--------------------------------------------------------
+        
+        pbfQtyMap.putAll( pbfDataValueService.getPBFDataValues( orgUnitIdsByComma, selDataSet, periodIdsByComma ) );
+        
+        //--------------------------------------------------------
         // Quantity Tariff Calculation
-        //-------------------------------------------------
-        Map<DataElement, Double> pbfTariffMap = new HashMap<DataElement, Double>();
-        
-        //-------------------------------------------------
-        // 
-        //-------------------------------------------------
+        //--------------------------------------------------------
+        Constant tariff_authority = constantService.getConstantByName( Lookup.TARIFF_SETTING_AUTHORITY );
+        int tariff_setting_authority = 1;
+        if ( tariff_authority != null )
+        {
+            tariff_setting_authority = (int) tariff_authority.getValue();
+        }
+
+        OrganisationUnit tariffOrgUnit = findParentOrgunitforTariff( selOrgUnit, tariff_setting_authority );
+        
+        if( tariffOrgUnit != null ) 
+        {
+            pbfTariffMap.putAll( tariffDataValueService.getTariffDataValues( tariffOrgUnit, selDataSet, period ) );
+        }
+        
+        //-----------------------------------------------------------
+        // QualityScore
+        //-----------------------------------------------------------
         
         return SUCCESS;
     }
+    
+    public OrganisationUnit findParentOrgunitforTariff( OrganisationUnit organisationUnit, Integer tariffOULevel )
+    {
+        Integer ouLevel = organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() );
+        if ( tariffOULevel == ouLevel )
+        {
+            return organisationUnit;
+        }
+        else
+        {
+            return findParentOrgunitforTariff( organisationUnit.getParent(), tariffOULevel );
+        }
+    }
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml	2014-04-05 12:21:33 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml	2014-04-07 12:32:43 +0000
@@ -19,6 +19,7 @@
     <bean id="org.hisp.dhis.pbf.api.PBFDataValueStore" class="org.hisp.dhis.pbf.impl.HibernatePBFDataValueStore">
         <property name="sessionFactory" ref="sessionFactory" />
         <property name="periodStore" ref="org.hisp.dhis.period.PeriodStore" />
+        <property name="jdbcTemplate" ref="jdbcTemplate" />
     </bean>
     
     <bean id="org.hisp.dhis.pbf.api.TariffDataValueService" class="org.hisp.dhis.pbf.impl.DefaultTariffDataValueService">