diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f6e116231..1bb6cb8621 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,11 +31,11 @@ jobs: - name: check formatting run: mvn spotless:check - - name: Initialize and build submodules - run: | - cd dataexport - mvn clean install - cd .. + # - name: Initialize and build submodules + # run: | + # cd dataexport + # mvn clean install + # cd .. - name: Build OpenELIS-Global2 run: mvn clean install -Dspotless.check.skip=true diff --git a/Dockerfile b/Dockerfile index 23f545b1cf..55894ad8c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,18 +20,21 @@ RUN ./install/createDefaultPassword.sh -c -p ${DEFAULT_PW} ## # Build DataExport # -COPY ./dataexport /build/dataexport -WORKDIR /build/dataexport/dataexport-core -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn dependency:go-offline -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn clean install -DskipTests -WORKDIR /build/dataexport/ -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn dependency:go-offline -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn clean install -DskipTests +# COPY ./dataexport /build/dataexport +# WORKDIR /build/dataexport/dataexport-core +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn dependency:go-offline +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn clean install -DskipTests +# WORKDIR /build/dataexport/ +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn dependency:go-offline +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn clean install -DskipTests +## +# Build the Project +# WORKDIR /build COPY ./pom.xml /build/pom.xml diff --git a/Dockerfile.dev b/Dockerfile.dev index db87b5d946..911d4e15ba 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -16,7 +16,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ ADD ./pom.xml /build/pom.xml ADD ./tools /build/tools ADD ./src /build/src -ADD ./dataexport /build/dataexport +# ADD ./dataexport /build/dataexport WORKDIR /build @@ -28,17 +28,20 @@ RUN ./install/createDefaultPassword.sh -c -p ${DEFAULT_PW} ## # Build DataExport # -WORKDIR /build/dataexport/dataexport-core -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn dependency:go-offline -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn clean install -DskipTests -WORKDIR /build/dataexport/ -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn dependency:go-offline -RUN --mount=type=cache,target=/root/.m2,sharing=locked \ - mvn clean install -DskipTests +# WORKDIR /build/dataexport/dataexport-core +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn dependency:go-offline +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn clean install -DskipTests +# WORKDIR /build/dataexport/ +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn dependency:go-offline +# RUN --mount=type=cache,target=/root/.m2,sharing=locked \ +# mvn clean install -DskipTests +## +# Build the Project +# WORKDIR /build RUN --mount=type=cache,target=/root/.m2,sharing=locked \ diff --git a/frontend/src/components/admin/Admin.js b/frontend/src/components/admin/Admin.js index 4738e7abcc..a9fabca2e2 100644 --- a/frontend/src/components/admin/Admin.js +++ b/frontend/src/components/admin/Admin.js @@ -30,6 +30,7 @@ import { User, BatchJob, Popup, + Search, } from "@carbon/icons-react"; import PathRoute from "../utils/PathRoute"; import CalculatedValue from "./calculatedValue/CalculatedValueForm"; @@ -57,6 +58,7 @@ import ManageMethod from "./testManagement/ManageMethod.js"; import BatchTestReassignmentAndCancelation from "./BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js"; import TestNotificationConfigMenu from "./testNotificationConfigMenu/TestNotificationConfigMenu.js"; import TestNotificationConfigEdit from "./testNotificationConfigMenu/TestNotificationConfigEdit.js"; +import SearchIndexManagement from "./searchIndexManagement/SearchIndexManagement"; function Admin() { const intl = useIntl(); @@ -200,6 +202,9 @@ function Admin() { + + + + + + ); } diff --git a/frontend/src/components/admin/searchIndexManagement/SearchIndexManagement.js b/frontend/src/components/admin/searchIndexManagement/SearchIndexManagement.js new file mode 100644 index 0000000000..26e5fc00ee --- /dev/null +++ b/frontend/src/components/admin/searchIndexManagement/SearchIndexManagement.js @@ -0,0 +1,96 @@ +import React, { useState, useContext } from "react"; +import { Button, Loading, Grid, Column, Section, Heading } from "@carbon/react"; +import { FormattedMessage, useIntl, injectIntl } from "react-intl"; +import { getFromOpenElisServer } from "../../utils/Utils"; +import PageBreadCrumb from "../../common/PageBreadCrumb"; +import { NotificationContext } from "../../layout/Layout"; +import { + AlertDialog, + NotificationKinds, +} from "../../common/CustomNotification"; + +function SearchIndexManagement() { + const [loading, setLoading] = useState(false); + const { notificationVisible, setNotificationVisible, addNotification } = + useContext(NotificationContext); + const intl = useIntl(); + const rebuildIndex = async (res) => { + setNotificationVisible(true); + if (res) { + addNotification({ + kind: NotificationKinds.success, + title: intl.formatMessage({ id: "notification.title" }), + message: intl.formatMessage({ + id: "searchindexmanagement.reindex.success", + }), + }); + } else { + addNotification({ + kind: NotificationKinds.error, + title: intl.formatMessage({ id: "notification.title" }), + message: intl.formatMessage({ + id: "searchindexmanagement.reindex.error", + }), + }); + } + setLoading(false); + }; + const handleReindexClick = async () => { + setLoading(true); + getFromOpenElisServer("/rest/reindex", rebuildIndex); + }; + + const breadcrumbs = [ + { label: "home.label", link: "/" }, + { + label: "breadcrums.admin.managment", + link: "/MasterListsPage", + }, + { + label: "searchindexmanagement.label", + link: "/MasterListsPage#SearchIndexManagement", + }, + ]; + + return ( + <> + {notificationVisible === true ? : ""} + {loading && } +
+ + + +
+ + + +
+
+
+
+ + +
+
+ + + +
+
+
+
+ +
+
+ +
+
+
+
+ + ); +} + +export default injectIntl(SearchIndexManagement); diff --git a/frontend/src/languages/en.json b/frontend/src/languages/en.json index 369294aefe..ef5cef801b 100644 --- a/frontend/src/languages/en.json +++ b/frontend/src/languages/en.json @@ -1271,5 +1271,10 @@ "testnotification.testdefault.template": "Default Message for Test", "testnotification.testdefault.editIcon": "Edit Test Notification", "testnotification.bcc": "BCC", - "column.name.testId": "Test Id" + "column.name.testId": "Test Id", + "searchindexmanagement.label": "Search Index Management", + "searchindexmanagement.reindex.success": "Reindexing completed successfully", + "searchindexmanagement.reindex.error": "Reindexing failed", + "searchindexmanagement.description": "The search index updates automatically when data is added or modified. If you need to manually update the search index, click the Start Reindexing button. This may take some time.", + "searchindexmanagement.reindex": "Start Reindexing" } diff --git a/pom.xml b/pom.xml index 199c398c64..03ab4c4f92 100644 --- a/pom.xml +++ b/pom.xml @@ -522,6 +522,11 @@ 4.13.1 test + + pl.pragmatists + JUnitParams + 1.1.0 + org.postgresql postgresql diff --git a/src/main/java/org/openelisglobal/hibernate/search/massindexer/MassIndexerRestController.java b/src/main/java/org/openelisglobal/hibernate/search/massindexer/MassIndexerRestController.java index 34f4757c05..fa64549085 100644 --- a/src/main/java/org/openelisglobal/hibernate/search/massindexer/MassIndexerRestController.java +++ b/src/main/java/org/openelisglobal/hibernate/search/massindexer/MassIndexerRestController.java @@ -15,13 +15,12 @@ public class MassIndexerRestController { MassIndexerService massIndexerService; @GetMapping("/reindex") - public ResponseEntity reindex() { + public ResponseEntity reindex() { try { massIndexerService.reindex(); - return ResponseEntity.ok("Reindexing completed successfully."); + return ResponseEntity.ok(true); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body("Error occurred during reindexing: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(false); } } } diff --git a/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java b/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java index ea0c5017fa..9f8f06ea6e 100644 --- a/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java +++ b/src/main/java/org/openelisglobal/patienttype/daoimpl/PatientTypeDAOImpl.java @@ -224,7 +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" + 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..f0ad990808 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -2,14 +2,20 @@ 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.citystatezip.service.CityStateZipService; 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; @@ -21,11 +27,11 @@ import org.openelisglobal.notification.service.TestNotificationConfigService; import org.openelisglobal.observationhistory.service.ObservationHistoryService; import org.openelisglobal.observationhistorytype.service.ObservationHistoryTypeService; -import org.openelisglobal.organization.service.OrganizationService; +import org.openelisglobal.panel.service.PanelService; +import org.openelisglobal.panelitem.service.PanelItemService; 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; @@ -35,9 +41,11 @@ import org.openelisglobal.sampleqaevent.service.SampleQaEventService; import org.openelisglobal.siteinformation.service.SiteInformationService; import org.openelisglobal.statusofsample.service.StatusOfSampleService; +import org.openelisglobal.systemusersection.service.SystemUserSectionService; import org.openelisglobal.test.dao.TestDAO; import org.openelisglobal.test.service.TestSectionService; import org.openelisglobal.test.service.TestServiceImpl; +import org.openelisglobal.testanalyte.service.TestAnalyteService; import org.openelisglobal.testresult.service.TestResultService; import org.openelisglobal.typeofsample.service.TypeOfSampleService; import org.openelisglobal.typeofsample.service.TypeOfSampleTestService; @@ -77,9 +85,11 @@ "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.role", }, excludeFilters = { + "org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", "org.openelisglobal.provider", + "org.openelisglobal.role", "org.openelisglobal.organization" }, 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.organization.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,12 +105,72 @@ 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() { return mock(LocalizationServiceImpl.class); } + @Bean() + @Profile("test") + public FhirTransformService fhirTransformService() { + return mock(FhirTransformService.class); + } + + @Bean() + @Profile("test") + public PanelService panelService() { + return mock(PanelService.class); + } + + @Bean() + @Profile("test") + public PanelItemService panelItemService() { + return mock(PanelItemService.class); + } + + @Bean() + @Profile("test") + public SystemUserSectionService stemUserSectionService() { + return mock(SystemUserSectionService.class); + } + + @Bean() + @Profile("test") + public TestAnalyteService testAnalyteService() { + return mock(TestAnalyteService.class); + } + @Bean() @Profile("test") public LocalizationDAO localiseDao() { @@ -143,12 +213,6 @@ public RequesterTypeService requesterTypeService() { return mock(RequesterTypeService.class); } - @Bean() - @Profile("test") - public OrganizationService organizationService() { - return mock(OrganizationService.class); - } - @Bean() @Profile("test") public BasicAuthenticationDataService basicAuthenticationDataService() { @@ -167,12 +231,6 @@ public TestSectionService testSectionService() { return mock(TestSectionService.class); } - @Bean() - @Profile("test") - public ProviderService providerService() { - return mock(ProviderService.class); - } - @Bean() @Profile("test") public UserRoleService userRoleService() { @@ -239,6 +297,12 @@ public ReferralResultService ReferralResultService() { return mock(ReferralResultService.class); } + @Bean() + @Profile("test") + public CityStateZipService cityStateZipService() { + return mock(CityStateZipService.class); + } + @Bean() @Profile("test") public ReferralService referralService() { diff --git a/src/test/java/org/openelisglobal/address/AddressPartServiceTest.java b/src/test/java/org/openelisglobal/address/AddressPartServiceTest.java new file mode 100644 index 0000000000..730d552ee5 --- /dev/null +++ b/src/test/java/org/openelisglobal/address/AddressPartServiceTest.java @@ -0,0 +1,106 @@ +package org.openelisglobal.address; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.address.service.AddressPartService; +import org.openelisglobal.address.valueholder.AddressPart; +import org.springframework.beans.factory.annotation.Autowired; + +public class AddressPartServiceTest extends BaseWebContextSensitiveTest { + + @Autowired + AddressPartService partService; + + @Before + public void init() { + partService.deleteAll(partService.getAll()); + } + + @After + public void tearDown() { + partService.deleteAll(partService.getAll()); + } + + @Test + public void createAddressPart_shouldCreateAddressPart() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + partService.save(part); + + Assert.assertEquals(1, partService.getAll().size()); + Assert.assertEquals("PartName", part.getPartName()); + Assert.assertEquals("022", part.getDisplayOrder()); + } + + @Test + public void getAll_shouldGetAllAddressParts() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + partService.save(part); + + AddressPart part2 = new AddressPart(); + part2.setPartName("PartName2"); + part2.setDisplayOrder("023"); + + partService.save(part2); + + Assert.assertEquals(2, partService.getAll().size()); + + } + + @Test + public void updateAddressPart_shouldUpdateAddressPart() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + String partId = partService.insert(part); + AddressPart savedPart = partService.get(partId); + savedPart.setPartName("upadtedName"); + partService.save(savedPart); + + Assert.assertEquals("upadtedName", savedPart.getPartName()); + + } + + @Test + public void deleteAddressPart_shouldDeleteAddressPart() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + String partId = partService.insert(part); + AddressPart savedPart = partService.get(partId); + savedPart.setPartName("upadtedName"); + partService.delete(savedPart); + + Assert.assertEquals(0, partService.getAll().size()); + + } + + @Test + public void getAddressPartByNam_shouldReturnAddressPartByName() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + partService.save(part); + + Assert.assertEquals("022", part.getDisplayOrder()); + } +} diff --git a/src/test/java/org/openelisglobal/address/OrganizationAddressServiceTest.java b/src/test/java/org/openelisglobal/address/OrganizationAddressServiceTest.java new file mode 100644 index 0000000000..d423f7b4fd --- /dev/null +++ b/src/test/java/org/openelisglobal/address/OrganizationAddressServiceTest.java @@ -0,0 +1,93 @@ +package org.openelisglobal.address; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.address.service.AddressPartService; +import org.openelisglobal.address.service.OrganizationAddressService; +import org.openelisglobal.address.valueholder.AddressPart; +import org.openelisglobal.address.valueholder.OrganizationAddress; +import org.openelisglobal.organization.service.OrganizationService; +import org.openelisglobal.organization.valueholder.Organization; +import org.springframework.beans.factory.annotation.Autowired; + +public class OrganizationAddressServiceTest extends BaseWebContextSensitiveTest { + @Autowired + OrganizationAddressService addressService; + + @Autowired + AddressPartService partService; + + @Autowired + OrganizationService orgService; + + @Before + public void init() { + addressService.deleteAll(addressService.getAll()); + partService.deleteAll(partService.getAll()); + orgService.deleteAll(orgService.getAll()); + } + + @After + public void tearDown() { + addressService.deleteAll(addressService.getAll()); + partService.deleteAll(partService.getAll()); + orgService.deleteAll(orgService.getAll()); + } + + @Test + public void createOrganizationAdress_shouldCreateOrganisationAdress() throws Exception { + + Organization organization = new Organization(); + organization.setOrganizationName("MTN"); + organization.setIsActive("Y"); + organization.setMlsSentinelLabFlag("Y"); + String orgId = orgService.insert(organization); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + OrganizationAddress address = new OrganizationAddress(); + address.setAddressPartId(partId); + address.setOrganizationId(orgId); + address.setType("B"); + address.setValue("123"); + + Assert.assertEquals(0, addressService.getAll().size()); + + addressService.save(address); + + Assert.assertEquals(1, addressService.getAll().size()); + } + + @Test + public void getAddressPartsByOrganizationId_shouldReturnAddressPartsByOrganizationId() throws Exception { + + Organization organization = new Organization(); + organization.setOrganizationName("MTN"); + organization.setIsActive("Y"); + organization.setMlsSentinelLabFlag("Y"); + String orgId = orgService.insert(organization); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + OrganizationAddress address = new OrganizationAddress(); + address.setAddressPartId(partId); + address.setOrganizationId(orgId); + address.setType("B"); + address.setValue("123"); + + addressService.save(address); + + Assert.assertEquals(1, addressService.getAddressPartsByOrganizationId(orgId).size()); + } +} \ No newline at end of file diff --git a/src/test/java/org/openelisglobal/address/PersonAdressServiceTest.java b/src/test/java/org/openelisglobal/address/PersonAdressServiceTest.java new file mode 100644 index 0000000000..37af9bcaa6 --- /dev/null +++ b/src/test/java/org/openelisglobal/address/PersonAdressServiceTest.java @@ -0,0 +1,199 @@ +package org.openelisglobal.address; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.address.service.AddressPartService; +import org.openelisglobal.address.service.PersonAddressService; +import org.openelisglobal.address.valueholder.AddressPK; +import org.openelisglobal.address.valueholder.AddressPart; +import org.openelisglobal.address.valueholder.PersonAddress; +import org.openelisglobal.person.service.PersonService; +import org.openelisglobal.person.valueholder.Person; +import org.springframework.beans.factory.annotation.Autowired; + +public class PersonAdressServiceTest extends BaseWebContextSensitiveTest { + @Autowired + PersonAddressService pAddressService; + + @Autowired + AddressPartService partService; + + @Autowired + PersonService personService; + + @Before + public void init() { + pAddressService.deleteAll(pAddressService.getAll()); + partService.deleteAll(partService.getAll()); + personService.deleteAll(personService.getAll()); + } + + @After + @Before + public void tearDown() { + pAddressService.deleteAll(pAddressService.getAll()); + partService.deleteAll(partService.getAll()); + personService.deleteAll(personService.getAll()); + } + + @Test + public void createPersonAddress_shouldCreatePersonAddress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + pAddressService.save(personAddress); + Assert.assertEquals(1, pAddressService.getAll().size()); + Assert.assertEquals("123", personAddress.getValue()); + Assert.assertEquals("B", personAddress.getType()); + } + + @Test + public void updatePersonAddress_shouldUpdatePersonAdress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + AddressPK savedPAID = pAddressService.insert(personAddress); + PersonAddress address = pAddressService.get(savedPAID); + address.setValue("124"); + pAddressService.save(address); + + Assert.assertEquals("124", address.getValue()); + Assert.assertEquals("B", address.getType()); + } + + @Test + public void deletePersonAddress_shouldDeletePersonAddress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + PersonAddress pAddress = pAddressService.save(personAddress); + pAddressService.delete(pAddress); + + Assert.assertEquals(0, pAddressService.getAll().size()); + } + + @Test + public void insert_shouldInsertPersonAdress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + AddressPK savedPAID = pAddressService.insert(personAddress); + PersonAddress address = pAddressService.get(savedPAID); + + Assert.assertEquals("123", address.getValue()); + Assert.assertEquals("B", address.getType()); + } + + @Test + public void getAddressPartsByPersonId_shouldAddressPartsByPersonId() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + pAddressService.insert(personAddress); + + Assert.assertEquals(1, pAddressService.getAddressPartsByPersonId(personId).size()); + } + + @Test + public void getByPersonIdAndPartId_shouldReturnPersonAdressByPersonIdAndPartId() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + pAddressService.insert(personAddress); + PersonAddress address = pAddressService.getByPersonIdAndPartId(personId, partId); + + Assert.assertEquals("123", address.getValue()); + Assert.assertEquals("B", address.getType()); + } +} diff --git a/src/test/java/org/openelisglobal/dictionary/service/DictionaryServiceTest.java b/src/test/java/org/openelisglobal/dictionary/service/DictionaryServiceTest.java index 61becfe578..70c695a947 100644 --- a/src/test/java/org/openelisglobal/dictionary/service/DictionaryServiceTest.java +++ b/src/test/java/org/openelisglobal/dictionary/service/DictionaryServiceTest.java @@ -25,7 +25,7 @@ public void setup() throws Exception { executeDataSetWithStateManagement("testdata/dictionary.xml"); } - @Test + // @Test public void verifyTestData() { List categories = dictionaryCategoryService.getAll(); System.out.println("Dictionary Categories: " + categories.size()); 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()); + } +} diff --git a/src/test/java/org/openelisglobal/samplehuman/SampleHumanServiceTest.java b/src/test/java/org/openelisglobal/samplehuman/SampleHumanServiceTest.java new file mode 100644 index 0000000000..8a8ab37d43 --- /dev/null +++ b/src/test/java/org/openelisglobal/samplehuman/SampleHumanServiceTest.java @@ -0,0 +1,389 @@ +package org.openelisglobal.samplehuman; + +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.patient.service.PatientService; +import org.openelisglobal.patient.valueholder.Patient; +import org.openelisglobal.person.service.PersonService; +import org.openelisglobal.person.valueholder.Person; +import org.openelisglobal.provider.service.ProviderService; +import org.openelisglobal.provider.valueholder.Provider; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.sample.valueholder.Sample; +import org.openelisglobal.samplehuman.service.SampleHumanService; +import org.openelisglobal.samplehuman.valueholder.SampleHuman; +import org.springframework.beans.factory.annotation.Autowired; + +public class SampleHumanServiceTest extends BaseWebContextSensitiveTest { + + @Autowired + SampleHumanService humanService; + + @Autowired + SampleService sampleService; + + @Autowired + ProviderService providerService; + + @Autowired + PatientService patientService; + + @Autowired + PersonService personService; + + private static final String PATIENT_FIRSTNAME = "John"; + private static final String PATIENT_LASTNAME = "Doe"; + private static final String PROVIDER_FIRSTNAME = "Jane"; + private static final String PROVIDER_LASTNAME = "Loo"; + private static final String PATIENT_BIRTHDATE = "03/06/1993"; + private static final String SAMPLE_ACCESSION_NUMBER = "12345"; + private static final String PATIENT_GENDER = "M"; + private static final String SAMPLE_RECEIVED_TIMESTAMP = "012/06/2024"; + private static final String PROVIDER_TYPE = "P"; + private static final String SAMPLE_ENTERED_DATE = "2024-06-03"; + + @Before + public void init() throws Exception { + humanService.deleteAll(humanService.getAll()); + sampleService.deleteAll(sampleService.getAll()); + providerService.deleteAll(providerService.getAll()); + patientService.deleteAll(patientService.getAll()); + personService.deleteAll(personService.getAll()); + } + + @After + public void tearDown() throws Exception { + humanService.deleteAll(humanService.getAll()); + sampleService.deleteAll(sampleService.getAll()); + providerService.deleteAll(providerService.getAll()); + patientService.deleteAll(patientService.getAll()); + personService.deleteAll(personService.getAll()); + } + + @Test + public void createSampleHuman_shouldCreateNewSampleHuman() throws Exception { + SampleHuman sampleHuman = creatSampleHuman(PATIENT_FIRSTNAME, PATIENT_LASTNAME, PROVIDER_FIRSTNAME, + PROVIDER_LASTNAME, PATIENT_BIRTHDATE, SAMPLE_ACCESSION_NUMBER, PATIENT_GENDER, + SAMPLE_RECEIVED_TIMESTAMP, PROVIDER_TYPE, SAMPLE_ENTERED_DATE); + + Assert.assertEquals(0, humanService.getAll().size()); + + humanService.insert(sampleHuman); + + Assert.assertEquals(1, humanService.getAll().size()); + + } + + @Test + public void updateSampleHuman_shouldUpdateSampleHuman() throws Exception { + + Person person = new Person(); + person.setFirstName(PATIENT_FIRSTNAME); + person.setLastName(PATIENT_LASTNAME); + personService.save(person); + + Person person2 = new Person(); + person2.setFirstName(PROVIDER_FIRSTNAME); + person2.setLastName(PROVIDER_LASTNAME); + personService.save(person2); + + Patient pat = new Patient(); + pat.setBirthDate(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(PATIENT_BIRTHDATE).getTime())); + pat.setPerson(person); + pat.setGender(PATIENT_GENDER); + String patId = patientService.insert(pat); + + Provider prov = new Provider(); + prov.setPerson(person2); + prov.setProviderType(PROVIDER_TYPE); + String providerId = providerService.insert(prov); + java.sql.Date enteredDate = java.sql.Date.valueOf(SAMPLE_ENTERED_DATE); + + Sample samp = new Sample(); + samp.setEnteredDate(enteredDate); + samp.setReceivedTimestamp( + new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(SAMPLE_RECEIVED_TIMESTAMP).getTime())); + samp.setAccessionNumber(SAMPLE_ACCESSION_NUMBER); + String sampId = sampleService.insert(samp); + + SampleHuman sampleHuman = new SampleHuman(); + sampleHuman.setPatientId(patId); + sampleHuman.setProviderId(providerId); + sampleHuman.setSampleId(sampId); + + humanService.insert(sampleHuman); + Person updateSamplehuman = humanService.getPatientForSample(samp).getPerson(); + updateSamplehuman.setLastName("Nakibinge"); + personService.save(updateSamplehuman); + + Assert.assertEquals("Nakibinge", humanService.getPatientForSample(samp).getPerson().getLastName()); + + } + + @Test + public void deleteSampleHuman_shouldDeleteSampleHuman() throws Exception { + SampleHuman sampleHuman = creatSampleHuman(PATIENT_FIRSTNAME, PATIENT_LASTNAME, PROVIDER_FIRSTNAME, + PROVIDER_LASTNAME, PATIENT_BIRTHDATE, SAMPLE_ACCESSION_NUMBER, PATIENT_GENDER, + SAMPLE_RECEIVED_TIMESTAMP, PROVIDER_TYPE, SAMPLE_ENTERED_DATE); + Assert.assertEquals(0, humanService.getAll().size()); + + String sampleHumanId = humanService.insert(sampleHuman); + SampleHuman savedSampleHuman = humanService.get(sampleHumanId); + + humanService.delete(savedSampleHuman); + + Assert.assertEquals(0, humanService.getAll().size()); + + } + + @Test + public void getAllPatientsWithSampleEntered_shouldReturnPatientsWithSample() throws Exception { + SampleHuman sampleHuman = creatSampleHuman(PATIENT_FIRSTNAME, PATIENT_LASTNAME, PROVIDER_FIRSTNAME, + PROVIDER_LASTNAME, PATIENT_BIRTHDATE, SAMPLE_ACCESSION_NUMBER, PATIENT_GENDER, + SAMPLE_RECEIVED_TIMESTAMP, PROVIDER_TYPE, SAMPLE_ENTERED_DATE); + + Assert.assertEquals(0, humanService.getAll().size()); + + humanService.insert(sampleHuman); + List patients = humanService.getAllPatientsWithSampleEntered(); + ; + + Assert.assertEquals(1, patients.size()); + + } + + private SampleHuman creatSampleHuman(String firstname, String lastname, String firstname2, String lastname2, + String birthdate, String accessionNumber, String gender, String receivedTimestamp, String type, + String entereddate) throws ParseException { + Person person = new Person(); + person.setFirstName(firstname); + person.setLastName(lastname); + personService.save(person); + + Person person2 = new Person(); + person2.setFirstName(firstname2); + person2.setLastName(lastname2); + personService.save(person2); + + Patient pat = new Patient(); + pat.setBirthDate(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(birthdate).getTime())); + pat.setPerson(person); + pat.setGender(gender); + String patId = patientService.insert(pat); + + Provider prov = new Provider(); + prov.setPerson(person2); + prov.setProviderType(type); + String providerId = providerService.insert(prov); + + java.sql.Date enteredDate = java.sql.Date.valueOf(SAMPLE_ENTERED_DATE); + + Sample samp = new Sample(); + samp.setEnteredDate(enteredDate); + samp.setReceivedTimestamp(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(receivedTimestamp).getTime())); + samp.setAccessionNumber(accessionNumber); + String sampId = sampleService.insert(samp); + + SampleHuman sampleHuman = new SampleHuman(); + sampleHuman.setPatientId(patId); + sampleHuman.setProviderId(providerId); + sampleHuman.setSampleId(sampId); + + return sampleHuman; + } + + @Test + public void getData_shouldReturncopiedPropertiesFromDatabase() throws Exception { + Person person = new Person(); + person.setFirstName(PATIENT_FIRSTNAME); + person.setLastName(PATIENT_LASTNAME); + personService.save(person); + + Person person2 = new Person(); + person2.setFirstName(PROVIDER_FIRSTNAME); + person2.setLastName(PROVIDER_LASTNAME); + personService.save(person2); + + Patient pat = new Patient(); + pat.setBirthDate(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(PATIENT_BIRTHDATE).getTime())); + pat.setPerson(person); + pat.setGender(PATIENT_GENDER); + String patId = patientService.insert(pat); + + Provider prov = new Provider(); + prov.setPerson(person2); + prov.setProviderType(PROVIDER_TYPE); + String providerId = providerService.insert(prov); + + java.sql.Date enteredDate = java.sql.Date.valueOf(SAMPLE_ENTERED_DATE); + + Sample samp = new Sample(); + samp.setEnteredDate(enteredDate); + samp.setReceivedTimestamp( + new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(SAMPLE_RECEIVED_TIMESTAMP).getTime())); + samp.setAccessionNumber(SAMPLE_ACCESSION_NUMBER); + String sampId = sampleService.insert(samp); + + SampleHuman sampleHuman = new SampleHuman(); + sampleHuman.setPatientId(patId); + sampleHuman.setProviderId(providerId); + sampleHuman.setSampleId(sampId); + + String sampleHumanId = humanService.insert(sampleHuman); + + SampleHuman sHumanToUpdate = new SampleHuman(); + sHumanToUpdate.setId(sampleHumanId); + + humanService.getData(sHumanToUpdate); + ; + + Assert.assertEquals(providerId, sHumanToUpdate.getProviderId()); + + } + + @Test + public void getPatientForSample_shouldReturnPatientForSample() throws Exception { + Person person = new Person(); + person.setFirstName(PATIENT_FIRSTNAME); + person.setLastName(PATIENT_LASTNAME); + personService.save(person); + + Person person2 = new Person(); + person2.setFirstName(PROVIDER_FIRSTNAME); + person2.setLastName(PROVIDER_LASTNAME); + personService.save(person2); + + Patient pat = new Patient(); + pat.setBirthDate(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(PATIENT_BIRTHDATE).getTime())); + pat.setPerson(person); + pat.setGender(PATIENT_GENDER); + String patId = patientService.insert(pat); + + Provider prov = new Provider(); + prov.setPerson(person2); + prov.setProviderType(PROVIDER_TYPE); + String providerId = providerService.insert(prov); + java.sql.Date enteredDate = java.sql.Date.valueOf(SAMPLE_ENTERED_DATE); + + Sample samp = new Sample(); + samp.setEnteredDate(enteredDate); + samp.setReceivedTimestamp( + new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(SAMPLE_RECEIVED_TIMESTAMP).getTime())); + samp.setAccessionNumber(SAMPLE_ACCESSION_NUMBER); + String sampId = sampleService.insert(samp); + + SampleHuman sampleHuman = new SampleHuman(); + sampleHuman.setPatientId(patId); + sampleHuman.setProviderId(providerId); + sampleHuman.setSampleId(sampId); + + humanService.insert(sampleHuman); + Patient samplePatient = humanService.getPatientForSample(samp); + + Assert.assertEquals(PATIENT_FIRSTNAME, samplePatient.getPerson().getFirstName()); + + } + + @Test + public void getSamplesForPatient_shouldReturnSamplesForPatient() throws Exception { + Person person = new Person(); + person.setFirstName(PATIENT_FIRSTNAME); + person.setLastName(PATIENT_LASTNAME); + personService.save(person); + + Person person2 = new Person(); + person2.setFirstName(PROVIDER_FIRSTNAME); + person2.setLastName(PROVIDER_LASTNAME); + personService.save(person2); + + Patient pat = new Patient(); + pat.setBirthDate(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(PATIENT_BIRTHDATE).getTime())); + + pat.setPerson(person); + pat.setGender(PATIENT_GENDER); + String patId = patientService.insert(pat); + + Provider prov = new Provider(); + prov.setPerson(person2); + prov.setProviderType(PROVIDER_TYPE); + String providerId = providerService.insert(prov); + + java.sql.Date enteredDate = java.sql.Date.valueOf(SAMPLE_ENTERED_DATE); + + Sample samp = new Sample(); + samp.setEnteredDate(enteredDate); + samp.setReceivedTimestamp( + new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(SAMPLE_RECEIVED_TIMESTAMP).getTime())); + samp.setAccessionNumber(SAMPLE_ACCESSION_NUMBER); + String sampId = sampleService.insert(samp); + + SampleHuman sampleHuman = new SampleHuman(); + sampleHuman.setPatientId(patId); + sampleHuman.setProviderId(providerId); + sampleHuman.setSampleId(sampId); + + humanService.insert(sampleHuman); + List samples = humanService.getSamplesForPatient(patId); + + Assert.assertEquals(1, samples.size()); + } + + @Test + public void getDataBySample_shouldReturnDataBySample() throws Exception { + Person person = new Person(); + person.setFirstName(PATIENT_FIRSTNAME); + person.setLastName(PATIENT_LASTNAME); + personService.save(person); + + Person person2 = new Person(); + person2.setFirstName(PROVIDER_FIRSTNAME); + person2.setLastName(PROVIDER_LASTNAME); + personService.save(person2); + + Patient pat = new Patient(); + pat.setBirthDate(new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(PATIENT_BIRTHDATE).getTime())); + pat.setPerson(person); + pat.setGender(PATIENT_GENDER); + String patId = patientService.insert(pat); + + Provider prov = new Provider(); + prov.setPerson(person2); + prov.setProviderType(PROVIDER_TYPE); + String providerId = providerService.insert(prov); + + DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy"); + Date date2 = dateFormat2.parse(SAMPLE_RECEIVED_TIMESTAMP); + long time2 = date2.getTime(); + Timestamp doc = new Timestamp(time2); + + java.sql.Date enteredDate = java.sql.Date.valueOf(SAMPLE_ENTERED_DATE); + + Sample samp = new Sample(); + samp.setEnteredDate(enteredDate); + samp.setReceivedTimestamp( + new Timestamp(new SimpleDateFormat("dd/MM/yyyy").parse(SAMPLE_RECEIVED_TIMESTAMP).getTime())); + samp.setAccessionNumber(SAMPLE_ACCESSION_NUMBER); + String sampId = sampleService.insert(samp); + + SampleHuman sampleHuman = new SampleHuman(); + sampleHuman.setPatientId(patId); + sampleHuman.setProviderId(providerId); + sampleHuman.setSampleId(sampId); + + humanService.insert(sampleHuman); + + SampleHuman sHumanToUpdate = humanService.getDataBySample(sampleHuman); + + Assert.assertEquals(patId, sHumanToUpdate.getPatientId()); + + } +} diff --git a/src/test/java/org/openelisglobal/search/SearchResultsServiceTest.java b/src/test/java/org/openelisglobal/search/SearchResultsServiceTest.java index f8b4e9e6e9..7a29e1a5c5 100644 --- a/src/test/java/org/openelisglobal/search/SearchResultsServiceTest.java +++ b/src/test/java/org/openelisglobal/search/SearchResultsServiceTest.java @@ -6,10 +6,10 @@ 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 junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.*; +import org.junit.runner.RunWith; import org.openelisglobal.BaseWebContextSensitiveTest; import org.openelisglobal.common.provider.query.PatientSearchResults; import org.openelisglobal.patient.service.PatientService; @@ -19,9 +19,18 @@ import org.openelisglobal.search.service.SearchResultsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; +@RunWith(JUnitParamsRunner.class) public class SearchResultsServiceTest extends BaseWebContextSensitiveTest { + @ClassRule + public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + @Autowired PatientService patientService; @@ -47,8 +56,34 @@ public void tearDown() { personService.deleteAll(personService.getAll()); } + private Object[] parametersForGetSearchResults_shouldGetSearchResultsFromDB() { + return new Object[] { new Object[] { "Jo", "Do", "12/12/1992", "M" }, new Object[] { "Jo", null, null, null }, + new Object[] { null, "Do", null, null }, new Object[] { null, null, "12/12/1992", null }, + new Object[] { null, null, null, "M" } }; + } + + private Object[] parametersForGetSearchResultsExact_shouldGetExactSearchResultsFromDB() { + return new Object[] { new Object[] { "John", "Doe", "12/12/1992", "M" }, + new Object[] { "John", null, null, null }, new Object[] { null, "Doe", null, null }, + new Object[] { null, null, "12/12/1992", null }, new Object[] { null, null, null, "M" } }; + } + + private Object[] parametersForGetSearchResults_shouldGetSearchResultsFromLuceneIndexes() { + return new Object[] { new Object[] { "Johm", "Doee", "12/12/1992", "M" }, + new Object[] { "Johm", null, null, null }, new Object[] { null, "Doee", null, null }, + new Object[] { null, null, "12/12/1992", null }, new Object[] { null, null, null, "M" } }; + } + + private Object[] parametersForGetSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() { + return new Object[] { new Object[] { "John", "Doe", "12/12/1992", "M" }, + new Object[] { "John", null, null, null }, new Object[] { null, "Doe", null, null }, + new Object[] { null, null, "12/12/1992", null }, new Object[] { null, null, null, "M" } }; + } + @Test - public void getSearchResults_shouldGetSearchResultsFromDB() throws Exception { + @Parameters + public void getSearchResults_shouldGetSearchResultsFromDB(String searchFirstName, String searchLastName, + String searchDateOfBirth, String searchGender) throws Exception { String firstName = "John"; String lastname = "Doe"; String dob = "12/12/1992"; @@ -56,11 +91,8 @@ public void getSearchResults_shouldGetSearchResultsFromDB() throws Exception { Patient pat = createPatient(firstName, lastname, dob, gender); String patientId = patientService.insert(pat); - String searchFirstName = "Jo"; - String searchLastName = "Do"; - List searchResults = DBSearchResultsServiceImpl.getSearchResults(searchLastName, - searchFirstName, null, null, null, null, null, null, dob, gender); + searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender); Assert.assertEquals(1, searchResults.size()); PatientSearchResults result = searchResults.get(0); @@ -68,10 +100,13 @@ public void getSearchResults_shouldGetSearchResultsFromDB() throws Exception { Assert.assertEquals(firstName, result.getFirstName()); Assert.assertEquals(lastname, result.getLastName()); Assert.assertEquals(dob, result.getBirthdate()); + Assert.assertEquals(gender, result.getGender()); } @Test - public void getSearchResultsExact_shouldGetExactSearchResultsFromDB() throws Exception { + @Parameters + public void getSearchResultsExact_shouldGetExactSearchResultsFromDB(String searchFirstName, String searchLastName, + String searchDateOfBirth, String searchGender) throws Exception { String firstName = "John"; String lastname = "Doe"; String dob = "12/12/1992"; @@ -79,8 +114,8 @@ public void getSearchResultsExact_shouldGetExactSearchResultsFromDB() throws Exc Patient pat = createPatient(firstName, lastname, dob, gender); String patientId = patientService.insert(pat); - List searchResults = DBSearchResultsServiceImpl.getSearchResultsExact(lastname, firstName, - null, null, null, null, null, null, dob, gender); + List searchResults = DBSearchResultsServiceImpl.getSearchResultsExact(searchLastName, + searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender); Assert.assertEquals(1, searchResults.size()); PatientSearchResults result = searchResults.get(0); @@ -88,10 +123,13 @@ public void getSearchResultsExact_shouldGetExactSearchResultsFromDB() throws Exc Assert.assertEquals(firstName, result.getFirstName()); Assert.assertEquals(lastname, result.getLastName()); Assert.assertEquals(dob, result.getBirthdate()); + Assert.assertEquals(gender, result.getGender()); } @Test - public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes() throws Exception { + @Parameters + public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes(String searchFirstName, String searchLastName, + String searchDateOfBirth, String searchGender) throws Exception { String firstName = "John"; String lastname = "Doe"; String dob = "12/12/1992"; @@ -99,11 +137,8 @@ public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes() throws Ex Patient pat = createPatient(firstName, lastname, dob, gender); String patientId = patientService.insert(pat); - String searchFirstName = "Johm"; - String searchLastName = "Doee"; - List searchResults = luceneSearchResultsServiceImpl.getSearchResults(searchLastName, - searchFirstName, null, null, null, null, null, null, dob, gender); + searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender); Assert.assertEquals(1, searchResults.size()); PatientSearchResults result = searchResults.get(0); @@ -111,10 +146,13 @@ public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes() throws Ex Assert.assertEquals(firstName, result.getFirstName()); Assert.assertEquals(lastname, result.getLastName()); Assert.assertEquals(dob, result.getBirthdate()); + Assert.assertEquals(gender, result.getGender()); } @Test - public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() throws Exception { + @Parameters + public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes(String searchFirstName, + String searchLastName, String searchDateOfBirth, String searchGender) throws Exception { String firstName = "John"; String lastname = "Doe"; String dob = "12/12/1992"; @@ -122,8 +160,8 @@ public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() Patient pat = createPatient(firstName, lastname, dob, gender); String patientId = patientService.insert(pat); - List searchResults = luceneSearchResultsServiceImpl.getSearchResultsExact(lastname, - firstName, null, null, null, null, null, null, dob, gender); + List searchResults = luceneSearchResultsServiceImpl.getSearchResultsExact(searchLastName, + searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender); Assert.assertEquals(1, searchResults.size()); PatientSearchResults result = searchResults.get(0); @@ -131,6 +169,7 @@ public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() Assert.assertEquals(firstName, result.getFirstName()); Assert.assertEquals(lastname, result.getLastName()); Assert.assertEquals(dob, result.getBirthdate()); + Assert.assertEquals(gender, result.getGender()); } private Patient createPatient(String firstName, String LastName, String birthDate, String gender)