← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17607: local/in Maintenance RBF work in progress

 

------------------------------------------------------------
revno: 17607
committer: Mithilesh Kumar Thakur <mithilesh.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-11-28 09:40:56 +0000
message:
  local/in Maintenance RBF work in progress
modified:
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerService.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerStore.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/DefaultPartnerService.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernatePartnerStore.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/RemovePartnerAction.java
  local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/SavePartnerDetailsResultAction.java
  local/in/dhis-web-maintenance-rbf/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-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerService.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerService.java	2014-11-20 06:34:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerService.java	2014-11-28 09:40:56 +0000
@@ -7,7 +7,9 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.option.Option;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
 
 /**
  * @author Mithilesh Kumar Thakur
@@ -36,4 +38,6 @@
     
     Set<OrganisationUnit> getPartnerOrganisationUnits( Integer dataSetId, Integer dataElementId, Integer optionId, String startDate, String endDate );
     
+    Map<Integer, Option> getPartners( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    
 }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerStore.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerStore.java	2014-11-20 06:34:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/api/PartnerStore.java	2014-11-28 09:40:56 +0000
@@ -7,7 +7,9 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.option.Option;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
 
 /**
  * @author Mithilesh Kumar Thakur
@@ -36,4 +38,6 @@
     
     Set<OrganisationUnit> getPartnerOrganisationUnits( Integer dataSetId, Integer dataElementId, Integer optionId, String startDate, String endDate );
     
+    Map<Integer, Option> getPartners( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    
 }

=== 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-11-12 09:32:10 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/dataentry/LoadDataEntryFormAction.java	2014-11-28 09:40:56 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.rbf.api.LookupService;
 import org.hisp.dhis.rbf.api.PBFDataValue;
 import org.hisp.dhis.rbf.api.PBFDataValueService;
+import org.hisp.dhis.rbf.api.PartnerService;
 import org.hisp.dhis.rbf.api.TariffDataValueService;
 import org.hisp.dhis.rbf.api.UtilizationRateService;
 import org.hisp.dhis.user.CurrentUserService;
@@ -144,6 +145,10 @@
     private DataElementService dataElementService;
     
     @Autowired
+    private PartnerService partnerService;
+
+    
+    @Autowired
     private DataElementCategoryService categoryService;
     
     private I18nService i18nService;
@@ -403,6 +408,7 @@
 
         // find parent
         Constant tariff_authority = constantService.getConstantByName( TARIFF_SETTING_AUTHORITY );
+        
         int tariff_setting_authority = 0;
         if ( tariff_authority == null )
         {
@@ -424,16 +430,61 @@
         }
         
         
-        
-        
-        
-        
         OrganisationUnitGroup orgUnitGroup = findPBFOrgUnitGroupforTariff( organisationUnit, dataSet.getId(), orgUnitBranchIds );
         if( orgUnitGroup != null )
         {
             tariffDataValueMap.putAll( tariffDataValueService.getTariffDataValues( orgUnitGroup, orgUnitBranchIds, dataSet, period ) );
         }
         
+        Map<Integer, Option> partnerMap = new HashMap<Integer, Option>();
+        
+        if( organisationUnit != null && dataSet != null && period != null  )
+        {
+            partnerMap.putAll( partnerService.getPartners( organisationUnit, dataSet, period ) );
+        }
+        
+        // setting partner in PBF DataValue
+        
+        for ( DataElement de : dataElements )
+        {
+            Option option = partnerMap.get( de.getId() );
+            
+            if ( option != null )
+            {   
+                //System.out.println( " Inside add partner in PBF Data Value  is : " + de.getName() );
+                
+                PBFDataValue pbfDataValue = pbfDataValueService.getPBFDataValue( organisationUnit, dataSet, period, de );
+                
+                if( pbfDataValue == null )
+                {
+                    pbfDataValue = new PBFDataValue();
+                    
+                    pbfDataValue.setDataSet( dataSet );
+                    pbfDataValue.setDataElement( de );
+                    pbfDataValue.setPeriod( period );
+                    pbfDataValue.setOrganisationUnit( organisationUnit );
+                    pbfDataValue.setStoredBy( currentUserService.getCurrentUsername() );
+                    pbfDataValue.setOption( option );
+                    pbfDataValue.setTimestamp( new Date() );
+                    
+                    pbfDataValueService.addPBFDataValue( pbfDataValue );
+                }
+
+                else
+                {
+                    //System.out.println( " Inside update partner In PBF Data Value is : " +  de.getName() );
+                    
+                    pbfDataValue.setOption( option );
+                    pbfDataValue.setTimestamp( new Date() );
+                    pbfDataValue.setStoredBy( currentUserService.getCurrentUsername() );
+                    
+                    pbfDataValueService.updatePBFDataValue( pbfDataValue );
+                }
+                                
+            }
+            
+        }
+
         //System.out.println( orgUnitBranchIds + " : " + orgUnitGroup.getId() + " : " + organisationUnit.getId() + " : " + dataSet.getId() );
         
         
@@ -465,6 +516,23 @@
                     pbfDataValueService.updatePBFDataValue( pbfDataValue );
                 }
             }
+            
+            /*
+            if ( pbfDataValue.getOption() == null || pbfDataValue.getOption().toString().trim().equals( "" ) )
+            {
+                Option option = partnerMap.get( de.getId() );
+                if ( option != null )
+                {
+                    pbfDataValue.setOption( option );
+                    pbfDataValue.setStoredBy( currentUserService.getCurrentUsername() );
+                    pbfDataValue.setTimestamp( new Date() );
+                                        
+                    pbfDataValueService.updatePBFDataValue( pbfDataValue );
+                }
+                
+            }
+            */
+            
             pbfDataValueMap.put( de, pbfDataValue );
         }
 
