We hope you'll join us for our 4/23 webinar on using data tables to apply reference ranges and AE codes in OC4. For more information and to register, visit https://register.gotowebinar.com/register/2882170018956684555

How can I assign a number to a field based on the input in a previous field

kristiakkristiak Posts: 1,339 ✭✭✭

I have 14 different questions and for each question there are three choices that will result in either a 2, a 1 or a 0  in the in COLUMN Q (REsponse values...). How can I set a value in an other field to 1  if the above field is =2

Thos is probanly very simply but the OC database is off line

Regards


Krister    

Comments

  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    via Email
    Since you have response options, the option for using a calculation with
    Decode is not available.

    You can instead use an insertaction rule type, or JavaScript. I think I
    have written about the former on this forum before (use Value attribute in
    the ruleref), and for the latter there are the wiki book articles (add a
    span with an id to the source and target items, set the target value on
    keyup or click).

    If you have trouble with either post your code for help.
  • kristiakkristiak Posts: 1,339 ✭✭✭
    via Email
    Well Lindsay, maybe I have been lazy and tried to use the func: Sum(field1+filed2+field3........) The problem is that I only want the results of Yes or No to be calculated while the third option should not be considered.

    It looks like this in the Excel sheet

    Column P Response Options Column Q, Response Values or Calculations
    Yes, No, Other 1, 0, 99
    Yes, No, Other 0, 1, 99
    Yes, No, Other 0, 1, 99
    .
    .
    .I have 14 such variables and need to add up the correct responses to yield a maximum of 14 points for all answers correct.


    An so on. The reason the values in Column Q changes is due to the fact the patient answers different questions with YES or NO. In column Q the value "1" is assigned if "YES" is correct and if "NO" is correct this will be assigned a 1. The third alternative should not give any value.

    I then want to summarize in another filed by using the calculate function func: Sum(field1+filed2+field3........). The problem is how to restrict the calculation to the YES and No fields. May I need a rule! I have to use different numbers but the problems is I really would need to assign "0" to both Yes/No and to Other.
    I have tried to use a separate field for Other but if I do not click on either Yes/No and leave the field bland and use the "Other" field then the calculation does not work. I have ran out of ideas. I'm not so great with writing rules.

    Regards

    Krister
  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    via Email
    OK so insert rule is no good here since you can only use it to copy values
    or conditionally insert a static value.

    Since you have few response options you can use decode inside the sum (its
    tedious but possible for larger response sets, and lets you avoid double
    coding an item for the sake of calculation)

    For example:

    sum(decode(field1,1,1,0),decode(field2,1,1,0),decode(field3,1,1,0))

    and so on. Each decode is saying, if there is a 1 then return 1, otherwise
    return 0. Jessica's post [1] has more examples.

    If you want to use JavaScript, the expression would be much the same,
    except using if and else statements in place of decode.

    [1] http://blog.openclinica.com/2014/10/22/demystifying-the-decode-function/
  • kristiakkristiak Posts: 1,339 ✭✭✭
    Thanks Lindsay, I will try this and let you know.
  • kristiakkristiak Posts: 1,339 ✭✭✭

    Thanks for all your help, Yours and Jessicas posts were very helpful and I finnaly ended up with this calculation, and it worked perfectly.

    func:sum(decode(NGTA1,0,0,1,1,99,0),decode(NGTA2,0,0,1,1,99,0),decode(NGTA3,0,0,1,1,99,0),decode(NGTA4,0,0,1,1,99,0),decode(NGTA5,0,0,1,1,99,0),decode(NGTA6,0,0,1,1,99,0),decode(NGTA7,0,0,1,1,99,0),decode(NGTA8,0,0,1,1,99,0),decode(NGTA9,0,0,1,1,99,0),decode(NGTA10,0,0,1,1,99,0),decode(NGTA11,0,0,1,1,99,0),decode(NGTA12,0,0,1,1,99,0),decode(NGTA13,0,0,1,1,99,0),decode(NGTA14,0,0,1,1,99,0))

    Best regards

    Krister


This discussion has been closed.