From 8b8d822f45b565bf3494e033b5581652bdca3129 Mon Sep 17 00:00:00 2001 From: Rishi Date: Fri, 30 Aug 2019 23:42:50 +0530 Subject: [PATCH] GSoC 2019: Patient search criteria module --- omod/pom.xml | 23 ++ .../patientsearch/patientSearchWidget.gsp | 26 +- .../patientsearch/patientSearchWidget.js | 254 +++++++++++++++++- pom.xml | 28 +- 4 files changed, 326 insertions(+), 5 deletions(-) diff --git a/omod/pom.xml b/omod/pom.xml index 04d963c5a..64b323be1 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -18,6 +18,15 @@ ${basedir}/.rubygems + + + + jitpack.io + https://jitpack.io + + + + + + com.github.Reyano132.openmrs-module-patientsearchcriteria + patientsearch-api + v1.0.0 + provided + + + com.github.Reyano132.openmrs-module-patientsearchcriteria + patientsearch-omod + v1.0.0 + provided + + diff --git a/omod/src/main/webapp/fragments/patientsearch/patientSearchWidget.gsp b/omod/src/main/webapp/fragments/patientsearch/patientSearchWidget.gsp index c37951719..6640e0bf3 100644 --- a/omod/src/main/webapp/fragments/patientsearch/patientSearchWidget.gsp +++ b/omod/src/main/webapp/fragments/patientsearch/patientSearchWidget.gsp @@ -94,8 +94,32 @@
value="${doInitialSearch}"<% } %>/> - <% if(patientSearchExtensions){ + + Search with age or birthdate
+ + + + <% if(patientSearchExtensions){ patientSearchExtensions.each { // create a base map from the fragmentConfig if it exists, otherwise just create an empty map def configs = [:]; diff --git a/omod/src/main/webapp/resources/scripts/patientsearch/patientSearchWidget.js b/omod/src/main/webapp/resources/scripts/patientsearch/patientSearchWidget.js index 9ae3f4e67..5e4c71e04 100644 --- a/omod/src/main/webapp/resources/scripts/patientsearch/patientSearchWidget.js +++ b/omod/src/main/webapp/resources/scripts/patientsearch/patientSearchWidget.js @@ -43,7 +43,7 @@ function PatientSearchWidget(configuration){ var highlightedMouseRowIndex; var searchDelayTimer; var requestCount = 0; - var searchUrl = '/' + OPENMRS_CONTEXT_PATH + '/ws/rest/v1/patient'; + var searchUrl = '/' + OPENMRS_CONTEXT_PATH + '/ws/rest/v1/patientsearch/patient'; var initialData = []; var initialPatientData = []; var initialPatientUuids = []; @@ -140,7 +140,52 @@ function PatientSearchWidget(configuration){ searchOnIdentifierAndName(query, currRequestCount); } else { - searchOnExactIdentifierMatchThenIdentifierAndName(query, currRequestCount, autoSelectIfExactIdentifierMatch); + var gender_search=jq('#patient-gender-search').val(); + var from_search=jq('#patient-age-range-from').val(); + var to_search=jq('#patient-age-range-to').val(); + var date_search; + if(jq('#patient-birthdate').val()!=''){ + console.log('birth '+jq('#patient-birthdate').val()); + date_search =new Date(jq('#patient-birthdate').val()); + date_search.setHours(0); + date_search.setMinutes(0); + } + + + if(query==''){ + if(gender_search!='' && from_search=='' && to_search=='' && jq('#patient-birthdate').val()==''){ + searchOnGender(gender_search,currRequestCount); + } else if(gender_search=='' && from_search!='' && to_search !='' && jq('#patient-birthdate').val()==''){ + searchOnRangeOfAge(from_search,to_search,currRequestCount); + }else if(gender_search=='' && jq('#patient-birthdate').val()!=''){ + searchOnBirthdate(date_search.getTime(),currRequestCount); + }else if(gender_search!='' && from_search!='' && to_search!=''){ + searchOnGenderAndRangeOfAge(gender_search,from_search,to_search,currRequestCount); + }else if(gender_search!='' && jq('#patient-birthdate').val()!=''){ + searchOnGenderAndBirthdate(gender_search,date_search.getTime(),currRequestCount); + }else{ + updateSearchResults(); + } + + } + else{ + if(gender_search!=''){ + if( from_search=='' && to_search=='' && jq('#patient-birthdate').val()==''){ + searchOnIdentifierAndNameAndGender(query,gender_search,currRequestCount); + }else if(from_search!='' && to_search !=''){ + searchOnIdentifierAndNameAndGenderAndRangeOfAge(query,gender_search,from_search,to_search,currRequestCount); + }else{ + searchOnIdentifierAndNameAndGenderAndBirthdate(query,gender_search,date_search.getTime(),currRequestCount); + } + }else if(from_search!='' && to_search !=''){ + searchOnIdentifierAndNameAndRangeOfAge(query,from_search,to_search,currRequestCount); + }else if(jq('#patient-birthdate').val()!=''){ + searchOnIdentifierAndNameAndBirthdate(query,date_search.getTime(),currRequestCount); + }else{ + searchOnExactIdentifierMatchThenIdentifierAndName(query, currRequestCount, autoSelectIfExactIdentifierMatch); + } + } + } } @@ -210,6 +255,136 @@ function PatientSearchWidget(configuration){ }); } + var searchOnIdentifierAndNameAndGender = function(query,gender_search,currRequestCount) { + emr.getJSON(searchUrl, {q: query, gender: gender_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnIdentifierAndNameAndRangeOfAge = function(query,from_search,to_search,currRequestCount) { + emr.getJSON(searchUrl, {q: query, from: from_search, to: to_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnIdentifierAndNameAndBirthdate = function(query,birthdate_search,currRequestCount) { + emr.getJSON(searchUrl, {q: query, birthdate: birthdate_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnIdentifierAndNameAndGenderAndRangeOfAge = function(query,gender_search,from_search,to_search,currRequestCount) { + emr.getJSON(searchUrl, {q: query, gender: gender_search, from: from_search, to: to_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnIdentifierAndNameAndGenderAndBirthdate = function(query,gender_search,birthdate_search,currRequestCount) { + emr.getJSON(searchUrl, {q: query, gender: gender_search, birthdate: birthdate_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnGenderAndRangeOfAge = function(gender_search,from_search,to_search,currRequestCount) { + emr.getJSON(searchUrl, {gender: gender_search, from: from_search, to: to_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnGenderAndBirthdate = function(gender_search,birthdate_search,currRequestCount) { + emr.getJSON(searchUrl, {gender: gender_search,birthdate: birthdate_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnGender = function(gender_search,currRequestCount) { + emr.getJSON(searchUrl, {gender: gender_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnRangeOfAge = function(from_search,to_search,currRequestCount) { + emr.getJSON(searchUrl, {from: from_search, to: to_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + + var searchOnBirthdate = function(birthdate_search,currRequestCount) { + emr.getJSON(searchUrl, {birthdate: birthdate_search, v: customRep }) + .done(function(data) { + //late ajax responses should be ignored not to overwrite the latest + if(data && (!currRequestCount || currRequestCount >= requestCount)){ + updateSearchResults(data.results); + } + }) + .fail(function (jqXHR) { + failSearch(); + }); + } + var failSearch = function() { performingSearch = false; if (!currRequestCount || currRequestCount >= requestCount) { @@ -244,6 +419,47 @@ function PatientSearchWidget(configuration){ } this.reset = reset; + //Add age range and birthdate search + + jq('#getAgeAndBirthdateFilter').click(function (event) { + if(this.checked){ + jq('#patient-search-age-birthdate').css('display','block'); + }else{ + jq('#patient-search-age-birthdate').css('display','none'); + jq( '#patient-age' ).prop( 'checked', false ); + jq( '#patient-birthdate' ).prop( 'checked', false ); + jq('#patient-age-range-from').val(''); + jq('#patient-age-range-to').val(''); + jq('input[type=date]').each( function resetDate(){ + this.value = this.defaultValue; + } ); + } + }) + + + $("input[name='patient-age-birthdate']").change(function(){ + var ageOrBirthdate= $("input[name='patient-age-birthdate']:checked").val() + if(ageOrBirthdate=="patient-age"){ + jq('#patient-birthdate-search').css('display','none'); + jq('#patient-age-range-search').css('display','block'); + jq('input[type=date]').each( function resetDate(){ + this.value = this.defaultValue; + } ); + } + if(ageOrBirthdate=="patient-birthdate"){ + jq('#patient-age-range-search').css('display','none'); + jq('#patient-birthdate-search').css('display','block'); + jq('#patient-age-range-from').val(''); + jq('#patient-age-range-to').val(''); + } + }); + + //for date type support to browsers + if ( jq('[type="date"]').prop('type') != 'date' ) { + jq('[type="date"]').datepicker(); + } + + var updateSearchResults = function(results){ var dataRows = []; if(results){ @@ -295,6 +511,7 @@ function PatientSearchWidget(configuration){ }); }else if(config.initialPatients){ //show the recently viewed + reset(); searchResultsData = initialPatientData; dataRows = initialData; } @@ -595,6 +812,39 @@ function PatientSearchWidget(configuration){ clearSearch(); }); + var searchByPatientSearchCriteria = function(){ + cancelAnyExistingSearch(); + var text=jq.trim(input.val()); + var currentCount = ++requestCount; + var effectiveSearchDelay = config.searchDelayShort; + window.setTimeout(function(){ + if(text=='' || text.length <= config.minSearchCharacters){ + doSearch('', currentCount); + }else{ + doSearch(text, currentCount); + } + }, effectiveSearchDelay); + + } + + jq('select').change( function(){ + searchByPatientSearchCriteria(); + }); + + jq('input[type="date"]').change(function(){ + searchByPatientSearchCriteria(); + }); + + + jq('#patient-age-range-from').keyup(function(){ + searchByPatientSearchCriteria(); + }); + + jq('#patient-age-range-to').keyup(function(){ + searchByPatientSearchCriteria(); + }); + + input.keyup(function(event) { var kc = event.keyCode; //ignore enter(because it was handled already onkeydown), keyboard navigation and control keys diff --git a/pom.xml b/pom.xml index ad734a5ed..9b993bed0 100644 --- a/pom.xml +++ b/pom.xml @@ -280,6 +280,25 @@ tests + + + com.github.Reyano132.openmrs-module-patientsearchcriteria + patientsearch-api + v1.0.0 + provided + + + com.github.Reyano132.openmrs-module-patientsearchcriteria + patientsearch-omod + v1.0.0 + provided + + + org.springframework + spring-core + 4.0.5.RELEASE + + @@ -290,8 +309,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.8 + 1.8 UTF-8 @@ -340,6 +359,11 @@ OpenMRS Nexus Repository http://mavenrepo.openmrs.org/nexus/content/repositories/public + + + jitpack.io + https://jitpack.io +