From a88cb84373616a1ec15da69dbfcf5e147d3bf942 Mon Sep 17 00:00:00 2001 From: Martina Duemcke Date: Fri, 8 Jun 2018 09:24:02 +0200 Subject: [PATCH] Martina, Roni, Eyal | BAH-460 | add api to search patients with similar name and gender --- .../patient/PatientSearchParameters.java | 10 +++ .../patient/mapper/PatientResponseMapper.java | 13 +-- .../module/bahmnicore/dao/PatientDao.java | 2 + .../bahmnicore/dao/impl/PatientDaoImpl.java | 80 ++++++++++++++++--- .../service/BahmniPatientService.java | 4 + .../impl/BahmniPatientServiceImpl.java | 9 +++ .../impl/BahmniPatientDaoImplLuceneIT.java | 51 +++++++++++- .../impl/BahmniPatientServiceImplTest.java | 23 +++++- .../search/BahmniPatientSearchController.java | 15 ++++ .../BahmniPatientSearchControllerIT.java | 45 +++++++++++ 10 files changed, 233 insertions(+), 19 deletions(-) create mode 100644 bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchControllerIT.java diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/PatientSearchParameters.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/PatientSearchParameters.java index 496dc54c4c..222bc955cf 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/PatientSearchParameters.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/PatientSearchParameters.java @@ -9,6 +9,7 @@ public class PatientSearchParameters { private Boolean filterPatientsByLocation; private String identifier; private String name; + private String gender; private String addressFieldName; private String addressFieldValue; private Integer start; @@ -43,6 +44,7 @@ public PatientSearchParameters(RequestContext context) { } else { this.setAddressFieldName("city_village"); } + this.setGender(context.getParameter("gender")); this.setAddressFieldValue(context.getParameter("addressFieldValue")); Map parameterMap = context.getRequest().getParameterMap(); this.setAddressSearchResultFields((String[]) parameterMap.get("addressSearchResultsConfig")); @@ -71,6 +73,14 @@ public void setName(String name) { this.name = name; } + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + public String getAddressFieldName() { return addressFieldName; } diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/mapper/PatientResponseMapper.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/mapper/PatientResponseMapper.java index b5a24f279c..245fc625b4 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/mapper/PatientResponseMapper.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/patient/mapper/PatientResponseMapper.java @@ -1,6 +1,5 @@ package org.bahmni.module.bahmnicore.contract.patient.mapper; -import java.util.Objects; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang3.StringUtils; import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse; @@ -17,11 +16,13 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import static java.util.Arrays.asList; + public class PatientResponseMapper { private PatientResponse patientResponse; private VisitService visitService; @@ -34,8 +35,8 @@ public PatientResponseMapper(VisitService visitService, BahmniVisitLocationServi } public PatientResponse map(Patient patient, String loginLocationUuid, String[] searchResultFields, String[] addressResultFields, Object programAttributeValue) { - List patientSearchResultFields = searchResultFields != null ? Arrays.asList(searchResultFields) : new ArrayList<>(); - List addressSearchResultFields = addressResultFields != null ? Arrays.asList(addressResultFields) : new ArrayList<>(); + List patientSearchResultFields = searchResultFields != null ? asList(searchResultFields) : new ArrayList<>(); + List addressSearchResultFields = addressResultFields != null ? asList(addressResultFields) : new ArrayList<>(); Integer visitLocationId = bahmniVisitLocationService.getVisitLocation(loginLocationUuid).getLocationId(); List activeVisitsByPatient = visitService.getActiveVisitsByPatient(patient); @@ -51,7 +52,9 @@ public PatientResponse map(Patient patient, String loginLocationUuid, String[] s patientResponse.setFamilyName(patient.getFamilyName()); patientResponse.setGender(patient.getGender()); PatientIdentifier primaryIdentifier = patient.getPatientIdentifier(); - patientResponse.setIdentifier(primaryIdentifier.getIdentifier()); + if(primaryIdentifier != null) { + patientResponse.setIdentifier(primaryIdentifier.getIdentifier()); + } patientResponse.setPatientProgramAttributeValue(programAttributeValue); mapExtraIdentifiers(patient, primaryIdentifier); diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/PatientDao.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/PatientDao.java index 0516349ff7..eca503486b 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/PatientDao.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/PatientDao.java @@ -19,6 +19,8 @@ List getPatientsUsingLuceneSearch(String identifier, String nam String programAttributeFieldName, String[] addressSearchResultFields, String[] patientSearchResultFields, String loginLocationUuid, Boolean filterPatientsByLocation, Boolean filterOnAllIdentifiers); + List getSimilarPatientsUsingLuceneSearch(String name, String gender, String loginLocationUuid, Integer length); + public Patient getPatient(String identifier); public List getPatients(String partialIdentifier, boolean shouldMatchExactPatientId); diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/impl/PatientDaoImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/impl/PatientDaoImpl.java index f147768b4c..de89c6605a 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/impl/PatientDaoImpl.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/dao/impl/PatientDaoImpl.java @@ -22,20 +22,26 @@ import org.openmrs.Patient; import org.openmrs.PatientIdentifier; import org.openmrs.PatientIdentifierType; +import org.openmrs.Person; +import org.openmrs.PersonName; import org.openmrs.RelationshipType; import org.openmrs.api.context.Context; +import org.openmrs.api.db.hibernate.HibernatePatientDAO; +import org.openmrs.api.db.hibernate.PersonLuceneQuery; +import org.openmrs.api.db.hibernate.search.LuceneQuery; import org.openmrs.module.bahmniemrapi.visitlocation.BahmniVisitLocationServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; + import java.util.ArrayList; -import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; -import static java.util.stream.Collectors.reducing; +import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; @Repository @@ -88,18 +94,68 @@ public List getPatientsUsingLuceneSearch(String identifier, Str List patientResponses = patientIdentifiers.stream() .map(patientIdentifier -> { Patient patient = patientIdentifier.getPatient(); - if(!uniquePatientIds.contains(patient.getPatientId())) { - PatientResponse patientResponse = patientResponseMapper.map(patient, loginLocationUuid, patientSearchResultFields, addressSearchResultFields, - programAttributes.get(patient.getPatientId())); - uniquePatientIds.add(patient.getPatientId()); - return patientResponse; - }else - return null; + return toPatientResponse(patientResponseMapper, patient, loginLocationUuid, addressSearchResultFields, patientSearchResultFields, programAttributes, uniquePatientIds); }).filter(Objects::nonNull) .collect(toList()); return patientResponses; } + @Override + public List getSimilarPatientsUsingLuceneSearch(String name, String gender, String loginLocationUuid, Integer length) { + PatientResponseMapper patientResponseMapper = new PatientResponseMapper(Context.getVisitService(),new BahmniVisitLocationServiceImpl(Context.getLocationService())); + List patients = getPatientsByNameAndGender(name, gender, length); + List patientResponses = patients.stream() + .map(patient -> {return patientResponseMapper.map(patient, loginLocationUuid, null, null,null);}).filter(Objects::nonNull) + .collect(toList()); + return patientResponses; + } + + private PatientResponse toPatientResponse(PatientResponseMapper patientResponseMapper, Patient patient, String loginLocationUuid, String[] addressSearchResultFields, String[] patientSearchResultFields, Map programAttributes, Set uniquePatientIds) { + if(!uniquePatientIds.contains(patient.getPatientId())) { + PatientResponse patientResponse = patientResponseMapper.map(patient, loginLocationUuid, patientSearchResultFields, addressSearchResultFields, + programAttributes.get(patient.getPatientId())); + uniquePatientIds.add(patient.getPatientId()); + return patientResponse; + } else { + return null; + } + } + + private List getPatientsByNameAndGender(String name, String gender, Integer length) { + if(isNullOrEmpty(name, gender)) { + return new ArrayList<>(); + } + + HibernatePatientDAO patientDAO = new HibernatePatientDAO(); + patientDAO.setSessionFactory(sessionFactory); + List patients = new ArrayList(); + String query = LuceneQuery.escapeQuery(name); + PersonLuceneQuery personLuceneQuery = new PersonLuceneQuery(sessionFactory); + LuceneQuery nameQuery = personLuceneQuery.getPatientNameQueryWithOrParser(query, false); + List 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()))); + 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()){ + return gender.equals(person.getGender()); + } else { + return true; + } + } + private List getPatientIdentifiers(String identifier, Boolean filterOnAllIdentifiers, Integer offset, Integer length) { FullTextSession fullTextSession = Search.getFullTextSession(sessionFactory.getCurrentSession()); QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(PatientIdentifier.class).get(); @@ -179,7 +235,7 @@ private boolean isValidAddressField(String addressFieldName) { "LOWER (TABLE_NAME) ='person_address' and LOWER(COLUMN_NAME) IN " + "( :personAddressField)"; Query queryToGetAddressFields = sessionFactory.getCurrentSession().createSQLQuery(query); - queryToGetAddressFields.setParameterList("personAddressField", Arrays.asList(addressFieldName.toLowerCase())); + queryToGetAddressFields.setParameterList("personAddressField", asList(addressFieldName.toLowerCase())); List list = queryToGetAddressFields.list(); return list.size() > 0; } @@ -201,7 +257,7 @@ private List getPersonAttributeIds(String[] patientAttributes) { String query = "select person_attribute_type_id from person_attribute_type where name in " + "( :personAttributeTypeNames)"; Query queryToGetAttributeIds = sessionFactory.getCurrentSession().createSQLQuery(query); - queryToGetAttributeIds.setParameterList("personAttributeTypeNames", Arrays.asList(patientAttributes)); + queryToGetAttributeIds.setParameterList("personAttributeTypeNames", asList(patientAttributes)); List list = queryToGetAttributeIds.list(); return (List) list; } @@ -229,7 +285,7 @@ public List getPatients(String patientIdentifier, boolean shouldMatchEx } Patient patient = getPatient(patientIdentifier); - List result = (patient == null ? new ArrayList() : Arrays.asList(patient)); + List result = (patient == null ? new ArrayList() : asList(patient)); return result; } diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniPatientService.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniPatientService.java index 5a3905ba5f..eb598e582b 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniPatientService.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniPatientService.java @@ -1,9 +1,11 @@ package org.bahmni.module.bahmnicore.service; 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.PatientConfigResponse; import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse; import org.openmrs.Patient; +import org.openmrs.Person; import org.openmrs.RelationshipType; import java.util.List; @@ -15,6 +17,8 @@ public interface BahmniPatientService { List luceneSearch(PatientSearchParameters searchParameters); + List searchSimilarPatients(PatientSearchParameters searchParameters); + public List get(String partialIdentifier, boolean shouldMatchExactPatientId); public List getByAIsToB(String aIsToB); diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImpl.java index 0c50fae0a8..2256f31fda 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImpl.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImpl.java @@ -20,6 +20,7 @@ @Service @Lazy //to get rid of cyclic dependencies public class BahmniPatientServiceImpl implements BahmniPatientService { + private static final int SIMILAR_PATIENT_RESULT_LENGTH = 5; private PersonService personService; private ConceptService conceptService; private PatientDao patientDao; @@ -83,6 +84,14 @@ public List luceneSearch(PatientSearchParameters searchParamete searchParameters.getFilterPatientsByLocation(), searchParameters.getFilterOnAllIdentifiers()); } + @Override + public List searchSimilarPatients(PatientSearchParameters searchParameters) { + return patientDao.getSimilarPatientsUsingLuceneSearch(searchParameters.getName(), + searchParameters.getGender(), + searchParameters.getLoginLocationUuid(), + SIMILAR_PATIENT_RESULT_LENGTH); + } + @Override public List get(String partialIdentifier, boolean shouldMatchExactPatientId) { return patientDao.getPatients(partialIdentifier, shouldMatchExactPatientId); diff --git a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/dao/impl/BahmniPatientDaoImplLuceneIT.java b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/dao/impl/BahmniPatientDaoImplLuceneIT.java index c02cfc7bc0..580103a0ae 100644 --- a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/dao/impl/BahmniPatientDaoImplLuceneIT.java +++ b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/dao/impl/BahmniPatientDaoImplLuceneIT.java @@ -7,7 +7,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.openmrs.Patient; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; @@ -213,4 +212,54 @@ public void shouldNotReturnDuplicatePatientsEvenIfTwoIdentifiersMatches() { assertTrue(patient.getExtraIdentifiers().contains("200006")); } + @Test + public void shouldSearchSimilarPatientByPatientName() { + List patients = patientDao.getSimilarPatientsUsingLuceneSearch("Peet", "", "c36006e5-9fbb-4f20-866b-0ece245615a1", 5); + assertEquals(2, patients.size()); + + PatientResponse patient1 = patients.get(0); + PatientResponse patient2 = patients.get(1); + assertEquals(patient1.getGivenName(), "Horatio"); + assertEquals(patient1.getMiddleName(), "Peeter"); + assertEquals(patient1.getFamilyName(), "Sinha"); + assertEquals(patient2.getGivenName(), "John"); + assertEquals(patient2.getMiddleName(), "Peeter"); + assertEquals(patient2.getFamilyName(), "Sinha"); + } + + @Test + public void shouldSearchSimilarPatientByPatientNameAndUseLimitResult() { + List patients = patientDao.getSimilarPatientsUsingLuceneSearch("Peet", "", "c36006e5-9fbb-4f20-866b-0ece245615a1", 1); + assertEquals("Should limit number of results",1, patients.size()); + PatientResponse patient1 = patients.get(0); + + assertEquals(patient1.getGivenName(), "Horatio"); + assertEquals(patient1.getMiddleName(), "Peeter"); + assertEquals(patient1.getFamilyName(), "Sinha"); + } + + @Test + public void shouldSearchSimilarPatientByPatientNameAndGender() { + List patients = patientDao.getSimilarPatientsUsingLuceneSearch("Peet", "F", "c36006e5-9fbb-4f20-866b-0ece245615a1", 5); + PatientResponse patient1 = patients.get(0); + + assertEquals(1, patients.size()); + assertEquals(patient1.getGivenName(), "John"); + assertEquals(patient1.getMiddleName(), "Peeter"); + assertEquals(patient1.getFamilyName(), "Sinha"); + } + + @Test + public void shouldReturnEmptyListIfAllSearchTermsAreEmpty() { + List patients = patientDao.getSimilarPatientsUsingLuceneSearch("", "", "c36006e5-9fbb-4f20-866b-0ece245615a1", 5); + + assertEquals(0, patients.size()); + } + + @Test + public void shouldReturnResultsIfOneFieldIsSet() { + List patients = patientDao.getSimilarPatientsUsingLuceneSearch("", "F", "c36006e5-9fbb-4f20-866b-0ece245615a1", 5); + + assertEquals(5, patients.size()); + } } diff --git a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImplTest.java b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImplTest.java index 5c77844fdb..2a6eba22c6 100644 --- a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImplTest.java +++ b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniPatientServiceImplTest.java @@ -1,5 +1,6 @@ package org.bahmni.module.bahmnicore.service.impl; +import org.bahmni.module.bahmnicore.contract.patient.PatientSearchParameters; import org.bahmni.module.bahmnicore.contract.patient.response.PatientConfigResponse; import org.bahmni.module.bahmnicore.dao.PatientDao; import org.junit.Before; @@ -9,12 +10,16 @@ import org.openmrs.PersonAttributeType; import org.openmrs.api.ConceptService; import org.openmrs.api.PersonService; +import org.openmrs.module.webservices.rest.web.RequestContext; +import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import static junit.framework.Assert.assertEquals; -import static org.mockito.Mockito.anyInt; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -25,6 +30,8 @@ public class BahmniPatientServiceImplTest { @Mock private ConceptService conceptService; @Mock + RequestContext requestContext; + @Mock private PatientDao patientDao; private BahmniPatientServiceImpl bahmniPatientService; @@ -67,4 +74,18 @@ public void shouldGetPatientByPartialIdentifier() throws Exception { bahmniPatientService.get("partial_identifier", shouldMatchExactPatientId); verify(patientDao).getPatients("partial_identifier", shouldMatchExactPatientId); } + + @Test + 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"); + patientSearchParameters.setLoginLocationUuid("someUUid"); + + bahmniPatientService.searchSimilarPatients(patientSearchParameters); + verify(patientDao).getSimilarPatientsUsingLuceneSearch("John", "M", "someUUid", 5); + } } diff --git a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchController.java b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchController.java index a3d71c703a..9885526517 100644 --- a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchController.java +++ b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchController.java @@ -66,4 +66,19 @@ public ResponseEntity> luceneSearch(HttpServletReq return new ResponseEntity(RestUtil.wrapErrorResponse(e, e.getMessage()), HttpStatus.BAD_REQUEST); } } + + @RequestMapping(value="similar", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity> searchSimilarPerson(HttpServletRequest request, + HttpServletResponse response) throws ResponseException{ + RequestContext requestContext = RestUtil.getRequestContext(request, response); + PatientSearchParameters searchParameters = new PatientSearchParameters(requestContext); + try { + List patients = bahmniPatientService.searchSimilarPatients(searchParameters); + AlreadyPaged alreadyPaged = new AlreadyPaged(requestContext, patients, false); + return new ResponseEntity(alreadyPaged, HttpStatus.OK); + }catch (IllegalArgumentException e){ + return new ResponseEntity(RestUtil.wrapErrorResponse(e, e.getMessage()), HttpStatus.BAD_REQUEST); + } + } } diff --git a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchControllerIT.java b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchControllerIT.java new file mode 100644 index 0000000000..a64bd1bb2f --- /dev/null +++ b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/search/BahmniPatientSearchControllerIT.java @@ -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")); + } +} \ No newline at end of file