← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10505: Create a new property Status for program-instance and remove Completed property.

 

------------------------------------------------------------
revno: 10505
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-04-10 10:13:47 +0700
message:
  Create a new property Status for program-instance and remove Completed property.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.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/java/org/hisp/dhis/mobile/service/FacilityReportingServiceImpl.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  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/program/DefaultProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java
  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/SaveValuesAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UncompleteDataEntryAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SetProgramInstanceStatusAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SaveAnonymousProgramAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetPatientProgramListAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-04-10 03:13:47 +0000
@@ -111,7 +111,7 @@
     private Set<UserAuthorityGroup> userRoles = new HashSet<UserAuthorityGroup>();
     
     private Boolean onlyEnrollOnce = false;
-
+    
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2013-04-10 03:13:47 +0000
@@ -50,6 +50,12 @@
 public class ProgramInstance
     implements Serializable
 {
+   public static int STATUS_ACTIVE = 0;
+   
+   public static int STATUS_COMPLETED = 1;
+   
+   public static int STATUS_CANCELLED = 2;
+   
     /**
      * Determines if a de-serialized file is compatible with this class.
      */
@@ -62,8 +68,8 @@
     private Date enrollmentDate;
 
     private Date endDate;
-
-    private boolean completed = false;
+    
+    private Integer status = STATUS_ACTIVE;
 
     private Patient patient;
 
@@ -86,12 +92,7 @@
         this.patient = patient;
         this.program = program;
     }
-
-    // -------------------------------------------------------------------------
-    // hashCode and equals
-    // -------------------------------------------------------------------------
-
-
+    
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -254,25 +255,23 @@
         this.endDate = endDate;
     }
 
+    
     /**
-     * @return the completed
+     * @return the status
      */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public boolean isCompleted()
-    {
-        return completed;
-    }
-
-    /**
-     * @param completed the completed to set
-     */
-    public void setCompleted( boolean completed )
-    {
-        this.completed = completed;
-    }
-
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )    
+    public int getStatus()
+    {
+        return status.intValue();
+    }
+
+    public void setStatus( Integer status )
+    {
+        this.status = status;
+    }
+    
     /**
      * @return the patient
      */

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java	2013-03-15 14:43:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java	2013-04-10 03:13:47 +0000
@@ -54,23 +54,23 @@
 
     Collection<ProgramInstance> getAllProgramInstances();
 
-    Collection<ProgramInstance> getProgramInstances( boolean completed );
+    Collection<ProgramInstance> getProgramInstances( Integer status );
 
     Collection<ProgramInstance> getProgramInstances( Program program );
 
     Collection<ProgramInstance> getProgramInstances( Collection<Program> programs );
 
-    Collection<ProgramInstance> getProgramInstances( Program program, boolean completed );
+    Collection<ProgramInstance> getProgramInstances( Program program, Integer status );
 
-    Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, boolean completed );
+    Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, Integer status );
 
     Collection<ProgramInstance> getProgramInstances( Patient patient );
 
-    Collection<ProgramInstance> getProgramInstances( Patient patient, boolean completed );
+    Collection<ProgramInstance> getProgramInstances( Patient patient, Integer status );
 
     Collection<ProgramInstance> getProgramInstances( Patient patient, Program program );
 
-    Collection<ProgramInstance> getProgramInstances( Patient patient, Program program, boolean completed );
+    Collection<ProgramInstance> getProgramInstances( Patient patient, Program program, Integer status );
 
     Collection<ProgramInstance> getProgramInstances( Program program, OrganisationUnit organisationUnit );
 
@@ -82,23 +82,19 @@
 
     Collection<ProgramInstance> getProgramInstances( Program program, Collection<Integer> orgunitIds, Date startDate,
         Date endDate, int min, int max );
-
-    int countProgramInstances( Program program, OrganisationUnit organisationUnit );
-
+    
     int countProgramInstances( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
 
-    int countProgramInstances( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
-        boolean completed );
-
     List<Grid> getProgramInstanceReport( Patient patient, I18n i18n, I18nFormat format );
 
     Grid getProgramInstanceReport( ProgramInstance programInstance, I18n i18n, I18nFormat format );
-    
-    Collection<ProgramInstance> getUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate,
+
+    int countProgramInstancesByStatus( Integer status, Program program, Collection<Integer> orgunitIds, Date startDate,
         Date endDate );
 
-    int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
-    
+    Collection<ProgramInstance> getProgramInstancesByStatus( Integer status, Program program,
+        Collection<Integer> orgunitIds, Date startDate, Date endDate );
+
     void removeProgramEnrollment( ProgramInstance programInstance );
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java	2013-03-15 14:43:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java	2013-04-10 03:13:47 +0000
@@ -42,23 +42,23 @@
 {
     String ID = ProgramInstanceStore.class.getName();
 
-    Collection<ProgramInstance> get( boolean completed );
+    Collection<ProgramInstance> get( Integer status );
 
     Collection<ProgramInstance> get( Program program );
 
     Collection<ProgramInstance> get( Collection<Program> programs );
 
-    Collection<ProgramInstance> get( Program program, boolean completed );
+    Collection<ProgramInstance> get( Program program, Integer status );
 
-    Collection<ProgramInstance> get( Collection<Program> programs, boolean completed );
+    Collection<ProgramInstance> get( Collection<Program> programs, Integer status );
 
     Collection<ProgramInstance> get( Patient patient );
 
-    Collection<ProgramInstance> get( Patient patient, boolean completed );
+    Collection<ProgramInstance> get( Patient patient, Integer status );
 
     Collection<ProgramInstance> get( Patient patient, Program program );
 
-    Collection<ProgramInstance> get( Patient patient, Program program, boolean completed );
+    Collection<ProgramInstance> get( Patient patient, Program program, Integer status );
 
     Collection<ProgramInstance> get( Program program, OrganisationUnit organisationUnit );
 
@@ -73,11 +73,14 @@
     
     int count( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
     
-    int count( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean completed );
-
-    Collection<ProgramInstance> getUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
-    
-    int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
+//    Collection<ProgramInstance> getUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
+//    
+//    int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
    
     void removeProgramEnrollment( ProgramInstance programInstance );
+    
+    int countByStatus( Integer status, Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
+    
+    Collection<ProgramInstance> getByStatus( Integer status, Program program, Collection<Integer> orgunitIds,
+        Date startDate, Date endDate );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-04-09 05:48:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-04-10 03:13:47 +0000
@@ -124,7 +124,7 @@
 
     int getOverDueEventCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate, Date endDate );
 
-    int averageNumberCompletedProgramInstance( Program program , Collection<Integer> orgunitIds, Date startDate, Date endDate, Boolean completed );
+    int averageNumberCompletedProgramInstance( Program program , Collection<Integer> orgunitIds, Date startDate, Date endDate, Integer status );
     
     Collection<Integer> getOrganisationUnitIds ( Date startDate, Date endDate );
     

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2013-04-09 05:48:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2013-04-10 03:13:47 +0000
@@ -122,7 +122,7 @@
     int getOverDueCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate, Date endDate );
 
     int averageNumberCompleted( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
-        Boolean completed );
+        Integer status );
 
     Collection<Integer> getOrgunitIds( Date startDate, Date endDate );
 

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java	2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java	2013-04-10 03:13:47 +0000
@@ -43,7 +43,17 @@
     
     private int version;
     
-    private boolean isCompleted;
+    private Integer status;
+
+    public Integer getStatus()
+    {
+        return status;
+    }
+
+    public void setStatus( Integer status )
+    {
+        this.status = status;
+    }
 
     private List<ProgramStage> programStages;
 
@@ -77,22 +87,13 @@
         this.clientVersion = clientVersion;
     }
 
