← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11109: Only show attributes of programs that user can access to through the user role.

 

------------------------------------------------------------
revno: 11109
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-30 14:18:04 +0700
message:
  Only show attributes of programs that user can access to through the user role.
modified:
  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/resources/META-INF/dhis/beans.xml


--
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-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-05-30 02:20:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2013-05-30 07:18:04 +0000
@@ -29,6 +29,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 
 import org.hisp.dhis.common.Grid;
@@ -84,6 +85,13 @@
         this.patientDataValueService = patientDataValueService;
     }
 
+    private ProgramService programService;
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -208,8 +216,6 @@
         attrGrid.addHeader( new GridHeader( i18n.getString( "value" ), false, true ) );
         attrGrid.addHeader( new GridHeader( "", true, false ) );
 
-        Collection<PatientAttribute> patientAttributes = patient.getAttributes();
-
         // ---------------------------------------------------------------------
         // Add fixed attribues
         // ---------------------------------------------------------------------
@@ -240,24 +246,35 @@
         // Add dynamic attribues
         // ---------------------------------------------------------------------
 
-        for ( PatientAttribute patientAttribute : patientAttributes )
+        Collection<Program> programs = programService
+            .getProgramsByCurrentUser( Program.MULTIPLE_EVENTS_WITH_REGISTRATION );
+        programs.addAll( programService.getProgramsByCurrentUser( Program.SINGLE_EVENT_WITH_REGISTRATION ) );
+
+        Collection<PatientAttributeValue> attributeValues = patientAttributeValueService
+            .getPatientAttributeValues( patient );
+        Iterator<PatientAttributeValue> iterAttribute = attributeValues.iterator();
+
+        for ( Program program : programs )
+        {
+            Collection<PatientAttribute> atttributes = program.getPatientAttributes();
+            while ( iterAttribute.hasNext() )
+            {
+                PatientAttributeValue attributeValue = iterAttribute.next();
+                if ( !atttributes.contains( attributeValue.getPatientAttribute() ) )
+                {
+                    iterAttribute.remove();
+                }
+            }
+        }
+
+        for ( PatientAttributeValue attributeValue : attributeValues )
         {
             attrGrid.addRow();
-            attrGrid.addValue( patientAttribute.getDisplayName() );
-            PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( patient,
-                patientAttribute );
-            String value = "";
-            if ( attributeValue == null )
-            {
-                value = PatientAttributeValue.UNKNOWN;
-            }
-            else if ( attributeValue.getPatientAttribute().getValueType().equals( PatientAttribute.TYPE_BOOL ) )
-            {
-                value = i18n.getString( attributeValue.getValue() );
-            }
-            else
-            {
-                value = attributeValue.getValue();
+            attrGrid.addValue( attributeValue.getPatientAttribute().getDisplayName() );
+            String value = attributeValue.getValue();
+            if ( attributeValue.getPatientAttribute().getValueType().equals( PatientAttribute.TYPE_BOOL ) )
+            {
+                value = i18n.getString( value );
             }
 
             attrGrid.addValue( value );
@@ -267,21 +284,36 @@
         // Add identifier
         // ---------------------------------------------------------------------
 
-        for ( PatientIdentifier identifier : patient.getIdentifiers() )
+        Collection<PatientIdentifier> identifiers = patient.getIdentifiers();
+        Iterator<PatientIdentifier> iterIdentifier = identifiers.iterator();
+
+        for ( Program program : programs )
+        {
+            Collection<PatientIdentifierType> identifierTypes = program.getPatientIdentifierTypes();
+            while ( iterIdentifier.hasNext() )
+            {
+                PatientIdentifier identifier = iterIdentifier.next();
+                if ( !identifierTypes.contains( identifier.getIdentifierType() ) )
+                {
+                    iterIdentifier.remove();
+                }
+            }
+        }
+
+        for ( PatientIdentifier identifier : identifiers )
         {
             attrGrid.addRow();
-
             PatientIdentifierType idType = identifier.getIdentifierType();
             if ( idType != null )
             {
                 attrGrid.addValue( idType.getName() );
-                attrGrid.addValue( identifier.getIdentifier() );
             }
             else
             {
                 attrGrid.addValue( i18n.getString( "system_identifier" ) );
-                attrGrid.addValue( identifier.getIdentifier() );
+
             }
+            attrGrid.addValue( identifier.getIdentifier() );
         }
 
         grids.add( attrGrid );
@@ -296,15 +328,18 @@
         {
             for ( ProgramInstance programInstance : programInstances )
             {
-                Grid gridProgram = getProgramInstanceReport( programInstance, i18n, format );
-
-                // ---------------------------------------------------------------------
-                // Grids for program-stage-instance
-                // ---------------------------------------------------------------------
-
-                getProgramStageInstancesReport( gridProgram, programInstance, format, i18n );
-
-                grids.add( gridProgram );
+                if ( programs.contains( programInstance.getProgram() ) )
+                {
+                    Grid gridProgram = getProgramInstanceReport( programInstance, i18n, format );
+
+                    // ---------------------------------------------------------------------
+                    // Grids for program-stage-instance
+                    // ---------------------------------------------------------------------
+
+                    getProgramStageInstancesReport( gridProgram, programInstance, format, i18n );
+
+                    grids.add( gridProgram );
+                }
             }
         }
 
@@ -377,14 +412,14 @@
         }
 
         PatientComment patientComment = programInstance.getPatientComment();
-        if( patientComment != null )
+        if ( patientComment != null )
         {
             grid.addRow();
             grid.addValue( i18n.getString( "comment" ) + " " + i18n.getString( "on" ) + " "
                 + format.formatDateTime( patientComment.getCreatedDate() ) );
             grid.addValue( patientComment.getCommentText() );
         }
-            
+
         // Get sms of the program-instance
 
         List<OutboundSms> messasges = programInstance.getOutboundSms();

=== 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-05-02 08:41:20 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-05-30 07:18:04 +0000
@@ -216,6 +216,8 @@
 			ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
 		<property name="patientDataValueService"
 			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
+		<property name="programService"
+			ref="org.hisp.dhis.program.ProgramService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramStageService" class="org.hisp.dhis.program.DefaultProgramStageService">