Skip to content

Commit cb5c762

Browse files
committed
change in UI to support new patient search criteria
1 parent 73c4468 commit cb5c762

File tree

5 files changed

+331
-8
lines changed

5 files changed

+331
-8
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
language: java
22
jdk:
3-
- oraclejdk8
3+
- openjdk8
4+
services:
5+
- xvfb
46
addons:
57
firefox: "43.0"
8+
cache:
9+
directories:
10+
- .autoconf
11+
- $HOME/.m2
612
install:
713
- export DISPLAY=:99.0
814
- sh -e /etc/init.d/xvfb start
915
- tar -xjf /tmp/firefox-43.0.tar.bz2 --directory /tmp
1016
- export PATH="/tmp/firefox:$PATH"
11-
script: mvn clean install
17+
script: mvn clean install -q

omod/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
<gem.path>${basedir}/.rubygems</gem.path>
1919
</properties>
2020

21+
<repositories>
22+
<repository>
23+
<id>jitpack.io</id>
24+
<url>https://jitpack.io</url>
25+
</repository>
26+
</repositories>
27+
2128
<dependencies>
2229

2330
<!--
@@ -255,6 +262,20 @@
255262
<scope>provided</scope>
256263
</dependency>
257264

265+
<!-- Patient search criteria module -->
266+
<dependency>
267+
<groupId>com.github.Reyano132.openmrs-module-patientsearchcriteria</groupId>
268+
<artifactId>patientsearch-api</artifactId>
269+
<version>v1.0.0</version>
270+
<scope>provided</scope>
271+
</dependency>
272+
<dependency>
273+
<groupId>com.github.Reyano132.openmrs-module-patientsearchcriteria</groupId>
274+
<artifactId>patientsearch-omod</artifactId>
275+
<version>v1.0.0</version>
276+
<scope>provided</scope>
277+
</dependency>
278+
258279
</dependencies>
259280

260281
<build>

omod/src/main/webapp/fragments/patientsearch/patientSearchWidget.gsp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@
9393

9494
<form method="get" id="patient-search-form" onsubmit="return false">
9595
<input type="text" id="patient-search" placeholder="${ ui.message("coreapps.findPatient.search.placeholder") }" autocomplete="off" <% if (doInitialSearch) { %>value="${doInitialSearch}"<% } %>/><i id="patient-search-clear-button" class="small icon-remove-sign"></i>
96+
97+
<select id="patient-gender-search">
98+
<option value="" selected>${ ui.message("coreapps.gender") }</option>
99+
<option value="M">${ ui.message("coreapps.gender.M") }</option>
100+
<option value="F">${ ui.message("coreapps.gender.F") }</option>
101+
</select>
102+
<input type="checkbox" id="getAgeAndBirthdateFilter" >Search with age or birthdate<br>
103+
104+
<div id="patient-search-age-birthdate" style="display:none">
105+
<input type="radio" name ="patient-age-birthdate" value="patient-age"> Search by range of age
106+
<br>
107+
<input type="radio" name ="patient-age-birthdate" value="patient-birthdate"> Search by birthdate
108+
109+
<p id="patient-age-range-search" style="display:none">
110+
<label>Range of Age</label>
111+
From:<input type="text" id="patient-age-range-from" placeholder="From" maxlength="2" style="min-width: 5px" onkeypress="return event.charCode >= 48 && event.charCode <= 57">
112+
To:<input type="text" id="patient-age-range-to" placeholder="To" maxlength="2"
113+
style="min-width: 5px" onkeypress="return event.charCode >= 48 && event.charCode <= 57">
114+
</p>
115+
116+
<p id="patient-birthdate-search" style="display:none">
117+
Birthdate:<input type="date" id="patient-birthdate" style="min-width: 5px"/>
118+
</p>
119+
</div>
96120
<% if(patientSearchExtensions){
97121
98122
patientSearchExtensions.each {

omod/src/main/webapp/resources/scripts/patientsearch/patientSearchWidget.js

Lines changed: 252 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = [];
@@ -136,11 +136,57 @@ function PatientSearchWidget(configuration){
136136
}
137137

138138
query = jq.trim(query);
139+
139140
if (query.indexOf(' ') >= 0) {
140141
searchOnIdentifierAndName(query, currRequestCount);
141142
}
142143
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+
144190
}
145191
}
146192

@@ -154,7 +200,7 @@ function PatientSearchWidget(configuration){
154200
var deferredList = [];
155201

156202
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})
158204
.then(function (data) {
159205
if (data && data.results && data.results.length > 0) {
160206
updateSearchResults(data.results);
@@ -180,7 +226,7 @@ function PatientSearchWidget(configuration){
180226
}
181227

182228
var searchOnExactIdentifierMatchThenIdentifierAndName = function(query, currRequestCount, autoSelectIfExactIdentifierMatch) {
183-
emr.getJSON(searchUrl, {identifier: query, v: customRep })
229+
emr.getJSON(searchUrl, {q: query, v: customRep })
184230
.done(function (data) {
185231
// update only if we've got results, and not late (late ajax responses should be ignored not to overwrite the latest)
186232
if (data && data.results && data.results.length > 0 && (!currRequestCount || currRequestCount >= requestCount)) {
@@ -210,6 +256,136 @@ function PatientSearchWidget(configuration){
210256
});
211257
}
212258

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+
213389
var failSearch = function() {
214390
performingSearch = false;
215391
if (!currRequestCount || currRequestCount >= requestCount) {
@@ -244,6 +420,46 @@ function PatientSearchWidget(configuration){
244420
}
245421
this.reset = reset;
246422

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+
247463
var updateSearchResults = function(results){
248464
var dataRows = [];
249465
if(results){
@@ -595,6 +811,38 @@ function PatientSearchWidget(configuration){
595811
clearSearch();
596812
});
597813

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+
598846
input.keyup(function(event) {
599847
var kc = event.keyCode;
600848
//ignore enter(because it was handled already onkeydown), keyboard navigation and control keys

0 commit comments

Comments
 (0)