← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13318: Add new patient attribute property called Age. When to enter number value for this attribute, the...

 

------------------------------------------------------------
revno: 13318
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-12-19 11:00:58 +0700
message:
  Add new patient attribute property called Age. When to enter number value for this attribute, the system calculates a date from this number and save into database. In update patient form, the system will calculate a number from this date and show in update form.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm
  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/updatePatientAttibuteForm.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/patient/PatientAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java	2013-12-18 08:01:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java	2013-12-19 04:00:58 +0000
@@ -39,6 +39,8 @@
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.view.DetailedView;
 
+import java.util.Calendar;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -65,11 +67,13 @@
     public static final String TYPE_TRUE_ONLY = "trueOnly";
 
     public static final String TYPE_COMBO = "combo";
-    
+
     public static final String TYPE_PHONE_NUMBER = "phoneNumber";
-    
+
     public static final String TYPE_TRACKER_ASSOCIATE = "trackerAssociate";
 
+    public static final String TYPE_AGE = "age";
+
     private String description;
 
     private String valueType;
@@ -108,7 +112,7 @@
         this.mandatory = mandatory;
         this.inherit = inherit;
         this.displayOnVisitSchedule = displayOnVisitSchedule;
-        
+
         setAutoFields();
     }
 
@@ -123,7 +127,7 @@
     {
         return TYPE_INT.equals( valueType );
     }
-    
+
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -269,4 +273,39 @@
     {
         this.sortOrderInVisitSchedule = sortOrderInVisitSchedule;
     }
+
+    public static Date getDateFromAge( int age )
+    {
+        Calendar todayCalendar = Calendar.getInstance();
+        todayCalendar.clear( Calendar.MILLISECOND );
+        todayCalendar.clear( Calendar.SECOND );
+        todayCalendar.clear( Calendar.MINUTE );
+        todayCalendar.set( Calendar.HOUR_OF_DAY, 0 );
+
+        todayCalendar.add( Calendar.YEAR, -1 * age );
+
+        return todayCalendar.getTime();
+    }
+    
+    public static int getAgeFromDate( Date date )
+    {
+        Calendar birthCalendar = Calendar.getInstance();
+        birthCalendar.setTime( date );
+
+        Calendar todayCalendar = Calendar.getInstance();
+
+        int age = todayCalendar.get( Calendar.YEAR ) - birthCalendar.get( Calendar.YEAR );
+
+        if ( todayCalendar.get( Calendar.MONTH ) < birthCalendar.get( Calendar.MONTH ) )
+        {
+            age--;
+        }
+        else if ( todayCalendar.get( Calendar.MONTH ) == birthCalendar.get( Calendar.MONTH )
+            && todayCalendar.get( Calendar.DAY_OF_MONTH ) < birthCalendar.get( Calendar.DAY_OF_MONTH ) )
+        {
+            age--;
+        }
+
+        return age;
+    }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java	2013-12-18 08:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java	2013-12-19 04:00:58 +0000
@@ -38,6 +38,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 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;
@@ -93,6 +94,8 @@
 
     private OrganisationUnitSelectionManager selectionManager;
 
+    private I18nFormat format;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -210,6 +213,11 @@
                     attributeValue = new PatientAttributeValue();
                     attributeValue.setPatient( patient );
                     attributeValue.setPatientAttribute( attribute );
+
+                    if ( attribute.getValueType().equals( PatientAttribute.TYPE_AGE ) )
+                    {
+                        value = format.formatDate( PatientAttribute.getDateFromAge( Integer.parseInt( value ) ) );
+                    }
                     attributeValue.setValue( value );
 
                     if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( attribute.getValueType() ) )
@@ -225,10 +233,6 @@
                             // Someone deleted this option ...
                         }
                     }
-                    else
-                    {
-                        attributeValue.setValue( value.trim() );
-                    }
                     patientAttributeValues.add( attributeValue );
                 }
             }
@@ -238,7 +242,7 @@
         // Save patient
         // -------------------------------------------------------------------------
 
