dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26069
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12932: Implement unit tests on ProgramDataEntryService service methods
------------------------------------------------------------
revno: 12932
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-11-13 11:19:10 +0700
message:
Implement unit tests on ProgramDataEntryService service methods
added:
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueServiceTest.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStoreTest.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientcomment/
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientcomment/PatientCommentServiceTest.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramDataEntryServiceTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.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/program/ProgramStageDataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java 2013-09-16 17:07:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java 2013-11-13 04:19:10 +0000
@@ -70,13 +70,13 @@
*/
private boolean compulsory = false;
- private Boolean allowProvidedElsewhere;
+ private Boolean allowProvidedElsewhere = false;
private Integer sortOrder;
- private Boolean displayInReports;
+ private Boolean displayInReports = false;
- private Boolean allowDateInFuture;
+ private Boolean allowDateInFuture = false;
// -------------------------------------------------------------------------
// Constructors
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2013-10-11 08:49:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2013-11-13 04:19:10 +0000
@@ -230,13 +230,13 @@
if ( inputHTML.contains( "title=\"\"" ) )
{
inputHTML = inputHTML.replace( "title=\"\"",
- "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " (" + dataElementType
- + ")\" " );
+ "title=\"[ " + dataElement.getUid() + " - " + dataElement.getName() + " - " + dataElementType
+ + " ]\" " );
}
else
{
- inputHTML += "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " ("
- + dataElementType + ")\" ";
+ inputHTML += "title=\"[ " + dataElement.getUid() + " - " + dataElement.getName() + " - "
+ + dataElementType + " ]\" ";
}
// -------------------------------------------------------------
@@ -423,14 +423,13 @@
if ( inputHTML.contains( "title=\"\"" ) )
{
- inputHTML = inputHTML.replace( "title=\"\"",
- "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " (" + dataElementType
- + ")\" " );
+ inputHTML = inputHTML.replace( "title=\"\"", "title=\"[ " + dataElement.getUid() + " - "
+ + dataElement.getName() + " - " + dataElementType + " ]\" " );
}
else
{
- inputHTML += "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " ("
- + dataElementType + ")\" ";
+ inputHTML += "title=\"[ " + dataElement.getUid() + " - " + dataElement.getName() + " - "
+ + dataElementType + " ]\" ";
}
// -------------------------------------------------------------
@@ -554,7 +553,6 @@
inputHTML = inputHTML + ">";
inputMatcher.appendReplacement( sb, inputHTML );
-
}
}
@@ -629,19 +627,19 @@
{
if ( dataElement != null )
{
- inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, " value=\"["
- + dataElement.getDisplayName() + "]\"" ) : inputHTML + " value=\"[" + dataElement.getDisplayName()
+ inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, "value=\"["
+ + dataElement.getDisplayName() + "]\"" ) : inputHTML + "value=\"[" + dataElement.getDisplayName()
+ "]\" ";
String displayTitle = dataElement.getUid() + " - " + dataElement.getName() + " - "
- + dataElement.getDetailedNumberType() + " - ";
- inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, " title=\""
- + displayTitle + "\"" ) : inputHTML + " title=\"" + displayTitle + "\"";
+ + dataElement.getDetailedNumberType();
+ inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, "title=\"[ "
+ + displayTitle + " ]\"" ) : inputHTML + " title=\"[ " + displayTitle + " ]\"";
}
else
{
- inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? " value=\"[" + DATA_ELEMENT_DOES_NOT_EXIST + "]\" "
- : " value=\"[ " + DATA_ELEMENT_DOES_NOT_EXIST + " ]\"";
+ inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? "value=\"[" + DATA_ELEMENT_DOES_NOT_EXIST + "]\" "
+ : " value=\"[" + DATA_ELEMENT_DOES_NOT_EXIST + "]\"";
}
return inputHTML;
@@ -712,7 +710,7 @@
private String populateCustomDataEntryForTextBox( DataElement dataElement, String inputHTML, String dataElementValue )
{
final String jsCodeForInputs = " name=\"entryfield\" tabIndex=\"$TABINDEX\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" options='$OPTIONS' maxlength=255 ";
- final String jsCodeForOnchange = " name=\"entryfield\" tabIndex=\"$TABINDEX\" onchange=\"saveVal( '$DATAELEMENTID' )\" onkeypress=\"return keyPress(event, this)\" maxlength=255 ";
+ final String jsCodeForOnchange = " onchange=\"saveVal( '$DATAELEMENTID' )\" onkeypress=\"return keyPress(event, this)\" ";
// -------------------------------------------------------------
// Insert value of data element in output code
@@ -746,6 +744,10 @@
inputHTML = inputHTML.replaceFirst( "input", "textarea" );
inputHTML += " >$VALUE</textarea>";
}
+ else
+ {
+ inputHTML += " />";
+ }
return inputHTML;
}
=== 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-12 04:21:08 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java 2013-11-13 04:19:10 +0000
@@ -83,7 +83,7 @@
@Autowired
private UserService userService;
- protected MockI18nFormat mockFormat;
+ private MockI18nFormat mockFormat;
private ProgramInstance programInstance;
=== added directory 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue'
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueServiceTest.java 2013-11-13 04:19:10 +0000
@@ -0,0 +1,400 @@
+/*
+ * 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.patientattributevalue;
+
+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.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeOption;
+import org.hisp.dhis.patient.PatientAttributeOptionService;
+import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ PatientAttributeValueServiceTest.java Nov 11, 2013 9:45:10 AM $
+ */
+public class PatientAttributeValueServiceTest
+ extends DhisSpringTest
+{
+
+ @Autowired
+ private PatientAttributeValueService attributeValueService;
+
+ @Autowired
+ private PatientService patientService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private PatientAttributeService attributeService;
+
+ @Autowired
+ private PatientAttributeOptionService attributeOptionService;
+
+ private PatientAttribute attributeA;
+
+ private PatientAttribute attributeB;
+
+ private PatientAttribute attributeC;
+
+ private PatientAttributeOption attributeOpionA;
+
+ private PatientAttributeOption attributeOpionB;
+
+ private Patient patientA;
+
+ private Patient patientB;
+
+ private Patient patientC;
+
+ private Patient patientD;
+
+ private int patientAId;
+
+ private int patientBId;
+
+ private PatientAttributeValue attributeValueA;
+
+ private PatientAttributeValue attributeValueB;
+
+ private PatientAttributeValue attributeValueC;
+
+ private PatientAttributeValue attributeValueD;
+
+ private PatientAttributeValue attributeValueE;
+
+ @Override
+ public void setUpTest()
+ {
+ OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+ organisationUnitService.addOrganisationUnit( organisationUnit );
+
+ patientA = createPatient( 'A', organisationUnit );
+ patientB = createPatient( 'B', organisationUnit );
+ patientC = createPatient( 'C', organisationUnit );
+ patientD = createPatient( 'D', organisationUnit );
+
+ patientAId = patientService.savePatient( patientA );
+ patientBId = patientService.savePatient( patientB );
+ patientService.savePatient( patientC );
+ patientService.savePatient( patientD );
+
+ attributeA = createPatientAttribute( 'A' );
+ attributeB = createPatientAttribute( 'B' );
+ attributeC = createPatientAttribute( 'C' );
+
+ attributeService.savePatientAttribute( attributeA );
+ attributeService.savePatientAttribute( attributeB );
+ attributeService.savePatientAttribute( attributeC );
+
+ attributeOpionA = createPatientAttributeOption( 'A', attributeC );
+ attributeOpionB = createPatientAttributeOption( 'B', attributeC );
+
+ attributeOptionService.addPatientAttributeOption( attributeOpionA );
+ attributeOptionService.addPatientAttributeOption( attributeOpionB );
+
+ attributeValueA = new PatientAttributeValue( attributeA, patientA, "A" );
+ attributeValueB = new PatientAttributeValue( attributeB, patientA, "B" );
+ attributeValueC = new PatientAttributeValue( attributeA, patientB, "C" );
+ attributeValueD = new PatientAttributeValue( attributeC, patientC, "AttributeOptionA" );
+ attributeValueD.setPatientAttributeOption( attributeOpionA );
+ attributeValueE = new PatientAttributeValue( attributeC, patientD, "AttributeOptionB" );
+ attributeValueE.setPatientAttributeOption( attributeOpionB );
+ }
+
+ @Test
+ public void testSavePatientAttributeValue()
+ {
+
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ }
+
+ @Test
+ public void testUpdatePatientAttributeValue()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+
+ attributeValueA.setValue( "B" );
+ attributeValueService.updatePatientAttributeValue( attributeValueA );
+
+ assertEquals( "B", attributeValueService.getPatientAttributeValue( patientA, attributeA ).getValue() );
+ }
+
+ @Test
+ public void testDeletePatientAttributeValue()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+
+ attributeValueService.deletePatientAttributeValue( attributeValueA );
+
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+
+ attributeValueService.deletePatientAttributeValue( attributeValueB );
+
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+ }
+
+ @Test
+ public void testDeletePatientAttributeValueByPatient()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+
+ attributeValueService.deletePatientAttributeValue( patientA );
+
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+
+ attributeValueService.deletePatientAttributeValue( patientB );
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+ }
+
+ @Test
+ public void testDeletePatientAttributeValueByAttribute()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+
+ attributeValueService.deletePatientAttributeValue( attributeA );
+
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+ assertNotNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+
+ attributeValueService.deletePatientAttributeValue( attributeB );
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientA, attributeB ) );
+ assertNull( attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+
+ }
+
+ @Test
+ public void testGetPatientAttributeValue()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ assertEquals( attributeValueA, attributeValueService.getPatientAttributeValue( patientA, attributeA ) );
+ assertEquals( attributeValueC, attributeValueService.getPatientAttributeValue( patientB, attributeA ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValuesByPatient()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueService.getPatientAttributeValues( patientA );
+
+ assertEquals( 2, attributeValues.size() );
+ assertTrue( equals( attributeValues, attributeValueA, attributeValueB ) );
+
+ attributeValues = attributeValueService.getPatientAttributeValues( patientB );
+
+ assertEquals( 1, attributeValues.size() );
+ assertTrue( equals( attributeValues, attributeValueC ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValuesbyAttribute()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueService
+ .getPatientAttributeValues( attributeA );
+ assertEquals( 2, attributeValues.size() );
+ assertTrue( attributeValues.contains( attributeValueA ) );
+ assertTrue( attributeValues.contains( attributeValueC ) );
+
+ attributeValues = attributeValueService.getPatientAttributeValues( attributeB );
+ assertEquals( 1, attributeValues.size() );
+ assertTrue( attributeValues.contains( attributeValueB ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValuesbyPatientList()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<Patient> patients = new HashSet<Patient>();
+ patients.add( patientA );
+ patients.add( patientB );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueService.getPatientAttributeValues( patients );
+ assertEquals( 3, attributeValues.size() );
+ assertTrue( equals( attributeValues, attributeValueA, attributeValueB, attributeValueC ) );
+ }
+
+ @Test
+ public void testGetAllPatientAttributeValues()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ assertTrue( equals( attributeValueService.getAllPatientAttributeValues(), attributeValueA, attributeValueB,
+ attributeValueC ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValueMapForPatients()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<Patient> patients = new HashSet<Patient>();
+ patients.add( patientA );
+ patients.add( patientB );
+
+ Map<Integer, Collection<PatientAttributeValue>> attributeValueMap = attributeValueService
+ .getPatientAttributeValueMapForPatients( patients );
+
+ assertEquals( 2, attributeValueMap.keySet().size() );
+ assertTrue( equals( attributeValueMap.get( patientAId ), attributeValueA, attributeValueB ) );
+ assertTrue( equals( attributeValueMap.get( patientBId ), attributeValueC ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValueMapForPatientsAttributes()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<Patient> patients = new HashSet<Patient>();
+ patients.add( patientA );
+ patients.add( patientB );
+
+ Map<Integer, PatientAttributeValue> attributeValueMap = attributeValueService
+ .getPatientAttributeValueMapForPatients( patients, attributeA );
+
+ assertEquals( 2, attributeValueMap.keySet().size() );
+ assertEquals( attributeValueA, attributeValueMap.get( patientAId ) );
+ assertEquals( attributeValueC, attributeValueMap.get( patientBId ) );
+ }
+
+ @Test
+ public void testSearchPatientAttributeValue()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueService.searchPatientAttributeValue(
+ attributeA, "A" );
+ assertTrue( equals( attributeValues, attributeValueA ) );
+ }
+
+ @Test
+ public void testCopyPatientAttributeValues()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ attributeValueService.copyPatientAttributeValues( patientA, patientB );
+
+ PatientAttributeValue attributeValue = attributeValueService.getPatientAttributeValue( patientB, attributeB );
+ assertEquals( "B", attributeValue.getValue() );
+
+ attributeValue = attributeValueService.getPatientAttributeValue( patientB, attributeA );
+ assertNull( attributeValue );
+ }
+
+ @Test
+ public void testGetPatients()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueB );
+ attributeValueService.savePatientAttributeValue( attributeValueC );
+
+ Collection<Patient> patients = attributeValueService.getPatient( attributeA, "A" );
+ assertEquals( 1, patients.size() );
+ assertTrue( patients.contains( patientA ) );
+ }
+
+ @Test
+ public void testCountByPatientAttributeoption()
+ {
+ attributeValueService.savePatientAttributeValue( attributeValueA );
+ attributeValueService.savePatientAttributeValue( attributeValueD );
+ attributeValueService.savePatientAttributeValue( attributeValueE );
+
+ int count = attributeValueService.countByPatientAttributeoption( attributeOpionA );
+ assertEquals( 1, count );
+ }
+
+}
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStoreTest.java 2013-11-13 04:19:10 +0000
@@ -0,0 +1,295 @@
+/*
+ * 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.patientattributevalue;
+
+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.Collection;
+import java.util.HashSet;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeOption;
+import org.hisp.dhis.patient.PatientAttributeOptionService;
+import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueStore;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ PatientattributeValueStoreTest.java Nov 11, 2013 9:45:10 AM $
+ */
+public class PatientAttributeValueStoreTest
+ extends DhisSpringTest
+{
+
+ @Autowired
+ private PatientAttributeValueStore attributeValueStore;
+
+ @Autowired
+ private PatientService patientService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private PatientAttributeService attributeService;
+
+ @Autowired
+ private PatientAttributeOptionService attributeOptionService;
+
+ private PatientAttribute attributeA;
+
+ private PatientAttribute attributeB;
+
+ private PatientAttribute attributeC;
+
+ private PatientAttributeOption attributeOpionA;
+
+ private PatientAttributeOption attributeOpionB;
+
+ private Patient patientA;
+
+ private Patient patientB;
+
+ private Patient patientC;
+
+ private Patient patientD;
+
+ private PatientAttributeValue attributeValueA;
+
+ private PatientAttributeValue attributeValueB;
+
+ private PatientAttributeValue attributeValueC;
+
+ private PatientAttributeValue attributeValueD;
+
+ private PatientAttributeValue attributeValueE;
+
+ @Override
+ public void setUpTest()
+ {
+ OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+ organisationUnitService.addOrganisationUnit( organisationUnit );
+
+ patientA = createPatient( 'A', organisationUnit );
+ patientB = createPatient( 'B', organisationUnit );
+ patientC = createPatient( 'C', organisationUnit );
+ patientD = createPatient( 'D', organisationUnit );
+
+ patientService.savePatient( patientA );
+ patientService.savePatient( patientB );
+ patientService.savePatient( patientC );
+ patientService.savePatient( patientD );
+
+ attributeA = createPatientAttribute( 'A' );
+ attributeB = createPatientAttribute( 'B' );
+ attributeC = createPatientAttribute( 'C' );
+
+ attributeService.savePatientAttribute( attributeA );
+ attributeService.savePatientAttribute( attributeB );
+ attributeService.savePatientAttribute( attributeC );
+
+ attributeOpionA = createPatientAttributeOption( 'A', attributeC );
+ attributeOpionB = createPatientAttributeOption( 'B', attributeC );
+
+ attributeOptionService.addPatientAttributeOption( attributeOpionA );
+ attributeOptionService.addPatientAttributeOption( attributeOpionB );
+
+ attributeValueA = new PatientAttributeValue( attributeA, patientA, "A" );
+ attributeValueB = new PatientAttributeValue( attributeB, patientA, "B" );
+ attributeValueC = new PatientAttributeValue( attributeA, patientB, "C" );
+ attributeValueD = new PatientAttributeValue( attributeC, patientC, "AttributeOptionA" );
+ attributeValueD.setPatientAttributeOption( attributeOpionA );
+ attributeValueE = new PatientAttributeValue( attributeC, patientD, "AttributeOptionB" );
+ attributeValueE.setPatientAttributeOption( attributeOpionB );
+ }
+
+ @Test
+ public void testSavePatientAttributeValue()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+
+ assertNotNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNotNull( attributeValueStore.get( patientA, attributeA ) );
+ }
+
+ @Test
+ public void testDeletePatientAttributeValueByPatient()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ assertNotNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNotNull( attributeValueStore.get( patientA, attributeB ) );
+ assertNotNull( attributeValueStore.get( patientB, attributeA ) );
+
+ attributeValueStore.deleteByPatient( patientA );
+
+ assertNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNull( attributeValueStore.get( patientA, attributeB ) );
+ assertNotNull( attributeValueStore.get( patientB, attributeA ) );
+
+ attributeValueStore.deleteByPatient( patientB );
+ assertNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNull( attributeValueStore.get( patientA, attributeB ) );
+ assertNull( attributeValueStore.get( patientB, attributeA ) );
+ }
+
+ @Test
+ public void testDeleteByAttribute()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ assertNotNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNotNull( attributeValueStore.get( patientA, attributeB ) );
+ assertNotNull( attributeValueStore.get( patientB, attributeA ) );
+
+ attributeValueStore.deleteByAttribute( attributeA );
+
+ assertNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNull( attributeValueStore.get( patientB, attributeA ) );
+ assertNotNull( attributeValueStore.get( patientA, attributeB ) );
+
+ attributeValueStore.deleteByAttribute( attributeB );
+ assertNull( attributeValueStore.get( patientA, attributeA ) );
+ assertNull( attributeValueStore.get( patientA, attributeB ) );
+ assertNull( attributeValueStore.get( patientB, attributeA ) );
+
+ }
+
+ @Test
+ public void testGetPatientAttributeValue()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ assertEquals( attributeValueA, attributeValueStore.get( patientA, attributeA ) );
+ assertEquals( attributeValueC, attributeValueStore.get( patientB, attributeA ) );
+ }
+
+ @Test
+ public void testGetByPatient()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueStore.get( patientA );
+
+ assertEquals( 2, attributeValues.size() );
+ assertTrue( equals( attributeValues, attributeValueA, attributeValueB ) );
+
+ attributeValues = attributeValueStore.get( patientB );
+
+ assertEquals( 1, attributeValues.size() );
+ assertTrue( equals( attributeValues, attributeValueC ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValuesbyAttribute()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueStore.get( attributeA );
+ assertEquals( 2, attributeValues.size() );
+ assertTrue( attributeValues.contains( attributeValueA ) );
+ assertTrue( attributeValues.contains( attributeValueC ) );
+
+ attributeValues = attributeValueStore.get( attributeB );
+ assertEquals( 1, attributeValues.size() );
+ assertTrue( attributeValues.contains( attributeValueB ) );
+ }
+
+ @Test
+ public void testGetPatientAttributeValuesbyPatientList()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ Collection<Patient> patients = new HashSet<Patient>();
+ patients.add( patientA );
+ patients.add( patientB );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueStore.get( patients );
+ assertEquals( 3, attributeValues.size() );
+ assertTrue( equals( attributeValues, attributeValueA, attributeValueB, attributeValueC ) );
+ }
+
+ @Test
+ public void testSearchPatientAttributeValue()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ Collection<PatientAttributeValue> attributeValues = attributeValueStore.searchByValue( attributeA, "A" );
+ assertTrue( equals( attributeValues, attributeValueA ) );
+ }
+
+ @Test
+ public void testGetPatients()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueB );
+ attributeValueStore.saveVoid( attributeValueC );
+
+ Collection<Patient> patients = attributeValueStore.getPatient( attributeA, "A" );
+ assertEquals( 1, patients.size() );
+ assertTrue( patients.contains( patientA ) );
+ }
+
+ @Test
+ public void testCountByPatientAttributeoption()
+ {
+ attributeValueStore.saveVoid( attributeValueA );
+ attributeValueStore.saveVoid( attributeValueD );
+ attributeValueStore.saveVoid( attributeValueE );
+
+ int count = attributeValueStore.countByPatientAttributeoption( attributeOpionA );
+ assertEquals( 1, count );
+ }
+
+}
=== added directory 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientcomment'
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientcomment/PatientCommentServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientcomment/PatientCommentServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientcomment/PatientCommentServiceTest.java 2013-11-13 04:19:10 +0000
@@ -0,0 +1,128 @@
+/*
+ * 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.patientcomment;
+
+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.Date;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.patientcomment.PatientComment;
+import org.hisp.dhis.patientcomment.PatientCommentService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ PatientCommentService.java Nov 5, 2013 3:11:48 PM $
+ */
+public class PatientCommentServiceTest
+ extends DhisSpringTest
+{
+ @Autowired
+ private PatientCommentService patientCommentService;
+
+ private PatientComment patientCommentA;
+
+ private PatientComment patientCommentB;
+
+ @Override
+ public void setUpTest()
+ {
+ patientCommentA = new PatientComment( "A", "Test", new Date() );
+ patientCommentB = new PatientComment( "B", "Test", new Date() );
+ }
+
+ @Test
+ public void testSavePatientComment()
+ {
+ int idA = patientCommentService.addPatientComment( patientCommentA );
+ int idB = patientCommentService.addPatientComment( patientCommentB );
+
+ assertNotNull( patientCommentService.getPatientComment( idA ) );
+ assertNotNull( patientCommentService.getPatientComment( idB ) );
+ }
+
+ @Test
+ public void testDeletePatientComment()
+ {
+ int idA = patientCommentService.addPatientComment( patientCommentA );
+ int idB = patientCommentService.addPatientComment( patientCommentB );
+
+ assertNotNull( patientCommentService.getPatientComment( idA ) );
+ assertNotNull( patientCommentService.getPatientComment( idB ) );
+
+ patientCommentService.deletePatientComment( patientCommentA );
+
+ assertNull( patientCommentService.getPatientComment( idA ) );
+ assertNotNull( patientCommentService.getPatientComment( idB ) );
+
+ patientCommentService.deletePatientComment( patientCommentB );
+
+ assertNull( patientCommentService.getPatientComment( idA ) );
+ assertNull( patientCommentService.getPatientComment( idB ) );
+ }
+
+ @Test
+ public void testUpdatePatientComment()
+ {
+ int idA = patientCommentService.addPatientComment( patientCommentA );
+
+ assertNotNull( patientCommentService.getPatientComment( idA ) );
+
+ patientCommentA.setCommentText( "B" );
+ patientCommentService.updatePatientComment( patientCommentA );
+
+ assertEquals( "B", patientCommentService.getPatientComment( idA ).getCommentText());
+ }
+
+ @Test
+ public void testGetPatientCommentById()
+ {
+ int idA = patientCommentService.addPatientComment( patientCommentA );
+ int idB = patientCommentService.addPatientComment( patientCommentB );
+
+ assertEquals( patientCommentA, patientCommentService.getPatientComment( idA ) );
+ assertEquals( patientCommentB, patientCommentService.getPatientComment( idB ) );
+ }
+
+
+ @Test
+ public void testGetAllPatientComments()
+ {
+ patientCommentService.addPatientComment( patientCommentA );
+ patientCommentService.addPatientComment( patientCommentB );
+
+ assertTrue( equals( patientCommentService.getAllPatientComments(), patientCommentA, patientCommentB ) );
+ }
+
+}
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java 2013-11-13 04:19:10 +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.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/program/ProgramDataEntryServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramDataEntryServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramDataEntryServiceTest.java 2013-11-13 04:19:10 +0000
@@ -0,0 +1,139 @@
+package org.hisp.dhis.program;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+
+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.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.mock.MockI18n;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class ProgramDataEntryServiceTest
+ extends DhisSpringTest
+{
+ @Autowired
+ private ProgramDataEntryService programDataEntryService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private DataElementService dataElementService;
+
+ @Autowired
+ private ProgramService programService;
+
+ @Autowired
+ private ProgramStageDataElementService programStageDataElementService;
+
+ @Autowired
+ private DataEntryFormService dataEntryFormService;
+
+ @Autowired
+ private ProgramStageService programStageService;
+
+ private OrganisationUnit organisationUnit;
+
+ private ProgramStage stageA;
+
+ private MockI18n mockI18n = new MockI18n();
+
+ private String htmlCode;
+
+ @Override
+ public void setUpTest()
+ {
+ organisationUnit = createOrganisationUnit( 'A' );
+ organisationUnitService.addOrganisationUnit( organisationUnit );
+
+ DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
+ dataEntryFormService.addDataEntryForm( dataEntryFormA );
+
+ Program program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+ programService.addProgram( program );
+
+ stageA = new ProgramStage( "A", program );
+ stageA.setUid( "StageA" );
+ 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 );
+
+ DataElement dataElementA = createDataElement( 'A' );
+ dataElementA.setUid( "DeA" );
+ DataElement dataElementB = createDataElement( 'B' );
+
+ dataElementService.addDataElement( dataElementA );
+ dataElementService.addDataElement( dataElementB );
+ ProgramStageDataElement stageDataElement = new ProgramStageDataElement( stageA, dataElementA, false, 1 );
+ programStageDataElementService.addProgramStageDataElement( stageDataElement );
+ stageDataElement = new ProgramStageDataElement( stageA, dataElementB, false, 2 );
+ programStageDataElementService.addProgramStageDataElement( stageDataElement );
+
+ htmlCode = "<input id=\"StageA-DeA-val\" style=\"width:4em;text-align:center\" value=\"\" title=\"\" />";
+ }
+
+ @Test
+ public void testPrepareDataEntryFormForAdd()
+ {
+ String expected = "<input id=\"StageA-DeA-val\" style=\"width:4em;text-align:center\" value=\"\" title=\"[ DeA - DataElementA - int ]\" "
+ + " name=\"entryfield\" tabIndex=\"1\" data=\"{compulsory:false, deName:\'DataElementA\', deType:\'int\'}\" options=\'false\' "
+ + "maxlength=255 onchange=\"saveVal( \'DeA\' )\" onkeypress=\"return keyPress(event, this)\" />";
+ String actual = programDataEntryService.prepareDataEntryFormForAdd( htmlCode, mockI18n, stageA );
+ assertEquals( expected, actual );
+ }
+
+ @Test
+ public void testPrepareDataEntryFormForEdit()
+ {
+ String expected = "<input id=\"StageA-DeA-val\" style=\"width:4em;text-align:center\" value=\"[DataElementA]\" title=\"[ DeA - DataElementA - int ]\" />";
+ String actual = programDataEntryService.prepareDataEntryFormForEdit( htmlCode );
+ assertEquals( expected, actual );
+ }
+}