Hi Everybody,
This is my first post and sorry for such a basic question. I have been messing around with MEL unsuccessfully for a while now and thought I should ask the experts.
I was given a form with Radio buttons. The medical users would like me to check a variable if it is null. If it is assign the variable with a value of Zero.
Below is my code.
{if OBSNOW("abn fac move") == "" then
OBSNOW("abn fac move","0")
endif}
My code compiles okay but at run time I get the following error.
{fn fn772854913_3177192()
{
local a = ((if F723954913_356_1 == "" then
OBSNOW("abn fac move","0")
endif)
val <-COMPILER ERROR NEARBY: Expect RIGHT PAREN. Instead had FUNCTION after RIGHT PAREN
Thanks!
Ralph
You have the right idea, where did you place this code? If you are working in Visual Form Editor, you should place it in the right code panel, just this, and add the '!' right after the opening bracket so it runs when the document is opened.
{!if OBSNOW(“abn fac move”) == “” then
OBSNOW(“abn fac move”,”0″)
endif}
The error message that you are showing does not look like it is necessarily coming from the same place. The 'local a =' part makes me think you tried to do this somewhere else in the form and left the code there, VFE shouldn't do that on it's own. You can see in the error it needs a closing ')' since there are two to open, the function below that is val() which is used to convert strings to numbers, its saying you can't call that until you close your if-then statement. I hope that helps...
Thanks,
I had the code in a function after the radio button line item. I do not think they want me to pick zero when the form opens..... Let me back up. At the end of the form there is a calculate button. In the calculate button code there is the Val code you mentioned. That code only works if all 6 radio buttons are filled in. If the user forgets one of the radio buttons I am supposed to default the value to zero.
I was hoping to put my checks in the calculate button code but that did not work.
{val(get(OBSNOW("abn fac move"),1))+val(get(OBSNOW("abn oral mov"),1))+val(get(OBSNOW("abn jaw mov"),1))+val(get(OBSNOW("abn tong mov"),1))+val(get(OBSNOW("abn UE mov"),1))+val(get(OBSNOW("abn LE mov"),1))+val(get(OBSNOW("abn neck mov"),1))}
Thanks for your help
Side note: What they are asking for really is 'improper' and potentially could yield erroneous results. Instead of 'assuming' that a 'forgotten' response is 'none', force each value to be populated. You can remind them that not all of the responses are valid using a userok statement.
If you do this once, more important calculations WILL be expected to behave the same way, a precedent you don't really want to establish. Some calculations can endanger the patient if assumptions are made. Legally speaking, if the code is 'answering' and patient harm results, the coder could be implicated in any tort action. Ethically speaking, having the code 'fill in' an omitted response is irresponsible and bordering on fraud. I recommend you weigh this decision carefully and establish a best practice approach. I don't want too sound preachy, but some things code simply should not do, even though it easily can - we all must resist that temptation.
That said, I would use Document Variables for the fields and in MEL, use a function to crosswalk the worded response and populate the obsterm using the numerical response. Given that all the response types appear to be the same, it would be a single function call for each response.
{OBSNOW("OBSNAME",fnGetValue(DOCUMENT.Q1))}
{! fn fnGetValue(strVar)
cond
case strVar == "None" return "0"
case strVar == "Minimal" return "1"
...
else return ""
endcond
}
}
Very efficient, small footprint, and less prone to issues.
For the omitted questions, you could use something like the following in the button:
if (DOCUMENT.Q1 == "" or DOCUMENT.Q2 == "" or ...) then userok("Please answer all questions before scoring survey.") else "" endif
DOCUMENT.Q1. I'm assuming Q1 is replaced with something else?
Thanks
Correct.
Document.Q1 is a placeholder for this post only. If you change the connection type of each radio button to a document variable, you would use that variable name in its place.
I was able to get my code working but I only want the code evaluated inside the calculate button. Below is the existing code in the calculate button.
{val(get(OBSNOW("abn fac move"),1))+val(get(OBSNOW("abn oral mov"),1))+val(get(OBSNOW("abn jaw mov"),1))+val(get(OBSNOW("abn tong mov"),1))+val(get(OBSNOW("abn UE mov"),1))+val(get(OBSNOW("abn LE mov"),1))+val(get(OBSNOW("abn neck mov"),1))}
I tried to add the if statement to the existing code, the code compiles okay but when I go to run it in the Centricity there are errors. So my question is are you not able to have to different statements in one function?
{if OBSNOW("abn fac move") == "" then OBSNOW("abn fac move","0-None") endif val(get(OBSNOW("abn fac move"),1))+val(get(OBSNOW("abn oral mov"),1))+val(get(OBSNOW("abn jaw mov"),1))+val(get(OBSNOW("abn tong mov"),1))+val(get(OBSNOW("abn UE mov"),1))+val(get(OBSNOW("abn LE mov"),1))+val(get(OBSNOW("abn neck mov"),1))}
results in the following error in Centricity when the encounter form is opened.
{fn fn773244818_3177192()
{
local a = (if F724344821_356_1 == "" then OBSNOW("abn fac move","0-None") endif val <-COMPILER ERROR NEARBY: Expect RIGHT PAREN. Instead had FUNCTION after ENDIF KEYWORD
Thanks
Look at what you have written and think about what the statement is instructing.
If 'this' is 'empty' then assign the value of '0-None', perform calculation for all variables
I don't think this is what you want.
In your reply, attach the form. I will post a sample for you to learn from having seen all of the variables.
I see why you need it all in the calc button - you are using EFE.
There are many ways to do what you want, below is but one of them.
{
local nTtl = ""
local strTtl = ""
if obsnow("abn fac move") <> "" then nTtl = val(get(OBSNOW("abn fac move"),1)) else nTtl = 0 endif
if obsnow("abn oral mov") <> "" then nTtl = nTtl + val(get(OBSNOW("abn oral mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("abn jaw mov") <> "" then nTtl = nTtl + val(get(OBSNOW("abn jaw mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("abn tong mov") <> "" then nTtl = nTtl + val(get(OBSNOW("abn tong mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("abn UE mov") <> "" then nTtl = nTtl + val(get(OBSNOW("abn UE mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("abn LE mov") <> "" then nTtl = nTtl + val(get(OBSNOW("abn LE mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("abn neck mov") <> "" then nTtl = nTtl + val(get(OBSNOW("abn neck mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("abnl mov sev") <> "" then nTtl = nTtl + val(get(OBSNOW("abnl mov sev"),1)) else nTtl = nTtl + 0 endif
if obsnow("abnl mov sev") <> "" then nTtl = nTtl + val(get(OBSNOW("abnl mov sev"),1)) else nTtl = nTtl + 0 endif
if obsnow("incap RT mov") <> "" then nTtl = nTtl + val(get(OBSNOW("incap RT mov"),1)) else nTtl = nTtl + 0 endif
if obsnow("prob teeth/d") <> "" then nTtl = nTtl + val(get(OBSNOW("prob teeth/d"),1)) else nTtl = nTtl + 0 endif
if obsnow("Dentures") <> "" then nTtl = nTtl + val(get(OBSNOW("Dentures"),1)) else nTtl = nTtl + 0 endif
if nTtl <> "" then strTtl = str(nTtl) endif
OBSNOW("aimstotalscr",strTtl))
}
Thanks Much! I'll play with it today.
Regarding EFE, is there something else I can use? We are on Centricity 9.8, Oracle database.
There are now several editors out there. GE sunset EFE when they began reselling Visual Form Editor (VFE). I'll let others comment on other products since I am partial to VFE. 🙂