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

Hi,

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!

Comments

  • 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,
    Lindsay

    [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">
    $.noConflict();
    jQuery(document).ready(function($){
        //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){
                fieldKoos-s.val(Symptom);
                fieldKoos-s.change();        
        }
    function calculatePain(){
            
            if (fieldKoos-p-mis < 5) {
        
                var Pain = fieldKoos-p;
                }
            else {
                var Pain = "999";
                }
            if (fieldKoos-p.val() != Pain){
                fieldKoos-p.val(Pain);
                fieldKoos-p.change();        
        }    



    // fire when anything is entered
        fieldKoos-p-mis.keyup(function(){
            calculateSympt();
            calculatePain();
        });
        
    fieldKoos-test.keyup(function(){
            calculateSympt();
            calculatePain();
        });


    });
    </script>
  • GerbenRienkGerbenRienk Posts: 795 ✭✭✭
    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>
    <script>
    $.noConflict();
    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(){
    numberOfMissings=0;
    totalScore=0;
    for (var i=1; i <= 7; i++){
    if (fld[i].val()==999){
    numberOfMissings=numberOfMissings+1;
    }
    else{
    totalScore=totalScore+Number(fld[i].val());
    };
    if (numberOfMissings > 3){
    totalScore=999;
    }
    console.log("number of missings: " + numberOfMissings);
    console.log("total score: " + totalScore);

    };
    fld[7].keyup(function(){
      calculateScore();
      });
    calculateScore();
    })
    </script>

This discussion has been closed.