dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20922
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9774: Improve validation rules in case entry form.
------------------------------------------------------------
revno: 9774
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-02-08 15:58:33 +0700
message:
Improve validation rules in case entry form.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramExpressionService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java
dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.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-api/src/main/java/org/hisp/dhis/program/ProgramExpressionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramExpressionService.java 2012-11-09 04:05:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramExpressionService.java 2013-02-08 08:58:33 +0000
@@ -28,31 +28,32 @@
package org.hisp.dhis.program;
import java.util.Collection;
+import java.util.Map;
import org.hisp.dhis.i18n.I18nFormat;
-
/**
* @author Chau Thu Tran
- *
+ *
* @version ProgramExpressionService.java 2:59:58 PM Nov 8, 2012 $
*/
public interface ProgramExpressionService
{
String ID = ProgramExpressionService.class.getName();
-
- int addProgramExpression(ProgramExpression programExpression );
-
- void updateProgramExpression(ProgramExpression programExpression );
-
- void deleteProgramExpression ( ProgramExpression programExpression );
-
+
+ int addProgramExpression( ProgramExpression programExpression );
+
+ void updateProgramExpression( ProgramExpression programExpression );
+
+ void deleteProgramExpression( ProgramExpression programExpression );
+
ProgramExpression getProgramExpression( int id );
-
+
Collection<ProgramExpression> getAllProgramExpressions();
-
- String getProgramExpressionValue( ProgramExpression programExpression, ProgramStageInstance programStageInstance, I18nFormat format );
-
+
+ String getProgramExpressionValue( ProgramExpression programExpression, ProgramStageInstance programStageInstance,
+ Map<String, String> patientDataValueMap );
+
String getExpressionDescription( String programExpression );
-
+
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java 2012-11-12 07:04:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java 2013-02-08 08:58:33 +0000
@@ -55,6 +55,6 @@
Collection<ProgramValidation> getProgramValidation( ProgramStageDataElement psdataElement );
- ProgramValidationResult validate( ProgramValidation validation,
- ProgramStageInstance programStageInstance, I18nFormat format );
+ Collection<ProgramValidationResult> validate( Collection<ProgramValidation> validation,
+ ProgramStageInstance programStageInstance );
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2013-01-24 04:15:05 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2013-02-08 08:58:33 +0000
@@ -512,7 +512,7 @@
private String addProvidedElsewherCheckbox( String appendCode, PatientDataValue patientDataValue,
ProgramStage programStage )
{
- String id = "$PROGRAMSTAGEID_$DATAELEMENTID_facility";
+ String id = "$PROGRAMSTAGEID-$DATAELEMENTID-facility";
appendCode += "<div id=\"span_"
+ id
+ "\" class=\"provided-elsewhere\"><input name=\"providedByAnotherFacility\" title=\"is provided by another Facility ?\" id=\""
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java 2013-01-23 10:27:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java 2013-02-08 08:58:33 +0000
@@ -32,15 +32,15 @@
import static org.hisp.dhis.program.ProgramExpression.SEPARATOR_OBJECT;
import java.util.Collection;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hisp.dhis.common.GenericStore;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.patientdatavalue.PatientDataValue;
import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.system.util.DateUtils;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -125,16 +125,16 @@
@Override
public String getProgramExpressionValue( ProgramExpression programExpression,
- ProgramStageInstance programStageInstance, I18nFormat format )
+ ProgramStageInstance programStageInstance, Map<String, String> patientDataValueMap )
{
String value = "";
if ( ProgramExpression.DUE_DATE.equals( programExpression.getExpression() ) )
{
- value = format.formatDate( programStageInstance.getDueDate() );
+ value = DateUtils.getMediumDateString( programStageInstance.getDueDate() );
}
else if ( ProgramExpression.REPORT_DATE.equals( programExpression.getExpression() ) )
{
- value = format.formatDate( programStageInstance.getExecutionDate() );
+ value = DateUtils.getMediumDateString( programStageInstance.getExecutionDate() );
}
else
{
@@ -144,16 +144,16 @@
Matcher matcher = pattern.matcher( programExpression.getExpression() );
while ( matcher.find() )
{
- String match = matcher.group();
+ String key = matcher.group().replaceAll( "[\\[\\]]", "" ).split( SEPARATOR_OBJECT )[1];
- PatientDataValue dataValue = getPatientDataValue( match, programStageInstance );
+ String dataValue = patientDataValueMap.get( key );
if ( dataValue == null )
{
return null;
}
- matcher.appendReplacement( description, dataValue.getValue() );
+ matcher.appendReplacement( description, dataValue );
}
matcher.appendTail( description );
@@ -189,7 +189,8 @@
return INVALID_CONDITION;
}
- matcher.appendReplacement( description, programStage.getDisplayName() + SEPARATOR_ID + dataElement.getName() );
+ matcher.appendReplacement( description,
+ programStage.getDisplayName() + SEPARATOR_ID + dataElement.getName() );
}
matcher.appendTail( description );
@@ -197,22 +198,4 @@
return description.toString();
}
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private PatientDataValue getPatientDataValue( String expression, ProgramStageInstance programStageInstance )
- {
- expression = expression.replaceAll( "[\\[\\]]", "" );
-
- String[] info = expression.split( SEPARATOR_OBJECT );
- String[] ids = info[1].split( SEPARATOR_ID );
-
- int dataElementId = Integer.parseInt( ids[1] );
- DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
- PatientDataValue dataValue = patientDataValueService.getPatientDataValue( programStageInstance, dataElement );
-
- return dataValue;
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java 2012-11-12 07:04:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java 2013-02-08 08:58:33 +0000
@@ -33,14 +33,18 @@
import static org.hisp.dhis.program.ProgramExpression.SEPARATOR_OBJECT;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValueService;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -62,6 +66,8 @@
private ProgramExpressionService expressionService;
+ private PatientDataValueService patientDataValueService;
+
// -------------------------------------------------------------------------
// Setters
// -------------------------------------------------------------------------
@@ -71,6 +77,11 @@
this.validationStore = validationStore;
}
+ public void setPatientDataValueService( PatientDataValueService patientDataValueService )
+ {
+ this.patientDataValueService = patientDataValueService;
+ }
+
public void setExpressionService( ProgramExpressionService expressionService )
{
this.expressionService = expressionService;
@@ -120,28 +131,55 @@
}
@Override
- public ProgramValidationResult validate( ProgramValidation validation, ProgramStageInstance programStageInstance,
- I18nFormat format )
+ public Collection<ProgramValidationResult> validate( Collection<ProgramValidation> validation,
+ ProgramStageInstance programStageInstance )
{
- String leftSideValue = expressionService.getProgramExpressionValue( validation.getLeftSide(),
- programStageInstance, format );
- String rightSideValue = expressionService.getProgramExpressionValue( validation.getRightSide(),
- programStageInstance, format );
- String operator = validation.getOperator().getMathematicalOperator();
-
- if ( (leftSideValue != null && rightSideValue.equals( NOT_NULL_VALUE_IN_EXPRESSION ) && rightSideValue == null)
- || ((leftSideValue != null && rightSideValue != null && !((operator.equals( "==" ) && leftSideValue
- .compareTo( rightSideValue ) == 0)
- || (operator.equals( "<" ) && leftSideValue.compareTo( rightSideValue ) < 0)
- || (operator.equals( "<=" ) && (leftSideValue.compareTo( rightSideValue ) <= 0))
- || (operator.equals( ">" ) && leftSideValue.compareTo( rightSideValue ) > 0)
- || (operator.equals( ">=" ) && leftSideValue.compareTo( rightSideValue ) >= 0) || (operator
- .equals( "!=" ) && leftSideValue.compareTo( rightSideValue ) == 0)))) )
- {
- return new ProgramValidationResult( programStageInstance, validation, leftSideValue, rightSideValue );
- }
-
- return null;
+ Collection<ProgramValidationResult> result = new HashSet<ProgramValidationResult>();
+
+ // ---------------------------------------------------------------------
+ // Get patient-data-values
+ // ---------------------------------------------------------------------
+
+ Collection<PatientDataValue> patientDataValues = patientDataValueService
+ .getPatientDataValues( programStageInstance );
+
+ Map<String, String> patientDataValueMap = new HashMap<String, String>( patientDataValues.size() );
+
+ for ( PatientDataValue patientDataValue : patientDataValues )
+ {
+ String key = patientDataValue.getProgramStageInstance().getProgramStage().getId() + "."
+ + patientDataValue.getDataElement().getId();
+ patientDataValueMap.put( key, patientDataValue.getValue() );
+ }
+
+ // ---------------------------------------------------------------------
+ // Validate rules
+ // ---------------------------------------------------------------------
+
+ for ( ProgramValidation validate : validation )
+ {
+ String leftSideValue = expressionService.getProgramExpressionValue( validate.getLeftSide(),
+ programStageInstance, patientDataValueMap );
+ String rightSideValue = expressionService.getProgramExpressionValue( validate.getRightSide(),
+ programStageInstance, patientDataValueMap );
+ String operator = validate.getOperator().getMathematicalOperator();
+
+ if ( (leftSideValue != null && rightSideValue.equals( NOT_NULL_VALUE_IN_EXPRESSION ) && rightSideValue == null)
+ || ((leftSideValue != null && rightSideValue != null && !((operator.equals( "==" ) && leftSideValue
+ .compareTo( rightSideValue ) == 0)
+ || (operator.equals( "<" ) && leftSideValue.compareTo( rightSideValue ) < 0)
+ || (operator.equals( "<=" ) && (leftSideValue.compareTo( rightSideValue ) <= 0))
+ || (operator.equals( ">" ) && leftSideValue.compareTo( rightSideValue ) > 0)
+ || (operator.equals( ">=" ) && leftSideValue.compareTo( rightSideValue ) >= 0) || (operator
+ .equals( "!=" ) && leftSideValue.compareTo( rightSideValue ) == 0)))) )
+ {
+ ProgramValidationResult validationResult = new ProgramValidationResult( programStageInstance, validate,
+ leftSideValue, rightSideValue );
+ result.add( validationResult );
+ }
+ }
+
+ return result;
}
public Collection<ProgramValidation> getProgramValidation( Program program )
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-02-04 16:14:38 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-02-08 08:58:33 +0000
@@ -233,6 +233,7 @@
<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
<property name="expressionService" ref="org.hisp.dhis.program.ProgramExpressionService" />
+ <property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
</bean>
<bean id="org.hisp.dhis.program.ProgramExpressionService" class="org.hisp.dhis.program.DefaultProgramExpressionService">
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java 2012-11-09 03:14:42 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java 2013-02-08 08:58:33 +0000
@@ -70,7 +70,7 @@
// Output
// -------------------------------------------------------------------------
- private List<ProgramValidationResult> programValidationResults;
+ private Collection<ProgramValidationResult> programValidationResults;
private Map<Integer, String> leftsideFormulaMap = new HashMap<Integer, String>();
@@ -105,7 +105,7 @@
return rightsideFormulaMap;
}
- public List<ProgramValidationResult> getProgramValidationResults()
+ public Collection<ProgramValidationResult> getProgramValidationResults()
{
return programValidationResults;
}
@@ -135,9 +135,14 @@
// Check validations for dataelement into multi-stages
// ---------------------------------------------------------------------
- runProgramValidation( programValidationService.getProgramValidation( programStageInstance.getProgramStage() ),
- programStageInstance );
+ // runProgramValidation( programValidationService.getProgramValidation(
+ // programStageInstance.getProgramStage() ),
+ // programStageInstance );
+ Collection<ProgramValidation> validation = programValidationService.getProgramValidation( programStageInstance
+ .getProgramStage() );
+ programValidationResults = programValidationService.validate( validation, programStageInstance );
+
return SUCCESS;
}
@@ -148,28 +153,31 @@
private void runProgramValidation( Collection<ProgramValidation> validations,
ProgramStageInstance programStageInstance )
{
- if ( validations != null )
- {
- for ( ProgramValidation validation : validations )
- {
- ProgramValidationResult validationResult = programValidationService.validate( validation,
- programStageInstance, format );
-
- if ( validationResult != null )
- {
- programValidationResults.add( validationResult );
-
- leftsideFormulaMap.put(
- validationResult.getProgramValidation().getId(),
- programExpressionService.getExpressionDescription( validationResult.getProgramValidation()
- .getLeftSide().getExpression() ) );
-
- rightsideFormulaMap.put(
- validationResult.getProgramValidation().getId(),
- programExpressionService.getExpressionDescription( validationResult.getProgramValidation()
- .getRightSide().getExpression() ) );
- }
- }
- }
+ // if ( validations != null )
+ // {
+ // for ( ProgramValidation validation : validations )
+ // {
+ // ProgramValidationResult validationResult =
+ // programValidationService.validate( validation,
+ // programStageInstance, format );
+ //
+ // if ( validationResult != null )
+ // {
+ // programValidationResults.add( validationResult );
+ //
+ // leftsideFormulaMap.put(
+ // validationResult.getProgramValidation().getId(),
+ // programExpressionService.getExpressionDescription(
+ // validationResult.getProgramValidation()
+ // .getLeftSide().getExpression() ) );
+ //
+ // rightsideFormulaMap.put(
+ // validationResult.getProgramValidation().getId(),
+ // programExpressionService.getExpressionDescription(
+ // validationResult.getProgramValidation()
+ // .getRightSide().getExpression() ) );
+ // }
+ // }
+ // }
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm 2013-01-24 04:15:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm 2013-02-08 08:58:33 +0000
@@ -72,7 +72,7 @@
</td>
#if( $programStage.program.displayProvidedOtherFacility=='true' )
<td style='width:20px;' align='center'>
- #set( $id = $programStageDataElement.programStage.id + '_' + $programStageDataElement.dataElement.id + '_facility' )
+ #set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-facility' )
#if( $programStageDataElement.allowProvidedElsewhere == 'true')
<input class='provided-elsewhere' name="$id" id="$id" type="checkbox" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )" #if($patientDataValue.providedElsewhere == 'true') checked #end />
#end
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2013-02-06 14:08:33 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2013-02-08 08:58:33 +0000
@@ -206,7 +206,7 @@
function ValueSaver( dataElementId_, value_, dataElementType_, resultColor_ )
{
var dataElementId = dataElementId_;
- var providedElsewhereId = getFieldValue('programStageId') + "_" + dataElementId_ + "_facility";
+ var providedElsewhereId = getFieldValue('programStageId') + "-" + dataElementId_ + "-facility";
var value = value_;
var type = dataElementType_;
var resultColor = resultColor_;
@@ -655,14 +655,16 @@
$('#validateProgramDiv' ).load( 'validateProgram.action',
function(){
$( "#loading-bar" ).dialog( "close" );
- }).dialog({
- title: i18n_violate_validation,
- maximize: true,
- closable: true,
- modal:true,
- overlay:{background:'#000000', opacity:0.1},
- width: 800,
- height: 450
+
+ $('#validateProgramDiv' ).dialog({
+ title: i18n_violate_validation,
+ maximize: true,
+ closable: true,
+ modal:true,
+ overlay:{background:'#000000', opacity:0.1},
+ width: 800,
+ height: 450
+ });
});
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm 2013-02-03 10:13:17 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm 2013-02-08 08:58:33 +0000
@@ -85,7 +85,7 @@
</td>
#if( $programStage.program.displayProvidedOtherFacility=='true' )
<td style='width:20px;' align='center'>
- #set( $id = $programStageDataElement.programStage.id + '_' + $programStageDataElement.dataElement.id + '_facility' )
+ #set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-facility' )
#if( $programStageDataElement.allowProvidedElsewhere == 'true')
<div id='span_$id' class='provided-elsewhere'>
<input class='provided-elsewhere' name="$id" id="$id" type="checkbox" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )" #if($patientDataValue.providedElsewhere == 'true') checked #end />