← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4801: Validate for patientChart when creating/updating a chart; Check duplicate name of other object is...

 

------------------------------------------------------------
revno: 4801
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-10-03 16:40:38 +0700
message:
  Validate for patientChart when creating/updating a chart; Check duplicate name of other object is wrong (Patient module).
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientchart/ValidatePatientChartAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/hibernate/HibernatePatientChartStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ValidateDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/ValidatePatientAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeGroupForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientChartForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteGroupForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientChartForm.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/patientchart/PatientChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartService.java	2011-09-06 02:47:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartService.java	2011-10-03 09:40:38 +0000
@@ -49,9 +49,11 @@
     void updatePatientChart( PatientChart patientChart );
 
     PatientChart getPatientChart( int id );
-    
-    Collection<PatientChart> getPatientCharts ( Collection<Program> programs );
-    
+
+    PatientChart getPatientChartByTitle( String title );
+
+    Collection<PatientChart> getPatientCharts( Collection<Program> programs );
+
     Collection<PatientChart> getAllPatientCharts();
 
     JFreeChart getJFreeChart( int id, I18nFormat format );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartStore.java	2011-09-06 02:47:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientchart/PatientChartStore.java	2011-10-03 09:40:38 +0000
@@ -29,7 +29,7 @@
 
 import java.util.Collection;
 
-import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.program.Program;
 
 /**
@@ -37,9 +37,12 @@
  * @version $ PatientChartStore.java Sep 5, 2011 8:06:43 AM $
  * 
  */
-public interface PatientChartStore extends GenericStore<PatientChart>
+public interface PatientChartStore
+    extends GenericIdentifiableObjectStore<PatientChart>
 {
     String ID = PatientChartStore.class.getName();
-    
-    Collection<PatientChart> getPatientCharts ( Collection<Program> programs );
+
+    Collection<PatientChart> getPatientCharts( Collection<Program> programs );
+
+    PatientChart getByTitle( String title );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java	2011-09-06 02:47:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java	2011-10-03 09:40:38 +0000
@@ -114,6 +114,12 @@
     }
 
     @Override
+    public PatientChart getPatientChartByTitle( String title )
+    {
+        return patientChartStore.getByTitle( title );
+    }
+    
+    @Override
     public Collection<PatientChart> getPatientCharts( Collection<Program> programs )
     {
         return patientChartStore.getPatientCharts( programs );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/hibernate/HibernatePatientChartStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/hibernate/HibernatePatientChartStore.java	2011-09-06 02:47:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/hibernate/HibernatePatientChartStore.java	2011-10-03 09:40:38 +0000
@@ -54,4 +54,10 @@
         criteria.add( Restrictions.in( "program", programs ) );
         return criteria.list();
     }
