← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13620: Fixed bug in Add/Update program form.

 

------------------------------------------------------------
revno: 13620
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-01-07 23:28:34 +0700
message:
  Fixed bug in Add/Update program form.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientAttribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientIdentifierType.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm


--
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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-01-07 15:23:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-01-07 16:28:34 +0000
@@ -28,12 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.view.DetailedView;
@@ -49,11 +48,12 @@
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.validation.ValidationCriteria;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
 /**
  * @author Abyot Asalefew
@@ -106,9 +106,9 @@
 
     private Boolean ignoreOverdueEvents = false;
 
-    private List<ProgramPatientIdentifierType> programPatientIdentifierTypes = new ArrayList<ProgramPatientIdentifierType>();
+    private Set<ProgramPatientIdentifierType> programPatientIdentifierTypes = new HashSet<ProgramPatientIdentifierType>();
 
-    private List<ProgramPatientAttribute> programPatientAttributes = new ArrayList<ProgramPatientAttribute>();
+    private Set<ProgramPatientAttribute> programPatientAttributes = new HashSet<ProgramPatientAttribute>();
 
     private Set<UserAuthorityGroup> userRoles = new HashSet<UserAuthorityGroup>();
 
@@ -371,12 +371,12 @@
     @JsonView( { DetailedView.class, ExportView.class, WithoutOrganisationUnitsView.class } )
     @JacksonXmlElementWrapper( localName = "programPersonIdentifierTypes", namespace = DxfNamespaces.DXF_2_0 )
     @JacksonXmlProperty( localName = "programPersonIdentifierType", namespace = DxfNamespaces.DXF_2_0 )
-    public List<ProgramPatientIdentifierType> getProgramPatientIdentifierTypes()
+    public Set<ProgramPatientIdentifierType> getProgramPatientIdentifierTypes()
     {
         return programPatientIdentifierTypes;
     }
 
-    public void setProgramPatientIdentifierTypes( List<ProgramPatientIdentifierType> programPatientIdentifierTypes )
+    public void setProgramPatientIdentifierTypes( Set<ProgramPatientIdentifierType> programPatientIdentifierTypes )
     {
         this.programPatientIdentifierTypes = programPatientIdentifierTypes;
     }
@@ -596,12 +596,12 @@
     @JsonView( { DetailedView.class, ExportView.class, WithoutOrganisationUnitsView.class } )
     @JacksonXmlElementWrapper( localName = "programPersonAttributes", namespace = DxfNamespaces.DXF_2_0 )
     @JacksonXmlProperty( localName = "programPersonAttribute", namespace = DxfNamespaces.DXF_2_0 )
-    public List<ProgramPatientAttribute> getProgramPatientAttributes()
+    public Set<ProgramPatientAttribute> getProgramPatientAttributes()
     {
         return programPatientAttributes;
     }
 
-    public void setProgramPatientAttributes( List<ProgramPatientAttribute> programPatientAttributes )
+    public void setProgramPatientAttributes( Set<ProgramPatientAttribute> programPatientAttributes )
     {
         this.programPatientAttributes = programPatientAttributes;
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientAttribute.java	2014-01-07 08:22:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientAttribute.java	2014-01-07 16:28:34 +0000
@@ -47,6 +47,8 @@
 
     private boolean displayedInList;
 
+    private Integer sortOrder;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -55,11 +57,12 @@
     {
     }
 
-    public ProgramPatientAttribute( Program program, PatientAttribute patientAttribute, boolean displayedInList )
+    public ProgramPatientAttribute( Program program, PatientAttribute patientAttribute, boolean displayedInList, int sortOrder )
     {
         this.program = program;
         this.patientAttribute = patientAttribute;
         this.displayedInList = displayedInList;
+        this.sortOrder = sortOrder;
     }
 
     // -------------------------------------------------------------------------
@@ -131,4 +134,14 @@
         this.displayedInList = displayedInList;
     }
 
+    public Integer getSortOrder()
+    {
+        return sortOrder;
+    }
+
+    public void setSortOrder( Integer sortOrder )
+    {
+        this.sortOrder = sortOrder;
+    }
+
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientIdentifierType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientIdentifierType.java	2014-01-07 15:14:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientIdentifierType.java	2014-01-07 16:28:34 +0000
@@ -47,6 +47,8 @@
 
     private boolean displayedInList;
 
+    private Integer sortOrder;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -56,11 +58,12 @@
     }
 
     public ProgramPatientIdentifierType( Program program, PatientIdentifierType patientIdentifierType,
-        boolean displayedInList )
+        boolean displayedInList, int sortOrder )
     {
         this.program = program;
         this.patientIdentifierType = patientIdentifierType;
         this.displayedInList = displayedInList;
+        this.sortOrder = sortOrder;
     }
 
     // -------------------------------------------------------------------------
@@ -131,5 +134,15 @@
     {
         this.displayedInList = displayedInList;
     }
-    
+
+    public Integer getSortOrder()
+    {
+        return sortOrder;
+    }
+
+    public void setSortOrder( Integer sortOrder )
+    {
+        this.sortOrder = sortOrder;
+    }
+
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2014-01-07 15:02:45 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2014-01-07 16:28:34 +0000
@@ -48,18 +48,16 @@
 
 		<property name="onlyEnrollOnce" />
 
-		<list name="programPatientIdentifierTypes" table="program_programpatientIdentifierTypes">
-			<key column="programid" foreign-key="fk_program_patientIdentifierTypes_programid" />
-			<list-index column="sort_order" base="0" />
+		<set name="programPatientIdentifierTypes" order-by="sort_order">
+			<key column="programid" />
 			<one-to-many class="org.hisp.dhis.program.ProgramPatientIdentifierType" />
-		</list>
+		</set>
 
-		<list name="programPatientAttributes" table="program_programpatientAttributes">
-			<key column="programid" foreign-key="fk_program_patientAttributes_programid" />
-			<list-index column="sort_order" base="0" />
+		<set name="programPatientAttributes" order-by="sort_order">
+			<key column="programid" />
 			<one-to-many class="org.hisp.dhis.program.ProgramPatientAttribute" />
-		</list>
-
+		</set>
+		
 		<property name="ignoreOverdueEvents" />
 
 		<set name="userRoles" table="program_userroles">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2014-01-07 15:02:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2014-01-07 16:28:34 +0000
@@ -305,7 +305,6 @@
 
         programService.addProgram( program );
 
-        List<PatientIdentifierType> identifierTypes = new ArrayList<PatientIdentifierType>();
         int index = 0;
         for ( String selectedPropertyId : selectedPropertyIds )
         {
@@ -316,7 +315,7 @@
                 PatientIdentifierType identifierType = patientIdentifierTypeService.getPatientIdentifierType( Integer
                     .parseInt( ids[1] ) );
                 ProgramPatientIdentifierType programPatientIdentifierType = new ProgramPatientIdentifierType( program,
-                    identifierType, personDisplayNames.get( index ) );
+                    identifierType, personDisplayNames.get( index ) , index + 1);
                 programPatientIdentifierTypeService.addProgramPatientIdentifierType( programPatientIdentifierType );
             }
             else if ( ids[0].equals( Patient.PREFIX_PATIENT_ATTRIBUTE ) )
@@ -325,7 +324,7 @@
                     .parseInt( ids[1] ) );
 
                 ProgramPatientAttribute programPatientAttribute = new ProgramPatientAttribute( program,
-                    patientAttribute, personDisplayNames.get( index ) );
+                    patientAttribute, personDisplayNames.get( index ), index + 1 );
                 programPatientAttributeService.addProgramPatientAttribute( programPatientAttribute );
             }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2014-01-07 15:02:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2014-01-07 16:28:34 +0000
@@ -29,7 +29,9 @@
  */
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
@@ -329,7 +331,12 @@
         program.setRelationshipFromA( relationshipFromA );
         program.setRelationshipText( relationshipText );
 