@@ -472,7 +540,7 @@
         tempDes.addAll( dataElements );
 
         tempDes.removeAll( pbfDataValueMap.keySet() );
-
+               
         for ( DataElement de : tempDes )
         {
             Double tariffAmount = tariffDataValueMap.get( de.getId() );
@@ -503,9 +571,37 @@
 
                 pbfDataValueMap.put( de, pbfDataValue );
             }
+            
+            Option option = partnerMap.get( de.getId() );
+            if ( option != null )
+            {
+                PBFDataValue pbfDataValue = new PBFDataValue();
+
+                pbfDataValue.setDataSet( dataSet );
+                pbfDataValue.setDataElement( de );
+                pbfDataValue.setPeriod( period );
+                pbfDataValue.setOrganisationUnit( organisationUnit );
+                pbfDataValue.setOption( option );
+                pbfDataValue.setStoredBy( currentUserService.getCurrentUsername() );
+                pbfDataValue.setTimestamp( new Date() );
+
+                //pbfDataValueService.addPBFDataValue( pbfDataValue );
+                pbfDataValueMap.put( de, pbfDataValue );
+            }
+            else
+            {
+                PBFDataValue pbfDataValue = new PBFDataValue();
+
+                pbfDataValue.setDataSet( dataSet );
+                pbfDataValue.setDataElement( de );
+                pbfDataValue.setPeriod( period );
+                pbfDataValue.setOrganisationUnit( organisationUnit );
+                pbfDataValue.setOption( null );
+
+                pbfDataValueMap.put( de, pbfDataValue );
+            }
         }
         
