I'm wanting to create a drop down with the choices being data pulled from obsterms. If I just put the obsterm in the mel expression box then that value is selectable in the drop down but it won't work for additional ones. Is this possible?
This is possible, but you have to create a custom function that will return a comma delimited list of the values you want to populate the list box with.
If you will post the OBS terms you are wanting to use, I can provide an example of this technique.
NECERVHEXTN
NECERVHOFFL
NECERVHOFFLC
NECERVHOFFR
Thanks!
Chris,
this should give you what you need. This could likely be programmed more efficiently, but I chose to do it this way for readability. I have included a screen shot of the function/form below along with the .dlg file so that you can play around with it in your environment. You didn't specify if you wanted values from the current visit (OBSNOW) or values from a previous visit (OBSPREV). That is easy enough to change in the function. Keep in mind that if you are wanting all four OBSTERMS to pull from a previous office visit, you should take the additional step to verify that the dates of the previously recorded OBS terms all match; otherwise your data may not be "cohesive". When pulling data from a previous visit it might be worth displaying in a data display the date of the visit the data was pulled from. I could probably provide better input if I understood your clinical process better. Regardless, this should get you pointed in the right direction.
Cheers,
Greg
Screenshot (click to enlarge)
DLG file for VFE
Thanks for the coding...upon initial launch it works but if I put it on hold then go back in the drop down is blank. Any thoughts?
Since you seem well versed in this programming, how would i go about matching items? For example:
If obs1 matches obs2 then "we have a match!" else "no match" endif
Chris,
I would really need to understand your workflow and see your form before I could answer that. The form works fine on my end, but I am sure you have modified it to accommodate your needs. No promises, but if you sent me the form you are developing and gave me the requirements, I might be able to fix it. Otherwise, I would just be speculating.
Chris,
I looked at this again and I see what is happening. The quick and dirty way to fix this is to modify the if statement at the top of the function so that it appears as follows:
!if (DOCUMENT.DYNAMIC_DDL == "" OR DOCUMENT.DYNAMIC_DDL <> "") then
Basically, this forces the dropdown list to repopulate every single time the form loads regardless of whether a value was already selected or not. That will solve your problem. A more efficient way to code this would be to add a hidden document variable on your form that would hold the comma delimited list of items and then have your dynamic dropdown reference the value (i.e. your comma delimited list) in that hidden variable. Make sense? Regardless, the code above will work fine for a quick and dirty fix.
Your second question about matching items. Several ways to skin that cat, but you might try this:
if you are wanting to compare dates, here is an example:
if (LAST_SIGNED_OBS_DATE("OBS1") == LAST_SIGNED_OBS_DATE("OBS2") ) then
if that doesn't work, then you may have to convert the dates to strings before doing the comparison; not converting dates to strings is a common error made in MEL when working with dates; here is how you would do that:
if (str(LAST_SIGNED_OBS_DATE("OBS1") )== str(LAST_SIGNED_OBS_DATE("OBS2") )) then
Comparing obs term values (assuming you want to compare previous values):
if (OBSPREV("OBS1") == OBSPREV("OBS2")) then
...
else
...
endif
I suspect that this might have to do with a quirk of working with observation terms. Observation term references are not initialized until after the watcher expressions are loaded/executed. As a result they often evaluate to NULL when the form is first opened.
I suspect that you could fix this by moving most of the code to a function and then calling the function from the watcher at startup.
1. Create a function:
!fn InitializeMyDropdown()
{
// include the rest of the code from the example except the outermost if condition statement here.
if obsprev(....
}
2. Update the watcher to only include the outermost check:
{!if DOCUMENT.DYNAMIC_DDL "" then InitializeMyDropdown() endif}
Other potential things you might need to do are:
1. Declare the document variable in a separate watcher. Sometimes this seems required, but I can never figure out why.
{!DOCUMENT.DYNAMIC_DDL}
2. Handle case where DOCUMENT variable returns NULL and doesn't evaluate to "". I don't think this should be needed here, but if the above code isn't working, a possible workaround is changing:
DOCUMENT.DYNAMIC_DDL ""
to:
str(DOCUMENT.DYNAMIC_DDL) ""
The str() function will convert a NULL value to an empty string.
I like the function idea and I think it might work better for my workflow...although one issue I'm noting is if the fields are changed, then the change isn't immediately noted in the drop down. I need to put it on hold and go back in for the function to trigger/update the drop down. I tried creating a runprocess button so I could update on the fly and used {FoodList01()} which didn't work so I tried fnFoodList01() whidch also doesn't work. I feel like the end is in sight just need to figure this part out 🙂 Thanks for the help!
If you wanted this to change dynamically as observation terms change you should be able to fix this by adding any observation terms that would update the expression back to the watcher. Sorry that I forgot to include that the first time.
{!OBSNOW("OBSNAME1")
OBSNOW("OBSNAME2")
OBSNOW("OBSNAME3")
if DOCUMENT.DYNAMIC_DDL "" then InitializeMyDropdown() endif}
The observation terms really just need to appear somewhere in the MEL expression to trigger it.
In this case you can actually usually leave out the ! since the expression will be triggered when the reference for the first observation term is filled in.