-        Integer id = patientService.createPatient( patient, representativeId, relationshipTypeId,
+       patientService.createPatient( patient, representativeId, relationshipTypeId,
             patientAttributeValues );
 
         // -------------------------------------------------------------------------
@@ -337,6 +341,11 @@
         this.patientService = patientService;
     }
 
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
     public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService )
     {
         this.patientIdentifierService = patientIdentifierService;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-12-16 04:27:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-12-19 04:00:58 +0000
@@ -31,6 +31,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -281,15 +282,18 @@
 
             PatientIdentifierType idType = null;
             Patient representative = patient.getRepresentative();
-            relationship = relationshipService.getRelationship( representative, patient );
-
-            for ( PatientIdentifier representativeIdentifier : representative.getIdentifiers() )
+            if ( representative != null )
             {
-                if ( representativeIdentifier.getIdentifierType() != null
-                    && representativeIdentifier.getIdentifierType().isRelated() )
+                relationship = relationshipService.getRelationship( representative, patient );
+
+                for ( PatientIdentifier representativeIdentifier : representative.getIdentifiers() )
                 {
-                    identiferMap.put( representativeIdentifier.getIdentifierType().getId(),
-                        representativeIdentifier.getIdentifier() );
+                    if ( representativeIdentifier.getIdentifierType() != null
+                        && representativeIdentifier.getIdentifierType().isRelated() )
+                    {
+                        identiferMap.put( representativeIdentifier.getIdentifierType().getId(),
+                            representativeIdentifier.getIdentifier() );
+                    }
                 }
             }
 
@@ -312,8 +316,14 @@
 
             for ( PatientAttributeValue patientAttributeValue : patientAttributeValues )
             {
-                patientAttributeValueMap.put( patientAttributeValue.getPatientAttribute().getId(),
-                    patientAttributeValue.getValue() );
+                String value = patientAttributeValue.getValue();
+                if ( patientAttributeValue.getPatientAttribute().getValueType().equals( PatientAttribute.TYPE_AGE ) )
+                {
+                    Date date = format.parseDate( value );
+                    value = PatientAttribute.getAgeFromDate( date ) + "";
+                }
+
+                patientAttributeValueMap.put( patientAttributeValue.getPatientAttribute().getId(), value );
             }
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java	2013-12-18 08:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java	2013-12-19 04:00:58 +0000
@@ -37,6 +37,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 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;
@@ -83,6 +84,8 @@
 
     private OrganisationUnitSelectionManager selectionManager;
 
+    private I18nFormat format;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -198,6 +201,11 @@
 
                 if ( StringUtils.isNotBlank( value ) )
                 {
+                    if ( attribute.getValueType().equals( PatientAttribute.TYPE_AGE ) )
+                    {
+                        value = format.formatDate( PatientAttribute.getDateFromAge( Integer.parseInt( value ) ) );
+                    }
+
                     attributeValue = patientAttributeValueService.getPatientAttributeValue( patient, attribute );
 
                     if ( attributeValue == null )
@@ -263,6 +271,11 @@
         this.userService = userService;
     }
 
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
     public void setHealthWorker( Integer healthWorker )
     {
         this.healthWorker = healthWorker;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-12-18 08:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-12-19 04:00:58 +0000
@@ -80,31 +80,33 @@
 						<td class='text-column'><label>$encoder.htmlEncode($attribute.displayName) #if($attribute.mandatory) <em title="$i18n.getString( 'required' )" class="required">*</em> #end</label></td>
 						<td class="input-column">
 							#if( $attribute.valueType == "bool" )
-								<select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit"> 
+								<select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$attribute.mandatory}" > 
 									<option value="" selected="selected">[$i18n.getString( "please_select" )]</option>
 									<option value="true" #if($value=='true') selected #end>$i18n.getString( "yes" )</option>
 									<option value="false" #if($value=='false') selected #end>$i18n.getString( "no" )</option>
 								</select>                
 							#elseif( $attribute.valueType == "trueOnly" )
-								<input type='checkbox' value="true" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" #if($value=='true') checked #end> 
+								<input type='checkbox' value="true" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" #if($value=='true') checked #end class="{validate:{required:$attribute.mandatory}" > 
 							#elseif( $attribute.valueType == "date" )
-								<input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class=' #validate( "default"  $attribute.mandatory )'/>
+								<input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class="{validate:{required:$attribute.mandatory}" />
 								<script type="text/javascript">
 									datePickerValid( 'attr$attribute.id', false, false );
 								</script>                    
 							#elseif( $attribute.valueType == "combo" )  
-								<select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class='#validate( "default"  $attribute.mandatory )'>
+								<select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$attribute.mandatory}" >
 									<option value="">[$i18n.getString( "please_select" )]</option>
 									#foreach ($option in $attribute.attributeOptions )
 										<option value="$option.id" #if("$value"=="$option.name") selected #end>$option.name</option>
 									#end
 								</select>
 							#elseif( $attribute.valueType == "phoneNumber" ) 
-								<input type='text' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{phone:true}}"/>
+								<input type='text' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{phone:true,required:$attribute.mandatory}}}"/>
 							#elseif( $attribute.valueType == "trackerAssociate" ) 
 								<input type="checkbox" value='true' id="attr$attribute.id" name="attr$attribute.id" 
 									inherit="$!attribute.inherit" #if($value=='true') checked #end
 									onclick="toggleUnderAge(this);" class='underAge' />
+							#elseif( $attribute.valueType == "age" || $attribute.valueType == "number" ) 
+								<input type='text' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$attribute.mandatory,number:true}}"/>
 							#else 
 								<input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class="{validate:{required:$attribute.mandatory #if($attribute.valueType=='NUMBER'),number:true #end }}" />
 							#end

=== 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	2013-12-18 08:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientAttributeForm.vm	2013-12-19 04:00:58 +0000
@@ -48,6 +48,7 @@
                 <option value="date">$i18n.getString( "date" )</option>
                 <option value="phoneNumber">$i18n.getString( "phone_number" )</option>
                 <option value="trackerAssociate">$i18n.getString( "tracker_associate" )</option>
+                <option value="age">$i18n.getString( "age" )</option>
                 <option value="combo">$i18n.getString( "attribute_combo_type" )</option>
             </select>
         </td>

=== 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	2013-12-18 08:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm	2013-12-19 04:00:58 +0000
@@ -50,7 +50,8 @@
                 <option value="trueOnly" #if( $patientAttribute.valueType == 'trueOnly' ) selected="selected" #end >$i18n.getString( "yes_only" )</option>
 				<option value="date" #if( $patientAttribute.valueType == 'date' ) selected="selected" #end>$i18n.getString( "date" )</option>
                 <option value="phoneNumber" #if( $patientAttribute.valueType == 'phoneNumber' ) selected="selected" #end>$i18n.getString( "phone_number" )</option>
-				 <option value="trackerAssociate" #if( $patientAttribute.valueType == 'trackerAssociate' ) selected="selected" #end>$i18n.getString( "tracker_associate" )</option>
+				<option value="trackerAssociate" #if( $patientAttribute.valueType == 'trackerAssociate' ) selected="selected" #end>$i18n.getString( "tracker_associate" )</option>
+				<option value="age" #if( $patientAttribute.valueType == 'age' ) selected="selected" #end>$i18n.getString( "age" )</option>
 				<option value="combo" #if( $patientAttribute.valueType == 'combo' ) selected="selected" #end>$i18n.getString( "attribute_combo_type" )</option>
             </select>
         </td>