-    public boolean isCompleted()
-    {
-        return isCompleted;
-    }
-
-    public void setCompleted( boolean isCompleted )
-    {
-        this.isCompleted = isCompleted;
-    }
 
     @Override
     public void serialize( DataOutputStream dout )
         throws IOException
     {
         super.serialize( dout );
-        dout.writeBoolean( this.isCompleted() );
+        dout.writeInt( this.status );
         dout.writeInt( this.getVersion() );
         if( programStages == null )
         {

=== 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-04-03 10:50:16 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2013-04-10 03:13:47 +0000
@@ -483,7 +483,7 @@
 
             programInstance.setProgram( programStage.getProgram() );
 
-            programInstance.setCompleted( true );
+            programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
 
             programInstanceService.addProgramInstance( programInstance );
 
@@ -579,7 +579,7 @@
                 if ( isAllProgramStageFinished( programStageInstance ) == true )
                 {
                     ProgramInstance programInstance = programStageInstance.getProgramInstance();
-                    programInstance.setCompleted( true );
+                    programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
                     programInstanceService.updateProgramInstance( programInstance );
                 }
 
@@ -625,7 +625,7 @@
         programInstance.setDateOfIncident( new Date() );
         programInstance.setProgram( program );
         programInstance.setPatient( patient );
-        programInstance.setCompleted( false );
+        programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
         programInstanceService.addProgramInstance( programInstance );
         patient.getPrograms().add( program );
         patientService.updatePatient( patient );
@@ -918,7 +918,7 @@
             org.hisp.dhis.api.mobile.model.LWUITmodel.Program enrollmentProgramMobile = new org.hisp.dhis.api.mobile.model.LWUITmodel.Program();
             enrollmentProgramMobile.setId( enrollmentProgram.getId() );
             enrollmentProgramMobile.setName( enrollmentProgram.getName() );
-            enrollmentProgramMobile.setCompleted( false );
+            enrollmentProgramMobile.setStatus( ProgramInstance.STATUS_ACTIVE );
             enrollmentProgramMobile.setVersion( enrollmentProgram.getVersion() );
             enrollmentProgramMobile.setProgramStages( null );
             enrollmentProgramListMobileList.add( enrollmentProgramMobile );
@@ -950,7 +950,7 @@
         mobileProgram.setVersion( programInstance.getProgram().getVersion() );
         mobileProgram.setId( programInstance.getId() );
         mobileProgram.setName( programInstance.getProgram().getName() );
-        mobileProgram.setCompleted( programInstance.isCompleted() );
+        mobileProgram.setStatus( programInstance.getStatus() );
         mobileProgram.setProgramStages( getMobileProgramStages( patient, programInstance ) );
         return mobileProgram;
     }
@@ -1013,9 +1013,8 @@
 
     private boolean checkIfProgramStageCompleted( Patient patient, Program program, ProgramStage programstage )
     {
-
         Collection<ProgramInstance> programIntances = programInstanceService.getProgramInstances( patient, program,
-            false );
+            ProgramInstance.STATUS_ACTIVE );
         ProgramStageInstance programStageInstance = new ProgramStageInstance();
         if ( programIntances != null && programIntances.size() == 1 )
         {
@@ -1149,9 +1148,9 @@
         List<Patient> patients = (List<Patient>) this.patientService.getPatientByFullname( firstName + middleName
             + lastName, orgUnitId );
 
-        //remove the own searcher
-        removeIfDuplicated( patients, enrollmentRelationship.getPersonAId());
-        
+        // remove the own searcher
+        removeIfDuplicated( patients, enrollmentRelationship.getPersonAId() );
+
         if ( patients.size() > 1 )
         {
             String patientsInfo = new String();
@@ -1160,8 +1159,8 @@
 
             for ( Patient each : patients )
             {
-                patientsInfo += each.getId() + "/" + each.getFullName() + "/"
-                    + dateFormat.format( each.getBirthDate() ) + "$";
+                patientsInfo += each.getId() + "/" + each.getFullName() + "/" + dateFormat.format( each.getBirthDate() )
+                    + "$";
             }
 
             throw new NotAllowedException( patientsInfo );
@@ -1337,7 +1336,7 @@
 
         return anonymousProgramMobile;
     }
-    
+
     private List<Patient> removeIfDuplicated( List<Patient> patients, int patientId )
     {
         for ( Patient each : patients )

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/FacilityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/FacilityReportingServiceImpl.java	2013-04-03 08:06:46 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/FacilityReportingServiceImpl.java	2013-04-10 03:13:47 +0000
@@ -30,7 +30,6 @@
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -57,9 +56,6 @@
 import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.patient.PatientAttributeService;
-import org.hisp.dhis.patient.PatientIdentifierType;
-import org.hisp.dhis.patient.PatientIdentifierTypeService;
 import org.hisp.dhis.period.DailyPeriodType;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
@@ -68,7 +64,6 @@
 import org.hisp.dhis.period.QuarterlyPeriodType;
 import org.hisp.dhis.period.WeeklyPeriodType;
 import org.hisp.dhis.period.YearlyPeriodType;
-import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.user.CurrentUserService;
 import org.springframework.beans.factory.annotation.Required;

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-04-03 06:20:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-04-10 03:13:47 +0000
@@ -50,6 +50,7 @@
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientStore;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.system.grid.GridUtils;
 import org.hisp.dhis.system.util.TextUtils;
@@ -431,7 +432,7 @@
                 isPriorityEvent = Boolean.parseBoolean( keys[5] );
                 patientWhere += patientOperator + "pgi.patientid=p.patientid and ";
                 patientWhere += "pgi.programid=" + id + " and ";
-                patientWhere += "pgi.completed = false ";
+                patientWhere += "pgi.status=" + ProgramInstance.STATUS_ACTIVE;
 
                 String operatorStatus = "";
                 String condition = " and ( ";
@@ -543,7 +544,7 @@
                 {
                     patientWhere += ")";
                 }
-                patientWhere += " and pgi.completed=false ";
+                patientWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";
                 patientOperator = " and ";
 
             }
@@ -573,7 +574,7 @@
                     break;
                 }
 
-                patientWhere += " and pgi.completed=false ";
+                patientWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";
                 patientOperator = " and ";
             }
         }

