dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27381
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13627: PBF Dataentry: PBFDataValue object
------------------------------------------------------------
revno: 13627
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-01-07 17:56:19 +0000
message:
PBF Dataentry: PBFDataValue object
added:
local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValue.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/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/resources/org/hisp/dhis/pbf/hibernate/PBFDataValue.hbm.xml
modified:
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/SaveValueAction.java
local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml
local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/javascript/pbfDataEntry.js
local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/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
=== added file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValue.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValue.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValue.java 2014-01-07 17:56:19 +0000
@@ -0,0 +1,196 @@
+package org.hisp.dhis.pbf.api;
+
+import java.io.Serializable;
+import java.util.Date;
+
+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 class PBFDataValue implements Serializable
+{
+ private OrganisationUnit organisationUnit;
+
+ private DataElement dataElement;
+
+ private DataSet dataSet;
+
+ private Period period;
+
+ private Integer quantityReported;
+
+ private Integer quantityValidated;
+
+ private Double tariffAmount;
+
+ private String storedBy;
+
+ private Date timestamp;
+
+ private String comment;
+
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+ public PBFDataValue()
+ {
+
+ }
+
+ public PBFDataValue( OrganisationUnit organisationUnit, DataElement dataElement, DataSet dataSet, Period period, Integer quantityReported, Integer quantityValidated, Double tariffAmount )
+ {
+ this.organisationUnit = organisationUnit;
+ this.dataElement = dataElement;
+ this.dataSet = dataSet;
+ this.period = period;
+ this.quantityReported = quantityReported;
+ this.quantityValidated = quantityValidated;
+ this.tariffAmount = tariffAmount;
+ }
+
+ // -------------------------------------------------------------------------
+ // hashCode and equals
+ // -------------------------------------------------------------------------
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+
+ if ( o == null )
+ {
+ return false;
+ }
+
+ if ( !(o instanceof PBFDataValue) )
+ {
+ return false;
+ }
+
+ final PBFDataValue other = (PBFDataValue) o;
+
+ return dataElement.equals( other.getDataElement() ) && dataSet.equals( other.getDataSet() ) && organisationUnit.equals( other.getOrganisationUnit() ) && period.equals( other.getPeriod() );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+
+ result = result * prime + dataSet.hashCode();
+ result = result * prime + dataElement.hashCode();
+ result = result * prime + organisationUnit.hashCode();
+ result = result * prime + period.hashCode();
+
+ return result;
+ }
+
+ // -------------------------------------------------------------------------
+ // Getters and setters
+ // -------------------------------------------------------------------------
+
+ public OrganisationUnit getOrganisationUnit()
+ {
+ return organisationUnit;
+ }
+
+ public void setOrganisationUnit(OrganisationUnit organisationUnit)
+ {
+ this.organisationUnit = organisationUnit;
+ }
+
+ public DataElement getDataElement()
+ {
+ return dataElement;
+ }
+
+ public void setDataElement(DataElement dataElement)
+ {
+ this.dataElement = dataElement;
+ }
+
+ public DataSet getDataSet()
+ {
+ return dataSet;
+ }
+
+ public void setDataSet(DataSet dataSet)
+ {
+ this.dataSet = dataSet;
+ }
+
+ public Period getPeriod()
+ {
+ return period;
+ }
+
+ public void setPeriod(Period period)
+ {
+ this.period = period;
+ }
+
+ public Integer getQuantityReported()
+ {
+ return quantityReported;
+ }
+
+ public void setQuantityReported(Integer quantityReported)
+ {
+ this.quantityReported = quantityReported;
+ }
+
+ public Integer getQuantityValidated()
+ {
+ return quantityValidated;
+ }
+
+ public void setQuantityValidated(Integer quantityValidated)
+ {
+ this.quantityValidated = quantityValidated;
+ }
+
+ public Double getTariffAmount()
+ {
+ return tariffAmount;
+ }
+
+ public void setTariffAmount(Double tariffAmount)
+ {
+ this.tariffAmount = tariffAmount;
+ }
+
+ public String getStoredBy()
+ {
+ return storedBy;
+ }
+
+ public void setStoredBy(String storedBy)
+ {
+ this.storedBy = storedBy;
+ }
+
+ public Date getTimestamp()
+ {
+ return timestamp;
+ }
+
+ public void setTimestamp(Date timestamp)
+ {
+ this.timestamp = timestamp;
+ }
+
+ public String getComment()
+ {
+ return comment;
+ }
+
+ public void setComment(String comment)
+ {
+ this.comment = comment;
+ }
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueService.java 2014-01-07 17:56:19 +0000
@@ -0,0 +1,25 @@
+package org.hisp.dhis.pbf.api;
+
+import java.util.Collection;
+
+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
+{
+
+ 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 );
+
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/PBFDataValueStore.java 2014-01-07 17:56:19 +0000
@@ -0,0 +1,23 @@
+package org.hisp.dhis.pbf.api;
+
+import java.util.Collection;
+
+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
+{
+ 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 );
+}
=== 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 2014-01-07 12:44:16 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/LoadDataEntryFormAction.java 2014-01-07 17:56:19 +0000
@@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
@@ -18,6 +20,8 @@
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.PBFDataValue;
+import org.hisp.dhis.pbf.api.PBFDataValueService;
import org.hisp.dhis.pbf.api.TariffDataValueService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
@@ -34,7 +38,15 @@
// Dependencies
// -------------------------------------------------------------------------
- private OrganisationUnitService organisationUnitService;
+
+ private PBFDataValueService pbfDataValueService;
+
+ public void setPbfDataValueService(PBFDataValueService pbfDataValueService)
+ {
+ this.pbfDataValueService = pbfDataValueService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
{
@@ -98,7 +110,14 @@
// Input/Output
// -------------------------------------------------------------------------
- private String orgUnitId;
+ private Map<DataElement, PBFDataValue> pbfDataValueMap;
+
+ public Map<DataElement, PBFDataValue> getPbfDataValueMap()
+ {
+ return pbfDataValueMap;
+ }
+
+ private String orgUnitId;
public void setOrgUnitId( String orgUnitId )
{
@@ -170,7 +189,8 @@
private DataElementCategoryOptionCombo qValOptCombo;
- public DataElementCategoryOptionCombo getqValOptCombo() {
+ public DataElementCategoryOptionCombo getqValOptCombo()
+ {
return qValOptCombo;
}
@@ -178,8 +198,6 @@
// Action implementation
// -------------------------------------------------------------------------
-
-
public String execute()
{
dataValueMap = new HashMap<String, String>();
@@ -206,9 +224,53 @@
Map<Integer, Double> tariffDataValueMap = new HashMap<Integer, Double>();
tariffDataValueMap.putAll( tariffDataValueService.getTariffDataValues( organisationUnit, dataSet, period ) );
+
+ pbfDataValueMap = new HashMap<DataElement, PBFDataValue>();
-
- for( DataElement dataElement : dataElements )
+ Set<PBFDataValue> pbfDataValues = new HashSet<PBFDataValue>( pbfDataValueService.getPBFDataValues(organisationUnit, dataSet, period) );
+ for( PBFDataValue pbfDataValue : pbfDataValues )
+ {
+ DataElement de = pbfDataValue.getDataElement();
+ if( pbfDataValue.getTariffAmount() == null )
+ {
+ Double tariffAmount = tariffDataValueMap.get( de.getId() );
+ if( tariffAmount != null )
+ {
+ pbfDataValue.setStoredBy( currentUserService.getCurrentUsername() );
+ pbfDataValue.setTariffAmount( tariffAmount );
+ pbfDataValue.setTimestamp( new Date() );
+ pbfDataValueService.updatePBFDataValue( pbfDataValue );
+ }
+ }
+ pbfDataValueMap.put( de, pbfDataValue );
+ }
+
+ Set<DataElement> tempDes = new HashSet<DataElement>();
+ tempDes.addAll( dataElements );
+
+ tempDes.removeAll( pbfDataValueMap.keySet() );
+
+ for( DataElement de : tempDes )
+ {
+ Double tariffAmount = tariffDataValueMap.get( de.getId() );
+ if( tariffAmount != null )
+ {
+ PBFDataValue pbfDataValue = new PBFDataValue();
+
+ pbfDataValue.setDataElement( de );
+ pbfDataValue.setPeriod( period );
+ pbfDataValue.setOrganisationUnit(organisationUnit);
+ pbfDataValue.setTariffAmount( tariffAmount );
+ pbfDataValue.setStoredBy( currentUserService.getCurrentUsername() );
+ pbfDataValue.setTimestamp( new Date() );
+
+ pbfDataValueService.addPBFDataValue( pbfDataValue );
+ pbfDataValueMap.put( de, pbfDataValue );
+ }
+ }
+
+ /*
+ for( DataElement dataElement : dataElements )
{
//DataElementCategoryOptionCombo decoc = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
@@ -258,6 +320,7 @@
}
}
+ */
/*
for( DataElementCategoryOptionCombo decombo : optionCombos )
=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/SaveValueAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/SaveValueAction.java 2014-01-07 10:10:48 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/dataentry/SaveValueAction.java 2014-01-07 17:56:19 +0000
@@ -27,24 +27,27 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.opensymphony.xwork2.Action;
+import java.util.Date;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+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.PBFDataValue;
+import org.hisp.dhis.pbf.api.PBFDataValueService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.user.CurrentUserService;
-import java.util.Date;
+import com.opensymphony.xwork2.Action;
/**
* @author Abyot Asalefew
@@ -100,18 +103,32 @@
this.dataSetService = dataSetService;
}
+ private PBFDataValueService pbfDataValueService;
+
+ public void setPbfDataValueService(PBFDataValueService pbfDataValueService)
+ {
+ this.pbfDataValueService = pbfDataValueService;
+ }
+
// -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
- private String value;
+ private String value;
public void setValue( String value )
{
this.value = value;
}
- private String dataElementId;
+ private String valueType;
+
+ public void setValueType(String valueType)
+ {
+ this.valueType = valueType;
+ }
+
+ private String dataElementId;
public void setDataElementId( String dataElementId )
{
@@ -125,12 +142,14 @@
this.organisationUnitId = organisationUnitId;
}
+ /*
private String optionComboId;
public void setOptionComboId( String optionComboId )
{
this.optionComboId = optionComboId;
}
+ */
private String periodId;
@@ -141,14 +160,24 @@
private String periodIso;
- public void setPeriodIso(String periodIso) {
+ public void setPeriodIso(String periodIso)
+ {
this.periodIso = periodIso;
}
+ private String dataSetId;
+
+ public void setDataSetId(String dataSetId)
+ {
+ this.dataSetId = dataSetId;
+ }
+
+
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
+
private int statusCode = 0;
public int getStatusCode()
@@ -183,13 +212,21 @@
{
return logError( "Invalid data element identifier: " + dataElementId );
}
-
+
+ /*
DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( Integer.parseInt(optionComboId) );
if ( optionCombo == null )
{
return logError( "Invalid category option combo identifier: " + optionComboId );
}
+ */
+
+ DataSet dataSet = dataSetService.getDataSet( Integer.parseInt( dataSetId ) );
+ if ( dataSet == null )
+ {
+ return logError( "Invalid dataset identifier: " + dataSetId );
+ }
String storedBy = currentUserService.getCurrentUsername();
@@ -225,15 +262,17 @@
// Check locked status
// ---------------------------------------------------------------------
+ /*
if ( dataSetService.isLocked( dataElement, period, organisationUnit, null ) )
{
return logError( "Entry locked for combination: " + dataElement + ", " + period + ", " + organisationUnit, 2 );
}
-
+*/
// ---------------------------------------------------------------------
// Update data
// ---------------------------------------------------------------------
+ /*
DataValue dataValue = dataValueService.getDataValue( dataElement, period,organisationUnit,optionCombo );
if ( dataValue == null )
@@ -263,6 +302,55 @@
System.out.println("Value Updated");
}
+*/
+
+ PBFDataValue pbfDataValue = pbfDataValueService.getPBFDataValue(organisationUnit, dataSet, period, dataElement);
+
+ if ( pbfDataValue == null )
+ {
+ if ( value != null )
+ {
+ pbfDataValue = new PBFDataValue( );
+ pbfDataValue.setDataElement(dataElement);
+ pbfDataValue.setPeriod(period);
+ pbfDataValue.setOrganisationUnit(organisationUnit);
+
+ if( valueType.equals("1") )
+ {
+ pbfDataValue.setQuantityReported( Integer.parseInt( value ) );
+ }
+ else if( valueType.equals("2") )
+ {
+ pbfDataValue.setQuantityValidated( Integer.parseInt( value ) );
+ }
+ pbfDataValue.setStoredBy(storedBy);
+ pbfDataValue.setTimestamp(now);
+ pbfDataValueService.addPBFDataValue(pbfDataValue);
+
+ System.out.println("Value Added");
+ }
+ }
+ else
+ {
+ if( valueType.equals("1") )
+ {
+ pbfDataValue.setQuantityReported( Integer.parseInt( value ) );
+ }
+ else if( valueType.equals("2") )
+ {
+ pbfDataValue.setQuantityValidated( Integer.parseInt( value ) );
+ }
+
+ pbfDataValue.setStoredBy(storedBy);
+
+ pbfDataValue.setTimestamp(now);
+
+ pbfDataValueService.updatePBFDataValue( pbfDataValue );
+
+ System.out.println("Value Updated");
+ }
+
+
return SUCCESS;
}
=== added 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 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/DefaultPBFDataValueService.java 2014-01-07 17:56:19 +0000
@@ -0,0 +1,61 @@
+package org.hisp.dhis.pbf.impl;
+
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.pbf.api.PBFDataValue;
+import org.hisp.dhis.pbf.api.PBFDataValueService;
+import org.hisp.dhis.pbf.api.PBFDataValueStore;
+import org.hisp.dhis.period.Period;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DefaultPBFDataValueService implements PBFDataValueService
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private 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 );
+ }
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/impl/HibernatePBFDataValueStore.java 2014-01-07 17:56:19 +0000
@@ -0,0 +1,113 @@
+package org.hisp.dhis.pbf.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.pbf.api.PBFDataValue;
+import org.hisp.dhis.pbf.api.PBFDataValueStore;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodStore;
+
+public class HibernatePBFDataValueStore implements PBFDataValueStore
+{
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private SessionFactory sessionFactory;
+
+ public void setSessionFactory( SessionFactory sessionFactory )
+ {
+ this.sessionFactory = sessionFactory;
+ }
+
+ private PeriodStore periodStore;
+
+ public void setPeriodStore( PeriodStore periodStore )
+ {
+ this.periodStore = periodStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // PBFDataValue
+ // -------------------------------------------------------------------------
+
+ @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() ) );
+
+ Session session = sessionFactory.getCurrentSession();
+
+ session.update( 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 );
+
+ if ( storedPeriod == null )
+ {
+ return null;
+ }
+
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( PBFDataValue.class );
+ criteria.add( Restrictions.eq( "organisationUnit", organisationUnit ) );
+ criteria.add( Restrictions.eq( "period", storedPeriod ) );
+ criteria.add( Restrictions.eq( "dataSet", dataSet ) );
+ 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 );
+
+ if ( storedPeriod == null )
+ {
+ return Collections.emptySet();
+ }
+
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( PBFDataValue.class );
+ criteria.add( Restrictions.eq( "organisationUnit", organisationUnit ) );
+ criteria.add( Restrictions.eq( "period", storedPeriod ) );
+ criteria.add( Restrictions.eq( "dataSet", dataSet ) );
+
+ return criteria.list();
+ }
+
+}
=== 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 11:54:34 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml 2014-01-07 17:56:19 +0000
@@ -10,11 +10,20 @@
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
+
+ <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" />
+ </bean>
<bean id="org.hisp.dhis.pbf.api.TariffDataValueService" class="org.hisp.dhis.pbf.impl.DefaultTariffDataValueService">
<property name="tariffDataValueStore" ref="org.hisp.dhis.pbf.api.TariffDataValueStore" />
</bean>
+ <bean id="org.hisp.dhis.pbf.api.PBFDataValueService" class="org.hisp.dhis.pbf.impl.DefaultPBFDataValueService">
+ <property name="pbfDataValueStore" ref="org.hisp.dhis.pbf.api.PBFDataValueStore" />
+ </bean>
+
<bean id="org.hisp.dhis.pbf.api.LookupStore" class="org.hisp.dhis.pbf.impl.HibernateLookupStore">
<property name="clazz" value="org.hisp.dhis.pbf.api.Lookup"/>
<property name="sessionFactory" ref="sessionFactory" />
@@ -138,6 +147,7 @@
<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"/>
+ <property name="pbfDataValueService" ref="org.hisp.dhis.pbf.api.PBFDataValueService" />
</bean>
<!-- Save Value -->
@@ -148,7 +158,8 @@
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
- <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ <property name="pbfDataValueService" ref="org.hisp.dhis.pbf.api.PBFDataValueService" />
</bean>
</beans>
\ No newline at end of file
=== added file 'local/in/dhis-web-maintenance-pbf/src/main/resources/org/hisp/dhis/pbf/hibernate/PBFDataValue.hbm.xml'
--- local/in/dhis-web-maintenance-pbf/src/main/resources/org/hisp/dhis/pbf/hibernate/PBFDataValue.hbm.xml 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/resources/org/hisp/dhis/pbf/hibernate/PBFDataValue.hbm.xml 2014-01-07 17:56:19 +0000
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.hisp.dhis.pbf.api.PBFDataValue" table="pbfdatavalue">
+
+ <composite-id>
+ <key-many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid" foreign-key="fk_pbfdatavalue_organisationunitid" />
+ <key-many-to-one name="dataSet" class="org.hisp.dhis.dataset.DataSet" column="datasetid" foreign-key="fk_pbfdatavalue_datasetid" />
+ <key-many-to-one name="period" class="org.hisp.dhis.period.Period" column="periodid" foreign-key="fk_pbfdatavalue_periodid" />
+ <key-many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" column="dataelementid" foreign-key="fk_tariffdatavalue_dataelementid" />
+ </composite-id>
+
+ <property name="quantityReported" column="qtyreported" />
+
+ <property name="quantityValidated" column="qtyValidated" />
+
+ <property name="tariffAmount" column="tariffamount" />
+
+ <property name="storedBy" column="storedby" length="100" />
+
+ <property name="timestamp" column="lastupdated" type="timestamp" />
+
+ <property name="comment" length="360" />
+
+ </class>
+</hibernate-mapping>
=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/javascript/pbfDataEntry.js'
--- local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/javascript/pbfDataEntry.js 2014-01-07 10:10:48 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/javascript/pbfDataEntry.js 2014-01-07 17:56:19 +0000
@@ -146,6 +146,75 @@
}
+function savePBFDataValue( dataElementId, valueType )
+{
+ var period = document.getElementById("selectedPeriodId").value;
+ var dataSetId = $( '#dataSetId' ).val();
+ var valueId = "";
+ if( valueType == 1 )
+ {
+ valueId = "pbfdv_qty_reported_"+dataElementId;
+ }
+ else
+ {
+ valueId = "pbfdv_qty_validated_"+dataElementId;
+ }
+
+ var fieldId = "#"+valueId;
+ var defaultValue = document.getElementById(valueId).defaultValue;
+ var value = document.getElementById( valueId ).value;
+
+ if(defaultValue != value)
+ {
+ var dataValue = {
+ 'dataElementId' : dataElementId,
+ 'valueType' : valueType,
+ 'dataSetId' : dataSetId,
+ 'organisationUnitId' : $("#selectedOrgunitID").val(),
+ 'periodIso' : period,
+ 'value' : value
+ };
+ jQuery.ajax( {
+ url: 'saveValue.action',
+ data: dataValue,
+ dataType: 'json',
+ success: handleSuccess,
+ error: handleError
+ } );
+ }
+
+ function handleSuccess( json )
+ {
+ var code = json.c;
+
+ alert(code)
+ if ( code == '0' || code == 0) // Value successfully saved on server
+ {
+ markValue( fieldId, COLOR_GREEN );
+ }
+ else if ( code == 2 )
+ {
+ markValue( fieldId, COLOR_RED );
+ window.alert( i18n_saving_value_failed_dataset_is_locked );
+ }
+ else // Server error during save
+ {
+ markValue( fieldId, COLOR_RED );
+ window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
+ }
+ }
+
+ function handleError( jqXHR, textStatus, errorThrown )
+ {
+ markValue( fieldId, COLOR_GREEN );
+ }
+
+ function markValue( fieldId, color )
+ {
+ document.getElementById(valueId).style.backgroundColor = color;
+ }
+}
+
// load periods
function loadPeriods()
{
=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataEntryForm.vm'
--- local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataEntryForm.vm 2014-01-07 12:44:16 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataEntryForm.vm 2014-01-07 17:56:19 +0000
@@ -21,7 +21,94 @@
#end
#end
-
+#set( $tabIndex = 1 )
+#if ( $dataElements.size() > 0)
+
+<table class="formSection" id="dataEntryTable">
+ <tr bgcolor="#CBDDEB">
+ <th>$i18n.getString( "dataelement" )</th>
+ <th style="text-align: center;">$i18n.getString( "qty_reported" )</th>
+ <th style="text-align: center;">$i18n.getString( "qty_validated" )</th>
+ <th style="text-align: center;">$i18n.getString( "tariff_amount" )</th>
+ <th style="text-align: center;">$i18n.getString( "total" )</th>
+ </tr>
+
+ #set( $mark = false )
+ #foreach($dataElement in $dataElements )
+ <tr #alternate($mark)>
+ <td><label>$dataElement.getFormNameFallback()</label></td>
+ #set( $count = 1)
+ #set( $pbfDataValue = $!pbfDataValueMap.get( $dataElement ) )
+ <td>
+ <input onblur="savePBFDataValue('$dataElement.id', 1 )" type="text" name="pbfdv_qty_reported_$dataElement.id" id="pbfdv_qty_reported_$dataElement.id"
+ value="$!pbfDataValue.quantityReported" tabindex="$tabIndex" style="text-align: center;"
+ #if($dataElement.type =='number') class="{validate:{number:true}}"
+ #elseif($dataElement.type =='int') class="{validate:{integer:true}}"
+ #elseif($dataElement.type =='positiveNumber') class="{validate:{positive_integer:true}}"
+ #elseif($dataElement.type =='negativeNumber') class="{validate:{negative_integer:true}}"
+ #end />
+ </td>
+ <td>
+ <input onblur="savePBFDataValue('$dataElement.id', 2 )" type="text" name="pbfdv_qty_validated_$dataElement.id" id="pbfdv_qty_validated_$dataElement.id"
+ value="$!pbfDataValue.quantityValidated" tabindex="$tabIndex" style="text-align: center;"
+ #if($dataElement.type =='number') class="{validate:{number:true}}"
+ #elseif($dataElement.type =='int') class="{validate:{integer:true}}"
+ #elseif($dataElement.type =='positiveNumber') class="{validate:{positive_integer:true}}"
+ #elseif($dataElement.type =='negativeNumber') class="{validate:{negative_integer:true}}"
+ #end class="quantity$count" onkeyup="calVal()" />
+ </td>
+ <td>
+ <input type="text" name="pbfdv_tariff_amt_$dataElement.id" id="pbfdv_tariff_amt_$dataElement.id"
+ value="$!pbfDataValue.tariffAmount" tabindex="$tabIndex" style="text-align: center;"
+ #if($dataElement.type =='number') class="{validate:{number:true}}"
+ #elseif($dataElement.type =='int') class="{validate:{integer:true}}"
+ #elseif($dataElement.type =='positiveNumber') class="{validate:{positive_integer:true}}"
+ #elseif($dataElement.type =='negativeNumber') class="{validate:{negative_integer:true}}"
+ #end class="tariff$count" readonly />
+ </td>
+
+ <script >
+ function calVal() {
+ var total = 0;
+ var quantity = $('.quantity'+$count).val();
+ var tariff = $('.tariff'+$count).val();
+
+ total = quantity * tariff;
+
+ $('.row-total'+$count).val(total);
+ }
+
+ calVal();
+
+ $('input').on('keyup', function() {
+ calVal();
+ });
+ </script>
+ #end
+ #set( $count = $count + 1)
+ <td >
+ <input type="text" class="row-total$count"/>
+ </td>
+
+ </tr>
+ #set( $tabIndex = $tabIndex + 1 )
+ #set( $mark = !$mark)
+ #end
+ <tr>
+ <td > </td>
+ <td > </td>
+ <td > </td>
+ <td > </td>
+ <td >
+ <input type="text" class="all-total"/>
+ </td>
+ </tr>
+
+</table
+
+#end
+
+<!--
#set( $tabIndex = 1 )
#if ( $dataElements.size() > 0)
@@ -92,4 +179,5 @@
</table
-#end
\ No newline at end of file
+#end
+-->
\ No newline at end of file