-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathregisterPatient.js
More file actions
399 lines (332 loc) · 16.1 KB
/
registerPatient.js
File metadata and controls
399 lines (332 loc) · 16.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
jq = jQuery;
// TODO refactor this all into something cleaner
// we expose this in the global scope so that other javascript widgets can access it--probably should have a better pattern for this
var NavigatorController;
function importMpiPatient(id) {
$.getJSON(emr.fragmentActionLink("registrationapp", "registerPatient", "importMpiPatient", {mpiPersonId: id}))
.success(function (response) {
var link = patientDashboardLink;
link += (link.indexOf('?') == -1 ? '?' : '&') + 'patientId=' + response.message;
location.href = link;
})
.error(function (xhr, status, err) {
alert('AJAX error ' + err);
});
}
jq(function() {
NavigatorController = new KeyboardController();
/* Similar patient functionality */
reviewSimilarPatients = emr.setupConfirmationDialog({
selector: '#reviewSimilarPatients',
actions: {
cancel: function () {
reviewSimilarPatients.close();
}
}
});
jq('#reviewSimilarPatientsButton').click(function () {
var slideView = $("#similarPatientsSlideView");
slideView.slideToggle();
return false;
});
function showSimilarPatients(data) {
if (data.length == 0 || jq('#checkbox-unknown-patient').is(':checked')) {
jq("#similarPatients").hide();
jq("#similarPatientsSlideView").hide();
return;
} else {
jq("#similarPatients").show();
}
jq('#similarPatientsCount').text(data.length);
var similarPatientsSelect = jq('#similarPatientsSelect');
similarPatientsSelect.empty();
for (index in data) {
var item = data[index];
var isMpi = false;
if (data[index].mpiPatient != null && data[index].mpiPatient == true) {
isMpi = true;
}
var container = $('#matchedPatientTemplates .container');
var cloned = container.clone();
cloned.find('.name').append(item.givenName + ' ' + item.familyName);
var gender = emr.message('coreapps.gender.' + item.gender);
var attributes = "";
if (item.attributeMap) {
_.each(item.attributeMap, function(value, key) {
if (value) {
attributes = attributes + ", " + value;
}
});
}
cloned.find('.info').append(gender + ', ' + item.birthdate + ', ' + item.personAddress + attributes);
if (item.identifiers) {
var identifiers = cloned.find('.identifiers');
item.identifiers.forEach(function (entry) {
var clonedIdName = identifiers.find('.idNameTemplate').clone();
clonedIdName.text(entry.name + ': ');
clonedIdName.removeClass("idNameTemplate");
identifiers.append(clonedIdName);
var clonedIdValue = identifiers.find(".idValueTemplate").clone();
clonedIdValue.text(entry.value);
clonedIdValue.removeClass("idValueTemplate");
identifiers.append(clonedIdValue);
});
}
var button;
if (isMpi) {
button = $('#matchedPatientTemplates .mpi_button').clone();
button.attr("onclick", "importMpiPatient('" + item.uuid + "')");
} else {
button = $('#matchedPatientTemplates .local_button').clone();
var link = patientDashboardLink;
link += (link.indexOf('?') == -1 ? '?' : '&') + 'patientId=' + item.uuid;
button.attr("onclick", "location.href=\'" + link + "\'");
}
cloned.append(button);
$('#similarPatientsSelect').append(cloned);
}
}
getSimilarPatients = function (field) {
var focusedField = $(':focus');
jq('.date-component').trigger('blur');
var formData = jq('#registration').serialize();
var url = '/' + OPENMRS_CONTEXT_PATH + '/registrationapp/matchingPatients/getSimilarPatients.action?appId='+appId;
jq.post(url, formData, function(data) {
jq("#reviewSimilarPatientsButton").show();
showSimilarPatients(data);
}, "json");
focusedField.focus();
};
jq('input').change(getSimilarPatients);
jq('select').change(getSimilarPatients);
// Biometric matching
// TODO: This is mostly copied from similar patients above. Refactor into shared, common functionality as appropriate
/* Biometric patient functionality */
reviewBiometricPatients = emr.setupConfirmationDialog({
selector: '#reviewBiometricPatients',
actions: {
cancel: function () {
reviewBiometricPatients.close();
}
}
});
jq('#reviewBiometricPatientsButton').click(function () {
var slideView = $("#biometricPatientsSlideView");
slideView.slideToggle();
return false;
});
function showBiometricPatients(data) {
if (data.length == 0) {
jq("#biometricPatients").hide();
jq("#biometricPatientsSlideView").hide();
return;
} else {
jq("#biometricPatients").show();
}
jq('#biometricPatientsCount').text(data.length);
var biometricPatientsSelect = jq('#biometricPatientsSelect');
biometricPatientsSelect.empty();
for (index in data) {
var item = data[index];
var container = $('#matchedPatientTemplates .container');
var cloned = container.clone();
cloned.find('.name').append(item.givenName + ' ' + item.familyName);
var gender = emr.message('coreapps.gender.' + item.gender);
var attributes = "";
if (item.attributeMap) {
_.each(item.attributeMap, function(value, key) {
if (value) {
attributes = attributes + ", " + value;
}
});
}
cloned.find('.info').append(gender + ', ' + item.birthdate + ', ' + item.personAddress + attributes);
if (item.identifiers) {
var identifiers = cloned.find('.identifiers');
item.identifiers.forEach(function (entry) {
var clonedIdName = identifiers.find('.idNameTemplate').clone();
clonedIdName.text(entry.name + ': ');
clonedIdName.removeClass("idNameTemplate");
identifiers.append(clonedIdName);
var clonedIdValue = identifiers.find(".idValueTemplate").clone();
clonedIdValue.text(entry.value);
clonedIdValue.removeClass("idValueTemplate");
identifiers.append(clonedIdValue);
});
}
var button = $('#matchedPatientTemplates .local_button').clone();
var link = patientDashboardLink;
link += (link.indexOf('?') == -1 ? '?' : '&') + 'patientId=' + item.uuid;
button.attr("onclick", "location.href=\'" + link + "\'");
cloned.append(button);
$('#biometricPatientsSelect').append(cloned);
}
}
getBiometricMatches = function(formData) {
var biometricUrl = '/' + OPENMRS_CONTEXT_PATH + '/registrationapp/matchingPatients/getBiometricMatches.action?appId='+appId;
jq.post(biometricUrl, formData, function(data) {
jq("#reviewBiometricPatientsButton").show();
showBiometricPatients(data);
// TODO: Uncomment the below if we wish to display the matching patient list open by default
//jq("#biometricPatientsSlideView").show();
}, "json");
};
/* Exact match patient functionality */
jq("#confirmation").on('select', function (confSection) {
var formData = jq('#registration').serialize();
jq('#exact-matches').hide();
jq('#mpi-exact-match').hide();
jq('#local-exact-match').hide();
var url = '/' + OPENMRS_CONTEXT_PATH + '/registrationapp/matchingPatients/getExactPatients.action?appId='+appId;
jq.post(url, formData, function(data) {
jq("#reviewSimilarPatientsButton").hide();
showSimilarPatients(data);
jq("#similarPatientsSlideView").show();
}, "json");
});
/* Submit functionality */
jq('#registration').submit(function (e) {
e.preventDefault();
jq('#submit').attr('disabled', 'disabled');
jq('#cancelSubmission').attr('disabled', 'disabled');
jq('#validation-errors').hide();
var formData = jq('#registration').serialize();
var url = '/' + OPENMRS_CONTEXT_PATH + '/registrationapp/registerPatient/submit.action?appId=' + appId;
jq.ajax({
url: url,
type: "POST",
data: formData,
dataType: "json",
success: function(response) {
emr.navigateTo({"applicationUrl": response.message});
},
error: function(response) {
jq('#validation-errors-content').html(response.responseJSON.globalErrors);
jq('#validation-errors').show();
jq('#submit').removeAttr('disabled');
jq('#cancelSubmission').removeAttr('disabled');
}
});
});
/* Registration date functionality */
if (NavigatorController.getQuestionById('registration-date') != null) { // if retro entry configured
_.each(NavigatorController.getQuestionById('registration-date').fields, function (field) { // registration fields are is disabled by default
if (field.id != 'checkbox-enable-registration-date') {
field.hide();
}
});
jq('#checkbox-enable-registration-date').click(function () {
if (jq('#checkbox-enable-registration-date').is(':checked')) {
_.each(NavigatorController.getQuestionById('registration-date').fields, function (field) {
if (field.id != 'checkbox-enable-registration-date') {
field.hide();
}
});
}
else {
_.each(NavigatorController.getQuestionById('registration-date').fields, function (field) {
if (field.id != 'checkbox-enable-registration-date') {
field.show();
}
});
}
});
}
/* Manual patient identifier entry functionality */
if (NavigatorController.getFieldById('patient-identifier') != null) { // if manual entry configured
NavigatorController.getFieldById('patient-identifier').hide();
jq('#checkbox-autogenerate-identifier').click(function () {
if (jq('#checkbox-autogenerate-identifier').is(':checked')) {
NavigatorController.getFieldById('patient-identifier').hide();
}
else {
NavigatorController.getFieldById('patient-identifier').show();
NavigatorController.getFieldById('patient-identifier').click();
}
})
}
/* Unknown patient functionality */
jq('#checkbox-unknown-patient').click(function () {
if (jq('#checkbox-unknown-patient').is(':checked')) {
$("#personRelationshipField h3").addClass("disabled");
$("#personRelationshipField p a").each(function(i, button) {
// Press the minus button
if ((i % 2) != 0){
button.click();
}
});
// Disable the remaining relationship
$("#personRelationshipField p select").addClass("disabled");
$("#personRelationshipField p select").prop( "disabled", true);
$("#personRelationshipField p select").val(null);
$("#personRelationshipField p input").addClass( "disabled");
$("#personRelationshipField p input").prop( "disabled", true);
$("#personRelationshipField p input").val(null);
// disable all questions & sections except gender andNavigatorControllerNavigatorControllerNavigatorControllerNa registration date
if (NavigatorController.getQuestionById('demographics-name') != undefined) {
_.each(NavigatorController.getQuestionById('demographics-name').fields, function (field) {
if (field.id != 'checkbox-unknown-patient') {
field.disable();
}
});
}
if (NavigatorController.getQuestionById('demographics-fieldset') != undefined) {
_.each(NavigatorController.getQuestionById('demographics-fieldset').fields, function (field) {
if (field.id != 'checkbox-unknown-patient' && field.id != 'gender-field') {
field.disable();
}
});
}
_.each(NavigatorController.getSectionById('demographics').questions, function(question) {
if (question.id != 'demographics-gender' && question.id != 'demographics-name' && question.id != 'demographics-fieldset') {
question.disable();
}
})
// TODO sections variable is currently hackily defined in registerPatient.gsp
_.each(sections, function(section) {
if (section != 'demographics') {
NavigatorController.getSectionById(section).disable();
}
});
// set unknown flag
jq('#demographics-unknown').val('true');
// jump ahead to gender
if (NavigatorController.getQuestionById('demographics-gender') != undefined) {
NavigatorController.getQuestionById('demographics-gender').click();
} else {
NavigatorController.getFieldById('gender-field').click();
}
}
else {
// Enable the relationship field
$("#personRelationshipField h3").removeClass("disabled");
$("#personRelationshipField p select").removeClass("disabled");
$("#personRelationshipField p select").prop( "disabled", false);
$("#personRelationshipField p input").removeClass( "disabled");
$("#personRelationshipField p input").prop( "disabled", false);
// re-enable all functionality
// hide all questions & sections except gender and registration date
if (NavigatorController.getQuestionById('demographics-name') != undefined) {
_.each(NavigatorController.getQuestionById('demographics-name').fields, function (field) {
if (field.id != 'checkbox-unknown-patient') {
field.enable();
}
});
}
if (NavigatorController.getQuestionById('demographics-birthdate') != undefined) {
NavigatorController.getQuestionById('demographics-birthdate').enable();
}
// TODO sections variable is currently hackily defined in registerPatient.gsp
_.each(sections, function(section) {
NavigatorController.getSectionById(section).enable();
});
// unset unknown flag
jq('#demographics-unknown').val('false');
if (NavigatorController.getQuestionById('demographics-name') != undefined) {
NavigatorController.getQuestionById('demographics-name').fields[0].click();
} else {
NavigatorController.getQuestionById('demographics-fieldset').fields[0].click();
}
}
});
});