I haven't taken a MEL class yet, but am reading documentation on how to use the language in VFE.
However, I have a form with a dropdown list (DOCUMENT.DUE_NEXT) and it has the following choices: 3 months,6 months,9 months,1 year,3 years,5 years,10 years (for when the patient will need to be back in the office). When the doctor chooses an option from DOCUMENT.DUE_NEXT, I would like it to calculate the date due in the obsterm COLONXTDUE.
I think I'm in over my head on this one! But perhaps someone knows a solution?
You can use the ADDDATES function. To use ADDDATES you just need to specify a date and then the number of years, months and days you would like to add. In CPS go into the help and search for ADDDATES. It has a a couple of good examples. The CPS help is pretty good if you are looking for examples with the built in MEL functions.
Also, to test any MEL code quickly you can use personal quicktext before moving it to VFE. In your example we will take bhoover's advice and look at the ADDDATES function example in the Help guide.
So create new personal quicktext ".adddates"
Paste the following into the "With"" field:
{ADDDATES("3/1/1997","2","0","0")}
Then open an update and test it out. As per the Help guide it should return:
"03/01/1999"
Now play around with it. Change the "2" to a "3" and check to see that it now returns:
"03/01/2000"
Calculating dates is tedious but the key is to know which function to use (thank you bhoover) and having a quick method of trial and error (thank you quicktext).
Just to add one more thought to this... consider what date you are adding to?
If today is 3/13/15, (the date the doctor is reviewing), but the test results from 1/13/15 are being reviewed. Now, the doctor says recall in six months. Which date do you add six months to? You want everyone to be clear about that. And, you may want it to be clear on your VFE data entry form.
Thank you all for your valuable answers! However, I don't think I explained correctly and after joeg's post, I realized I need to make sure I have the correct date it's calculating it from or else the calculation will be off.
So in layman's terms, I have a date field that will populate the LST COLON DT obs term. Once the Doctor puts in that date, that will be the date it calculates from.
Then, the doctor will fill in the DOCUMENT.DUE_NEXT field (3 months,6 months,9 months,1 year,3 years,5 years,10 years).
Lets say he enters the LST COLON DT to be 3/13/15 and DUE_NEXT is 3 months.
I would like the obs term COLONNXTDUE to populate with 6/13/15.
Does this make sense?
Here is our Adult Prevention Services form. There is a button called "Update Next Due Dates". There is a code there (case statements) to do what you want to do.
I have been following this and am trying to do the exact same thing, and like mlaroche I have not taken a MEL class.
I am not understanding how to convert the add dates to a string. Can anyone help?
I want to use a document variable or obs I am open to either.
thanks!!
Janet, the result of ADDDATES is a string. And the date to add to in the parameters is also a string. If the date you want to use is not a string, you convert it by wrapping it in str().