I am trying to create a simple calculation to calculate the gestational age of a patient from their LMP date. I have tried duration string and duration days but I am not sure I have the context correct. I am getting a 0 result when I use it.
Any suggestions appreciated!!
The most common mistake folks make in date calculations is forgetting to convert ._TODAYSDATE into a string. I'm guessing that's the reason you are getting a zero (0) returned as result. Also remember to put any actual dates in the mm/dd/yyyy format and surround with double quotes.
Proper Usage:
DURATIONDAYS("12/22/2016", str(._TODAYSDATE))
Executing the above function would return the number of days since 12/22/2016
Hope that helps.
If you are passing the LMP as an OBS term, you might also be having an issue with how the OBS term is storing the value (text or numeric). Again, the date functions in MEL expect dates to be passed as strings in the format mm/dd/yyyy. So it might be that you have to convert the value stored in the OBS term to a string as well before the function will return a valid result.
I think that is where I am stuck, I am not exactly sure how to take my obs and convert to a string. Can you help with that too?
Thanks so much!!!
If you will email me the dlg file or clinical kit, I would be happy to fix. Or send me the OBS term you are using to capture LMP and I will send you a code sample that works. I'm assuming you have a custom form that's not working. Please advise if this is a quick text you are wanting.
Oh thank you, the obs is DATE OF LMP
This should do what you are looking for:
{! fn fnCalcEGAFromLMP(strLMP)
{
local lReferenceDate
local lBegin
local lDays
local lIndex
local lDateAndTime
if (getRowCount("DOCUMENT") 0)then
lDateAndTime = str(DOCUMENT.CLINICALDATE)
lIndex = match(lDateAndTime, " ")
lReferenceDate = (remove(lDateAndTime, lIndex))
else
lReferenceDate = (str(._TODAYSDATE))
endif
lBegin = SUBTRACTDATES(strLMP, "0", "0", "280")
lDays = val(DURATIONDAYS(lBegin, lReferenceDate))
if (lDays > 340 OR lDays <= 0) then
return ""
else
return (div(lDays, 7) + "W" + mod(lDays, 7) + "D")
endif
}
}
Use the function call of:
fnCalcEGAFromLMP(lastobsvalue("DATE OF LMP"))
Hope that helps.
Janet, looks like Lee provided a viable solution. If that doesn't work for you, let me know. Thanks.
This is what I use. It has worked well for years and is very simple:
{
local lDays = val(DURATIONDAYS(OBSANY("LAST MP"), str(DOCUMENT.CLINICALDATE)))
OBSNOW("GEST AGE",(div(lDays, 7) + "W" + mod(lDays, 7) + "D"))
}
I chose to use the document date rather than today's date because I want to know the GA as of the visit date, not the GA as of today. The provider could be charting on an open document 3 days after the actual visit.
Here is an extended version. If the provider has entered a final EDD (usually based on ultrasound findings) then I use that date to calculate GA. If there is no final EDD then I use the LMP. I also use the obsterm "GEST AGE BY" to record which date was used.
{!
OBSNOW("GEST AGE BY","No dates found") //set this as default
OBSNOW("GEST AGE","") //blank to start
if (OBSANY("LAST MP")"") then
OBSNOW("GEST AGE BY","LMP")
local lDays = val(DURATIONDAYS(OBSANY("LAST MP"), str(DOCUMENT.CLINICALDATE)))
OBSNOW("GEST AGE",(div(lDays, 7) + "W" + mod(lDays, 7) + "D"))
endif
if (OBSNOW("EDC")"") then
startDate=SUBTRACTDATES(OBSNOW("EDC"), "0", "0", "280")
OBSNOW("GEST AGE BY","Final EDD")
local lDays = val(DURATIONDAYS(startDate, str(DOCUMENT.CLINICALDATE)))
OBSNOW("GEST AGE",(div(lDays, 7) + "W" + mod(lDays, 7) + "D"))
endif
}
Steve Peterson
Circle of Life Women's Center
Thank You. Our new OB provider would like the EGA in the patient banner, and to update on a daily basis even if the patient isn't seen. I have no idea if this is even possible or where to begin. Anyone willing to point me in the right direction?
Thanks
Laurie