-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredcap_hooks.php
More file actions
142 lines (99 loc) · 5.1 KB
/
redcap_hooks.php
File metadata and controls
142 lines (99 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
Custom REDCap Hooks File
It is possible to configure your hooks in many ways. In playing around with a few I've adopted this convention:
Inside your base redcap directory you should create a folder called hooks. So, your directory might look like this:
- redcap_vx.y.z
- temp
- webtools2
- plugins
- hooks
Inside the hooks directory you need a 'main' hook configuration file (this file!) which I call redcap_hooks.php
In the Control Center under general settings, you have to define the location of this file, something like:
/var/html/www/redcap/hooks/redcap_hooks.php)
The purpose of this configuration is to permit you to have a single hook function call from REDCap call both
global and project-specific hooks. Because I like things complicated, there are two methods to include either
a global or project-specific hook:
Method 1: A 'master' hooks file exists for global and each project. Each file can 'catch' all hook calls and use
simple if-then syntax to decide which events to process. These files should be located at
hooks/global/global_hooks.php
hooks/pidxxx/custom_hooks.php
Method 2: A custom hook file for each hook function (named the same as the hook function itself). Examples include
hooks/global/redcap_custom_verify_username.php
hooks/pidxxx/redcap_data_entry_form.php
Any combination of methods 1 and 2 can be used. Exercise caution in defining new functions that could be included
more than once for a given hook event (or use custom namespaces).
Also inside this hooks directory I have the following:
- hooks_common.php (a file with utility functions and constants you might want to adjust)
- global (a directory with hooks to be applied for all projects)
- pidxxx (a folders for project-specific hooks
- pid_TEMPLATE (a template folder that contains the template functions for a new project-specific hooks)
Andrew Martin
Stanford University
**/
// Turn on error reporting
error_reporting(E_ALL);
// Include the common functions
require_once('hooks_common.php');
### FOR EACH HOOK METHOD IN REDCAP, A FUNCTION OF MATCHING NAME SHOULD BE ENTERED BELOW
// redcap_add_edit_records_page (REDCap >= 6.8.0)
function redcap_add_edit_records_page ($project_id, $instrument, $event_id) {
// Example use of hook_log to track time to execute a hook:
$hook_start_time = microtime(true);
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
hook_log(" - $hook_event took " . hook_exec_time($hook_start_time), 'DEBUG');
}
// redcap_add_edit_records_page (REDCap >= 5.11.0)
function redcap_control_center() {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event) as $script) include $script;
}
// redcap_add_edit_records_page (REDCap >= 5.8.0)
function redcap_custom_verify_username($username) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event) as $script) include $script;
}
// redcap_data_entry_form (REDCap >= 5.11.0)
function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_data_entry_form_top (REDCap >= 6.8.0)
function redcap_data_entry_form_top($project_id, $record, $instrument, $event_id, $group_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_project_home_page (REDCap >= 6.9.0)
function redcap_project_home_page($project_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_save_record (REDCap >= 5.11.0)
function redcap_save_record($project_id, $record, $instrument, $event_id, $group_id, $survey_hash, $response_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_survey_complete (REDCap >= 5.11.0)
function redcap_survey_complete($project_id, $record, $instrument, $event_id, $group_id, $survey_hash, $response_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_survey_page (REDCap >= 5.11.0)
function redcap_survey_page($project_id, $record, $instrument, $event_id, $group_id, $survey_hash, $response_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_survey_page_top (REDCap >= 6.8.0)
function redcap_survey_page_top($project_id, $record, $instrument, $event_id, $group_id, $survey_hash, $response_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// redcap_user_rights (REDCap >= 5.11.0)
function redcap_user_rights($project_id) {
$hook_event = __FUNCTION__;
foreach (get_hook_include_files($hook_event, $project_id) as $script) include $script;
}
// INSERT ADDITONAL HOOKS HERE AS THEY ARE DEVELOPED HERE
/////////////////////////////////////
hook_log("------------ redcap_hooks loaded ------------", "DEBUG");