It is best if you have had training in writing code in Javascript. If that's the case, you can easily write your code yourself. If you are not yet proficient in Javascript, this might be a handy page for you. Below are some snippets of code, matching specific question types. You can use this code when building your computations.
Summarizing the values of single choice questions
If you want to summarize all answer values and add them to a total score, this is the code for you:
var computations = { phq9_score: function(data){ var sum = 0; sum += data.q1; sum += data.q2; sum += data.q3; sum += data.q4; sum += data.q5; sum += data.q6; sum += data.q7; sum += data.q8; sum += data.q9; return sum; } };
- phq9_score = name of the computation
- q1, q2, q3… = names of the questions in CMS
Summarizing the values of multiple choice question(s)
Some questionnaires have multiple choice questions where it is necessary to sum up all the values that the clients choses for the result. For example:
Which symptoms did you experience during the panic attack?
- pounding or racing heart (1 point)
- trembling (1 point)
- chest pain (1 point)
- difficulty breathing (1 point)
var computations = { panic_symptoms: function(data) { var total = 0; for (var i in data.symptoms) { total += parseInt(data.symptoms[i]); } return total; } };
- panic_symptoms = name of the computation
- symptoms = name of the multiple choice question in CMS
Summarizing the values of more than one multiple choice question
It is also possible to set different values for every answer option or sum up answers from more than one multiple choice question. For that, copy the code below. Replace "symptoms" with the name of the other question and change the letter i to another. In this example the names of 2 seperate questions are visible 'symptoms' and 'behaviour'.
panic_symptoms: function(data) { var total = 0; // first question called "symptoms" for (var i in data.symptoms) { total += parseInt(data.symptoms[i]); } // second question called "behaviour" for (var j in data.behaviour) { total += parseInt(data.behaviour[j]); } return total; }
- panic_symptoms = name of the computation
- symptoms = name of the question
- behaviour = name of the question