Patient search by first name

markleeds wrote on Wednesday, February 15, 2006:

I have not been able to search by first name, so I looked at openemr/openemr/library/patient.inc function getPatientLnames.  It looks like the regex requires that there be at least one non-space character before the comma.  I sometimes want to search by first name only with none of the last name, so I tried this change which seems to work the way I like.  I still need the comma, but none of the last name needs to be known.

old:
//if (preg_match(’/^(.*\S)\s*,\s*(.*)/’, $lname, $matches)) {

new:
if (preg_match(’/^(.*),\s*(.*)/’, $lname, $matches)) {
     $lname = $matches[1];
     $fname = $matches[2];
}

mbrinson wrote on Wednesday, June 21, 2006:

On the subject of searching for patient information:
Do you know which module I would look in to modify the search behavior from the calendar?
I mean the java script that gets run when searching for a patient by clicking on a time slot on the calendar.
We don’t have that many patients and I wanted to regain the option of being able to leave the search field blank and get a list of all patients returned.
I have this working for the php based search, but I can’t find which module to look in for the javascript that is run from the calendar for this searching.

Sorry about the long post, I didn’t know how else to explain it.

Any help?

Thanks,

Mike B.

markleeds wrote on Wednesday, June 21, 2006:

I think it calls the same search function.

Try typing a space and then press ‘search’ or ‘find patient’.

michael_barnett wrote on Wednesday, June 21, 2006:

gotto /interface/main/finder/patient_select.php

comment out line 10

//if ($patient==’’) $patient=‘Please enter some information’;

if you do this you can hit findpatient with no information and it will select all of your patients and display them for you to pick.

i did this for testing but i only have 10 or 15 patients to play with

andres_paglayan wrote on Wednesday, June 21, 2006:

for a database with thousands, commenting it, will time out or use all server resources for a while,

markleeds wrote on Wednesday, June 21, 2006:

There should be a limit clause in the query to prevent that.

michael_barnett wrote on Wednesday, June 21, 2006:

ok i miss read your post. your talking about when you are using the popup when scheduling a patient right?

i added the first name search to mine but for some reason it still gives me everyone when i type in a first name.  did not have much time to tinker though 

i added a function in the patients.inc

function getPatientFnames($fname = “%”, $given1 = “pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,’%m/%d/%Y’) as DOB_TS”, $orderby = “lname ASC, fname ASC”)
{   
    $sql=“select $given1 from patient_data where fname like ‘$fname%’ order by $orderby”;

    $rez = sqlStatement($sql);

    for($iter=0; $row=sqlFetchArray($rez); $iter++)
    $returnval[$iter]=$row;

    return $returnval;
}
i just diced the last name function on a guess hehe
i also added a function to get insurance phone numbers

function getInsurancePhone($id){

    $sql =“select foreign_id, country_code, area_code, prefix, number from phone_numbers where foreign_id = ‘$id’”;
   
    return sqlQuery($sql);
}
I use this for one of the custome fee sheets. I found no other way to get an insurance phone number. if there is one please point it out.

And I’m here to learn any advice or critisism on the code i present is appreciated.

i also added to the find_patient_popup.php

if ($searchby == "Last") {
   $result = getPatientLnames("$searchparm","*");
  } elseif ($searchby == "ID") {
   $result = getPatientId("$searchparm","*");
  } elseif ($searchby == "DOB") {
   $result = getPatientDOB("$searchparm","*");
  } elseif ($searchby == "SSN") {
   $result = getPatientSSN("$searchparm","*");
  } elseif ($searchby == "First"){
      $result = getPatientFnames("$searchparam","*");
    }
}

<select name=‘searchby’>
    <option value=“Last”>Last Name</option>
    <option value=“First”<? if ($searchby == ‘First’) echo ’ selected’ ?>>First Name</option>
    <option value=“ID”<? if ($searchby == ‘ID’) echo ’ selected’ ?>>ID</option>
    <option value=“SSN”<? if ($searchby == ‘SSN’) echo ’ selected’ ?>>SSN</option>
    <option value=“DOB”<? if ($searchby == ‘DOB’) echo ’ selected’ ?>>DOB</option>
   </select>

<table border=‘0’>
<tr>
<td><b>First Name</b></td>
  <td><b>Last Name</b></td>
  <td><b>SS</b></td>
  <td><b>DOB</b></td>
  <td><b>ID</b></td>
</tr>

sunsetsystems wrote on Wednesday, June 21, 2006:

If you grep the source for “phone_numbers” you’ll find plenty of sample code relating to those.  One good example is custom/BillingExport.csv.php which contains several useful joins.

Also there’s a PhoneNumber class that might already have what you want.

Rod
www.sunsetsystems.com

markleeds wrote on Thursday, June 22, 2006:

Michael,

