From a2186199db1148aa55d8e4d57d1b2c6dcd196b8c Mon Sep 17 00:00:00 2001 From: josephbate Date: Wed, 6 Nov 2024 16:20:57 +0300 Subject: [PATCH] added more test for patientService and patientTypeService --- .../daoimpl/PatientTypeDAOImpl.java | 3 +- .../org/openelisglobal/AppTestConfig.java | 47 +- .../patient/PatientServiceTest.java | 444 ------------------ .../patient/PatientTypeServiceTest.java | 186 ++++++++ 4 files changed, 227 insertions(+), 453 deletions(-) create mode 100644 src/test/java/org/openelisglobal/patient/PatientTypeServiceTest.java diff --git a/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java b/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java index ea0c5017fa..a76d8963a6 100644 --- a/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java +++ b/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java @@ -224,8 +224,7 @@ 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..c8a2eb3a33 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -3,13 +3,21 @@ import static org.mockito.Mockito.mock; import com.fasterxml.jackson.annotation.JsonInclude; + +import ca.uhn.fhir.context.FhirContext; + 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; @@ -77,9 +85,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 +104,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 +206,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..0930cdd2ec 100644 --- a/src/test/java/org/openelisglobal/patient/PatientServiceTest.java +++ b/src/test/java/org/openelisglobal/patient/PatientServiceTest.java @@ -18,9 +18,6 @@ import org.openelisglobal.patient.service.PatientService; import org.openelisglobal.patient.service.PatientTypeService; import org.openelisglobal.patient.valueholder.Patient; -import org.openelisglobal.patientidentity.service.PatientIdentityService; -import org.openelisglobal.patientidentity.valueholder.PatientIdentity; -import org.openelisglobal.patientidentitytype.service.PatientIdentityTypeService; import org.openelisglobal.patienttype.valueholder.PatientType; import org.openelisglobal.person.service.PersonService; import org.openelisglobal.person.valueholder.Person; @@ -37,16 +34,8 @@ public class PatientServiceTest extends BaseWebContextSensitiveTest { @Autowired PersonService personService; - @Autowired - PatientIdentityTypeService identityTypeService; - - @Autowired - PatientIdentityService identityService; - @Before public void init() throws Exception { - // identityTypeService.deleteAll(identityTypeService.getAll()); - identityService.deleteAll(identityService.getAll()); patientService.deleteAll(patientService.getAll()); personService.deleteAll(personService.getAll()); patientTypeService.deleteAll(patientTypeService.getAll()); @@ -55,8 +44,6 @@ public void init() throws Exception { @After public void tearDown() { - // identityTypeService.deleteAll(identityTypeService.getAll()); - identityService.deleteAll(identityService.getAll()); patientService.deleteAll(patientService.getAll()); personService.deleteAll(personService.getAll()); patientTypeService.deleteAll(patientTypeService.getAll()); @@ -97,413 +84,6 @@ public void getData_shouldCopyPropertiesFromDatabase() throws Exception { Assert.assertEquals(gender, savedPatient.getGender()); } - @Test - public void getSubjectNumber_shouldReturnSubjectNumber() 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); - - String typeID = identityTypeService.getNamedIdentityType("SUBJECT").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("334-422-A"); - identityService.insert(patientIdentity); - - Assert.assertEquals("334-422-A", patientService.getSubjectNumber(patient)); - } - - @Test - public void getIdentityList_shouldReturnIdentityList() 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); - - String typeID = identityTypeService.getNamedIdentityType("AKA").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("BigMan"); - identityService.insert(patientIdentity); - - String typeID2 = identityTypeService.getNamedIdentityType("GUID").getId(); - - PatientIdentity patientIdentity2 = new PatientIdentity(); - patientIdentity2.setIdentityTypeId(typeID2); - patientIdentity2.setPatientId(patientId); - patientIdentity2.setIdentityData("EA400A1"); - identityService.insert(patientIdentity2); - - Assert.assertEquals(2, patientService.getIdentityList(patient).size()); - } - - @Test - public void getNationality_shouldReturnNationality() 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); - - String typeID = identityTypeService.getNamedIdentityType("NATIONALITY").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("Ugandan"); - identityService.insert(patientIdentity); - - Assert.assertEquals("Ugandan", patientService.getNationality(patient)); - } - - @Test - public void getOtherNationality_shouldReturnOtherNationality() 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); - - String typeID = identityTypeService.getNamedIdentityType("OTHER NATIONALITY").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("USA"); - identityService.insert(patientIdentity); - - Assert.assertEquals("USA", patientService.getOtherNationality(patient)); - } - - @Test - public void getMother_shouldReturnMother() 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); - - String typeID = identityTypeService.getNamedIdentityType("MOTHER").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("Jackie Moore"); - identityService.insert(patientIdentity); - - Assert.assertEquals("Jackie Moore", patientService.getMother(patient)); - } - - @Test - public void getMothersInitial_shouldReturnMothersInitial() 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); - - String typeID = identityTypeService.getNamedIdentityType("MOTHERS_INITIAL").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("Jackie Moore"); - identityService.insert(patientIdentity); - - Assert.assertEquals("Jackie Moore", patientService.getMothersInitial(patient)); - } - - @Test - public void getInsurance_shouldReturnInsurance() 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); - - String typeID = identityTypeService.getNamedIdentityType("INSURANCE").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("US119a36"); - identityService.insert(patientIdentity); - - Assert.assertEquals("US119a36", patientService.getInsurance(patient)); - } - - @Test - public void getOccupation_shouldReturnOccupation() 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); - - String typeID = identityTypeService.getNamedIdentityType("OCCUPATION").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("Truck Driver"); - identityService.insert(patientIdentity); - - Assert.assertEquals("Truck Driver", patientService.getOccupation(patient)); - } - - @Test - public void getOrgSite_shouldReturnOrgSite() 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); - - String typeID = identityTypeService.getNamedIdentityType("ORG_SITE").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("orgSite"); - identityService.insert(patientIdentity); - - Assert.assertEquals("orgSite", patientService.getOrgSite(patient)); - } - - @Test - public void getEducation_shouldReturnEducationQualification() 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); - - String typeID = identityTypeService.getNamedIdentityType("EDUCATION").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("MBA Certificate"); - identityService.insert(patientIdentity); - - Assert.assertEquals("MBA Certificate", patientService.getEducation(patient)); - } - - @Test - public void getHealthDistrict_shouldReturnHealthDistrict() 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); - - String typeID = identityTypeService.getNamedIdentityType("HEALTH DISTRICT").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("Jinja"); - identityService.insert(patientIdentity); - - Assert.assertEquals("Jinja", patientService.getHealthDistrict(patient)); - } - - @Test - public void getHealthRegion_shouldReturnHealthRegion() 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); - - String typeID = identityTypeService.getNamedIdentityType("HEALTH REGION").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("EastAfrica"); - identityService.insert(patientIdentity); - - Assert.assertEquals("EastAfrica", patientService.getHealthRegion(patient)); - } - - @Test - public void getMaritalStatus_shouldReturnMaritalStatus() 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); - - String typeID = identityTypeService.getNamedIdentityType("MARITIAL").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("Married"); - identityService.insert(patientIdentity); - - Assert.assertEquals("Married", patientService.getMaritalStatus(patient)); - } - - @Test - public void getObNumber_shouldReturngObNumber() 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); - - String typeID = identityTypeService.getNamedIdentityType("OB_NUMBER").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("1234"); - identityService.insert(patientIdentity); - - Assert.assertEquals("1234", patientService.getObNumber(patient)); - } - - @Test - public void getPCNumber_shouldReturngPCNumber() 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); - - String typeID = identityTypeService.getNamedIdentityType("PC_NUMBER").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("1234"); - identityService.insert(patientIdentity); - - Assert.assertEquals("1234", patientService.getPCNumber(patient)); - } - - @Test - public void getSTNumber_shouldReturngSTNumber() 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); - - String typeID = identityTypeService.getNamedIdentityType("ST").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("1234"); - identityService.insert(patientIdentity); - - Assert.assertEquals("1234", patientService.getSTNumber(patient)); - } - - @Test - public void getAKA_shouldReturnAKA() 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); - - String typeID = identityTypeService.getNamedIdentityType("AKA").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("BigMan"); - identityService.insert(patientIdentity); - - Assert.assertEquals("BigMan", patientService.getAKA(patient)); - } - - @Test - public void getGUID_shouldReturnGUID() 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); - - String typeID = identityTypeService.getNamedIdentityType("GUID").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("EA400A1"); - identityService.insert(patientIdentity); - - Assert.assertEquals("EA400A1", patientService.getGUID(patient)); - } - - @Test - public void getGUID_shouldReturnEmptyStringForNullPatient() throws Exception { - Assert.assertEquals("", patientService.getGUID(null)); - } - - @Test - public void getGUID_shouldReturnEmptyStringForNullPatientWithNoGUID() 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); - - Assert.assertEquals("", patientService.getGUID(patient)); - } - - @Test - public void getPatientForGuid_shouldReturnPatientForGuid() 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); - - String typeID = identityTypeService.getNamedIdentityType("GUID").getId(); - - PatientIdentity patientIdentity = new PatientIdentity(); - patientIdentity.setIdentityTypeId(typeID); - patientIdentity.setPatientId(patientId); - patientIdentity.setIdentityData("EA400A1"); - identityService.insert(patientIdentity); - - Patient savedPatient = patientService.getPatientForGuid("EA400A1"); - - Assert.assertEquals(gender, savedPatient.getGender()); - } - @Test public void getData_shouldCopyPropertiesFromDatabaseById() throws Exception { String firstName = "John"; @@ -592,18 +172,6 @@ public void getAllPatients_shouldGetAllPatients() throws Exception { Assert.assertEquals(1, patientService.getAllPatients().size()); } - @Test - public void getByExternalId_shouldGetAllPatients() throws Exception { - String firstName = "John"; - String lastname = "Doe"; - String dob = "12/12/1992"; - String gender = "M"; - Patient patient = createPatient(firstName, lastname, dob, gender); - patient.setExternalId("432"); - patientService.insert(patient); - Assert.assertEquals(gender, patientService.getByExternalId("432").getGender()); - } - @Test public void getPatientByPerson_shouldReturnPatientByPerson() throws Exception { String firstName = "John"; @@ -934,18 +502,6 @@ public void getLocalizedGender_shouldReturnCorrectLocalizedGender() throws Excep Assert.assertEquals("MALE", localizedGender); } - @Test - public void getBirthdayForDisplay_shouldReturnBirthdayForDisplay() throws Exception { - String firstName = "Tayebwa"; - String lastName = "Noah"; - String dob = "01/01/2020"; - String gender = "M"; - Patient pat = createPatient(firstName, lastName, dob, gender); - pat.setBirthDateForDisplay("01/01/2020"); - - Assert.assertEquals(dob, patientService.getBirthdayForDisplay(pat)); - } - @Test public void getPageOfPatients_shouldReturnCorrectPatients() throws Exception { String firstName1 = "Josh"; 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..58ea5919eb --- /dev/null +++ b/src/test/java/org/openelisglobal/patient/PatientTypeServiceTest.java @@ -0,0 +1,186 @@ +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.patient.valueholder.Patient; +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()); + } +}