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.
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;
}
};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?
var computations = {
panic_symptoms: function(data) {
var total = 0;
for (var i in data.symptoms) {
total += parseInt(data.symptoms[i]);
}
return total;
}
};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;
}