I added first name search to the existing function, getPatientLnames.

This is what is currently in CVS also.

Explaining it makes it sound complicated, but it’s pretty intuitive.

you type a search string with or without a comma and with or without text before and after the comma.  The term before the comma is the last name search string and the term after the comma is the first name search string.  If either term starts with a capital letter, it matches from the beginning of the name.  If not, then it finds all names with the search string contained anywhere in the name.  If no comma, only last names are matched.  If starts with a comma, then a string, only first names are matched.

It works great for us.  We are at the point now where we call out name fragments when someone asks for a patient name.  “Look up first name ‘rr’!”, for example if the patient’s name is Harriet Smith (fake name, not real patient).

You can find the code in patient.inc in CVS.  Since we’re posting code here and CVS access here can be very slow sometimes, here it is, with the commented-out cruft removed.

function getPatientLnames($lname = “%”, $given = “pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,’%m/%d/%Y’) as DOB_TS”, $orderby = “lname ASC, fname ASC”, $limit=“all”, $start=“0”)
{
        // Allow the last name to be followed by a comma and some part of a first name.
        $lname = trim($lname);
        $fname = ‘’;
        if (preg_match(’/^(.*),(.*)/’, $lname, $matches)) {
                $lname = trim($matches[1]);
                $fname = trim($matches[2]);
        }
        $search_for_pieces1 = ‘’;
        $search_for_pieces2 = ‘’;
        if ($lname{0} != strtoupper($lname{0})) {$search_for_pieces1 = ‘%’;}
        if ($fname{0} != strtoupper($fname{0})) {$search_for_pieces2 = ‘%’;}
        $sql=“select $given from patient_data where lname like '”
                .$search_for_pieces1."$lname%’ "
                .“and fname like '”
                .$search_for_pieces2."$fname%’ "
                .“order by $orderby”;

        if ($limit != "all")
                $sql .= " limit $start, $limit";
        $rez = sqlStatement($sql);

        for($iter=0; $row=sqlFetchArray($rez); $iter++)
                $returnval[$iter]=$row;

        return $returnval;
}

michael_barnett wrote on Thursday, June 22, 2006:

* puts down "See Jane, Spot,and Dick Run" book *

hehe nice I was a literature major in college for a few years. and looking at your code makes me think I’m talking to Hemmingway especially compared to mine.

CVS how do i use it???

michael_barnett wrote on Thursday, June 22, 2006:

Never mind i saw the write up…good lord

markleeds wrote on Thursday, June 22, 2006:

It’s easy.  Look at the CVS instructions on this website.  There are a couple of lines that you can cut and paste and run from the command line on your computer.  If you are using windows, download the CVS client for windows and then you can run those commands.  Don’t worry at first what it all means.  You just need to download the latest files for now. 

Basically it’s this (copied from https://sourceforge.net/cvs/?group_id=60081):

cvs -d:pserver:anonymous@openemr.cvs.sourceforge.net:/cvsroot/openemr login

cvs -z3 -d:pserver:anonymous@openemr.cvs.sourceforge.net:/cvsroot/openemr co -P openemr

Just save as a batch file and run it from the command line and you will get the whole openemr directory with the latest files.

markleeds wrote on Thursday, June 22, 2006:

If I didn’t make it clear in the last post, those commands won’t work unless the CVS program (client) is already installed on your computer.

You may want to try http://www.wincvs.org/

kashurjmax wrote on Friday, June 23, 2006:

tortisecvs is a very neat CVS tool for windows - it integrates with the windows shell (right click on file and get options) - very neat

ggd wrote on Saturday, July 26, 2008:

Hi!

Today I ‘discovered’ the old issue, i.e. OpenEMR cannot find patient by first name :frowning:

While evaluating GNUmed, I see it does it.

Any plan to improve search in OpenEMR?

btw, it would be nice to improve UI (and get rid of frames) and have search-category as e.g. drop-down list…

Sincerely,
Gour

drbowen wrote on Monday, July 28, 2008:

Well, actually you can.

Type in a comma followed by the first name.  ", Sam"  as an example, will bring up all patients with first names: Sam, Samuel, Sammy, Samantha etc.

You can also do partial searches on both first and last names: "bow, sam" would work on my system and brings up "Bowen, Samuel".

Sincerely,

Sam(uel) Bowen, MD

ggd wrote on Tuesday, July 29, 2008:

<quote>
Well, actually you can.

Type in a comma followed by the first name. ", Sam" as an example, will bring up all patients with first names: Sam, Samuel, Sammy, Samantha etc.
</quote>

Ohh, that very nice :slight_smile:

<quote>
You can also do partial searches on both first and last names: "bow, sam" would work on my system and brings up "Bowen, Samuel".
</quote>

Even nicer. Cute :wink:

Thank you.

Sincerely,
Gour