dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18236
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7617: (mobile) fixed bug for number attributes of zero length (were validated as numbers, which would a...
------------------------------------------------------------
revno: 7617
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-07-16 11:15:37 +0300
message:
(mobile) fixed bug for number attributes of zero length (were validated as numbers, which would always fail)
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/namebaseddataentry/action/SaveProgramStageFormAction.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/registration/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-07-13 09:18:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2012-07-16 08:15:37 +0000
@@ -27,35 +27,21 @@
package org.hisp.dhis.light.beneficiaryregistration.action;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.servlet.http.HttpServletRequest;
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.light.utils.FormUtils;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.patient.Patient;
-import org.hisp.dhis.patient.PatientAttribute;
-import org.hisp.dhis.patient.PatientAttributeOption;
-import org.hisp.dhis.patient.PatientAttributeOptionService;
-import org.hisp.dhis.patient.PatientAttributeService;
-import org.hisp.dhis.patient.PatientIdentifier;
-import org.hisp.dhis.patient.PatientIdentifierType;
-import org.hisp.dhis.patient.PatientIdentifierTypeService;
-import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patient.*;
import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
import org.hisp.dhis.util.ContextUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
-import com.opensymphony.xwork2.Action;
-import com.opensymphony.xwork2.ActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
public class SaveBeneficiaryAction
implements Action
@@ -317,8 +303,7 @@
try
{
patient.setBirthDateFromAge( Integer.parseInt( dateOfBirth ), Patient.AGE_TYPE_YEAR );
- }
- catch ( NumberFormatException nfe )
+ } catch ( NumberFormatException nfe )
{
validationMap.put( "dob", "is_invalid_number" );
}
@@ -330,8 +315,7 @@
DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay();
DateTime date = sdf.parseDateTime( dateOfBirth );
patient.setBirthDate( date.toDate() );
- }
- catch ( Exception e )
+ } catch ( Exception e )
{
validationMap.put( "dob", "is_invalid_date" );
}
@@ -340,7 +324,7 @@
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
ServletActionContext.HTTP_REQUEST );
Map<String, String> parameterMap = ContextUtils.getParameterMap( request );
-
+
for ( PatientIdentifierType patientIdentifierType : patientIdentifierTypeService.getAllPatientIdentifierTypes() )
{
if ( patientIdentifierType.getProgram() == null )
@@ -376,19 +360,20 @@
if ( patientAttribute.getProgram() == null )
{
String key = "AT" + patientAttribute.getId();
- String value = parameterMap.get( key );
+ String value = parameterMap.get( key ).trim();
+
if ( value != null )
{
if ( patientAttribute.isMandatory() && value.trim().equals( "" ) )
{
this.validationMap.put( key, "is_empty" );
}
- else if ( patientAttribute.getValueType().equals( PatientAttribute.TYPE_INT )
+ else if ( value.trim().length() > 0 && patientAttribute.getValueType().equals( PatientAttribute.TYPE_INT )
&& !FormUtils.isInteger( value ) )
{
this.validationMap.put( key, "is_invalid_number" );
}
- else if ( patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE )
+ else if ( value.trim().length() > 0 && patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE )
&& !FormUtils.isDate( value ) )
{
this.validationMap.put( key, "is_invalid_date" );
@@ -396,6 +381,7 @@
else
{
PatientAttributeValue patientAttributeValue = new PatientAttributeValue();
+
if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( patientAttribute.getValueType() ) )
{
PatientAttributeOption option = patientAttributeOptionService.get( NumberUtils.toInt(
@@ -405,11 +391,13 @@
patientAttributeValue.setPatientAttributeOption( option );
}
}
+
patientAttributeValue.setPatient( patient );
patientAttributeValue.setPatientAttribute( patientAttribute );
patientAttributeValue.setValue( value.trim() );
patientAttributeValues.add( patientAttributeValue );
}
+
this.previousValues.put( key, value );
}
}
@@ -424,6 +412,7 @@
this.previousValues.put( "dobType", this.dobType );
return ERROR;
}
+
patient.setIdentifiers( patientIdentifierSet );
patient.setAttributes( patientAttributeSet );
patientId = patientService.createPatient( patient, null, null, patientAttributeValues );
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java 2012-07-13 09:18:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java 2012-07-16 08:15:37 +0000
@@ -27,11 +27,8 @@
package org.hisp.dhis.light.namebaseddataentry.action;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.api.mobile.ActivityReportingService;
import org.hisp.dhis.api.mobile.NotAllowedException;
@@ -51,8 +48,12 @@
import org.hisp.dhis.program.ProgramStageDataElementService;
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.util.ContextUtils;
-import com.opensymphony.xwork2.Action;
-import com.opensymphony.xwork2.ActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class SaveProgramStageFormAction
implements Action
@@ -305,7 +306,7 @@
programStage = util.getProgramStage( programId, programStageId );
program = programStageService.getProgramStage( programStageId ).getProgram();
org.hisp.dhis.program.ProgramStage dhisProgramStage = programStageService.getProgramStage( programStageId );
-
+
patient = patientService.getPatient( patientId );
dataElements = programStage.getDataElements();
@@ -342,6 +343,7 @@
{
typeViolations.put( key, typeViolation );
}
+
prevDataValues.put( key, value );
}
else if ( valueIsEmpty && programStageDataElement.isCompulsory() )
@@ -373,8 +375,7 @@
try
{
activityReportingService.saveActivityReport( organisationUnit, activityValue );
- }
- catch ( NotAllowedException e )
+ } catch ( NotAllowedException e )
{
e.printStackTrace();
return ERROR;
=== 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-07-15 07:10:03 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties 2012-07-16 08:15:37 +0000
@@ -56,7 +56,7 @@
details_for=Detail For
organisation_unit=Organisation Unit
beneficiary_registration=Person Registration
-full_name=FullName
+full_name=Full Name
male=Male
female=Female
transgender=Transgender
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/registration/beneficiaryRegistrationForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/registration/beneficiaryRegistrationForm.vm 2012-07-15 07:10:03 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/registration/beneficiaryRegistrationForm.vm 2012-07-16 08:15:37 +0000
@@ -59,8 +59,8 @@
#end
>$i18n.getString( "verified" )</option>
</select>
-
- <label>$i18n.getString( "date_of_birth" )</label>
+
+ <label>$i18n.getString( "date_of_birth" )*</label>
#if( $validationMap.get( "dob" ) )
<br /><span style="color: #990000;"> $i18n.getString($validationMap.get( "dob" ))</span>
#end
@@ -76,7 +76,7 @@
<input type="text" name="$key" value="$!previousValues.get($key)" />
#end
#end
-
+
#foreach($patientAttribute in $patientAttributes)
#if(! $patientAttribute.program)
#set($key = "AT${patientAttribute.id}")