← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15067: Fixed bug - Don't display the attributes which belongs to the program in Add new TEI in Single ev...

 

------------------------------------------------------------
revno: 15067
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-28 22:22:49 +0800
message:
  Fixed bug - Don't display the attributes which belongs to the program in Add new TEI in Single event with registration form.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.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-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java	2014-04-28 14:22:49 +0000
@@ -46,14 +46,17 @@
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeGroup;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeGroupService;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityForm;
 import org.hisp.dhis.trackedentity.TrackedEntityFormService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.trackedentity.comparator.TrackedEntityAttributeGroupSortOrderComparator;
 import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -109,6 +112,9 @@
         this.attributeGroupService = attributeGroupService;
     }
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
     private I18n i18n;
 
     public void setI18n( I18n i18n )
@@ -145,63 +151,138 @@
 
     private List<TrackedEntityAttributeGroup> attributeGroups;
 
-    private Map<Integer, Collection<TrackedEntityAttribute>> attributeGroupsMap = new HashMap<Integer, Collection<TrackedEntityAttribute>>();
-
     private Program program;
 
+    private TrackedEntityForm trackedEntityForm;
+
+    public TrackedEntityForm getTrackedEntityForm()
+    {
+        return trackedEntityForm;
+    }
+
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
+    private Map<Integer, String> trackedEntityAttributeValueMap = new HashMap<Integer, String>();
+
+    public Map<Integer, String> getTrackedEntityAttributeValueMap()
+    {
+        return trackedEntityAttributeValueMap;
+    }
+
+    private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
+
+    public Map<Integer, Boolean> getMandatoryMap()
+    {
+        return mandatoryMap;
+    }
+
+    private Map<String, List<TrackedEntityAttribute>> attributesMap = new HashMap<String, List<TrackedEntityAttribute>>();
+
+    public Map<String, List<TrackedEntityAttribute>> getAttributesMap()
+    {
+        return attributesMap;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
     public String execute()
     {
-        // Get health workers
+        // ---------------------------------------------------------------------
+        // Get registration form
+        // ---------------------------------------------------------------------
+
+        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
+
         organisationUnit = selectionManager.getSelectedOrganisationUnit();
         healthWorkers = organisationUnit.getUsers();
 
-        program = programService.getProgram( programId );
-        TrackedEntityForm trackedEntityForm = trackedEntityFormService.getTrackedEntityForm( program );
-
-        if ( trackedEntityForm != null )
-        {
-            customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
-                .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
-                format );
-        }
+        if ( programId == null || programId.isEmpty() )
+        {
+            trackedEntityForm = trackedEntityFormService.getCommonTrackedEntityForm();
+
+            if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
+            {
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
+                    format );
+            }
+        }
+        else
+        {
+            program = programService.getProgram( programId );
+            trackedEntityForm = trackedEntityFormService.getTrackedEntityForm( program );
+
+            if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
+            {
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
+                    format );
+            }
+        }
+
+        List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
 
         if ( customRegistrationForm == null )
         {
-            Collection<TrackedEntityAttribute> attributesInProgram = new HashSet<TrackedEntityAttribute>();
-            Collection<Program> programs = programService.getAllPrograms();
-            programs.remove( program );
-            for ( Program p : programs )
-            {
-                for ( ProgramTrackedEntityAttribute programAttribute : p.getAttributes() )
-                {
-                    attributesInProgram.add( programAttribute.getAttribute() );
-                }
-            }
-
             attributeGroups = new ArrayList<TrackedEntityAttributeGroup>(
                 attributeGroupService.getAllTrackedEntityAttributeGroups() );
             Collections.sort( attributeGroups, new TrackedEntityAttributeGroupSortOrderComparator() );
-            for ( TrackedEntityAttributeGroup attributeGroup : attributeGroups )
-            {
-                List<TrackedEntityAttribute> attributes = attributeGroupService
-                    .getTrackedEntityAttributes( attributeGroup );
-                attributes.removeAll( attributesInProgram );
-
-                if ( attributes.size() > 0 )
-                {
-                    attributeGroupsMap.put( attributeGroup.getId(), attributes );
-                }
-            }
-
-            noGroupAttributes = attributeService.getTrackedEntityAttributesWithoutGroup();
-            noGroupAttributes.removeAll( attributesInProgram );
+
+            if ( program == null )
+            {
+                attributes = new ArrayList<TrackedEntityAttribute>(
+                    attributeService.getTrackedEntityAttributesDisplayInList( true ) );
+                Collection<Program> programs = programService.getAllPrograms();
+
+                for ( Program p : programs )
+                {
+                    attributes.removeAll( p.getAttributes() );
+                }
+
+                for ( TrackedEntityAttribute attribute : attributes )
+                {
+                    mandatoryMap.put( attribute.getId(), false );
+                }
+            }
+            else
+            {
+                attributes = program.getTrackedEntityAttributes();
+                for ( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() )
+                {
+                    mandatoryMap.put( programAttribute.getAttribute().getId(), programAttribute.isMandatory() );
+                }
+            }
+
+            for ( TrackedEntityAttribute attribute : attributes )
+            {
+                TrackedEntityAttributeGroup attributeGroup = attribute.getAttributeGroup();
+                String groupName = (attributeGroup == null) ? "" : attributeGroup.getDisplayName();
+                if ( attributesMap.containsKey( groupName ) )
+                {
+                    List<TrackedEntityAttribute> attrs = attributesMap.get( groupName );
+                    attrs.add( attribute );
+                }
+                else
+                {
+                    List<TrackedEntityAttribute> attrs = new ArrayList<TrackedEntityAttribute>();
+                    attrs.add( attribute );
+                    attributesMap.put( groupName, attrs );
+                }
+            }
+
         }
 
+        // ---------------------------------------------------------------------
         // Get data entry form
+        // ---------------------------------------------------------------------
+
         programStage = program.getProgramStages().iterator().next();
         if ( programStage.getDataEntryForm() != null )
         {
@@ -220,7 +301,7 @@
     // -------------------------------------------------------------------------
     // Getter/Setter
     // -------------------------------------------------------------------------
-    
+
     public Program getProgram()
     {
         return program;
@@ -271,8 +352,4 @@
         return attributeGroups;
     }
 
-    public Map<Integer, Collection<TrackedEntityAttribute>> getAttributeGroupsMap()
-    {
-        return attributeGroupsMap;
-    }
 }