Hello,
I am just about at my wits' end with this form I'm trying to build. I've been creating a behavioral health questionnaire form using a list box to enter the answers, creating functions that put the document variables into arrays, then using COND to convert the strings of my document variables into numeric strings (for example, "Describes me exactly (2)" becomes 2--depending on the questions "Describes me exactly" can also be 0, so I also have a value of "Describes me exactly (0)" that becomes 0--and so on), and adding the sum of the array into a single string and setting to an obs term.
I've managed to get these functions to work to set the obs term for every scoring entry so far...EXCEPT the single score that uses the same document variables as other functions in its array.
So for example, this function works:
{fn MENHLCALC(){
local menhlanswers
menhlanswers = array(DOCUMENT.Q1, DOCUMENT.Q4, DOCUMENT.Q5, DOCUMENT.Q13, DOCUMENT.Q14)
local sum2
sum2 = size(menhlanswers)local n
local score
local DMNHn=1
DMNH = 0
local xWHILE n <= sum2 DO
x = get(menhlanswers,n)COND
CASE str(x) == "Does not describe me (0)"
score = 0
CASE str(x) == "Describes me exactly (0)"
score = 0
CASE str(x) == "A lot (0)"
score = 0
CASE str(x) == "Somewhat describes me (1)"
score = 1
CASE str(x) == "Some (1)"
score = 1
CASE str(x) == "Does not describe me (2)"
score = 2
CASE str(x) == "Describes me exactly (2)"
score = 2
CASE str(x) == "None (2)"
score = 2
CASE x == ""
USEROK("Missing Answer(s). Please complete and Try Again")
BREAK
ENDCONDDMNH = DMNH + score
n=n+1
ENDWHILE
obsnow("PSYCHHXQ2",str(DMNH))
}}
But this one that uses some of the same document variables does not (document variables Q1 and Q4 are repeated):
{fn SECALC(){
local seanswers
seanswers = array(DOCUMENT.Q1,DOCUMENT.Q2,DOCUMENT.Q4,DOCUMENT.Q6,DOCUMENT.Q7)
local sum9
sum9 = size(seanswers)local n
local score
local DSELn=1
DSEL = 0
local xWHILE n <= sum9 DO
x = get(seanswers,n)COND
CASE str(x) == "Does not describe me (0)"
score = 0
CASE str(x) == "Describes me exactly (0)"
score = 0
CASE str(x) == "Somewhat describes me (1)"
score = 1
CASE str(x) == "Does not describe me (2)"
score = 2
CASE str(x) == "Describes me exactly (2)"
score = 2
ENDCONDDSEL = DSEL + score
n=n+1
ENDWHILE
obsnow("PSYCHHXQ6",str(DSEL))
}
}
Any ideas what I'm doing wrong or if a workaround is possible? This is the last thing standing between me and this form being complete.
Thank you!
Can I ask if you are getting any results, or if you are getting nothing at all?
Also, I noticed that in the code you posted, you have an issue when creating your array in the non-working function. you wrote: seanswers = array(DOCUMENT.Q1,DOCUMENT.Q2,DOCUMENT.Q4,DOCUMENT.Q6,DOCUMENT.Q7)
but in your working code, the array and the parentheses are not on 2 separate lines.
I have a mel-tester form that you can use in a document with the form you are trying to fix. it will let you run the function you built, and see the outcome of the code as you do it. Let me know if you have any questions on that. you could also send me the files and I can try it in our test environment if you need additional troubleshooting.
Daniel Carpenter
Hi Daniel,
Thanks for your answer! My function is not giving my any results, i.e. not populating the obs term I want it to.
The array and the parentheses aren't actually on two separate lines in my code. That's a formatting trick from wordwrap.
Now HERE'S something interesting: when I used your MEL tester, I couldn't get my function to work as written even taking out the document variables and replacing them with strings array(1,2,3,4,5) with the conditional case to set the score values (CASE str(x) == "1" score = 1 and so on). I realized this was because I didn't have "fn SECALC()" defined in the MEL test form, so I took that out and the rest of the function worked as expected (summing to 15 and populating the obs term). So I went back into VFE and took out "{fn SECALC(){" and the second closing curly bracket, and suddenly it works! (And yes, I did have a button to fire the "SECALC()" function)
I can't explain it, but I'll take it. Thanks so much for this resource!
-Billie
Yeah no worries! A quick tip: if you have the form you create the function in AND the Mel Tester form in the same document update, you can type the function call into the MEL tester and it will call the function you built. I use this when a patient chart is doing odd things with custom forms. I can pull the MEL tester in and try running the code to see what happens. you can also see the values of global variables by doing this as well.
I am glad your code works now! good luck and happy coding in the future. ^_^
Daniel.