Would anyone be familiar with writing a calculation code for resulting a rating scale of Low, Moderate or High, dependent on the Yes/No answers within a 6 question survey?
I built a VFE form for the Columbia Suicide Severity Rating Scale, as part of the Depression Screening PHQ-9 for Adolescents. Try as I might I cannot seem to create a calculation code dependent on the Low = yes to Q1 and/or Q2; Mod = yes to Q3; and High = yes to Q4 and Q5.
Would anyone be interested in taking a look at this? I can email the rating scale guidelines and my latest VFE form version with my code attempt in the sidebar. I'm having trouble uploading to this post.
Thank you in advance!
I'd be happy to take a look at it and get you on the right track. Just send me the point scoring system and the .dlg file for the form.
Thank you. I attached both. You can email me directly if you need to [email protected].
Anna,
I'll take a look at this over the weekend and get back to you.
I checked out your DLG. I created a form with some pretty simple code that works and I can send you, but you can also modify your dlg.
Problem 1 - you are using "else if document.cssrs_11 = "Yes""
this should be "=="
also, you are using document.cssrs_11 for all of your if statements. change those to the correct doc variables (cssrs_21,cssrs_3,etc)
here is my code. You can see if this is a bit more simplistic. You can then just add in your code to push values to the obsterm:
{
if document.question1 == "yes" and document.question2 "yes" and document.question3 "yes" and document.question4 "yes" and document.question5 "yes" and document.question6 "yes" then
document.result = "Low"
else if document.question2 == "yes" and document.question3 "yes" and document.question4 "yes" and document.question5 "yes" and document.question6 "yes" then
document.result = "Low"
else if document.question3 == "yes" and document.question4 "yes" and document.question5 "yes" and document.question6 "yes" then
document.result = "Moderate"
else if document.question4 == "yes" and document.question5 "yes" and document.question6 "yes" then
document.result = "High"
else if document.question5 == "yes" and document.question6 "yes" then
document.result = "High"
else if document.question6 == "yes" and document.when == ">3mo" then
document.result2 = "Low"
else if document.question6 == "yes" and document.when == "1wk" then
document.result2 = "Moderate"
else if document.question6 == "yes" and document.when == "<1wk" then
document.result2 = "High"
endif
endif
endif
endif
endif
endif
endif
endif
}
{cond
case document.result == "Low" and document.result2 == "Low"
Obsnow("CSSRSRESULT","Low",str(._todaysdate))
case document.result == "Low" and document.result2 "" and document.result2 "Low"
Obsnow("CSSRSRESULT",document.result2,str(._todaysdate))
case document.result == "Moderate" and (document.result2 == "Moderate" or document.result2 == "Low")
Obsnow("CSSRSRESULT","Moderate",str(._todaysdate))
case document.result == "Moderate" and document.result2 == "High"
Obsnow("CSSRSRESULT","High",str(._todaysdate))
case document.result == "High"
Obsnow("CSSRSRESULT","High",str(._todaysdate))
endcond
}
Thank you so much for digging into this. Will test this out next week for sure.
Great. Thank you.
Anna,
I have emailed you the modified version of your form to accommodate the risk level calculation for the Columbia Suicide Severity Rating scale. In addition to correcting the calculation logic, I made the following enhancements.
- Questions 3 thru 5 are disabled until the user selects "Yes" for question 2 (per the guidelines, those questions are N/A unless the answer to question 2 is "Yes")
- I included a data display at the bottom of the form to dynamically display the Disposition Considerations; this is based on the calculated risk level
- I removed any superfluous coding on your form (in the function view)
- A pop-up box will display informing the user that not enough data has been entered to calculate the risk level if the user attempts to calculate the risk level before answering the appropriate questions
I tested several different scenarios and everything appears to be working in accordance with the rules provided, but you may want to test it yourself to be sure. I noticed the timeframes on the original form you provided for question 6 did not match the timeframes specified in the documentation so I modified those accordingly. If you need to make changes to those, just remember you will need to update the section of code that corresponds to the risk level calculation for question 6. I thoroughly documented the code so you should be able to easily identify what each section is doing.
The function that calculates the correct risk level is provided below for anyone else that might be interested. I've attached a text file version as well since code posted on the forum often loses legibility. Click here to access --> CSSR-Calculation-Function
//Calculate Suicide Risk Level - function fires when <Calculate CSSR> button is pressed
{fn CalcCSSR()
{
//Define local variables for function
local cssr_risk1 = 0 //used to store risk for questions 1 thru 5
local cssr_risk2 = 0 //used to store risk for question 6
local cssr_risk = 0 //used to store overall risk rating
local topquest = 0 //used to store highest question number receiving response of Yes
//Determine highest numbered question 1 through 5 receiving a response of Yes
//store question responses in array
local qresponse = array(DOCUMENT.CSSRS_11,DOCUMENT.CSSRS_21,DOCUMENT.CSSRS_3,DOCUMENT.CSSRS_4,DOCUMENT.CSSRS_5)
for i=1, i <= 5, i=i+1 //Loop through 5 questions
do
if (qresponse[i] == "Yes") then
topquest = i
else
//Do nothing, continue looping through questions
endif
endfor
//Determine risk level associated with questions 1 thru 5
cond
case topquest == 1 //Low risk
cssr_risk1 = 1
case topquest == 2 //Low risk
cssr_risk1 = 1
case topquest == 3 //Moderate risk
cssr_risk1 = 2
case topquest == 4 //High risk
cssr_risk1 = 3
case topquest == 5 //High risk
cssr_risk1 = 3
else
cssr_risk1 = 0 //No risk
endcond
//Determine risk level associated with question 6
cond
case DOCUMENT.CSSRS_6A == "Greater than 3 months"//Low risk
cssr_risk2 = 1
case DOCUMENT.CSSRS_6A == "Between 1 week and 3 months"//Moderate risk
cssr_risk2 = 2
case DOCUMENT.CSSRS_6A == "Less than 1 week"//High risk
cssr_risk2 = 3
else
cssr_risk2 = 0 //No risk
endcond
//Determine collective risk level (higher risk of risk1 and risk2)
if (cssr_risk1 == cssr_risk2) then
cssr_risk = cssr_risk1
else
if (cssr_risk1 > cssr_risk2) then
cssr_risk = cssr_risk1
else
cssr_risk = cssr_risk2
endif
endif
//Assign proper description to OBS term and update disposition considerations on form
cond
case cssr_risk == 1 //Low risk
OBSNOW("CSSRSRESULT","LOW")
gvar_DispCons = "Outpatient mental health referral, community resource information (e.g. 774-HELP)"
case cssr_risk == 2 //Moderate risk
OBSNOW("CSSRSRESULT","MODERATE")
gvar_DispCons = "PHP referral, CSU referral, Crisis Services follow-up, follow up with outpatient providers, routine mental health referral"
case cssr_risk == 3 //High risk
OBSNOW("CSSRSRESULT","HIGH")
gvar_DispCons = "Psychiatric hospitalization, CSU referral, PHP referral, Crisis Services follow-up, follow up with outpatient providers"
else
userok("Sorry. Not enough data to determine suicide risk level.")
endcond
}
}
Your coding works perfectly. Our lead BH provider has reviewed the scoring and has confirmed risk level results are accurate, and exactly what is needed.
Thank you for taking the time to share your expertise.
I've attached the final version of our Depression Screening for Adolescents PHQ-A form, which includes the Columbia Suicide Severity Rating Scale, and page reference for providers.Depression Screening - PHQ-A .
I will also post this form in a separate post with the form name in the title.
Anna