← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12209: more tests, and error description refinement

 

------------------------------------------------------------
revno: 12209
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-23 12:29:51 +0200
message:
  more tests, and error description refinement
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.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-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2013-09-23 10:29:51 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.Assert;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -300,6 +301,8 @@
     public void deleteEnrollment( Enrollment enrollment )
     {
         ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
+        Assert.notNull( programInstance );
+
         programInstanceService.deleteProgramInstance( programInstance );
     }
 
@@ -307,6 +310,8 @@
     public void cancelEnrollment( Enrollment enrollment )
     {
         ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
+        Assert.notNull( programInstance );
+
         programInstanceService.cancelProgramInstanceStatus( programInstance );
     }
 
@@ -314,6 +319,8 @@
     public void completeEnrollment( Enrollment enrollment )
     {
         ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
+        Assert.notNull( programInstance );
+
         programInstanceService.completeProgramInstanceStatus( programInstance, getFormat() );
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2013-09-23 08:37:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2013-09-23 10:29:51 +0000
@@ -216,13 +216,13 @@
 
                 if ( programStageInstances.isEmpty() )
                 {
-                    return new ImportSummary( ImportStatus.ERROR, "No active event exists for single event registration program " + program.getUid()
-                        + ", please check and correct your database." );
+                    return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + " is not enrolled in program " + program.getUid() );
                 }
                 else if ( programStageInstances.size() > 1 )
                 {
-                    return new ImportSummary( ImportStatus.ERROR, "Multiple active events exists for single event registration program " + program.getUid()
-                        + ", please check and correct your database." );
+                    return new ImportSummary( ImportStatus.ERROR,
+                        "Person " + patient.getUid() + " have multiple active enrollments into program " + program.getUid()
+                            + " please check and correct your database for multiple active events." );
                 }
 
                 programStageInstance = programStageInstances.get( 0 );
@@ -625,10 +625,12 @@
         {
             programStageInstance = createProgramStageInstance( programStage, programInstance, organisationUnit, eventDate,
                 event.getCompleted(), event.getCoordinate(), storedBy );
-
-            importSummary.setReference( programStageInstance.getUid() );
         }
 
+        programStageInstance.setStatus( event.getStatus().getValue() );
+        programStageInstance.setCompleted( event.getCompleted() );
+        importSummary.setReference( programStageInstance.getUid() );
+
         for ( DataValue dataValue : event.getDataValues() )
         {
             DataElement dataElement = dataElementService.getDataElement( dataValue.getDataElement() );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java	2013-09-23 08:37:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java	2013-09-23 10:29:51 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.dxf2.events.event.DataValue;
 import org.hisp.dhis.dxf2.events.event.Event;
 import org.hisp.dhis.dxf2.events.event.EventService;
+import org.hisp.dhis.dxf2.events.event.EventStatus;
 import org.hisp.dhis.dxf2.events.person.Person;
 import org.hisp.dhis.dxf2.events.person.PersonService;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
@@ -57,8 +58,7 @@
 import java.util.Date;
 import java.util.HashSet;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.*;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -216,6 +216,34 @@
         assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
     }
 
+    @Test
+    public void testMultipleEnrollmentsWithEventShouldGiveDifferentUIDs()
+    {
+        Enrollment enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
+        enrollmentService.saveEnrollment( enrollment );
+
+        Event event = createEvent( programA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson() );
+        event.setCompleted( true );
+        event.setStatus( EventStatus.COMPLETED );
+        ImportSummary importSummary1 = eventService.saveEvent( event );
+        assertEquals( ImportStatus.SUCCESS, importSummary1.getStatus() );
+        enrollment = enrollmentService.getEnrollments( personMaleA ).getEnrollments().get( 0 );
+        enrollmentService.completeEnrollment( enrollment );
+
+        enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
+        enrollmentService.saveEnrollment( enrollment );
+
+        event = createEvent( programA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson() );
+        event.setCompleted( true );
+        event.setStatus( EventStatus.COMPLETED );
+        ImportSummary importSummary2 = eventService.saveEvent( event );
+        assertEquals( ImportStatus.SUCCESS, importSummary2.getStatus() );
+        enrollment = enrollmentService.getEnrollments( personMaleA ).getEnrollments().get( 0 );
+        enrollmentService.completeEnrollment( enrollment );
+
+        assertNotEquals( importSummary1.getReference(), importSummary2.getReference() );
+    }
+
     private Enrollment createEnrollment( String program, String person )
     {
         Enrollment enrollment = new Enrollment();

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2013-09-20 09:01:03 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2013-09-23 10:29:51 +0000
@@ -726,6 +726,7 @@
         // ---------------------------------------------------------------------
 
         List<OutboundSms> outboundSms = programInstance.getOutboundSms();
+
         if ( outboundSms == null )
         {
             outboundSms = new ArrayList<OutboundSms>();