From 45511a0915ddf8dd5f1ed02a8da3da854604ca5b Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 24 Sep 2025 10:05:20 +0300 Subject: [PATCH 1/2] Calculate the total score without using JS code --- categories/quiz/QuestionnaireScoring.markdown | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 categories/quiz/QuestionnaireScoring.markdown diff --git a/categories/quiz/QuestionnaireScoring.markdown b/categories/quiz/QuestionnaireScoring.markdown new file mode 100644 index 0000000..654a64a --- /dev/null +++ b/categories/quiz/QuestionnaireScoring.markdown @@ -0,0 +1,195 @@ +# Questionnaire Scoring for Medical Forms + +## Problem +Doctors need to create tailored questionnaires for their practice without coding expertise, including the ability to calculate numerical scores based on patient responses to guide treatment plans. The scoring varies by form, such as the PHQ-9 for depression screening or custom true/false eligibility checks. + +## Solution +You can use SurveyJS Creator to enable doctors to design questionnaires with built-in scoring logic. For numerical scoring (e.g., PHQ-9), assign values to radiogroup choices or matrix dropdowns and sum them using expressions. For conditional logic (e.g., eligibility screening), define calculated variables with initial values and update them based on triggers using expressions like `iif`. This approach requires no JavaScript coding and is configurable within the form designer. + +#### Survey JSON Schema for PHQ-9 Scoring +Radiogroup questions with numerical values (0–3) summed via an expression for a total score. +```json +{ + "title": "PATIENT HEALTH QUESTIONNAIRE-9 (PHQ-9)", + "pages": [ + { + "name": "Page 1", + "title": "Over the last 2 weeks, how often have you been bothered by any of the following problems?", + "elements": [ + { + "type": "radiogroup", + "name": "q1", + "title": "Little interest or pleasure in doing things", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q2", + "title": "Feeling down, depressed, or hopeless", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q3", + "title": "Trouble falling or staying asleep, or sleeping too much", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q4", + "title": "Feeling tired or having little energy", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q5", + "title": "Poor appetite or overeating", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q6", + "title": "Feeling bad about yourself — or that you are a failure or have let yourself or your family down", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q7", + "title": "Trouble concentrating on things, such as reading the newspaper or watching television", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q8", + "title": "Moving or speaking so slowly that other people could have noticed? Or the opposite — being so fidgety or restless that you have been moving around a lot more than usual", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q9", + "title": "Thoughts that you would be better off dead or of hurting yourself in some way", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "expression", + "name": "totalScoreInfo", + "title": "Total Score", + "titleLocation": "left", + "expression": "{q1} + {q2} + {q3} + {q4} + {q5} + {q6} + {q7} + {q8} + {q9}" + } + ] + } + ], + "showQuestionNumbers": "on" +} +``` + +#### Survey JSON Schema for Eligibility Screening +A calculated variable `isIllegible` initialized to `true`. This variable is updated to `false` based on conditions (`q1='none' and q3=10 or q5='All'`) using the `iif` function. + +```json +{ + "title": "Eligibility Screening Survey", + "pages": [ + { + "name": "page1", + "elements": [ + { + "type": "radiogroup", + "name": "q1", + "title": "Q1. Select an option", + "isRequired": true, + "choices": [ + "none", + "option1", + "option2" + ] + }, + { + "type": "text", + "name": "q3", + "title": "Q3. Enter a number", + "isRequired": true, + "inputType": "number" + }, + { + "type": "radiogroup", + "name": "q5", + "title": "Q5. Select one", + "isRequired": true, + "choices": [ + "All", + "Some", + "None" + ] + }, + { + "type": "expression", + "name": "isIllegibleResult", + "title": "Patient Illegibility Status", + "expression": "{eligibilityCheck}" + } + ] + } + ], + "calculatedValues": [ + { + "name": "isIllegible", + "expression": "true" + }, + { + "name": "eligibilityCheck", + "expression": "iif(({q1} = 'none' and {q3} = 10) or {q5} = 'All', false, {isIllegible})" + } + ] +} +``` + +## Learn More + +* [SurveyJS Conditional Logic and Expression Functions](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#expressions) \ No newline at end of file From 3c141092d9f1c793d177f7c9e84f337709b1549d Mon Sep 17 00:00:00 2001 From: RomanTsukanov Date: Thu, 25 Sep 2025 13:50:16 +0400 Subject: [PATCH 2/2] Update the article --- categories/quiz/QuestionnaireScoring.markdown | 195 -------------- .../create-a-scored-survey-without-js-code.md | 238 ++++++++++++++++++ 2 files changed, 238 insertions(+), 195 deletions(-) delete mode 100644 categories/quiz/QuestionnaireScoring.markdown create mode 100644 categories/quiz/create-a-scored-survey-without-js-code.md diff --git a/categories/quiz/QuestionnaireScoring.markdown b/categories/quiz/QuestionnaireScoring.markdown deleted file mode 100644 index 654a64a..0000000 --- a/categories/quiz/QuestionnaireScoring.markdown +++ /dev/null @@ -1,195 +0,0 @@ -# Questionnaire Scoring for Medical Forms - -## Problem -Doctors need to create tailored questionnaires for their practice without coding expertise, including the ability to calculate numerical scores based on patient responses to guide treatment plans. The scoring varies by form, such as the PHQ-9 for depression screening or custom true/false eligibility checks. - -## Solution -You can use SurveyJS Creator to enable doctors to design questionnaires with built-in scoring logic. For numerical scoring (e.g., PHQ-9), assign values to radiogroup choices or matrix dropdowns and sum them using expressions. For conditional logic (e.g., eligibility screening), define calculated variables with initial values and update them based on triggers using expressions like `iif`. This approach requires no JavaScript coding and is configurable within the form designer. - -#### Survey JSON Schema for PHQ-9 Scoring -Radiogroup questions with numerical values (0–3) summed via an expression for a total score. -```json -{ - "title": "PATIENT HEALTH QUESTIONNAIRE-9 (PHQ-9)", - "pages": [ - { - "name": "Page 1", - "title": "Over the last 2 weeks, how often have you been bothered by any of the following problems?", - "elements": [ - { - "type": "radiogroup", - "name": "q1", - "title": "Little interest or pleasure in doing things", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q2", - "title": "Feeling down, depressed, or hopeless", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q3", - "title": "Trouble falling or staying asleep, or sleeping too much", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q4", - "title": "Feeling tired or having little energy", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q5", - "title": "Poor appetite or overeating", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q6", - "title": "Feeling bad about yourself — or that you are a failure or have let yourself or your family down", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q7", - "title": "Trouble concentrating on things, such as reading the newspaper or watching television", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q8", - "title": "Moving or speaking so slowly that other people could have noticed? Or the opposite — being so fidgety or restless that you have been moving around a lot more than usual", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "radiogroup", - "name": "q9", - "title": "Thoughts that you would be better off dead or of hurting yourself in some way", - "choices": [ - { "value": "0", "text": "Not at all" }, - { "value": "1", "text": "Several days" }, - { "value": "2", "text": "More than half the days" }, - { "value": "3", "text": "Nearly every day" } - ] - }, - { - "type": "expression", - "name": "totalScoreInfo", - "title": "Total Score", - "titleLocation": "left", - "expression": "{q1} + {q2} + {q3} + {q4} + {q5} + {q6} + {q7} + {q8} + {q9}" - } - ] - } - ], - "showQuestionNumbers": "on" -} -``` - -#### Survey JSON Schema for Eligibility Screening -A calculated variable `isIllegible` initialized to `true`. This variable is updated to `false` based on conditions (`q1='none' and q3=10 or q5='All'`) using the `iif` function. - -```json -{ - "title": "Eligibility Screening Survey", - "pages": [ - { - "name": "page1", - "elements": [ - { - "type": "radiogroup", - "name": "q1", - "title": "Q1. Select an option", - "isRequired": true, - "choices": [ - "none", - "option1", - "option2" - ] - }, - { - "type": "text", - "name": "q3", - "title": "Q3. Enter a number", - "isRequired": true, - "inputType": "number" - }, - { - "type": "radiogroup", - "name": "q5", - "title": "Q5. Select one", - "isRequired": true, - "choices": [ - "All", - "Some", - "None" - ] - }, - { - "type": "expression", - "name": "isIllegibleResult", - "title": "Patient Illegibility Status", - "expression": "{eligibilityCheck}" - } - ] - } - ], - "calculatedValues": [ - { - "name": "isIllegible", - "expression": "true" - }, - { - "name": "eligibilityCheck", - "expression": "iif(({q1} = 'none' and {q3} = 10) or {q5} = 'All', false, {isIllegible})" - } - ] -} -``` - -## Learn More - -* [SurveyJS Conditional Logic and Expression Functions](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#expressions) \ No newline at end of file diff --git a/categories/quiz/create-a-scored-survey-without-js-code.md b/categories/quiz/create-a-scored-survey-without-js-code.md new file mode 100644 index 0000000..0b6ebd5 --- /dev/null +++ b/categories/quiz/create-a-scored-survey-without-js-code.md @@ -0,0 +1,238 @@ +# Create a Scored Questionnaire Without JavaScript Code in SurveyJS + +## Problem + +Doctors often need to build custom questionnaires for their practice without coding. These forms may need to calculate scores from patient responses to support treatment decisions. Scoring rules vary: for example, the PHQ-9 for depression screening uses summed values, while eligibility checks rely on true/false conditions. + +## Solution + +Even without JavaScript, you can implement scoring in two ways: + +- **Multiple-choice scoring (dropdowns, radio groups)** +Assign numeric values to answer options and use an expression to sum them into a total score. See [Survey JSON Schema for PHQ-9 Scoring](#survey-json-schema-for-phq-9-scoring). + +- **Calculated values** +For yes/no eligibility rules, create a calculated value with an expression that evaluates conditions (e.g., "age over 18 and not pregnant"). See [Survey JSON Schema for Eligibility Screening](#survey-json-schema-for-eligibility-screening). + +### Survey JSON Schema for PHQ-9 Scoring + +```json +{ + "title": "PATIENT HEALTH QUESTIONNAIRE-9 (PHQ-9)", + "pages": [ + { + "name": "page1", + "title": "Over the last 2 weeks, how often have you been bothered by any of the following problems?", + "elements": [ + { + "type": "radiogroup", + "name": "q1", + "title": "Little interest or pleasure in doing things", + "choices": [ + { "value": "0", "text": "Not at all" }, + { "value": "1", "text": "Several days" }, + { "value": "2", "text": "More than half the days" }, + { "value": "3", "text": "Nearly every day" } + ] + }, + { + "type": "radiogroup", + "name": "q2", + "title": "Feeling down, depressed, or hopeless", + "choicesFromQuestion": "q1" + }, + { + "type": "radiogroup", + "name": "q3", + "title": "Trouble falling or staying asleep, or sleeping too much", + "choicesFromQuestion": "q1" + + }, + { + "type": "radiogroup", + "name": "q4", + "title": "Feeling tired or having little energy", + "choicesFromQuestion": "q1" + }, + { + "type": "radiogroup", + "name": "q5", + "title": "Poor appetite or overeating", + "choicesFromQuestion": "q1" + }, + { + "type": "radiogroup", + "name": "q6", + "title": "Feeling bad about yourself — or that you are a failure or have let yourself or your family down", + "choicesFromQuestion": "q1" + }, + { + "type": "radiogroup", + "name": "q7", + "title": "Trouble concentrating on things, such as reading the newspaper or watching television", + "choicesFromQuestion": "q1" + }, + { + "type": "radiogroup", + "name": "q8", + "title": "Moving or speaking so slowly that other people could have noticed? Or the opposite — being so fidgety or restless that you have been moving around a lot more than usual", + "choicesFromQuestion": "q1" + }, + { + "type": "radiogroup", + "name": "q9", + "title": "Thoughts that you would be better off dead or of hurting yourself in some way", + "choicesFromQuestion": "q1" + }, + { + "type": "expression", + "name": "totalScoreInfo", + "title": "Total Score: ", + "titleLocation": "left", + "showNumber": false, + "expression": "{q1} + {q2} + {q3} + {q4} + {q5} + {q6} + {q7} + {q8} + {q9}" + } + ] + } + ], + "showQuestionNumbers": true +} +``` + +[Open in Plunker](https://plnkr.co/edit/GiNUr7uq0PfqCftM) + +### Survey JSON Schema for Eligibility Screening + + + +```json +{ + "title": "Medical Eligibility Screening Survey", + "description": "Please answer the following questions honestly to help us determine your eligibility.", + "calculatedValues": [ + { + "name": "isEligible", + "expression": "age({dob}) >= 18 and !{pregnant} and !({conditions} anyof ['Heart disease','Cancer','Immunodeficiency'])", + "includeIntoResult": true + } + ], + "pages": [ + { + "name": "basic_info", + "elements": [ + { + "type": "text", + "name": "fullName", + "title": "Full Name", + "isRequired": true + }, + { + "type": "text", + "inputType": "date", + "name": "dob", + "title": "Date of Birth", + "isRequired": true + }, + { + "type": "radiogroup", + "name": "gender", + "title": "Gender", + "isRequired": true, + "choices": ["Male", "Female", "Other", "Prefer not to say"] + } + ] + }, + { + "name": "medical_history", + "elements": [ + { + "type": "checkbox", + "name": "conditions", + "title": "Do you have or have you ever been diagnosed with any of the following?", + "isRequired": true, + "choices": [ + "Heart disease", + "High blood pressure", + "Diabetes", + "Asthma or other respiratory condition", + "Cancer", + "Immunodeficiency" + ], + "showNoneItem": true, + "noneText": "None of the above", + }, + { + "type": "boolean", + "name": "pregnant", + "title": "Are you currently pregnant?", + "visibleIf": "{gender} = 'Female'" + }, + { + "type": "boolean", + "name": "medications", + "title": "Are you currently taking any prescription medications?" + }, + { + "type": "comment", + "name": "medications_list", + "title": "If yes, please list them", + "visibleIf": "{medications} = true" + } + ] + }, + { + "name": "risk_factors", + "elements": [ + { + "type": "boolean", + "name": "allergies", + "title": "Do you have any severe allergies (e.g., to medication, food, latex)?", + "isRequired": true + }, + { + "type": "boolean", + "name": "smoking", + "title": "Do you currently smoke or use tobacco products?" + }, + { + "type": "boolean", + "name": "alcohol", + "title": "Do you consume alcohol regularly?" + }, + { + "type": "boolean", + "name": "drug_use", + "title": "Do you use recreational drugs?" + } + ] + }, + { + "name": "final", + "elements": [ + { + "type": "comment", + "name": "other_concerns", + "title": "Please list any other health concerns you think we should be aware of" + }, + { + "type": "expression", + "name": "eligibility_result", + "title": "Eligibility Result", + "showNumber": false, + "expression": "iif({isEligible} = true, '✅ You are eligible.', '❌ You are not eligible.')" + } + ] + } + ], + "showQuestionNumbers": true, + "completeText": "Submit" +} +``` + + + +[Open in Plunker](https://plnkr.co/edit/Bu1pVNmnU63rU7Od) + +## Learn More + +* [SurveyJS Expressions](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#expressions) \ No newline at end of file