Using Form Variables to Calculate a Future Date

I am trying to create a snippet that will calculate a date for a future appointment based on a date provided in the form.

What I am looking to do is to create a form like this

Enter Date of First Appointment: [FirstDate]
Calculated Date of Follow up Appointment: [FirstDate + 1day]

After reading the available documentation it seems like the best way to do this would be to:

  1. Use the Date/Time function to allow the user to enter the date of the first appointment
  2. Use a second Date/Time function that takes the date entered by the user and shift it +1 Day

When I try to use this snippet, I get an error message saying that the system can not parse "firstdate" as a date or time.

My expectation from working with forms and variables in other snippets is when I enter the form variable "firstdate" into the "at" section of the Date/Time function the system would parse the value related to "firstdate" and not the text "firstdate"

Is this the expected behavior, a bug, or am I doing something wrong?
Is there anyway to pass a date entered by a user in a form to the "at" section of a Date/Time function so it can be shifted?

Thank you!

Hey @Ryan_Wolff -- welcome and great question.

You're just missing one thing that we don't make super obvious. You've already clicked the "advanced editor" which is correct (see how the icon next to "at" is yellow). But what you need to do is make your "firstdate" field inside of the "at" setting as a formula. That is, instead of just having firstdate as the value of at, make it {=firstdate}. That should work for you.

That did it, thanks!

to piggyback off of this -
I'm trying to calculate a 4 week, 8 week, 12 week future appt from a specific date.

e.g., patient last filled a controlled prescription on 01/27/24 (not 01/27/2024 format) and the next follow-up appointment has to be 4/8/12 weeks from that last fill date.

Additionally is it possible to create a shortcut that uses the "import" function?

Thanks!

Edit view-expanded
Preview
Import function possibility?

Hi, welcome to the Text Blaze community!

Would this work for you?

Start date: {formdate: MM/DD/YY; name=start}

Date 4 weeks later: {time: MM/DD/YY; at={=start}; pattern=MM/DD/YY; shift=+4W}

Date 8 weeks later: {time: MM/DD/YY; at={=start}; pattern=MM/DD/YY; shift=+8W}

Date 12 weeks later: {time: MM/DD/YY; at={=start}; pattern=MM/DD/YY; shift=+12W}

Also, can you explain what you mean regarding the import command? The import command allows you to use other snippets within snippets. This allows you to make changes in one snippet and have them reflected in all other snippets in which it is imported.

Does that answer your question?

1 Like

you rock, thank you!
re: import command - it might be solved if we can separate the above into individual snippets?
e.g.,
snippet #1 = 4 weeks later
snippet #2 = 8 weeks later
snippet #3 = 12 weeks later

Hi,

Sure, you can definitely do that.

Here's a folder with a primary snippet that does the same as the above except that the dates are individual snippets imported to one primary snippet.

Please note that with the folder above, the imported snippets show an error, but work properly in the primary snippet.

You can customize each of the imported snippets and the changes will be reflected when you use the primary snippet.

You can also put the imported snippets inside of a toggle field to turn them on/off as needed. This is what that would look like:
{formtoggle: name=4 weeks; default=yes}{import: /4weeks}{endformtoggle}

This is what it looks like:
import-rx

Please let me know if this works for you and if you have any additional questions. Happy to help!