dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19248
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8312: [mobile] apply validation rule for program stage form
------------------------------------------------------------
revno: 8312
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Mon 2012-10-01 11:36:31 +0700
message:
[mobile] apply validation rule for program stage form
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.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/META-INF/dhis/beans.xml
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/namebased/programStageForm.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-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java 2012-09-22 12:23:40 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java 2012-10-01 04:36:31 +0000
@@ -32,7 +32,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-
import org.hisp.dhis.caseentry.state.SelectedStateManager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.PatientAttribute;
=== 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-16 08:15:37 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java 2012-10-01 04:36:31 +0000
@@ -27,6 +27,16 @@
package org.hisp.dhis.light.namebaseddataentry.action;
+import static org.hisp.dhis.program.ProgramValidation.AFTER_CURRENT_DATE;
+import static org.hisp.dhis.program.ProgramValidation.AFTER_DUE_DATE;
+import static org.hisp.dhis.program.ProgramValidation.AFTER_OR_EQUALS_TO_CURRENT_DATE;
+import static org.hisp.dhis.program.ProgramValidation.AFTER_OR_EQUALS_TO_DUE_DATE;
+import static org.hisp.dhis.program.ProgramValidation.BEFORE_CURRENT_DATE;
+import static org.hisp.dhis.program.ProgramValidation.BEFORE_DUE_DATE;
+import static org.hisp.dhis.program.ProgramValidation.BEFORE_DUE_DATE_PLUS_OR_MINUS_MAX_DAYS;
+import static org.hisp.dhis.program.ProgramValidation.BEFORE_OR_EQUALS_TO_CURRENT_DATE;
+import static org.hisp.dhis.program.ProgramValidation.BEFORE_OR_EQUALS_TO_DUE_DATE;
+
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
@@ -38,19 +48,26 @@
import org.hisp.dhis.api.mobile.model.ProgramStage;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.light.utils.NamebasedUtils;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patientdatavalue.PatientDataValueService;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageDataElementService;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
import org.hisp.dhis.program.ProgramStageService;
+import org.hisp.dhis.program.ProgramValidation;
+import org.hisp.dhis.program.ProgramValidationService;
import org.hisp.dhis.util.ContextUtils;
-
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -147,6 +164,42 @@
this.programStageDataElementService = programStageDataElementService;
}
+ private PatientDataValueService patientDataValueService;
+
+ public PatientDataValueService getPatientDataValueService()
+ {
+ return patientDataValueService;
+ }
+
+ public void setPatientDataValueService( PatientDataValueService patientDataValueService )
+ {
+ this.patientDataValueService = patientDataValueService;
+ }
+
+ private ProgramValidationService programValidationService;
+
+ public ProgramValidationService getProgramValidationService()
+ {
+ return programValidationService;
+ }
+
+ public void setProgramValidationService( ProgramValidationService programValidationService )
+ {
+ this.programValidationService = programValidationService;
+ }
+
+ private ProgramStageInstanceService programStageInstanceService;
+
+ public ProgramStageInstanceService getProgramStageInstanceService()
+ {
+ return programStageInstanceService;
+ }
+
+ public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+ {
+ this.programStageInstanceService = programStageInstanceService;
+ }
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
@@ -290,6 +343,46 @@
this.patient = patient;
}
+ private List<ProgramValidation> programValidations;
+
+ public List<ProgramValidation> getProgramValidations()
+ {
+ return programValidations;
+ }
+
+ public void setProgramValidations( List<ProgramValidation> programValidations )
+ {
+ this.programValidations = programValidations;
+ }
+
+ private Map<Integer, String> leftsideFormulaMap;
+
+ public Map<Integer, String> getLeftsideFormulaMap()
+ {
+ return leftsideFormulaMap;
+ }
+
+ public void setLeftsideFormulaMap( Map<Integer, String> leftsideFormulaMap )
+ {
+ this.leftsideFormulaMap = leftsideFormulaMap;
+ }
+
+ private Map<Integer, String> rightsideFormulaMap;
+
+ public Map<Integer, String> getRightsideFormulaMap()
+ {
+ return rightsideFormulaMap;
+ }
+
+ public void setRightsideFormulaMap( Map<Integer, String> rightsideFormulaMap )
+ {
+ this.rightsideFormulaMap = rightsideFormulaMap;
+ }
+
+ private I18n i18n;
+
+ private I18nFormat format;
+
@Override
public String execute()
throws Exception
@@ -363,11 +456,13 @@
}
}
+ // Check type violation
if ( !typeViolations.isEmpty() )
{
return ERROR;
}
+ // Save patient data value
ActivityValue activityValue = new ActivityValue();
activityValue.setDataValues( dataValues );
activityValue.setProgramInstanceId( programStageInstanceId );
@@ -375,12 +470,26 @@
try
{
activityReportingService.saveActivityReport( organisationUnit, activityValue );
- } catch ( NotAllowedException e )
+ }
+ catch ( NotAllowedException e )
{
e.printStackTrace();
return ERROR;
}
+ // Check validation rule
+ ProgramStageInstance programStageInstance = programStageInstanceService
+ .getProgramStageInstance( programStageInstanceId );
+ programValidations = new ArrayList<ProgramValidation>();
+ this.runProgramValidation(
+ programValidationService.getProgramValidation( programStageInstance.getProgramStage() ),
+ programStageInstance );
+
+ if ( programValidations.size() > 0 )
+ {
+ return ERROR;
+ }
+
if ( dhisProgramStage.getIrregular() )
{
return REGISTER_NEXT_DUEDATE;
@@ -395,4 +504,102 @@
return SUCCESS_AND_BACK_TO_PROGRAMSTAGE;
}
}
+
+ private void runProgramValidation( Collection<ProgramValidation> validations,
+ ProgramStageInstance programStageInstance )
+ {
+ if ( validations != null )
+ {
+ for ( ProgramValidation validation : validations )
+ {
+ boolean valid = programValidationService.runValidation( validation, programStageInstance, format );
+ if ( !valid )
+ {
+ programValidations.add( validation );
+ validation.getDescription();
+ }
+ }
+ }
+
+ if ( !programValidations.isEmpty() )
+ {
+ leftsideFormulaMap = new HashMap<Integer, String>( programValidations.size() );
+ rightsideFormulaMap = new HashMap<Integer, String>( programValidations.size() );
+
+ for ( ProgramValidation validation : programValidations )
+ {
+ leftsideFormulaMap.put( validation.getId(),
+ programValidationService.getValidationDescription( validation.getLeftSide() ) );
+
+ if ( validation.getDateType() )
+ {
+ String rightSide = validation.getRightSide();
+ int index = rightSide.indexOf( 'D' );
+ if ( index < 0 )
+ {
+ int rightValidation = Integer.parseInt( rightSide );
+
+ switch ( rightValidation )
+ {
+ case BEFORE_CURRENT_DATE:
+ rightsideFormulaMap.put( validation.getId(), i18n.getString( "before_current_date" ) );
+ break;
+ case BEFORE_OR_EQUALS_TO_CURRENT_DATE:
+ rightsideFormulaMap.put( validation.getId(),
+ i18n.getString( "before_or_equals_to_current_date" ) );
+ break;
+ case AFTER_CURRENT_DATE:
+ rightsideFormulaMap.put( validation.getId(), i18n.getString( "after_current_date" ) );
+ break;
+ case AFTER_OR_EQUALS_TO_CURRENT_DATE:
+ rightsideFormulaMap.put( validation.getId(),
+ i18n.getString( "after_or_equals_to_current_date" ) );
+ break;
+ case BEFORE_DUE_DATE:
+ rightsideFormulaMap.put( validation.getId(), i18n.getString( "before_due_date" ) );
+ break;
+ case BEFORE_OR_EQUALS_TO_DUE_DATE:
+ rightsideFormulaMap.put( validation.getId(),
+ i18n.getString( "before_or_equals_to_due_date" ) );
+ break;
+ case AFTER_DUE_DATE:
+ rightsideFormulaMap.put( validation.getId(), i18n.getString( "after_due_date" ) );
+ break;
+ case AFTER_OR_EQUALS_TO_DUE_DATE:
+ rightsideFormulaMap
+ .put( validation.getId(), i18n.getString( "after_or_equals_to_due_date" ) );
+ break;
+ default:
+ rightsideFormulaMap.put( validation.getId(), "" );
+ break;
+
+ }
+ }
+ else
+ {
+ int rightValidation = Integer.parseInt( rightSide.substring( 0, index ) );
+
+ int daysValue = Integer.parseInt( rightSide.substring( index + 1, rightSide.length() ) );
+
+ if ( rightValidation == BEFORE_DUE_DATE_PLUS_OR_MINUS_MAX_DAYS )
+ {
+ rightsideFormulaMap.put(
+ validation.getId(),
+ i18n.getString( "in_range_due_date_plus_or_minus" ) + " " + daysValue
+ + i18n.getString( "days" ) );
+ }
+ }
+ }
+ else if ( validation.getRightSide().equals( "1==1" ) )
+ {
+ rightsideFormulaMap.put( validation.getId(), "" );
+ }
+ else
+ {
+ rightsideFormulaMap.put( validation.getId(),
+ programValidationService.getValidationDescription( validation.getRightSide() ) );
+ }
+ }
+ }
+ }
}
=== 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-09-28 08:13:37 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-10-01 04:36:31 +0000
@@ -174,6 +174,8 @@
ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
<property name="programStageDataElementService" ref="org.hisp.dhis.program.ProgramStageDataElementService" />
+ <property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+ <property name="programValidationService" ref="org.hisp.dhis.program.ProgramValidationService" />
</bean>
<bean
@@ -206,6 +208,7 @@
ref="org.hisp.dhis.relationship.RelationshipTypeService" />
<property name="util" ref="org.hisp.dhis.light.utils.NamebasedUtils" />
<property name="patientIdentifierService" ref="org.hisp.dhis.patient.PatientIdentifierService" />
+
</bean>
<bean
=== 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-09-28 09:17:17 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties 2012-10-01 04:36:31 +0000
@@ -123,3 +123,4 @@
visit_schedule_type=Visit Schedule Type
or_register_new_person=or register new person
invalid_phone_number=invalid phone number
+save_any_way=Save anyway
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm 2012-07-13 09:18:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm 2012-10-01 04:36:31 +0000
@@ -1,12 +1,17 @@
<h2>$encoder.htmlEncode( $programStage.name )</h2>
#set( $typeViolationsSize = $typeViolations.size() )
+#set( $programViolationsSize = $programValidations.size() )
-#if( $typeViolationsSize > 0 )
+#if( $typeViolationsSize > 0 || $programViolationsSize > 0)
<div class="header-box" align="center">
<h3 style="text-align: left; background-color: #990000; color: white;">$i18n.getString("warnings_and_errors")</h3>
<p style="text-align: left;">
- $typeViolationsSize $i18n.getString("type_violation_errors"). <br />
+ #if ($typeViolationsSize > 0)$typeViolationsSize $i18n.getString("type_violation_errors"). <br /> #end
+ #foreach($programValidation in $programValidations)
+ $programValidation.description. <br/>
+ #end
+ #if ($programViolationsSize > 0 && $typeViolationsSize == 0) <a href="showPatientProgramList.action?patientId=${patientId}">$i18n.getString("save_any_way")</a> #end
</p>
</div>
#end