List<Integer> personId = new ArrayList<Integer>();
List<Object> personList = new ArrayList<Object>();
//first we are going to search by name for patients
PatientService patientService = Context.getPatientService();
for (Patient p : patientService.getPatients(searchPhrase, null, null, false)) {
personList.add(PersonListItem.createBestMatch(p));
personId.add(p.getId());
}
// now we check for persons (that won't be brought back by the patient search)
PersonService ps = Context.getPersonService();
for (Person p : ps.getPeople(searchPhrase, null)) {
if(!personId.contains(p.getId()))
{
personList.add(PersonListItem.createBestMatch(p));
}
}
// also search on patient identifier if the query contains a number
if (searchPhrase.matches(".*\\d+.*")) {
patientService = Context.getPatientService();
for (Patient p : patientService.getPatients(null, searchPhrase, null, false)) {
if(!personId.contains(p.getId()))
{
personList.add(PersonListItem.createBestMatch(p));
}
}