SMS hook request

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

SMS hook request

Post by mopensoft » Tue Nov 05, 2013 5:46 pm

Hi Opendental

I would like to have some hook for SMS added to OD source code.

The first hook is in the FormTxtMsgEdit.SendText function. This allow to used other SMS provider.

Code: Select all

public void SendText(long patNum,string wirelessPhone,string message,YN txtMsgOk) {
            if (OpenDentBusiness.Plugins.HookMethod(this, "FormTxtMsgEdit.SendText", patNum, wirelessPhone, message, txtMsgOk))
                return;

			if(wirelessPhone=="") {
				MsgBox.Show(this,"Please enter a phone number.");
				return;
			}
The second hook is in the FormConfirmList.FormConfirmList_Load function. This allows users to send confirm texts using different SMS provider

Code: Select all

if (!Programs.IsEnabled(ProgramName.CallFire))
            {
                butText.Enabled = false;
            }
            FillMain();

            // Minh Test
            Plugins.HookAddCode(this, "FormConfirmList.Load_End", butText);
        }
In FormConfirmList.butText_Click function, there's a checking for CallFire plugin to before sending text. It's good to have another checking there but it's actually duplicated since if CallFire is not enabled, the Text button is disable anyway. I would like to have this 'if condition' removed, since I could not find a good way to replace this function with a plugin method because at the end of the function, it call FillMain() to refresh the grid. If I want to call the private method FillMain() from plugin, I think I have to rewrite the function in my plugin. Is there any way to call a private method in OD from the plugin?

Code: Select all

 if (grid.Rows.Count == 0)
            {
                MsgBox.Show(this, "There are no Patients in the table.  Must have at least one.");
                return;
            }
           if (!Programs.IsEnabled(ProgramName.CallFire))
            {
                MsgBox.Show(this, "CallFire must be enabled to send text messages. Go to Setup | Program Links | CallFire, and enable CallFire.");
                return;
            }
            if (PrefC.GetLong(PrefName.ConfirmStatusTextMessaged) == 0)
            {
                MsgBox.Show(this, "You need to set a status first for confirmation text messages in the Recall Setup window.");
                return;
            }
Thanks

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Wed Nov 06, 2013 12:38 pm

I will look into adding these soon.
Allen
Open Dental Software
http://www.opendental.com

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Thu Nov 07, 2013 8:53 am

public void SendText(long patNum,string wirelessPhone,string message,YN txtMsgOk) {
if(Plugins.HookMethod(this,"FormTxtMsgEdit.SendText_Start",patNum,wirelessPhone,message,txtMsgOk)) {
return;
}

if(wirelessPhone=="") {
MsgBox.Show(this,"Please enter a phone number.");
return;
}
I changed your hook to reflect our patterns better. We try to use { } around any if statement, including one liners.
This hook has been added
if (!Programs.IsEnabled(ProgramName.CallFire))
{
butText.Enabled = false;
}
FillMain();

// Minh Test
Plugins.HookAddCode(this, "FormConfirmList.Load_End", butText);
}
This hook has been added.
if (grid.Rows.Count == 0)
{
MsgBox.Show(this, "There are no Patients in the table. Must have at least one.");
return;
}
if (!Programs.IsEnabled(ProgramName.CallFire))
{
MsgBox.Show(this, "CallFire must be enabled to send text messages. Go to Setup | Program Links | CallFire, and enable CallFire.");
return;
}

if (PrefC.GetLong(PrefName.ConfirmStatusTextMessaged) == 0)
{
MsgBox.Show(this, "You need to set a status first for confirmation text messages in the Recall Setup window.");
return;
}
This code was removed so you shouldn't need to call FillMain().

All of these hooks were added to 13.3 and will be available when it is released to the public.
Allen
Open Dental Software
http://www.opendental.com

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Thu Nov 07, 2013 9:00 pm

Thanks mate.
This is my first hook request and didn't think OpenDental proceeds it that quick. Really appreciate!

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Mon Dec 09, 2013 2:46 pm

Hi Allen

I would like to add one more hook in FormApptEdit to enable the "Text" button:

#if DEBUG
Text="AptNum"+AptCur.AptNum;
#endif


Plugins.HookAddCode(this, "FormApptEdit.Load_End", pat, butText);

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Mon Dec 09, 2013 2:55 pm

Hi Allen

I would like to add one more hook at the end of FormApptEdit_Load() function in FormApptEdit.cs to enable the "Text" button:

