← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13609: PBF: work in progress PBF Dataentry

 

------------------------------------------------------------
revno: 13609
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-01-07 11:54:34 +0000
message:
  PBF: work in progress PBF Dataentry
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/TariffDataValueService.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueStore.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/LoadDataEntryFormAction.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultTariffDataValueService.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/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	2013-12-21 09:11:48 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java	2014-01-07 11:54:34 +0000
@@ -6,6 +6,8 @@
 {
     public static final String DS_PBF_TYPE = "DS_PBF_TYPE";
     
+    public static final String OC_TARIFF = "OC_TARIFF"; 
+    
     public static final String BANK = "BANK";
     
     private String type;

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueService.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueService.java	2013-12-21 05:25:33 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueService.java	2014-01-07 11:54:34 +0000
@@ -2,10 +2,12 @@
 
 import java.util.Collection;
 import java.util.Date;
+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 TariffDataValueService
 {
@@ -23,5 +25,7 @@
     
     Collection<TariffDataValue> getTariffDataValues( OrganisationUnit organisationUnit, DataSet dataSet );
     
+    Map<Integer, Integer> getTariffDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    
     Collection<TariffDataValue> getTariffDataValues( OrganisationUnit organisationUnit, DataElement dataElement );
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueStore.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueStore.java	2013-12-21 05:25:33 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/TariffDataValueStore.java	2014-01-07 11:54:34 +0000
@@ -2,10 +2,12 @@
 
 import java.util.Collection;
 import java.util.Date;
+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 TariffDataValueStore
 {
@@ -23,5 +25,7 @@
     
     Collection<TariffDataValue> getTariffDataValues( OrganisationUnit organisationUnit, DataSet dataSet );
     
+    Map<Integer, Integer> getTariffDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    
     Collection<TariffDataValue> getTariffDataValues( OrganisationUnit organisationUnit, DataElement dataElement );
 }

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/LoadDataEntryFormAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/LoadDataEntryFormAction.java	2013-12-31 07:59:05 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/LoadDataEntryFormAction.java	2014-01-07 11:54:34 +0000
@@ -1,6 +1,7 @@
 package org.hisp.dhis.pbf.dataentry;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -8,14 +9,19 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.datavalue.DataValue;
 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.TariffDataValueService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -49,6 +55,34 @@
         this.dataValueService = dataValueService;
     }
 
+    private LookupService lookupService;
+    
+    public void setLookupService( LookupService lookupService )
+    {
+        this.lookupService = lookupService;
+    }
+    
+    private DataElementCategoryService dataElementCategoryService;
+    
+    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+    {
+        this.dataElementCategoryService = dataElementCategoryService;
+    }
+    
+    private TariffDataValueService tariffDataValueService;
+    
+    public void setTariffDataValueService( TariffDataValueService tariffDataValueService )
+    {
+        this.tariffDataValueService = tariffDataValueService;
+    }
+    
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
     // -------------------------------------------------------------------------
     // Comparator
     // -------------------------------------------------------------------------
@@ -63,7 +97,7 @@
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
-    
+
     private String orgUnitId;
   
     public void setOrgUnitId( String orgUnitId )
@@ -127,16 +161,27 @@
         return optionCombos;
     }
     
+    private DataElementCategoryOptionCombo tariffOptCombo;
+    
+    public DataElementCategoryOptionCombo getTariffOptCombo()
+    {
+        return tariffOptCombo;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
-
  
     public String execute()
     {
         
         dataValueMap = new HashMap<String, String>();
         
+        
+        Lookup lookup = lookupService.getLookupByName( Lookup.OC_TARIFF );
+
+        DataElementCategoryOptionCombo tariffOptCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( lookup.getValue() ) );
+        
         organisationUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
         
         dataSet = dataSetService.getDataSet( dataSetId );
@@ -146,6 +191,11 @@
         dataElements = new ArrayList<DataElement>( dataSet.getDataElements() );
         
         optionCombos = new ArrayList<DataElementCategoryOptionCombo>();
+        
+        Map<Integer, Integer> tariffDataValueMap = new HashMap<Integer, Integer>();
+        
+        tariffDataValueMap.putAll( tariffDataValueService.getTariffDataValues( organisationUnit, dataSet, period ) );
+
        
         for( DataElement dataElement : dataElements )
         {
@@ -167,6 +217,29 @@
                 {
                     value = dataValue.getValue();
                 }
+                else
+                {                    
+                    if( decombo.getId() == tariffOptCombo.getId() )
+                    {
+                        Integer tariffValue = tariffDataValueMap.get( dataElement.getId() );
+                        
+                        if( tariffValue != null )
+                        {
+                            value = tariffValue+"";
+                            
+                            dataValue = new DataValue( );
+                            dataValue.setDataElement(dataElement);
+                            dataValue.setPeriod(period);
+                            dataValue.setSource(organisationUnit);
+                            dataValue.setValue( value );
+                            dataValue.setStoredBy( currentUserService.getCurrentUsername() );
+                            dataValue.setTimestamp( new Date() );
+                            dataValue.setCategoryOptionCombo( decombo );
+                            
+                            dataValueService.addDataValue( dataValue );                            
+                        }
+                    }
+                }
                 
                 String key = dataElement.getId()+ ":" +  decombo.getId();
                 

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultTariffDataValueService.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultTariffDataValueService.java	2013-12-21 05:25:33 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultTariffDataValueService.java	2014-01-07 11:54:34 +0000
@@ -2,6 +2,7 @@
 
 import java.util.Collection;
 import java.util.Date;
+import java.util.Map;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
@@ -9,6 +10,7 @@
 import org.hisp.dhis.pbf.api.TariffDataValue;
 import org.hisp.dhis.pbf.api.TariffDataValueService;
 import org.hisp.dhis.pbf.api.TariffDataValueStore;
+import org.hisp.dhis.period.Period;
 import org.springframework.transaction.annotation.Transactional;
 
 @Transactional
@@ -71,4 +73,8 @@
         return tariffDataValueStore.getTariffDataValues( organisationUnit, dataElement );
     }
 
+    public Map<Integer, Integer> getTariffDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        return tariffDataValueStore.getTariffDataValues( organisationUnit, dataSet, period );
+    }
 }

