← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2148: Set to List to get the selected PatientAttribute List in order

 

------------------------------------------------------------
revno: 2148
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: dhis2
timestamp: Tue 2010-11-23 14:16:02 +0700
message:
  Set to List to get the selected PatientAttribute List in order
  Send only PatientAttributes which is checked to be sent to client.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientMobileSetting.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientMobileSetting.hbm.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/ShowMobileSettingFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/UpdateMobileSettingAction.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-api/src/main/java/org/hisp/dhis/patient/PatientMobileSetting.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientMobileSetting.java	2010-11-22 10:23:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientMobileSetting.java	2010-11-23 07:16:02 +0000
@@ -27,24 +27,25 @@
 
 package org.hisp.dhis.patient;
 
+import java.util.List;
 import java.util.Set;
 
 import org.hisp.dhis.common.IdentifiableObject;
 
 public class PatientMobileSetting extends IdentifiableObject
 {
-    private Set<PatientAttribute> patientAttributes;
+    private List<PatientAttribute> patientAttributes;
 
     public PatientMobileSetting()
     {
     }
 
-    public Set<PatientAttribute> getPatientAttributes()
+    public List<PatientAttribute> getPatientAttributes()
     {
         return patientAttributes;
     }
 
-    public void setPatientAttributes( Set<PatientAttribute> patientAttributes )
+    public void setPatientAttributes( List<PatientAttribute> patientAttributes )
     {
         this.patientAttributes = patientAttributes;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientMobileSetting.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientMobileSetting.hbm.xml	2010-11-22 10:23:44 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientMobileSetting.hbm.xml	2010-11-23 07:16:02 +0000
@@ -9,9 +9,10 @@
 			<generator class="native" />
 		</id>
 		
-		<set name="patientAttributes">
+		<list name="patientAttributes">
 			<key column="patientmobilesettingid" />
+			<list-index column="sort_order_patientattributename" base="0"/>
 			<one-to-many class="org.hisp.dhis.patient.PatientAttribute" />
-		</set>
+		</list>
 	</class>
 </hibernate-mapping>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java	2010-11-20 08:35:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java	2010-11-23 07:16:02 +0000
@@ -15,6 +15,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patient.PatientMobileSetting;
+import org.hisp.dhis.patient.PatientMobileSettingService;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
@@ -55,6 +57,8 @@
     private org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService;
 
     private CurrentUserService currentUserService;
+    
+    private PatientMobileSettingService patientMobileSettingService;
 
     // -------------------------------------------------------------------------
     // MobileDataSetService
@@ -173,37 +177,49 @@
         patientAttribute = null;
 
         // Set all attributes
-        org.hisp.dhis.patient.PatientAttribute houseName = patientAttService.getPatientAttributeByName( "House Name" );
-        org.hisp.dhis.patient.PatientAttribute houseNumber = patientAttService
-            .getPatientAttributeByName( "House Number" );
-        org.hisp.dhis.patient.PatientAttribute wardNumber = patientAttService.getPatientAttributeByName( "Ward Number" );
-        org.hisp.dhis.patient.PatientAttribute nearestContact = patientAttService
-            .getPatientAttributeByName( "Nearest Contact Person Name" );
-
-        PatientAttributeValue houseNameValue = patientAttValueService.getPatientAttributeValue( patient, houseName );
-        if ( houseNameValue != null )
-        {
-            patientAtts.add( new PatientAttribute( "House Name", houseNameValue.getValue() ) );
-        }
-
-        PatientAttributeValue houseNumberValue = patientAttValueService.getPatientAttributeValue( patient, houseNumber );
-        if ( houseNumberValue != null )
-        {
-            patientAtts.add( new PatientAttribute( "House Number", houseNumberValue.getValue() ) );
-        }
-
-        PatientAttributeValue wardNumberValue = patientAttValueService.getPatientAttributeValue( patient, wardNumber );
-        if ( wardNumberValue != null )
-        {
-            patientAtts.add( new PatientAttribute( "Ward Number", wardNumberValue.getValue() ) );
-        }
-
-        PatientAttributeValue nearestContactValue = patientAttValueService.getPatientAttributeValue( patient,
-            nearestContact );
-        if ( nearestContactValue != null )
-        {
-            patientAtts.add( new PatientAttribute( "Nearest Contact", nearestContactValue.getValue() ) );
-        }
+        PatientMobileSetting setting = patientMobileSettingService.getCurrentSetting()==null?null:patientMobileSettingService.getCurrentSetting().iterator().next();
+        List<org.hisp.dhis.patient.PatientAttribute> atts;
+        if(setting != null){
+            atts = setting.getPatientAttributes();
+            for(org.hisp.dhis.patient.PatientAttribute each : atts){
+                PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, each );
+                if ( value != null )
+                {
+                    patientAtts.add( new PatientAttribute( each.getName(), value.getValue() ) );
+                }
+            }
+        }
+//        org.hisp.dhis.patient.PatientAttribute houseName = patientAttService.getPatientAttributeByName( "House Name" );
+//        org.hisp.dhis.patient.PatientAttribute houseNumber = patientAttService
+//            .getPatientAttributeByName( "House Number" );
+//        org.hisp.dhis.patient.PatientAttribute wardNumber = patientAttService.getPatientAttributeByName( "Ward Number" );
+//        org.hisp.dhis.patient.PatientAttribute nearestContact = patientAttService
+//            .getPatientAttributeByName( "Nearest Contact Person Name" );
+
+//        PatientAttributeValue houseNameValue = patientAttValueService.getPatientAttributeValue( patient, houseName );
+//        if ( houseNameValue != null )
+//        {
+//            patientAtts.add( new PatientAttribute( "House Name", houseNameValue.getValue() ) );
+//        }
+//
+//        PatientAttributeValue houseNumberValue = patientAttValueService.getPatientAttributeValue( patient, houseNumber );
+//        if ( houseNumberValue != null )
+//        {
+//            patientAtts.add( new PatientAttribute( "House Number", houseNumberValue.getValue() ) );
+//        }
+//
+//        PatientAttributeValue wardNumberValue = patientAttValueService.getPatientAttributeValue( patient, wardNumber );
+//        if ( wardNumberValue != null )
+//        {
+//            patientAtts.add( new PatientAttribute( "Ward Number", wardNumberValue.getValue() ) );
+//        }
+//
+//        PatientAttributeValue nearestContactValue = patientAttValueService.getPatientAttributeValue( patient,
+//            nearestContact );
+//        if ( nearestContactValue != null )
+//        {
+//            patientAtts.add( new PatientAttribute( "Nearest Contact", nearestContactValue.getValue() ) );
+//        }
 
         beneficiary.setPatientAttValues( patientAtts );
 
@@ -386,4 +402,12 @@
         this.currentUserService = currentUserService;
     }
 
