Your integration could be considered complete now that you have the feature loaded on the page. However, there’s more you can do to create a seamless user experience.
Fullscript.js fires events when actions happen that your app may want to know about. For example, an event is fired when a practitioner finishes creating a treatment plan for a patient. The event includes data about the treatment plan that your app can store. When receiving this event, you’ll also know the user is done with the feature and you can choose to unmount it.
Unmounting is optional. It removes the feature from your page, but you can also leave it there, or navigate away if that makes sense for your use case.
Take a moment to review the available events for your feature.
To listen for the events fired by the embedded feature, subscribe with treatmentPlanFeature.on()
.
Create a function to call when the patient.selected
event is triggered.
Connect this to the event with treatmentPlanFeature.on()
.
function handlePatientSelected(data) {
console.log("data", data);
// Use this as an opportunity to save the Fullscript patient id,
// unmount the feature, change page etc
}
treatmentPlanFeature.on("patient.selected", handlePatientSelected);
Or, use TypeScript (if using NPM version) to add the EventListener:
const handlePatientSelected = (data: EventListenerPayload<"patient.selected">) => {
console.log(data);
// Use this as an opportunity to save the Fullscript patient id,
// unmount the feature, change page etc
};
Create a function to call when the treatmentPlan.activated
event is triggered.
Connect this to the event with treatmentPlanFeature.on()
.
function handleTreatmentPlanActivated(data) {
console.log("data", data);
// Use this as an opportunity to store data about the plan,
// unmount the feature, change page etc
}
treatmentPlanFeature.on("treatmentPlan.activated", handleTreatmentPlanActivated);
Alternately, use TypeScript (if using NPM version):
const handleTreatmentPlanActivated = (data: EventListenerPayload<"treatmentPlan.activated">) => {
console.log("data", data);
// Use this as an opportunity to store data about the plan,
// unmount the feature, change page etc
};
If desired, you can also stop listening to an event:
treatmentPlanFeature.off("treatmentPlan.activated", handleTreatmentPlanActivated);
treatmentPlanFeature.off("patient.selected", handlePatientSelected);