Skip to content

Commit

Permalink
Merge pull request #1 from carhartl/resume-BAH-460
Browse files Browse the repository at this point in the history
Simplify `getPatientsByNameAndGender()` method
  • Loading branch information
mduemcke authored Aug 8, 2018
2 parents aac9741 + b039a2b commit ecfd83c
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,15 @@ private List<Patient> getPatientsByNameAndGender(String name, String gender, Int

HibernatePatientDAO patientDAO = new HibernatePatientDAO();
patientDAO.setSessionFactory(sessionFactory);
List<Patient> patients = new ArrayList<Patient>();
String query = LuceneQuery.escapeQuery(name);
PersonLuceneQuery personLuceneQuery = new PersonLuceneQuery(sessionFactory);
LuceneQuery<PersonName> nameQuery = personLuceneQuery.getPatientNameQueryWithOrParser(query, false);
List<PersonName> persons = nameQuery.list().stream()
.filter(
personName ->
personName.getPreferred()
&& checkGender(personName.getPerson(), gender)
).collect(toList());
persons = persons.subList(0, Math.min(length, persons.size()));
persons.forEach(person -> patients.add(new Patient(person.getPerson())));
List<Patient> patients = nameQuery.list().stream()
.filter(personName ->
personName.getPreferred() && checkGender(personName.getPerson(), gender))
.limit(length)
.map(personName -> new Patient(personName.getPerson()))
.collect(toList());
return patients;
}

Expand Down

0 comments on commit ecfd83c

Please sign in to comment.