← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12920: Implement unit tests on PatientDataValue service methods.

 

------------------------------------------------------------
revno: 12920
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-11-12 11:21:08 +0700
message:
  Implement unit tests on PatientDataValue service methods.
added:
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueStoreTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueStoreTest.java


--
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 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java	2013-09-05 13:09:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java	2013-11-12 04:21:08 +0000
@@ -78,6 +78,14 @@
         this.timestamp = timeStamp;
     }
 
+    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement, String value )
+    {
+        super();
+        this.dataElement = dataElement;
+        this.programStageInstance = programStageInstance;
+        this.value = value;
+    }
+
     public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement, Date timeStamp,
         String value )
     {
@@ -108,19 +116,19 @@
         {
             return true;
         }
-        
+
         if ( object == null )
         {
             return false;
         }
-        
+
         if ( getClass() != object.getClass() )
         {
             return false;
         }
-        
+
         final PatientDataValue other = (PatientDataValue) object;
-        
+
         if ( dataElement == null )
         {
             if ( other.dataElement != null )
@@ -132,7 +140,7 @@
         {
             return false;
         }
-        
+
         if ( programStageInstance == null )
         {
             if ( other.programStageInstance != null )
@@ -144,21 +152,16 @@
         {
             return false;
         }
-        
+
         return true;
     }
 
     @Override
     public String toString()
     {
-        return "PatientDataValue{" +
-            "dataElement=" + dataElement +
-            ", programStageInstance=" + programStageInstance +
-            ", timestamp=" + timestamp +
-            ", value='" + value + '\'' +
-            ", providedElsewhere=" + providedElsewhere +
-            ", storedBy='" + storedBy + '\'' +
-            '}';
+        return "PatientDataValue{" + "dataElement=" + dataElement + ", programStageInstance=" + programStageInstance
+            + ", timestamp=" + timestamp + ", value='" + value + '\'' + ", providedElsewhere=" + providedElsewhere
+            + ", storedBy='" + storedBy + '\'' + '}';
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java	2013-11-04 03:13:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java	2013-11-12 04:21:08 +0000
@@ -76,13 +76,6 @@
     int deletePatientDataValue( ProgramStageInstance programStageInstance );
 
     /**
-     * Deletes all {@link PatientDataValue} of an {@link DataElement}
-     * 
-     * @param patientDataValue the PatientDataValue to delete.
-     */
-    int deletePatientDataValue( DataElement dataElement );
-
-    /**
      * Retrieve patient data values of a event
      * 
      * @param programStageInstance ProgramStageInstance

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java	2013-11-04 03:13:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java	2013-11-12 04:21:08 +0000
@@ -54,16 +54,14 @@
      */
     void saveVoid( PatientDataValue patientDataValue );
 
+    /**
+     * Deletes a {@link PatientDataValue}.
+     * 
+     * @param programStageInstance ProgramStageInstance.
+     */
     int delete( ProgramStageInstance programStageInstance );
 
     /**
-     * Deletes a {@link PatientDataValue}.
-     * 
-     * @param patientDataValue the PatientDataValue to delete.
-     */
-    int delete( DataElement dataElement );
-
-    /**
      * Retrieve patient data values of a event
      * 
      * @param programStageInstance ProgramStageInstance
@@ -111,8 +109,8 @@
      * 
      * @return PatientDataValue list
      */
-    Collection<PatientDataValue> get( Patient patient, Collection<DataElement> dataElements, Date after,
-        Date before );
+    Collection<PatientDataValue> get( Patient patient, Collection<DataElement> dataElements, Date after, Date before );
+
     /**
      * Retrieve a patient data value on an event and a data element
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java	2013-09-16 17:07:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java	2013-11-12 04:21:08 +0000
@@ -76,12 +76,7 @@
     {
         return patientDataValueStore.delete( programStageInstance );
     }
-
-    public int deletePatientDataValue( DataElement dataElement )
-    {
-        return patientDataValueStore.delete( dataElement );
-    }
-
+    
     public void updatePatientDataValue( PatientDataValue patientDataValue )
     {
         if ( patientDataValue.getValue() == null )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java	2013-11-04 00:01:39 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java	2013-11-12 04:21:08 +0000
@@ -61,13 +61,6 @@
         return query.executeUpdate();
     }
 
-    public int delete( DataElement dataElement )
-    {
-        Query query = getQuery( "delete from PatientDataValue where dataElement = :dataElement" );
-        query.setEntity( "dataElement", dataElement );
-        return query.executeUpdate();
-    }
-
     @SuppressWarnings( "unchecked" )
     public Collection<PatientDataValue> get( ProgramStageInstance programStageInstance )
     {
@@ -78,12 +71,11 @@
     public Collection<PatientDataValue> get( ProgramStageInstance programStageInstance,
         Collection<DataElement> dataElements )
     {
-        String hql = 
-            "from PatientDataValue pdv where pdv.dataElement in ( :dataElements ) " + 
-            "and pdv.programStageInstance = :programStageInstance";
+        String hql = "from PatientDataValue pdv where pdv.dataElement in ( :dataElements ) "
+            + "and pdv.programStageInstance = :programStageInstance";
 
-        return getQuery( hql ).setParameterList( "dataElements", dataElements ).setEntity( "programStageInstance",
-            programStageInstance ).list();
+        return getQuery( hql ).setParameterList( "dataElements", dataElements )
+            .setEntity( "programStageInstance", programStageInstance ).list();
     }
 
     @SuppressWarnings( "unchecked" )
@@ -107,10 +99,9 @@
     public Collection<PatientDataValue> get( Patient patient, Collection<DataElement> dataElements, Date startDate,
         Date endDate )
     {
-        String hql = 
-            "from PatientDataValue pdv where pdv.dataElement in ( :dataElements ) " + 
-            "and pdv.programStageInstance.programInstance.patient = :patient " + 
-            "and pdv.programStageInstance.executionDate >= :startDate and pdv.programStageInstance.executionDate <= :endDate ";
+        String hql = "from PatientDataValue pdv where pdv.dataElement in ( :dataElements ) "
+            + "and pdv.programStageInstance.programInstance.patient = :patient "
+            + "and pdv.programStageInstance.executionDate >= :startDate and pdv.programStageInstance.executionDate <= :endDate ";
 
         return getQuery( hql ).setParameterList( "dataElements", dataElements ).setEntity( "patient", patient )
             .setDate( "startDate", startDate ).setDate( "endDate", endDate ).list();

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java	2013-11-11 02:42:44 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java	2013-11-12 04:21:08 +0000
@@ -146,7 +146,7 @@
             PatientReminder.MESSAGE_TYPE_DIRECT_SMS );
         patientReminders = new HashSet<PatientReminder>();
         patientReminders.add( patientReminderB );
-        stageA.setPatientReminders( patientReminders );
+        stageB.setPatientReminders( patientReminders );
 
         Set<ProgramStage> programStages = new HashSet<ProgramStage>();
         programStages.add( stageA );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueServiceTest.java	2013-11-11 07:56:27 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueServiceTest.java	2013-11-12 04:21:08 +0000
@@ -74,15 +74,15 @@
     @Autowired
     private PatientAttributeOptionService attributeOptionService;
 
-    PatientAttribute attributeA;
-
-    PatientAttribute attributeB;
-
-    PatientAttribute attributeC;
-
-    PatientAttributeOption attributeOpionA;
-
-    PatientAttributeOption attributeOpionB;
+    private PatientAttribute attributeA;
+
+    private PatientAttribute attributeB;
+
+    private PatientAttribute attributeC;
+
+    private PatientAttributeOption attributeOpionA;
+
+    private PatientAttributeOption attributeOpionB;
 
     private Patient patientA;
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueStoreTest.java	2013-11-11 07:56:27 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientattributevalue/PatientAttributeValueStoreTest.java	2013-11-12 04:21:08 +0000
@@ -73,15 +73,15 @@
     @Autowired
     private PatientAttributeOptionService attributeOptionService;
 
-    PatientAttribute attributeA;
-
-    PatientAttribute attributeB;
-
-    PatientAttribute attributeC;
-
-    PatientAttributeOption attributeOpionA;
-
-    PatientAttributeOption attributeOpionB;
+    private PatientAttribute attributeA;
+
+    private PatientAttribute attributeB;
+
+    private PatientAttribute attributeC;
+
+    private PatientAttributeOption attributeOpionA;
+
+    private PatientAttributeOption attributeOpionB;
 
     private Patient patientA;
 

=== added directory 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue'
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueServiceTest.java	2013-11-12 04:21:08 +0000
@@ -0,0 +1,349 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient.patientdatavalue;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.program.ProgramStageService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientDataValueServiceTest.java Nov 5, 2013 3:11:48 PM $
+ */
+public class PatientDataValueServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientDataValueService patientDataValueService;
+
+    @Autowired
+    private PatientService patientService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private ProgramStageService programStageService;
+
+    @Autowired
+    private ProgramInstanceService programInstanceService;
+
+    @Autowired
+    private ProgramStageInstanceService programStageInstanceService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private DataElementService dataElementService;
+
+    private ProgramInstance programInstance;
+
+    private ProgramStageInstance stageInstanceA;
+
+    private ProgramStageInstance stageInstanceB;
+
+    private DataElement dataElementA;
+
+    private DataElement dataElementB;
+
+    private PatientDataValue dataValueA;
+
+    private PatientDataValue dataValueB;
+
+    private PatientDataValue dataValueC;
+
+    private PatientDataValue dataValueD;
+
+    private Date yesterday;
+
+    private Date tomorrow;
+
+    private Patient patient;
+
+    @Override
+    public void setUpTest()
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        dataElementA = createDataElement( 'A' );
+        dataElementB = createDataElement( 'B' );
+
+        dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
+
+        patient = createPatient( 'A', organisationUnit );
+        patientService.savePatient( patient );
+
+        Program program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( program );
+
+        ProgramStage stageA = new ProgramStage( "A", program );
+        programStageService.saveProgramStage( stageA );
+
+        ProgramStage stageB = new ProgramStage( "B", program );
+        programStageService.saveProgramStage( stageB );
+
+        Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+        programStages.add( stageA );
+        programStages.add( stageB );
+        program.setProgramStages( programStages );
+        programService.updateProgram( program );
+
+        Calendar calYesterday = Calendar.getInstance();
+        calYesterday.add( Calendar.DATE, -1 );
+        yesterday = calYesterday.getTime();
+        Calendar calTomorrow = Calendar.getInstance();
+        calTomorrow.add( Calendar.DATE, 1 );
+        tomorrow = calTomorrow.getTime();
+
+        programInstance = programInstanceService.enrollPatient( patient, program, yesterday, yesterday,
+            organisationUnit, null );
+
+        stageInstanceA = programStageInstanceService.getProgramStageInstance( programInstance, stageA );
+        stageInstanceB = programStageInstanceService.getProgramStageInstance( programInstance, stageB );
+
+        dataValueA = new PatientDataValue( stageInstanceA, dataElementA, "A" );
+        dataValueB = new PatientDataValue( stageInstanceA, dataElementB, "B" );
+        dataValueC = new PatientDataValue( stageInstanceB, dataElementA, "C" );
+        dataValueD = new PatientDataValue( stageInstanceB, dataElementB, "D" );
+    }
+
+    @Test
+    public void testSavePatientDataValue()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB ) );
+    }
+
+    @Test
+    public void testDeletePatientDataValue()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB ) );
+
+        patientDataValueService.deletePatientDataValue( dataValueA );
+
+        assertNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB ) );
+
+        patientDataValueService.deletePatientDataValue( dataValueB );
+
+        assertNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+        assertNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB ) );
+    }
+
+    @Test
+    public void testUpdatePatientDataValue()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+
+        dataValueA.setValue( "B" );
+        patientDataValueService.updatePatientDataValue( dataValueA );
+
+        assertEquals( "B", patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ).getValue() );
+    }
+
+    @Test
+    public void testDeletePatientDataValueByStageInstance()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+        patientDataValueService.savePatientDataValue( dataValueC );
+        patientDataValueService.savePatientDataValue( dataValueD );
+
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceB, dataElementA ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceB, dataElementB ) );
+
+        patientDataValueService.deletePatientDataValue( stageInstanceA );
+        assertNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA ) );
+        assertNull( patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceB, dataElementA ) );
+        assertNotNull( patientDataValueService.getPatientDataValue( stageInstanceB, dataElementB ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByStageInstance()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+        patientDataValueService.savePatientDataValue( dataValueC );
+        patientDataValueService.savePatientDataValue( dataValueD );
+
+        Collection<PatientDataValue> dataValues = patientDataValueService.getPatientDataValues( stageInstanceA );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueB ) );
+
+        dataValues = patientDataValueService.getPatientDataValues( stageInstanceB );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueC ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByStageElement()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+        patientDataValueService.savePatientDataValue( dataValueC );
+        patientDataValueService.savePatientDataValue( dataValueD );
+
+        Collection<DataElement> dataElements = new HashSet<DataElement>();
+        dataElements.add( dataElementA );
+        dataElements.add( dataElementB );
+
+        Collection<PatientDataValue> dataValues = patientDataValueService.getPatientDataValues( stageInstanceA,
+            dataElements );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueB ) );
+    }
+
+    @Test
+    public void testGetPatientDataValues()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+        patientDataValueService.savePatientDataValue( dataValueC );
+        patientDataValueService.savePatientDataValue( dataValueD );
+
+        Collection<ProgramStageInstance> programStageInstances = new HashSet<ProgramStageInstance>();
+        programStageInstances.add( stageInstanceA );
+        programStageInstances.add( stageInstanceB );
+
+        Collection<PatientDataValue> dataValues = patientDataValueService.getPatientDataValues( programStageInstances );
+        assertEquals( 4, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueB ) );
+        assertTrue( dataValues.contains( dataValueC ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByDataElement()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+        patientDataValueService.savePatientDataValue( dataValueC );
+        patientDataValueService.savePatientDataValue( dataValueD );
+
+        Collection<PatientDataValue> dataValues = patientDataValueService.getPatientDataValues( dataElementA );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueC ) );
+
+        dataValues = patientDataValueService.getPatientDataValues( dataElementB );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueB ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByPatientDataElement()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+        patientDataValueService.savePatientDataValue( dataValueC );
+        patientDataValueService.savePatientDataValue( dataValueD );
+
+        Collection<DataElement> dataElements = new HashSet<DataElement>();
+        dataElements.add( dataElementA );
+        dataElements.add( dataElementB );
+
+        Collection<PatientDataValue> dataValues = patientDataValueService.getPatientDataValues( patient, dataElements,
+            yesterday, tomorrow );
+
+        dataValues = patientDataValueService.getPatientDataValues( dataElementB );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueB ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValue()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueB );
+
+        PatientDataValue dataValue = patientDataValueService.getPatientDataValue( stageInstanceA, dataElementA );
+        assertEquals( dataValueA, dataValue );
+
+        dataValue = patientDataValueService.getPatientDataValue( stageInstanceA, dataElementB );
+        assertEquals( dataValueB, dataValue );
+    }
+
+    @Test
+    public void testGetAllPatientDataValues()
+    {
+        patientDataValueService.savePatientDataValue( dataValueA );
+        patientDataValueService.savePatientDataValue( dataValueA );
+
+        assertTrue( equals( patientDataValueService.getAllPatientDataValues(), dataValueA, dataValueA ) );
+    }
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/patientdatavalue/PatientDataValueStoreTest.java	2013-11-12 04:21:08 +0000
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient.patientdatavalue;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValueStore;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.program.ProgramStageService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientDataValueServiceTest.java Nov 5, 2013 3:11:48 PM $
+ */
+public class PatientDataValueStoreTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientDataValueStore patientDataValueStore;
+
+    @Autowired
+    private PatientService patientService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private ProgramStageService programStageService;
+
+    @Autowired
+    private ProgramInstanceService programInstanceService;
+
+    @Autowired
+    private ProgramStageInstanceService programStageInstanceService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private DataElementService dataElementService;
+
+    private ProgramInstance programInstance;
+
+    private ProgramStageInstance stageInstanceA;
+
+    private ProgramStageInstance stageInstanceB;
+
+    private DataElement dataElementA;
+
+    private DataElement dataElementB;
+
+    private PatientDataValue dataValueA;
+
+    private PatientDataValue dataValueB;
+
+    private PatientDataValue dataValueC;
+
+    private PatientDataValue dataValueD;
+
+    private Date yesterday;
+
+    private Date tomorrow;
+
+    private Patient patient;
+
+    @Override
+    public void setUpTest()
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        dataElementA = createDataElement( 'A' );
+        dataElementB = createDataElement( 'B' );
+
+        dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
+
+        patient = createPatient( 'A', organisationUnit );
+        patientService.savePatient( patient );
+
+        Program program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( program );
+
+        ProgramStage stageA = new ProgramStage( "A", program );
+        programStageService.saveProgramStage( stageA );
+
+        ProgramStage stageB = new ProgramStage( "B", program );
+        programStageService.saveProgramStage( stageB );
+
+        Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+        programStages.add( stageA );
+        programStages.add( stageB );
+        program.setProgramStages( programStages );
+        programService.updateProgram( program );
+
+        Calendar calYesterday = Calendar.getInstance();
+        calYesterday.add( Calendar.DATE, -1 );
+        yesterday = calYesterday.getTime();
+        Calendar calTomorrow = Calendar.getInstance();
+        calTomorrow.add( Calendar.DATE, 1 );
+        tomorrow = calTomorrow.getTime();
+
+        programInstance = programInstanceService.enrollPatient( patient, program, yesterday, yesterday,
+            organisationUnit, null );
+
+        stageInstanceA = programStageInstanceService.getProgramStageInstance( programInstance, stageA );
+        stageInstanceB = programStageInstanceService.getProgramStageInstance( programInstance, stageB );
+
+        dataValueA = new PatientDataValue( stageInstanceA, dataElementA, "A" );
+        dataValueB = new PatientDataValue( stageInstanceA, dataElementB, "B" );
+        dataValueC = new PatientDataValue( stageInstanceB, dataElementA, "C" );
+        dataValueD = new PatientDataValue( stageInstanceB, dataElementB, "D" );
+    }
+
+    @Test
+    public void testSavePatientDataValue()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+
+        assertNotNull( patientDataValueStore.get( stageInstanceA, dataElementA ) );
+        assertNotNull( patientDataValueStore.get( stageInstanceA, dataElementB ) );
+    }
+
+
+    @Test
+    public void testDeletePatientDataValueByStageInstance()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+        patientDataValueStore.saveVoid( dataValueC );
+        patientDataValueStore.saveVoid( dataValueD );
+
+        assertNotNull( patientDataValueStore.get( stageInstanceA, dataElementA ) );
+        assertNotNull( patientDataValueStore.get( stageInstanceA, dataElementB ) );
+        assertNotNull( patientDataValueStore.get( stageInstanceB, dataElementA ) );
+        assertNotNull( patientDataValueStore.get( stageInstanceB, dataElementB ) );
+
+        patientDataValueStore.delete( stageInstanceA );
+        assertNull( patientDataValueStore.get( stageInstanceA, dataElementA ) );
+        assertNull( patientDataValueStore.get( stageInstanceA, dataElementB ) );
+        assertNotNull( patientDataValueStore.get( stageInstanceB, dataElementA ) );
+        assertNotNull( patientDataValueStore.get( stageInstanceB, dataElementB ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByStageInstance()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+        patientDataValueStore.saveVoid( dataValueC );
+        patientDataValueStore.saveVoid( dataValueD );
+
+        Collection<PatientDataValue> dataValues = patientDataValueStore.get( stageInstanceA );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueB ) );
+
+        dataValues = patientDataValueStore.get( stageInstanceB );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueC ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByStageElement()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+        patientDataValueStore.saveVoid( dataValueC );
+        patientDataValueStore.saveVoid( dataValueD );
+
+        Collection<DataElement> dataElements = new HashSet<DataElement>();
+        dataElements.add( dataElementA );
+        dataElements.add( dataElementB );
+
+        Collection<PatientDataValue> dataValues = patientDataValueStore.get( stageInstanceA,
+            dataElements );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueB ) );
+    }
+
+    @Test
+    public void testGetPatientDataValues()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+        patientDataValueStore.saveVoid( dataValueC );
+        patientDataValueStore.saveVoid( dataValueD );
+
+        Collection<ProgramStageInstance> programStageInstances = new HashSet<ProgramStageInstance>();
+        programStageInstances.add( stageInstanceA );
+        programStageInstances.add( stageInstanceB );
+
+        Collection<PatientDataValue> dataValues = patientDataValueStore.get( programStageInstances );
+        assertEquals( 4, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueB ) );
+        assertTrue( dataValues.contains( dataValueC ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByDataElement()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+        patientDataValueStore.saveVoid( dataValueC );
+        patientDataValueStore.saveVoid( dataValueD );
+
+        Collection<PatientDataValue> dataValues = patientDataValueStore.get( dataElementA );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueA ) );
+        assertTrue( dataValues.contains( dataValueC ) );
+
+        dataValues = patientDataValueStore.get( dataElementB );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueB ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValuesByPatientDataElement()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+        patientDataValueStore.saveVoid( dataValueC );
+        patientDataValueStore.saveVoid( dataValueD );
+
+        Collection<DataElement> dataElements = new HashSet<DataElement>();
+        dataElements.add( dataElementA );
+        dataElements.add( dataElementB );
+
+        Collection<PatientDataValue> dataValues = patientDataValueStore.get( patient, dataElements,
+            yesterday, tomorrow );
+
+        dataValues = patientDataValueStore.get( dataElementB );
+        assertEquals( 2, dataValues.size() );
+        assertTrue( dataValues.contains( dataValueB ) );
+        assertTrue( dataValues.contains( dataValueD ) );
+    }
+
+    @Test
+    public void testGetPatientDataValue()
+    {
+        patientDataValueStore.saveVoid( dataValueA );
+        patientDataValueStore.saveVoid( dataValueB );
+
+        PatientDataValue dataValue = patientDataValueStore.get( stageInstanceA, dataElementA );
+        assertEquals( dataValueA, dataValue );
+
+        dataValue = patientDataValueStore.get( stageInstanceA, dataElementB );
+        assertEquals( dataValueB, dataValue );
+    }
+
+}