Diagnosis Keyword Search

Had a neat question come up the other day and it lead to an even neater script that I thought I might share with you. The question was; if a patient is diabetic, can we indicate that on the diet iForm for...(some medical reason, I kinda blank out on those)...? But the problem was really interesting and got me to thinking.

The Problem:

Checking the diagnosis list for any one of what seems like (and probably is) over a hundred possible diabetic diagnoses.

The Solution:

Do a keyword search on all of a patient's diagnoses. If one of the diagnoses has any of our keywords, then notify the user with a popup and a visual indicator.

The VGR:

The VGR is really simple, we just want to import x diagnoses for our script to search through. I did 20, but it's up to you.
INIT,MAP,TEXT,diagnosis1,TO,get_order.display_string.12006154.1
INIT,MAP,TEXT,diagnosis2,TO,get_order.display_string.12006154.2
Repeat as many times as desired.

The HTML:

The HTML is very simple. You need text boxes to put your diagnoses descriptions on your page so that we can keyword search them. They can be put anywhere since they're going to be invisible.

    
Again, repeat as many times as necessary to match the VGR.

The CSS:

Just enough CSS to hide my diagnosis text boxes and my Diabetes indicator.
.diag{display:none;}
.beetus{display:none;}

The Script:

This script takes in the array (keywords) and runs once for each of them, comparing them to the values in each of our text boxes that have the "diag" class. if any of the keywords match anywhere in the diagnosis, it fires the alert popup, unhides our indicator picture, and increments the var breaktime to prevent additional loops from triggering more popups. (I'm leaving this one up even though Scott has come up with a better way to do it [below] so you can see an earlier iteration that you could easily customize to accomplish other tasks)
function diagnosisAlarm(keywords){
 var test;
 var breaktime = 0;
 $(keywords).each(function(){
  test=this;
  $(".diag").each(function(i){
   if($(this).val().indexOf(test) >= 0 && breaktime == 0){
    alert ("this patient has a diagnosis associated with Diabetes, order an appropriate diet");
    $(".beetus").removeClass("beetus");
    breaktime++;
   }
  });
 });
}//end Diagnosis Alarm 

The Improved Script:

Scott came up with a much more efficient way to execute the diagnosis search, it takes in the same array of keywords and compares them to the values of all of the diag class, then breaks the loop. Works pretty much the same way, but if you have a huge keyword array this will save you some resources.
function diagnosisAlarm(keywords) {
    $(keywords).each(function(i) {
        if ($('.diag[value~="' + this + '"]').length > 0) {
            alert ("this patient has a diagnosis associated with Diabetes, order an appropriate diet");
            $(".beetus").removeClass("beetus");
            return false;
        }
    });
}

The trigger:

I trigger it on load, but you could easily adapt this code to run at any point, even connect it to an open text box with a search button if for some reason you needed to have a flexible query. I'm imputing just four keywords since they seem to be predominant in most Diabetes diagnoses, but it should handle as many as you want to put in.
onload="diagnosisAlarm(['Diabetes','Diabetic','diabetes','diabetic']);"

That's it, not a whole lot to it. It feels like the kind of thing that might have more uses, but I'm not medical and I depend on other people in my dept to come up with those. So, if you think of additional uses for this code, please share them.

Oh yeah, the Diabetes indicator I mentioned.... may or may not look like this

1 comments: