← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12211: minor fixes to event service and tests

 

------------------------------------------------------------
revno: 12211
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-23 14:07:14 +0200
message:
  minor fixes to event service and tests
modified:
  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/event/AbstractEventService.java'
--- 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
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2013-09-23 12:07:14 +0000
@@ -216,12 +216,12 @@
 
                 if ( programStageInstances.isEmpty() )
                 {
-                    return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + " is not enrolled in program " + program.getUid() );
+                    return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + " is not enrolled in programStage " + programStage.getUid() );
                 }
                 else if ( programStageInstances.size() > 1 )
                 {
                     return new ImportSummary( ImportStatus.ERROR,
-                        "Person " + patient.getUid() + " have multiple active enrollments into program " + program.getUid()
+                        "Person " + patient.getUid() + " have multiple active enrollments into programStage " + programStage.getUid()
                             + " please check and correct your database for multiple active events." );
                 }
 
@@ -567,6 +567,14 @@
         Coordinate coordinate, String storedBy )
     {
         ProgramStageInstance programStageInstance = new ProgramStageInstance();
+        updateProgramStageInstance( programStage, programInstance, organisationUnit, date, completed, coordinate, storedBy, programStageInstance );
+        programStageInstanceService.addProgramStageInstance( programStageInstance );
+
+        return programStageInstance;
+    }
+
+    private void updateProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance, OrganisationUnit organisationUnit, Date date, Boolean completed, Coordinate coordinate, String storedBy, ProgramStageInstance programStageInstance )
+    {
         programStageInstance.setProgramInstance( programInstance );
         programStageInstance.setProgramStage( programStage );
         programStageInstance.setDueDate( date );
@@ -585,16 +593,15 @@
             }
         }
 
-        if ( completed != null )
+        programStageInstance.setCompleted( completed );
+
+        if ( programStageInstance.isCompleted() )
         {
-            programStageInstance.setCompleted( completed );
+            programStageInstance.setStatus( ProgramStageInstance.COMPLETED_STATUS );
             programStageInstance.setCompletedDate( new Date() );
             programStageInstance.setCompletedUser( storedBy );
+            programStageInstanceService.completeProgramStageInstance( programStageInstance, getFormat() );
         }
-
-        programStageInstanceService.addProgramStageInstance( programStageInstance );
-
-        return programStageInstance;
     }
 
     private ImportSummary saveEvent( Program program, ProgramInstance programInstance, ProgramStage programStage, ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions )
@@ -607,11 +614,6 @@
         importSummary.setStatus( ImportStatus.SUCCESS );
         boolean dryRun = importOptions != null && importOptions.isDryRun();
 
-        if ( !program.isSingleEvent() )
-        {
-            return new ImportSummary( ImportStatus.ERROR, "Multi-event programs are not supported right now." );
-        }
-
         Date eventDate = getFormat().parseDate( event.getEventDate() );
 
         if ( eventDate == null )
@@ -621,16 +623,22 @@
 
         String storedBy = getStoredBy( event, importSummary );
 
-        if ( !dryRun && programStageInstance == null )
+        if ( !dryRun )
         {
-            programStageInstance = createProgramStageInstance( programStage, programInstance, organisationUnit, eventDate,
-                event.getCompleted(), event.getCoordinate(), storedBy );
+            if ( programStageInstance == null )
+            {
+                programStageInstance = createProgramStageInstance( programStage, programInstance, organisationUnit, eventDate,
+                    event.getCompleted(), event.getCoordinate(), storedBy );
+            }
+            else
+            {
+                updateProgramStageInstance( programStage, programInstance, organisationUnit, eventDate,
+                    event.getCompleted(), event.getCoordinate(), storedBy, programStageInstance );
+            }
+
+            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 10:29:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java	2013-09-23 12:07:14 +0000
@@ -37,7 +37,6 @@
 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;
@@ -224,7 +223,6 @@
 
         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 );
@@ -235,7 +233,6 @@
 
         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 );

=== 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-23 10:29:51 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2013-09-23 12:07:14 +0000
@@ -739,6 +739,7 @@
         // -----------------------------------------------------------------
 
         List<MessageConversation> messageConversations = programInstance.getMessageConversations();
+
         if ( messageConversations == null )
         {
             messageConversations = new ArrayList<MessageConversation>();
@@ -752,7 +753,6 @@
         // -----------------------------------------------------------------
 
         programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
-
         programInstance.setEndDate( new Date() );
 
         updateProgramInstance( programInstance );