=== 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-02 08:24:05 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-04-10 03:13:47 +0000
@@ -199,8 +199,10 @@
         executeSql( "update caseaggregationcondition set \"operator\"='times' where \"operator\"='SUM'" );
 
         updateUid();
-        
+
         updateUidInDataEntryFrom();
+
+        updateProgramInstanceStatus();
     }
 
     // -------------------------------------------------------------------------
@@ -309,7 +311,7 @@
                 }
 
                 inputMatcher.appendTail( sb );
-                
+
                 htmlCode = (sb.toString().isEmpty()) ? htmlCode : sb.toString();
                 dataEntryForm.setHtmlCode( htmlCode );
                 dataEntryForm.setFormat( DataEntryForm.CURRENT_FORMAT );
@@ -317,7 +319,25 @@
             }
         }
     }
-    
+
+    private void updateProgramInstanceStatus()
+    {
+        // Set active status for events
+        executeSql( "UPDATE programinstance SET status=0 WHERE completed=false" );
+
+        // Set un-completed status for events
+        executeSql( "UPDATE programinstance SET status=2 WHERE programinstanceid in "
+            + "( select psi.programinstanceid from programinstance pi join programstageinstance psi "
+            + "on psi.programinstanceid = psi.programstageinstanceid "
+            + "where pi.completed=true and psi.completed = false )" );
+
+        // Set completed status for events
+        executeSql( "UPDATE programinstance SET status=1 WHERE status is null" );
+
+        // Drop the column with name as completed
+        executeSql( "ALTER TABLE programinstance DROP COLUMN completed" );
+    }
+
     private int executeSql( String sql )
     {
         try

=== 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-03-15 14:43:16 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2013-04-10 03:13:47 +0000
@@ -105,9 +105,9 @@
         return programInstanceStore.get( id );
     }
 
-    public Collection<ProgramInstance> getProgramInstances( boolean completed )
+    public Collection<ProgramInstance> getProgramInstances( Integer status )
     {
-        return programInstanceStore.get( completed );
+        return programInstanceStore.get( status );
     }
 
     public void updateProgramInstance( ProgramInstance programInstance )
@@ -125,14 +125,14 @@
         return programInstanceStore.get( programs );
     }
 
-    public Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, boolean completed )
+    public Collection<ProgramInstance> getProgramInstances( Collection<Program> programs,Integer status )
     {
-        return programInstanceStore.get( programs, completed );
+        return programInstanceStore.get( programs, status );
     }
 
-    public Collection<ProgramInstance> getProgramInstances( Program program, boolean completed )
+    public Collection<ProgramInstance> getProgramInstances( Program program, Integer status )
     {
-        return programInstanceStore.get( program, completed );
+        return programInstanceStore.get( program, status );
     }
 
     public Collection<ProgramInstance> getProgramInstances( Patient patient )
@@ -140,9 +140,9 @@
         return programInstanceStore.get( patient );
     }
 
-    public Collection<ProgramInstance> getProgramInstances( Patient patient, boolean completed )
+    public Collection<ProgramInstance> getProgramInstances( Patient patient, Integer status )
     {
-        return programInstanceStore.get( patient, completed );
+        return programInstanceStore.get( patient, status );
     }
 
     public Collection<ProgramInstance> getProgramInstances( Patient patient, Program program )
@@ -150,9 +150,9 @@
         return programInstanceStore.get( patient, program );
     }
 
-    public Collection<ProgramInstance> getProgramInstances( Patient patient, Program program, boolean completed )
+    public Collection<ProgramInstance> getProgramInstances( Patient patient, Program program, Integer status )
     {
-        return programInstanceStore.get( patient, program, completed );
+        return programInstanceStore.get( patient, program, status );
     }
 
     public Collection<ProgramInstance> getProgramInstances( Program program, OrganisationUnit organisationUnit )
@@ -348,24 +348,40 @@
         return grid;
     }
 
-    @Override
-    public Collection<ProgramInstance> getUnenrollment( Program program, Collection<Integer> orgunitIds,
+    public int countProgramInstancesByStatus( Integer status, Program program, Collection<Integer> orgunitIds,
         Date startDate, Date endDate )
     {
-        return programInstanceStore.getUnenrollment( program, orgunitIds, startDate, endDate );
+        return programInstanceStore.countByStatus( status, program, orgunitIds, startDate, endDate );
     }
 
-    @Override
-    public int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate )
+    public Collection<ProgramInstance> getProgramInstancesByStatus( Integer status, Program program,
+        Collection<Integer> orgunitIds, Date startDate, Date endDate )
     {
-        return programInstanceStore.countUnenrollment( program, orgunitIds, startDate, endDate );
+        return programInstanceStore.getByStatus( status, program, orgunitIds, startDate, endDate );
     }
 
+    // @Override
+    // public Collection<ProgramInstance> getUnenrollment( Program program,
+    // Collection<Integer> orgunitIds,
+    // Date startDate, Date endDate )
+    // {
+    // return programInstanceStore.getUnenrollment( program, orgunitIds,
+    // startDate, endDate );
+    // }
+    //
+    // @Override
+    // public int countUnenrollment( Program program, Collection<Integer>
+    // orgunitIds, Date startDate, Date endDate )
+    // {
+    // return programInstanceStore.countUnenrollment( program, orgunitIds,
+    // startDate, endDate );
+    // }
+
     public void removeProgramEnrollment( ProgramInstance programInstance )
     {
         programInstanceStore.removeProgramEnrollment( programInstance );
     }
-    
+
     // -------------------------------------------------------------------------
     // due-date && report-date
     // -------------------------------------------------------------------------
