← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1371: PatientAttributeGroup for Patient Record.

 

------------------------------------------------------------
revno: 1371
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-01-29 16:15:10 +0700
message:
  PatientAttributeGroup for Patient Record.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/GetOptionalPatientAttributesWithoutGroupAction.java
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DatabaseAutomaticAccessProvider.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddPatientAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/UpdatePatientAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.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/org/hisp/dhis/patient/i18n_module.properties
  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/addPatientAttributeForm.vm
  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/addPatientForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientAttributeValue.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientForm.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-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DatabaseAutomaticAccessProvider.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DatabaseAutomaticAccessProvider.java	2009-12-21 08:11:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DatabaseAutomaticAccessProvider.java	2010-01-29 09:15:10 +0000
@@ -72,6 +72,7 @@
 
 		UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
 		userAuthorityGroup.setName(UserAuthorityGroup.SUPER_USER_GROUP);
+		
 		userAuthorityGroup
 				.setAuthorities(new HashSet<String>(getAuthorities()));
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddPatientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddPatientAction.java	2009-12-02 07:53:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddPatientAction.java	2010-01-29 09:15:10 +0000
@@ -27,16 +27,25 @@
 
 package org.hisp.dhis.patient.action.patient;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.struts2.ServletActionContext;
+import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeService;
 import org.hisp.dhis.patient.PatientIdentifier;
 import org.hisp.dhis.patient.PatientIdentifierService;
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.patient.state.SelectedStateManager;
-import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -78,7 +87,7 @@
     {
         this.selectionManager = selectionManager;
     }
-    
+
     private SelectedStateManager selectedStateManager;
 
     public void setSelectedStateManager( SelectedStateManager selectedStateManager )
@@ -86,6 +95,20 @@
         this.selectedStateManager = selectedStateManager;
     }
 
+    private PatientAttributeService patientAttributeService;
+
+    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+    {
+        this.patientAttributeService = patientAttributeService;
+    }
+
+    private PatientAttributeValueService patientAttributeValueService;
+
+    public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
+    {
+        this.patientAttributeValueService = patientAttributeValueService;
+    }
+
     // -------------------------------------------------------------------------
     // Input - identifier
     // -------------------------------------------------------------------------
@@ -207,10 +230,10 @@
         {
             if ( age != null )
             {
-                patient.setBirthDateFromAge( age.intValue() );                
+                patient.setBirthDateFromAge( age.intValue() );
             }
         }
-        
+
         patient.setRegistrationDate( new Date() );
 
         patientService.savePatient( patient );
@@ -222,11 +245,36 @@
         patientIdentifier.setPreferred( true );
 
         patientIdentifierService.savePatientIdentifier( patientIdentifier );
-        
+
         selectedStateManager.clearListAll();
         selectedStateManager.clearSearchingAttributeId();
         selectedStateManager.setSearchText( patientIdentifier.getIdentifier() );
 
+        // add attribute value
+        Collection<PatientAttribute> patientAttributes = patientAttributeService.getPatientAttributesByMandatory( true );
+
+        HttpServletRequest request = ServletActionContext.getRequest();
+        ArrayList<String> attributeValue = new ArrayList<String>();
+        
+        for ( PatientAttribute patientAttribute : patientAttributes )
+        {
+            int patientAttributeId = patientAttribute.getId();
+            String value = request.getParameterValues( patientAttributeId + "" )[0].trim();
+            if ( value.length() > 0 )
+            {
+                if ( !patient.getAttributes().contains( patientAttribute ) )
+                {
+                    patient.getAttributes().add( patientAttribute );
+                }
+                
+                PatientAttributeValue patientAttributeValue = new PatientAttributeValue( patientAttribute, patient, value );
+
+                patientAttributeValueService.savePatientAttributeValue( patientAttributeValue );
+            }
+        }
+        
+        patientService.updatePatient( patient );
+        
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientAction.java	2009-10-25 11:36:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientAction.java	2010-01-29 09:15:10 +0000
@@ -74,7 +74,7 @@
     {
         this.programService = programService;
     }
