@@ -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 = [ ] ;
@@ -140,7 +140,52 @@ function PatientSearchWidget(configuration){
140
140
searchOnIdentifierAndName ( query , currRequestCount ) ;
141
141
}
142
142
else {
143
- searchOnExactIdentifierMatchThenIdentifierAndName ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) ;
143
+ var gender_search = jq ( '#patient-gender-search' ) . val ( ) ;
144
+ var from_search = jq ( '#patient-age-range-from' ) . val ( ) ;
145
+ var to_search = jq ( '#patient-age-range-to' ) . val ( ) ;
146
+ var date_search ;
147
+ if ( jq ( '#patient-birthdate' ) . val ( ) != '' ) {
148
+ console . log ( 'birth ' + jq ( '#patient-birthdate' ) . val ( ) ) ;
149
+ date_search = new Date ( jq ( '#patient-birthdate' ) . val ( ) ) ;
150
+ date_search . setHours ( 0 ) ;
151
+ date_search . setMinutes ( 0 ) ;
152
+ }
153
+
154
+
155
+ if ( query == '' ) {
156
+ if ( gender_search != '' && from_search == '' && to_search == '' && jq ( '#patient-birthdate' ) . val ( ) == '' ) {
157
+ searchOnGender ( gender_search , currRequestCount ) ;
158
+ } else if ( gender_search == '' && from_search != '' && to_search != '' && jq ( '#patient-birthdate' ) . val ( ) == '' ) {
159
+ searchOnRangeOfAge ( from_search , to_search , currRequestCount ) ;
160
+ } else if ( gender_search == '' && jq ( '#patient-birthdate' ) . val ( ) != '' ) {
161
+ searchOnBirthdate ( date_search . getTime ( ) , currRequestCount ) ;
162
+ } else if ( gender_search != '' && from_search != '' && to_search != '' ) {
163
+ searchOnGenderAndRangeOfAge ( gender_search , from_search , to_search , currRequestCount ) ;
164
+ } else if ( gender_search != '' && jq ( '#patient-birthdate' ) . val ( ) != '' ) {
165
+ searchOnGenderAndBirthdate ( gender_search , date_search . getTime ( ) , currRequestCount ) ;
166
+ } else {
167
+ updateSearchResults ( ) ;
168
+ }
169
+
170
+ }
171
+ else {
172
+ if ( gender_search != '' ) {
173
+ if ( from_search == '' && to_search == '' && jq ( '#patient-birthdate' ) . val ( ) == '' ) {
174
+ searchOnIdentifierAndNameAndGender ( query , gender_search , currRequestCount ) ;
175
+ } else if ( from_search != '' && to_search != '' ) {
176
+ searchOnIdentifierAndNameAndGenderAndRangeOfAge ( query , gender_search , from_search , to_search , currRequestCount ) ;
177
+ } else {
178
+ searchOnIdentifierAndNameAndGenderAndBirthdate ( query , gender_search , date_search . getTime ( ) , currRequestCount ) ;
179
+ }
180
+ } else if ( from_search != '' && to_search != '' ) {
181
+ searchOnIdentifierAndNameAndRangeOfAge ( query , from_search , to_search , currRequestCount ) ;
182
+ } else if ( jq ( '#patient-birthdate' ) . val ( ) != '' ) {
183
+ searchOnIdentifierAndNameAndBirthdate ( query , date_search . getTime ( ) , currRequestCount ) ;
184
+ } else {
185
+ searchOnExactIdentifierMatchThenIdentifierAndName ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) ;
186
+ }
187
+ }
188
+
144
189
}
145
190
}
146
191
@@ -210,6 +255,136 @@ function PatientSearchWidget(configuration){
210
255
} ) ;
211
256
}
212
257
258
+ var searchOnIdentifierAndNameAndGender = function ( query , gender_search , currRequestCount ) {
259
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , v : customRep } )
260
+ . done ( function ( data ) {
261
+ //late ajax responses should be ignored not to overwrite the latest
262
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
263
+ updateSearchResults ( data . results ) ;
264
+ }
265
+ } )
266
+ . fail ( function ( jqXHR ) {
267
+ failSearch ( ) ;
268
+ } ) ;
269
+ }
270
+
271
+ var searchOnIdentifierAndNameAndRangeOfAge = function ( query , from_search , to_search , currRequestCount ) {
272
+ emr . getJSON ( searchUrl , { q : query , from : from_search , to : to_search , v : customRep } )
273
+ . done ( function ( data ) {
274
+ //late ajax responses should be ignored not to overwrite the latest
275
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
276
+ updateSearchResults ( data . results ) ;
277
+ }
278
+ } )
279
+ . fail ( function ( jqXHR ) {
280
+ failSearch ( ) ;
281
+ } ) ;
282
+ }
283
+
284
+ var searchOnIdentifierAndNameAndBirthdate = function ( query , birthdate_search , currRequestCount ) {
285
+ emr . getJSON ( searchUrl , { q : query , birthdate : birthdate_search , v : customRep } )
286
+ . done ( function ( data ) {
287
+ //late ajax responses should be ignored not to overwrite the latest
288
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
289
+ updateSearchResults ( data . results ) ;
290
+ }
291
+ } )
292
+ . fail ( function ( jqXHR ) {
293
+ failSearch ( ) ;
294
+ } ) ;
295
+ }
296
+
297
+ var searchOnIdentifierAndNameAndGenderAndRangeOfAge = function ( query , gender_search , from_search , to_search , currRequestCount ) {
298
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , from : from_search , to : to_search , v : customRep } )
299
+ . done ( function ( data ) {
300
+ //late ajax responses should be ignored not to overwrite the latest
301
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
302
+ updateSearchResults ( data . results ) ;
303
+ }
304
+ } )
305
+ . fail ( function ( jqXHR ) {
306
+ failSearch ( ) ;
307
+ } ) ;
308
+ }
309
+
310
+ var searchOnIdentifierAndNameAndGenderAndBirthdate = function ( query , gender_search , birthdate_search , currRequestCount ) {
311
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , birthdate : birthdate_search , v : customRep } )
312
+ . done ( function ( data ) {
313
+ //late ajax responses should be ignored not to overwrite the latest
314
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
315
+ updateSearchResults ( data . results ) ;
316
+ }
317
+ } )
318
+ . fail ( function ( jqXHR ) {
319
+ failSearch ( ) ;
320
+ } ) ;
321
+ }
322
+
323
+ var searchOnGenderAndRangeOfAge = function ( gender_search , from_search , to_search , currRequestCount ) {
324
+ emr . getJSON ( searchUrl , { gender : gender_search , from : from_search , to : to_search , v : customRep } )
325
+ . done ( function ( data ) {
326
+ //late ajax responses should be ignored not to overwrite the latest
327
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
328
+ updateSearchResults ( data . results ) ;
329
+ }
330
+ } )
331
+ . fail ( function ( jqXHR ) {
332
+ failSearch ( ) ;
333
+ } ) ;
334
+ }
335
+
336
+ var searchOnGenderAndBirthdate = function ( gender_search , birthdate_search , currRequestCount ) {
337
+ emr . getJSON ( searchUrl , { gender : gender_search , birthdate : birthdate_search , v : customRep } )
338
+ . done ( function ( data ) {
339
+ //late ajax responses should be ignored not to overwrite the latest
340
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
341
+ updateSearchResults ( data . results ) ;
342
+ }
343
+ } )
344
+ . fail ( function ( jqXHR ) {
345
+ failSearch ( ) ;
346
+ } ) ;
347
+ }
348
+
349
+ var searchOnGender = function ( gender_search , currRequestCount ) {
350
+ emr . getJSON ( searchUrl , { gender : gender_search , v : customRep } )
351
+ . done ( function ( data ) {
352
+ //late ajax responses should be ignored not to overwrite the latest
353
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
354
+ updateSearchResults ( data . results ) ;
355
+ }
356
+ } )
357
+ . fail ( function ( jqXHR ) {
358
+ failSearch ( ) ;
359
+ } ) ;
360
+ }
361
+
362
+ var searchOnRangeOfAge = function ( from_search , to_search , currRequestCount ) {
363
+ emr . getJSON ( searchUrl , { from : from_search , to : to_search , v : customRep } )
364
+ . done ( function ( data ) {
365
+ //late ajax responses should be ignored not to overwrite the latest
366
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
367
+ updateSearchResults ( data . results ) ;
368
+ }
369
+ } )
370
+ . fail ( function ( jqXHR ) {
371
+ failSearch ( ) ;
372
+ } ) ;
373
+ }
374
+
375
+ var searchOnBirthdate = function ( birthdate_search , currRequestCount ) {
376
+ emr . getJSON ( searchUrl , { birthdate : birthdate_search , v : customRep } )
377
+ . done ( function ( data ) {
378
+ //late ajax responses should be ignored not to overwrite the latest
379
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
380
+ updateSearchResults ( data . results ) ;
381
+ }
382
+ } )
383
+ . fail ( function ( jqXHR ) {
384
+ failSearch ( ) ;
385
+ } ) ;
386
+ }
387
+
213
388
var failSearch = function ( ) {
214
389
performingSearch = false ;
215
390
if ( ! currRequestCount || currRequestCount >= requestCount ) {
@@ -244,6 +419,47 @@ function PatientSearchWidget(configuration){
244
419
}
245
420
this . reset = reset ;
246
421
422
+ //Add age range and birthdate search
423
+
424
+ jq ( '#getAgeAndBirthdateFilter' ) . click ( function ( event ) {
425
+ if ( this . checked ) {
426
+ jq ( '#patient-search-age-birthdate' ) . css ( 'display' , 'block' ) ;
427
+ } else {
428
+ jq ( '#patient-search-age-birthdate' ) . css ( 'display' , 'none' ) ;
429
+ jq ( '#patient-age' ) . prop ( 'checked' , false ) ;
430
+ jq ( '#patient-birthdate' ) . prop ( 'checked' , false ) ;
431
+ jq ( '#patient-age-range-from' ) . val ( '' ) ;
432
+ jq ( '#patient-age-range-to' ) . val ( '' ) ;
433
+ jq ( 'input[type=date]' ) . each ( function resetDate ( ) {
434
+ this . value = this . defaultValue ;
435
+ } ) ;
436
+ }
437
+ } )
438
+
439
+
440
+ $ ( "input[name='patient-age-birthdate']" ) . change ( function ( ) {
441
+ var ageOrBirthdate = $ ( "input[name='patient-age-birthdate']:checked" ) . val ( )
442
+ if ( ageOrBirthdate == "patient-age" ) {
443
+ jq ( '#patient-birthdate-search' ) . css ( 'display' , 'none' ) ;
444
+ jq ( '#patient-age-range-search' ) . css ( 'display' , 'block' ) ;
445
+ jq ( 'input[type=date]' ) . each ( function resetDate ( ) {
446
+ this . value = this . defaultValue ;
447
+ } ) ;
448
+ }
449
+ if ( ageOrBirthdate == "patient-birthdate" ) {
450
+ jq ( '#patient-age-range-search' ) . css ( 'display' , 'none' ) ;
451
+ jq ( '#patient-birthdate-search' ) . css ( 'display' , 'block' ) ;
452
+ jq ( '#patient-age-range-from' ) . val ( '' ) ;
453
+ jq ( '#patient-age-range-to' ) . val ( '' ) ;
454
+ }
455
+ } ) ;
456
+
457
+ //for date type support to browsers
458
+ if ( jq ( '[type="date"]' ) . prop ( 'type' ) != 'date' ) {
459
+ jq ( '[type="date"]' ) . datepicker ( ) ;
460
+ }
461
+
462
+
247
463
var updateSearchResults = function ( results ) {
248
464
var dataRows = [ ] ;
249
465
if ( results ) {
@@ -595,6 +811,39 @@ 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
+
846
+
598
847
input . keyup ( function ( event ) {
599
848
var kc = event . keyCode ;
600
849
//ignore enter(because it was handled already onkeydown), keyboard navigation and control keys
0 commit comments