31 Dec 2018: Thank you to our knowledgeable and friendly forums users for another great year. We are aware of the uptick in spam accounts and are doing our best to ban these at first sight. Thank you for your patience!

calculation only allowed if enough items entered


I want to calculation a Score with 7 items. Each item has 6 values (0,1,2,3,4,999). 999 is for not entered.
To calculate the score, 4 ore more items must be entered.
So I made a "help" calculation, which calculates how many items are not entered:

calc_missing               func: ((Item1+Item2+Item3+Item4+Item5+Item6+Item7)/999)

worked perfectly
for score calculation I used following funktion:
score                         func: decode(calc_missing,>3,999,(100-(((((Item1+Item2+Item3+Item4+Item5+Item6+Item7)-(999*calc_missing))/(7-calc_missing))*100)/4)))

the calculation works but >3 is ingnored...I found out that decode can't handle > or <

Now my question ist, how can I handle this problem without RuleDesigner?

Thanks for your help!


  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    via Email
    Hi Leonard

    Alicia provided a solution to a similar problem in this post [1]. Although,
    this requires that every item has a value, and probably wont cover the '4
    or more items' requirement.

    The alternative is to use javascript. There are some examples of this at
    [2] and [3].

    Best regards,

    [1] https://forums.openclinica.com/discussion/comment/15052/#Comment_15052
    [2] http://www.trialdatasolutions.com/tds/howto/usingregexpfortimefield.jsp
    [3] http://www.trialdatasolutions.com/tds/howto/eventdateincrf.jsp
  • leonardleonard Posts: 4
    Hi Lindsay,

    Thanks for your answer!
    I tried to integrate the javascript, lile trialdatasolutions
    but nothing happens...

    here is my script (I'm using OC 3.3):

    <script src="includes/jmesa/jquery.min.js">// for OC versions before 3.1.4, use jquery-1.3.2.min.js !</script>
    <script lang="Javascript">
        //find out who's who
        var fieldKoos-s = $("#koos-s").parent().parent().find("input");
        var fieldKoos-p = $("#koos-p").parent().parent().find("input");
        var fieldKoos-s-mis = $("#koos-s-missing").parent().parent().find("input");    
        var fieldKoos-p-mis = $("#koos-p-missing").parent().parent().find("input");
        var fieldKoos-test = $("#koos-test").parent().parent().find("input");

    function calculateSympt(){
            if (fieldKoos-s-mis > 3) {
                var Symptom = 999;
            if (fieldKoos-s.val() != Symptom){
    function calculatePain(){
            if (fieldKoos-p-mis < 5) {
                var Pain = fieldKoos-p;
            else {
                var Pain = "999";
            if (fieldKoos-p.val() != Pain){

    // fire when anything is entered

  • GerbenRienkGerbenRienk Posts: 799 ✭✭✭
    Hi Leonard,
    Maybe you could use an array to loop through the items. I tested it with <div id="I1"></div>, <div id="I2"></div>, etc  and then your code would be like below:
    I hope this gives you enough info to get started.
    Kind regards,
    Gerben Rienk

    <script src="includes/jmesa/jquery.min.js"></script>
    jQuery(document).ready(function($) { 
    var fld=[];
    var divName;
    var numberOfMissings;
    var totalScore;
    for (var i=1; i<=7; i++){
    divname="#I" + i;
    fld[i] = $(divname).parent().parent().find("input");
    function calculateScore(){
    for (var i=1; i <= 7; i++){
    if (fld[i].val()==999){
    if (numberOfMissings > 3){
    console.log("number of missings: " + numberOfMissings);
    console.log("total score: " + totalScore);


This discussion has been closed.