-    
+
     private PatientAttributeValueService patientAttributeValueService;
 
     public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
@@ -98,7 +98,7 @@
     public Patient getPatient()
     {
         return patient;
-    }   
+    }
 
     private PatientIdentifier patientIdentifier;
 
@@ -113,7 +113,7 @@
     {
         return programs;
     }
-    
+
     private Map<Integer, String> patientAttributeValueMap = new HashMap<Integer, String>();
 
     public Map<Integer, String> getPatientAttributeValueMap()
@@ -121,6 +121,18 @@
         return patientAttributeValueMap;
     }
 
+    private Collection<PatientAttribute> patientAttributes;
+
+    public Collection<PatientAttribute> getPatientAttributes()
+    {
+        return patientAttributes;
+    }
+
+    public void setPatientAttributes( Collection<PatientAttribute> patientAttributes )
+    {
+        this.patientAttributes = patientAttributes;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -128,22 +140,22 @@
     public String execute()
         throws Exception
     {
-
-        patient = patientService.getPatient( id );       
-
-        patientIdentifier = patientIdentifierService.getPatientIdentifier( patient );        
-        
-        for( PatientAttribute patientAttribute : patient.getAttributes() )
+        patient = patientService.getPatient( id );
+
+        patientIdentifier = patientIdentifierService.getPatientIdentifier( patient );
+
+        for ( PatientAttribute patientAttribute : patient.getAttributes() )
         {
             patientAttributeValueMap.put( patientAttribute.getId(), PatientAttributeValue.UNKNOWN );
         }
 
         Collection<PatientAttributeValue> patientAttributeValues = patientAttributeValueService
-            .getPatientAttributeValues( patient );       
+            .getPatientAttributeValues( patient );
 
         for ( PatientAttributeValue patientAttributeValue : patientAttributeValues )
         {
-            patientAttributeValueMap.put( patientAttributeValue.getPatientAttribute().getId(), patientAttributeValue.getValue() );
+            patientAttributeValueMap.put( patientAttributeValue.getPatientAttribute().getId(), patientAttributeValue
+                .getValue() );
         }
 
         programs = programService.getAllPrograms();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java	2009-11-25 09:08:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java	2010-01-29 09:15:10 +0000
@@ -27,8 +27,12 @@
 
 package org.hisp.dhis.patient.action.patient;
 
+import java.util.Collection;
+
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeService;
 import org.hisp.dhis.patient.PatientIdentifierService;
 
 import com.opensymphony.xwork2.Action;
@@ -58,6 +62,13 @@
         this.patientIdentifierService = patientIdentifierService;
     }
 
+    public PatientAttributeService patientAttributeService;
+
+    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+    {
+        this.patientAttributeService = patientAttributeService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -69,6 +80,13 @@
         return identifier;
     }
 
+    private Collection<PatientAttribute> patientAttributes;
+
+    public Collection<PatientAttribute> getPatientAttributes()
+    {
+        return patientAttributes;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -79,6 +97,8 @@
 
         identifier = patientIdentifierService.getNextIdentifierForOrgUnit( organisationUnit );
 
+        patientAttributes = patientAttributeService.getPatientAttributesByMandatory(true);
+        
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/UpdatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/UpdatePatientAction.java	2009-10-27 09:52:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/UpdatePatientAction.java	2010-01-29 09:15:10 +0000
@@ -26,10 +26,22 @@
  */
 package org.hisp.dhis.patient.action.patient;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeService;
 import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patient.action.patientattribute.SavePatientAttributeValueAction;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
 import org.hisp.dhis.i18n.I18nFormat;
 
 import com.opensymphony.xwork2.Action;
@@ -41,6 +53,7 @@
 public class UpdatePatientAction
     implements Action
 {
+    private static final Log LOG = LogFactory.getLog( UpdatePatientAction.class );
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -60,6 +73,20 @@
         this.patientService = patientService;
     }
 
+    public PatientAttributeService patientAttributeService;
+
+    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+    {
+        this.patientAttributeService = patientAttributeService;
+    }
+
+    private PatientAttributeValueService patientAttributeValueService;
+
+    public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
+    {
+        this.patientAttributeValueService = patientAttributeValueService;
+    }
+
     // -------------------------------------------------------------------------
     // Input - Id
     // -------------------------------------------------------------------------
@@ -106,9 +133,9 @@
     {
         this.birthDate = birthDate;
     }
-    
+
     private boolean birthDateEstimated;
-    
+
     public void setBirthDateEstimated( boolean birthDateEstimated )
     {
         this.birthDateEstimated = birthDateEstimated;
@@ -150,12 +177,59 @@
         patient.setMiddleName( middleName );
         patient.setLastName( lastName );
         patient.setGender( gender );
-        patient.setBirthDate( format.parseDate( birthDate ) );        
-        patient.setBirthDateEstimated( birthDateEstimated );        
+        patient.setBirthDate( format.parseDate( birthDate ) );
+        patient.setBirthDateEstimated( birthDateEstimated );
         patient.setRegistrationDate( new Date() );
 
         patientService.updatePatient( patient );
 
+        // add attribute value
+        Collection<PatientAttribute> patientAttributes = patientAttributeService.getPatientAttributesByMandatory( true );
+
+        HttpServletRequest request = ServletActionContext.getRequest();
+        ArrayList<String> attributeValue = new ArrayList<String>();
+
+        for ( PatientAttribute patientAttribute : patientAttributes )
+        {
+            int patientAttributeId = patientAttribute.getId();
+            String value = request.getParameterValues( patientAttributeId + "" )[0].trim();
+            if ( value.length() > 0 )
+            {
+                if ( !patient.getAttributes().contains( patientAttribute ) )
+                {
+                    patient.getAttributes().add( patientAttribute );
+                }
+                
+                updatePatientAttributeValue(patientAttribute, value);
+            }
+        }
+
+        patientService.updatePatient( patient );
+        
         return SUCCESS;
     }
+
+    private void updatePatientAttributeValue(PatientAttribute patientAttribute, String value)
+    {
+
+        PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( patient,
+            patientAttribute );
+
+        if ( patientAttributeValue == null )
+        {
+                LOG.debug( "Adding PatientAttributeValue, value added" );
+
+                patientAttributeValue = new PatientAttributeValue( patientAttribute, patient, value );
+
+                patientAttributeValueService.savePatientAttributeValue( patientAttributeValue );
+        }
+        else
+        {
+            LOG.debug( "Updating PatientAttributeValue, value added/changed" );
+
+            patientAttributeValue.setValue( value );
+
+            patientAttributeValueService.updatePatientAttributeValue( patientAttributeValue );
+        }
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java	2009-10-26 09:04:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java	2010-01-29 09:15:10 +0000
@@ -75,6 +75,13 @@
         this.valueType = valueType;
     }
 
+    private boolean mandatory;
+    
+    public void setMandatory( boolean mandatory )
+    {
+        this.mandatory = mandatory;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -88,7 +95,8 @@
         patientAttribute.setName( nameField );
         patientAttribute.setDescription( description );
         patientAttribute.setValueType( valueType );
-
+        patientAttribute.setMandatory(mandatory);
+        
         patientAttributeService.savePatientAttribute( patientAttribute );
 
         return SUCCESS;

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/GetOptionalPatientAttributesWithoutGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/GetOptionalPatientAttributesWithoutGroupAction.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/patientattribute/GetOptionalPatientAttributesWithoutGroupAction.java	2010-01-29 09:15:10 +0000
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2004-2009, 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.patientattribute;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Abyot Asalefew Gizaw
+ * @version $Id$
+ */
+public class GetOptionalPatientAttributesWithoutGroupAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private PatientAttributeService patientAttributeService;
+
+    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+    {
+        this.patientAttributeService = patientAttributeService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Collection<PatientAttribute> patientAttributes = new ArrayList<PatientAttribute>();
+
+    public Collection<PatientAttribute> getPatientAttributes()
+    {
+        return patientAttributes;
+    }
+
+   
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        patientAttributes = patientAttributeService.getOptionalPatientAttributesWithoutGroup();
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.java	2010-01-29 03:08:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.java	2010-01-29 09:15:10 +0000
@@ -53,7 +53,7 @@
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
-    
+
     private int id;
 
     public void setId( int id )
@@ -82,6 +82,13 @@
         this.valueType = valueType;
     }
 
+    private boolean mandatory;
+
+    public void setMandatory( boolean mandatory )
+    {
+        this.mandatory = mandatory;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -93,6 +100,7 @@
         patientAttribute.setName( nameField );
         patientAttribute.setDescription( description );
         patientAttribute.setValueType( valueType );
+        patientAttribute.setMandatory( mandatory );
 
         patientAttributeService.updatePatientAttribute( patientAttribute );
 

=== 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	2010-01-29 03:08:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2010-01-29 09:15:10 +0000
@@ -316,6 +316,8 @@
 			ref="org.hisp.dhis.patient.state.SelectedStateManager" />
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
+		<property name="patientAttributeValueService"
+			ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.action.patient.RemovePatientAction"
@@ -328,6 +330,10 @@
 		class="org.hisp.dhis.patient.action.patient.UpdatePatientAction"
 		scope="prototype">
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
+		<property name="patientAttributeService"
+			ref="org.hisp.dhis.patient.PatientAttributeService" />
+		<property name="patientAttributeValueService"
+			ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.action.patient.ShowAddPatientFormAction"
@@ -337,6 +343,8 @@
 			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
 		<property name="patientIdentifierService"
 			ref="org.hisp.dhis.patient.PatientIdentifierService" />
+		<property name="patientAttributeService"
+			ref="org.hisp.dhis.patient.PatientAttributeService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.action.patient.ValidatePatientAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2010-01-29 03:08:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2010-01-29 09:15:10 +0000
@@ -262,4 +262,6 @@
 update_patient_attribute_group = Update Patient Attribute Group
 add_new_patient_attribute_group = Add New Patient Attribute Group
 attribute_group = Attribute Group
-mandatory_attribute = Mandatory Attribute
\ No newline at end of file
+mandatory_attribute = Mandatory Attribute
+madatory = Mandatory
+value_must_date = Value must be an date
\ 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	2010-01-29 03:08:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2010-01-29 09:15:10 +0000
@@ -355,18 +355,26 @@
 			<param name="page">/dhis-web-maintenance-patient/addPatientForm.vm</param>
 			<param name="menu">/dhis-web-maintenance-patient/menuWithTree.vm</param>
 			<param name="menuTreeHeight">321</param>
-			<param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/calendar/calendar.js,../dhis-web-commons/calendar/calendar-lang.js,../dhis-web-commons/calendar/calendar-setup.js,javascript/patient.js</param>
+			<param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/calendar/calendar.js,../dhis-web-commons/calendar/calendar-lang.js,../dhis-web-commons/calendar/calendar-setup.js,javascript/patient.js,
+				javascript/patientAttributeValue.js </param>
 			<param name="requiredAuthorities">F_PATIENT_ADD</param>
 		</action>
 
 		<action name="showUpdatePatientForm"
+			class="org.hisp.dhis.patient.action.patient.ShowAddPatientFormAction">
+			<result name="success" type="chain">showUpdatePatientFormChain
+			</result>
+		</action>
+
+		<action name="showUpdatePatientFormChain"
 			class="org.hisp.dhis.patient.action.patient.GetPatientAction">
 			<interceptor-ref name="organisationUnitTreeStack" />
 			<result name="success" type="velocity">/main.vm</result>
 			<param name="page">/dhis-web-maintenance-patient/updatePatientForm.vm</param>
 			<param name="menu">/dhis-web-maintenance-patient/menuWithTree.vm</param>
 			<param name="menuTreeHeight">321</param>
-			<param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/calendar/calendar.js,../dhis-web-commons/calendar/calendar-lang.js,../dhis-web-commons/calendar/calendar-setup.js,javascript/patient.js</param>
+			<param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/calendar/calendar.js,../dhis-web-commons/calendar/calendar-lang.js,../dhis-web-commons/calendar/calendar-setup.js,javascript/patient.js,
+				javascript/patientAttributeValue.js</param>
 			<param name="requiredAuthorities">F_PATIENT_UPDATE</param>
 		</action>
 
@@ -684,7 +692,7 @@
 			</result>
 			<param name="requiredAuthorities">F_PATIENTATTRIBUTE_DELETE</param>
 		</action>
-		
+
 		<action name="addPatientAttributeGroup"
 			class="org.hisp.dhis.patient.action.patientattributegroup.AddPatientAttributeGroupAction">
 			<result name="success" type="redirect">patientAttributeGroup.action

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeForm.vm	2009-10-22 07:41:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeForm.vm	2010-01-29 09:15:10 +0000
@@ -23,6 +23,8 @@
                 <option value="bool">$i18n.getString( "yes_no" )</option>
                 <option value="date">$i18n.getString( "date" )</option>
             </select>
+			<input type="hidden" id="mandatory" name="mandatory">
+			<label>$i18n.getString( "madatory" )</label> <input type="checkbox" onChange="javascript: byId('mandatory').value=this.checked;">
         </td>
     </tr>  
         

=== 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	2010-01-29 03:08:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeGroupForm.vm	2010-01-29 09:15:10 +0000
@@ -10,10 +10,7 @@
     <tr>
         <td><label>$i18n.getString( "name" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
         <td><input type="text" id="nameField" name="nameField"  style="width:20em"></td>
-        <td colspan="2"><label>$i18n.getString( "required" )</label>
-		<input type='hidden' id='requiredField' name="requiredField">
-        <input type="checkbox" id="required" name="required" onchange="javascript: byId('requiredField').value = this.checked"></td>
-      </td>
+        </td>
     </tr>   
     
     <tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm	2009-12-01 09:17:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm	2010-01-29 09:15:10 +0000
@@ -9,7 +9,7 @@
 	</tr>
 	<tr>
 		<td><label for="identifier">$i18n.getString( "identifier" )</label></td>
-		<td><input type="text" readonly="readonly" id="identifier" name="identifier" value="$encoder.htmlEncode( $identifier )" style="width:30em"></td>		
+		<td colspan="2"><input type="text" readonly="readonly" id="identifier" name="identifier" value="$encoder.htmlEncode( $identifier )" style="width:30em"></td>		
 	</tr>	
 	<tr><td>&nbsp;</td></tr>
 	<tr>
@@ -17,7 +17,7 @@
 	</tr>
 	<tr>
 		<td><label for="firstName">$i18n.getString( "first_name" )</label></td>
-		<td><input type="text" id="firstName" name="firstName" maxlength="30" style="width:30em"></td>
+		<td ><input type="text" id="firstName" name="firstName" maxlength="30" style="width:30em"></td>
 	</tr>
 	<tr>
 		<td><label for="middleName">$i18n.getString( "middle_name" ) </label></td>
@@ -54,7 +54,52 @@
             <input type="checkbox" id="birthDateEstimated" name="birthDateEstimated" value="true"> 
 	   </td>
 	</tr>
-	  	
+	
+	<tr><td>&nbsp;</td></tr>	
+	<tr>
+		<th colspan="2">$i18n.getString( "mandatory_attribute" )</th>
+	</tr>
+    
+#set( $rowCount = 0 )
+#set( $mark = 0 )
+#set( $tabIndex = 1 )
+
+#foreach( $patientAttribute in $patientAttributes )
+    #set( $rowCount = $rowCount + 1 )    
+   
+    #set( $patientAttributeValue = false )
+    #set( $patientAttributeValue = $patientAttributeValueMap.get( $patientAttribute.id ) )    
+    <tr>
+        <td>
+            <span id="value[$patientAttribute.id].name" title="$!encoder.htmlEncode( $patientAttribute.description )">
+                $rowCount. $encoder.htmlEncode( $patientAttribute.name )            
+            </span>
+        </td>        
+        ##type        ##entry        
+        <td>        
+            #if( $patientAttribute.valueType == "bool" )
+                <select name="$patientAttribute.id" id="$patientAttribute.id" style="width:100%" tabindex="$tabIndex">              
+                    <option value="">[$i18n.getString( "please_select" )]</option>
+                    <option value="true">$i18n.getString( "yes" )</option>
+                    <option value="false">$i18n.getString( "no" )</option>
+                </select>                
+            #elseif( $patientAttribute.valueType == "date" )
+                <input type="text" id="$patientAttribute.id" name="$patientAttribute.id" onchange="validateAttributeValue(  $patientAttribute.id, '$encoder.jsEncode( $patientAttribute.name )' , '$patientAttribute.valueType')" tabindex="$tabIndex" >
+                    <img src="../images/calendar_icon.gif" width="16" height="16" id="getDateValue$patientAttribute.id" style="cursor: pointer;" title="$i18n.getString("date_selector")" onmouseover="this.style.background='orange';" onmouseout="this.style.background=''" alt="$i18n.getString( "date" )">
+                    <script type="text/javascript">
+                        Calendar.setup({
+                            inputField     :    "$patientAttribute.id",      // id of the input field
+                            ifFormat       :    "$i18n.getString("format.date.label")",       // format of the input field
+                            button         :    "getDateValue$patientAttribute.id"   // trigger for the calendar (button ID)
+                        });
+                    </script>                    
+            #else
+                <input name="$patientAttribute.id" id="$patientAttribute.id" type="text" onchange="validateAttributeValue( $patientAttribute.id, '$encoder.jsEncode( $patientAttribute.name )' , '$patientAttribute.valueType')" tabindex="$tabIndex" >
+            #end
+        </td>       
+    </tr>
+    #set( $tabIndex = $tabIndex + 1 )
+#end
 </table>
 
 <p>
@@ -72,6 +117,9 @@
 	firstNameField.select();
 	firstNameField.focus();
 	var i18n_age_must_integer = '$encoder.jsEscape( $i18n.getString( "age_must_integer" ) , "'")';
+	var i18n_value_must_integer = '$encoder.jsEscape( $i18n.getString( "value_must_integer" ) , "'")';
+	var i18n_value_must_date = '$encoder.jsEscape( $i18n.getString( "value_must_date" ) , "'")';
+
 </script>	
 
 <script type="text/javascript">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientAttributeValue.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientAttributeValue.js	2009-11-24 15:39:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientAttributeValue.js	2010-01-29 09:15:10 +0000
@@ -316,3 +316,49 @@
     }
 }
 
+// Validate
+// Input datetime
+function isDate( value ) {
+	var re = /^(\d{2,4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
+	return (re.test(value)) ? true : false;
+}
+
+function validateAttributeValue(  patientAttributeId, patientAttributeName, type)
+{ 
+	var field = byId( patientAttributeId );
+    
+    if( field.value != '' )
+    {
+    	if( type == 'int' )
+    	{
+    		if ( !isInt( field.value ))
+            {
+                field.style.backgroundColor = '#ffcc00';
+
+                window.alert( i18n_value_must_integer + '\n\n' + patientAttributeName );
+				field.value = '';
+                
+				field.select();
+                field.focus();
+
+                return;
+            }
+    	} else if(type == 'date'){
+			if(!isDate(field.value ))
+			{
+				field.style.backgroundColor = '#ffcc00';
+			
+				window.alert( i18n_value_must_date + '\n\n' + patientAttributeName );
+				field.value = '';
+                
+				field.select();
+                field.focus();
+
+                return;
+			}
+		}
+		field.style.backgroundColor = '';
+    }
+}
+
+

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm	2009-10-26 09:04:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm	2010-01-29 09:15:10 +0000
@@ -31,6 +31,8 @@
                 <option value="bool" #if( $patientAttribute.valueType == 'bool' ) selected="selected" #end>$i18n.getString( "yes_no" )</option>
                 <option value="date" #if( $patientAttribute.valueType == 'date' ) selected="selected" #end>$i18n.getString( "date" )</option>
             </select>
+			<input type="hidden" id="mandatory" name="mandatory">
+			<label>$i18n.getString( "madatory" )</label> <input type="checkbox" #if($patientAttribute.mandatory==true) checked #end onChange="javascript: byId('mandatory').value=this.checked;">
         </td>
       </tr>
       <tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientForm.vm	2009-12-01 09:17:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientForm.vm	2010-01-29 09:15:10 +0000
@@ -55,7 +55,51 @@
             <label for="age">$i18n.getString( "age" )</label>&nbsp;&nbsp;$encoder.htmlEncode( $patient.getAge() )            
         </td> 
 	</tr>  
-		
+		<tr><td>&nbsp;</td></tr>	
+	<tr>
+		<th colspan="2">$i18n.getString( "mandatory_attribute" )</th>
+	</tr>
+    
+#set( $rowCount = 0 )
+#set( $mark = 0 )
+#set( $tabIndex = 1 )
+
+#foreach( $patientAttribute in $patientAttributes )
+    #set( $rowCount = $rowCount + 1 )
+    #set( $patientAttributeValue = false )
+    #set( $patientAttributeValue = $patientAttributeValueMap.get( $patientAttribute.id ) )    
+    <tr #if( $mark == 0 ) style="background-color:#dddddd" #end>
+        <td>
+            <span id="value[$patientAttribute.id].name" title="$!encoder.htmlEncode( $patientAttribute.description )">
+                $rowCount. $encoder.htmlEncode( $patientAttribute.name )            
+            </span>
+        </td>        
+        ##type        ##entry        
+        <td>        
+            #if( $patientAttribute.valueType == "bool" )
+                <select name="$patientAttribute.id" id="$patientAttribute.id" style="width:100%" tabindex="$tabIndex">              
+                    <option value="">[$i18n.getString( "please_select" )]</option>
+                    <option value="true" #if( $patientAttributeValueMap.get($patientAttribute.id ) == "true" ) selected="selected" #end>$i18n.getString( "yes" )</option>
+                    <option value="false" #if( $patientAttributeValueMap.get($patientAttribute.id ) == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
+                </select>                
+            #elseif( $patientAttribute.valueType == "date" )
+                <input type="text" id="$patientAttribute.id" name="$patientAttribute.id" value="$!encoder.htmlEncode( $patientAttributeValueMap.get($patientAttribute.id ))" onchange="validateAttributeValue(  $patientAttribute.id, '$encoder.jsEncode( $patientAttribute.name )' , '$patientAttribute.valueType')" tabindex="$tabIndex" >
+                    <img src="../images/calendar_icon.gif" width="16" height="16" id="getDateValue$patientAttribute.id" style="cursor: pointer;" title="$i18n.getString("date_selector")" onmouseover="this.style.background='orange';" onmouseout="this.style.background=''" alt="$i18n.getString( "date" )">
+                    <script type="text/javascript">
+                        Calendar.setup({
+                            inputField     :    "$patientAttribute.id",      // id of the input field
+                            ifFormat       :    "$i18n.getString("format.date.label")",       // format of the input field
+                            button         :    "getDateValue$patientAttribute.id"   // trigger for the calendar (button ID)
+                        });
+                    </script>                    
+            #else
+                <input name="$patientAttribute.id" id="$patientAttribute.id" type="text" value="$!encoder.htmlEncode( $patientAttributeValueMap.get($patientAttribute.id ) )" onchange="validateAttributeValue( $patientAttribute.id, '$encoder.jsEncode( $patientAttribute.name )' , '$patientAttribute.valueType')" tabindex="$tabIndex" >
+            #end
+        </td>       
+    </tr>
+    #set( $tabIndex = $tabIndex + 1 )
+#end
+
 </table>
 
 <p>
@@ -81,5 +125,10 @@
             ifFormat       :    "$i18n.getString("format.date.label")",       // format of the input field
             button         :    "getBirthDate"   // trigger for the calendar (button ID)
         });
+		
+	var i18n_value_must_integer = '$encoder.jsEscape( $i18n.getString( "value_must_integer" ) , "'")';
+	var i18n_value_must_date = '$encoder.jsEscape( $i18n.getString( "value_must_date" ) , "'")';
+
 </script>
+
 				
\ No newline at end of file