← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3655: [DHISMobile] Support sort order of dataelement for Mobile Patient Tracking

 

------------------------------------------------------------
revno: 3655
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Thu 2011-05-19 10:18:49 +0700
message:
  [DHISMobile] Support sort order of dataelement for Mobile Patient Tracking
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java	2011-05-19 03:18:49 +0000
@@ -0,0 +1,31 @@
+package org.hisp.dhis.program.comparator;
+
+import java.util.Comparator;
+
+import org.hisp.dhis.program.ProgramStageDataElement;
+
+public class ProgramStageDataElementSortOrderComparator
+    implements Comparator<ProgramStageDataElement>
+{
+
+    @Override
+    public int compare( ProgramStageDataElement programStageDataElement0,
+        ProgramStageDataElement programStageDataElement1 )
+    {
+        if ( programStageDataElement0.getDataElement().getSortOrder() == null
+            || programStageDataElement0.getDataElement().getSortOrder() == 0 )
+        {
+            return programStageDataElement0.getDataElement().getName()
+                .compareTo( programStageDataElement1.getDataElement().getName() );
+        }
+        if ( programStageDataElement1.getDataElement().getSortOrder() == null
+            || programStageDataElement1.getDataElement().getSortOrder() == 0 )
+        {
+            return programStageDataElement0.getDataElement().getName()
+                .compareTo( programStageDataElement1.getDataElement().getName() );
+        }
+        return programStageDataElement0.getDataElement().getSortOrder()
+            - programStageDataElement1.getDataElement().getSortOrder();
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java	2011-01-12 09:13:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java	2011-05-19 03:18:49 +0000
@@ -30,10 +30,13 @@
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.comparator.ProgramStageDataElementSortOrderComparator;
 import org.hisp.dhis.web.api.model.DataElement;
 import org.hisp.dhis.web.api.model.Model;
 import org.hisp.dhis.web.api.model.ModelList;
@@ -126,12 +129,19 @@
             programStage = i18n( i18nService, locale, programStage );
 
             ProgramStage prStg = new ProgramStage();
+
             prStg.setId( programStage.getId() );
+
             prStg.setName( programStage.getName() );
+
             List<DataElement> des = new ArrayList<DataElement>();
 
-            for ( org.hisp.dhis.program.ProgramStageDataElement programStagedataElement : programStage
-                .getProgramStageDataElements() )
+            List<ProgramStageDataElement> programStageDataElements = new ArrayList<ProgramStageDataElement>(
+                programStage.getProgramStageDataElements() );
+
+            Collections.sort( programStageDataElements, new ProgramStageDataElementSortOrderComparator() );
+
+            for ( ProgramStageDataElement programStagedataElement : programStageDataElements )
             {
                 programStagedataElement = i18n( i18nService, locale, programStagedataElement );
 


Follow ups