dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26037
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12916: Implement unit tests on PatientReminderServiceTest service methods
------------------------------------------------------------
revno: 12916
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-11-11 09:42:44 +0700
message:
Implement unit tests on PatientReminderServiceTest service methods
added:
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeServiceTest.java
dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.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/patient/PatientReminder.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java 2013-09-10 04:51:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java 2013-11-11 02:42:44 +0000
@@ -42,34 +42,53 @@
private static final long serialVersionUID = 3101502417481903219L;
public static final String DUE_DATE_TO_COMPARE = "duedate";
+
public static final String ENROLLEMENT_DATE_TO_COMPARE = "enrollmentdate";
+
public static final String INCIDENT_DATE_TO_COMPARE = "dateofincident";
public static final String TEMPLATE_MESSSAGE_PATIENT_NAME = "{patient-name}";
+
public static final String TEMPLATE_MESSSAGE_PROGRAM_NAME = "{program-name}";
+
public static final String TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME = "{program-stage-name}";
+
public static final String TEMPLATE_MESSSAGE_DUE_DATE = "{due-date}";
+
public static final String TEMPLATE_MESSSAGE_ORGUNIT_NAME = "{orgunit-name}";
+
public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE = "{days-since-due-date}";
+
public static final String TEMPLATE_MESSSAGE_INCIDENT_DATE = "{incident-date}";
+
public static final String TEMPLATE_MESSSAGE_ENROLLMENT_DATE = "{enrollement-date}";
+
public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE = "{days-since-enrollment-date}";
+
public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE = "{days-since-incident-date}";
public static final int SEND_TO_PATIENT = 1;
+
public static final int SEND_TO_HEALTH_WORKER = 2;
+
public static final int SEND_TO_ORGUGNIT_REGISTERED = 3;
+
public static final int SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED = 4;
+
public static final int SEND_TO_USER_GROUP = 5;
public static final int SEND_WHEN_TO_EMROLLEMENT = 1;
+
public static final int SEND_WHEN_TO_C0MPLETED_EVENT = 2;
+
public static final int SEND_WHEN_TO_C0MPLETED_PROGRAM = 3;
public static final int MESSAGE_TYPE_DIRECT_SMS = 1;
+
public static final int MESSAGE_TYPE_DHIS_MESSAGE = 2;
+
public static final int MESSAGE_TYPE_BOTH = 3;
-
+
private int id;
private String name;
@@ -85,7 +104,7 @@
private Integer whenToSend;
private Integer messageType;
-
+
private UserGroup userGroup;
// -------------------------------------------------------------------------
@@ -103,8 +122,20 @@
this.templateMessage = templateMessage;
}
- //TODO implement hashcode and equals
-
+ public PatientReminder( String name, Integer daysAllowedSendMessage, String templateMessage, String dateToCompare,
+ Integer sendTo, Integer whenToSend, Integer messageType )
+ {
+ this.name = name;
+ this.daysAllowedSendMessage = daysAllowedSendMessage;
+ this.templateMessage = templateMessage;
+ this.dateToCompare = dateToCompare;
+ this.sendTo = sendTo;
+ this.whenToSend = whenToSend;
+ this.messageType = messageType;
+ }
+
+ // TODO implement hashcode and equals
+
// -------------------------------------------------------------------------
// Getter && Setter
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeServiceTest.java 2013-11-08 03:05:02 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeServiceTest.java 2013-11-11 02:42:44 +0000
@@ -176,7 +176,7 @@
identifierTypeService.savePatientIdentifierType( identifierTypeA );
identifierTypeService.savePatientIdentifierType( identifierTypeB );
identifierTypeService.savePatientIdentifierType( identifierTypeC );
-System.out.println("\n\n ===\n " + identifierTypeA.getPersonDisplayName() );
+
Collection<PatientIdentifierType> identifierTypes = identifierTypeService
.getDisplayedPatientIdentifierTypes( true );
assertEquals( 2, identifierTypes.size() );
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java 2013-11-08 07:40:31 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java 2013-11-11 02:42:44 +0000
@@ -169,7 +169,6 @@
patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
Collection<PatientRegistrationForm> forms = patientRegistrationFormService.getAllPatientRegistrationForms();
- System.out.println( "\n\n forms : " + forms );
assertEquals( 2, forms.size() );
assertTrue( forms.contains( patientRegistrationFormA ) );
assertTrue( forms.contains( patientRegistrationFormB ) );
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientReminderServiceTest.java 2013-11-11 02:42:44 +0000
@@ -0,0 +1,195 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.mock.MockI18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+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.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ PatientAttributeGroupServiceTest.java Nov 5, 2013 3:11:48 PM $
+ */
+public class PatientReminderServiceTest
+ extends DhisSpringTest
+{
+ @Autowired
+ private PatientReminderService patientReminderService;
+
+ @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 UserService userService;
+
+ protected MockI18nFormat mockFormat;
+
+ private ProgramInstance programInstance;
+
+ private PatientReminder patientReminderA;
+
+ private PatientReminder patientReminderB;
+
+ private PatientReminder patientReminderC;
+
+ private Patient patient;
+
+ private ProgramStage stageA;
+
+ private User user;
+
+ @Override
+ public void setUpTest()
+ {
+ mockFormat = new MockI18nFormat();
+
+ OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+ organisationUnitService.addOrganisationUnit( organisationUnit );
+ Set<OrganisationUnit> orgUnits = new HashSet<OrganisationUnit>();
+ orgUnits.add( organisationUnit );
+
+ user = new User();
+ user.setSurname( "A" );
+ user.setFirstName( "B" );
+ user.setPhoneNumber( "111-222-333" );
+ user.updateOrganisationUnits( orgUnits );
+ userService.addUser( user );
+
+ patient = createPatient( 'A', organisationUnit );
+ patientService.savePatient( patient );
+
+ Program program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+ patientReminderA = new PatientReminder( "A", 0, "Test program message template "
+ + PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, PatientReminder.ENROLLEMENT_DATE_TO_COMPARE,
+ PatientReminder.SEND_TO_PATIENT, PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT,
+ PatientReminder.MESSAGE_TYPE_DIRECT_SMS );
+ Set<PatientReminder> patientReminders = new HashSet<PatientReminder>();
+ patientReminders.add( patientReminderA );
+ program.setPatientReminders( patientReminders );
+ programService.addProgram( program );
+
+ stageA = new ProgramStage( "A", program );
+ patientReminderB = new PatientReminder( "B", 0, "Test event template"
+ + PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, PatientReminder.DUE_DATE_TO_COMPARE,
+ PatientReminder.SEND_TO_PATIENT, PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT,
+ PatientReminder.MESSAGE_TYPE_DIRECT_SMS );
+ patientReminders = new HashSet<PatientReminder>();
+ patientReminders.add( patientReminderB );
+ stageA.setPatientReminders( patientReminders );
+ programStageService.saveProgramStage( stageA );
+
+ ProgramStage stageB = new ProgramStage( "B", program );
+ patientReminderC = new PatientReminder( "C", 0, "Test event template"
+ + PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, PatientReminder.DUE_DATE_TO_COMPARE,
+ PatientReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED, PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT,
+ PatientReminder.MESSAGE_TYPE_DIRECT_SMS );
+ patientReminders = new HashSet<PatientReminder>();
+ patientReminders.add( patientReminderB );
+ stageA.setPatientReminders( patientReminders );
+
+ Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+ programStages.add( stageA );
+ programStages.add( stageB );
+ program.setProgramStages( programStages );
+ programStageService.saveProgramStage( stageB );
+
+ programService.updateProgram( program );
+
+ programInstance = programInstanceService.enrollPatient( patient, program, new Date(), new Date(),
+ organisationUnit, null );
+ }
+
+ @Test
+ public void testGetMessageFromTemplateByProgram()
+ {
+ String message = patientReminderService.getMessageFromTemplate( patientReminderA, programInstance, mockFormat );
+ assertEquals( "Test program message template NameA", message );
+ }
+
+ @Test
+ public void testGetMessageFromTemplateByProgramStage()
+ {
+ ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(
+ programInstance, stageA );
+ String message = patientReminderService.getMessageFromTemplate( patientReminderA, programStageInstance,
+ mockFormat );
+ assertEquals( "Test program message template NameA", message );
+ }
+
+ @Test
+ public void testGetPhonenumbers()
+ {
+ Set<String> phoneNumbers = patientReminderService.getPhonenumbers( patientReminderA, patient );
+ assertEquals( 1, phoneNumbers.size() );
+ assertTrue( phoneNumbers.contains( "123456789" ) );
+ }
+
+ @Test
+ public void testGetUsers()
+ {
+ Set<User> users = patientReminderService.getUsers( patientReminderC, patient );
+ assertEquals( 1, users.size() );
+ assertTrue( users.contains( user ) );
+ }
+}