-        List<PatientIdentifierType> identifierTypes = new ArrayList<PatientIdentifierType>();
+        Set<ProgramPatientIdentifierType> programPatientIdentifierTypes = new HashSet<ProgramPatientIdentifierType>(
+            program.getProgramPatientIdentifierTypes() );
+
+        Set<ProgramPatientAttribute> programPatientAttributes = new HashSet<ProgramPatientAttribute>(
+            program.getProgramPatientAttributes() );
+
         int index = 0;
         for ( String selectedPropertyId : selectedPropertyIds )
         {
@@ -346,14 +353,17 @@
                 if ( programPatientIdentifierType == null )
                 {
                     programPatientIdentifierType = new ProgramPatientIdentifierType( program, identifierType,
-                        personDisplayNames.get( index ) );
+                        personDisplayNames.get( index ), index + 1 );
                     programPatientIdentifierTypeService.addProgramPatientIdentifierType( programPatientIdentifierType );
                 }
                 else
                 {
                     programPatientIdentifierType.setDisplayedInList( personDisplayNames.get( index ) );
+                    programPatientIdentifierType.setSortOrder( index + 1 );
                     programPatientIdentifierTypeService
                         .updateProgramPatientIdentifierType( programPatientIdentifierType );
+
+                    programPatientIdentifierTypes.remove( programPatientIdentifierType );
                 }
             }
             else if ( ids[0].equals( Patient.PREFIX_PATIENT_ATTRIBUTE ) )
