dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23476
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11433: revise dhis-service-mobile test
------------------------------------------------------------
revno: 11433
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Thu 2013-07-18 13:31:42 +0700
message:
revise dhis-service-mobile test
modified:
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
dhis-2/dhis-services/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/service/ActivityReportingServiceTest.java
dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.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-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java 2013-05-16 08:40:58 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java 2013-07-18 06:31:42 +0000
@@ -57,6 +57,9 @@
public Patient findPatient( String name, int orgUnitId )
throws NotAllowedException;
+ public Patient findPatient( int patientId )
+ throws NotAllowedException;
+
public String saveProgramStage( ProgramStage programStage, int patientId, int orgUnitId )
throws NotAllowedException;
@@ -83,8 +86,11 @@
public Program findProgram( String programInfo )
throws NotAllowedException;
- public Patient findLatestPatient() throws NotAllowedException;
-
- public String savePatient(Patient patient, int orgUnitId) throws NotAllowedException;
+
+ public Patient findLatestPatient()
+ throws NotAllowedException;
+
+ public Integer savePatient( Patient patient, int orgUnitId )
+ throws NotAllowedException;
}
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2013-07-11 07:56:43 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2013-07-18 06:31:42 +0000
@@ -453,6 +453,7 @@
lastName = keyword.substring( endIndex + 1, keyword.length() );
}
}
+
List<Patient> patients = (List<Patient>) this.patientService.getPatientByFullname( firstName + middleName
+ lastName, orgUnitId );
@@ -477,7 +478,7 @@
else
{
org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patients.get( 0 ) );
-
+
return patientMobile;
}
}
@@ -486,7 +487,7 @@
Patient patient = patientService.getPatient( Integer.parseInt( keyword ) );
org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patient );
-
+
return patientMobile;
}
@@ -503,9 +504,10 @@
ProgramStageInstance prStageInstance = programStageInstanceService
.getProgramStageInstance( mobileProgramStage.getId() );
ProgramStage programStage = programStageService.getProgramStage( prStageInstance.getProgramStage().getId() );
- //ProgramStage programStage = programStageService.getProgramStage( mobileProgramStage.getId() );
+ // ProgramStage programStage = programStageService.getProgramStage(
+ // mobileProgramStage.getId() );
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
-
+
// ---------------------------------------------------------------------
// Add a new program-instance
// ---------------------------------------------------------------------
@@ -556,31 +558,30 @@
}
return SINGLE_EVENT_UPLOADED;
-
+
}
else
{
ProgramStageInstance programStageInstance = programStageInstanceService
.getProgramStageInstance( mobileProgramStage.getId() );
-
- /*//Begin Changes
- ProgramStage programStage = programStageService.getProgramStage( mobileProgramStage.getId() );
- Patient patient = patientService.getPatient( patientId );
- Program program = programStage.getProgram();
-
- Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient, program );
- ProgramStageInstance programStageInstance = null;
- for ( ProgramInstance each : programInstances )
- {
- if( each.getStatus()==ProgramInstance.STATUS_ACTIVE )
- {
- programStageInstance = programStageInstanceService.getProgramStageInstance( each, programStage );
- break;
- }
- }
- //End Changes
-*/
+ /*
+ * //Begin Changes ProgramStage programStage =
+ * programStageService.getProgramStage( mobileProgramStage.getId()
+ * ); Patient patient = patientService.getPatient( patientId );
+ * Program program = programStage.getProgram();
+ *
+ * Collection<ProgramInstance> programInstances =
+ * programInstanceService.getProgramInstances( patient, program );
+ * ProgramStageInstance programStageInstance = null; for (
+ * ProgramInstance each : programInstances ) { if(
+ * each.getStatus()==ProgramInstance.STATUS_ACTIVE ) {
+ * programStageInstance =
+ * programStageInstanceService.getProgramStageInstance( each,
+ * programStage ); break; } }
+ *
+ * //End Changes
+ */
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> dataElements = mobileProgramStage
.getDataElements();
@@ -721,7 +722,7 @@
private Activity getActivity( ProgramStageInstance instance, boolean late )
{
-
+
Activity activity = new Activity();
Patient patient = instance.getProgramInstance().getPatient();
@@ -852,7 +853,10 @@
Period period = new Period( new DateTime( patient.getBirthDate() ), new DateTime() );
patientModel.setAge( period.getYears() );
- patientModel.setOrganisationUnitName( patient.getOrganisationUnit().getName() );
+ if ( patient.getOrganisationUnit() != null )
+ {
+ patientModel.setOrganisationUnitName( patient.getOrganisationUnit().getName() );
+ }
patientModel.setPhoneNumber( patient.getPhoneNumber() );
this.setSetting( getSettings() );
@@ -920,7 +924,7 @@
List<ProgramInstance> listOfProgramInstance = new ArrayList<ProgramInstance>(
programInstanceService.getProgramInstances( patient ) );
-
+
if ( listOfProgramInstance.size() > 0 )
{
for ( ProgramInstance each : listOfProgramInstance )
@@ -930,31 +934,26 @@
}
patientModel.setPrograms( mobileProgramList );
- /*List<Integer> mobileProgramIDList = new ArrayList<Integer>();
- for ( Program eachProgram : patient.getPrograms())
- {
- mobileProgramIDList.add( eachProgram.getId() );
- }
- patientModel.setProgramsID( mobileProgramIDList );
-
- // Set patient Data value for off-line storage function
- Map<Integer, String> patientDataValues = new HashMap<Integer, String>();
- for ( ProgramInstance eachProgramInstance : programInstanceService.getProgramInstances( patient, ProgramInstance.STATUS_ACTIVE ) )
- {
- for ( ProgramStageInstance eachProgramStageInstance : eachProgramInstance.getProgramStageInstances() )
- {
- for ( PatientDataValue each : patientDataValueService.getPatientDataValues( eachProgramStageInstance ) )
- {
- if( each.getValue() != null && !each.getValue().isEmpty())
- {
- Integer dataElementID = each.getDataElement().getId();
- String value = each.getValue();
- patientDataValues.put( dataElementID, value );
- }
- }
- }
- }
- patientModel.setPatientDataValues( patientDataValues );*/
+ /*
+ * List<Integer> mobileProgramIDList = new ArrayList<Integer>(); for (
+ * Program eachProgram : patient.getPrograms()) {
+ * mobileProgramIDList.add( eachProgram.getId() ); }
+ * patientModel.setProgramsID( mobileProgramIDList );
+ *
+ * // Set patient Data value for off-line storage function Map<Integer,
+ * String> patientDataValues = new HashMap<Integer, String>(); for (
+ * ProgramInstance eachProgramInstance :
+ * programInstanceService.getProgramInstances( patient,
+ * ProgramInstance.STATUS_ACTIVE ) ) { for ( ProgramStageInstance
+ * eachProgramStageInstance :
+ * eachProgramInstance.getProgramStageInstances() ) { for (
+ * PatientDataValue each : patientDataValueService.getPatientDataValues(
+ * eachProgramStageInstance ) ) { if( each.getValue() != null &&
+ * !each.getValue().isEmpty()) { Integer dataElementID =
+ * each.getDataElement().getId(); String value = each.getValue();
+ * patientDataValues.put( dataElementID, value ); } } } }
+ * patientModel.setPatientDataValues( patientDataValues );
+ */
// Set Relationship
List<Relationship> relationships = new ArrayList<Relationship>(
@@ -970,16 +969,20 @@
relationshipMobile.setName( eachRelationship.getRelationshipType().getaIsToB() );
relationshipMobile.setPersonBName( eachRelationship.getPatientB().getFullName() );
relationshipMobile.setPersonBId( eachRelationship.getPatientB().getId() );
- //relationshipMobile.setPersonAName( eachRelationship.getPatientA().getFullName() );
- //relationshipMobile.setPersonAId( eachRelationship.getPatientA().getId() );
+ // relationshipMobile.setPersonAName(
+ // eachRelationship.getPatientA().getFullName() );
+ // relationshipMobile.setPersonAId(
+ // eachRelationship.getPatientA().getId() );
}
else
{
relationshipMobile.setName( eachRelationship.getRelationshipType().getbIsToA() );
relationshipMobile.setPersonBName( eachRelationship.getPatientA().getFullName() );
relationshipMobile.setPersonBId( eachRelationship.getPatientA().getId() );
- //relationshipMobile.setPersonAName( eachRelationship.getPatientB().getFullName() );
- //relationshipMobile.setPersonAId( eachRelationship.getPatientB().getId() );
+ // relationshipMobile.setPersonAName(
+ // eachRelationship.getPatientB().getFullName() );
+ // relationshipMobile.setPersonAId(
+ // eachRelationship.getPatientB().getId() );
}
relationshipList.add( relationshipMobile );
}
@@ -1132,18 +1135,17 @@
{
mobileDataElement.setValue( null );
}
-
+
// Option set
if ( programStageDataElement.getDataElement().getOptionSet() != null )
{
- mobileDataElement.setOptionSet( modelMapping.getOptionSet( programStageDataElement
- .getDataElement() ) );
+ mobileDataElement.setOptionSet( modelMapping.getOptionSet( programStageDataElement.getDataElement() ) );
}
else
{
mobileDataElement.setOptionSet( null );
}
-
+
// Category Option Combo
if ( programStageDataElement.getDataElement().getCategoryCombo() != null )
{
@@ -1409,8 +1411,7 @@
if ( programStageDataElement.getDataElement().getOptionSet() != null )
{
- mobileDataElement.setOptionSet( modelMapping.getOptionSet( programStageDataElement
- .getDataElement() ) );
+ mobileDataElement.setOptionSet( modelMapping.getOptionSet( programStageDataElement.getDataElement() ) );
}
else
{
@@ -1722,7 +1723,7 @@
}
@Override
- public String savePatient( org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patient, int orgUnitId )
+ public Integer savePatient( org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patient, int orgUnitId )
throws NotAllowedException
{
org.hisp.dhis.patient.Patient patientWeb = new org.hisp.dhis.patient.Patient();
@@ -1824,7 +1825,16 @@
patientId = patientService.createPatient( patientWeb, null, null, patientAttributeValues );
- return PATIENT_REGISTERED;
-
+ return patientId;
+
+ }
+
+ @Override
+ public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient findPatient( int patientId )
+ throws NotAllowedException
+ {
+ Patient patient = this.patientService.getPatient( patientId );
+ org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patient );
+ return patientMobile;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2013-07-16 11:57:30 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2013-07-18 06:31:42 +0000
@@ -54,5 +54,5 @@
<property name="clazz" value="org.hisp.dhis.patient.PatientMobileSetting"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
-
+
</beans>
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/service/ActivityReportingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/service/ActivityReportingServiceTest.java 2013-07-17 09:52:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/service/ActivityReportingServiceTest.java 2013-07-18 06:31:42 +0000
@@ -1,5 +1,32 @@
package org.hisp.dhis.mobile.service;
+/*
+ * Copyright (c) 2010, 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.*;
import java.util.ArrayList;
@@ -22,22 +49,23 @@
@Test
public void testSavePatient()
+ throws NotAllowedException
{
Patient patientA = this.createLWUITPatient( 'A' );
Patient patientB = this.createLWUITPatient( 'B' );
- try
- {
- assertNotNull( activityReportingService.savePatient( patientA, 779 ) );
- assertNotNull( activityReportingService.savePatient( patientB, 779 ) );
- }
- catch ( NotAllowedException e )
- {
- e.printStackTrace();
- }
-
+
+ int patientAId = activityReportingService.savePatient( patientA, 779 );
+ int patientBId = activityReportingService.savePatient( patientB, 779 );
+
+ patientA = activityReportingService.findPatient( patientAId );
+ assertEquals( patientAId, patientA.getId() );
+ assertEquals( "FirstnameA", patientA.getFirstName() );
+
+ patientB = activityReportingService.findPatient( patientBId );
+ assertEquals( patientBId, patientB.getId() );
+ assertEquals( "FirstnameB", patientB.getFirstName() );
}
-
private Patient createLWUITPatient( char uniqueCharacter )
{
Patient patient = new Patient();
@@ -45,7 +73,7 @@
patient.setBirthDate( new Date() );
patient.setFirstName( "Firstname" + uniqueCharacter );
patient.setMiddleName( "Middlename" + uniqueCharacter );
- patient.setLastName( "LastName" + uniqueCharacter );
+ patient.setLastName( "Lastname" + uniqueCharacter );
patient.setGender( "male" );
patient.setOrganisationUnitName( "OrgUnitName" );
patient.setPhoneNumber( "095678943" );
=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-07-11 07:56:43 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-07-18 06:31:42 +0000
@@ -47,6 +47,10 @@
private static final String DATASET_REPORT_UPLOADED = "dataset_report_uploaded";
+ private static final String PATIENT_REGISTERED = "patient_registered";
+
+ private static final String PATIENT_REGISTER_FAIL = "patient_registered_fail";
+
@Autowired
private ActivityReportingService activityReportingService;
@@ -408,9 +412,14 @@
public String savePatient( @PathVariable int id, @RequestBody Patient patient )
throws NotAllowedException
{
-
- return activityReportingService.savePatient( patient, id );
-
+ if ( activityReportingService.savePatient( patient, id ) != null )
+ {
+ return PATIENT_REGISTERED;
+ }
+ else
+ {
+ return PATIENT_REGISTER_FAIL;
+ }
}
@RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/getVariesInfo" )