dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16874
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6543: [mobile] validate beneficiary form
------------------------------------------------------------
revno: 6543
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Wed 2012-04-11 16:59:20 +0700
message:
[mobile] validate beneficiary form
modified:
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java
dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties
dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/beneficiaryRegistrationForm.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-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2012-04-10 06:49:47 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2012-04-11 09:59:20 +0000
@@ -27,6 +27,9 @@
package org.hisp.dhis.light.beneficiaryregistration.action;
+import java.util.HashMap;
+import java.util.Map;
+
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientService;
@@ -130,9 +133,9 @@
{
this.dateOfBirth = dateOfBirth;
}
-
+
public boolean validated;
-
+
public boolean isValidated()
{
return validated;
@@ -143,6 +146,30 @@
this.validated = validated;
}
+ public Map<String, String> validationMap = new HashMap<String, String>();
+
+ public Map<String, String> getValidationMap()
+ {
+ return validationMap;
+ }
+
+ public void setValidationMap( Map<String, String> validationMap )
+ {
+ this.validationMap = validationMap;
+ }
+
+ public Map<String, String> previousValues = new HashMap<String, String>();
+
+ public Map<String, String> getPreviousValues()
+ {
+ return previousValues;
+ }
+
+ public void setPreviousValues( Map<String, String> previousValues )
+ {
+ this.previousValues = previousValues;
+ }
+
@Override
public String execute()
throws Exception
@@ -151,32 +178,49 @@
patient.setOrganisationUnit( organisationUnitService.getOrganisationUnit( Integer.parseInt( orgUnitId ) ) );
- String[] tokens = this.patientFullName.split( " " );
-
- patient.setFirstName( tokens[0] );
-
- if ( tokens.length == 2 )
+ if ( this.patientFullName.trim().equals( "" ) )
{
- patient.setLastName( tokens[1] );
+ validationMap.put( "fullName", "is_empty" );
}
- else if ( tokens.length > 2 )
+ else
{
- patient.setMiddleName( tokens[1] );
- patient.setLastName( tokens[2] );
+ String[] tokens = this.patientFullName.split( " " );
+
+ patient.setFirstName( tokens[0] );
+
+ if ( tokens.length == 2 )
+ {
+ patient.setLastName( tokens[1] );
+ }
+ else if ( tokens.length > 2 )
+ {
+ patient.setMiddleName( tokens[1] );
+ patient.setLastName( tokens[2] );
+ }
}
patient.setGender( gender );
patient.setBloodGroup( bloodGroup );
- DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay();
- DateTime date = sdf.parseDateTime( dateOfBirth );
try
{
+ DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay();
+ DateTime date = sdf.parseDateTime( dateOfBirth );
patient.setBirthDate( date.toDate() );
}
catch ( Exception e )
{
- e.printStackTrace();
+ validationMap.put( "dob", "is_invalid_date" );
+ }
+
+ if ( this.validationMap.size() > 0 )
+ {
+ this.validated = false;
+ this.previousValues.put( "fullName", this.patientFullName );
+ this.previousValues.put( "gender", this.gender );
+ this.previousValues.put( "bloodGroup", this.bloodGroup );
+ this.previousValues.put( "dob", this.dateOfBirth );
+ return SUCCESS;
}
patientService.savePatient( patient );
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2012-04-07 10:23:28 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2012-04-11 09:59:20 +0000
@@ -161,12 +161,13 @@
// -------------------------------------------------------------------------
@SuppressWarnings( "unchecked" )
- public Map<String, DeflatedDataValue> getValidationViolations( OrganisationUnit organisationUnit, Collection<DataElement> dataElements,
- Period period )
+ public Map<String, DeflatedDataValue> getValidationViolations( OrganisationUnit organisationUnit,
+ Collection<DataElement> dataElements, Period period )
{
Map<String, DeflatedDataValue> validationErrorMap = new HashMap<String, DeflatedDataValue>();
- Collection<MinMaxDataElement> minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit, dataElements );
+ Collection<MinMaxDataElement> minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit,
+ dataElements );
Collection<DeflatedDataValue> deflatedDataValues;
if ( minmaxs == null )
@@ -310,7 +311,8 @@
try
{
Double.parseDouble( value );
- } catch ( NumberFormatException e )
+ }
+ catch ( NumberFormatException e )
{
return false;
}
@@ -323,7 +325,8 @@
try
{
Integer.parseInt( value );
- } catch ( NumberFormatException e )
+ }
+ catch ( NumberFormatException e )
{
return false;
}
@@ -353,7 +356,8 @@
{
return true;
}
- } catch ( NumberFormatException e )
+ }
+ catch ( NumberFormatException e )
{
}
@@ -372,7 +376,8 @@
{
return true;
}
- } catch ( NumberFormatException e )
+ }
+ catch ( NumberFormatException e )
{
}
@@ -392,7 +397,8 @@
{
sdf.parseDateTime( value );
return true;
- } catch ( IllegalArgumentException e )
+ }
+ catch ( IllegalArgumentException e )
{
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties 2012-04-10 06:49:47 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties 2012-04-11 09:59:20 +0000
@@ -58,4 +58,5 @@
full_name=FullName
male=Male
female=Female
-transgender=Transgender
\ No newline at end of file
+transgender=Transgender
+is_empty=Empty Field
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/beneficiaryRegistrationForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/beneficiaryRegistrationForm.vm 2012-04-10 06:49:47 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/beneficiaryRegistrationForm.vm 2012-04-11 09:59:20 +0000
@@ -13,26 +13,49 @@
<input type="hidden" name="orgUnitId" value="$orgUnitId"/>
<p style="text-align: left;">
<label>$i18n.getString( "full_name" )</label>
- <input type="text" name="patientFullName" value="$!prevDataValues.get($key)" />
+ #if( $validationMap.get( "fullName" ) )
+ <br /><span style="color: #990000;"> $i18n.getString($validationMap.get( "fullName" ))</span>
+ #end
+ <input type="text" name="patientFullName" value="$!previousValues.get("fullName")" />
+
<label>$i18n.getString( "gender" )</label>
<select name="gender">
- <option value="M">$i18n.getString( "male" )</option>
- <option value="F">$i18n.getString( "female" )</option>
- <option value="T">$i18n.getString( "transgender" )</option>
+ <option value="M"
+ #if($previousValues.get("gender") == "M")
+ selected
+ #end
+ >$i18n.getString( "male" )</option>
+
+ <option value="F"
+ #if($previousValues.get("gender") == "F")
+ selected
+ #end
+ >$i18n.getString( "female" )</option>
+
+ <option value="T"
+ #if($previousValues.get("gender") == "T")
+ selected
+ #end
+ >$i18n.getString( "transgender" )</option>
</select>
+
<label>$i18n.getString( "date_of_birth" )</label>
- <input type="text" name="dateOfBirth" value="$!prevDataValues.get($key)" />
+ #if( $validationMap.get( "dob" ) )
+ <br /><span style="color: #990000;"> $i18n.getString($validationMap.get( "dob" ))</span>
+ #end
+ <input type="text" name="dateOfBirth" value="$!previousValues.get("dob")" />
+
<label>$i18n.getString( "blood_group" )</label>
<select name="bloodGroup">
<option value="">[Please select]</option>
- <option value="A+">A+</option>
- <option value="A-">A-</option>
- <option value="AB+">AB+</option>
- <option value="AB-">AB-</option>
- <option value="B+">B+</option>
- <option value="B-">B-</option>
- <option value="O+">O+</option>
- <option value="O-">O-</option>
+ #set($bloodGroups = ["A+", "A-", "AB+", "AB-", "B+", "B-", "O+", "O-"])
+ #foreach($item in $bloodGroups)
+ <option value="$item"
+ #if($previousValues.get("bloodGroup") == $item)
+ selected
+ #end
+ >$item</option>
+ #end
</select>
</p>
</div>