@@ -367,18 +377,31 @@
                 if ( programPatientAttribute == null )
                 {
                     programPatientAttribute = new ProgramPatientAttribute( program, patientAttribute,
-                        personDisplayNames.get( index ) );
+                        personDisplayNames.get( index ) , index + 1);
                     programPatientAttributeService.addProgramPatientAttribute( programPatientAttribute );
                 }
                 else
                 {
                     programPatientAttribute.setDisplayedInList( personDisplayNames.get( index ) );
+                    programPatientAttribute.setSortOrder( index + 1 );
                     programPatientAttributeService.updateProgramPatientAttribute( programPatientAttribute );
+
+                    programPatientAttributes.remove( programPatientAttribute );
                 }
             }
             index++;
         }
 
+        for ( ProgramPatientIdentifierType identifier : programPatientIdentifierTypes )
+        {
+            programPatientIdentifierTypeService.deleteProgramPatientIdentifierType( identifier );
+        }
+
+        for ( ProgramPatientAttribute attribute : programPatientAttributes )
+        {
+            programPatientAttributeService.deleteProgramPatientAttribute( attribute );
+        }
+
         if ( relatedProgramId != null )
         {
             Program relatedProgram = programService.getProgram( relatedProgramId );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm	2014-01-07 15:02:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm	2014-01-07 16:28:34 +0000
@@ -233,7 +233,7 @@
 		<tr>
 			<td>
 				<select size="15" style="width:100%;" multiple id="availablePropertyIds" name="availablePropertyIds" ondblclick="selectProperties();" #if( $program.type=='3' ) disabled #end>
-					#foreach( $identifier in $availableIdentifierTypes )
+					#foreach( $identifier in $availableIdentifierTypes ) 
 						<option value="iden_$identifier.id">$identifier.displayName</option>
 					#end
 					#foreach( $attribute in $availableAttributes )
@@ -261,17 +261,18 @@
                             </tr>
 						</thead>
 						<tbody id="selectedList" #if($program.type==3) style="display:none;" #end>
-							#foreach( $programIdentifier in $program.programPatientIdentifierTypes )
+							#foreach( $programIdentifier in $program.programPatientIdentifierTypes ) 
 								#set($identifier = $programIdentifier.patientIdentifierType)
 								<tr ondblclick="unSelectProperties( this )" id="iden_$identifier.id">
 									<td onmousedown="select(event, this)">$encoder.htmlEncode( $identifier.name )</td>
-									<td align="center"><input type="checkbox" name="displayed" value="iden_$identifier.id" #if($identifier.personDisplayName == true ) checked #end #if($program.type==3) disabled #end /></td>
+									<td align="center"><input type="checkbox" name="displayed" value="iden_$identifier.id" #if($programIdentifier.displayedInList == true ) checked #end #if($program.type==3) disabled #end /></td>
 								</tr>
 							#end
 							#foreach( $programPatientAttribute in $program.programPatientAttributes )
+								#set($attribute = $programPatientAttribute.patientAttribute)
 								<tr ondblclick="unSelectProperties( this )" id="attr_$programPatientAttribute.patientAttribute.id">
 									<td onmousedown="select(event, this)">$encoder.htmlEncode( $attribute.name )</td>
-									<td align="center"><input type="checkbox" name="displayed" value="attr_$programPatientAttribute.patientAttribute.id" #if($programPatientAttribute.patientAttribute.displayedInList == true ) checked #end #if($program.type==3) disabled #end  /></td>
+									<td align="center"><input type="checkbox" name="displayed" value="attr_$programPatientAttribute.patientAttribute.id" #if($programPatientAttribute.displayedInList == true ) checked #end #if($program.type==3) disabled #end  /></td>
 								</tr>
 							#end
 						</tbody>