-
         /*
          * for( DataElement dataElement : dataElements ) {
          * //DataElementCategoryOptionCombo decoc =

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPartnerService.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPartnerService.java	2014-11-20 06:34:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/DefaultPartnerService.java	2014-11-28 09:40:56 +0000
@@ -7,7 +7,9 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.option.Option;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.rbf.api.Partner;
 import org.hisp.dhis.rbf.api.PartnerService;
 import org.hisp.dhis.rbf.api.PartnerStore;
@@ -90,6 +92,11 @@
     public Set<OrganisationUnit> getPartnerOrganisationUnits( Integer dataSetId, Integer dataElementId, Integer optionId, String startDate, String endDate )
     {
         return partnerStore.getPartnerOrganisationUnits( dataSetId, dataElementId, optionId, startDate, endDate );
-    }   
+    } 
+    
+    public Map<Integer, Option> getPartners( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        return partnerStore.getPartners( organisationUnit, dataSet, period );
+    }     
     
 }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernatePartnerStore.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernatePartnerStore.java	2014-11-20 06:34:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/impl/HibernatePartnerStore.java	2014-11-28 09:40:56 +0000
@@ -16,8 +16,11 @@
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.option.Option;
+import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.rbf.api.Partner;
 import org.hisp.dhis.rbf.api.PartnerStore;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,7 +56,9 @@
 
     @Autowired
     private OrganisationUnitService organisationUnitService;
-
+    
+    @Autowired
+    private OptionService optionService;
     // -------------------------------------------------------------------------
     // Partner
     // -------------------------------------------------------------------------
@@ -295,5 +300,68 @@
         return organisationUnits;
 
     }
-
+    
+    // getPartners
+    
+    public Map<Integer, Option> getPartners( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        Map<Integer, Option> partnerMap = new HashMap<Integer, Option>();
+        
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        
+        String curPeriodStartDate = simpleDateFormat.format( period.getStartDate() );
+        
+        String curPeriodEndDate = simpleDateFormat.format( period.getEndDate() );
+        
+        try
+        {
+            String query = "SELECT dataelementid, optionid FROM partner " +
+                " WHERE " +
+                    " organisationunitid = " + organisationUnit.getId() + " AND " +
+                    " datasetid = " + dataSet.getId() + " AND " +
+                    " startdate BETWEEN '" + curPeriodStartDate + "' AND '" + curPeriodEndDate + "' AND " +  
+                    " enddate BETWEEN '" + curPeriodStartDate + "' AND '" + curPeriodEndDate + "' ";
+            
+            
+            /*
+            String query = "SELECT dataelementid, optionid FROM partner " +
+                            " WHERE " +
+                                " organisationunitid = " + organisationUnit.getId() + " AND " +
+                                " datasetid = " + dataSet.getId() + " AND " +
+                                " startdate >= '" + curPeriodStartDate + "' AND "+ 
+                                " enddate <= '" + curPeriodEndDate +"'";
+            
+            
+                        
+            String query = "SELECT dataelementid, optionid FROM partner " +
+                " WHERE " +
+                    " organisationunitid = " + organisationUnit.getId() + " AND " +
+                    " datasetid = " + dataSet.getId() + " AND " +
+                    " startdate <= '" + curPeriodEndDate + "' AND "+ 
+                    " enddate >= '" + curPeriodEndDate +"'";
+            
+            
+            */
+            
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer dataElementId = rs.getInt( 1 );
+                Integer optionId = rs.getInt( 2 );
+                
+                if ( optionId != null )
+                {
+                    Option option = optionService.getOption( optionId );
+                    partnerMap.put( dataElementId, option );
+                    
+                }
+            }
+        }
+        catch( Exception e )
+        {
+            System.out.println("In getPartner Exception :"+ e.getMessage() );
+        }
+        
+        return partnerMap;
+    }
 }

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/RemovePartnerAction.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/RemovePartnerAction.java	2014-11-20 06:34:00 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/RemovePartnerAction.java	2014-11-28 09:40:56 +0000
@@ -1,10 +1,8 @@
 package org.hisp.dhis.rbf.partner.action;
 
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
@@ -14,10 +12,7 @@
 import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.rbf.api.PBFDataValue;
-import org.hisp.dhis.rbf.api.PBFDataValueService;
 import org.hisp.dhis.rbf.api.Partner;
 import org.hisp.dhis.rbf.api.PartnerService;
 import org.hisp.dhis.user.CurrentUserService;
@@ -33,9 +28,10 @@
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
-    
+    /*
     @Autowired
     private PBFDataValueService pbfDataValueService;
+    */
     
     @Autowired
     private OrganisationUnitService organisationUnitService;
