Jobs for Miracle Feet's CommCare to Salesforce integration, using the Open Function platform. See the MiracleFeet India repository for more on the India CAST app integration.
N.B., all changes to the master
branch will be automatically deployed to Open Function.
MiracleFeet has configured CommCare to deliver the "CAST" application to support partner treatment providers and service delivery across 26 countries.
MiracleFeet has implemented OpenFn to automate one-way data integration between CAST (CommCare) and the MF Global System (Salesforce) for real-time monitoring and reporting across CommCare form submissions and case updates.
- Users submit new
forms
or modifycases
in CommCare - A webhook configured in the CommCareHQ project automatically forwards this data to MiracleFeet's OpenFn project
Inbox
asMessages
- OpenFn jobs are triggered to process & upload this CommCare data to Salesforce
- These jobs receive case, location, and form data from CommCare and perform upserts on related business objects in Salesforce in real time.
- We're considering allowing a single job to load data to a variety of different SF instances—making Miracle Feet's OpenFn project effectively a router for various CommCare-Salesforce implementations.
- Mappings that use
humanProper(...)
(e.g.,field('gciclubfoot__Brace_Problems__c', humanProper(state.data.properties.brace_problems)),
) will work for new language-common version.
MiracleFeet global administrators are responsible for integration monitoring & reprocessing of any failed runs. For additional OpenFn support, users may contact [email protected].
Originally the SMS scheduling solution relied on CommCare form updates received in the OpenFn inbox to schedule messages. It has been re-designed to achieve the same functionality based on patient details fetched from Salesforce. See here for the data flow diagrams.
Watch the solution overview video for the original CommCare-Infobip SMS integration for patient visit reminders and educational SMSs.
And see here for the original project concept.
Prerequisites Patients' Salesforce information necessary for SMS scheduling is now being synced from CommCare via the existing Add new patient, Update Patient, Add new visit and Update visit jobs when an update happens in CommCare. These update the new Salesforce fields: SMS Treatment, SMS Original Treatment, SMS Treatment Start Date, and the Pronoun fields. We also make use of the Patient First Name, Guardian First Name, Brace Problems Type, Last and Next Visit dates, and the Send SMS and SMS Opt In fields to create messages and verify consent.
Inbox Security is set up for the projec with Basic Authentication.
How it works...
- An OpenFn job [SMS-Flow-1] Fetch contacts from SF runs daily to query contacts from Salesforce and fetch their treatment and appointment information.
- A second OpenFn job [SMS-Flow-2] Schedule SMSs will be triggered to schedule relevant SMS alerts in the Infobip Portal
We have separate jobs to schedule "Bracing Night" messages and to handle changes in clinic status.
A high-level overview of the SMS jobs can be found here.
The following diagrams describe the SMS scheduling/cancelation logic for the different flows.
- Alerts: scheduling logic for educational messages in the [SMS-Flow-1] Fetch contacts from SF flow.
- Reminders: Appointment reminder scheduling logic in the same SMS Flow.
- Opt-out: SMS cancelation logic when a patient opts out of some or all of the SMS-s, handled in the same SMS flow.
- Deletion: Deleting SMSs for previous treatment in case the treatment has changed or stopped in the same flow.
- Bracing night: Logic for scheduling "Bracing night" messages in the "Bracing Night" flow.
- Deactivated clinic: Logic for canceling all SMSs in case a clinic is deactivated, handled in the deactivation flow.
- Suspended clinic: Canceling appointment reminders for suspended clinic in the deactivation flow.
Alert IDs in the diagrams (e.g. Alert 8
) refer to # Alert in the Master Mapping Table. Admins can check all information on the alert (scheduling time, condition for scheduling, SMS text and translations) in the sheet by Alert ID.
Overview
- SMS-s are scheduled in Infobip using constructed
bulkId
-s.bulkId
are constructed from the alert ID (e.g.casting_intro-1
and the CommCarecase_id
:casting_intro-1-XXX
. They are used to uniquely identify SMS-s in Infobip. - SMS-s are scheduled using
upsert
logic in Infobip: when scheduling or deleting an SMS, OpenFn first checks if an SMS with the correspondingbulkId
has already been scheduled for the future or already sent. If this is the case, no changes are made. If the SMS hasn't been scheduled or sent, it gets scheduled. - In case of deletion, OpenFn checks if an SMS with the corresponding
bulkId
has been scheduled for the future or already sent. If it is scheduled, it gets canceled. - Educational SMS alerts are scheduled following the logic outlined here.
- Visit reminders and missed appointment reminders are scheduled to be sent according to the next visit date indicated in the form. We don't send missed appointments reminders more than 1 week after the appointment date.
- Detailed scheduling conditions and SMS content can be found in the master mapping table. The current Salesforce-based solution uses the Salesforce mapping table. (The previous, CommCare-based job uses a different mapping table.
- Both scheduleSMSv2 and bracing-night jobs use the "[CURRENT] Master Mapping Table Salesforce" mapping. ScheduleSMSV2 schedules alert
8
and9
of the bracing-night messages and all the other (non-bracing-night) alerts. The bracing-night job only schedules alerts9B
to9P
. - SMS scheduling times are adjusted for local time zones.
- SMS-s are only scheduled to be sent between 8am-8pm local time.
- We only schedule SMS if
Guardian_1_Phone_Landline__c == false
on the Patient's Salesforce profile. - Errors returned by the Infobip API for incorrect phone numbers are uploaded regularly to Contacts' SMS Error field. We only schedule SMS to patients where this is empty, and we delete scheduled alerts for Contacts that have any SMS Errors marked.
- Due to limitations of the Infobip API, we don't schedule any messages for more than 6 months ahead.
Logic for setting missed appointment reminders
SMS reminders are scheduled to be sent if a patient misses an appointment they are scheduled for. This is set when a new next_visit_date
is added. If there were alerts set for previous visits, those are canceled in Infobip.
Used values: last_visit_date/original_next_visit_date
for previous scheduled visits, next visit date
for next visit
Steps
-
Check if there’s a last visit date. If so, check if these bulkIDs have been scheduled
visitAfter1-{form.case.@case_id}-{last_visit_date}
visitAfter2-{form.case.@case_id}-{last_visit_date}
If yes, delete them. -
Schedule the reminders with the current next visit date
visitAfter1-{form.case.@case_id}-{next_visit_date}
visitAfter2-{form.case.@case_id}-{next_visit_date}
Scheduling a message on the Infobip API
curl --location --request POST 'https://apidomain.infobip.com/sms/1/text/advanced' \
--header 'Authorization: App ${api_key}' \
--data-raw '{"bulkId": "bracing_day-6-345678", "messages":[{"from": "+111","destinations": [{"to": "+111"}],"text": "A long time ago, in a galaxy far, far away...","sendAt": "2021-12-24T18:20:00.000"}]}'
Opt-in, opt-out
- Opting in to receiving SMS-s:
Send_SMS__c = true
- Opting in to receive educational messages:
SMS_Opt_In_II__c = true
- Opting in to receive visit reminders:
SMS_Opt_In__c = true
Treatment changes, stopping treatment
When a patient is marked as stopped, suspended or completed treatment, they will no receive educational messages and visit reminders. If they move from one treatment to a different one, educational messages for the original treatment are stopped and SMS campaign for the new treatment is scheduled.
Scheduling "Bracing Night" SMSs
Since September 2021 it's not possible to schedule messages on the Infobip API for more than 6 month ahead.
The Bracing Night
SMS campaign runs for more than 3.5 years. We use the following process to schedule these messages:
We run the [Bracing-night 1] Fetch bracing night contacts from SF job to check on SF if there's any contact that has Bracing Night set as SMS Treatment.
The [Bracing-night 2] Schedule bracing night SMSs will then automatically launch to schedule any necessary SMSs for the next 3 months, based on the SMS_Treatment_Start_Date__c
field.
Clinic status and SMS scheduling
Clinic status is set in Salesforce, in the Status field.
All "Actively supported" clinics are eligible for SMS (although not all have it turned on)
We run the [Deactivation-1] Fetch Inactive Clinics from SF job daily to check for clinics that are inactive and disable SMS-s for associated patients guided by the below logic:
- "Previously Supported" and "Active - CAST Guest User Only" clinics are inactive, we cancel all SMSs for patients
- For "Temporarily Suspended" clinics we cancel patients' appointment reminders. If clinic Status changed back to actively supported, the admin will need to re-enroll each individual in reminders.
** To enroll a new country to SMS**
- Turn on SMS for the CommCare user (
send_sms
field) - Add country to Fetch contacts and Fetch bracing night contacts jobs, e.g.:
Account.Country__c in ('Nigeria', 'Uganda')
To update SMS scheduling times, SMS templates, SMS language codes, or add new translations:
- Make a copy of the Master Mapping Table.
- Make your edits in the new sheet (see an example here).
- Notify OpenFn support at [email protected] to implement the changes.
Migration Checklist
Access here.
- Copy the whole content of the mapping table
- Paste on this converter at the left pane https://csvjson.com/csv2json
- Get the generated json
- Paste it on content-input.json
- Execute
node mappings/converter.js
- Copy the resulting content from content-output-minified.js https://github.com/OpenFn/Miracle-Feet/blob/master/mappings/content-output-minified.js
- Paste it in the job in place of mapping variable at line 3. If there is code formatting enabled, it might expand the contents. In that case, undo that last change to make sure content is on one line. There are 2 jobs to update:
- The entire mapping sheet should be added to: https://github.com/OpenFn/Miracle-Feet/blob/master/schedule_smsV2.js
- Only the "Bracing Night" messages to be added to: https://github.com/OpenFn/Miracle-Feet/blob/master/2.scheduleContactSMS.js
To add/remove alerts or reminders, update CommCare field names, change opt-in/opt-out conditions, add new CommCare forms that trigger SMS-s, or any other change, contact [email protected].
SMS scheduling only happens for patients whose Clinic Status
in Salesforce is either in "Actively Supported" or "Temporarily Suspended". In order to add or remove clinic from the scheduling flow, change the Clinic Status accordingly. To opt a clinic into SMS alerts, this Status
should be updated in Salesforce.
Administrator Training Slides
Change Management Training Slides
Salesforce-based flow roll-out
- Finish testing to sign-off on alert scheduling logic. See new test suite.
- Sync
Brace Problems Type
data to patients in Salesforce - Deactivate original Schedule SMS job
- Link [SMS-Flow-1] Fetch contacts from SF job to timer trigger
Original flow roll-out
- Finish testing across countries to sign-off on alert scheduling logic & content. See Test Suite for detailed unit tests. and the updated test suite for the Salesforce-Infobop integration.
- Remove code in OpenFn job that executes flow only for test users
- Confirm all Infobip sender IDs are correct
- System admin training on solution management
- ...
- [ ]