Skip to content

Commit

Permalink
Merge pull request #1150 from rahul6603/service-and-dao-impl
Browse files Browse the repository at this point in the history
Add new implementations for the search results service and the DAO and modify the existing implementations
  • Loading branch information
mozzy11 authored Jul 9, 2024
2 parents 5ef1724 + 30d1365 commit 11d4faa
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 18 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/openelisglobal/sample/dao/SearchResultsDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@

public interface SearchResultsDAO {

String FIRST_NAME_PARAM = "firstName";
String LAST_NAME_PARAM = "lastName";
String NATIONAL_ID_PARAM = "nationalID";
String EXTERNAL_ID_PARAM = "externalID";
String ST_NUMBER_PARAM = "stNumber";
String SUBJECT_NUMBER_PARAM = "subjectNumber";
String ID_PARAM = "id";
String GUID = "guid";
String DATE_OF_BIRTH = "dateOfBirth";
String GENDER = "gender";

String ID_TYPE_FOR_ST = "stNumberId";
String ID_TYPE_FOR_SUBJECT_NUMBER = "subjectNumberId";
String ID_TYPE_FOR_GUID = "guidId";

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,17 @@
import org.openelisglobal.common.provider.query.PatientSearchResults;
import org.openelisglobal.patientidentitytype.util.PatientIdentityTypeMap;
import org.openelisglobal.sample.dao.SearchResultsDAO;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class SearchResultsDAOImp implements SearchResultsDAO {
@Primary
public class DBSearchResultsDAOImpl implements SearchResultsDAO {

@PersistenceContext
EntityManager entityManager;

private static final String FIRST_NAME_PARAM = "firstName";
private static final String LAST_NAME_PARAM = "lastName";
private static final String NATIONAL_ID_PARAM = "nationalID";
private static final String EXTERNAL_ID_PARAM = "externalID";
private static final String ST_NUMBER_PARAM = "stNumber";
private static final String SUBJECT_NUMBER_PARAM = "subjectNumber";
private static final String ID_PARAM = "id";
private static final String GUID = "guid";
private static final String DATE_OF_BIRTH = "dateOfBirth";
private static final String GENDER = "gender";

private static final String ID_TYPE_FOR_ST = "stNumberId";
private static final String ID_TYPE_FOR_SUBJECT_NUMBER = "subjectNumberId";
private static final String ID_TYPE_FOR_GUID = "guidId";

@Override
@SuppressWarnings("rawtypes")
@Transactional
Expand Down
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import org.openelisglobal.common.provider.query.PatientSearchResults;
import org.openelisglobal.sample.dao.SearchResultsDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SearchResultsServiceImpl implements SearchResultsService {
@Primary
public class DBSearchResultsServiceImpl implements SearchResultsService {

@Autowired
SearchResultsDAO searchResultsDAO;
Expand Down
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);
}
}
3 changes: 2 additions & 1 deletion src/test/java/org/openelisglobal/AppTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"org.openelisglobal.menu.service", "org.openelisglobal.menu.daoimpl", "org.openelisglobal.login.daoimpl",
"org.openelisglobal.systemusermodule.service", "org.openelisglobal.rolemodule.service",
"org.openelisglobal.systemusermodule.daoimpl", "org.openelisglobal.systemusermodule.service",
"org.openelisglobal.login.service", "org.openelisglobal.view", }, excludeFilters = {
"org.openelisglobal.login.service", "org.openelisglobal.view", "org.openelisglobal.search.service",
"org.openelisglobal.sample.daoimpl", }, excludeFilters = {
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.config.*"),
Expand Down
147 changes: 147 additions & 0 deletions src/test/java/org/openelisglobal/search/SearchResultsServiceTest.java
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;
}

}

0 comments on commit 11d4faa

Please sign in to comment.