Skip to content

Commit

Permalink
Martina, Roni | BAH-460 | add lucene search to find patients with sim…
Browse files Browse the repository at this point in the history
…ilar name and gender
  • Loading branch information
mduemcke committed Jun 8, 2018
1 parent 7ee46a5 commit 9ea15aa
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ private PatientResponse toPatientResponse(PatientResponseMapper patientResponseM
}

private List<Patient> getPatientsByNameAndGender(String name, String gender, Integer length) {
if(isNullOrEmpty(name, gender)) {
return new ArrayList<>();
}

HibernatePatientDAO patientDAO = new HibernatePatientDAO();
patientDAO.setSessionFactory(sessionFactory);
List<Patient> patients = new ArrayList<Patient>();
Expand All @@ -139,6 +143,10 @@ && checkGender(personName.getPerson(), gender)
return patients;
}

private Boolean isNullOrEmpty(String name, String gender) {
return (name == null || name.trim().isEmpty()) && (gender == null || gender.isEmpty());
}


private Boolean checkGender(Person person, String gender) {
if(gender != null && !gender.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,18 @@ public void shouldSearchSimilarPatientByPatientNameAndGender() {
assertEquals(patient1.getMiddleName(), "Peeter");
assertEquals(patient1.getFamilyName(), "Sinha");
}

@Test
public void shouldReturnEmptyListIfAllSearchTermsAreEmpty() {
List<PatientResponse> patients = patientDao.getSimilarPatientsUsingLuceneSearch("", "", "c36006e5-9fbb-4f20-866b-0ece245615a1", 5);

assertEquals(0, patients.size());
}

@Test
public void shouldReturnResultsIfOneFieldIsSet() {
List<PatientResponse> patients = patientDao.getSimilarPatientsUsingLuceneSearch("", "F", "c36006e5-9fbb-4f20-866b-0ece245615a1", 5);

assertEquals(5, patients.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ public void shouldGetPatientByPartialIdentifier() throws Exception {
}

@Test
public void shouldCallgetSimilarPatientsUsingLuceneSearch() {
public void shouldCallGetSimilarPatientsUsingLuceneSearch() {
HttpServletRequest request = mock(HttpServletRequest.class);
when(requestContext.getRequest()).thenReturn(request);
when(request.getParameterMap()).thenReturn(new HashMap<>());

PatientSearchParameters patientSearchParameters = new PatientSearchParameters(requestContext);
patientSearchParameters.setName("John");
patientSearchParameters.setGender("M");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller.search;

import org.bahmni.module.bahmnicore.contract.patient.PatientSearchParameters;
import org.bahmni.module.bahmnicore.contract.patient.mapper.PatientResponseMapper;
import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse;
import org.bahmni.module.bahmnicore.service.BahmniPatientService;
import org.openmrs.Patient;
import org.openmrs.PatientIdentifier;
import org.openmrs.Person;
import org.openmrs.api.context.Context;
import org.openmrs.module.bahmniemrapi.visitlocation.BahmniVisitLocationServiceImpl;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.RestUtil;
Expand All @@ -21,7 +15,6 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller.search;

import org.bahmni.module.bahmnicore.web.v1_0.BaseIntegrationTest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class BahmniPatientSearchControllerIT extends BaseIntegrationTest {

@Before
public void setup() throws Exception {
executeDataSet("apiTestData.xml");
updateSearchIndex();
}

@Test
public void shouldReturnPatientDetailsWhenUsingLuceneSearch() throws Exception {
MockHttpServletRequest request = newGetRequest("/rest/v1/bahmnicore/search/patient/lucene");
request.setParameter("loginLocationUuid", "c36006e5-9fbb-4f20-866b-0ece245615a1");
request.setParameter("q", "GAN200001");

MockHttpServletResponse response = handle(request);

assertEquals(200, response.getStatus());
assertTrue("Expected response to contain patient uuid", response.getContentAsString().contains("uuid"));
}

@Test
public void shouldReturnPatientDetailsWhenUsingSimilarSearch() throws Exception {
MockHttpServletRequest request = newGetRequest("/rest/v1/bahmnicore/search/patient/similar");
request.setParameter("gender", "M");
request.setParameter("loginLocationUuid", "c36006e5-9fbb-4f20-866b-0ece245615a1");
request.setParameter("q", "John");

MockHttpServletResponse response = handle(request);

assertEquals(200, response.getStatus());
assertTrue("Expected response to contain list of results", response.getContentAsString().contains("pageOfResults"));
assertTrue("Expected response to contain patient uuid", response.getContentAsString().contains("uuid"));
}
}

0 comments on commit 9ea15aa

Please sign in to comment.