=== 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	2013-12-24 12:23:11 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernateTariffDataValueStore.java	2014-01-07 11:54:34 +0000
@@ -1,7 +1,10 @@
 package org.hisp.dhis.pbf.impl;
 
+import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.hibernate.Criteria;
 import org.hibernate.Session;
@@ -13,6 +16,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.pbf.api.TariffDataValue;
 import org.hisp.dhis.pbf.api.TariffDataValueStore;
+import org.hisp.dhis.period.Period;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
 
 public class HibernateTariffDataValueStore implements TariffDataValueStore
 {
@@ -26,6 +32,13 @@
     {
         this.sessionFactory = sessionFactory;
     }
+    
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
 
     // -------------------------------------------------------------------------
     // TariffDataValue
@@ -105,4 +118,35 @@
         return criteria.list();
     }
 
+    public Map<Integer, Integer> getTariffDataValues( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        Map<Integer, Integer> tariffDataValueMap = new HashMap<Integer, Integer>();
+        
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        String curPeriod = simpleDateFormat.format( period.getEndDate() );
+        
+        try
+        {
+            String query = "SELECT dataelementid, value FROM tariffdatavalue " +
+                            " WHERE " +
+                                " organisationunitid = " + organisationUnit.getId() + " AND " +
+                                " datasetid = " + dataSet.getId() + " AND " +
+                                " startdate <= '" + curPeriod + "' AND "+ 
+                                " enddate >= '" + curPeriod +"'";
+            
+            SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+            while ( rs.next() )
+            {
+                Integer dataElementId = rs.getInt( 1 );
+                Integer value = rs.getInt( 2 );
+                tariffDataValueMap.put( dataElementId, value );
+            }
+        }
+        catch( Exception e )
+        {
+            System.out.println("In getTariffDataValues Exception :"+ e.getMessage() );
+        }
+        
+        return tariffDataValueMap;
+    }
 }

=== 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-01-07 10:10:48 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml	2014-01-07 11:54:34 +0000
@@ -8,6 +8,7 @@
     
     <bean id="org.hisp.dhis.pbf.api.TariffDataValueStore" class="org.hisp.dhis.pbf.impl.HibernateTariffDataValueStore">
         <property name="sessionFactory" ref="sessionFactory" />
+        <property name="jdbcTemplate" ref="jdbcTemplate" />
     </bean>
     
     <bean id="org.hisp.dhis.pbf.api.TariffDataValueService" class="org.hisp.dhis.pbf.impl.DefaultTariffDataValueService">
@@ -101,7 +102,6 @@
     </bean>
     
     
-    
 <!--  PBF Data Entry -->
 
 	<bean id="org.hisp.dhis.pbf.dataentry.PageInitAction" class="org.hisp.dhis.pbf.dataentry.PageInitAction" scope="prototype">
@@ -133,7 +133,11 @@
 	 <bean id="org.hisp.dhis.pbf.dataentry.LoadDataEntryFormAction" class="org.hisp.dhis.pbf.dataentry.LoadDataEntryFormAction" scope="prototype">   
 		<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
 		<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService"/>
-		<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService"/>  
+		<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService"/>
+		<property name="lookupService" ref="org.hisp.dhis.pbf.api.LookupService" />		
+		<property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
+		<property name="tariffDataValueService" ref="org.hisp.dhis.pbf.api.TariffDataValueService"/>
+		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
 	 </bean>    
     
     <!-- Save Value -->