← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10629: Fix bug when to change type of program from non-anonymous to anonymous program.

 

------------------------------------------------------------
revno: 10629
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-19 10:50:54 +0700
message:
  Fix bug when to change type of program from non-anonymous to anonymous program.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.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-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-04-19 03:31:52 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-04-19 03:50:54 +0000
@@ -215,6 +215,7 @@
         executeSql( "ALTER TABLE patient ALTER COLUMN birthdate DROP NOT NULL");
         executeSql( "ALTER TABLE patient ALTER COLUMN gender DROP NOT NULL");
         executeSql( "ALTER TABLE patient ALTER COLUMN underage DROP NOT NULL");
+        executeSql( "ALTER TABLE program ALTER COLUMN dateofenrollmentdescription DROP NOT NULL");
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2013-04-19 03:31:52 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2013-04-19 03:50:54 +0000
@@ -19,7 +19,7 @@
 
     <property name="version" />
 
-    <property name="dateOfEnrollmentDescription" type="text" not-null="true" />
+    <property name="dateOfEnrollmentDescription" type="text" />
 
     <property name="dateOfIncidentDescription" type="text" />
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java	2013-04-10 03:13:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java	2013-04-19 03:50:54 +0000
@@ -27,6 +27,7 @@
 
 package org.hisp.dhis.caseentry.action.caseentry;
 
+import java.util.Collection;
 import java.util.Date;
 
 import org.apache.commons.logging.Log;
@@ -164,14 +165,16 @@
     {
         Date dateValue = format.parseDate( executionDate );
 
-        OrganisationUnit organisationUnit = organisationUnitId == null ? selectedStateManager.getSelectedOrganisationUnit() :
-            organisationUnitService.getOrganisationUnit( organisationUnitId );
+        OrganisationUnit organisationUnit = organisationUnitId == null ? selectedStateManager
+            .getSelectedOrganisationUnit() : organisationUnitService.getOrganisationUnit( organisationUnitId );
 
-        Patient patient = patientId == null ? selectedStateManager.getSelectedPatient() : patientService.getPatient( patientId );
+        Patient patient = patientId == null ? selectedStateManager.getSelectedPatient() : patientService
+            .getPatient( patientId );
 
         if ( dateValue != null )
         {
-            ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId );
+            ProgramStageInstance programStageInstance = programStageInstanceService
+                .getProgramStageInstance( programStageInstanceId );
 
             // If the program-stage-instance of the patient not exists,
             // create a program-instance and program-stage-instance for
@@ -206,7 +209,21 @@
                 }
                 else if ( type == Program.SINGLE_EVENT_WITHOUT_REGISTRATION )
                 {
-                    programInstance = programInstanceService.getProgramInstances( program ).iterator().next();
+                    Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( program );
+                    if ( programInstances == null || programInstances.size() == 0 )
+                    {
+                        // Add a new program-instance
+                        programInstance = new ProgramInstance();
+                        programInstance.setEnrollmentDate( dateValue );
+                        programInstance.setDateOfIncident( dateValue );
+                        programInstance.setProgram( program );
+                        programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
+                        programInstanceService.addProgramInstance( programInstance );
+                    }
+                    else
+                    {
+                        programInstance = programInstanceService.getProgramInstances( program ).iterator().next();
+                    }
                 }
 
                 // Add a new program-stage-instance