← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19497: Support for tracked entity attributes as variables in Add/Update Program Rule form.

 

------------------------------------------------------------
revno: 19497
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-23 16:02:05 +0700
message:
  Support for tracked entity attributes as variables in Add/Update Program Rule form.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariable.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramRule.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programRule.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramRule.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/programrule/ProgramRuleVariable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariable.java	2015-05-13 02:28:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariable.java	2015-06-23 09:02:05 +0000
@@ -69,7 +69,7 @@
      * within the current event. dataelement_previous_event Get a specific
      * data elements value, specifically from the event preceding the current
      * event, if this exists. calculated_value Do not assign the variable a
-     * hard-linked source, it will be populated by rules with “assignvariable”
+     * hard-linked source, it will be populated by rules with assignvariable
      * actions(i.e. calculation rules). tei_attribute Get a specific attribute
      * from the current tracked entity. the linked attribute will be used to
      * lookup the attributes uID value.
@@ -89,7 +89,7 @@
      * <ul>
      * <li>dataelement_newest_event_program_stage</li>
      * <li>dataelement_newest_event_program</li>
-     * <li>dataelement_current_event</li>
+     * <li>dataelement_current_even</li>
      * </ul>
      */
     private DataElement dataElement;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties	2015-06-19 10:59:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties	2015-06-23 09:02:05 +0000
@@ -546,4 +546,5 @@
 expression_items=Expression items
 filter_items=Filter items
 filter_description=Filter description
-select_program_stage=Select program stage
\ No newline at end of file
+select_program_stage=Select program stage
+tei_attribute = Tracked entity attribute
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramRule.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramRule.vm	2015-05-24 15:56:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramRule.vm	2015-06-23 09:02:05 +0000
@@ -180,10 +180,11 @@
 				<select type="" id="sourceType" name="sourceType" onchange="sourceTypeOnChange()" style="width:250px;">
 					<option value="DATAELEMENT_NEWEST_EVENT_PROGRAM">$i18n.getString("data_element_newest_event_program")</option>
 					<option value="DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE">$i18n.getString("data_element_newest_event_program_stage")</option>
+					<option value="TEI_ATTRIBUTE">$i18n.getString("tei_attribute")</option>
 				</select>
 			</td>
 		</td>
-		<tr>
+		<tr name="deSourceType">
 			<td>$i18n.getString('source_program_stage')</td>
 			<td>
 				<select type="" id="programStageId" disabled style="width:250px;" onchange="getDataElementsByStage();">
@@ -194,7 +195,7 @@
 				</select>
 			</td>
 		</td>
-		<tr>
+		<tr name="deSourceType">
 			<td>$i18n.getString('source_dataElement') <em title="$i18n.getString( "required" )" class="required">*</em></td>
 			<td>
 				<select type="" id="dataElementId" style="width:250px;">
@@ -207,6 +208,18 @@
 				<span style="color:red;display:none;" id="dataElementIdError" ></span>
 			</td>
 		</td>
+		
+		<tr name="teiAttrSourceType" style='display:none'>
+			<td>$i18n.getString('tei_attribute') <em title="$i18n.getString( "required" )" class="required">*</em></td>
+			<td>
+				<select type="" id="attributeId" style="width:250px;">
+					#foreach( $programAttribute in $program.programAttributes )
+						<option value="$programAttribute.attribute.uid">$programAttribute.attribute.displayName</option>
+					#end
+				</select>
+				<span style="color:red;display:none;" id="attributeIdError" ></span>
+			</td>
+		</td>
 		<tr>
 			<td>$i18n.getString('variable_name') <em title="$i18n.getString( "required" )" class="required">*</em></td>
 			<td><input type="text" id="variableName" name="variableName" style="width:247px;" onkeypress="return variableNameKeyPress(event)" />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programRule.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programRule.js	2015-05-24 15:56:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programRule.js	2015-06-23 09:02:05 +0000