+    @Required
+    public void setPatientMobileSettingService( PatientMobileSettingService patientMobileSettingService )
+    {
+        this.patientMobileSettingService = patientMobileSettingService;
+    }
+    
+    
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml	2010-11-18 11:32:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml	2010-11-23 07:16:02 +0000
@@ -36,6 +36,7 @@
     <property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
     <property name="dataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
+    <property name="patientMobileSettingService" ref="org.hisp.dhis.patient.PatientMobileSettingService" />
   </bean>
 
   <bean id="org.hisp.dhis.web.api.service.IProgramService" class="org.hisp.dhis.web.api.service.DefaultProgramService">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/ShowMobileSettingFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/ShowMobileSettingFormAction.java	2010-11-22 10:23:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/ShowMobileSettingFormAction.java	2010-11-23 07:16:02 +0000
@@ -1,8 +1,10 @@
 package org.hisp.dhis.patient.action.mobilesetting;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import org.hisp.dhis.patient.PatientAttribute;
@@ -46,14 +48,14 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private Set<PatientAttribute> patientAtts;
+    private List<PatientAttribute> patientAtts;
 
-    public Set<PatientAttribute> getPatientAtts()
+    public List<PatientAttribute> getPatientAtts()
     {
         return patientAtts;
     }
 
-    public void setPatientAtts( Set<PatientAttribute> patientAtts )
+    public void setPatientAtts( List<PatientAttribute> patientAtts )
     {
         this.patientAtts = patientAtts;
     }
@@ -99,7 +101,7 @@
             else
             {
                 System.out.println( "Setting is null" );
-                patientAtts = new HashSet<PatientAttribute>();
+                patientAtts = new ArrayList<PatientAttribute>();
             }
         }
 //        System.out.println( "List " + patientAtts + " has size: " + patientAtts.size() );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/UpdateMobileSettingAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/UpdateMobileSettingAction.java	2010-11-22 10:23:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/mobilesetting/UpdateMobileSettingAction.java	2010-11-23 07:16:02 +0000
@@ -1,8 +1,9 @@
 package org.hisp.dhis.patient.action.mobilesetting;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Set;
+import java.util.List;
 
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeService;
@@ -58,13 +59,13 @@
             PatientMobileSetting setting;
             if(patientMobileSettingService.getCurrentSetting().size()>0){
                 setting = patientMobileSettingService.getCurrentSetting().iterator().next();
-                Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
+                List<PatientAttribute> attributes = new ArrayList<PatientAttribute>();
                 setting.setPatientAttributes( attributes );
                 fillValues( attributes );
                 patientMobileSettingService.updatePatientMobileSetting( setting );
             }else{
                 setting = new PatientMobileSetting();
-                Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
+                List<PatientAttribute> attributes = new ArrayList<PatientAttribute>();
                 setting.setPatientAttributes( attributes );
                 fillValues( attributes );
                 patientMobileSettingService.savePatientMobileSetting( setting );
@@ -73,13 +74,13 @@
             PatientMobileSetting setting;
             if(patientMobileSettingService.getCurrentSetting().size()>0){
                 setting = patientMobileSettingService.getCurrentSetting().iterator().next();
-                Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
+                List<PatientAttribute> attributes = new ArrayList<PatientAttribute>();
                 setting.setPatientAttributes( attributes );
                 fillValues( attributes );
                 patientMobileSettingService.updatePatientMobileSetting( setting );
             }else{
                 setting = new PatientMobileSetting();
-                Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
+                List<PatientAttribute> attributes = new ArrayList<PatientAttribute>();
                 setting.setPatientAttributes( attributes );
                 fillValues( attributes );
                 patientMobileSettingService.savePatientMobileSetting( setting );
@@ -88,7 +89,7 @@
         return SUCCESS;
     }
     
-    private void fillValues(Set<PatientAttribute> attributes){
+    private void fillValues(List<PatientAttribute> attributes){
         for(String id : selectedList){
             attributes.add( patientAttributeService.getPatientAttribute( Integer.parseInt( id )) );
         }