Skip to main content

Setting up rules

Healee Rules provide a way to customize and automate actions based on user interactions and events within the Healee platform.

Together with Forms and Tags, Rules are a component of the configurable logic that governs how patients are automatically matched to specific providers or groups of providers.

Supported events that trigger the rules engine include:

  • Profile Created - triggers the rule upon the patient’s profile creation
  • Before Profile Updated
  • After Profile Updated
  • Forms Submitted - triggers the rule upon submission of a registration form
  • Invite Link Opened - triggers the rule upon the patient opening an invitation link
  • Appointment Created - triggers the rule upon the creation of an appointment
  • Patient-Provider Connected

Check the technical guide below for more information on the actual implementation.

Rule actions

When a rule is triggered, its "action" (JavaScript code) is executed.

Rule properties

The key element in the rule's action is the props object which has the following functions:

{
getProperty(name: string, defaultValue: any): any, // Returns a profile property value by its name (e.g. "firstName")
getFilter(): object, // Returns the current provider filter
getDoctor(): { code: string, doctorId: string, bookingDoctorId: number, bookingClinicId?: number }, // Returns an object with the doctor's ID and the doctor's code. This function is available when the rule is triggered by the following events: Invite Link Opened, Appointment Created
getChanges(): object, // Returns the changed fields. This function is available when the rule is triggered by the "Before Profile Updated" event
getForm(formId: string): object, // Returns the submitted form having the specified "formId". This function is available when the rule is triggered by the "Profile Created" and by the "Forms Submitted" events
getFormAnswer(formId: string, answerId: string): object, // Returns the answer from the submitted form (having the specified "formId") having the specified "answerId". This function is available when the rule is triggered by the "Profile Created" and by the "Forms Submitted" events
getScheduledData(): object, // Returns the data object that has been passed to the schedule method (if the current execution of the rule has been scheduled)
getShare(): object, // Returns the object that represents the connection between provider and patient. This function is available when the rule is triggered by the "Patient-Provider Connected" event and can be used for programmatically sending a form to the connected patient
setFilter(filter: object): void, // Sets the new provider filter object
setClinics([ number ]): void, // Sets the IDs of the clinics to which this patient is attached
setDoctors([ { code?: string, doctorId?: string, bookingDoctorId: number } ]): void, // Sets the list of doctors to whom this patient is attached
sendForm(share: object, form: { _id: string, name: string }): void, // Sends a form to the patient on behalf of the provider
sendEmail(email: string, props: object, attachments: [ object ]): void, // Sends an email to a recipient
sendSms(phoneNumber, props: object): void, // Sends an SMS to a recipient
sendSystemMessage(share: object, message: string): void, // Sends a system message (appearing in the patient thread with the provider) to the patient
getTagIdByKey(tagKey: string): number, // Gets the ID of the tag by the tag's name
getPageLink(string: action): string, // Gets a URL of a rule page, which when visited triggers the action for that rule
isPageOpened(): boolean, // Determine whether the current rule action has been triggered by opening a rule page
getPageContext(): object, // Gets the context for the current page action (if the action is triggered by opening a rule page)
showPage(content: string): void, // Shows some HTML content within the opened rule page
schedule(date: Date, data?: object, options?: { taskId?: string, group?: string }): void, // Sets the rule to be executed again at the specified date
unschedule(options?: { ruleName?: string, group?: string }): void, // Unschedule a scheduled rule (the current rule or another one)
isScheduled(): boolean, // Determine whether the current execution of the rule has been scheduled or is triggered by the respective event
fetch(url: string, options?: object): object, // Makes an async HTTP(S) request to the specified URL (should be used with "await")
log(obj1 ... objN: object) // Log data for debugging purposes. Logs are kept for 7 days
}

Provider filters

Here are the different properties that can be used to define provider filters:

{
"specialties": [ number ],
"symptoms": [ number ],
"tags": {
"[Tag Group]": [ number ],
...
},
"practices": {
"city": [ number ],
"region": [ number ],
"insurances": [ number ],
"reasons": [ number ],
"workdays": [ number (1, 2, 3, 4, 5, 6, 7) ],
"locations": [ string ("video", "home_visits", "cabinet") ]
},
"licensed_in": number,
"kids": boolean,
"video": boolean,
"sex": "male" | "female" | "other",
"age": {
"$gt": number // (optional) Greater than
"$lt": number // (optional) Less than
},
"showHidden": boolean,
"allowStartOver": boolean
}

Example Rule definition

const filter = {
tags: {
"Symptoms": []
},
allowStartOver: true
};

if (props.getFormAnswer("myForm", "symptom") === "headache") {
filter.tags["Symptoms"].push(5); // The ID of the tag is copied from the admin panel
}
props.setFilter(filter);