← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18597: Partly merged branch lp:~folkehelsa/dhis2/folkehelsa from Markus. Adds objects, stores and servic...

 

------------------------------------------------------------
revno: 18597
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-03-13 09:24:36 +0100
message:
  Partly merged branch lp:~folkehelsa/dhis2/folkehelsa from Markus. Adds objects, stores and services for ProgramRule, ProgramRuleAction, ProgramRuleVariable.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRule.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariable.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableSourceType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleActionSchemaDescriptor.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleSchemaDescriptor.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleVariableSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleActionService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleVariableService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionDeletionHandler.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleDeletionHandler.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableDeletionHandler.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleActionStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleVariableStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRule.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleAction.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleVariable.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleStoreTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableStoreTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleActionController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleVariableController.java
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.filters.js


--
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
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRule.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRule.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRule.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,219 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+
+/**
+ * @author markusbekken
+ */
+
+public class ProgramRule
+    extends BaseIdentifiableObject
+{
+    private static final long serialVersionUID = -2807997671779497354L;
+    
+    /**
+     * The program that the rule belongs to
+     */
+    private Program program;
+    
+    /**
+     * The program that the rule belongs to
+     */
+    private String description;
+    
+    /**
+     * The programStage that the rule belongs to
+     */
+    private ProgramStage programStage;
+    
+    /**
+     * The collection of actions that will be triggered if the the rule is triggered.
+     */
+    private Set<ProgramRuleAction> programRuleActions;
+
+    /**
+     * The condition expression, if this expression is evaluated to true, the actions is triggered.
+     */
+    private String condition;
+
+    /**
+     * The priority of the rule within the program. The lower the priority, the earlier the rule is run.
+     * Null means that the rule is run last(together will all other null-rules)
+     */
+    private Integer priority;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public ProgramRule()
+    {
+        this.setAutoFields();
+        this.programRuleActions = new HashSet<ProgramRuleAction>();
+    }
+    
+    public ProgramRule( String name, String description, Program program, ProgramStage programStage, Set<ProgramRuleAction> programRuleActions, String condition, Integer priority )
+    {
+        this();
+        this.name = name;
+        this.setDescription( description );
+        this.program = program;
+        this.programStage = programStage;
+        this.programRuleActions = programRuleActions;
+        this.condition = condition;
+        this.priority = priority;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Program getProgram()
+    {
+        return program;
+    }
+
+    public void setProgram( Program program )
+    {
+        this.program = program;
+    }
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ProgramStage getProgramStage()
+    {
+        return programStage;
+    }
+
+    public void setProgramStage( ProgramStage programStage )
+    {
+        this.programStage = programStage;
+    }
+    
+    @JsonProperty
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    public Set<ProgramRuleAction> getProgramRuleActions()
+    {
+        return programRuleActions;
+    }
+
+    public void setProgramRuleActions( Set<ProgramRuleAction> programRuleActions )
+    {
+        this.programRuleActions = programRuleActions;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getCondition()
+    {
+        return condition;
+    }
+
+    public void setCondition( String condition )
+    {
+        this.condition = condition;
+    }
+    
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Integer getPriority()
+    {
+        return priority;
+    }
+
+    public void setPriority( Integer priority )
+    {
+        this.priority = priority;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+    
+    @Override
+    public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+    {
+        super.mergeWith( other, strategy );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            ProgramRule programRule = (ProgramRule) other;
+
+            if ( strategy.isReplace() )
+            {
+                description = programRule.getDescription();
+                priority = programRule.getPriority();
+                condition = programRule.getCondition();
+                program = programRule.getProgram();
+                programStage = programRule.getProgramStage();
+            }
+            else if ( strategy.isMerge() )
+            {
+                description = programRule.getDescription() == null ? description : programRule.getDescription();
+                priority = programRule.getPriority() == null ? priority : programRule.getPriority();
+                condition = programRule.getCondition() == null ? condition : programRule.getCondition();
+                program = programRule.getProgram() == null ? program : programRule.getProgram();
+                programStage = programRule.getProgramStage() == null ? programStage : programRule.getProgramStage();
+            }
+
+            programRuleActions.clear();
+            programRuleActions.addAll( programRule.getProgramRuleActions() );
+        }
+    }
+}
\ No newline at end of file

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleAction.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,246 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.DimensionalView;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.dataelement.DataElement;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+
+/**
+ * @author markusbekken
+ */
+
+public class ProgramRuleAction
+    extends BaseIdentifiableObject
+{
+    private static final long serialVersionUID = -2807997671779497354L;
+
+    /**
+     * The programRule that the action belongs to
+     */
+    private ProgramRule programRule;
+    
+    /**
+     * The type of action that is performed when the action is effectuated
+     * 
+     * The actual action the ruleaction row is performing. Allowed values are:
+     *   displaytext
+     *       Shows a text in the rulebound widget with the matching location string.
+     *           location: the location code of the widget to display data in
+     *           content: A hardcoded string to display
+     *           data: a variable to be evaluated and displayed at the end of the string, can be null.
+     *   displaykeyvaluepair
+     *       Shows a key data box with a hardcoded name and a variable value.
+     *           location: the location code of the widget to display data in
+     *           content: A hardcoded string to display as title in the key data box
+     *           data: The variable to be evaluated and display in the lower half of the key data box.
+     *   hidefield
+     *       Hides a dataelement from the page, as long as the dataelement is not containing a value.
+     *           dataelement: the dataelement to hide.
+     *   assignvariable
+     *       Assigns/calculates a value that can be further used by other rules. Make sure the priorities is set so the rules that depend on the calculation is run after the assignvariable-rule.
+     *           content: the variable name to be assigned. “$severeanemia” for example.
+     *           data: the expression to be evaluated and assigned to the content field. Can contain a hardcoded value(f.ex. “true”) or an expression that is evaluated(for exampple “$hemoglobin < 7”). 
+     *   showwarning
+     *       Shows a validation warning connected to a designated dataelement
+     *           dataelement: the dataelement to show validationerror for
+     *           content: the validation error itself 
+     *   showerror
+     *       Shows a validation error connected to a designated dataelement
+     *           dataelement: the dataelement to show validationerror for
+     *           content: the validation error itself 
+     */
+    private ProgramRuleActionType programRuleActionType;
+    
+    /**
+     * the dataelement that is affected by the ruleAction. 
+     * Used for 
+     *       hidefield
+     *       showwarning
+     *       showerror
+     */
+    private DataElement dataElement;
+    
+    /**
+     * Used to determine which widget to display data for the two action types:
+     *       displaytext
+     *       displaykeydata
+     */
+    private String location;
+
+    /**
+     * Used by all the different actions. See “actions”
+     */
+    private String content;
+    
+    /**
+     * Used by all the different actions. See “actions”. The data field will be evaluated, so it can contain a rich expression.
+     */
+    private String data;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public ProgramRuleAction()
+    {
+        setAutoFields();
+    }
+    
+    public ProgramRuleAction( String name, ProgramRule programRule, ProgramRuleActionType programRuleActionType, DataElement dataElement, String location, String content, String data )
+    {
+        this();
+        this.name = name;
+        this.programRule = programRule;
+        this.programRuleActionType = programRuleActionType;
+        this.dataElement = dataElement;
+        this.location = location;
+        this.content = content;
+        this.data = data;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+    
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ProgramRule getProgramRule()
+    {
+        return programRule;
+    }
+
+    public void setProgramRule( ProgramRule programRule )
+    {
+        this.programRule = programRule;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class, DimensionalView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ProgramRuleActionType getProgramRuleActionType()
+    {
+        return programRuleActionType;
+    }
+
+    public void setProgramRuleActionType( ProgramRuleActionType programRuleActionType )
+    {
+        this.programRuleActionType = programRuleActionType;
+    }
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public DataElement getDataElement()
+    {
+        return dataElement;
+    }
+
+    public void setDataElement( DataElement dataElement )
+    {
+        this.dataElement = dataElement;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getLocation()
+    {
+        return location;
+    }
+
+    public void setLocation( String location )
+    {
+        this.location = location;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getContent()
+    {
+        return content;
+    }
+
+    public void setContent( String content )
+    {
+        this.content = content;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getData()
+    {
+        return data;
+    }
+
+    public void setData( String data )
+    {
+        this.data = data;
+    }
+    
+    @Override
+    public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+    {
+        super.mergeWith( other, strategy );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            ProgramRuleAction programRuleAction = (ProgramRuleAction) other;
+
+            if ( strategy.isReplace() )
+            {
+                programRule = programRuleAction.getProgramRule();
+                programRuleActionType = programRuleAction.getProgramRuleActionType();
+                dataElement = programRuleAction.getDataElement();
+                location = programRuleAction.getLocation();
+                content = programRuleAction.getContent();
+                data = programRuleAction.getData();
+            }
+            else if ( strategy.isMerge() )
+            {
+                programRule = programRuleAction.getProgramRule() == null ? programRule : programRuleAction.getProgramRule();
+                programRuleActionType = programRuleAction.getProgramRuleActionType() == null ? programRuleActionType : programRuleAction.getProgramRuleActionType();
+                dataElement = programRuleAction.getDataElement() == null ? dataElement : programRuleAction.getDataElement();
+                location = programRuleAction.getLocation() == null ? location : programRuleAction.getLocation();
+                content = programRuleAction.getContent() == null ? content : programRuleAction.getContent();
+                data = programRuleAction.getData() == null ? data : programRuleAction.getData();            
+            }
+        }
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionService.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+/**
+ *
+ * @author markusbekken
+ */
+public interface ProgramRuleActionService
+{
+    String ID = ProgramRuleActionService.class.getName();
+
+    /**
+     * Adds an {@link ProgramRuleAction}
+     *
+     * @param ProgramRuleAction The to ProgramRuleAction add.
+     * @return A generated unique id of the added {@link ProgramRuleAction}.
+     */
+    int addProgramRuleAction( ProgramRuleAction programRuleAction );
+
+    /**
+     * Deletes a {@link ProgramRuleAction}
+     *
+     * @param ProgramRuleAction The ProgramRuleAction to delete.
+     */
+    void deleteProgramRuleAction( ProgramRuleAction programRuleAction );
+
+    /**
+     * Updates an {@link ProgramRuleAction}.
+     *
+     * @param ProgramRuleAction The ProgramRuleAction to update.
+     */
+    void updateProgramRuleAction( ProgramRuleAction programRuleAction );
+
+    /**
+     * Returns a {@link ProgramRuleAction}.
+     *
+     * @param id the id of the ProgramRuleAction to return.
+     * @return the ProgramRuleAction with the given id
+     */
+    ProgramRuleAction getProgramRuleAction( int id );
+
+    /**
+     * Returns all {@link ProgramRuleAction}.
+     *
+     * @return a collection of all ProgramRuleAction, or an empty collection if
+     * there are no ProgramRuleActions.
+     */
+    Collection<ProgramRuleAction> getAllProgramRuleAction();
+
+    /**
+     * Get validation by {@link ProgramRule}
+     *
+     * @param program Program
+     * @return ProgramRuleAction list
+     */
+    Collection<ProgramRuleAction> getProgramRuleAction( ProgramRule programRule );
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionStore.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,49 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import org.hisp.dhis.common.GenericNameableObjectStore;
+
+/**
+ * @author markusbekken
+ */
+public interface ProgramRuleActionStore
+    extends GenericNameableObjectStore<ProgramRuleAction>
+{
+    String ID = ProgramRuleActionStore.class.getName();
+
+    /**
+     * Get programRuleAction by program
+     *
+     * @param program {@link Program}
+     * @return ProgramRuleActionVariable list
+     */
+    Collection<ProgramRuleAction> get( ProgramRule programRule );
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionType.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,61 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author markusbekken
+ */
+public enum ProgramRuleActionType {
+    DISPLAYTEXT( "displaytext" ),
+    DISPLAYKEYVALUEPAIR( "displaykeyvaluepair" ),
+    HIDEFIELD( "hidefield" ),
+    ASSIGNVARIABLE( "assignvariable" ),
+    SHOWWARNING( "showwarning" ),
+    SHOWERROR( "showerror" );
+
+    final String value;
+
+    private ProgramRuleActionType( String value )
+    {
+        this.value = value;
+    }
+
+    public static ProgramRuleActionType fromValue( String value )
+    {
+        for ( ProgramRuleActionType type : ProgramRuleActionType.values() )
+        {
+            if ( type.value.equalsIgnoreCase( value ) )
+            {
+                return type;
+            }
+        }
+
+        return null;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleService.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import org.hisp.dhis.program.Program;
+
+/**
+ *
+ * @author markusbekken
+ */
+public interface ProgramRuleService
+{
+    String ID = ProgramRuleService.class.getName();
+
+    /**
+     * Adds an {@link ProgramRule}
+     *
+     * @param ProgramRule The to ProgramRule add.
+     * @return A generated unique id of the added {@link ProgramRule}.
+     */
+    int addProgramRule( ProgramRule programRule );
+
+    /**
+     * Deletes a {@link ProgramRule}
+     *
+     * @param ProgramRule The ProgramRule to delete.
+     */
+    void deleteProgramRule( ProgramRule programRule );
+
+    /**
+     * Updates an {@link ProgramRule}.
+     *
+     * @param ProgramRule The ProgramRule to update.
+     */
+    void updateProgramRule( ProgramRule programRule );
+
+    /**
+     * Returns a {@link ProgramRule}.
+     *
+     * @param id the id of the ProgramRule to return.
+     * @return the ProgramRule with the given id
+     */
+    ProgramRule getProgramRule( int id );
+
+    /**
+     * Returns all {@link ProgramRule}.
+     *
+     * @return a collection of all ProgramRule, or an empty collection if
+     * there are no ProgramRules.
+     */
+    Collection<ProgramRule> getAllProgramRule();
+
+    /**
+     * Get validation by {@link Program}
+     *
+     * @param program Program
+     * @return ProgramRule list
+     */
+    Collection<ProgramRule> getProgramRule( Program program );
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleStore.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.common.GenericNameableObjectStore;
+import org.hisp.dhis.program.Program;
+
+/**
+ * @author markusbekken
+ */
+public interface ProgramRuleStore
+    extends GenericNameableObjectStore<ProgramRule>
+{
+    String ID = ProgramRuleStore.class.getName();
+
+    /**
+     * Get programRule by program
+     *
+     * @param program {@link Program}
+     * @return ProgramRuleVariable list
+     */
+    Collection<ProgramRule> get( Program program );
+}

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariable.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,222 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.DimensionalView;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+/**
+ * @author markusbekken
+ */
+@JacksonXmlRootElement( localName = "programRuleVariable", namespace = DxfNamespaces.DXF_2_0 )
+public class ProgramRuleVariable
+    extends BaseIdentifiableObject
+{
+    private static final long serialVersionUID = -2807997671779497354L;
+
+    /**
+     * The program that the variable belongs to
+     */
+    private Program program;
+
+
+    /**
+     * The source of the variables content. Allowed values are:
+     * dataelement_newest_event_program_stage Get a specific data elements value
+     * from the most recent event in the current enrollment, but within one
+     * program stage. dataelement_uID and programstage_uID needs to be
+     * specified. dataelement_newest_event_program Get a specific data elements
+     * value from the most recent event in the current enrollment, regardless of
+     * program stage.datalement_uID needs to be specified.
+     * dataelement_current_event Get a specific data elements value, but only
+     * 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”
+     * 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.
+     */
+    private ProgramRuleVariableSourceType sourceType;
+
+    /**
+     * Used for sourceType tei_attribute to determine which attribute to fetch
+     * into the variable.
+     */
+    private TrackedEntityAttribute attribute;
+
+    /**
+     * The data element that is linked to the variable. Must de defined if the
+     * sourceType is one of the following:
+     * dataelement_newest_event_program_stage dataelement_newest_event_program
+     * dataelement_current_event
+     */
+    private DataElement dataElement;
+
+    /**
+     * Specification of the program stage that the variable should be fetched
+     * from. Only used for source type dataelement_newest_event_program_stage
+     */
+    private ProgramStage programStage;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public ProgramRuleVariable()
+    {
+        setAutoFields();
+    }
+
+    public ProgramRuleVariable( String name, 
+            Program program, 
+            ProgramRuleVariableSourceType sourceType,
+            TrackedEntityAttribute attribute,
+            DataElement dataElement,
+            ProgramStage programStage)
+    {
+        this();
+        this.name = name;
+        this.program = program;
+        this.sourceType = sourceType;
+        this.attribute = attribute;
+        this.dataElement = dataElement;
+        this.programStage = programStage;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Program getProgram()
+    {
+        return program;
+    }
+
+    public void setProgram( Program program )
+    {
+        this.program = program;
+    }
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ProgramStage getProgramStage()
+    {
+        return programStage;
+    }
+
+    public void setProgramStage( ProgramStage programStage )
+    {
+        this.programStage = programStage;
+    }
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public DataElement getDataElement()
+    {
+        return dataElement;
+    }
+
+    public void setDataElement( DataElement dataElement )
+    {
+        this.dataElement = dataElement;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public TrackedEntityAttribute getAttribute()
+    {
+        return attribute;
+    }
+
+    public void setAttribute( TrackedEntityAttribute attribute )
+    {
+        this.attribute = attribute;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class, DimensionalView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ProgramRuleVariableSourceType getSourceType()
+    {
+        return sourceType;
+    }
+
+    public void setSourceType( ProgramRuleVariableSourceType sourceType )
+    {
+        this.sourceType = sourceType;
+    }
+    
+    @Override
+    public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+    {
+        super.mergeWith( other, strategy );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            ProgramRuleVariable programRuleVariable = (ProgramRuleVariable) other;
+
+            if ( strategy.isReplace() )
+            {
+                this.sourceType = programRuleVariable.getSourceType();
+                this.attribute = programRuleVariable.getAttribute();
+                this.dataElement = programRuleVariable.getDataElement();
+                this.programStage = programRuleVariable.getProgramStage();
+            }
+            else if ( strategy.isMerge() )
+            {
+                this.sourceType = programRuleVariable.getSourceType() == null ? sourceType : programRuleVariable.getSourceType();
+                this.attribute = programRuleVariable.getAttribute() == null ? attribute : programRuleVariable.getAttribute();
+                this.dataElement = programRuleVariable.getDataElement() == null ? dataElement : programRuleVariable.getDataElement();
+                this.programStage = programRuleVariable.getProgramStage() == null ? programStage : programRuleVariable.getProgramStage();
+            }
+        }
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableService.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.program.Program;
+
+/**
+ *
+ * @author markusbekken
+ */
+public interface ProgramRuleVariableService
+{
+    String ID = ProgramRuleVariableService.class.getName();
+
+    /**
+     * Adds an {@link ProgramRuleVariable}
+     *
+     * @param programRuleVariable The to ProgramRuleVariable add.
+     * @return A generated unique id of the added {@link ProgramRuleVariable}.
+     */
+    int addProgramRuleVariable( ProgramRuleVariable programRuleVariable );
+
+    /**
+     * Deletes a {@link ProgramRuleVariable}
+     *
+     * @param programRuleVariable The ProgramRuleVariable to delete.
+     */
+    void deleteProgramRuleVariable( ProgramRuleVariable programRuleVariable );
+
+    /**
+     * Updates an {@link ProgramRuleVariable}.
+     *
+     * @param programRuleVariable The ProgramRuleVariable to update.
+     */
+    void updateProgramRuleVariable( ProgramRuleVariable programRuleVariable );
+
+    /**
+     * Returns a {@link ProgramRuleVariable}.
+     *
+     * @param id the id of the ProgramRuleVariable to return.
+     * @return the ProgramRuleVariable with the given id
+     */
+    ProgramRuleVariable getProgramRuleVariable( int id );
+
+    /**
+     * Returns all {@link ProgramRuleVariable}.
+     *
+     * @return a collection of all ProgramRuleVariable, or an empty collection if
+     * there are no ProgramRuleVariables.
+     */
+    Collection<ProgramRuleVariable> getAllProgramRuleVariable();
+
+    /**
+     * Get validation by {@link Program}
+     *
+     * @param program Program
+     * @return ProgramRuleVariable list
+     */
+    Collection<ProgramRuleVariable> getProgramRuleVariable( Program program );
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableSourceType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableSourceType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableSourceType.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,66 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author markusbekken
+ */
+@JacksonXmlRootElement( localName = "programRuleVariableSourceType", namespace = DxfNamespaces.DXF_2_0 )
+public enum ProgramRuleVariableSourceType {
+    DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE("dataelement_newest_event_program_stage"), 
+    DATAELEMENT_NEWEST_EVENT_PROGRAM("dataelement_newest_event_program"), 
+    DATAELEMENT_CURRENT_EVENT("dataelement_current_event"), 
+    DATAELEMENT_PREVIOUS_EVENT("dataelement_previous_event"), 
+    CALCULATED_VALUE("calculated_value"), 
+    TEI_ATTRIBUTE("tei_attribute"),
+    CONTEXT_VARIABLE("context_variable");
+    
+    private final String value;
+
+    private ProgramRuleVariableSourceType( String value )
+    {
+        this.value = value;
+    }
+
+    public static ProgramRuleVariableSourceType fromValue( String value )
+    {
+        for ( ProgramRuleVariableSourceType type : ProgramRuleVariableSourceType.values() )
+        {
+            if ( type.value.equalsIgnoreCase( value ) )
+            {
+                return type;
+            }
+        }
+
+        return null;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableStore.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.common.GenericNameableObjectStore;
+import org.hisp.dhis.program.Program;
+
+/**
+ * @author markusbekken
+ */
+public interface ProgramRuleVariableStore
+    extends GenericNameableObjectStore<ProgramRuleVariable>
+{
+    String ID = ProgramRuleVariableStore.class.getName();
+
+    /**
+     * Get programRuleVariable by program
+     *
+     * @param program {@link Program}
+     * @return ProgramRuleVariable list
+     */
+    Collection<ProgramRuleVariable> get( Program program );
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleActionSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleActionSchemaDescriptor.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleActionSchemaDescriptor.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.schema.descriptors;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Lists;
+import org.hisp.dhis.schema.Authority;
+import org.hisp.dhis.schema.AuthorityType;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaDescriptor;
+import org.hisp.dhis.programrule.ProgramRuleAction;
+import org.springframework.stereotype.Component;
+
+/**
+ *
+ * @author markusbekken
+ */
+@Component
+public class ProgramRuleActionSchemaDescriptor implements SchemaDescriptor
+{
+    public static final String SINGULAR = "programRuleAction";
+
+    public static final String PLURAL = "programRuleActions";
+
+    public static final String API_ENDPOINT = "/" + PLURAL;
+
+    @Override
+    public Schema getSchema()
+    {
+        Schema schema = new Schema( ProgramRuleAction.class, SINGULAR, PLURAL );
+        schema.setApiEndpoint( API_ENDPOINT );
+        schema.setOrder( 1392 );
+
+        schema.getAuthorities().add( new Authority( AuthorityType.CREATE, Lists.newArrayList( "F_PROGRAMRULEACTION_ADD" ) ) );
+        schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_PROGRAMRULEACTION_DELETE" ) ) );
+
+        return schema;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleSchemaDescriptor.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleSchemaDescriptor.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.schema.descriptors;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Lists;
+import org.hisp.dhis.schema.Authority;
+import org.hisp.dhis.schema.AuthorityType;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaDescriptor;
+import org.hisp.dhis.programrule.ProgramRule;
+import org.springframework.stereotype.Component;
+
+/**
+ *
+ * @author markusbekken
+ */
+@Component
+public class ProgramRuleSchemaDescriptor implements SchemaDescriptor
+{
+    public static final String SINGULAR = "programRule";
+
+    public static final String PLURAL = "programRules";
+
+    public static final String API_ENDPOINT = "/" + PLURAL;
+
+    @Override
+    public Schema getSchema()
+    {
+        Schema schema = new Schema( ProgramRule.class, SINGULAR, PLURAL );
+        schema.setApiEndpoint( API_ENDPOINT );
+        schema.setOrder( 1391 );
+        
+        schema.getAuthorities().add( new Authority( AuthorityType.CREATE, Lists.newArrayList( "F_PROGRAMRULE_ADD" ) ) );
+        schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_PROGRAMRULE_DELETE" ) ) );
+
+        return schema;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleVariableSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleVariableSchemaDescriptor.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramRuleVariableSchemaDescriptor.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.schema.descriptors;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Lists;
+import org.hisp.dhis.schema.Authority;
+import org.hisp.dhis.schema.AuthorityType;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaDescriptor;
+import org.hisp.dhis.programrule.ProgramRuleVariable;
+import org.springframework.stereotype.Component;
+
+/**
+ *
+ * @author markusbekken
+ */
+@Component
+public class ProgramRuleVariableSchemaDescriptor implements SchemaDescriptor
+{
+    public static final String SINGULAR = "programRuleVariable";
+
+    public static final String PLURAL = "programRuleVariables";
+
+    public static final String API_ENDPOINT = "/" + PLURAL;
+
+    @Override
+    public Schema getSchema()
+    {
+        Schema schema = new Schema( ProgramRuleVariable.class, SINGULAR, PLURAL );
+        schema.setApiEndpoint( API_ENDPOINT );
+        schema.setOrder( 1390 );
+        
+        schema.getAuthorities().add( new Authority( AuthorityType.CREATE, Lists.newArrayList( "F_PROGRAMRULEVARIABLE_ADD" ) ) );
+        schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_PROGRAMRULEVARIABLE_DELETE" ) ) );
+
+        return schema;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2015-03-03 08:22:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2015-03-13 08:24:36 +0000
@@ -251,6 +251,18 @@
   <bean id="programStageSectionImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
     <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.program.ProgramStageSection" />
   </bean>
+  
+  <bean id="programRuleImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
+    <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.programrule.ProgramRule" />
+  </bean>
+  
+  <bean id="programRuleActionImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
+    <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.programrule.ProgramRuleAction" />
+  </bean>
+
+  <bean id="programRuleVariableImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
+    <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.programrule.ProgramRuleVariable" />
+  </bean>
 
   <bean id="relationshipTypeImporter" class="org.hisp.dhis.dxf2.metadata.importers.DefaultIdentifiableObjectImporter" scope="prototype">
     <constructor-arg name="importerClass" type="java.lang.Class" value="org.hisp.dhis.relationship.RelationshipType" />

=== added directory 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule'
=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleActionService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleActionService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleActionService.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,91 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author markusbekken
+ */
+@Transactional
+public class DefaultProgramRuleActionService
+    implements ProgramRuleActionService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramRuleActionStore programRuleActionStore;
+
+    public void setProgramRuleActionStore( ProgramRuleActionStore programRuleActionStore )
+    {
+        this.programRuleActionStore = programRuleActionStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // ProgramRuleAction implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int addProgramRuleAction( ProgramRuleAction programRuleAction )
+    {
+        return programRuleActionStore.save( programRuleAction );
+    }
+
+    @Override
+    public void deleteProgramRuleAction( ProgramRuleAction programRuleAction )
+    {
+        programRuleActionStore.delete( programRuleAction );
+    }
+
+    @Override
+    public void updateProgramRuleAction( ProgramRuleAction programRuleAction )
+    {
+        programRuleActionStore.update( programRuleAction );
+    }
+
+    @Override
+    public ProgramRuleAction getProgramRuleAction( int id )
+    {
+        return programRuleActionStore.get( id );
+    }
+
+    @Override
+    public Collection<ProgramRuleAction> getAllProgramRuleAction()
+    {
+        return programRuleActionStore.getAll();
+    }
+
+    @Override
+    public Collection<ProgramRuleAction> getProgramRuleAction( ProgramRule programRule )
+    {
+        return programRuleActionStore.get( programRule );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleService.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,93 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.program.Program;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author markusbekken
+ */
+@Transactional
+public class DefaultProgramRuleService
+    implements ProgramRuleService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramRuleStore programRuleStore;
+
+    public void setProgramRuleStore( ProgramRuleStore programRuleStore )
+    {
+        this.programRuleStore = programRuleStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // ProgramRule implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int addProgramRule( ProgramRule programRule )
+    {
+        return programRuleStore.save( programRule );
+    }
+
+    @Override
+    public void deleteProgramRule( ProgramRule programRule )
+    {
+        programRuleStore.delete( programRule );
+    }
+
+    @Override
+    public void updateProgramRule( ProgramRule programRule )
+    {
+        programRuleStore.update( programRule );
+    }
+
+    @Override
+    public ProgramRule getProgramRule( int id )
+    {
+        return programRuleStore.get( id );
+    }
+
+    @Override
+    public Collection<ProgramRule> getAllProgramRule()
+    {
+        return programRuleStore.getAll();
+    }
+
+    @Override
+    public Collection<ProgramRule> getProgramRule( Program program )
+    {
+        return programRuleStore.get( program );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleVariableService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleVariableService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/DefaultProgramRuleVariableService.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,93 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.program.Program;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author markusbekken
+ */
+@Transactional
+public class DefaultProgramRuleVariableService
+    implements ProgramRuleVariableService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramRuleVariableStore programRuleVariableStore;
+
+    public void setProgramRuleVariableStore( ProgramRuleVariableStore programRuleVariableStore )
+    {
+        this.programRuleVariableStore = programRuleVariableStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // ProgramRuleVariable implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int addProgramRuleVariable( ProgramRuleVariable programRuleVariable )
+    {
+        return programRuleVariableStore.save( programRuleVariable );
+    }
+
+    @Override
+    public void deleteProgramRuleVariable( ProgramRuleVariable programRuleVariable )
+    {
+        programRuleVariableStore.delete( programRuleVariable );
+    }
+
+    @Override
+    public void updateProgramRuleVariable( ProgramRuleVariable programRuleVariable )
+    {
+        programRuleVariableStore.update( programRuleVariable );
+    }
+
+    @Override
+    public ProgramRuleVariable getProgramRuleVariable( int id )
+    {
+        return programRuleVariableStore.get( id );
+    }
+
+    @Override
+    public Collection<ProgramRuleVariable> getAllProgramRuleVariable()
+    {
+        return programRuleVariableStore.getAll();
+    }
+
+    @Override
+    public Collection<ProgramRuleVariable> getProgramRuleVariable( Program program )
+    {
+        return programRuleVariableStore.get( program );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleActionDeletionHandler.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author markusbekken
+ */
+public class ProgramRuleActionDeletionHandler
+    extends DeletionHandler 
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    ProgramRuleActionService programRuleActionService;
+
+    public void setProgramRuleActionService( ProgramRuleActionService programRuleActionService )
+    {
+        this.programRuleActionService = programRuleActionService;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Implementation methods
+    // -------------------------------------------------------------------------
+    
+    @Override
+    protected String getClassName()
+    {
+        return ProgramRuleAction.class.getSimpleName();
+    }
+    
+    @Override
+    public void deleteProgramRule( ProgramRule programRule )
+    {
+        for ( ProgramRuleAction programRuleAction : programRuleActionService.getProgramRuleAction( programRule ) )
+        {
+            programRuleActionService.deleteProgramRuleAction( programRuleAction );
+        }
+    }
+    
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleDeletionHandler.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author markusbekken
+ */
+public class ProgramRuleDeletionHandler
+    extends DeletionHandler 
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    ProgramRuleService programRuleService;
+
+    public void setProgramRuleService( ProgramRuleService programRuleService )
+    {
+        this.programRuleService = programRuleService;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Implementation methods
+    // -------------------------------------------------------------------------
+    
+    @Override
+    protected String getClassName()
+    {
+        return ProgramRule.class.getSimpleName();
+    }
+    
+    @Override
+    public void deleteProgram( Program program )
+    {
+        for ( ProgramRule programRule : programRuleService.getProgramRule( program ) )
+        {
+            programRuleService.deleteProgramRule( programRule );
+        }
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/ProgramRuleVariableDeletionHandler.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author markusbekken
+ */
+public class ProgramRuleVariableDeletionHandler
+    extends DeletionHandler 
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    ProgramRuleVariableService programRuleVariableService;
+
+    public void setProgramRuleVariableService( ProgramRuleVariableService programRuleVariableService )
+    {
+        this.programRuleVariableService = programRuleVariableService;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Implementation methods
+    // -------------------------------------------------------------------------
+    @Override
+    protected String getClassName()
+    {
+        return ProgramRuleVariable.class.getSimpleName();
+    }
+    
+    @Override
+    public void deleteProgram( Program program )
+    {
+        for ( ProgramRuleVariable programRuleVariable : programRuleVariableService.getProgramRuleVariable( program ) )
+        {
+            programRuleVariableService.deleteProgramRuleVariable( programRuleVariable );
+        }
+    }
+    
+}

=== added directory 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate'
=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleActionStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleActionStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleActionStore.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.programrule.hibernate;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.programrule.ProgramRule;
+import org.hisp.dhis.programrule.ProgramRuleAction;
+import org.hisp.dhis.programrule.ProgramRuleActionStore;
+
+/**
+ * @author markusbekken
+ */
+public class HibernateProgramRuleActionStore
+    extends HibernateIdentifiableObjectStore<ProgramRuleAction>
+    implements ProgramRuleActionStore
+{
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public Collection<ProgramRuleAction> get( ProgramRule programRule )
+    {
+        return getCriteria( Restrictions.eq( "programRule", programRule ) ).list();
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleStore.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.programrule.hibernate;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.programrule.ProgramRule;
+import org.hisp.dhis.programrule.ProgramRuleStore;
+
+/**
+ * @author markusbekken
+ */
+public class HibernateProgramRuleStore
+    extends HibernateIdentifiableObjectStore<ProgramRule>
+    implements ProgramRuleStore
+{
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public Collection<ProgramRule> get( Program program )
+    {
+        return getCriteria( Restrictions.eq( "program", program ) ).list();
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleVariableStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleVariableStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/programrule/hibernate/HibernateProgramRuleVariableStore.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.programrule.hibernate;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.programrule.ProgramRuleVariable;
+import org.hisp.dhis.programrule.ProgramRuleVariableStore;
+
+/**
+ * @author markusbekken
+ */
+public class HibernateProgramRuleVariableStore
+    extends HibernateIdentifiableObjectStore<ProgramRuleVariable>
+    implements ProgramRuleVariableStore
+{
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public Collection<ProgramRuleVariable> get( Program program )
+    {
+        return getCriteria( Restrictions.eq( "program", program ) ).list();
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2015-03-08 13:34:06 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2015-03-13 08:24:36 +0000
@@ -28,7 +28,6 @@
 		class="org.hisp.dhis.program.hibernate.HibernateProgramStageInstanceStore">
 		<property name="clazz" value="org.hisp.dhis.program.ProgramStageInstance" />
 		<property name="sessionFactory" ref="sessionFactory" />
-		<property name="jdbcTemplate" ref="jdbcTemplate" />
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
 	</bean>
 
@@ -114,6 +113,24 @@
 		<property name="sessionFactory" ref="sessionFactory" />
 	</bean>
 
+	<bean id="org.hisp.dhis.programrule.ProgramRuleVariableStore"
+		class="org.hisp.dhis.programrule.hibernate.HibernateProgramRuleVariableStore">
+		<property name="clazz" value="org.hisp.dhis.programrule.ProgramRuleVariable" />
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleStore"
+		class="org.hisp.dhis.programrule.hibernate.HibernateProgramRuleStore">
+		<property name="clazz" value="org.hisp.dhis.programrule.ProgramRule" />
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleActionStore"
+		class="org.hisp.dhis.programrule.hibernate.HibernateProgramRuleActionStore">
+		<property name="clazz" value="org.hisp.dhis.programrule.ProgramRuleAction" />
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
+
 	<bean id="org.hisp.dhis.trackedentity.TrackedEntityAuditStore"
 		class="org.hisp.dhis.trackedentity.hibernate.HibernateTrackedEntityAuditStore">
 		<property name="clazz"
@@ -138,7 +155,7 @@
 	    <property name="clazz" value="org.hisp.dhis.eventchart.EventChart" />
         <property name="sessionFactory" ref="sessionFactory" />			
 	</bean>
-	
+        
 	<!-- Service definitions -->
 
 	<bean id="org.hisp.dhis.program.ProgramDataEntryService" class="org.hisp.dhis.program.DefaultProgramDataEntryService">
@@ -217,6 +234,18 @@
 		<property name="programStageStore" ref="org.hisp.dhis.program.ProgramStageStore" />
 		<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
 	</bean>
+        
+	<bean id="org.hisp.dhis.programrule.ProgramRuleVariableService" class="org.hisp.dhis.programrule.DefaultProgramRuleVariableService">
+		<property name="programRuleVariableStore" ref="org.hisp.dhis.programrule.ProgramRuleVariableStore" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleService" class="org.hisp.dhis.programrule.DefaultProgramRuleService">
+		<property name="programRuleStore" ref="org.hisp.dhis.programrule.ProgramRuleStore" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleActionService" class="org.hisp.dhis.programrule.DefaultProgramRuleActionService">
+		<property name="programRuleActionStore" ref="org.hisp.dhis.programrule.ProgramRuleActionStore" />
+	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramStageSectionService" class="org.hisp.dhis.program.DefaultProgramStageSectionService">
 		<property name="programStageSectionStore"
@@ -394,8 +423,7 @@
 		</property>
 	</bean>
 
-	<bean
-		class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+	<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
 		<property name="targetObject"
 			ref="org.hisp.dhis.system.startup.StartupRoutineExecutor" />
 		<property name="targetMethod" value="addStartupRoutines" />
@@ -456,6 +484,21 @@
 		class="org.hisp.dhis.program.ProgramStageDeletionHandler">
 		<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleDeletionHandler"
+		class="org.hisp.dhis.programrule.ProgramRuleDeletionHandler">
+		<property name="programRuleService" ref="org.hisp.dhis.programrule.ProgramRuleService" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleVariableDeletionHandler"
+		class="org.hisp.dhis.programrule.ProgramRuleVariableDeletionHandler">
+		<property name="programRuleVariableService" ref="org.hisp.dhis.programrule.ProgramRuleVariableService" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.programrule.ProgramRuleActionDeletionHandler"
+		class="org.hisp.dhis.programrule.ProgramRuleActionDeletionHandler">
+		<property name="programRuleActionService" ref="org.hisp.dhis.programrule.ProgramRuleActionService" />
+	</bean>
 
 	<bean id="org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueDeletionHandler"
 		class="org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueDeletionHandler">
@@ -534,6 +577,9 @@
 					<ref bean="org.hisp.dhis.program.ProgramValidationDeletionHandler" />
 					<ref bean="org.hisp.dhis.program.ProgramDataEntryFormDeletionHandler" />
 					<ref bean="org.hisp.dhis.program.ProgramIndicatorDeletionHandler" />
+					<ref bean="org.hisp.dhis.programrule.ProgramRuleDeletionHandler" />
+					<ref bean="org.hisp.dhis.programrule.ProgramRuleVariableDeletionHandler" />
+					<ref bean="org.hisp.dhis.programrule.ProgramRuleActionDeletionHandler" />
 					<ref bean="org.hisp.dhis.trackedentity.TrackedEntityFormDeletionHandler" />
 					<ref bean="org.hisp.dhis.eventchart.EventChartDeletionHandler" />
 					<ref bean="org.hisp.dhis.eventreport.EventReportDeletionHandler" />

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRule.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRule.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRule.hbm.xml	2015-03-13 08:24:36 +0000
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
+  [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+  >
+
+<hibernate-mapping>
+  <class name="org.hisp.dhis.programrule.ProgramRule" table="programrule">
+
+    <cache usage="read-write" />
+
+    <id name="id" column="programruleid">
+      <generator class="native" />
+    </id>
+
+    &identifiableProperties;
+
+    <property name="name" column="name" length="230" />
+    
+    <property name="description" />
+
+    <many-to-one name="program" class="org.hisp.dhis.program.Program" 
+       	column="programid" foreign-key="fk_programrule_program" />
+    
+	<many-to-one name="programStage" class="org.hisp.dhis.program.ProgramStage" 
+		column="programstageid" foreign-key="fk_programrule_programstage" />
+
+    <set name="programRuleActions" cascade="all">
+		<key column="programruleid" />
+		<one-to-many class="org.hisp.dhis.programrule.ProgramRuleAction" />
+	</set>
+
+    <property name="condition" />
+   
+    <property name="priority" />
+   
+  </class>
+</hibernate-mapping>

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleAction.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleAction.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleAction.hbm.xml	2015-03-13 08:24:36 +0000
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
+  [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+  >
+
+<hibernate-mapping>
+  <class name="org.hisp.dhis.programrule.ProgramRuleAction" table="programruleaction">
+
+    <cache usage="read-write" />
+
+    <id name="id" column="programruleactionid">
+      <generator class="native" />
+    </id>
+
+    &identifiableProperties;
+
+    <property name="name" column="name" length="230" />
+
+	<many-to-one name="programRule" class="org.hisp.dhis.programrule.ProgramRule" 
+		column="programruleid" foreign-key="fk_programruleaction_programrule" />
+
+    <property name="programRuleActionType" column="actiontype">
+        <type name="org.hibernate.type.EnumType">
+            <param name="enumClass">org.hisp.dhis.programrule.ProgramRuleActionType</param>
+            <param name="type">12</param>
+        </type>
+    </property>
+
+    <many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" 
+        column="dataelementid" foreign-key="fk_programruleaction_dataelement" />
+
+    <property name="location" />
+   
+    <property name="content" />
+    
+    <property name="data" />
+  </class>
+</hibernate-mapping>

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleVariable.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleVariable.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramRuleVariable.hbm.xml	2015-03-13 08:24:36 +0000
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
+  [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+  >
+
+<hibernate-mapping>
+  <class name="org.hisp.dhis.programrule.ProgramRuleVariable" table="programrulevariable">
+
+    <cache usage="read-write" />
+
+    <id name="id" column="programrulevariableid">
+      <generator class="native" />
+    </id>
+
+    &identifiableProperties;
+
+    <property name="name" column="name" length="230" />
+
+    <many-to-one name="program" class="org.hisp.dhis.program.Program" 
+       	column="programid" foreign-key="fk_programrulevariable_program" />
+    
+    <property name="sourceType" column="sourcetype">
+        <type name="org.hibernate.type.EnumType">
+            <param name="enumClass">org.hisp.dhis.programrule.ProgramRuleVariableSourceType</param>
+            <param name="type">12</param>
+        </type>
+    </property>
+    
+    <many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute" 
+        column="trackedentityattributeid" foreign-key="fk_programrulevariable_trackedentityattribute" />
+    
+    <many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" 
+        column="dataelementid" foreign-key="fk_programrulevariable_dataelement" />
+     
+    <many-to-one name="programStage" class="org.hisp.dhis.program.ProgramStage" 
+        column="programstageid" foreign-key="fk_programrulevariable_programstage" />
+        
+  </class>
+</hibernate-mapping>

=== added directory 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule'
=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionServiceTest.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,154 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.Assert.*;
+
+public class ProgramRuleActionServiceTest
+    extends DhisSpringTest
+{
+    private ProgramRule programRuleA;
+    private ProgramRule programRuleB;
+    private ProgramRule programRuleC;
+    private DataElement dataElementA;
+    
+    @Autowired
+    private ProgramRuleService programRuleService;
+    
+    @Autowired
+    private DataElementService dataElementService;
+    
+    @Autowired
+    private ProgramRuleActionService actionService;
+    
+    @Override
+    public void setUpTest()
+    {
+        programRuleA = createProgramRule( 'A' );
+        programRuleB = createProgramRule( 'B' );
+        programRuleC = createProgramRule( 'C' );
+        dataElementA = createDataElement( 'A' );
+        
+        programRuleService.addProgramRule( programRuleA );
+        programRuleService.addProgramRule( programRuleB );
+        programRuleService.addProgramRule( programRuleC );
+        dataElementService.addDataElement( dataElementA );
+    }
+    
+    @Test
+    public void testAddGet()
+    {
+        ProgramRuleAction actionA = new ProgramRuleAction( "ActionA", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
+        ProgramRuleAction actionB = new ProgramRuleAction( "ActionB", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionC = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        
+        int idA = actionService.addProgramRuleAction( actionA );
+        int idB = actionService.addProgramRuleAction( actionB );
+        int idC = actionService.addProgramRuleAction( actionC );
+        
+        assertEquals( actionA, actionService.getProgramRuleAction( idA ) );
+        assertEquals( actionB, actionService.getProgramRuleAction( idB ) );
+        assertEquals( actionC, actionService.getProgramRuleAction( idC ) );
+    }
+    
+    @Test
+    public void testGetByProgram()
+    {
+        ProgramRuleAction actionD = new ProgramRuleAction( "ActionD", programRuleB, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
+        ProgramRuleAction actionE = new ProgramRuleAction( "ActionE", programRuleB, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionF = new ProgramRuleAction( "ActionF", programRuleB, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        //Add an action that is not part of programRuleB....
+        ProgramRuleAction actionG = new ProgramRuleAction( "ActionG", programRuleC, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+        
+        actionService.addProgramRuleAction( actionD );
+        actionService.addProgramRuleAction( actionE );
+        actionService.addProgramRuleAction( actionF );
+        actionService.addProgramRuleAction( actionG );
+        
+        //Get all the 3 rules for programB
+        Collection<ProgramRuleAction> rules = actionService.getProgramRuleAction( programRuleB );
+        assertEquals( 3, rules.size() );
+        assertTrue( rules.contains( actionD ) );
+        assertTrue( rules.contains( actionE ) );
+        assertTrue( rules.contains( actionF ) );
+        //Make sure that the action connected to rule A is not returned as part of collection of actions in rule B.
+        assertFalse( rules.contains( actionG ) );
+        
+    }
+    
+    @Test
+    public void testUpdate()
+    {
+        ProgramRuleAction actionH = new ProgramRuleAction( "ActionH", programRuleB, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
+        
+        int idH = actionService.addProgramRuleAction( actionH );
+        
+        actionH.setName( "new name" );
+        actionH.setData( "$newdata" );
+        actionH.setLocation( "newlocation" );
+        actionH.setDataElement( dataElementA );
+        actionH.setProgramRule( programRuleC );
+        actionH.setProgramRuleActionType( ProgramRuleActionType.HIDEFIELD );
+        
+        actionService.updateProgramRuleAction( actionH );
+        
+        assertEquals( actionH, actionService.getProgramRuleAction( idH ) );
+    }
+    
+    @Test
+    public void testDeleteProgramRuleVariable()
+    {
+        ProgramRuleAction actionI = new ProgramRuleAction( "ActionI", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");
+        ProgramRuleAction actionJ = new ProgramRuleAction( "ActionJ", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
+        
+        int idI = actionService.addProgramRuleAction( actionI );
+        int idJ = actionService.addProgramRuleAction( actionJ );
+        
+        assertNotNull( actionService.getProgramRuleAction( idI ) );
+        assertNotNull( actionService.getProgramRuleAction( idJ ) );
+
+        actionService.deleteProgramRuleAction( actionI );
+
+        assertNull( actionService.getProgramRuleAction( idI ) );
+        assertNotNull( actionService.getProgramRuleAction( idJ ) );
+
+        actionService.deleteProgramRuleAction( actionJ );
+
+        assertNull( actionService.getProgramRuleAction( idI ) );
+        assertNull( actionService.getProgramRuleAction( idJ ) );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleActionStoreTest.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementStore;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class ProgramRuleActionStoreTest
+    extends DhisSpringTest
+{
+    public ProgramRule programRuleA; 
+    
+    public DataElement dataElementA;
+    
+    
+    @Autowired
+    public ProgramRuleStore programRuleStore;
+    
+    @Autowired
+    public DataElementStore dataElementStore;
+    
+    @Autowired
+    public ProgramRuleActionStore actionStore;
+    
+    @Override
+    public void setUpTest()
+    {
+        programRuleA = createProgramRule( 'A' );
+        dataElementA = createDataElement( 'A' );
+        
+        programRuleStore.save( programRuleA );
+        dataElementStore.save( dataElementA );
+    }
+    
+    @Test
+    public void testGetByProgram()
+    {
+        ProgramRuleAction actionA = new ProgramRuleAction( "ActionA", programRuleA, ProgramRuleActionType.ASSIGNVARIABLE, null, null, "$myvar", "true");        
+        ProgramRuleAction actionB = new ProgramRuleAction( "ActionB", programRuleA, ProgramRuleActionType.DISPLAYTEXT, null, "con","Hello", "$placeofliving");
+        ProgramRuleAction actionC = new ProgramRuleAction( "ActionC", programRuleA, ProgramRuleActionType.HIDEFIELD, dataElementA, null, null, null);
+       
+        actionStore.save( actionA );
+        actionStore.save( actionB );
+        actionStore.save( actionC );
+        
+        Collection<ProgramRuleAction> vars = actionStore.get( programRuleA );
+        
+        assertEquals( 3, vars.size() );
+        assertTrue( vars.contains( actionA ) );
+        assertTrue( vars.contains( actionB ) );
+        assertTrue( vars.contains( actionC ) );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleServiceTest.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,206 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.Assert.*;
+
+public class ProgramRuleServiceTest
+    extends DhisSpringTest
+{
+    private Program programA;
+    private Program programB;
+    private Program programC;
+    
+    private ProgramStage programStageA;
+    private ProgramRule programRuleA;
+    private ProgramRuleAction programRuleActionA;
+    private ProgramRuleAction programRuleActionB;
+    private ProgramRuleVariable programRuleVariableA;
+    private ProgramRuleVariable programRuleVariableB;
+    
+    
+    @Autowired
+    private ProgramService programService;
+    
+    @Autowired
+    private ProgramStageService programStageService;
+    
+    @Autowired
+    private ProgramRuleService programRuleService;
+
+    @Autowired
+    private ProgramRuleActionService programRuleActonService;
+    
+    @Autowired
+    private ProgramRuleVariableService programRuleVariableService;
+    
+    @Override
+    public void setUpTest()
+    {
+        programA = createProgram( 'A', null, null );
+        programB = createProgram( 'B', null, null );
+        programC = createProgram( 'C', null, null );
+        
+        programStageA = createProgramStage( 'A', 1 );
+        programStageA.setProgram( programA );
+        Set<ProgramStage> stagesA = new HashSet<ProgramStage>();
+        stagesA.add( programStageA );
+        programA.setProgramStages( stagesA );
+        
+        programService.addProgram( programA );
+        programService.addProgram( programB );
+        programService.addProgram( programC );
+        
+        programStageService.saveProgramStage( programStageA );
+        
+        //Add a tree of variables, rules and actions to programA:
+        programRuleA = createProgramRule( 'A', programA );
+        programRuleService.addProgramRule( programRuleA );
+        
+        programRuleActionA = createProgramRuleAction( 'A', programRuleA );
+        programRuleActionB = createProgramRuleAction( 'B', programRuleA );
+        programRuleActonService.addProgramRuleAction( programRuleActionA );
+        programRuleActonService.addProgramRuleAction( programRuleActionB );
+        
+        programRuleVariableA = createProgramRuleVariable( 'A', programA );
+        programRuleVariableB = createProgramRuleVariable( 'B', programA );
+        programRuleVariableService.addProgramRuleVariable( programRuleVariableA );
+        programRuleVariableService.addProgramRuleVariable( programRuleVariableB );  
+    }
+    
+    @Test
+    public void testAddGet()
+    {
+        ProgramRule ruleA = new ProgramRule( "RuleA", "descriptionA", programA, programStageA, null, "true", null );
+        ProgramRule ruleB = new ProgramRule( "RuleA", "descriptionA", programA, null, null, "$a < 1", 1 );
+        ProgramRule ruleC = new ProgramRule( "RuleA", "descriptionA", programA, null, null, "($a < 1 && $a > -10) && !$b", 0 );
+        
+        int idA = programRuleService.addProgramRule( ruleA );
+        int idB = programRuleService.addProgramRule( ruleB );
+        int idC = programRuleService.addProgramRule( ruleC );
+        
+        assertEquals( ruleA, programRuleService.getProgramRule( idA ) );
+        assertEquals( ruleB, programRuleService.getProgramRule( idB ) );
+        assertEquals( ruleC, programRuleService.getProgramRule( idC ) );
+    }
+    
+    @Test
+    public void testGetByProgram()
+    {
+        ProgramRule ruleD = new ProgramRule( "RuleD", "descriptionD", programB, null, null, "true", null );
+        ProgramRule ruleE = new ProgramRule( "RuleE", "descriptionE", programB, null, null, "$a < 1", 1 );
+        ProgramRule ruleF = new ProgramRule( "RuleF", "descriptionF", programB, null, null, "($a < 1 && $a > -10) && !$b", 0 );
+        //Add a rule that is not part of programB....
+        ProgramRule ruleG = new ProgramRule( "RuleG", "descriptionG", programA, null, null, "!false", 0 );
+        
+        programRuleService.addProgramRule( ruleD );
+        programRuleService.addProgramRule( ruleE );
+        programRuleService.addProgramRule( ruleF );
+        programRuleService.addProgramRule( ruleG );
+        
+        //Get all the 3 rules for programB
+        Collection<ProgramRule> rules = programRuleService.getProgramRule( programB );
+        assertEquals( 3, rules.size() );
+        assertTrue( rules.contains( ruleD ) );
+        assertTrue( rules.contains( ruleE ) );
+        assertTrue( rules.contains( ruleF ) );
+        //Make sure that the rule connected to program A is not returned as part of collection of rules in program B.
+        assertFalse( rules.contains( ruleG ) );
+        
+    }
+    
+    @Test
+    public void testUpdate()
+    {
+        ProgramRule ruleH = new ProgramRule( "RuleA", "descriptionA", programA, programStageA, null, "true", null );
+        
+        int idH = programRuleService.addProgramRule( ruleH );
+        
+        ruleH.setCondition( "$newcondition == true" );
+        ruleH.setName( "new name" );
+        ruleH.setDescription( "new desc" );
+        ruleH.setPriority( 99 );
+        ruleH.setProgram( programC );
+        
+        programRuleService.updateProgramRule( ruleH );
+        
+        assertEquals( ruleH, programRuleService.getProgramRule( idH ) );
+    }
+    
+    
+
+    @Test
+    public void testDeleteProgramRule()
+    {
+        ProgramRule ruleI = new ProgramRule( "RuleI", "descriptionI", programB, null, null, "true", null );
+        ProgramRule ruleJ = new ProgramRule( "RuleJ", "descriptionJ", programB, null, null, "$a < 1", 1 );
+
+        int idI = programRuleService.addProgramRule( ruleI );
+        int idJ = programRuleService.addProgramRule( ruleJ );
+        
+        assertNotNull( programRuleService.getProgramRule( idI ) );
+        assertNotNull( programRuleService.getProgramRule( idJ ) );
+
+        programRuleService.deleteProgramRule( ruleI );
+
+        assertNull( programRuleService.getProgramRule( idI ) );
+        assertNotNull( programRuleService.getProgramRule( idJ ) );
+
+        programRuleService.deleteProgramRule( ruleJ );
+
+        assertNull( programRuleService.getProgramRule( idI ) );
+        assertNull( programRuleService.getProgramRule( idJ ) );
+    }
+    
+    /*TODO: Fix the functionality for 2 level cascading deletes.
+        
+    @Test
+    public void testCascadingDeleteProgram()
+    {
+        programService.deleteProgram( programA );
+        
+        assertNull( programRuleService.getProgramRule( programRuleA.getId() ) );
+        assertNull( programRuleActonService.getProgramRuleAction( programRuleActionA.getId() ) );
+        assertNull( programRuleActonService.getProgramRuleAction( programRuleActionB.getId() ) );
+        assertNull( programRuleVariableService.getProgramRuleVariable( programRuleVariableA.getId() ) );
+        assertNull( programRuleVariableService.getProgramRuleVariable( programRuleVariableB.getId() ) );
+    }*/
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleStoreTest.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageStore;
+import org.hisp.dhis.program.ProgramStore;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class ProgramRuleStoreTest
+    extends DhisSpringTest
+{
+    public Program programA; 
+    
+    public ProgramStage programStageA;
+    
+    @Autowired
+    public ProgramStore programStore;
+    
+    @Autowired
+    public ProgramStageStore programStageStore;
+    
+    @Autowired
+    public ProgramRuleStore variableStore;
+    
+    @Override
+    public void setUpTest()
+    {
+        programA = createProgram('A', null, null);
+        programStageA = createProgramStage( 'A', 0 );
+        
+        programStore.save( programA );
+        programStageStore.save( programStageA );
+        
+    }
+    
+    @Test
+    public void testGetByProgram()
+    {
+        ProgramRule ruleA = new ProgramRule( "RuleA", "descriptionA", programA, programStageA, null, "true", null );
+        ProgramRule ruleB = new ProgramRule( "RuleA", "descriptionA", programA, null, null, "$a < 1", 1 );
+        ProgramRule ruleC = new ProgramRule( "RuleA", "descriptionA", programA, null, null, "($a < 1 && $a > -10) && !$b", 0 );
+        
+        variableStore.save( ruleA );
+        variableStore.save( ruleB );
+        variableStore.save( ruleC );
+        
+        Collection<ProgramRule> vars = variableStore.get( programA );
+        
+        assertEquals( 3, vars.size() );
+        assertTrue( vars.contains( ruleA ) );
+        assertTrue( vars.contains( ruleB ) );
+        assertTrue( vars.contains( ruleC ) );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableServiceTest.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,165 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.Assert.*;
+
+public class ProgramRuleVariableServiceTest
+    extends DhisSpringTest
+{
+    private Program programA;
+    private Program programB;
+    private Program programC;
+    
+    private DataElement dataElementA;
+    private TrackedEntityAttribute attributeA;
+    
+    @Autowired
+    private ProgramService programService;
+    
+    @Autowired
+    private DataElementService dataElementService;
+    
+    @Autowired
+    private TrackedEntityAttributeService attributeService;
+    
+    @Autowired
+    private ProgramRuleVariableService variableService;
+    
+    @Override
+    public void setUpTest()
+    {
+        programA = createProgram( 'A', null, null );
+        programB = createProgram( 'B', null, null );
+        programC = createProgram( 'C', null, null );
+        
+        dataElementA = createDataElement( 'A' );
+        attributeA = createTrackedEntityAttribute( 'A' );
+        
+        programService.addProgram( programA );
+        programService.addProgram( programB );
+        programService.addProgram( programC );
+        dataElementService.addDataElement( dataElementA );
+        attributeService.addTrackedEntityAttribute( attributeA );
+    }
+    
+    @Test
+    public void testAddGet()
+    {
+        ProgramRuleVariable variableA = new ProgramRuleVariable( "RuleVariableA", programA, ProgramRuleVariableSourceType.DATAELEMENT_CURRENT_EVENT, null, dataElementA, null );
+        ProgramRuleVariable variableB = new ProgramRuleVariable( "RuleVariableB", programA, ProgramRuleVariableSourceType.TEI_ATTRIBUTE, attributeA, null, null );
+        ProgramRuleVariable variableC = new ProgramRuleVariable( "RuleVariableC", programA, ProgramRuleVariableSourceType.CALCULATED_VALUE, null, null, null );
+        
+        int idA = variableService.addProgramRuleVariable( variableA );
+        int idB = variableService.addProgramRuleVariable( variableB );
+        int idC = variableService.addProgramRuleVariable( variableC );
+        
+        assertEquals( variableA, variableService.getProgramRuleVariable( idA ) );
+        assertEquals( variableB, variableService.getProgramRuleVariable( idB ) );
+        assertEquals( variableC, variableService.getProgramRuleVariable( idC ) );
+    }
+    
+    @Test
+    public void testGetByProgram()
+    {
+        ProgramRuleVariable variableD = new ProgramRuleVariable( "RuleVariableD", programB, ProgramRuleVariableSourceType.DATAELEMENT_CURRENT_EVENT, null, dataElementA, null );
+        ProgramRuleVariable variableE = new ProgramRuleVariable( "RuleVariableE", programB, ProgramRuleVariableSourceType.TEI_ATTRIBUTE, attributeA, null, null );
+        ProgramRuleVariable variableF = new ProgramRuleVariable( "RuleVariableF", programB, ProgramRuleVariableSourceType.CALCULATED_VALUE, null, null, null );
+         //Add a var that is not part of programB....
+        ProgramRuleVariable variableG = new ProgramRuleVariable( "RuleVariableG", programA, ProgramRuleVariableSourceType.CALCULATED_VALUE, null, null, null );
+        
+        variableService.addProgramRuleVariable( variableD );
+        variableService.addProgramRuleVariable( variableE );
+        variableService.addProgramRuleVariable( variableF );
+        variableService.addProgramRuleVariable( variableG );
+
+        //Get all the 3 rules for programB
+        Collection<ProgramRuleVariable> vars = variableService.getProgramRuleVariable( programB );
+        assertEquals( 3, vars.size() );
+        assertTrue( vars.contains( variableD ) );
+        assertTrue( vars.contains( variableE ) );
+        assertTrue( vars.contains( variableF ) );
+        //Make sure that the var connected to program A is not returned as part of collection of vars in program B.
+        assertFalse( vars.contains( variableG ) );
+        
+    }
+    
+    @Test
+    public void testUpdate()
+    {
+        ProgramRuleVariable variableH = new ProgramRuleVariable( "RuleVariableH", programA, ProgramRuleVariableSourceType.CALCULATED_VALUE, null, null, null );
+        
+        int idH = variableService.addProgramRuleVariable( variableH );
+        
+        variableH.setAttribute( attributeA );
+        variableH.setDataElement( dataElementA );
+        variableH.setName( "newname" );
+        variableH.setProgram( programC );
+        variableH.setSourceType( ProgramRuleVariableSourceType.DATAELEMENT_PREVIOUS_EVENT );
+                
+        variableService.updateProgramRuleVariable( variableH );
+        
+        assertEquals( variableH, variableService.getProgramRuleVariable( idH ) );
+    }
+    
+    @Test
+    public void testDeleteProgramRuleVariable()
+    {
+        ProgramRuleVariable ruleVariableI = new ProgramRuleVariable( "RuleVariableI", programA, ProgramRuleVariableSourceType.DATAELEMENT_CURRENT_EVENT, null, dataElementA, null );
+        ProgramRuleVariable ruleVariableJ = new ProgramRuleVariable( "RuleVariableJ", programA, ProgramRuleVariableSourceType.TEI_ATTRIBUTE, attributeA, null, null );
+
+        int idI = variableService.addProgramRuleVariable( ruleVariableI );
+        int idJ = variableService.addProgramRuleVariable( ruleVariableJ );
+        
+        assertNotNull( variableService.getProgramRuleVariable( idI ) );
+        assertNotNull( variableService.getProgramRuleVariable( idJ ) );
+
+        variableService.deleteProgramRuleVariable( ruleVariableI );
+
+        assertNull( variableService.getProgramRuleVariable( idI ) );
+        assertNotNull( variableService.getProgramRuleVariable( idJ ) );
+
+        variableService.deleteProgramRuleVariable( ruleVariableJ );
+
+        assertNull( variableService.getProgramRuleVariable( idI ) );
+        assertNull( variableService.getProgramRuleVariable( idJ ) );
+    }
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/programrule/ProgramRuleVariableStoreTest.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.programrule;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementStore;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStore;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class ProgramRuleVariableStoreTest
+    extends DhisSpringTest
+{
+    public Program programA; 
+    
+    public DataElement dataelementA;
+    
+    @Autowired
+    public ProgramStore programStore;
+    
+    @Autowired
+    public DataElementStore dataElementStore;
+    
+    @Autowired
+    public ProgramRuleVariableStore variableStore;
+    
+    @Override
+    public void setUpTest()
+    {
+        programA = createProgram('A', null, null);
+        dataelementA = createDataElement('A');
+        
+        programStore.save( programA );
+        dataElementStore.save( dataelementA );
+        
+    }
+    
+    @Test
+    public void testGetByProgram()
+    {
+        ProgramRuleVariable varA = new ProgramRuleVariable( "VarA", programA, ProgramRuleVariableSourceType.DATAELEMENT_CURRENT_EVENT, null, dataelementA, null);
+        ProgramRuleVariable varB = new ProgramRuleVariable( "VarB", programA, ProgramRuleVariableSourceType.DATAELEMENT_NEWEST_EVENT_PROGRAM, null, dataelementA, null);
+        ProgramRuleVariable varC = new ProgramRuleVariable( "VarC", programA, ProgramRuleVariableSourceType.CALCULATED_VALUE, null, null, null);
+        
+        variableStore.save( varA );
+        variableStore.save( varB );
+        variableStore.save( varC );
+        
+        Collection<ProgramRuleVariable> vars = variableStore.get( programA );
+        
+        assertEquals( 3, vars.size() );
+        assertTrue( vars.contains( varA ) );
+        assertTrue( vars.contains( varB ) );
+        assertTrue( vars.contains( varC ) );
+    }
+}

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2015-02-24 13:16:58 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2015-03-13 08:24:36 +0000
@@ -76,6 +76,9 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.programrule.ProgramRule;
+import org.hisp.dhis.programrule.ProgramRuleAction;
+import org.hisp.dhis.programrule.ProgramRuleVariable;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageInstance;
@@ -604,6 +607,33 @@
     public void deleteProgramStageInstance( ProgramStageInstance programStageInstance )
     {
     }
+    
+    public String allowDeleteProgramRule( ProgramRule programRule )
+    {
+        return null;
+    }
+
+    public void deleteProgramRule( ProgramRule programRule )
+    {
+    }
+    
+    public String allowDeleteProgramRuleVariable( ProgramRuleVariable programRuleVariable )
+    {
+        return null;
+    }
+
+    public void deleteProgramRuleVariable( ProgramRuleVariable programRuleVariable )
+    {
+    }
+    
+    public String allowDeleteProgramRuleAction( ProgramRuleAction programRuleAction )
+    {
+        return null;
+    }
+
+    public void deleteProgramRuleAction( ProgramRuleAction programRuleAction )
+    {
+    }
 
     public String allowDeleteProgramStageDataElement( ProgramStageDataElement programStageDataElement )
     {

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2015-03-10 11:36:58 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2015-03-13 08:24:36 +0000
@@ -84,6 +84,9 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.programrule.ProgramRule;
+import org.hisp.dhis.programrule.ProgramRuleAction;
+import org.hisp.dhis.programrule.ProgramRuleVariable;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
@@ -1134,6 +1137,54 @@
         
         return program;
     }
+    
+    public static ProgramRule createProgramRule ( char uniqueCharacter )
+    {
+        ProgramRule programRule = new ProgramRule();
+        programRule.setName( "ProgramRule" + uniqueCharacter );
+    
+        return programRule;
+    }
+    
+    public static ProgramRule createProgramRule ( char uniqueCharacter, Program parentProgram )
+    {
+        ProgramRule programRule = createProgramRule( uniqueCharacter );
+        programRule.setProgram( parentProgram );
+    
+        return programRule;
+    }
+    
+    public static ProgramRuleAction createProgramRuleAction ( char uniqueCharacter )
+    {
+        ProgramRuleAction programRuleAction = new ProgramRuleAction();
+        programRuleAction.setName( "ProgramRuleAction" + uniqueCharacter );
+    
+        return programRuleAction;
+    }
+    
+    public static ProgramRuleAction createProgramRuleAction ( char uniqueCharacter, ProgramRule parentRule )
+    {
+        ProgramRuleAction programRuleAction = createProgramRuleAction( uniqueCharacter );
+        programRuleAction.setProgramRule( parentRule );
+    
+        return programRuleAction;
+    }
+    
+    public static ProgramRuleVariable createProgramRuleVariable ( char uniqueCharacter )
+    {
+        ProgramRuleVariable programRuleVariable = new ProgramRuleVariable();
+        programRuleVariable.setName( "ProgramRuleVariable" + uniqueCharacter );
+    
+        return programRuleVariable;
+    }
+    
+    public static ProgramRuleVariable createProgramRuleVariable ( char uniqueCharacter, Program parentProgram )
+    {
+        ProgramRuleVariable programRuleVariable = createProgramRuleVariable( uniqueCharacter );
+        programRuleVariable.setProgram( parentProgram );
+        
+        return programRuleVariable;
+    }
 
     public static ProgramStage createProgramStage( char uniqueCharacter, int minDays )
     {

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleActionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleActionController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleActionController.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,46 @@
+package org.hisp.dhis.webapi.controller.event;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.programrule.ProgramRuleAction;
+import org.hisp.dhis.schema.descriptors.ProgramRuleActionSchemaDescriptor;
+import org.hisp.dhis.webapi.controller.AbstractCrudController;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ *
+ * @author markusbekken
+ */
+@Controller
+@RequestMapping( value = ProgramRuleActionSchemaDescriptor.API_ENDPOINT )
+public class ProgramRuleActionController
+    extends AbstractCrudController<ProgramRuleAction>
+{
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleController.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,46 @@
+package org.hisp.dhis.webapi.controller.event;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.programrule.ProgramRule;
+import org.hisp.dhis.schema.descriptors.ProgramRuleSchemaDescriptor;
+import org.hisp.dhis.webapi.controller.AbstractCrudController;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ *
+ * @author markusbekken
+ */
+@Controller
+@RequestMapping( value = ProgramRuleSchemaDescriptor.API_ENDPOINT )
+public class ProgramRuleController
+    extends AbstractCrudController<ProgramRule>
+{
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleVariableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleVariableController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramRuleVariableController.java	2015-03-13 08:24:36 +0000
@@ -0,0 +1,46 @@
+package org.hisp.dhis.webapi.controller.event;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.programrule.ProgramRuleVariable;
+import org.hisp.dhis.schema.descriptors.ProgramRuleVariableSchemaDescriptor;
+import org.hisp.dhis.webapi.controller.AbstractCrudController;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ *
+ * @author markusbekken
+ */
+@Controller
+@RequestMapping( value = ProgramRuleVariableSchemaDescriptor.API_ENDPOINT )
+public class ProgramRuleVariableController
+    extends AbstractCrudController<ProgramRuleVariable>
+{
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.filters.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.filters.js	2015-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.filters.js	2015-03-13 08:24:36 +0000
@@ -86,6 +86,31 @@
     };
 })
 
+/* trim away all single and double quotes in the start and end of a string*/
+.filter('trimquotes', function() {
+    return function(input) {
+        if (!input || (typeof input !== 'string' && !(input instanceof String))) {
+            return input;
+        }
+        
+        var beingTrimmed = input;
+        var trimmingComplete = false;
+        //Trim until no more quotes can be removed.
+        while(!trimmingComplete) {
+            var beforeTrimming = beingTrimmed;
+            beingTrimmed = input.replace(/^'/,"").replace(/'$/,"");
+            beingTrimmed = beingTrimmed.replace(/^"/,"").replace(/"$/,"");
+            
+            if(beforeTrimming.length === beingTrimmed.length) {
+                trimmingComplete = true;
+            }
+        }
+        
+        
+        return beingTrimmed;
+    };
+})
+
 .filter('forLoop', function() {
     return function(input, start, end) {
         input = new Array(end - start);