dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24011
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11716: wip, assignedPrograms, added meta-data properties, and ou + children (which have programs). Only ...
------------------------------------------------------------
revno: 11716
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-08-20 15:23:29 +0200
message:
wip, assignedPrograms, added meta-data properties, and ou + children (which have programs). Only single event no registration is supported.
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java
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/webdomain/form/Form.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/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2013-08-20 11:01:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2013-08-20 13:23:29 +0000
@@ -49,7 +49,6 @@
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramService;
@@ -69,9 +68,9 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -284,52 +283,48 @@
throw new NotAuthenticatedException();
}
- Forms forms = new Forms();
-
- List<Program> programsByCurrentUser = new ArrayList<Program>( programService.getProgramsByCurrentUser() );
+ Set<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>();
Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
- Map<String, Set<Program>> mappedPrograms = new HashMap<String, Set<Program>>();
-
- for ( Program program : programsByCurrentUser )
- {
- for ( OrganisationUnit organisationUnit : program.getOrganisationUnits() )
+ Set<Program> programs = new HashSet<Program>();
+ Map<String, Collection<Program>> programAssociations = new HashMap<String, Collection<Program>>();
+
+ if ( currentUser.getOrganisationUnits().isEmpty() && currentUser.getUserCredentials().getAllAuthorities().contains( "ALL" ) )
+ {
+ userOrganisationUnits.addAll( organisationUnitService.getRootOrganisationUnits() );
+ }
+ else
+ {
+ userOrganisationUnits.addAll( currentUser.getOrganisationUnits() );
+ }
+
+ for ( OrganisationUnit organisationUnit : userOrganisationUnits )
+ {
+ Collection<Program> ouPrograms = programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION, organisationUnit );
+
+ if ( !ouPrograms.isEmpty() )
{
organisationUnits.add( organisationUnit );
-
- if ( mappedPrograms.get( organisationUnit.getUid() ) == null )
- {
- Set<Program> programs = new HashSet<Program>();
- programs.add( program );
- mappedPrograms.put( organisationUnit.getUid(), programs );
-
- }
- else
- {
- mappedPrograms.get( organisationUnit.getUid() ).add( program );
- }
+ programs.addAll( ouPrograms );
+ programAssociations.put( organisationUnit.getUid(), ouPrograms );
}
- for ( OrganisationUnitGroup organisationUnitGroup : program.getOrganisationUnitGroups() )
+ for ( OrganisationUnit child : organisationUnit.getChildren() )
{
- for ( OrganisationUnit organisationUnit : organisationUnitGroup.getMembers() )
+ ouPrograms = programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION, child );
+
+ if ( !ouPrograms.isEmpty() )
{
- organisationUnits.add( organisationUnit );
-
- if ( mappedPrograms.get( organisationUnit.getUid() ) == null )
- {
- Set<Program> programs = new HashSet<Program>();
- programs.add( program );
- mappedPrograms.put( organisationUnit.getUid(), programs );
-
- }
- else
- {
- mappedPrograms.get( organisationUnit.getUid() ).add( program );
- }
+ organisationUnits.add( child );
+ programs.addAll( ouPrograms );
+ programAssociations.put( organisationUnit.getUid(), ouPrograms );
}
}
}
+ i18nService.internationalise( programs );
+
+ Forms forms = new Forms();
+
for ( OrganisationUnit organisationUnit : organisationUnits )
{
FormOrganisationUnit formOrganisationUnit = new FormOrganisationUnit();
@@ -337,13 +332,11 @@
formOrganisationUnit.setLabel( organisationUnit.getDisplayName() );
formOrganisationUnit.setLevel( organisationUnit.getOrganisationUnitLevel() );
- Set<Program> programs = mappedPrograms.get( organisationUnit.getUid() );
-
- for ( Program program : programs )
+ for ( Program program : programAssociations.get( organisationUnit.getUid() ) )
{
FormProgram formProgram = new FormProgram();
+ formProgram.setId( program.getUid() );
formProgram.setLabel( program.getDisplayName() );
- formProgram.setId( program.getUid() );
formOrganisationUnit.getPrograms().add( formProgram );
}
@@ -351,6 +344,11 @@
forms.getOrganisationUnits().put( formOrganisationUnit.getId(), formOrganisationUnit );
}
+ for ( Program program : programs )
+ {
+ forms.getForms().put( program.getUid(), FormUtils.fromProgram( program ) );
+ }
+
JacksonUtils.toJson( response.getOutputStream(), forms );
}
=== 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-07-01 10:38:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java 2013-08-20 13:23:29 +0000
@@ -37,6 +37,10 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.Section;
import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
@@ -53,6 +57,10 @@
{
Form form = new Form();
form.setLabel( dataSet.getDisplayName() );
+
+ form.getOptions().put( "periodType", dataSet.getPeriodType().getName() );
+ form.getOptions().put( "allowFuturePeriods", dataSet.isAllowFuturePeriods() );
+
form.setPeriodType( dataSet.getPeriodType().getName() );
form.setAllowFuturePeriods( dataSet.isAllowFuturePeriods() );
@@ -88,6 +96,39 @@
}
+ public static Form fromProgram( Program program )
+ {
+ Assert.notNull( program );
+ Assert.isTrue( program.getType() == Program.SINGLE_EVENT_WITHOUT_REGISTRATION );
+
+ Form form = new Form();
+ form.setLabel( program.getDisplayName() );
+
+ if ( !StringUtils.isEmpty( program.getDescription() ) )
+ {
+ form.getOptions().put( "description", program.getDescription() );
+ }
+
+ if ( !StringUtils.isEmpty( program.getDateOfEnrollmentDescription() ) )
+ {
+ form.getOptions().put( "dateOfEnrollmentDescription", program.getDateOfEnrollmentDescription() );
+ }
+
+ if ( !StringUtils.isEmpty( program.getDateOfIncidentDescription() ) )
+ {
+ form.getOptions().put( "dateOfIncidentDescription", program.getDateOfIncidentDescription() );
+ }
+
+ form.getOptions().put( "type", "SINGLE_EVENT_WITHOUT_REGISTRATION" );
+
+ ProgramStage programStage = program.getProgramStageByStage( 1 );
+ Assert.notNull( programStage );
+
+ form.getOptions().put( "captureCoordinates", programStage.getCaptureCoordinates() );
+
+ return form;
+ }
+
private static List<Field> inputsFromDataElements( List<DataElement> dataElements )
{
return inputsFromDataElements( dataElements, new ArrayList<DataElementOperand>() );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java 2013-02-03 09:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java 2013-08-20 13:23:29 +0000
@@ -31,21 +31,27 @@
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@XmlRootElement( name = "form" )
+@XmlRootElement(name = "form")
public class Form
{
private String label;
+ @Deprecated
private String periodType;
+ @Deprecated
+ private Boolean allowFuturePeriods;
+
private List<Group> groups = new ArrayList<Group>();
- private boolean allowFuturePeriods;
+ private Map<String, Object> options = new HashMap<String, Object>();
public Form()
{
@@ -85,16 +91,27 @@
}
@JsonProperty
- public boolean isAllowFuturePeriods()
+ public Boolean isAllowFuturePeriods()
{
return allowFuturePeriods;
}
- public void setAllowFuturePeriods( boolean allowFuturePeriods )
+ public void setAllowFuturePeriods( Boolean allowFuturePeriods )
{
this.allowFuturePeriods = allowFuturePeriods;
}
+ @JsonProperty
+ public Map<String, Object> getOptions()
+ {
+ return options;
+ }
+
+ public void setOptions( Map<String, Object> options )
+ {
+ this.options = options;
+ }
+
@Override
public String toString()
{