- UiEvents occur when a user has taken a certain action on their workstation. For example, the PatientSelected event will fire whenever a new patient is selected within an instance of Open Dental.
- DbEvents occur when any column has changed in a specific database table. This change could be made through an instance of Open Dental or the API.
You can use a simple webhook site for initial testing, such as Webhook.site or similar.
Subscribing to an Event
This example will subscribe to the Appointment database event. This can be used to keep a list of appointments up to date.
1. Create a Subscription
Use the Subscriptions POST API method to create the subscription. Include a JSON body similar to what is shown below, but be sure to use your current machine name for the Workstation field:
Code: Select all
{
"EndPointUrl": "https://myserver/apievents/",
"Workstation": "MOLLYR",
"WatchTable": "Appointment",
"PollingSeconds": 5
}
Code: Select all
{
"SubscriptionNum": 1,
"EndPointUrl": "https://myserver/apievents/",
"Workstation": "MOLLYR",
"CustomerKey": /*YourCustomerAPIKey*/,
"WatchTable": "Appointment",
"PollingSeconds": 5,
"UiEventType": "",
"DateTimeStart": "2022-11-28 15:04:31",
"DateTimeStop": "0001-01-01 00:00:00",
"Note": ""
}
2. Process the Subscription
There are two ways a Subscription can be processed:
- OpenDental.exe running on a workstation can process both UI and Database Events.
- OpenDentalAPIService.exe running on a server can only process Database Events (no UI).
At the interval specified in your subscription’s PollingSeconds, Open Dental will look for changes that occurred in the WatchTable since the DateTimeStart. In our example, the following occurs:
- Examine all subscriptions that apply to the current workstation (“MOLLYR”) or all workstations (left blank, “”).
- Exclude any expired subscriptions (DateTimeStop field is before the current time).
- Determine if it is time to check the database for changes. This is true when the current time is equal to or later than DateTimeStart + PollingSeconds (2022-11-28 15:04:31 + 00:00:05).
- Open Dental will query the appointment table for rows with DateTStamp values equal to or greater than DateTimeStart (2022-11-28 15:04:31)
- If any rows meet these criteria, they are sent to your EndPointUrl in a single webhook.
Now we will make a change to the appointment table of this database to trigger an event. This change can occur in two ways:
- Through the API’s Appointments PUT and POST methods. All API modes will trigger an event.
- Through OpenDental.exe on a workstation. Any change made on any workstation will trigger an event.
Code: Select all
{
"PatNum": 10,
"AptDateTime": "2022-12-02 13:30:00",
"Op": 1
}
Now we will edit this appointment within Open Dental to trigger an event. In the Appointment Module, double click on the appointment we just created. Any change made to the appointment will cause an event to fire, but let’s update the Confirmed field to “Confirmed”. Click OK to save your changes and fire an event. On your webhook site, the body of this event will be identical to the first except for the updated Confirmed field.
Additional Notes
An ApiEvent will not fire if there is nothing to send; they will be sent only when a change has occurred.
Only one ApiEvent will fire per PollingSeconds interval per Subscription. In the above example, if three appointments were added in our 5 second interval, a single event will fire. This event will contain the list of three appointments.
When a Subscription is processed the DateTimeStart is updated to the current time. Therefore, you can see that the subscription is active/being processed because this field will be incremented by PollingSeconds. This incrementing occurs regardless of if there were changes requiring an event to be fired.
The Workstation specified in the Subscription is important. If the field is left blank, all instances of Open Dental will fire the same database event (duplicates). Most subscriptions for database events will specify a workstation. Because the API Service can fire database events, we recommend setting the Subscription.Workstation to the machine on which it is installed. This has the added benefit of processing subscriptions/firing events during the off hours when typical workstations are not running Open Dental.
UiEvents fire immediately and do no utilize a PollingSeconds parameter. Most subscriptions for UiEvents are used for applications installed on each workstation. Therefore, these developers will likely leave the Workstation field blank (so that all machines fire) and use an EndPointUrl containing “localhost”.
Finally, the EndPointUrl of the Subscription can be used in a multitude of ways. Query parameters can be included in this string that your webhook service can use in its parsing logic such as “https://myserver/apievents?type=patientdb”). See an in-depth discussion on this here.
Update: More information has been added to the headers of API event webhooks. The name of the machine that sent the event can be found in the "Workstation" header as of version 22.4.28. Similarly, the type of event fired (e.g. "WatchTable: Appointment") can be found in the "Event-Type" header starting in 22.4.35.
Troubleshooting
Unable to see an event on your webhook service:
- Ensure an instance of Open Dental (or the API Service) is running to process the subscription.
- Ensure the workstation of the subscription either 1) matches the machine running Open Dental/API Service, or 2) is blank. Events will not fire if there is a mismatch.
- For Database events, use Subscriptions GET a few times to see that the DateTimeStart is incremented by PollingSeconds. This will not occur if there is an issue processing the subscription due to the above reasons.
- For database events, make sure the action you are performing actually changes the database. Updating an Appointment’s Confirmed status from “Unconfirmed” to “Unconfirmed” does not actually change the data in the appointment table, and an event will not fire.
- Similarly, selecting the same patient repeatedly will not fire the PatientSelected UiEvent.
- Ensure the EndPointUrl of your Subscription is accurate. Check the documentation of your webhook service for required formatting. Support for some characters (such as trailing ‘/’) varies widely.
- Ensure the Workstation of your subscription specifies a machine name for database events. Leaving this field blank will cause all instances of Open Dental at the dental office to fire the same event.
- If a Workstation is specified, make sure there is only one instance of Open Dental open on the machine processing subscriptions. Having an instance of Open Dental and the API Service running on the specified machine would also produce this result.