dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39186
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19867: program rule support for TEI attributes
------------------------------------------------------------
revno: 19867
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-08-27 12:06:06 +0200
message:
program rule support for TEI attributes
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programrule/GetProgramRuleAction.java
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/ProgramRuleAction.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java 2015-08-26 18:14:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java 2015-08-27 10:06:06 +0000
@@ -202,9 +202,9 @@
this.dataElement = dataElement;
}
- @JsonProperty( "trackedEntityAttribute" )
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( localName = "trackedEntityAttribute", namespace = DxfNamespaces.DXF_2_0 )
+ @JsonProperty
+ @JsonSerialize( as = BaseIdentifiableObject.class )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public TrackedEntityAttribute getAttribute()
{
return attribute;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programrule/GetProgramRuleAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programrule/GetProgramRuleAction.java 2015-04-11 13:18:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programrule/GetProgramRuleAction.java 2015-08-27 10:06:06 +0000
@@ -27,9 +27,10 @@
*/
package org.hisp.dhis.trackedentity.action.programrule;
-import java.util.ArrayList;
import java.util.List;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.programrule.ProgramRule;
import org.hisp.dhis.programrule.ProgramRuleService;
import org.hisp.dhis.programrule.ProgramRuleVariable;
@@ -55,6 +56,9 @@
@Autowired
private ProgramRuleVariableService variableService;
+
+ @Autowired
+ private ProgramService programService;
// -------------------------------------------------------------------------
// Input/Output
@@ -73,6 +77,13 @@
{
return programRule;
}
+
+ private Program program;
+
+ public Program getProgram()
+ {
+ return program;
+ }
private List<ProgramRuleVariable> ruleVariables;
@@ -90,8 +101,10 @@
throws Exception
{
programRule = programRuleService.getProgramRule( id );
-
- ruleVariables = new ArrayList<>( variableService.getProgramRuleVariable( programRule.getProgram() ));
+
+ program = programService.getProgram( programRule.getProgram().getId() );
+
+ ruleVariables = variableService.getProgramRuleVariable( program );
return SUCCESS;
}
=== 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-06-23 09:02:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramRule.vm 2015-08-27 10:06:06 +0000
@@ -36,6 +36,13 @@
var i18n_please_enter_alert_message_when_hiding_a_field = '$encoder.jsEscape( $i18n.getString( "please_enter_alert_message_when_hiding_a_field_that_contains_value" ) , "'")';
var i18n_please_enter_alert_message_when_hiding_a_section = '$encoder.jsEscape( $i18n.getString( "please_enter_alert_message_when_hiding_a_section_that_contains_values" ) , "'")';
var i18n_hide_section = '$encoder.jsEscape( $i18n.getString( "hide_section" ) , "'" )';
+ var i18n_data_element_label = '$encoder.jsEscape( $i18n.getString( "data_element" ) , "'" )';
+ var i18n_program_attribute_label = '$encoder.jsEscape( $i18n.getString( "program_attribute" ) , "'" )';
+
+ var attributeList = new Array();
+ #foreach( $programAttribute in $program.programAttributes )
+ attributeList['$programAttribute.attribute.uid'] = '$programAttribute.attribute.displayName';
+ #end
var sectionSelector = "<select class='actionSections' >";
#foreach( $programStage in $program.programStages )
@@ -94,19 +101,32 @@
<col width="50%" />
#set($idx = 0 )
#foreach($ruleVariable in $ruleVariables)
- #set( $json_Data='{"name":"' + $ruleVariable.name + '"'
+ #if( $ruleVariable.sourceType == 'TEI_ATTRIBUTE')
+ #set( $json_Data='{"name":"' + $ruleVariable.name + '"'
+ + ',"sourceType":"' + $ruleVariable.sourceType + '"'
+ + ',"trackedEntityAttribute":{ "id":"' + $ruleVariable.trackedEntityAttribute.id + '"}'
+ + ',"program":{"id":"' + $ruleVariable.program.id + '"}}' )
+ #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" + '"}}' )
+ #end
+
#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:150px;' onclick='insertVariable(this)'/></td>
+ <tr class="$clazz" jsonData='$json_Data' id="$ruleVariable.uid">
+ #if( $ruleVariable.sourceType == 'TEI_ATTRIBUTE')
+ <td>$!encoder.htmlEncode($ruleVariable.trackedEntityAttribute) $!encoder.htmlEncode($ruleVariable.trackedEntityAttribute.displayName)</td>
+ <td><input type='button' teAttId='$ruleVariable.trackedEntityAttribute.uid' realValue='$ruleVariable.name' value='#{$ruleVariable.name}' style='width:150px;' onclick='insertVariable(this)'/> <strong>[ATT]</strong></td>
+ #else
+ <td>$!encoder.htmlEncode($ruleVariable.dataElement.displayName)</td>
+ <td><input type='button' deId='$ruleVariable.dataElement.uid' realValue='$ruleVariable.name' value='#{$ruleVariable.name}' style='width:150px;' onclick='insertVariable(this)'/> <strong>[DE]</strong></td>
+ #end
</tr>
#end
</table>
=== 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-08-07 15:49:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programRule.js 2015-08-27 10:06:06 +0000
@@ -65,7 +65,10 @@
$("#sourceFieldList tr").each(function(){
var deName = $(this).find('td:first').html();
var deId = $(this).find('input').attr("deId");
- program_DataElements[deId] = deName;
+ if(deId){
+ program_DataElements[deId] = deName;
+ }
+
});
$("#programRuleVariableDiv #dataElementId option").each(function () {
@@ -317,6 +320,7 @@
function addProgramRule()
{
+ console.log('trying to save program rule');
lockScreen();
var json_Data = {
"name": getFieldValue('name'),
@@ -337,6 +341,7 @@
,contentType: "application/json"
,data: JSON.stringify(json_Data)
,success: function(data){
+ console.log('data: ', data);
if( data.response && data.response.lastImported ){
saveProgramRuleVariable();
saveAction( data.response.lastImported );
@@ -369,17 +374,26 @@
function saveAction( programRuleId )
{
+ console.log('trying to save action..');
$("#actionTB tr").each(function(){
var row = $(this);
var json_Data = {
"programRuleActionType": row.find(".actionList").val(),
- "programRule":{ "id":programRuleId },
- "dataElement":{ "id": row.find(".actionDEs").val() },
- "programStageSection":{ "id": row.find(".actionSections").val() },
+ "programRule":{ "id":programRuleId },
"content": row.find(".content").val()
- }
-
- var actionId = $(this).attr('id');
+ };
+
+ var key = row.find(".actionDEs").val();
+
+ if(attributeList[key]){
+ json_Data.attribute = {id: key};
+ }
+ else{
+ json_Data.dataElement = {id: key};
+ json_Data.programStageSection = {id: row.find(".actionSections").val() };
+ }
+
+ var actionId = $(this).attr('id');
var actionMethod = ( actionId === undefined ) ? "POST" : "PUT";
var url = ( actionId === undefined ) ? "../api/programRuleActions/" : "../api/programRuleActions/" + actionId;
@@ -402,7 +416,7 @@
if( status == 1 )
{
status = 0;
- window.location.href='programRule.action?id=' + getFieldValue('programLocalId');
+ //window.location.href='programRule.action?id=' + getFieldValue('programLocalId');
}
});
@@ -447,13 +461,21 @@
}
function addMoreAction()
-{
+{
var table = $("#actionTB");
var dataElementSelector = "<select class='actionDEs' style='width:100%;' >";
+ dataElementSelector += "<optgroup label='" + i18n_data_element_label + "'>";
for( var i in program_DataElements )
{
dataElementSelector += "<option value='" + i + "'>" + program_DataElements[i] + "</option>";
}
+ dataElementSelector += "</optgroup>";
+ dataElementSelector += "<optgroup label='" + i18n_program_attribute_label + "'>";
+ for( var key in attributeList)
+ {
+ dataElementSelector += "<option value='" + key + "'>" + attributeList[key] + "</option>";
+ }
+ dataElementSelector += "</optgroup>";
dataElementSelector += "</select>";
var clazz = "class='listAlternateRow'";
=== 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-07-07 11:49:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramRule.vm 2015-08-27 10:06:06 +0000
@@ -36,6 +36,13 @@
var i18n_please_enter_alert_message_when_hiding_a_field = '$encoder.jsEscape( $i18n.getString( "please_enter_alert_message_when_hiding_a_field_that_contains_value" ) , "'")';
var i18n_please_enter_alert_message_when_hiding_a_section = '$encoder.jsEscape( $i18n.getString( "please_enter_alert_message_when_hiding_a_section_that_contains_values" ) , "'")';
var i18n_hide_section = '$encoder.jsEscape( $i18n.getString( "hide_section" ) , "'" )';
+ var i18n_data_element_label = '$encoder.jsEscape( $i18n.getString( "data_element" ) , "'" )';
+ var i18n_program_attribute_label = '$encoder.jsEscape( $i18n.getString( "program_attribute" ) , "'" )';
+
+ var attributeList = new Array();
+ #foreach( $programAttribute in $program.programAttributes )
+ attributeList['$programAttribute.attribute.uid'] = '$programAttribute.attribute.displayName';
+ #end
var sectionSelector = "<select class='actionSections' >";
#foreach( $programStage in $programRule.program.programStages )
@@ -109,7 +116,7 @@
<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>
+ <td><input type='button' teAttId='$ruleVariable.trackedEntityAttribute.uid' realValue='$ruleVariable.name' value='#{$ruleVariable.name}' style='width:100%;' onclick='insertVariable(this)'/></td>
</tr>
#else
#set( $json_Data='{"name":"' + $ruleVariable.name + '"'
@@ -176,6 +183,13 @@
#end
#set($idx = $idx + 1 )
+ #set( $actionFieldName = $action.dataElement.displayName )
+ #if( !$actionFieldName )
+ #set( $actionFieldName = $action.attribute.name )
+ Hi
+ $!encoder.htmlEncode( $actionFieldName )
+ #end
+
<tr $clazz id="$action.uid">
<td>
<select class='actionList' style='width:100%' onchange="actionListToggle(this)">
@@ -188,8 +202,12 @@
<td><input type='text' class='content' style='width:97%;' value='$!encoder.htmlEncode( $action.content )'/></td>
<td>
<span class="deCell" #if($action.programRuleActionType=='HIDESECTION') style='display:none;' #end>
- <select class='actionDEs' style='width:100%;'>
- <option value="$programRule.dataElement.uid">$!encoder.htmlEncode( $action.dataElement.displayName )</option>
+ <select style='width:100%;'>
+ #if( $action.dataElement && $action.dataElement.displayName != 'undefined')
+ <option class='actionDEs' value="$action.dataElement.uid">$!encoder.htmlEncode( $action.dataElement.displayName )</option>
+ #else
+ <option class='actionDEs' value="$action.attribute.uid">$!encoder.htmlEncode( $action.attribute.displayName )</option>
+ #end
</select>
</span>