dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18208
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7591: [mobile] add attributes and identifiers in registration form
------------------------------------------------------------
revno: 7591
committer: Long <thanhlongngo1988@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-07-12 17:33:43 +0700
message:
[mobile] add attributes and identifiers in registration 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/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml
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-11 09:13:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2012-07-12 10:33:43 +0000
@@ -27,18 +27,35 @@
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 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.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;
public class SaveBeneficiaryAction
implements Action
@@ -71,6 +88,42 @@
this.organisationUnitService = organisationUnitService;
}
+ private PatientIdentifierTypeService patientIdentifierTypeService;
+
+ public PatientIdentifierTypeService getPatientIdentifierTypeService()
+ {
+ return patientIdentifierTypeService;
+ }
+
+ public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
+ {
+ this.patientIdentifierTypeService = patientIdentifierTypeService;
+ }
+
+ private PatientAttributeService patientAttributeService;
+
+ public PatientAttributeService getPatientAttributeService()
+ {
+ return patientAttributeService;
+ }
+
+ public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+ {
+ this.patientAttributeService = patientAttributeService;
+ }
+
+ private PatientAttributeOptionService patientAttributeOptionService;
+
+ public PatientAttributeOptionService getPatientAttributeOptionService()
+ {
+ return patientAttributeOptionService;
+ }
+
+ public void setPatientAttributeOptionService( PatientAttributeOptionService patientAttributeOptionService )
+ {
+ this.patientAttributeOptionService = patientAttributeOptionService;
+ }
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
@@ -171,12 +224,53 @@
this.dobType = dobType;
}
+ private Integer patientId;
+
+ public Integer getPatientId()
+ {
+ return patientId;
+ }
+
+ public void setPatientId( Integer patientId )
+ {
+ this.patientId = patientId;
+ }
+
+ private Collection<PatientIdentifierType> patientIdentifierTypes;
+
+ public Collection<PatientIdentifierType> getPatientIdentifierTypes()
+ {
+ return patientIdentifierTypes;
+ }
+
+ public void setPatientIdentifierTypes( Collection<PatientIdentifierType> patientIdentifierTypes )
+ {
+ this.patientIdentifierTypes = patientIdentifierTypes;
+ }
+
+ private Collection<PatientAttribute> patientAttributes;
+
+ public Collection<PatientAttribute> getPatientAttributes()
+ {
+ return patientAttributes;
+ }
+
+ public void setPatientAttributes( Collection<PatientAttribute> patientAttributes )
+ {
+ this.patientAttributes = patientAttributes;
+ }
+
@Override
public String execute()
throws Exception
{
Patient patient = new Patient();
+ Set<PatientIdentifier> patientIdentifierSet = new HashSet<PatientIdentifier>();
+ Set<PatientAttribute> patientAttributeSet = new HashSet<PatientAttribute>();
+ List<PatientAttributeValue> patientAttributeValues = new ArrayList<PatientAttributeValue>();
+ patientIdentifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
+ patientAttributes = patientAttributeService.getAllPatientAttributes();
patient.setOrganisationUnit( organisationUnitService.getOrganisationUnit( orgUnitId ) );
if ( this.patientFullName.trim().length() < 2 )
@@ -217,7 +311,7 @@
patient.setGender( gender );
patient.setRegistrationDate( new Date() );
patient.setDobType( dobType.charAt( 0 ) );
-
+
if ( dobType.equals( "A" ) )
{
try
@@ -243,6 +337,85 @@
}
}
+ 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 )
+ {
+ String key = "IDT" + patientIdentifierType.getId();
+ String value = parameterMap.get( key );
+ if ( value != null )
+ {
+ if ( patientIdentifierType.isMandatory() && value.trim().equals( "" ) )
+ {
+ this.validationMap.put( key, "is_empty" );
+ }
+ else if ( patientIdentifierType.getType().equals( "number" ) && !FormUtils.isNumber( value ) )
+ {
+ this.validationMap.put( key, "is_invalid_number" );
+ this.previousValues.put( key, value );
+ }
+ else
+ {
+ PatientIdentifier patientIdentifier = new PatientIdentifier();
+ patientIdentifier.setIdentifierType( patientIdentifierType );
+ patientIdentifier.setPatient( patient );
+ patientIdentifierSet.add( patientIdentifier );
+ patientIdentifier.setIdentifier( value.trim() );
+ }
+ }
+ }
+ }
+
+ for ( PatientAttribute patientAttribute : patientAttributeService.getAllPatientAttributes() )
+ {
+ patientAttributeSet.add( patientAttribute );
+ if ( patientAttribute.getProgram() == null )
+ {
+ String key = "AT" + patientAttribute.getId();
+ String value = parameterMap.get( key );
+ if ( value != null )
+ {
+ if ( patientAttribute.isMandatory() && value.trim().equals( "" ) )
+ {
+ this.validationMap.put( key, "is_empty" );
+ }
+ else if ( patientAttribute.getValueType().equals( PatientAttribute.TYPE_INT )
+ && !FormUtils.isInteger( value ) )
+ {
+ this.validationMap.put( key, "is_invalid_number" );
+ this.previousValues.put( key, value );
+ }
+ else if ( patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE )
+ && !FormUtils.isDate( value ) )
+ {
+ this.validationMap.put( key, "is_invalid_date" );
+ this.previousValues.put( key, value );
+ }
+ else
+ {
+ PatientAttributeValue patientAttributeValue = new PatientAttributeValue();
+ if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( patientAttribute.getValueType() ) )
+ {
+ PatientAttributeOption option = patientAttributeOptionService.get( NumberUtils.toInt(
+ value, 0 ) );
+ if ( option != null )
+ {
+ patientAttributeValue.setPatientAttributeOption( option );
+ }
+ }
+ patientAttributeValue.setPatient( patient );
+ patientAttributeValue.setPatientAttribute( patientAttribute );
+ patientAttributeValue.setValue( value.trim() );
+ patientAttributeValues.add( patientAttributeValue );
+ }
+ }
+ }
+ }
+
if ( this.validationMap.size() > 0 )
{
this.validated = false;
@@ -252,11 +425,11 @@
this.previousValues.put( "dobType", this.dobType );
return ERROR;
}
-
- patientService.savePatient( patient );
+ patient.setIdentifiers( patientIdentifierSet );
+ patient.setAttributes( patientAttributeSet );
+ patientId = patientService.createPatient( patient, null, null, patientAttributeValues );
validated = true;
return SUCCESS;
}
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-07-11 09:13:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-07-12 10:33:43 +0000
@@ -273,7 +273,10 @@
scope="prototype">
<property name="organisationUnitService"
ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
- <property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
+ <property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
+ <property name="patientIdentifierTypeService" ref="org.hisp.dhis.patient.PatientIdentifierTypeService" />
+ <property name="patientAttributeService" ref="org.hisp.dhis.patient.PatientAttributeService" />
+ <property name="patientAttributeOptionService" ref="org.hisp.dhis.patient.PatientAttributeOptionService" />
</bean>
<!-- Beneficiary Enrollment -->
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml 2012-07-11 09:13:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml 2012-07-12 10:33:43 +0000
@@ -221,7 +221,7 @@
<action name="saveBeneficiary"
class="org.hisp.dhis.light.beneficiaryregistration.action.SaveBeneficiaryAction">
- <result name="success" type="redirect">/light/showBeneficiarySearchingForm.action</result>
+ <result name="success" type="redirect">/light/selectEnrollmentProgram.action?patientId=${patientId}</result>
<result name="error" type="velocity">/dhis-web-light/main.vm</result>
<param name="page">/dhis-web-light/registration/beneficiaryRegistrationForm.vm</param>
</action>
=== 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-11 09:13:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/registration/beneficiaryRegistrationForm.vm 2012-07-12 10:33:43 +0000
@@ -67,13 +67,37 @@
<input type="text" name="dateOfBirth" value="$!previousValues.get("dob")" />
#foreach($patientIdentifierType in $patientIdentifierTypes)
- <label>$patientIdentifierType.getName()</label>
- <input type="text" name="$patientIdentifierType.getId()" value="$!previousValues.get($patientIdentifierType.getId())" />
+ #if(! $patientIdentifierType.program)
+ #set($key = "IDT${patientIdentifierType.id}")
+ <label>$patientIdentifierType.getName()#if( $patientIdentifierType.isMandatory() )*#end </label>
+ #if( $validationMap.get( $key ) )
+ <br /><span style="color: #990000;"> $i18n.getString($validationMap.get( $key ))</span>
+ #end
+ <input type="text" name="$key" value="$!previousValues.get($key)" />
+ #end
#end
#foreach($patientAttribute in $patientAttributes)
- <label>$patientAttribute.getName()</label>
- <input type="text" name="$patientAttribute.getId()" value="$!previousValues.get($patientAttribute.getId())" />
+ #if(! $patientAttribute.program)
+ #set($key = "AT${patientAttribute.id}")
+ <label>$patientAttribute.getName()#if( $patientAttribute.isMandatory() )*#end </label>
+ #if( $validationMap.get( $key ) )
+ <br /><span style="color: #990000;"> $i18n.getString($validationMap.get( $key ))</span>
+ #end
+ #if($patientAttribute.getValueType() == "COMBO")
+ <select type="text" name="$key" />
+ #foreach($option in $patientAttribute.getAttributeOptions())
+ <option value="$option.id"
+ #if( $prevDataValues.get( $option.id ) == $option.getName() )
+ selected
+ #end
+ > $option.getName() </option>
+ #end
+ </select>
+ #else
+ <input type="text" name="$key" value="$!previousValues.get($key)" />
+ #end
+ #end
#end