Skip to content

Commit 5d9a332

Browse files
committed
GSoC 2019: Patient search criteria module
1 parent 63dc352 commit 5d9a332

File tree

4 files changed

+324
-3
lines changed

4 files changed

+324
-3
lines changed

Diff for: omod/pom.xml

+28
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
<gem.path>${basedir}/.rubygems</gem.path>
1919
</properties>
2020

21+
<!-- Repository for patient search criteria -->
22+
<repositories>
23+
<repository>
24+
<id>jitpack.io</id>
25+
<url>https://jitpack.io</url>
26+
</repository>
27+
</repositories>
28+
29+
2130
<dependencies>
2231

2332
<!--
@@ -255,6 +264,25 @@
255264
<scope>provided</scope>
256265
</dependency>
257266

267+
<!-- Patient search criteria module -->
268+
<dependency>
269+
<groupId>com.github.Reyano132.openmrs-module-patientsearchcriteria</groupId>
270+
<artifactId>patientsearch-api</artifactId>
271+
<version>v1.0.0</version>
272+
<scope>provided</scope>
273+
</dependency>
274+
<dependency>
275+
<groupId>com.github.Reyano132.openmrs-module-patientsearchcriteria</groupId>
276+
<artifactId>patientsearch-omod</artifactId>
277+
<version>v1.0.0</version>
278+
<scope>provided</scope>
279+
</dependency>
280+
<dependency>
281+
<groupId>org.springframework</groupId>
282+
<artifactId>spring-core</artifactId>
283+
<version>4.0.5.RELEASE</version>
284+
</dependency>
285+
258286
</dependencies>
259287

260288
<build>

Diff for: omod/src/main/webapp/fragments/patientsearch/patientSearchWidget.gsp

+25-1
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,32 @@
9494
<div class="col-md-12 col-sm-12 col-xs-12">
9595
<form method="get" id="patient-search-form" onsubmit="return false">
9696
<input class="form-control input-sm input-lg" 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>
97-
<% if(patientSearchExtensions){
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>
98120

121+
122+
<% if(patientSearchExtensions){
99123
patientSearchExtensions.each {
100124
// create a base map from the fragmentConfig if it exists, otherwise just create an empty map
101125
def configs = [:];

Diff for: omod/src/main/webapp/resources/scripts/patientsearch/patientSearchWidget.js

+252-2
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 = [];
@@ -140,7 +140,52 @@ function PatientSearchWidget(configuration){
140140
searchOnIdentifierAndName(query, currRequestCount);
141141
}
142142
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+
144189
}
145190
}
146191

@@ -210,6 +255,136 @@ function PatientSearchWidget(configuration){
210255
});
211256
}
212257

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+
213388
var failSearch = function() {
214389
performingSearch = false;
215390
if (!currRequestCount || currRequestCount >= requestCount) {
@@ -244,6 +419,47 @@ function PatientSearchWidget(configuration){
244419
}
245420
this.reset = reset;
246421

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+
247463
var updateSearchResults = function(results){
248464
var dataRows = [];
249465
if(results){
@@ -295,6 +511,7 @@ function PatientSearchWidget(configuration){
295511
});
296512
}else if(config.initialPatients){
297513
//show the recently viewed
514+
reset();
298515
searchResultsData = initialPatientData;
299516
dataRows = initialData;
300517
}
@@ -595,6 +812,39 @@ function PatientSearchWidget(configuration){
595812
clearSearch();
596813
});
597814

815+
var searchByPatientSearchCriteria = function(){
816+
cancelAnyExistingSearch();
817+
var text=jq.trim(input.val());
818+
var currentCount = ++requestCount;
819+
var effectiveSearchDelay = config.searchDelayShort;
820+
window.setTimeout(function(){
821+
if(text=='' || text.length <= config.minSearchCharacters){
822+
doSearch('', currentCount);
823+
}else{
824+
doSearch(text, currentCount);
825+
}
826+
}, effectiveSearchDelay);
827+
828+
}
829+
830+
jq('select').change( function(){
831+
searchByPatientSearchCriteria();
832+
});
833+
834+
jq('input[type="date"]').change(function(){
835+
searchByPatientSearchCriteria();
836+
});
837+
838+
839+
jq('#patient-age-range-from').keyup(function(){
840+
searchByPatientSearchCriteria();
841+
});
842+
843+
jq('#patient-age-range-to').keyup(function(){
844+
searchByPatientSearchCriteria();
845+
});
846+
847+
598848
input.keyup(function(event) {
599849
var kc = event.keyCode;
600850
//ignore enter(because it was handled already onkeydown), keyboard navigation and control keys

0 commit comments

Comments
 (0)