@@ -43,7 +43,7 @@ function PatientSearchWidget(configuration){
43
43
var highlightedMouseRowIndex ;
44
44
var searchDelayTimer ;
45
45
var requestCount = 0 ;
46
- var searchUrl = '/' + OPENMRS_CONTEXT_PATH + '/ws/rest/v1/patient' ;
46
+ var searchUrl = '/' + OPENMRS_CONTEXT_PATH + '/ws/rest/v1/patientsearch/ patient' ;
47
47
var initialData = [ ] ;
48
48
var initialPatientData = [ ] ;
49
49
var initialPatientUuids = [ ] ;
@@ -136,11 +136,57 @@ function PatientSearchWidget(configuration){
136
136
}
137
137
138
138
query = jq . trim ( query ) ;
139
+
139
140
if ( query . indexOf ( ' ' ) >= 0 ) {
140
141
searchOnIdentifierAndName ( query , currRequestCount ) ;
141
142
}
142
143
else {
143
- searchOnExactIdentifierMatchThenIdentifierAndName ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) ;
144
+ var gender_search = jq ( '#patient-gender-search' ) . val ( ) ;
145
+ var from_search = jq ( '#patient-age-range-from' ) . val ( ) ;
146
+ var to_search = jq ( '#patient-age-range-to' ) . val ( ) ;
147
+ var date_search ;
148
+ if ( jq ( '#patient-birthdate' ) . val ( ) != '' ) {
149
+ console . log ( 'birth ' + jq ( '#patient-birthdate' ) . val ( ) ) ;
150
+ date_search = new Date ( jq ( '#patient-birthdate' ) . val ( ) ) ;
151
+ date_search . setHours ( 0 ) ;
152
+ date_search . setMinutes ( 0 ) ;
153
+ }
154
+
155
+
156
+ if ( query == '' ) {
157
+ if ( gender_search != '' && from_search == '' && to_search == '' && jq ( '#patient-birthdate' ) . val ( ) == '' ) {
158
+ searchOnGender ( gender_search , currRequestCount ) ;
159
+ } else if ( gender_search == '' && from_search != '' && to_search != '' && jq ( '#patient-birthdate' ) . val ( ) == '' ) {
160
+ searchOnRangeOfAge ( from_search , to_search , currRequestCount ) ;
161
+ } else if ( gender_search == '' && jq ( '#patient-birthdate' ) . val ( ) != '' ) {
162
+ searchOnBirthdate ( date_search . getTime ( ) , currRequestCount ) ;
163
+ } else if ( gender_search != '' && from_search != '' && to_search != '' ) {
164
+ searchOnGenderAndRangeOfAge ( gender_search , from_search , to_search , currRequestCount ) ;
165
+ } else if ( gender_search != '' && jq ( '#patient-birthdate' ) . val ( ) != '' ) {
166
+ searchOnGenderAndBirthdate ( gender_search , date_search . getTime ( ) , currRequestCount ) ;
167
+ } else {
168
+ updateSearchResults ( ) ;
169
+ }
170
+
171
+ }
172
+ else {
173
+ if ( gender_search != '' ) {
174
+ if ( from_search == '' && to_search == '' && jq ( '#patient-birthdate' ) . val ( ) == '' ) {
175
+ searchOnIdentifierAndNameAndGender ( query , gender_search , currRequestCount ) ;
176
+ } else if ( from_search != '' && to_search != '' ) {
177
+ searchOnIdentifierAndNameAndGenderAndRangeOfAge ( query , gender_search , from_search , to_search , currRequestCount ) ;
178
+ } else {
179
+ searchOnIdentifierAndNameAndGenderAndBirthdate ( query , gender_search , date_search . getTime ( ) , currRequestCount ) ;
180
+ }
181
+ } else if ( from_search != '' && to_search != '' ) {
182
+ searchOnIdentifierAndNameAndRangeOfAge ( query , from_search , to_search , currRequestCount ) ;
183
+ } else if ( jq ( '#patient-birthdate' ) . val ( ) != '' ) {
184
+ searchOnIdentifierAndNameAndBirthdate ( query , date_search . getTime ( ) , currRequestCount ) ;
185
+ } else {
186
+ searchOnExactIdentifierMatchThenIdentifierAndName ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) ;
187
+ }
188
+ }
189
+
144
190
}
145
191
}
146
192
@@ -154,7 +200,7 @@ function PatientSearchWidget(configuration){
154
200
var deferredList = [ ] ;
155
201
156
202
jq . each ( identifiers , function ( idx , identifier ) {
157
- var deferred = emr . getJSON ( searchUrl , { identifier : identifier , v : customRep } )
203
+ var deferred = emr . getJSON ( searchUrl , { q : identifier , v : customRep } )
158
204
. then ( function ( data ) {
159
205
if ( data && data . results && data . results . length > 0 ) {
160
206
updateSearchResults ( data . results ) ;
@@ -180,7 +226,7 @@ function PatientSearchWidget(configuration){
180
226
}
181
227
182
228
var searchOnExactIdentifierMatchThenIdentifierAndName = function ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) {
183
- emr . getJSON ( searchUrl , { identifier : query , v : customRep } )
229
+ emr . getJSON ( searchUrl , { q : query , v : customRep } )
184
230
. done ( function ( data ) {
185
231
// update only if we've got results, and not late (late ajax responses should be ignored not to overwrite the latest)
186
232
if ( data && data . results && data . results . length > 0 && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
@@ -210,6 +256,136 @@ function PatientSearchWidget(configuration){
210
256
} ) ;
211
257
}
212
258
259
+ var searchOnIdentifierAndNameAndGender = function ( query , gender_search , currRequestCount ) {
260
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , v : customRep } )
261
+ . done ( function ( data ) {
262
+ //late ajax responses should be ignored not to overwrite the latest
263
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
264
+ updateSearchResults ( data . results ) ;
265
+ }
266
+ } )
267
+ . fail ( function ( jqXHR ) {
268
+ failSearch ( ) ;
269
+ } ) ;
270
+ }
271
+
272
+ var searchOnIdentifierAndNameAndRangeOfAge = function ( query , from_search , to_search , currRequestCount ) {
273
+ emr . getJSON ( searchUrl , { q : query , from : from_search , to : to_search , v : customRep } )
274
+ . done ( function ( data ) {
275
+ //late ajax responses should be ignored not to overwrite the latest
276
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
277
+ updateSearchResults ( data . results ) ;
278
+ }
279
+ } )
280
+ . fail ( function ( jqXHR ) {
281
+ failSearch ( ) ;
282
+ } ) ;
283
+ }
284
+
285
+ var searchOnIdentifierAndNameAndBirthdate = function ( query , birthdate_search , currRequestCount ) {
286
+ emr . getJSON ( searchUrl , { q : query , birthdate : birthdate_search , v : customRep } )
287
+ . done ( function ( data ) {
288
+ //late ajax responses should be ignored not to overwrite the latest
289
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
290
+ updateSearchResults ( data . results ) ;
291
+ }
292
+ } )
293
+ . fail ( function ( jqXHR ) {
294
+ failSearch ( ) ;
295
+ } ) ;
296
+ }
297
+
298
+ var searchOnIdentifierAndNameAndGenderAndRangeOfAge = function ( query , gender_search , from_search , to_search , currRequestCount ) {
299
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , from : from_search , to : to_search , v : customRep } )
300
+ . done ( function ( data ) {
301
+ //late ajax responses should be ignored not to overwrite the latest
302
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
303
+ updateSearchResults ( data . results ) ;
304
+ }
305
+ } )
306
+ . fail ( function ( jqXHR ) {
307
+ failSearch ( ) ;
308
+ } ) ;
309
+ }
310
+
311
+ var searchOnIdentifierAndNameAndGenderAndBirthdate = function ( query , gender_search , birthdate_search , currRequestCount ) {
312
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , birthdate : birthdate_search , v : customRep } )
313
+ . done ( function ( data ) {
314
+ //late ajax responses should be ignored not to overwrite the latest
315
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
316
+ updateSearchResults ( data . results ) ;
317
+ }
318
+ } )
319
+ . fail ( function ( jqXHR ) {
320
+ failSearch ( ) ;
321
+ } ) ;
322
+ }
323
+
324
+ var searchOnGenderAndRangeOfAge = function ( gender_search , from_search , to_search , currRequestCount ) {
325
+ emr . getJSON ( searchUrl , { gender : gender_search , from : from_search , to : to_search , v : customRep } )
326
+ . done ( function ( data ) {
327
+ //late ajax responses should be ignored not to overwrite the latest
328
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
329
+ updateSearchResults ( data . results ) ;
330
+ }
331
+ } )
332
+ . fail ( function ( jqXHR ) {
333
+ failSearch ( ) ;
334
+ } ) ;
335
+ }
336
+
337
+ var searchOnGenderAndBirthdate = function ( gender_search , birthdate_search , currRequestCount ) {
338
+ emr . getJSON ( searchUrl , { gender : gender_search , birthdate : birthdate_search , v : customRep } )
339
+ . done ( function ( data ) {
340
+ //late ajax responses should be ignored not to overwrite the latest
341
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
342
+ updateSearchResults ( data . results ) ;
343
+ }
344
+ } )
345
+ . fail ( function ( jqXHR ) {
346
+ failSearch ( ) ;
347
+ } ) ;
348
+ }
349
+
350
+ var searchOnGender = function ( gender_search , currRequestCount ) {
351
+ emr . getJSON ( searchUrl , { gender : gender_search , v : customRep } )
352
+ . done ( function ( data ) {
353
+ //late ajax responses should be ignored not to overwrite the latest
354
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
355
+ updateSearchResults ( data . results ) ;
356
+ }
357
+ } )
358
+ . fail ( function ( jqXHR ) {
359
+ failSearch ( ) ;
360
+ } ) ;
361
+ }
362
+
363
+ var searchOnRangeOfAge = function ( from_search , to_search , currRequestCount ) {
364
+ emr . getJSON ( searchUrl , { from : from_search , to : to_search , v : customRep } )
365
+ . done ( function ( data ) {
366
+ //late ajax responses should be ignored not to overwrite the latest
367
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
368
+ updateSearchResults ( data . results ) ;
369
+ }
370
+ } )
371
+ . fail ( function ( jqXHR ) {
372
+ failSearch ( ) ;
373
+ } ) ;
374
+ }
375
+
376
+ var searchOnBirthdate = function ( birthdate_search , currRequestCount ) {
377
+ emr . getJSON ( searchUrl , { birthdate : birthdate_search , v : customRep } )
378
+ . done ( function ( data ) {
379
+ //late ajax responses should be ignored not to overwrite the latest
380
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
381
+ updateSearchResults ( data . results ) ;
382
+ }
383
+ } )
384
+ . fail ( function ( jqXHR ) {
385
+ failSearch ( ) ;
386
+ } ) ;
387
+ }
388
+
213
389
var failSearch = function ( ) {
214
390
performingSearch = false ;
215
391
if ( ! currRequestCount || currRequestCount >= requestCount ) {
@@ -244,6 +420,46 @@ function PatientSearchWidget(configuration){
244
420
}
245
421
this . reset = reset ;
246
422
423
+ //Add age range and birthdate search
424
+
425
+ jq ( '#getAgeAndBirthdateFilter' ) . click ( function ( event ) {
426
+ if ( this . checked ) {
427
+ jq ( '#patient-search-age-birthdate' ) . css ( 'display' , 'block' ) ;
428
+ } else {
429
+ jq ( '#patient-search-age-birthdate' ) . css ( 'display' , 'none' ) ;
430
+ jq ( '#patient-age' ) . prop ( 'checked' , false ) ;
431
+ jq ( '#patient-birthdate' ) . prop ( 'checked' , false ) ;
432
+ jq ( '#patient-age-range-from' ) . val ( '' ) ;
433
+ jq ( '#patient-age-range-to' ) . val ( '' ) ;
434
+ jq ( 'input[type=date]' ) . each ( function resetDate ( ) {
435
+ this . value = this . defaultValue ;
436
+ } ) ;
437
+ }
438
+ } )
439
+
440
+
441
+ $ ( "input[name='patient-age-birthdate']" ) . change ( function ( ) {
442
+ var ageOrBirthdate = $ ( "input[name='patient-age-birthdate']:checked" ) . val ( )
443
+ if ( ageOrBirthdate == "patient-age" ) {
444
+ jq ( '#patient-birthdate-search' ) . css ( 'display' , 'none' ) ;
445
+ jq ( '#patient-age-range-search' ) . css ( 'display' , 'block' ) ;
446
+ jq ( 'input[type=date]' ) . each ( function resetDate ( ) {
447
+ this . value = this . defaultValue ;
448
+ } ) ;
449
+ }
450
+ if ( ageOrBirthdate == "patient-birthdate" ) {
451
+ jq ( '#patient-age-range-search' ) . css ( 'display' , 'none' ) ;
452
+ jq ( '#patient-birthdate-search' ) . css ( 'display' , 'block' ) ;
453
+ jq ( '#patient-age-range-from' ) . val ( '' ) ;
454
+ jq ( '#patient-age-range-to' ) . val ( '' ) ;
455
+ }
456
+ } ) ;
457
+
458
+ //for date type support to browsers
459
+ if ( jq ( '[type="date"]' ) . prop ( 'type' ) != 'date' ) {
460
+ jq ( '[type="date"]' ) . datepicker ( ) ;
461
+ }
462
+
247
463
var updateSearchResults = function ( results ) {
248
464
var dataRows = [ ] ;
249
465
if ( results ) {
@@ -595,6 +811,38 @@ function PatientSearchWidget(configuration){
595
811
clearSearch ( ) ;
596
812
} ) ;
597
813
814
+ var searchByPatientSearchCriteria = function ( ) {
815
+ cancelAnyExistingSearch ( ) ;
816
+ var text = jq . trim ( input . val ( ) ) ;
817
+ var currentCount = ++ requestCount ;
818
+ var effectiveSearchDelay = config . searchDelayShort ;
819
+ window . setTimeout ( function ( ) {
820
+ if ( text == '' || text . length <= config . minSearchCharacters ) {
821
+ doSearch ( '' , currentCount ) ;
822
+ } else {
823
+ doSearch ( text , currentCount ) ;
824
+ }
825
+ } , effectiveSearchDelay ) ;
826
+
827
+ }
828
+
829
+ jq ( 'select' ) . change ( function ( ) {
830
+ searchByPatientSearchCriteria ( ) ;
831
+ } ) ;
832
+
833
+ jq ( 'input[type="date"]' ) . change ( function ( ) {
834
+ searchByPatientSearchCriteria ( ) ;
835
+ } ) ;
836
+
837
+
838
+ jq ( '#patient-age-range-from' ) . keyup ( function ( ) {
839
+ searchByPatientSearchCriteria ( ) ;
840
+ } ) ;
841
+
842
+ jq ( '#patient-age-range-to' ) . keyup ( function ( ) {
843
+ searchByPatientSearchCriteria ( ) ;
844
+ } ) ;
845
+
598
846
input . keyup ( function ( event ) {
599
847
var kc = event . keyCode ;
600
848
//ignore enter(because it was handled already onkeydown), keyboard navigation and control keys
0 commit comments