So I think what would work out best here is to add events to override any currently added form in the system with the form in the module.
Something along the lines of
$event = new CustomFormEvent($_GET['formname']); // CustomFormEvent would need to be added to the core system
$event->setFormPathLocation($incdir/forms/ . $_GET["formname"]);
$event =$GLOBALS["kernel"]->getEventDispatcher()->dispatch(CustomFormEvent::FILTER_CUSTOM_FORM_LOCATION, $event);
// the getFormPathLocation or the setFormPathLocation should have security checks to make sure a file cannot be included outside of the OpenEMR modules or regular forms directory for safety. Don't want anyone accidently including data inside the patient documents directory
// for load_forms.php
include_once $event->getFormPathLocation() . "/new.php";
// for forms.php
include_once $event->getFormPathLocation() . "/report.php";
// view_form.php
include_once $event->getFormPathLocation() . "/view.php";
In your module you would just listen to the CustomFormEvent::FILTER_CUSTOM_FORM_LOCATION and then return the location for your module.
That solves the case for forms.php, load_form.php, and view_form.php.
To deal with the sql piece that you are adding in the InstModuleTable.php I would add into your module’s table.sql file the following
-- You would add this for each encounter form you are adding. I'm using the example of phq9 here as an example
-- Note the #IfNotRow syntax will only add the registry item if it does not currently exist with a form name of 'phq9'
#IfNotRow registry name phq9
INSERT INTO registry SET name="phq9", state=0, directory="my_custom_modules", sql_run=0, unpackaged=1, category="Clinical",patient_encounter=1, therapy_group_encounter=0, aco_spec="encounters|notes", date=NOW();
#EndIf
We do need to add to our module installer another file to execute sql to uninstall the form as we don’t currently have the ability to execute any code in the module when a module is removed.
I probably won’t be able to get to this until next week or the week after if I were to code it up. However, I’m happy to review it and offer suggestions if you want to make a pull request from your github repository. If you write up the CustomFormEvent and stick it in the src/Events/Core/ folder then I can review this for you. You’ll need to add the dispatch of the events to the three files (forms.php, load_form.php, view_form.php) but hopefully that won’t be too tough seeing the changes you’ve already made.
Hope that helps. If you need help knowing how to make a pull request, you can see our contributing guide here https://github.com/openemr/openemr/blob/master/CONTRIBUTING.md (Steps 1-9 at the top, you can skip the local docker piece if you’ve already got OpenEMR installed a different way).