New Hook Request

This forum is for programmers who have questions about the source code.
Post Reply
dmadsen
Posts: 2
Joined: Thu Feb 11, 2016 10:26 am

New Hook Request

Post by dmadsen » Wed May 04, 2016 12:12 pm

Could you please add the following hooks?

Thanks,


1. In the FormCreditCardEdit form at very end of FormCreditCardEdit_Load

Code: Select all

Plugins.HookAddCode(this,"FormCreditCardEdit.Load_end",PatCur);
2. In the form FormCreditRecurringCharges in the middle of the FillGrid() method.

After this line:

Code: Select all

table=CreditCards.GetRecurringChargeList();
But before this line:

Code: Select all

table.Columns.Add("RepeatChargeAmt");

Code: Select all

bool isValid = false;
   object[] parameters = { table, isValid };
   Plugins.HookAddCode(null, "CreditCards.GetRecurringChargeList_end", parameters);
   if ((bool)parameters[1] == true)
   {
       table = (DataTable)parameters[0];
   }
3. In the FormAdjust form at the end of the FormAdjust_Load method

Code: Select all

Plugins.HookAddCode(this, "FormAdjust.Load_end", AdjustmentCur, PatCur);
4. In the FormAdjust form at the beginning of the butOK_Click method

Code: Select all

bool isValid = true;
   object[] parameters = new object[] { isValid, sender, PatCur };
   Plugins.HookAddCode(this, "FormAdjust.butOK_Click_beginning", parameters);
   if ((bool)parameters[0] == false)
   {//Didn't pass plug-in validation
       DialogResult = DialogResult.OK;
       return;
   }
5. In the FormAdjust form at the beginning of the butDelete_Click method

Code: Select all

 bool isValid = true;
   object[] parameters = new object[] { isValid, sender, PatCur };
   Plugins.HookAddCode(this, "FormAdjust.butDelete_Click_beginning", parameters);
   if ((bool)parameters[0] == false)
   {//Didn't pass plug-in validation
       DialogResult = DialogResult.OK;
       return;
   }
6. In the ContrAccount form in the gridAccount_CellDoubleClick method

After this line:

Code: Select all

