@@ -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 = [ ] ;
@@ -137,10 +137,16 @@ function PatientSearchWidget(configuration){
137
137
138
138
query = jq . trim ( query ) ;
139
139
if ( query . indexOf ( ' ' ) >= 0 ) {
140
- searchOnIdentifierAndName ( query , currRequestCount ) ;
140
+ searchOnIdentifierAndName ( query , currRequestCount ) ;
141
141
}
142
142
else {
143
- searchOnExactIdentifierMatchThenIdentifierAndName ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) ;
143
+ if ( jq ( '#patient-gender' ) . val ( ) != '' ) {
144
+ var gender_search = jq ( '#patient-gender' ) . val ( ) ;
145
+ searchOnIdentifierAndNameAndGender ( query , gender_search , currRequestCount ) ;
146
+ } else {
147
+ searchOnExactIdentifierMatchThenIdentifierAndName ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) ;
148
+ }
149
+
144
150
}
145
151
}
146
152
@@ -154,7 +160,7 @@ function PatientSearchWidget(configuration){
154
160
var deferredList = [ ] ;
155
161
156
162
jq . each ( identifiers , function ( idx , identifier ) {
157
- var deferred = emr . getJSON ( searchUrl , { identifier : identifier , v : customRep } )
163
+ var deferred = emr . getJSON ( searchUrl , { q : identifier , v : customRep } )
158
164
. then ( function ( data ) {
159
165
if ( data && data . results && data . results . length > 0 ) {
160
166
updateSearchResults ( data . results ) ;
@@ -180,7 +186,7 @@ function PatientSearchWidget(configuration){
180
186
}
181
187
182
188
var searchOnExactIdentifierMatchThenIdentifierAndName = function ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) {
183
- emr . getJSON ( searchUrl , { identifier : query , v : customRep } )
189
+ emr . getJSON ( searchUrl , { q : query , v : customRep } )
184
190
. done ( function ( data ) {
185
191
// update only if we've got results, and not late (late ajax responses should be ignored not to overwrite the latest)
186
192
if ( data && data . results && data . results . length > 0 && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
@@ -210,6 +216,20 @@ function PatientSearchWidget(configuration){
210
216
} ) ;
211
217
}
212
218
219
+ var searchOnIdentifierAndNameAndGender = function ( query , gender_search , currRequestCount ) {
220
+ emr . getJSON ( searchUrl , { q : query , gender : gender_search , v : customRep } )
221
+ . done ( function ( data ) {
222
+ //late ajax responses should be ignored not to overwrite the latest
223
+ if ( data && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
224
+ updateSearchResults ( data . results ) ;
225
+ }
226
+ } )
227
+ . fail ( function ( jqXHR ) {
228
+ failSearch ( ) ;
229
+ } ) ;
230
+ }
231
+
232
+
213
233
var failSearch = function ( ) {
214
234
performingSearch = false ;
215
235
if ( ! currRequestCount || currRequestCount >= requestCount ) {
@@ -244,6 +264,41 @@ function PatientSearchWidget(configuration){
244
264
}
245
265
this . reset = reset ;
246
266
267
+ //Add age range and birthdate search
268
+
269
+ jq ( '#getAgeAndBirthdateFilter' ) . click ( function ( event ) {
270
+ if ( this . checked ) {
271
+ jq ( '#patient-search-age-birthdate' ) . css ( 'display' , 'block' ) ;
272
+ } else {
273
+ jq ( '#patient-search-age-birthdate' ) . css ( 'display' , 'none' ) ;
274
+ jq ( '#patient-age' ) . prop ( 'checked' , false ) ;
275
+ jq ( '#patient-birthdate' ) . prop ( 'checked' , false ) ;
276
+ }
277
+ } )
278
+
279
+
280
+ $ ( "input[name='patient-age-birthdate']" ) . change ( function ( ) {
281
+ var ageOrBirthdate = $ ( "input[name='patient-age-birthdate']:checked" ) . val ( )
282
+ if ( ageOrBirthdate == "patient-age" ) {
283
+ jq ( '#patient-birthdate-search' ) . css ( 'display' , 'none' ) ;
284
+ jq ( '#patient-age-range-search' ) . css ( 'display' , 'block' ) ;
285
+ jq ( 'input[type=date]' ) . each ( function resetDate ( ) {
286
+ this . value = this . defaultValue ;
287
+ } ) ;
288
+ }
289
+ if ( ageOrBirthdate == "patient-birthdate" ) {
290
+ jq ( '#patient-age-range-search' ) . css ( 'display' , 'none' ) ;
291
+ jq ( '#patient-birthdate-search' ) . css ( 'display' , 'block' ) ;
292
+ jq ( '#patient-age-range-from' ) . val ( '' ) ;
293
+ jq ( '#patient-age-range-to' ) . val ( '' ) ;
294
+ }
295
+ } ) ;
296
+
297
+ //for date type support to browsers
298
+ if ( jq ( '[type="date"]' ) . prop ( 'type' ) != 'date' ) {
299
+ jq ( '[type="date"]' ) . datepicker ( ) ;
300
+ }
301
+
247
302
var updateSearchResults = function ( results ) {
248
303
var dataRows = [ ] ;
249
304
if ( results ) {
0 commit comments