@@ -158,6 +158,49 @@
 
 function addProgramRuleVariable()
 {
+	var sourceType = getFieldValue('sourceType');
+	
+	if( sourceType == 'TEI_ATTRIBUTE' ){
+		addProgramRuleAttrVariable();
+	}
+	else{
+		addProgramRuleDEVariable();
+	}
+}
+
+function addProgramRuleAttrVariable()
+{
+	var attributeId = getFieldValue('programRuleVariableDiv #attributeId');
+	var variableName = getFieldValue('variableName');
+	if( validateVariable( attributeId, variableName ) )
+	{	
+		hideById('variableNameError');
+		
+		var sourceType = getFieldValue('sourceType');
+		var programStageId = getFieldValue('programStageId');
+		var attributeName = $('#attributeId option:selected').text();
+		var json_Data = getAttrVariableJson( variableName, sourceType, attributeId );
+		
+		var clazz = "listAlternateRow";
+		if( $("#sourceFieldList tr").length % 2 == 0 )
+		{
+			clazz = "listRow";
+		}
+			
+		var row = "<tr class='" + clazz + " newVariable' jsonData='" + json_Data + "'><td>" + attributeName + "</td><td>" + addAttrVariableButton( variableName, attributeId ) +"</td></tr>";
+		$("#sourceFieldList").append(row);
+		
+		// Remove the data element from Add the Source field form. This data was used, so cannot be used for any variables.
+		
+		$('#programRuleVariableDiv #attributeId option[value="' + attributeId + '"]').remove();		
+		$("#programRuleVariableDiv").dialog("close");
+	}
+	
+}
+
+
+function addProgramRuleDEVariable()
+{
 	var dataElementId = getFieldValue('programRuleVariableDiv #dataElementId');
 	var variableName = getFieldValue('variableName');
 	if( validateVariable( dataElementId, variableName ) )
@@ -167,7 +210,7 @@
 		var sourceType = getFieldValue('sourceType');
 		var programStageId = getFieldValue('programStageId');
 		var dataElementName = $('#dataElementId option:selected').text();
-		var json_Data = getVariableJson( variableName, sourceType, dataElementId, programStageId );
+		var json_Data = getDEVariableJson( variableName, sourceType, dataElementId, programStageId );
 		
 		var clazz = "listAlternateRow";
 		if( $("#sourceFieldList tr").length % 2 == 0 )
@@ -175,7 +218,7 @@
 			clazz = "listRow";
 		}
 			
-		var row = "<tr class='" + clazz + " newVariable' jsonData='" + json_Data + "'><td>" + dataElementName + "</td><td>" + addVariableButton( variableName, dataElementId ) +"</td></tr>";
+		var row = "<tr class='" + clazz + " newVariable' jsonData='" + json_Data + "'><td>" + dataElementName + "</td><td>" + addDEVariableButton( variableName, dataElementId ) +"</td></tr>";
 		$("#sourceFieldList").append(row);
 		
 		// Remove the data element from Add the Source field form. This data was used, so cannot be used for any variables.
@@ -186,17 +229,23 @@
 	
 }
 
-function addVariableButton( name, deId )
+function addDEVariableButton( name, deId )
 {
 	return "<input type='button' deId='" + deId + "' realValue='" + name + "' value='#{" + name + "}' style='width:100%;' onclick='insertVariable(this)'/>";
 }
 
+function addAttrVariableButton( name, attributeId )
+{
+	return "<input type='button' attributeId='" + attributeId + "' realValue='" + name + "' value='A{" + name + "}' style='width:100%;' onclick='insertVariable(this)'/>";
+}
+
+
 function insertVariable(_this)
 {
 	insertTextCommon('condition', _this.value + " "); 
 }
 
-function getVariableJson( variableName, sourceType, dataElementId, programStageId )
+function getDEVariableJson( variableName, sourceType, dataElementId, programStageId )
 {
 	var json_Data = '{ '
 		+ '"name": "' + variableName + '",'
@@ -209,6 +258,19 @@
 	return json_Data;
 }
 
