I have a PEG form that I have built for pain management visit. I am able to total the score of the three questions but it will not recognize the number 10 except as the number 1. So it will total all the numbers under 9 correctly but reads the number 10 as 1. Is there a way to fix this?
I also wanted to know if there was a way to do an average of the final score and round it to the nearest whole number. Does any one have a current PEG form they are using or could assist me on this?
Thank you
Do you have the code you are using to add the score? I have built a few forms to add and total scores, but I have never encountered the problem you are describing.
Also, for the rounding of an average, there is a MEL function to round decimals to a specific decimal point. for example if the score is 3.79, you can use {round(3.79,0)} and the result will be 4.
Is the score that is turning from 10 to 1 a decimal number?
Thank you,
Daniel Carpenter
Thank you for your quick response. I am new at coding and generally copy other codes that I find. So I am most likely missing a vital step. Here is the code:
{!if (DOCUMENT.Q1 + DOCUMENT.Q2 + DOCUMENT.Q3)<>"" then
fnTotalPoints(DOCUMENT.Q1, DOCUMENT.Q2, DOCUMENT.Q3)
else
OBSNOW("PEGPRVCOMM", "")
endif
}
{fn fnTotalPoints(Q1,Q2,Q3) {
local totScore=0
local ansQ1="", ansQ2="", ansQ3=""
local i=0
//Question 1
if Q1<>"" then
i = match(Q1,"(")
ansQ1 = sub(Q1,i+1,1)
if totScore=="" and ansQ1=="0" then
totScore = 0
else
totScore = totScore + ansQ1
endif
else "" endif
//Question 2
if Q2<>"" then
i = match(Q2,"(")
ansQ2 = sub(Q2,i+1,1)
if totScore=="" and ansQ2=="0" then
totScore = 0
else
totScore = totScore + ansQ2
endif
else "" endif
//Question 3
if Q3<>"" then
i = match(Q3,"(")
ansQ3 = sub(Q3,i+1,1)
if totScore=="" and ansQ3=="0" then
totScore = 0
else
totScore = totScore + ansQ3
endif
else "" endif
totScore = str(totScore)
OBSNOW("PEGPRVCOMM", totScore)
All obs terms are stored as strings. If you are going to do any math on the obs term, it must first be converted to a value, i.e. val(obsnow("someobsterm"))
I think I found your problem. So the code you have is checking the text value of the 3 Document Variables. It finds if there is an open parentheses "(" and if so, it gets the character to the right of it. in your code, look where it says
ansQ1 = sub(Q1,i+1,1)
You can use the Centricity Help file to look up what mel code does, and it says that sub takes 3 arguments:
sub(string,starting_character,length )since the length of the answer is 1, when the user puts a 10, it simply cuts off the zero. here is what I suggest to modify the code, assuming that 10 is the highest number they can choose.
i = match(Q2,"(")
if sub(Q2,i+2,1) == "0" then
j = 1
else
j = 2
ansQ2 = sub(Q2,i+1,j)
this will check if after the first digit, there is a zero. if so, grab the next 2 characters after the "("
otherwise, get a single digit. If you have questions, or need a different solution, let me know. Could you send an example of what an answer with 1 and an answer with 10 looks like?
Thank you,
Dan
Dan,
Thank you again for your answer. Yes, you are correct on the issue. However, the code still doesn't work for me. I was able to get it to total the single dig numbers or the multiple dig numbers but not both. I keep getting a complier error, but I'll keep trying.
You asked to see what it looks like for an answer for one and another with ten. Sorry, it won't let me past anything in here. But basically it will total any 3 numbers like: 9+9+9=27 but 9+9+10= 19.
Thank you, Andria
Hi Andria,
I forgot to put an endif on my code I sent you. that is probably causing the compiler error. here is the code that should work.
i = match(Q2,"(")
j=1
if sub(Q2,i+2,1) == "0" then
j = 1
else
j = 2
endif
ansQ2 = sub(Q2,i+1,j)
I was just curious at what the answers look like on the form, since the code is breaking them down based on parentheses. If I had some reference, then there might be a better way to write the code. you could send a screenshot to my work email: [email protected] if you would like.
Thank you,
Dan