-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1150 from rahul6603/service-and-dao-impl
Add new implementations for the search results service and the DAO and modify the existing implementations
- Loading branch information
Showing
7 changed files
with
249 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/openelisglobal/sample/daoimpl/LuceneSearchResultsDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.openelisglobal.sample.daoimpl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.transaction.Transactional; | ||
import org.openelisglobal.common.exception.LIMSRuntimeException; | ||
import org.openelisglobal.common.provider.query.PatientSearchResults; | ||
import org.openelisglobal.sample.dao.SearchResultsDAO; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class LuceneSearchResultsDAOImpl implements SearchResultsDAO { | ||
|
||
@Override | ||
@Transactional | ||
public List<PatientSearchResults> getSearchResults(String lastName, String firstName, String STNumber, | ||
String subjectNumber, String nationalID, String externalID, String patientID, String guid, | ||
String dateOfBirth, String gender) throws LIMSRuntimeException { | ||
|
||
List<PatientSearchResults> patientSearchResultsList = new ArrayList<>(); | ||
return patientSearchResultsList; | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public List<PatientSearchResults> getSearchResultsByGUID(String lastName, String firstName, String STNumber, | ||
String subjectNumber, String nationalID, String externalID, String patientID, String guid, | ||
String dateOfBirth, String gender) throws LIMSRuntimeException { | ||
|
||
List<PatientSearchResults> patientSearchResultsList = new ArrayList<>(); | ||
return patientSearchResultsList; | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public List<PatientSearchResults> getSearchResultsExact(String lastName, String firstName, String STNumber, | ||
String subjectNumber, String nationalID, String externalID, String patientID, String guid, | ||
String dateOfBirth, String gender) throws LIMSRuntimeException { | ||
|
||
List<PatientSearchResults> patientSearchResultsList = new ArrayList<>(); | ||
return patientSearchResultsList; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/org/openelisglobal/search/service/LuceneSearchResultsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.openelisglobal.search.service; | ||
|
||
import java.util.List; | ||
import javax.transaction.Transactional; | ||
import org.openelisglobal.common.provider.query.PatientSearchResults; | ||
import org.openelisglobal.sample.dao.SearchResultsDAO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class LuceneSearchResultsServiceImpl implements SearchResultsService { | ||
|
||
@Autowired | ||
@Qualifier("luceneSearchResultsDAOImpl") | ||
SearchResultsDAO searchResultsDAO; | ||
|
||
@Override | ||
@Transactional | ||
public List<PatientSearchResults> getSearchResults(String lastName, String firstName, String STNumber, | ||
String subjectNumber, String nationalID, String externalID, String patientID, String guid, | ||
String dateOfBirth, String gender) { | ||
return searchResultsDAO.getSearchResults(lastName, firstName, STNumber, subjectNumber, nationalID, externalID, | ||
patientID, guid, dateOfBirth, gender); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public List<PatientSearchResults> getSearchResultsExact(String lastName, String firstName, String STNumber, | ||
String subjectNumber, String nationalID, String externalID, String patientID, String guid, | ||
String dateOfBirth, String gender) { | ||
return searchResultsDAO.getSearchResultsExact(lastName, firstName, STNumber, subjectNumber, nationalID, | ||
externalID, patientID, guid, dateOfBirth, gender); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
src/test/java/org/openelisglobal/search/SearchResultsServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package org.openelisglobal.search; | ||
|
||
import java.sql.Timestamp; | ||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openelisglobal.BaseWebContextSensitiveTest; | ||
import org.openelisglobal.common.provider.query.PatientSearchResults; | ||
import org.openelisglobal.patient.service.PatientService; | ||
import org.openelisglobal.patient.valueholder.Patient; | ||
import org.openelisglobal.person.service.PersonService; | ||
import org.openelisglobal.person.valueholder.Person; | ||
import org.openelisglobal.search.service.SearchResultsService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
public class SearchResultsServiceTest extends BaseWebContextSensitiveTest { | ||
|
||
@Autowired | ||
PatientService patientService; | ||
|
||
@Autowired | ||
PersonService personService; | ||
|
||
@Autowired | ||
SearchResultsService DBSearchResultsServiceImpl; | ||
|
||
@Autowired | ||
@Qualifier("luceneSearchResultsServiceImpl") | ||
SearchResultsService luceneSearchResultsServiceImpl; | ||
|
||
@Before | ||
public void init() throws Exception { | ||
patientService.deleteAll(patientService.getAll()); | ||
personService.deleteAll(personService.getAll()); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
patientService.deleteAll(patientService.getAll()); | ||
personService.deleteAll(personService.getAll()); | ||
} | ||
|
||
@Test | ||
public void getSearchResults_shouldGetSearchResultsFromDB() throws Exception { | ||
String firstName = "John"; | ||
String lastname = "Doe"; | ||
String dob = "12/12/1992"; | ||
String gender = "M"; | ||
Patient pat = createPatient(firstName, lastname, dob, gender); | ||
String patientId = patientService.insert(pat); | ||
|
||
String searchFirstName = "Jo"; | ||
String searchLastName = "Do"; | ||
|
||
List<PatientSearchResults> searchResults = DBSearchResultsServiceImpl.getSearchResults(searchLastName, | ||
searchFirstName, null, null, null, null, null, null, dob, gender); | ||
|
||
Assert.assertEquals(1, searchResults.size()); | ||
PatientSearchResults result = searchResults.get(0); | ||
Assert.assertEquals(patientId, result.getPatientID()); | ||
Assert.assertEquals(firstName, result.getFirstName()); | ||
Assert.assertEquals(lastname, result.getLastName()); | ||
Assert.assertEquals(dob, result.getBirthdate()); | ||
} | ||
|
||
@Test | ||
public void getSearchResultsExact_shouldGetExactSearchResultsFromDB() throws Exception { | ||
String firstName = "John"; | ||
String lastname = "Doe"; | ||
String dob = "12/12/1992"; | ||
String gender = "M"; | ||
Patient pat = createPatient(firstName, lastname, dob, gender); | ||
String patientId = patientService.insert(pat); | ||
|
||
List<PatientSearchResults> searchResults = DBSearchResultsServiceImpl.getSearchResultsExact(lastname, firstName, | ||
null, null, null, null, null, null, dob, gender); | ||
|
||
Assert.assertEquals(1, searchResults.size()); | ||
PatientSearchResults result = searchResults.get(0); | ||
Assert.assertEquals(patientId, result.getPatientID()); | ||
Assert.assertEquals(firstName, result.getFirstName()); | ||
Assert.assertEquals(lastname, result.getLastName()); | ||
Assert.assertEquals(dob, result.getBirthdate()); | ||
} | ||
|
||
@Test | ||
public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes() throws Exception { | ||
String firstName = "John"; | ||
String lastname = "Doe"; | ||
String dob = "12/12/1992"; | ||
String gender = "M"; | ||
Patient pat = createPatient(firstName, lastname, dob, gender); | ||
String patientId = patientService.insert(pat); | ||
|
||
List<PatientSearchResults> searchResults = luceneSearchResultsServiceImpl.getSearchResults(lastname, firstName, | ||
null, null, null, null, null, null, dob, gender); | ||
|
||
// The search results are currently expected to be empty because the method has | ||
// not been implemented yet | ||
Assert.assertEquals(0, searchResults.size()); | ||
} | ||
|
||
@Test | ||
public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() throws Exception { | ||
String firstName = "John"; | ||
String lastname = "Doe"; | ||
String dob = "12/12/1992"; | ||
String gender = "M"; | ||
Patient pat = createPatient(firstName, lastname, dob, gender); | ||
String patientId = patientService.insert(pat); | ||
|
||
List<PatientSearchResults> searchResults = luceneSearchResultsServiceImpl.getSearchResultsExact(lastname, | ||
firstName, null, null, null, null, null, null, dob, gender); | ||
|
||
// The search results are currently expected to be empty because the method has | ||
// not been implemented yet | ||
Assert.assertEquals(0, searchResults.size()); | ||
} | ||
|
||
private Patient createPatient(String firstName, String LastName, String birthDate, String gender) | ||
throws ParseException { | ||
Person person = new Person(); | ||
person.setFirstName(firstName); | ||
person.setLastName(LastName); | ||
personService.save(person); | ||
|
||
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); | ||
Date date = dateFormat.parse(birthDate); | ||
long time = date.getTime(); | ||
Timestamp dob = new Timestamp(time); | ||
|
||
Patient pat = new Patient(); | ||
pat.setPerson(person); | ||
pat.setBirthDate(dob); | ||
pat.setGender(gender); | ||
|
||
return pat; | ||
} | ||
|
||
} |