@@ -426,11 +442,4 @@
         }
     }
 
-    @Override
-    public int countProgramInstances( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
-        boolean completed )
-    {
-        return programInstanceStore.count( program, orgunitIds, startDate, endDate, completed );
-    }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2013-04-09 05:48:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2013-04-10 03:13:47 +0000
@@ -333,12 +333,11 @@
 
         // Total programs completed in this period
 
-        int totalDiscontinued = programInstanceService.countUnenrollment( program, orgunitIds, startDate, endDate );
-        int totalCompleted = programInstanceService.countProgramInstances( program, orgunitIds, startDate, endDate,
-            true );
+        int totalCompleted = programInstanceService.countProgramInstancesByStatus( ProgramInstance.STATUS_COMPLETED,
+            program, orgunitIds, startDate, endDate );
         grid.addRow();
         grid.addValue( i18n.getString( "total_programs_completed_in_this_period" ) );
-        grid.addValue( totalCompleted - totalDiscontinued );
+        grid.addValue( totalCompleted );
         grid.addValue( "" );
         grid.addValue( "" );
         grid.addValue( "" );
@@ -347,7 +346,9 @@
         grid.addValue( "" );
 
         // Total programs discontinued (un-enrollments)
-
+        
+        int totalDiscontinued = programInstanceService.countProgramInstancesByStatus( ProgramInstance.STATUS_CANCELLED,
+            program, orgunitIds, startDate, endDate );
         grid.addRow();
         grid.addValue( i18n.getString( "total_programs_discontinued_unenrollments" ) );
         grid.addValue( totalDiscontinued );
@@ -365,8 +366,9 @@
         double percent = 0.0;
         if ( totalCompleted != 0 )
         {
-            int stageCompleted = averageNumberCompletedProgramInstance( program, orgunitIds, startDate, endDate, true );
-            percent = (stageCompleted + 0.0) / (totalCompleted - totalDiscontinued);
+            int stageCompleted = averageNumberCompletedProgramInstance( program, orgunitIds, startDate, endDate,
+                ProgramInstance.STATUS_ACTIVE );
+            percent = (stageCompleted + 0.0) / totalCompleted;
         }
         grid.addValue( format.formatValue( percent ) );
         grid.addValue( "" );
@@ -481,8 +483,8 @@
     @Override
     public Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
         String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters,
-        List<Period> periods, String aggregateType, Integer limit, Boolean useCompletedEvents, Boolean displayTotals, I18nFormat format,
-        I18n i18n )
+        List<Period> periods, String aggregateType, Integer limit, Boolean useCompletedEvents, Boolean displayTotals,
+        I18nFormat format, I18n i18n )
     {
         return programStageInstanceStore.getAggregateReport( position, programStage, orgunitIds, facilityLB, deGroupBy,
             deSum, deFilters, periods, aggregateType, limit, useCompletedEvents, displayTotals, format, i18n );
@@ -497,9 +499,9 @@
 
     @Override
     public int averageNumberCompletedProgramInstance( Program program, Collection<Integer> orgunitIds, Date startDate,
-        Date endDate, Boolean completed )
+        Date endDate, Integer status )
     {
-        return programStageInstanceStore.averageNumberCompleted( program, orgunitIds, startDate, endDate, completed );
+        return programStageInstanceStore.averageNumberCompleted( program, orgunitIds, startDate, endDate, status );
     }
 
     @Override
@@ -507,5 +509,5 @@
     {
         return programStageInstanceStore.getOrgunitIds( startDate, endDate );
     }
-    
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2013-03-15 14:43:16 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2013-04-10 03:13:47 +0000
@@ -30,7 +30,6 @@
 import java.util.Collection;
 import java.util.Date;
 
-import org.hibernate.Criteria;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
@@ -64,11 +63,11 @@
     // -------------------------------------------------------------------------
     // Implemented methods
     // -------------------------------------------------------------------------
