diff --git a/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java b/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java index ea0c5017fa..bff45f06ba 100644 --- a/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java +++ b/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java @@ -224,8 +224,9 @@ public PatientType readPatientType(String idString) { public List getPatientTypes(String description) throws LIMSRuntimeException { List list = new Vector<>(); try { - String sql = "from patientType l where upper(l.description) like upper(:param) order by" - + " upper(l.description)"; + String sql = "from PatientType l where upper(l.description) like upper(:param) order by " + + "upper(l.description)"; + org.hibernate.query.Query query = entityManager.unwrap(Session.class).createQuery(sql); query.setParameter("param", description + "%"); diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index 58b807c5eb..1abaad601e 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -2,14 +2,19 @@ import static org.mockito.Mockito.mock; +import ca.uhn.fhir.context.FhirContext; import com.fasterxml.jackson.annotation.JsonInclude; import java.util.ArrayList; import java.util.List; import lombok.NonNull; +import org.apache.http.impl.client.CloseableHttpClient; import org.openelisglobal.audittrail.dao.AuditTrailService; import org.openelisglobal.common.services.IStatusService; import org.openelisglobal.common.util.Versioning; +import org.openelisglobal.dataexchange.fhir.FhirConfig; +import org.openelisglobal.dataexchange.fhir.FhirUtil; import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService; +import org.openelisglobal.dataexchange.fhir.service.FhirTransformService; import org.openelisglobal.dataexchange.service.order.ElectronicOrderService; import org.openelisglobal.externalconnections.service.BasicAuthenticationDataService; import org.openelisglobal.externalconnections.service.ExternalConnectionService; @@ -25,7 +30,6 @@ import org.openelisglobal.program.service.ImmunohistochemistrySampleService; import org.openelisglobal.program.service.PathologySampleService; import org.openelisglobal.program.service.ProgramSampleService; -import org.openelisglobal.provider.service.ProviderService; import org.openelisglobal.referral.service.ReferralResultService; import org.openelisglobal.referral.service.ReferralService; import org.openelisglobal.referral.service.ReferralSetService; @@ -77,9 +81,10 @@ "org.openelisglobal.view", "org.openelisglobal.search.service", "org.openelisglobal.sample", "org.openelisglobal.sampleitem.", "org.openelisglobal.analysis", "org.openelisglobal.result.service", "org.openelisglobal.result.daoimpl", "org.openelisglobal.resultlimit", "org.openelisglobal.resultlimits", - "org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", + "org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", "org.openelisglobal.provider", "org.openelisglobal.role", }, excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"), + @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.provider.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.sample.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.config.*"), @@ -95,6 +100,36 @@ public FhirPersistanceService fhirPesistence() { return mock(FhirPersistanceService.class); } + @Bean() + @Profile("test") + public FhirUtil fhirUtil() { + return mock(FhirUtil.class); + } + + @Bean() + @Profile("test") + public FhirConfig fhirConfig() { + return mock(FhirConfig.class); + } + + @Bean() + @Profile("test") + public CloseableHttpClient closeableHttpClient() { + return mock(CloseableHttpClient.class); + } + + @Bean() + @Profile("test") + public FhirContext fhirContext() { + return mock(FhirContext.class); + } + + @Bean() + @Profile("test") + public FhirTransformService fhirTransformServicehirTransformService() { + return mock(FhirTransformService.class); + } + @Bean() @Profile("test") public LocalizationServiceImpl localise() { @@ -167,12 +202,6 @@ public TestSectionService testSectionService() { return mock(TestSectionService.class); } - @Bean() - @Profile("test") - public ProviderService providerService() { - return mock(ProviderService.class); - } - @Bean() @Profile("test") public UserRoleService userRoleService() { diff --git a/src/test/java/org/openelisglobal/patient/PatientServiceTest.java b/src/test/java/org/openelisglobal/patient/PatientServiceTest.java index 960db97bb0..71ec856496 100644 --- a/src/test/java/org/openelisglobal/patient/PatientServiceTest.java +++ b/src/test/java/org/openelisglobal/patient/PatientServiceTest.java @@ -50,7 +50,6 @@ public void init() throws Exception { patientService.deleteAll(patientService.getAll()); personService.deleteAll(personService.getAll()); patientTypeService.deleteAll(patientTypeService.getAll()); - } @After @@ -62,41 +61,6 @@ public void tearDown() { patientTypeService.deleteAll(patientTypeService.getAll()); } - @Test - public void createPatient_shouldCreateNewPatient() throws Exception { - String firstName = "John"; - String lastname = "Doe"; - String dob = "12/12/1992"; - String gender = "M"; - Patient pat = createPatient(firstName, lastname, dob, gender); - - Assert.assertEquals(0, patientService.getAllPatients().size()); - - String patientId = patientService.insert(pat); - Patient savedPatient = patientService.get(patientId); - - Assert.assertEquals(1, patientService.getAllPatients().size()); - Assert.assertEquals(firstName, savedPatient.getPerson().getFirstName()); - Assert.assertEquals(lastname, savedPatient.getPerson().getLastName()); - Assert.assertEquals(gender, savedPatient.getGender()); - } - - @Test - public void getData_shouldCopyPropertiesFromDatabase() throws Exception { - String firstName = "John"; - String lastname = "Doe"; - String dob = "12/12/1992"; - String gender = "M"; - Patient patient = createPatient(firstName, lastname, dob, gender); - String patientId = patientService.insert(patient); - - Patient savedPatient = new Patient(); - savedPatient.setId(patientId); - patientService.getData(savedPatient); - - Assert.assertEquals(gender, savedPatient.getGender()); - } - @Test public void getSubjectNumber_shouldReturnSubjectNumber() throws Exception { String firstName = "John"; @@ -504,6 +468,25 @@ public void getPatientForGuid_shouldReturnPatientForGuid() throws Exception { Assert.assertEquals(gender, savedPatient.getGender()); } + @Test + public void createPatient_shouldCreateNewPatient() throws Exception { + String firstName = "John"; + String lastname = "Doe"; + String dob = "12/12/1992"; + String gender = "M"; + Patient pat = createPatient(firstName, lastname, dob, gender); + + Assert.assertEquals(0, patientService.getAllPatients().size()); + + String patientId = patientService.insert(pat); + Patient savedPatient = patientService.get(patientId); + + Assert.assertEquals(1, patientService.getAllPatients().size()); + Assert.assertEquals(firstName, savedPatient.getPerson().getFirstName()); + Assert.assertEquals(lastname, savedPatient.getPerson().getLastName()); + Assert.assertEquals(gender, savedPatient.getGender()); + } + @Test public void getData_shouldCopyPropertiesFromDatabaseById() throws Exception { String firstName = "John"; diff --git a/src/test/java/org/openelisglobal/patient/PatientTypeServiceTest.java b/src/test/java/org/openelisglobal/patient/PatientTypeServiceTest.java new file mode 100644 index 0000000000..fab265d0d2 --- /dev/null +++ b/src/test/java/org/openelisglobal/patient/PatientTypeServiceTest.java @@ -0,0 +1,184 @@ +package org.openelisglobal.patient; + +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.util.ConfigurationProperties; +import org.openelisglobal.patient.service.PatientTypeService; +import org.openelisglobal.patienttype.valueholder.PatientType; +import org.springframework.beans.factory.annotation.Autowired; + +public class PatientTypeServiceTest extends BaseWebContextSensitiveTest { + + @Autowired + PatientTypeService typeService; + + @Before + public void init() { + typeService.deleteAll(typeService.getAll()); + } + + @After + public void tearDown() { + typeService.deleteAll(typeService.getAll()); + } + + @Test + public void createPatientType_shouldCreateNewPatientType() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + + Assert.assertEquals(1, typeService.getAllPatientTypes().size()); + Assert.assertEquals("Test Type Description", savedPatientType.getDescription()); + Assert.assertEquals("Test Type", savedPatientType.getType()); + } + + @Test + public void UpdatePatientType_shouldReturnUpdatedPatientType() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + savedPatientType.setType("Test2 Type"); + typeService.save(savedPatientType); + + Assert.assertEquals(1, typeService.getAllPatientTypes().size()); + Assert.assertEquals("Test Type Description", savedPatientType.getDescription()); + Assert.assertEquals("Test2 Type", savedPatientType.getType()); + } + + @Test + public void deletePatientType_shouldDeletePatientType() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + typeService.delete(savedPatientType); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + } + + @Test + public void getallPatientTypes_shouldReturnPatientType() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + + Assert.assertEquals(1, typeService.getAllPatientTypes().size()); + } + + @Test + public void getTotalPatientTypeCount_shouldReturnTotalPatientTypeCount() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + + Assert.assertEquals(1, typeService.getTotalPatientTypeCount().longValue()); + } + + @Test + public void getPatientTypes_shouldReturnListOfFilteredPatientTypes() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + + PatientType patientType2 = new PatientType(); + patientType2.setDescription("Test2 Type Description"); + patientType2.setType("Test2 Type"); + + String patientTypeId2 = typeService.insert(patientType2); + Assert.assertEquals(2, typeService.getAll().size()); + + List savedPatientTypes = typeService.getPatientTypes("Test2"); + + Assert.assertEquals(1, savedPatientTypes.size()); + } + + @Test + public void getPageOfPatientType_shouldReturnPatientTypes() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.get(patientTypeId); + + PatientType patientType2 = new PatientType(); + patientType2.setDescription("Test2 Type Description"); + patientType2.setType("Test2 Type"); + + String patientTypeId2 = typeService.insert(patientType2); + Assert.assertEquals(2, typeService.getAll().size()); + + List patientTypesPage = typeService.getPageOfPatientType(1); + + int expectedPageSize = Integer + .parseInt(ConfigurationProperties.getInstance().getPropertyValue("page.defaultPageSize")); + + Assert.assertTrue(patientTypesPage.size() <= expectedPageSize); + + if (expectedPageSize >= 2) { + Assert.assertTrue(patientTypesPage.stream().anyMatch(p -> p.getType().equals("Test Type"))); + Assert.assertTrue(patientTypesPage.stream().anyMatch(p -> p.getType().equals("Test2 Type"))); + } + } + + @Test + public void getData_shouldCopyPropertiesFromDatabase() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + String patientTypeId = typeService.insert(patientType); + + PatientType patientType2 = new PatientType(); + patientType2.setId(patientTypeId); + typeService.getData(patientType2); + + Assert.assertEquals("Test Type", patientType2.getType()); + } + + @Test + public void getallPatientTypeByName_shouldReturnPatientType() throws Exception { + PatientType patientType = new PatientType(); + patientType.setDescription("Test Type Description"); + patientType.setType("Test Type"); + + Assert.assertEquals(0, typeService.getAllPatientTypes().size()); + + String patientTypeId = typeService.insert(patientType); + PatientType savedPatientType = typeService.getPatientTypeByName(patientType); + + Assert.assertEquals("Test Type", savedPatientType.getType()); + } +}