Code: Select all

#if DEBUG
				Text="AptNum"+AptCur.AptNum;
			#endif
            
           
            [b]Plugins.HookAddCode(this, "FormApptEdit.Load_End", pat, butText)[/b];
One more function I want to change is SendText() function in FormTxtMsgEdit(). I think after sending message, usually SMS provider returns a response. It would be good to return that response value to see if you the text was successfully sent or not. Of course you can display the response in the SendText() function itself in a message box but in FormConfirmList.cs, SendText() function is called multiple times, it'd better to display the response once instead of one for each message sent. So if you can change the SendText() to return a string, it's more flexible.

Thanks

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Tue Dec 10, 2013 8:23 am

I will look into adding this soon.
Allen
Open Dental Software
http://www.opendental.com

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Tue Dec 10, 2013 12:23 pm

I backported the FormApptEdit_Load plugin to 13.2.

As for the change to the SendText method, this is more of a feature request. Coding the method to return the response of the sent message would be more involved than a simple plugin request.
If you have an idea for how to do this with a plugin, then I could easily change the method to return a string.
Allen
Open Dental Software
http://www.opendental.com

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Wed Dec 11, 2013 2:35 pm

Does it mean that all the hooks I requested are now available on 13.2 too? it's great.

The reason I asked for return is that when you send confirm SMS, you need to know whether it's successfully sent or not before you set the status of appointment to be "Texted". Currently, it doesn't matter, the status will be "Texted" after you click "Text" button. So the return of SendText() function can be just true/false. I guess you need to check the return of the function before setting the appointment status.

Code: Select all

FormTME.SendText(patNum,wirelessPhone,message,txtMsgOk);
Appointments.SetConfirmed(PIn.Long(Table.Rows[grid.SelectedIndices[i]]"AptNum"].ToString()),PrefC.GetLong(PrefName.ConfirmStatusTextMessaged));

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Thu Dec 12, 2013 7:59 am

All of these hooks are now backported to 13.2 and will be available with the next release.

I see what you mean about the text message changes. I will add this to our bug list to fix, but it is a lower priority bug so it may be a bit before it gets attention.
Thanks for the help though. :)
Allen
Open Dental Software
http://www.opendental.com

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Thu Dec 12, 2013 2:37 pm

Thanks mate, it would be great to have the hooks on 13.2 since most of OpenDental users do not have 13.3 yet.

I am not sure make SendText return a boolean or string can help as I dont see you you can get return value from the hook function. It's only return true or false if the hook exist or not respectively. If you can help me to return a value from hook, it's very good

Cheers
Minh

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Fri Dec 13, 2013 7:20 am

The SendText returning a boolean would be to fix our current validation to prevent methods that are not sent from becoming marked as texted.

If I changed the return type of the SendText method to a boolean then you could do something like this
bool hasSent
object[] parameters={hasSent,patNum,wirelessPhone,message,txtMsgOk};
if(Plugins.HookAddCode(this,"FormTxtMsgEdit.SendText_Start", parameters)) {
hasSent=(bool)parameters[0];
return hasSent;
}
Allen
Open Dental Software
http://www.opendental.com

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Mon Jan 06, 2014 3:07 pm

Thanks for showing me the way to get return value from hook methods. It's very useful.

Also I want to add another hook which enable sending recall sms. The hook is at the end of FormRecallList_Load function:

Code: Select all

Plugins.HookAddCode(this, "FormRecallList.Load_End", table);
Thanks
Minh

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: SMS hook request

Post by allends » Wed Jan 08, 2014 8:12 am

Plugins.HookAddCode(this, "FormRecallList.Load_End", table);

This has been backported to 13.2 and will be released in the next update.
Allen
Open Dental Software
http://www.opendental.com

User avatar
mopensoft
Posts: 146
Joined: Tue Dec 04, 2012 3:33 pm
Location: Melbourne, Australia
Contact:

Re: SMS hook request

Post by mopensoft » Wed Jan 08, 2014 3:44 pm

Thanks mate.

I get some request to get SMS reply for appointment confirmation. It's easy to get the reply back but it's hard to update the right appointment with only patient name and appointment time. I'm wondering whether OpenDental include the appointment ID in the test message template. I can easily add [AptNum] field into the template and replace it with actually appointment id or remove it when interpret the message. But it helps when I receive reply, I get enough information to create common log for user to track the confirmation.

Cheers
Minh

Post Reply