+
+function getAttrVariableJson( variableName, sourceType, attributeId )
+{
+	var json_Data = '{ '
+		+ '"name": "' + variableName + '",'
+		+ '"programRuleVariableSourceType": "' +  sourceType + '",'
+		+ '"trackedEntityAttribute": { "id" : "' + attributeId + '"},'
+		+ '"program": { "id" :"' + getFieldValue("programId") + '"}'
+	+ '}';
+	
+	return json_Data;
+}
+
 function closeVariableForm()
 {
 	$("#programRuleVariableDiv").dialog("close");
@@ -232,12 +294,14 @@
 {
 	status = 0; 
 	var valid = true;
-	$("#actionTB tr").find(".content").each(function(){
-		if( $(this).val() == "" )
+	$("#actionTB tr").find(".actionList").each(function(){
+		var sourceType = $(this).val();
+		var contentCell = $(this).closest("tr").find(".content");
+		if( contentCell.val() == "" && sourceType.indexOf("HIDE") < 0 )
 		{
-			var message = $(this).closest('tr').find('.actionList option:selected').attr("errorMessage");
-			$(this).css('background-color', 'pink');
-			$(this).attr('placeholder', message);
+			var message = $(this).find('option:selected').attr("errorMessage");
+			contentCell.css('background-color', 'pink');
+			contentCell.attr('placeholder', message);
 			unLockScreen();
 			valid = false;
 			return;
@@ -353,9 +417,19 @@
 	if( sourceType == "DATAELEMENT_NEWEST_EVENT_PROGRAM" ){
 		setFieldValue( "programStageId", "" );
 		disable("programStageId");
+		$("[name='deSourceType']").show();
+		$("[name='teiAttrSourceType']").hide();		
 	}
-	else{
+	else if( sourceType == "DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE" ){
 		enable("programStageId");
+		$("[name='deSourceType']").show();
+		$("[name='teiAttrSourceType']").hide();	
+	}
+	else if( sourceType == "TEI_ATTRIBUTE" ){
+		setFieldValue( "programStageId", "" );
+		disable("programStageId");
+		$("[name='deSourceType']").hide();
+		$("[name='teiAttrSourceType']").show();	
 	}
 }
 
@@ -388,9 +462,9 @@
 	}
 	var row = "<tr " + clazz + ">"
 			+ "<td><select class='actionList' style='width:100%' onchange='actionListToggle(this)'>"
+			+ "	<option value='HIDEFIELD' errorMessage='" + i18n_please_enter_alert_message_when_hiding_a_field + "' >" + i18n_hide_field + "</option>"
+			+ "	<option value='SHOWWARNING' errorMessage='" + i18n_please_enter_warning_message + "' >" + i18n_show_warning + "</option>"
 			+ "	<option value='SHOWERROR' errorMessage='" + i18n_please_enter_error_message + "' >" + i18n_show_error + "</option>"
-			+ "	<option value='SHOWWARNING' errorMessage='" + i18n_please_enter_warning_message + "' >" + i18n_show_warning + "</option>"
-			+ "	<option value='HIDEFIELD' errorMessage='" + i18n_please_enter_alert_message_when_hiding_a_field + "' >" + i18n_hide_field + "</option>"
 			+ "	<option value='HIDESECTION' errorMessage='" + i18n_please_enter_alert_message_when_hiding_a_section + "' >" + i18n_hide_section + "</option>"
 			+ "</select>"
 			+ "</td>"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramRule.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramRule.vm	2015-05-24 15:56:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramRule.vm	2015-06-23 09:02:05 +0000
@@ -95,20 +95,34 @@
 						<col width="50%" />
 						#set($idx = 0 )
 						#foreach($ruleVariable in $ruleVariables)
-							#set( $json_Data='{"name":"' + $ruleVariable.name + '"'
-								+ ',"sourceType":"' + $ruleVariable.sourceType + '"'
-								+ ',"dataElement":{ "id":"' + $ruleVariable.dataElement.id + '"}'
-								+ ',"program":{"id":"' + $ruleVariable.program.id + '"}'
-								+ ',"programStage":{"id":"' + "$!ruleVariable.programStage.id" + '"}}' )
 							#set($clazz = "listAlternateRow")
 							#if( $idx % 2 == 0 )
 								#set($clazz = "listRow")
 							#end		
 							#set($idx = $idx + 1 )
-							<tr class="$clazz" jsonData='$json_Data' id="$ruleVariable.uid">
-								<td>$!encoder.htmlEncode($ruleVariable.dataElement.displayName)</td>
-								<td><input type='button' deId='$ruleVariable.dataElement.uid' realValue='$ruleVariable.name' value='#{$ruleVariable.name}' style='width:100%;' onclick='insertVariable(this)'/></td>
-							</tr>
+							
+							#if( $ruleVariable.sourceType == "TEI_ATTRIBUTE" )
+								#set( $json_Data='{"name":"' + $ruleVariable.name + '"'
+									+ ',"sourceType":"' + $ruleVariable.sourceType + '"'
+									+ ',"trackedEntityAttribute":{ "id":"' + $ruleVariable.dataElement.id + '"}'
+									+ ',"program":{"id":"' + "$!ruleVariable.program.id" + '"}}' )
+								
+								<tr class="$clazz" jsonData='$json_Data' id="$ruleVariable.uid">
+									<td>$!encoder.htmlEncode($ruleVariable.attribute.displayName)</td>
+									<td><input type='button' deId='$ruleVariable.attribute.uid' realValue='$ruleVariable.name' value='#{$ruleVariable.name}' style='width:100%;' onclick='insertVariable(this)'/></td>
+								</tr>
+							#else
+								#set( $json_Data='{"name":"' + $ruleVariable.name + '"'
+									+ ',"sourceType":"' + $ruleVariable.sourceType + '"'
+									+ ',"dataElement":{ "id":"' + $ruleVariable.dataElement.id + '"}'
+									+ ',"program":{"id":"' + $ruleVariable.program.id + '"}'
+									+ ',"programStage":{"id":"' + "$!ruleVariable.programStage.id" + '"}}' )
+								
+								<tr class="$clazz" jsonData='$json_Data' id="$ruleVariable.uid">
+									<td>$!encoder.htmlEncode($ruleVariable.dataElement.displayName)</td>
+									<td><input type='button' deId='$ruleVariable.dataElement.uid' realValue='$ruleVariable.name' value='#{$ruleVariable.name}' style='width:100%;' onclick='insertVariable(this)'/></td>
+								</tr>
+							#end
 						#end
 					</table>
 				</div>
@@ -223,10 +237,11 @@
 				<select type="" id="sourceType" name="sourceType" onchange="sourceTypeOnChange()" style="width:250px;">
 					<option value="DATAELEMENT_NEWEST_EVENT_PROGRAM">$i18n.getString("data_element_newest_event_program")</option>
 					<option value="DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE">$i18n.getString("data_element_newest_event_program_stage")</option>
+					<option value="TEI_ATTRIBUTE">$i18n.getString("tei_attribute")</option>
 				</select>
 			</td>
 		</td>
-		<tr>
+		<tr name="deSourceType">
 			<td>$i18n.getString('source_program_stage')</td>
 			<td>
 				<select type="" id="programStageId" disabled style="width:250px;" onchange="getDataElementsByStage();">
@@ -237,7 +252,7 @@
 				</select>
 			</td>
 		</td>
-		<tr>
+		<tr name="deSourceType">
 			<td>$i18n.getString('source_dataElement') <em title="$i18n.getString( "required" )" class="required">*</em></td>
 			<td>
 				<select type="" id="dataElementId" style="width:250px;">
@@ -256,6 +271,18 @@
 			<span style="color:red;display:none;" id="variableNameError" ></span></td>
 		</td>
 		
+		<tr name="teiAttrSourceType" style='display:none'>
+			<td>$i18n.getString('tei_attribute') <em title="$i18n.getString( "required" )" class="required">*</em></td>
+			<td>
+				<select type="" id="attributeId" style="width:250px;">
+					#foreach( $programAttribute in $program.programAttributes )
+						<option value="$programAttribute.attribute.uid">$programAttribute.attribute.displayName</option>
+					#end
+				</select>
+				<span style="color:red;display:none;" id="attributeIdError" ></span>
+			</td>
+		</td>
+		
 		<tr>
 			<td></td>
 			<td>