+    
+    @Override
+    public PatientChart getByTitle( String title )
+    {
+        return getObject( Restrictions.eq( "title", title ) );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ValidateDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ValidateDataEntryFormAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ValidateDataEntryFormAction.java	2011-10-03 09:40:38 +0000
@@ -96,7 +96,7 @@
     {
         DataEntryForm match = dataEntryFormService.getDataEntryFormByName( name );
 
-        if ( match != null && (dataEntryFormId == null || match.getId() != dataEntryFormId) )
+        if ( match != null && (dataEntryFormId == null || match.getId() != dataEntryFormId.intValue()) )
         {
             message = i18n.getString( "duplicate_names" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/ValidatePatientAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/ValidatePatientAttributeAction.java	2011-07-28 06:46:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/ValidatePatientAttributeAction.java	2011-10-03 09:40:38 +0000
@@ -96,7 +96,7 @@
 
         PatientAttribute match = patientAttributeService.getPatientAttributeByName( name );
 
-        if ( match != null && (id == null || match.getId() != id) )
+        if ( match != null && (id == null || match.getId() != id.intValue()) )
         {
             message = i18n.getString( "name_in_use" );
 

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientchart/ValidatePatientChartAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientchart/ValidatePatientChartAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientchart/ValidatePatientChartAction.java	2011-10-03 09:40:38 +0000
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient.action.patientchart;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patientchart.PatientChart;
+import org.hisp.dhis.patientchart.PatientChartService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $Id: ValidatePatientChartAction.java Oct 3, 2011 2:52:13 PM $
+ */
+public class ValidatePatientChartAction
+    implements Action
+{
+
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    private PatientChartService patientChartService;
+
+    public void setPatientChartService( PatientChartService patientChartService )
+    {
+        this.patientChartService = patientChartService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private String title;
+
+    public void setTitle( String title )
+    {
+        this.title = title;
+    }
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        title = title.trim();
+
+        PatientChart match = patientChartService.getPatientChartByTitle( title );
+
+        if ( match != null && (id == null || match.getId() != id.intValue()) )
+        {
+            message = i18n.getString( "name_in_use" );
+
+            return INPUT;
+        }
+
+        message = i18n.getString( "everything_is_ok" );
+
+        return SUCCESS;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAction.java	2011-10-03 09:40:38 +0000
@@ -70,7 +70,7 @@
     {
         this.name = name;
     }
-    
+
     private String message;
 
     public String getMessage()
@@ -96,7 +96,7 @@
 
         Program match = programService.getProgramByName( name );
 
-        if ( match != null && (id == null || match.getId() != id) )
+        if ( match != null && (id == null || match.getId() != id.intValue()) )
         {
             message = i18n.getString( "duplicate_names" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAttributeAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ValidateProgramAttributeAction.java	2011-10-03 09:40:38 +0000
@@ -96,7 +96,7 @@
 
         ProgramAttribute match = programAttributeService.getProgramAttributeByName( name );
 
-        if ( match != null && (id == null || !match.getId().equals( id )) )
+        if ( match != null && (id == null || match.getId() != id.intValue() )) )
         {
             message = i18n.getString( "duplicate_names" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java	2011-10-03 09:40:38 +0000
@@ -94,7 +94,7 @@
     {
         ProgramStage match = programStageService.getProgramStageByName( name );
 
-        if ( match != null && (id == null || match.getId() != id) )
+        if ( match != null && (id == null || match.getId() != id.intValue()) )
         {
             message = i18n.getString( "duplicate_names" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2011-10-02 09:53:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2011-10-03 09:40:38 +0000
@@ -971,4 +971,12 @@
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
 	</bean>
 	
+	<bean
+		id="org.hisp.dhis.patient.action.patientchart.ValidatePatientChartAction"
+		class="org.hisp.dhis.patient.action.patientchart.ValidatePatientChartAction"
+		scope="prototype">
+		<property name="patientChartService"
+			ref="org.hisp.dhis.patientchart.PatientChartService" />
+	</bean>
+	
 </beans>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2011-10-02 09:53:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2011-10-03 09:40:38 +0000
@@ -988,6 +988,15 @@
 				/dhis-web-maintenance-patient/responsePatientChart.vm</result>
 			<param name="requiredAuthorities">F_PROGRAM_ADD</param>
 		</action>
+		
+		<action name="validatePatientChart"
+			class="org.hisp.dhis.patient.action.patientchart.ValidatePatientChartAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+			<result name="input" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseInput.vm</result>
+			<param name="onExceptionReturn">plainTextError</param>
+		</action>
 
 	</package>
 </struts>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeGroupForm.vm	2011-10-03 08:45:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeGroupForm.vm	2011-10-03 09:40:38 +0000
@@ -75,7 +75,7 @@
 			<input type="button" value="&lt;" title="$i18n.getString('remove_selected')" onclick="dhisAjaxSelect_moveAllSelected( 'selectedAttributes', 'availableAttributes' )"/>
 		</td>
 		<td>
-			<select multiple id="selectedAttributes" name="selectedAttributes" size="15" style="width:100%;margin-top:23px"></select>
+			<select multiple id="selectedAttributes" name="selectedAttributes" size="15" style="width:100%"></select>
 		</td>
 		<td>
 			<a href="javascript:moveUpSelectedOption( 'selectedAttributes')" title="$i18n.getString( 'move_up' )"><img src="../images/move_up.png" alt="$i18n.getString( 'move_up' )"/></a><br/><br/>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientChartForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientChartForm.vm	2011-09-29 04:17:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientChartForm.vm	2011-10-03 09:40:38 +0000
@@ -2,9 +2,8 @@
 	jQuery(document).ready(	function(){
 		validation( 'addPatientChartForm', function( form ){			
 			form.submit();
-		});				
-		
-		//checkValueIsExist( "name", "validateProgram.action");
+		});	
+		checkValueIsExist( "title", "validatePatientChart.action");
 	});		
 
     var i18n_must_select_one_dataelement = '$encoder.jsEscape( $i18n.getString( "must_select_one_dataelement" ), "'")';

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteGroupForm.vm	2011-10-03 08:45:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteGroupForm.vm	2011-10-03 09:40:38 +0000
@@ -77,7 +77,7 @@
 			<input type="button" value="&lt;" title="$i18n.getString('remove_selected')" onclick="dhisAjaxSelect_moveAllSelected( 'selectedAttributes', 'availableAttributes' )"/>
 		</td>
 		<td>
-			<select multiple id="selectedAttributes" name="selectedAttributes" size="15" style="width:100%;margin-top:23px">
+			<select multiple id="selectedAttributes" name="selectedAttributes" size="15" style="width:100%">
 			#foreach($patientAttribute in $patientAttributeGroup.attributes)
 			#if($!patientAttribute)
 				<option value='$patientAttribute.id'>$patientAttribute.name</option>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientChartForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientChartForm.vm	2011-09-29 04:17:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientChartForm.vm	2011-10-03 09:40:38 +0000
@@ -2,9 +2,9 @@
 	jQuery(document).ready(	function(){
 		validation( 'updatePatientChartForm', function( form ){			
 			form.submit();
-		});				
-		
-		//checkValueIsExist( "name", "validateProgram.action");
+		});			
+	
+		checkValueIsExist( "title", "validatePatientChart.action", {id:'$patientChart.id'});	
 	});		
 
     var i18n_must_select_one_dataelement = '$encoder.jsEscape( $i18n.getString( "must_select_one_dataelement" ), "'")';
@@ -12,7 +12,7 @@
 
 <h3>$i18n.getString( "edit_patient_chart" )</h3>
 
-<form id="updatePatientChartForm" name="addPatientChartForm" method="post" action="updatePatientChart.action">
+<form id="updatePatientChartForm" name="updatePatientChartForm" method="post" action="updatePatientChart.action">
 <input type='hidden' id='id' name='id' value='$patientChart.id'>
 
 <table>