=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/GetProgramEnrollmentFormAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/GetProgramEnrollmentFormAction.java 2012-06-27 10:03:43 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/GetProgramEnrollmentFormAction.java 2012-10-03 07:23:08 +0000 @@ -28,9 +28,12 @@ package org.hisp.dhis.light.beneficiaryenrollment.action; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.Date; import org.hisp.dhis.patient.Patient; +import org.hisp.dhis.patient.PatientAttribute; +import org.hisp.dhis.patient.PatientIdentifierType; import org.hisp.dhis.patient.PatientService; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramService; @@ -109,10 +112,8 @@ } private Program program; - + private String now; - - public String getNow() { @@ -124,13 +125,39 @@ this.now = now; } + private Collection patientIdentifierTypes; + + public Collection getPatientIdentifierTypes() + { + return patientIdentifierTypes; + } + + public void setPatientIdentifierTypes( Collection patientIdentifierTypes ) + { + this.patientIdentifierTypes = patientIdentifierTypes; + } + + private Collection patientAttributes; + + public Collection getPatientAttributes() + { + return patientAttributes; + } + + public void setPatientAttributes( Collection patientAttributes ) + { + this.patientAttributes = patientAttributes; + } + @Override public String execute() throws Exception { patient = patientService.getPatient( patientId ); program = programService.getProgram( programId ); - now = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + patientAttributes = program.getPatientAttributes(); + patientIdentifierTypes = program.getPatientIdentifierTypes(); + now = new SimpleDateFormat( "yyyy-MM-dd" ).format( new Date() ); return SUCCESS; } === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java 2012-08-16 15:47:08 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java 2012-10-03 07:23:08 +0000 @@ -1,12 +1,27 @@ package org.hisp.dhis.light.beneficiaryenrollment.action; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; +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.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.PatientIdentifierService; +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.patientattributevalue.PatientAttributeValueService; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramInstance; import org.hisp.dhis.program.ProgramInstanceService; @@ -15,10 +30,11 @@ import org.hisp.dhis.program.ProgramStageInstance; import org.hisp.dhis.program.ProgramStageInstanceService; import org.hisp.dhis.system.util.DateUtils; +import org.hisp.dhis.util.ContextUtils; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; - import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionContext; public class SaveMobileProgramEnrollmentAction implements Action @@ -68,6 +84,66 @@ this.formUtils = formUtils; } + private PatientIdentifierTypeService patientIdentifierTypeService; + + public PatientIdentifierTypeService getPatientIdentifierTypeService() + { + return patientIdentifierTypeService; + } + + public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService ) + { + this.patientIdentifierTypeService = patientIdentifierTypeService; + } + + private PatientIdentifierService patientIdentifierService; + + public PatientIdentifierService getPatientIdentifierService() + { + return patientIdentifierService; + } + + public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService ) + { + this.patientIdentifierService = patientIdentifierService; + } + + 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; + } + + private PatientAttributeValueService patientAttributeValueService; + + public PatientAttributeValueService getPatientAttributeValueService() + { + return patientAttributeValueService; + } + + public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService ) + { + this.patientAttributeValueService = patientAttributeValueService; + } + // ------------------------------------------------------------------------- // Input/Output // ------------------------------------------------------------------------- @@ -165,9 +241,43 @@ this.validated = validated; } + private Collection patientIdentifierTypes; + + public Collection getPatientIdentifierTypes() + { + return patientIdentifierTypes; + } + + public void setPatientIdentifierTypes( Collection patientIdentifierTypes ) + { + this.patientIdentifierTypes = patientIdentifierTypes; + } + + private Collection patientAttributes; + + public Collection getPatientAttributes() + { + return patientAttributes; + } + + public void setPatientAttributes( Collection patientAttributes ) + { + this.patientAttributes = patientAttributes; + } + public String execute() throws Exception { + patient = patientService.getPatient( patientId ); + program = programService.getProgram( programId ); + patientAttributes = program.getPatientAttributes(); + patientIdentifierTypes = program.getPatientIdentifierTypes(); + + List patientAttributeValues = new ArrayList(); + + HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get( + ServletActionContext.HTTP_REQUEST ); + Map parameterMap = ContextUtils.getParameterMap( request ); DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay(); if ( !FormUtils.isDate( enrollmentDate ) ) @@ -180,6 +290,99 @@ validationMap.put( "incidentDate", "is_invalid_date" ); } + // Handle Attribute and Identifier + + for ( PatientIdentifierType patientIdentifierType : patientIdentifierTypes ) + { + { + String key = "IDT" + patientIdentifierType.getId(); + String value = parameterMap.get( key ); + + PatientIdentifier duplicateId = null; + + if ( !value.isEmpty() ) + { + duplicateId = patientIdentifierService.get( patientIdentifierType, value ); + } + + if ( value != null ) + { + if ( patientIdentifierType.isMandatory() && value.trim().equals( "" ) ) + { + this.validationMap.put( key, "is_mandatory" ); + } + else if ( patientIdentifierType.getType().equals( "number" ) && !FormUtils.isNumber( value ) ) + { + this.validationMap.put( key, "is_invalid_number" ); + } + else if ( duplicateId != null ) + { + this.validationMap.put( key, "is_duplicate" ); + } + else + { + PatientIdentifier patientIdentifier = new PatientIdentifier(); + patientIdentifier.setIdentifierType( patientIdentifierType ); + patientIdentifier.setPatient( patient ); + patientIdentifier.setIdentifier( value.trim() ); + patient.getIdentifiers().add( patientIdentifier ); + } + + this.previousValues.put( key, value ); + } + } + } + + for ( PatientAttribute patientAttribute : patientAttributes ) + { + { + String key = "AT" + patientAttribute.getId(); + String value = parameterMap.get( key ).trim(); + + if ( value != null ) + { + if ( patientAttribute.isMandatory() && value.trim().equals( "" ) ) + { + this.validationMap.put( key, "is_mandatory" ); + } + else if ( value.trim().length() > 0 + && patientAttribute.getValueType().equals( PatientAttribute.TYPE_INT ) + && !FormUtils.isInteger( value ) ) + { + this.validationMap.put( key, "is_invalid_number" ); + } + else if ( value.trim().length() > 0 + && patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE ) + && !FormUtils.isDate( value ) ) + { + this.validationMap.put( key, "is_invalid_date" ); + } + 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 ); + } + + this.previousValues.put( key, value ); + } + } + } + if ( validationMap.size() > 0 ) { previousValues.put( "enrollmentDate", enrollmentDate ); @@ -188,9 +391,8 @@ return ERROR; } - patient = patientService.getPatient( patientId ); - - program = programService.getProgram( programId ); + this.saveAttributeValue( patientAttributeValues ); + patientService.updatePatient( patient ); Collection programInstances = programInstanceService.getProgramInstances( patient, program, false ); @@ -247,8 +449,18 @@ programStageInstanceService.updateProgramStageInstance( programStageInstance ); } } + validated = true; return SUCCESS; } + private void saveAttributeValue( List patientAttributeValues ) + { + for ( PatientAttributeValue patientAttributeValue : patientAttributeValues ) + { + patientAttributeValueService.savePatientAttributeValue( patientAttributeValue ); + } + + } + } === 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-09-27 06:54:00 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2012-10-03 07:23:08 +0000 @@ -452,8 +452,8 @@ PatientIdentifier patientIdentifier = new PatientIdentifier(); patientIdentifier.setIdentifierType( patientIdentifierType ); patientIdentifier.setPatient( patient ); + patientIdentifier.setIdentifier( value.trim() ); patientIdentifierSet.add( patientIdentifier ); - patientIdentifier.setIdentifier( value.trim() ); } this.previousValues.put( key, value ); === 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-10-01 04:36:31 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-10-03 07:23:08 +0000 @@ -350,6 +350,14 @@ ref="org.hisp.dhis.program.ProgramStageInstanceService" /> + + + + === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/enrollment/programEnrollmentForm.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/enrollment/programEnrollmentForm.vm 2012-07-16 07:58:15 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/enrollment/programEnrollmentForm.vm 2012-10-03 07:23:08 +0000 @@ -12,8 +12,44 @@ #if( $validationMap.get( "incidentDate" ) )
$i18n.getString($validationMap.get( "incidentDate" )) - #end - + #end + + + #foreach($patientIdentifierType in $patientIdentifierTypes) + #set($key = "IDT${patientIdentifierType.id}") + + #if( $validationMap.get( $key ) ) +
$i18n.getString($validationMap.get( $key )) + #end + + + #end + + #foreach($patientAttribute in $patientAttributes) + #set($key = "AT${patientAttribute.id}") + + #if( $validationMap.get( $key ) ) +
$i18n.getString($validationMap.get( $key )) + #end + #if($patientAttribute.getValueType() == "COMBO") + + #elseif( $patientAttribute.getValueType() == "YES/NO" ) + + #else + + #end + #end