We use a form called OB EDD Calculations that always pulls in the Last Menstrual Period Date and The Expected Date of Delivery. We want these fields to clear when the patient is on a new pregnancy. I have read all the information on CHUG and feel like I'm getting close, but I think the fuction I'm using is not working with my Edit Field (The Date field box is checked)
The function I'm using is this in the right function pane (pulled from another post on CHUG):
fn afterLMP(obs)
{
daysPast = DURATIONDAYS(OBSANY("LAST MP"),str(LASTOBSDATE(obs)))
IF(daysPast >= 0) Then
return LASTOBSVALUE(obs)
ELSE
return "FALSE"
ENDIF
}
In the Edit Field I have the Date field box checked. The Connection type is New Observation (Default Previous), Observation is LAST MP.
On the Advanced tab I checked Enable Expression, and entered the following:
{afterLMP("LAST MP")}
When I import the form the LMP date field is now grayed out but still displaying the old LMP date which is earlier than the last delivery date I have entered.
I am even open to using a different form, but all I've looked at seem to keep pulling these two fields. We have the CCC Full package and Basic.
Thanks in advance for any guidance.
The enable expression box in the Advanced tab is only for allowing a user to edit/click the field. since you are checking the date with your afterLMP() function in that enable field, it is only turning it grey, and not allowing the field to be edited by users. The date field itself is still being set with the "New Observation(default previous)" which is why you are seeing the old LMPs.
I would suggest not using the advanced tab, and changing the date field to a New Observation Only (for user's to type into). Then Create a new Data Display with the following code in it.
{!if afterLMP(“LAST MP”) <> FALSE AND DOCUMENT.LMP == "" then
DOCUMENT.LMP = afterLMP(“LAST MP”)
else ""
endif}
This will allow you to set that date field with the last LMP if it fits inside the time range. I hope this helps you with the form building. 🙂
That function looks like one of mine. I may have been the one who posted in the post you got it from. But I have never used it in an enablement function on the advanced tab. 'dcarpenter' is right. Enablement expressions have to return 'TRUE' or 'FALSE'.
Here are some examples of how I use that function and others like it.
1) Use a Data Display field and set it as Type: Mel Expression. Insert your function like 'afterLMP("STREP B CULT"). If the patient's last strep B result is after the LMP, then it will display it. Otherwise, it will not.
2) Use an Edit Field and set it to "New Observation" or "Document Variable". In the coding section of VFE (right hand pane), create a watcher expression using the code that 'dcarpenter' gave above.
FYI: I have a heck of time getting that function to work when I try to use it inside of another function or expression. I usually have to rewrite the whole thing rather than just calling afterLMP(). Sometimes MEL is an extremely finicky language. (or in other words, it sucks)
Steve Peterson
Director of I.T.
Circle of Life Women's Center
Thanks for the help Steve. I do have one last thing to figure out, and I'm hoping you can help. For your first example:
1) Use a Data Display field and set it as Type: Mel Expression. Insert your function like 'afterLMP("STREP B CULT"). If the patient's last strep B result is after the LMP, then it will display it. Otherwise, it will not.
What if there are multiple obs terms to take into consideration? Instead of "STREP B CULT", we would use the last delivery date, but the last delivery date obs term could be DELDATE1, DELDATE2, DELDATE3, DELDATE4, DELDATE5, or DELDATE6.
Thanks Again!!
How do you want the computer to decide which date to use? Something like: If date1 exists then use it, if not, look for date2, if date 2 doesn't exist then try date3, etc? For this workflow, you would probably have to modify the afterLMP() function to add some nested IF statements.
Something like this: (not tested)
pregStartDate = ""
if (OBSANY(DELDATE1)"" Then
pregStartDate = obsany(DELDATE1)
else
if (obsany(DELDATE2)"" Then
pregStartDate = obsany(DELDATE2)
else
if (obsany(DELDATE3)"" Then
pregStartDate = obsany(DELDATE3)
else
""
endif
endif
endif
You could probably use a case statement too, but I don't know the syntax off the top of my head.
Then, once you have populated the pregStartDate variable with the proper date, you would use pregStartDate as the first parameter in your DURATIONDAYS function, instead of obsany("LAST MP").