-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlibrary.js
executable file
·226 lines (174 loc) · 7.01 KB
/
library.js
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"use strict";
var customFields = {
npi : "",
institution : "",
practicetype : "",
specialty : "",
practiceyears : ""
},
customData = [],
user = module.parent.require('./user'),
db = module.parent.require('./database'),
plugin = {};
plugin.init = function(params, callback) {
var app = params.router,
middleware = params.middleware,
controllers = params.controllers;
app.get('/admin/custom-registration-fields', middleware.admin.buildHeader, renderAdmin);
app.get('/api/admin/custom-registration-fields', renderAdmin);
callback();
};
plugin.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/custom-registration-fields',
icon: 'fa-tint',
name: 'Custom Registration Fields'
});
callback(null, header);
};
plugin.customHeaders = function(headers, callback) {
for(var key in customFields) {
switch(key) {
case 'npi':
var label = "NPI #";
break;
case 'institution':
var label = "Institution";
break;
case 'practicetype':
var label = "Practice Type";
break;
case 'specialty':
var label = "Specialty";
break;
case 'practiceyears':
var label = "Practice Years";
break;
}
headers.headers.push({
label: label
});
}
callback(null, headers);
};
plugin.customFields = function(params, callback) {
var users = params.users.map(function(user) {
if (!user.customRows) {
user.customRows = [];
for(var key in customFields) {
user.customRows.push({value: customFields[key]});
}
}
return user;
});
callback(null, {users: users});
};
plugin.addField = function(params, callback) {
for(var key in customFields) {
if (key == "") {
callback(null, params);
return;
}
switch(key) {
case 'npi':
var html = '<input class="form-control" type="text" name="npi" id="npi" placeholder="Enter NPI #"><span class="custom-feedback" id="npi-notify"></span><span class="help-block">A unique 10-digit identification number.</span>';
var label = "NPI #";
break;
case 'institution':
var html = '<input class="form-control" type="text" name="institution" id="institution" placeholder="Enter Institution"><span class="custom-feedback" id="institution-notify"></span>';
var label = "Institution";
break;
case 'practicetype':
var html = '<select class="form-control" name="practicetype" id="practicetype"><option value="" disabled="" selected="">Select your practice type</option><option value="1">Academic</option><option value="2">Community</option><option value="3">Hospital</option></select><span class="custom-feedback" id="practice-notify"></span>';
var label = "Practice Type";
break;
case 'specialty':
var html = '<select class="form-control" name="specialty" id="specialty"><option value="" disabled="" selected="">Select your specialty</option><option value="1">Oncology</option><option value="2">Hematology</option><option value="3">Oncology/Hematology</option><option value="4">Radiation Oncology</option><option value="5">Nuclear Medicine</option><option value="5">Surgery</option></select><span class="custom-feedback" id="specialty-notify"></span>';
var label = "Specialty";
break;
case 'practiceyears':
var html = '<select class="form-control" name="practiceyears" id="practiceyears"><option value="" disabled="" selected="">Select your years in practice</option><option value="1">In Training</option><option value="2">1 to 3 Years</option><option value="3">4 to 7 Years</option><option value="4">8 to 10 Years</option><option value="5">>10 Years</option></select><span class="custom-feedback" id="years-notify"></span>';
var label = "Practice Years";
break;
}
var captcha = {
label: label,
html: html
};
if (params.templateData.regFormEntry && Array.isArray(params.templateData.regFormEntry)) {
params.templateData.regFormEntry.push(captcha);
} else {
params.templateData.captcha = captcha;
}
}
callback(null, params);
};
plugin.checkField = function(params, callback) {
var userData = params.userData;
var error = null;
for(var key in customFields) {
var value = userData[key];
if (key == 'npi') {
if (value.length != 10) {
error = {message: 'NPI # must be 10 digits'};
}
else if (!/^[0-9]+$/.test(value)) {
error = {message: 'NPI # must be a numerical value'};
}
}
else if (value == "" || value == undefined) {
error = {message: 'Please complete all fields before registering.'};
}
}
callback(error, params);
};
plugin.creatingUser = function(params, callback) {
customData = params.data.customRows;
callback(null, params);
};
plugin.createdUser = function(params) {
var addCustomData = {
npi : customData[0].value,
institution : customData[1].value,
practicetype : customData[2].value,
specialty : customData[3].value,
practiceyears : customData[4].value
}
var keyID = 'user:' + params.uid + ':ns:custom_fields';
db.setObject(keyID, addCustomData, function(err) {
if (err) {
return callback(err);
}
});
};
plugin.addToApprovalQueue = function(params, callback) {
var data = params.data;
var userData = params.userData;
data.customRows = [];
for (var key in customFields) {
switch(key) {
case 'npi':
var fieldData = params.userData['npi'];
break;
case 'institution':
var fieldData = params.userData['institution'];
break;
case 'practicetype':
var fieldData = params.userData['practicetype'];
break;
case 'specialty':
var fieldData = params.userData['specialty'];
break;
case 'practiceyears':
var fieldData = params.userData['practiceyears'];
break;
}
customFields[key] = fieldData;
data.customRows.push({value: customFields[key]});
}
callback(null, {data: data, userData: userData});
};
function renderAdmin(req, res, next) {
res.render('admin/custom-registration-fields', {fields: customFields});
}
module.exports = plugin;