else if(table.Rows[e.Row]["PayPlanNum"].ToString()!="0"){
           PayPlan payplan=PayPlans.GetOne(PIn.Long(table.Rows[e.Row]["PayPlanNum"].ToString()));
But before this line:

Code: Select all

FormPayPlan2 = new FormPayPlan(PatCur,payplan);

Code: Select all

bool isValid = false;
   object[] parameters = { PatCur, payplan, isValid };
   Plugins.HookAddCode(this, "ContrAccount.gridAccount_CellDoubleClick_middle", parameters);
   if ((bool)parameters[2] == true)
   {
      bool isSelectFamily = gridAcctPat.GetSelectedIndex() == this.DataSetMain.Tables["patient"].Rows.Count - 1;
      ModuleSelected(PatCur.PatNum, isSelectFamily);
      return;   
   }
7. In the ContrAccount form in the gridAccount_CellDoubleClick method

After this line:

Code: Select all

if(table.Rows[e.Row]["PayPlanNum"].ToString()!="0") {//Payment plan
           PayPlan payplan=PayPlans.GetOne(PIn.Long(table.Rows[e.Row]["PayPlanNum"].ToString()));
But before this line:

Code: Select all

FormPayPlan2 = new FormPayPlan(PatCur,payplan);

Code: Select all

bool isValid = false;
   object[] parameters = { PatCur, payplan, isValid };
   Plugins.HookAddCode(this, "ContrAccount.gridPayPlan_CellDoubleClick_middle", parameters);
   if ((bool)parameters[2] == true)
   {
       bool isSelectFamily = gridAcctPat.GetSelectedIndex() == this.DataSetMain.Tables["patient"].Rows.Count - 1;
       ModuleSelected(PatCur.PatNum, isSelectFamily);
       return;
   }
8. In the ContrAccount form in the toolBarButPayPlan_Click method

After this line:

Code: Select all

PayPlans.Insert(payPlan);
But before this line:

Code: Select all

FormPayPlan FormPP =new FormPayPlan(PatCur,payPlan);

Code: Select all

bool isValid = false;
   object[] parameters = { PatCur, payPlan, isValid };
   Plugins.HookAddCode(this, "ContrAccount.toolBarButPayPlan_Click_middle", parameters);
   if ((bool)parameters[2] == true)
   {
       ModuleSelected(PatCur.PatNum);
       return;
   }
9. In the ContrAccount form at the end of the FillPaymentPlans method

Code: Select all

Plugins.HookAddCode(this, "ContrAccount.FillPaymentPlans_end", PatCur, table);
This is my first attempt at requesting hooks, so if my naming isn't what it should be or anything else needs to be changed, let me know.

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: New Hook Request

Post by jsalmon » Wed May 04, 2016 3:10 pm

Welcome to the forums and welcome to the wonderful world of plugins. My following post might seem harsh but I'm not trying to be so please don't take it that way. We're here to help you and get your hooks added to the program in such a way that will be most beneficial to you, other developers (might take advantage of your hooks as well), and for ourselves (so that our customers not using any plugins don't notice any strange behavior).

With that in mind, a lot of your hooks can be simplified and more control will be put into your hands (good for both parties). You should try to enhance your plug-in to utilize the following hook examples instead of some of the ones requested. With the following examples I'm about to make you will be able to enhance your plug-in(s) with new features and new logic in the future without having to request any changes to the hooks you've just requested we make. Basically your plug-in will be enhanced to have most (hopefully all) logic necessary for the lifespan of your plug-in so that you don't have to request more parameters or any logical changes. A lot of your hook requests have us (Open Dental) doing your isValid logic check which we don't want to do for you (nothing personal :D ). Instead, you should return false from your methods within your Plugin.cs class which will in the end act like your plug-in doesn't support the hook (OD will then act as it usually does which is what your users will typically desire). You can even show a message box that tells them some sort of error like "Super Awesome Plug-in Validation Failed" and then return false to Open Dental (even though your plug-in did in fact act upon the hook) so that business can go on as usual.

E.g.
#2 doesn't need any validation code within Open Dental. Do that within your plug-in

Code: Select all

   bool isValid = false;
   object[] parameters = { table, isValid };
   Plugins.HookAddCode(null, "CreditCards.GetRecurringChargeList_end", parameters);
   if ((bool)parameters[1] == true)
   {
       table = (DataTable)parameters[0];
   }
can instead be:

Code: Select all

object[] parameters={ table };
Plugins.HookAddCode(...);
table=(DataTable)parameters[0];
With the example above, simply return false or don't manipulate the table parameter within your plug-in code if the user "fails validation".

#4 is slightly different because you want to set the DialogResult and return if they don't pass your validation. Why would you want to close the adjustment window and not save anything if they didn't pass your validation? I'd prefer if you left the adjustment window open and left the user looking at the window instead of closing it under their feet (not saving any of their data):

Code: Select all

   bool isValid = true;
   object[] parameters = new object[] { isValid, sender, PatCur };
   Plugins.HookAddCode(this, "FormAdjust.butOK_Click_beginning", parameters);
   if ((bool)parameters[0] == false)
   {//Didn't pass plug-in validation
       DialogResult = DialogResult.OK;
       return;
   }
can instead be:

Code: Select all

if(Plugins.HookMethod(...)) {
	return;
}
With the example above, you'll return false to Open Dental within your Plugin.cs when the user passes validation (you do the code you want your plug-in to do and then returning false will continue with the Open Dental logic). If they fail your validation, return true and maybe show a message letting the user know why the window isn't going to close and save their changes.

Same thing with #5

#6 is unique because you want to call "ModuleSelected". You already have access to gridAcctPat (see our plug-in example project that has example code on how to loop through controls from sender) so you should only need to get fancy with how you invoke ModuleSelected and then this can also turn into a HookMethod instead of a HookAddCode.
I'll let you figure out the ContrAccount.cs hook code with the new knowledge given from the examples above for #2 and #4 and will instead help you with invoking ModuleSelected from within your Plugin.cs class:

Code: Select all

((ContrAccount)sender).ModuleSelected(PatCur.PatNum);
Same thing with #7 and #8

Let me know if and how the above examples don't work for you (if in fact they won't work for your scenario) and we'll help you figure out a good solution. Once again, the less code that is within Open Dental for your hooks, the better it is for you. I've written several plug-ins and am glad that the majority of the logic and control is within my plug-in class(es) instead of dependent on code within Open Dental after my plug-in code executes.
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

Post Reply