← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11724: finished /api/currentUser/assignedPrograms, now includes form description of single event no regi...

 

------------------------------------------------------------
revno: 11724
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-08-21 09:28:04 +0200
message:
  finished /api/currentUser/assignedPrograms, now includes form description of single event no registration programs
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java	2013-08-20 13:23:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java	2013-08-21 07:28:04 +0000
@@ -39,6 +39,8 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageSection;
 import org.springframework.util.Assert;
 import org.springframework.util.StringUtils;
 
@@ -126,9 +128,50 @@
 
         form.getOptions().put( "captureCoordinates", programStage.getCaptureCoordinates() );
 
+        if ( programStage.getProgramStageSections().size() > 0 )
+        {
+            for ( ProgramStageSection section : programStage.getProgramStageSections() )
+            {
+                List<Field> fields = inputsFromProgramStageDataElements( section.getProgramStageDataElements() );
+
+                if ( !fields.isEmpty() )
+                {
+                    Group s = new Group();
+                    s.setLabel( section.getDisplayName() );
+                    s.setFields( fields );
+                    form.getGroups().add( s );
+                }
+            }
+        }
+        else
+        {
+            List<Field> fields = inputsFromProgramStageDataElements(
+                new ArrayList<ProgramStageDataElement>( programStage.getProgramStageDataElements() ) );
+
+            if ( !fields.isEmpty() )
+            {
+                Group s = new Group();
+                s.setLabel( "default" );
+                s.setFields( fields );
+                form.getGroups().add( s );
+            }
+        }
+
         return form;
     }
 
+    private static List<Field> inputsFromProgramStageDataElements( List<ProgramStageDataElement> programStageDataElements )
+    {
+        List<DataElement> dataElements = new ArrayList<DataElement>();
+
+        for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
+        {
+            dataElements.add( programStageDataElement.getDataElement() );
+        }
+
+        return inputsFromDataElements( dataElements, new ArrayList<DataElementOperand>() );
+    }
+
     private static List<Field> inputsFromDataElements( List<DataElement> dataElements )
     {
         return inputsFromDataElements( dataElements, new ArrayList<DataElementOperand>() );