-    
+
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramInstance> get( boolean completed )
+    public Collection<ProgramInstance> get( Integer status )
     {
-        return getCriteria( Restrictions.eq( "completed", completed ) ).list();
+        return getCriteria( Restrictions.eq( "status", status ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
@@ -84,15 +83,15 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramInstance> get( Program program, boolean completed )
+    public Collection<ProgramInstance> get( Program program, Integer status )
     {
-        return getCriteria( Restrictions.eq( "program", program ), Restrictions.eq( "completed", completed ) ).list();
+        return getCriteria( Restrictions.eq( "program", program ), Restrictions.eq( "status", status ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramInstance> get( Collection<Program> programs, boolean completed )
+    public Collection<ProgramInstance> get( Collection<Program> programs, Integer status )
     {
-        return getCriteria( Restrictions.in( "program", programs ), Restrictions.eq( "completed", completed ) ).list();
+        return getCriteria( Restrictions.in( "program", programs ), Restrictions.eq( "status", status ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
@@ -102,9 +101,9 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramInstance> get( Patient patient, boolean completed )
+    public Collection<ProgramInstance> get( Patient patient, Integer status )
     {
-        return getCriteria( Restrictions.eq( "patient", patient ), Restrictions.eq( "completed", completed ) ).list();
+        return getCriteria( Restrictions.eq( "patient", patient ), Restrictions.eq( "status", status ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
@@ -114,10 +113,10 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramInstance> get( Patient patient, Program program, boolean completed )
+    public Collection<ProgramInstance> get( Patient patient, Program program, Integer status )
     {
         return getCriteria( Restrictions.eq( "patient", patient ), Restrictions.eq( "program", program ),
-            Restrictions.eq( "completed", completed ) ).list();
+            Restrictions.eq( "status", status ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
@@ -176,55 +175,68 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    public int count( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean completed )
+    // @SuppressWarnings( "unchecked" )
+    // public Collection<ProgramInstance> getUnenrollment( Program program,
+    // Collection<Integer> orgunitIds,
+    // Date startDate, Date endDate )
+    // {
+    // return getCriteria( Restrictions.eq( "program", program ),
+    // Restrictions.ge( "enrollmentDate", startDate ),
+    // Restrictions.le( "enrollmentDate", endDate ) ).createAlias( "patient",
+    // "patient" )
+    // .createAlias( "programStageInstances", "programStageInstance" )
+    // .createAlias( "patient.organisationUnit", "organisationUnit" )
+    // .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).add(
+    // Restrictions.eq( "completed", true ) )
+    // .add( Restrictions.eq( "programStageInstance.completed", false )
+    // ).list();
+    // }
+    //
+    // public int countUnenrollment( Program program, Collection<Integer>
+    // orgunitIds, Date startDate, Date endDate )
+    // {
+    // Number rs = (Number) getCriteria( Restrictions.eq( "program", program ),
+    // Restrictions.ge( "endDate", startDate ), Restrictions.le( "endDate",
+    // endDate ) )
+    // .createAlias( "patient", "patient" ).createAlias(
+    // "programStageInstances", "programStageInstance" )
+    // .createAlias( "patient.organisationUnit", "organisationUnit" )
+    // .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).add(
+    // Restrictions.eq( "completed", true ) )
+    // .add( Restrictions.eq( "programStageInstance.completed", false ) )
+    // .setProjection( Projections.projectionList().add(
+    // Projections.countDistinct( "id" ) ) ).uniqueResult();
+    //
+    // return rs != null ? rs.intValue() : 0;
+    // }
+
+    public int countByStatus( Integer status, Program program, Collection<Integer> orgunitIds, Date startDate,
+        Date endDate )
     {
-        Criteria criteria = getCriteria( Restrictions.eq( "program", program ) );
-        criteria.createAlias( "patient", "patient" ).createAlias( "patient.organisationUnit", "organisationUnit" )
-            .add( Restrictions.in( "organisationUnit.id", orgunitIds ) )
-            .add( Restrictions.eq( "completed", completed ) );
-        if ( completed )
-        {
-            criteria.add( Restrictions.between( "endDate", startDate, endDate ) );
-        }
-        else
-        {
-            criteria.add( Restrictions.between( "enrollmentDate", startDate, endDate ) );
-        }
+        Number rs = (Number) getCriteria( Restrictions.eq( "program", program ),
+            Restrictions.between( "endDate", startDate, endDate ) ).createAlias( "patient", "patient" )
+            .createAlias( "patient.organisationUnit", "organisationUnit" )
+            .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).add( Restrictions.eq( "status", status ) )
+            .setProjection( Projections.projectionList().add( Projections.countDistinct( "id" ) ) ).uniqueResult();
 
-        Number rs = (Number) criteria.setProjection( Projections.rowCount() ).uniqueResult();
         return rs != null ? rs.intValue() : 0;
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramInstance> getUnenrollment( Program program, Collection<Integer> orgunitIds,
+    public Collection<ProgramInstance> getByStatus( Integer status, Program program, Collection<Integer> orgunitIds,
         Date startDate, Date endDate )
     {
-        return getCriteria( Restrictions.eq( "program", program ), Restrictions.ge( "enrollmentDate", startDate ),
-            Restrictions.le( "enrollmentDate", endDate ) ).createAlias( "patient", "patient" )
-            .createAlias( "programStageInstances", "programStageInstance" )
-            .createAlias( "patient.organisationUnit", "organisationUnit" )
-            .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).add( Restrictions.eq( "completed", true ) )
-            .add( Restrictions.eq( "programStageInstance.completed", false ) ).list();
-    }
-
-    public int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate )
-    {
-        Number rs = (Number) getCriteria( Restrictions.eq( "program", program ),
-            Restrictions.ge( "endDate", startDate ), Restrictions.le( "endDate", endDate ) )
-            .createAlias( "patient", "patient" ).createAlias( "programStageInstances", "programStageInstance" )
-            .createAlias( "patient.organisationUnit", "organisationUnit" )
-            .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).add( Restrictions.eq( "completed", true ) )
-            .add( Restrictions.eq( "programStageInstance.completed", false ) )
-            .setProjection( Projections.projectionList().add( Projections.countDistinct( "id" ) ) ).uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
+        return getCriteria( Restrictions.eq( "program", program ), Restrictions.between( "endDate", startDate, endDate ) )
+            .createAlias( "patient", "patient" ).createAlias( "patient.organisationUnit", "organisationUnit" )
+            .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).add( Restrictions.eq( "status", status ) )
+            .list();
     }
 
     public void removeProgramEnrollment( ProgramInstance programInstance )
     {
         String sql = "delete from programstageinstance where programinstanceid=" + programInstance.getId();
         jdbcTemplate.execute( sql );
-        
+
         sql = "delete from programinstance where programinstanceid=" + programInstance.getId();
         jdbcTemplate.execute( sql );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-04-09 08:28:13 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-04-10 03:13:47 +0000
@@ -396,7 +396,9 @@
             + "     ON org.organisationunitid = p.organisationunitid "
             + " INNER JOIN patientreminder prm  "
             + "     ON prm.programstageid = ps.programstageid "
-            + "WHERE pi.completed=false  "
+            + "WHERE pi.status="
+            + ProgramInstance.STATUS_ACTIVE
+            + " "
             + "     and p.phonenumber is not NULL and p.phonenumber != '' "
             + "     and prm.templatemessage is not NULL and prm.templatemessage != '' "
             + "     and pg.type=1 and prm.daysallowedsendmessage is not null  "
@@ -671,7 +673,7 @@
             sql = getAggregateReportSQL8( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods
                 .iterator().next(), aggregateType, limit, useCompletedEvents, format );
         }
-        
+
         if ( !sql.isEmpty() )
         {
             SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
@@ -1654,9 +1656,9 @@
         {
             for ( Integer root : roots )
             {
-               allOrgunitIds = getOrganisationUnits( root, facilityLB );
-               Collection<Integer> orgunitIds = getServiceOrgunit( allOrgunitIds, period );
-               
+                allOrgunitIds = getOrganisationUnits( root, facilityLB );
+                Collection<Integer> orgunitIds = getServiceOrgunit( allOrgunitIds, period );
+
                 sql += "(SELECT ";
                 sql += "( SELECT ou.name FROM organisationunit ou WHERE ou.organisationunitid=" + root
                     + " ) as orgunit, ";
@@ -2039,16 +2041,16 @@
     }
 
     public int averageNumberCompleted( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
-        Boolean completed )
+        Integer status )
     {
-        Collection<ProgramInstance> programInstances = programInstanceService.getUnenrollment( program, orgunitIds,
-            startDate, endDate );
+        Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstancesByStatus(
+            ProgramInstance.STATUS_COMPLETED, program, orgunitIds, startDate, endDate );
         Criteria criteria = getCriteria();
         criteria.createAlias( "programInstance", "programInstance" );
         criteria.createAlias( "programStage", "programStage" );
         criteria.createAlias( "programInstance.patient", "patient" );
         criteria.add( Restrictions.eq( "programInstance.program", program ) );
-        criteria.add( Restrictions.eq( "programInstance.completed", completed ) );
+        criteria.add( Restrictions.eq( "programInstance.status", status ) );
         criteria.add( Restrictions.in( "organisationUnit.id", orgunitIds ) );
         criteria.add( Restrictions.between( "programInstance.endDate", startDate, endDate ) );
         criteria.add( Restrictions.eq( "completed", true ) );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-08 09:24:43 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-10 03:13:47 +0000
@@ -519,7 +519,7 @@
 		<property name="dataElementService"
 			ref="org.hisp.dhis.dataelement.DataElementService" />
 		<property name="dataEntryFormService"
-			ref="org.hisp.dhis.dataentryform.DataEntryFormService" />		
+			ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
 	</bean>
 
 	<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml	2013-01-23 05:03:18 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml	2013-04-10 03:13:47 +0000
@@ -16,7 +16,7 @@
 
     <property name="endDate" column="enddate" />
 
-    <property name="completed" not-null="true" />
+    <property name="status" />
 
     <many-to-one name="patient" class="org.hisp.dhis.patient.Patient" column="patientid"
       foreign-key="fk_programinstance_patientid" />

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java	2013-03-01 07:34:20 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java	2013-04-10 03:13:47 +0000
@@ -132,7 +132,7 @@
                 }
             }
 
-            programInstance.setCompleted( true );
+            programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
             programInstance.setEndDate( new Date() );
 
             programInstanceService.updateProgramInstance( programInstance );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java	2013-04-08 04:57:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java	2013-04-10 03:13:47 +0000
@@ -39,7 +39,6 @@
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.orgunitdistribution.OrgUnitDistributionService;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2013-04-10 03:13:47 +0000
@@ -139,7 +139,7 @@
         if ( program.getType() == Program.MULTIPLE_EVENTS_WITH_REGISTRATION)
         {
             programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( patient,
-                program, false ) );
+                program, ProgramInstance.STATUS_ACTIVE ) );
         }
         else if ( program.getType() == Program.SINGLE_EVENT_WITH_REGISTRATION )
         {

=== 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-08 04:57:19 +0000
+++ 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
@@ -196,7 +196,7 @@
                     programInstance.setEnrollmentDate( dateValue );
                     programInstance.setDateOfIncident( dateValue );
                     programInstance.setProgram( program );
-                    programInstance.setCompleted( false );
+                    programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
 
                     programInstance.setPatient( patient );
                     patient.getPrograms().add( program );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java	2013-04-04 05:07:53 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java	2013-04-10 03:13:47 +0000
@@ -160,7 +160,7 @@
         programInstance.setEnrollmentDate( currentDate );
         programInstance.setDateOfIncident( currentDate );
         programInstance.setProgram( program );
-        programInstance.setCompleted( true );
+        programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
         programInstance.setPatient( patient );
 
         patient.getPrograms().add( program );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UncompleteDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UncompleteDataEntryAction.java	2012-07-12 10:23:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UncompleteDataEntryAction.java	2013-04-10 03:13:47 +0000
@@ -113,9 +113,10 @@
         // ----------------------------------------------------------------------
 
         ProgramInstance programInstance = programStageInstance.getProgramInstance();
-        if ( programInstance.isCompleted() )
+        
+        if ( ProgramInstance.STATUS_COMPLETED == programInstance.getStatus() )
         {
-            programInstance.setCompleted( false );
+            programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
             programInstance.setEndDate( null );
             programInstanceService.updateProgramInstance( programInstance );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-03-04 15:35:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-04-10 03:13:47 +0000
@@ -173,7 +173,7 @@
         {
             program = programService.getProgram( programId );
             Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient,
-                program, false );
+                program, ProgramInstance.STATUS_ACTIVE );
 
             ProgramInstance programInstance = null;
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java	2013-04-10 03:13:47 +0000
@@ -185,7 +185,7 @@
     {
         this.patientId = patientId;
     }
-
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -230,14 +230,14 @@
         {
             if ( programs.contains( programInstance.getProgram() ) )
             {
-                if ( programInstance.isCompleted() )
+                if ( programInstance.getStatus() == ProgramInstance.STATUS_ACTIVE )
+                {
+                    activeProgramInstances.add( programInstance );
+                }
+                else
                 {
                     completedProgramInstances.add( programInstance );
                 }
-                else
-                {
-                    activeProgramInstances.add( programInstance );
-                }
             }
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java	2013-03-18 08:56:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java	2013-04-10 03:13:47 +0000
@@ -120,7 +120,7 @@
         programs.retainAll( programService.getProgramsByCurrentUser());
         programs.removeAll( patient.getPrograms() );
         
-        Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient, false );
+        Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient, ProgramInstance.STATUS_ACTIVE );
 
         for ( ProgramInstance programInstance : programInstances )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java	2013-01-24 13:37:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java	2013-04-10 03:13:47 +0000
@@ -165,7 +165,7 @@
         }
 
         Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient, program,
-            false );
+            ProgramInstance.STATUS_ACTIVE );
 
         if ( programInstances.iterator().hasNext() )
         {
@@ -179,7 +179,7 @@
             programInstance.setDateOfIncident( format.parseDate( dateOfIncident ) );
             programInstance.setProgram( program );
             programInstance.setPatient( patient );
-            programInstance.setCompleted( false );
+            programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
 
             programInstanceService.addProgramInstance( programInstance );
 
@@ -201,7 +201,7 @@
                     Date dueDate = DateUtils
                         .getDateAfterAddition( dateCreatedEvent, programStage.getMinDaysFromStart() );
 
-                    if ( ! ( program.getIgnoreOverdueEvents() && dueDate.before( currentDate ) ))
+                    if ( !(program.getIgnoreOverdueEvents() && dueDate.before( currentDate )) )
                     {
                         ProgramStageInstance programStageInstance = new ProgramStageInstance();
                         programStageInstance.setProgramInstance( programInstance );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SetProgramInstanceStatusAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SetProgramInstanceStatusAction.java	2013-03-01 09:15:24 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SetProgramInstanceStatusAction.java	2013-04-10 03:13:47 +0000
@@ -28,14 +28,18 @@
 package org.hisp.dhis.caseentry.action.patient;
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -54,6 +58,8 @@
 
     private ProgramInstanceService programInstanceService;
 
+    private ProgramStageInstanceService programStageInstanceService;
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -62,7 +68,7 @@
 
     private Collection<Program> programs = new ArrayList<Program>();
 
-    private boolean completed;
+    private int status;
 
     // -------------------------------------------------------------------------
     // Getters && Setters
@@ -78,6 +84,11 @@
         this.programInstanceService = programInstanceService;
     }
 
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
     public Collection<Program> getPrograms()
     {
         return programs;
@@ -88,9 +99,9 @@
         this.programInstanceId = programInstanceId;
     }
 
-    public void setCompleted( boolean completed )
+    public void setStatus( int status )
     {
-        this.completed = completed;
+        this.status = status;
     }
 
     // -------------------------------------------------------------------------
@@ -105,28 +116,56 @@
         Patient patient = programInstance.getPatient();
 
         Program program = programInstance.getProgram();
-        programInstance.setCompleted( completed );
-        
-        if ( completed )
+        programInstance.setStatus( status );
+
+        if ( status == ProgramInstance.STATUS_COMPLETED )
         {
             programInstance.setEndDate( new Date() );
-            
+
             if ( !program.getOnlyEnrollOnce() )
             {
                 patient.getPrograms().remove( program );
                 patientService.updatePatient( patient );
             }
         }
+        if ( status == ProgramInstance.STATUS_CANCELLED )
+        {
+            Calendar today = Calendar.getInstance();
+            PeriodType.clearTimeOfDay( today );
+            Date currentDate = today.getTime();
+            
+            programInstance.setEndDate( currentDate );
+
+            for ( ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances() )
+            {
+                if ( programStageInstance.getExecutionDate() == null )
+                {
+                    // Set status as skipped for overdue events
+                    if ( programStageInstance.getDueDate().before( currentDate ) )
+                    {
+                        programStageInstance.setStatus( ProgramStageInstance.SKIPPED_STATUS );
+                        programStageInstanceService.updateProgramStageInstance( programStageInstance );
+                    }
+                    // Delete scheduled events
+                    else
+                    {
+                        programStageInstanceService.deleteProgramStageInstance( programStageInstance );
+                    }
+                }
+            }
+            patient.getPrograms().remove( program );
+            patientService.updatePatient( patient );
+        }
         else
         {
             programInstance.setEndDate( null );
-            
+
             patient.getPrograms().add( program );
             patientService.updatePatient( patient );
         }
 
         programInstanceService.updateProgramInstance( programInstance );
-        
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-04-08 04:57:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-04-10 03:13:47 +0000
@@ -656,6 +656,7 @@
 		scope="prototype">
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
+		<property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.caseentry.action.patient.GetProgramAction"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-04-09 05:48:54 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-04-10 03:13:47 +0000
@@ -620,4 +620,6 @@
 home = Home
 show_all_sections = Show all sections
 aggregate_options = Aggregate options
-display_totals = Display totals
\ No newline at end of file
+display_totals = Display totals
+cancelled_programs = Cancelled programs
+quit = Quit
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-04-08 05:43:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-04-10 03:13:47 +0000
@@ -121,7 +121,7 @@
 	var i18n_enter_values_for_longitude_and_latitude_fields = '$encoder.jsEscape( $i18n.getString( "enter_values_for_longitude_and_latitude_fields" ) , "'" )';
 	var i18n_enter_a_valid_number = '$encoder.jsEscape( $i18n.getString( "enter_a_valid_number" ) , "'" )';
 	
-	#if( $programStageInstance.programInstance.program.type=='1' && $programStageInstance.programInstance.completed=="true")
+	#if( $programStageInstance.programInstance.program.type=='1' && $programStageInstance.programInstance.status==1)
 		jQuery("[id=entryFormContainer] :input").prop('disabled', true);
 		jQuery("[id=entryFormContainer] :input").datepicker("destroy");
 		jQuery("[id=executionDate]").prop('disabled', true);

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-04-04 06:01:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-04-10 03:13:47 +0000
@@ -1399,14 +1399,14 @@
 		});
 }
 
-function unenrollmentForm( programInstanceId )
+function unenrollmentForm( programInstanceId, status )
 {	
 	if( confirm(i18n_incomplete_confirm_message) )
 	{
 		$.ajax({
 			type: "POST",
 			url: 'setProgramInstanceStatus.action',
-			data: "programInstanceId=" + programInstanceId + "&completed=true",
+			data: "programInstanceId=" + programInstanceId + "&status=" + status,
 			success: function( json ) 
 			{
 				var type=jQuery("#tr1_" + programInstanceId ).attr('type');
@@ -1797,8 +1797,8 @@
 				field.value="";
 				field.style.backgroundColor = SUCCESS_COLOR;
 				
-				jQuery('#enrollmentDate').width('270');
-				jQuery('#dateOfIncident').width('270');
+				jQuery('#enrollmentDate').width('325');
+				jQuery('#dateOfIncident').width('325');
 				jQuery('#removeProgram').remove();
 			}
 			else {
@@ -1862,8 +1862,8 @@
 			else{
 				commentDivToggle(false);
 			}
-			jQuery('#enrollmentDate').width('270');
-			jQuery('#dateOfIncident').width('270');
+			jQuery('#enrollmentDate').width('325');
+			jQuery('#dateOfIncident').width('325');
 			jQuery('#removeProgram').remove();
 		});
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm	2013-03-15 04:08:40 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm	2013-04-10 03:13:47 +0000
@@ -144,7 +144,7 @@
 			saveCoordinatesEvent($!programStageInstance.id);
 		});
 		
-		#if( $programInstance.completed)
+		#if( $programInstance.status==1)
 			jQuery("[id=tab-2] :input").prop('disabled', true);
 			jQuery("[id=tab-3] :input").prop('disabled', true);
 			jQuery("[id=tab-4] :input").prop('disabled', true);

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm	2013-03-18 07:22:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm	2013-04-10 03:13:47 +0000
@@ -4,21 +4,20 @@
 	<table>
 		<tr>
 			<td class='text-column'>$programInstance.program.dateOfEnrollmentDescription:</td>
-			<td><input name="enrollmentDate" id="enrollmentDate" readonly value="$!format.formatDate( $programInstance.enrollmentDate )" style="width:270px;"></td>
+			<td><input name="enrollmentDate" id="enrollmentDate" readonly value="$!format.formatDate( $programInstance.enrollmentDate )" style="width:325px;"></td>
 		</tr>
 		<tr>
 			<td class='text-column'>$programInstance.program.dateOfIncidentDescription:</td>
-			<td><input name="dateOfIncident" id="dateOfIncident" readonly value="$!format.formatDate( $programInstance.dateOfIncident )" style="width:270px;"></td>
+			<td><input name="dateOfIncident" id="dateOfIncident" readonly value="$!format.formatDate( $programInstance.dateOfIncident )" style="width:325px;"></td>
 		</tr>
 		<tr>
 			<td></td>
 			<td>
 				<input type="button" style='width:80px' value="$i18n.getString( 'update' )" onclick='updateEnrollment($programInstance.patient.id, $programInstance.program.id, $programInstance.id, "$programInstance.program.displayName")'/>
-				<input type="button" class='large-button' id='completeProgram' value="$i18n.getString( 'complete_quit' )" onclick='unenrollmentForm($programInstance.id)' />
+				<input type="button" style='width:80px' id='completeProgram' value="$i18n.getString( 'complete' )" onclick='unenrollmentForm($programInstance.id, 1)' />
+				<input type="button" style='width:80px' id='cancelProgram' value="$i18n.getString( 'quit' )" onclick='unenrollmentForm($programInstance.id, 2)' />
 				<input type="button" style='width:80px' id='incompleteProgram' value="$i18n.getString( 're_enrol' )" onclick='reenrollmentForm($programInstance.id)' />
 				#set($allowRemove = 'true')
-				
-				
 				#foreach( $programStageInstance in $programStageInstances )
 					#if( $!programStageInstance.executionDate 
 						|| $!programStageInstance.outboundSms.size() > 0 
@@ -31,8 +30,8 @@
 				#if($allowRemove == 'true')
 					<input type="button" style='width:80px' id='removeProgram' value="$i18n.getString( 'remove' )" onclick='removeProgramInstance($programInstance.id)' />
 					<script>
-						jQuery('#enrollmentDate').width('355');
-						jQuery('#dateOfIncident').width('355');
+						jQuery('#enrollmentDate').width('410');
+						jQuery('#dateOfIncident').width('410');
 					</script>
 				#end
 			</td>
@@ -125,7 +124,7 @@
 #end
 
 <script>
-	#if( $programInstance.completed=='false')
+	#if( $programInstance.status==0)
 		datePickerInRangeValid( 'dateOfIncident' , 'enrollmentDate' );
 		jQuery("#incompleteProgram").attr('disabled', true);
 	#else

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SaveAnonymousProgramAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SaveAnonymousProgramAction.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SaveAnonymousProgramAction.java	2013-04-10 03:13:47 +0000
@@ -312,7 +312,7 @@
 
         programInstance.setProgram( program );
 
-        programInstance.setCompleted( true );
+        programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
 
         programInstanceService.addProgramInstance( programInstance );
 

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java	2013-04-10 03:13:47 +0000
@@ -305,8 +305,7 @@
 
         List<PatientAttributeValue> patientAttributeValues = new ArrayList<PatientAttributeValue>();
 
-        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
-            StrutsStatics.HTTP_REQUEST );
+        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get( StrutsStatics.HTTP_REQUEST );
         Map<String, String> parameterMap = ContextUtils.getParameterMap( request );
         DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay();
 
@@ -425,7 +424,7 @@
         patientService.updatePatient( patient );
 
         Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient, program,
-            false );
+            ProgramInstance.STATUS_ACTIVE );
 
         ProgramInstance programInstance = null;
 
@@ -441,7 +440,7 @@
             programInstance.setDateOfIncident( sdf.parseDateTime( incidentDate ).toDate() );
             programInstance.setProgram( program );
             programInstance.setPatient( patient );
-            programInstance.setCompleted( false );
+            programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
 
             programInstanceService.addProgramInstance( programInstance );
 
@@ -466,7 +465,7 @@
                         .getDateAfterAddition( dateCreatedEvent, programStage.getMinDaysFromStart() );
 
                     programStageInstance.setDueDate( dueDate );
-                    
+
                     if ( program.isSingleEvent() )
                     {
                         programStageInstance.setExecutionDate( dueDate );

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetPatientProgramListAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetPatientProgramListAction.java	2013-03-20 03:54:42 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetPatientProgramListAction.java	2013-04-10 03:13:47 +0000
@@ -286,7 +286,7 @@
         Collection<Program> programByCurrentUser = programService.getProgramsByCurrentUser();
         for ( ProgramInstance programInstance : programInstanceService.getProgramInstances( patient ) )
         {
-            if ( !programInstance.isCompleted() && programByCurrentUser.contains( programInstance.getProgram() ) )
+            if ( programInstance.getStatus() == ProgramInstance.STATUS_ACTIVE && programByCurrentUser.contains( programInstance.getProgram() ) )
             {
                 programInstances.add( programInstance );
             }
@@ -318,7 +318,7 @@
 
         for ( ProgramInstance each : listOfProgramInstance )
         {
-            if ( each.isCompleted() )
+            if ( each.getStatus() == ProgramInstance.STATUS_COMPLETED )
             {
                 this.listOfCompletedProgram.add( each );
             }
@@ -342,13 +342,13 @@
             }
             else if ( !program.isSingleEvent() )
             {
-                if ( programInstanceService.getProgramInstances( patient, program, false ).size() == 0 )
+                if ( programInstanceService.getProgramInstances( patient, program, ProgramInstance.STATUS_ACTIVE ).size() == 0 )
                 {
                     programs.add( program );
                 }
                 else if ( programInstanceService.getProgramInstances( patient, program ).size() > 0
                     && !program.getOnlyEnrollOnce()
-                    && programInstanceService.getProgramInstances( patient, program, false ).size() == 0 )
+                    && programInstanceService.getProgramInstances( patient, program, ProgramInstance.STATUS_ACTIVE ).size() == 0 )
                 {
                     programs.add( program );
                 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java	2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java	2013-04-10 03:13:47 +0000
@@ -459,7 +459,7 @@
             programStageInstance.setCompleted( true );
             programStageInstanceService.updateProgramStageInstance( programStageInstance );
 
-            programInstance.setCompleted( true );
+            programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
             programInstanceService.updateProgramInstance( programInstance );
         }
         else
@@ -469,7 +469,7 @@
             programInstance.setDateOfIncident( new Date() );
             programInstance.setProgram( program );
             programInstance.setPatient( patient );
-            programInstance.setCompleted( true );
+            programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
             programInstanceService.addProgramInstance( programInstance );
 
             ProgramStageInstance programStageInstance = new ProgramStageInstance();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-04-08 08:33:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-04-10 03:13:47 +0000
@@ -285,7 +285,7 @@
             programInstance.setEnrollmentDate( new Date() );
             programInstance.setDateOfIncident( new Date() );
             programInstance.setProgram( program );
-            programInstance.setCompleted( false );
+            programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
 
             programInstanceService.addProgramInstance( programInstance );
         }