@@ -120,16 +116,21 @@
         
         //Period period = periodService.getPeriod( sDate, eDate, dataSet.getPeriodType() );
         
+        /*
         List<Period> periodsBetweenDates = new ArrayList<Period>();
         
         periodsBetweenDates =  new ArrayList<Period>( periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), sDate, eDate ) );
         
+        */
+        
         //periodService.getPeriod( arg0, arg1, arg2 )
         
         //Option option = optionService.getOption( optionSetId );
         
         Set<OrganisationUnit> partnerOrgUnits = new HashSet<OrganisationUnit>( partnerService.getPartnerOrganisationUnits( dataSetId, dataElementId, optionSetId, startDate, endDate ) );
-
+        
+        // Delete partner from PBF dataValue
+        /*
         for ( OrganisationUnit organisationUnit : partnerOrgUnits )
         {
             //System.out.println( " Period Id " + period.getId() );
@@ -160,6 +161,7 @@
             
             //System.out.println( " orgUnit name -- " + organisationUnit.getName() );
         }
+        */
         
         // Delete partner from partner
       

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/SavePartnerDetailsResultAction.java'
--- local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/SavePartnerDetailsResultAction.java	2014-11-25 07:11:06 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/java/org/hisp/dhis/rbf/partner/action/SavePartnerDetailsResultAction.java	2014-11-28 09:40:56 +0000
@@ -16,10 +16,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
-import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.rbf.api.PBFDataValue;
-import org.hisp.dhis.rbf.api.PBFDataValueService;
 import org.hisp.dhis.rbf.api.Partner;
 import org.hisp.dhis.rbf.api.PartnerService;
 import org.hisp.dhis.user.CurrentUserService;
@@ -42,13 +39,14 @@
     {
         this.selectionTreeManager = selectionTreeManager;
     }
-    
+    /*
     private PBFDataValueService pbfDataValueService;
     
     public void setPbfDataValueService(PBFDataValueService pbfDataValueService) 
     {
         this.pbfDataValueService = pbfDataValueService;
     }
+    */
     
     @Autowired
     private OrganisationUnitService organisationUnitService;
@@ -144,9 +142,9 @@
         //periodService.getPeriod( arg0, arg1, arg2 )
         
         
-        List<Period> periodsBetweenDates = new ArrayList<Period>();
+        //List<Period> periodsBetweenDates = new ArrayList<Period>();
         
-        periodsBetweenDates =  new ArrayList<Period>( periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), sDate, eDate ) );
+        //periodsBetweenDates =  new ArrayList<Period>( periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), sDate, eDate ) );
         
         Option option = optionService.getOption( optionSetId );
         
@@ -177,6 +175,7 @@
         
         dataSetSources.retainAll( orgUnitList );
         
+        /*
         for ( OrganisationUnit organisationUnit : dataSetSources )
         {
             if( periodsBetweenDates!= null  && periodsBetweenDates.size() > 0 )
@@ -222,6 +221,8 @@
             //System.out.println( " orgUnit name -- " + organisationUnit.getName() );
         }
         
+        */
+        
         // save partnet in partner
         
         //System.out.println( " Data Set source size "  + dataSetSources.size() );

=== modified file 'local/in/dhis-web-maintenance-rbf/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-maintenance-rbf/src/main/resources/META-INF/dhis/beans.xml	2014-11-25 07:11:06 +0000
+++ local/in/dhis-web-maintenance-rbf/src/main/resources/META-INF/dhis/beans.xml	2014-11-28 09:40:56 +0000
@@ -825,7 +825,7 @@
         class="org.hisp.dhis.rbf.partner.action.SavePartnerDetailsResultAction"
         scope="prototype">
         <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
-        <property name="pbfDataValueService" ref="org.hisp.dhis.rbf.api.PBFDataValueService" />
+        <!--<property name="pbfDataValueService" ref="org.hisp.dhis.rbf.api.PBFDataValueService" />-->
     </bean>