@@ -43,7 +43,7 @@ function PatientSearchWidget(configuration){
4343 var highlightedMouseRowIndex ;
4444 var searchDelayTimer ;
4545 var requestCount = 0 ;
46- var searchUrl = '/' + OPENMRS_CONTEXT_PATH + '/ws/rest/v1/patient' ;
46+ var searchUrl = '/' + OPENMRS_CONTEXT_PATH + '/ws/rest/v1/patientsearch/ patient' ;
4747 var initialData = [ ] ;
4848 var initialPatientData = [ ] ;
4949 var initialPatientUuids = [ ] ;
@@ -137,10 +137,16 @@ function PatientSearchWidget(configuration){
137137
138138 query = jq . trim ( query ) ;
139139 if ( query . indexOf ( ' ' ) >= 0 ) {
140- searchOnIdentifierAndName ( query , currRequestCount ) ;
140+ searchOnIdentifierAndName ( query , currRequestCount ) ;
141141 }
142142 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+
144150 }
145151 }
146152
@@ -154,7 +160,7 @@ function PatientSearchWidget(configuration){
154160 var deferredList = [ ] ;
155161
156162 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 } )
158164 . then ( function ( data ) {
159165 if ( data && data . results && data . results . length > 0 ) {
160166 updateSearchResults ( data . results ) ;
@@ -180,7 +186,7 @@ function PatientSearchWidget(configuration){
180186 }
181187
182188 var searchOnExactIdentifierMatchThenIdentifierAndName = function ( query , currRequestCount , autoSelectIfExactIdentifierMatch ) {
183- emr . getJSON ( searchUrl , { identifier : query , v : customRep } )
189+ emr . getJSON ( searchUrl , { q : query , v : customRep } )
184190 . done ( function ( data ) {
185191 // update only if we've got results, and not late (late ajax responses should be ignored not to overwrite the latest)
186192 if ( data && data . results && data . results . length > 0 && ( ! currRequestCount || currRequestCount >= requestCount ) ) {
@@ -210,6 +216,20 @@ function PatientSearchWidget(configuration){
210216 } ) ;
211217 }
212218
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+
213233 var failSearch = function ( ) {
214234 performingSearch = false ;
215235 if ( ! currRequestCount || currRequestCount >= requestCount ) {
@@ -244,6 +264,41 @@ function PatientSearchWidget(configuration){
244264 }
245265 this . reset = reset ;
246266
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+
247302 var updateSearchResults = function ( results ) {
248303 var dataRows = [ ] ;
249304 if ( results ) {
0 commit comments