diff --git a/src/main/java/org/isf/utils/excel/ExcelExporter.java b/src/main/java/org/isf/utils/excel/ExcelExporter.java index eaffa918b..70cc9996a 100644 --- a/src/main/java/org/isf/utils/excel/ExcelExporter.java +++ b/src/main/java/org/isf/utils/excel/ExcelExporter.java @@ -160,7 +160,7 @@ private void exportTableToCSV(JTable jtable, File file, String separator) throws } outFile.write("\n"); - int rowCount = model.getColumnCount(); + int rowCount = model.getRowCount(); for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { String strVal; @@ -232,7 +232,7 @@ private void exportResultsetToCSV(ResultSet resultSet, File exportFile, String s int colCount = rsmd.getColumnCount(); for (int i = 1; i <= colCount; i++) { - if (i == colCount - 1) { + if (i == colCount) { output.write(rsmd.getColumnName(i)); } else { output.write(rsmd.getColumnName(i) + separator); diff --git a/src/test/java/org/isf/OHCoreTestCase.java b/src/test/java/org/isf/OHCoreTestCase.java index 350880279..b167f2030 100644 --- a/src/test/java/org/isf/OHCoreTestCase.java +++ b/src/test/java/org/isf/OHCoreTestCase.java @@ -21,7 +21,11 @@ */ package org.isf; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; +import java.util.stream.Stream; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -56,4 +60,18 @@ public void cleanH2InMemoryDb() { entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate(); } + public void executeSQLScript(String fileName) { + entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY FALSE").executeUpdate(); + try { + Path path = Paths.get(getClass().getResource(fileName).toURI()); + Stream lines = Files.lines(path); + for (String line : (Iterable) lines::iterator) { + entityManager.createNativeQuery(line).executeUpdate(); + } + lines.close(); + } catch(Exception exception) { + LOGGER.error("Error trying to execute script: " + fileName, exception); + } + entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate(); + } } diff --git a/src/test/java/org/isf/permissions/TestGroupPermission.java b/src/test/java/org/isf/permissions/TestGroupPermission.java new file mode 100644 index 000000000..4315da4e2 --- /dev/null +++ b/src/test/java/org/isf/permissions/TestGroupPermission.java @@ -0,0 +1,51 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.permissions; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.isf.OHCoreTestCase; +import org.isf.menu.model.UserGroup; +import org.isf.permissions.model.GroupPermission; +import org.isf.permissions.model.Permission; +import org.junit.jupiter.api.Test; + +class TestGroupPermission extends OHCoreTestCase { + + @Test + void testModel() throws Exception { + GroupPermission groupPermission = new GroupPermission(); + + groupPermission.setId(-1); + assertThat(groupPermission.getId()).isEqualTo(-1); + + Permission permission = new Permission(); + permission.setId(-1); + groupPermission.setPermission(permission); + assertThat(groupPermission.getPermission().getId()).isEqualTo(-1); + + UserGroup userGroup = new UserGroup(); + userGroup.setCode("code"); + groupPermission.setUserGroup(userGroup); + assertThat(groupPermission.getUserGroup().getCode()).isEqualTo("code"); + } +} diff --git a/src/test/java/org/isf/permissions/TestGroupPermissionManager.java b/src/test/java/org/isf/permissions/TestGroupPermissionManager.java new file mode 100644 index 000000000..82d46add8 --- /dev/null +++ b/src/test/java/org/isf/permissions/TestGroupPermissionManager.java @@ -0,0 +1,56 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.permissions; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.isf.OHCoreTestCase; +import org.isf.permissions.manager.GroupPermissionManager; +import org.isf.permissions.model.GroupPermission; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +class TestGroupPermissionManager extends OHCoreTestCase { + + @Autowired + GroupPermissionManager groupPermissionManager; + + @BeforeEach + void setUp() { + cleanH2InMemoryDb(); + executeSQLScript("LoadPermissionTables.sql"); + } + + @Test + void testFindByIdIn() throws Exception { + List listIds = new ArrayList<>(); + listIds.add(1); + listIds.add(10); + List groupPermissionList = groupPermissionManager.findByIdIn(listIds); + assertThat(groupPermissionList).isNotEmpty(); + assertThat(groupPermissionList).hasSize(2); + } +} diff --git a/src/test/java/org/isf/permissions/TestPermission.java b/src/test/java/org/isf/permissions/TestPermission.java new file mode 100644 index 000000000..fde5f3be0 --- /dev/null +++ b/src/test/java/org/isf/permissions/TestPermission.java @@ -0,0 +1,54 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.permissions; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.isf.OHCoreTestCase; +import org.isf.permissions.model.GroupPermission; +import org.isf.permissions.model.Permission; +import org.junit.jupiter.api.Test; + +class TestPermission extends OHCoreTestCase { + + @Test + void testModel() throws Exception { + Permission permission = new Permission(); + + permission.setId(-1); + assertThat(permission.getId()).isEqualTo(-1); + + permission.setDescription("description"); + assertThat(permission.getDescription()).isEqualTo("description"); + + permission.setName("name"); + assertThat(permission.getName()).isEqualTo("name"); + + List groupPermissions = new ArrayList<>(); + groupPermissions.add(new GroupPermission()); + permission.setGroupPermission(groupPermissions); + assertThat(permission.getGroupPermission()).hasSize(1); + } +} diff --git a/src/test/java/org/isf/permissions/TestPermissionManager.java b/src/test/java/org/isf/permissions/TestPermissionManager.java new file mode 100644 index 000000000..81b4825ce --- /dev/null +++ b/src/test/java/org/isf/permissions/TestPermissionManager.java @@ -0,0 +1,97 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.permissions; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.isf.OHCoreTestCase; +import org.isf.permissions.manager.PermissionManager; +import org.isf.permissions.model.Permission; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +class TestPermissionManager extends OHCoreTestCase { + + @Autowired + PermissionManager permissionManager; + + @BeforeEach + void setUp() { + cleanH2InMemoryDb(); + executeSQLScript("LoadPermissionTables.sql"); + } + + @Test + void testRetrieveByGroupCode() throws Exception { + List permissions = permissionManager.retrievePermissionsByGroupCode("doctor"); + assertThat(permissions).isNotEmpty(); + assertThat(permissions.get(0).getName()).isEqualTo("admissions.create"); + assertThat(permissions.get(0).getDescription()).isEmpty(); + } + + @Test + void testRetrieveByUsername() throws Exception { + List permissions = permissionManager.retrievePermissionsByUsername("admin"); + assertThat(permissions).isNotEmpty(); + assertThat(permissions.get(0).getName()).isEqualTo("admissions.create"); + assertThat(permissions.get(0).getDescription()).isEmpty(); + } + + @Test + void testRetrieveById() throws Exception { + Permission permission = permissionManager.retrievePermissionById(3); + assertThat(permission).isNotNull(); + assertThat(permission.getName()).isEqualTo("admissions.update"); + assertThat(permission.getDescription()).isEmpty(); + assertThat(permission.getId()).isEqualTo(3); + assertThat(permission.getGroupPermission()).isNotNull(); + } + + @Test + void testRetrieveByName() throws Exception { + Permission permission = permissionManager.retrievePermissionByName("admissions.create"); + assertThat(permission).isNotNull(); + assertThat(permission.getName()).isEqualTo("admissions.create"); + assertThat(permission.getDescription()).isEmpty(); + } + + @Test + void testRetrieveAllPermissions() throws Exception { + List permissions = permissionManager.retrieveAllPermissions(); + assertThat(permissions).isNotEmpty(); + assertThat(permissions.get(0).getName()).isEqualTo("admissions.create"); + assertThat(permissions.get(0).getDescription()).isEmpty(); + + assertThat(permissions).hasSize(30); + } + + @Test + void testExists() throws Exception { + Permission permission = permissionManager.retrievePermissionById(3); + assertThat(permission).isNotNull(); + assertThat(permissionManager.exists(5)).isTrue(); + assertThat(permissionManager.exists(-999)).isFalse(); + } +} diff --git a/src/test/java/org/isf/utils/db/TestDbJpaUtil.java b/src/test/java/org/isf/utils/db/TestDbJpaUtil.java new file mode 100644 index 000000000..c04b5b4ec --- /dev/null +++ b/src/test/java/org/isf/utils/db/TestDbJpaUtil.java @@ -0,0 +1,66 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.db; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; + +import org.isf.menu.manager.Context; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.context.ApplicationContext; + +class TestDbJpaUtil { + + @Mock + EntityManagerFactory entityManagerFactoryMock; + @Mock + EntityManager entityManagerMock; + @Mock + ApplicationContext applicationContextMock; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + Context.setApplicationContext(applicationContextMock); + when(applicationContextMock.getBean("entityManagerFactory", EntityManagerFactory.class)).thenReturn(entityManagerFactoryMock); + } + + @Test + void testNew() throws Exception { + DbJpaUtil dbJpaUtil = new DbJpaUtil(); + assertThat(dbJpaUtil).isNotNull(); + } + + @Test + void testOpen() throws Exception { + DbJpaUtil dbJpaUtil = new DbJpaUtil(); + when(entityManagerFactoryMock.createEntityManager()).thenReturn(entityManagerMock); + dbJpaUtil.open(); + } + +} diff --git a/src/test/java/org/isf/utils/db/TestDbQueryLogger.java b/src/test/java/org/isf/utils/db/TestDbQueryLogger.java new file mode 100644 index 000000000..ba68c1478 --- /dev/null +++ b/src/test/java/org/isf/utils/db/TestDbQueryLogger.java @@ -0,0 +1,64 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.db; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.when; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; + +import org.isf.menu.manager.Context; +import org.isf.utils.exception.OHException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.context.ApplicationContext; + +class TestDbQueryLogger { + + @Mock + EntityManagerFactory entityManagerFactoryMock; + @Mock + EntityManager entityManagerMock; + @Mock + ApplicationContext applicationContextMock; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + Context.setApplicationContext(applicationContextMock); + when(applicationContextMock.getBean("entityManagerFactory", EntityManagerFactory.class)).thenReturn(entityManagerFactoryMock); + } + + @Test + void testNew() throws Exception { + when(entityManagerFactoryMock.createEntityManager()).thenReturn(entityManagerMock); + DbQueryLogger dbQueryLogger = new DbQueryLogger(); + assertThat(dbQueryLogger).isNotNull(); + String query = "SHOW TABLES"; + assertThatThrownBy(() -> { dbQueryLogger.getData(query, true); }) + .isInstanceOf(OHException.class); + } +} diff --git a/src/test/java/org/isf/utils/db/TestDbSingleJpaConn.java b/src/test/java/org/isf/utils/db/TestDbSingleJpaConn.java new file mode 100644 index 000000000..d998dc0e7 --- /dev/null +++ b/src/test/java/org/isf/utils/db/TestDbSingleJpaConn.java @@ -0,0 +1,56 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.db; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.when; + +import jakarta.persistence.EntityManagerFactory; + +import org.isf.menu.manager.Context; +import org.isf.utils.exception.OHException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.context.ApplicationContext; + +class TestDbSingleJpaConn { + + @Mock + EntityManagerFactory entityManagerFactoryMock; + @Mock + ApplicationContext applicationContextMock; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + Context.setApplicationContext(applicationContextMock); + when(applicationContextMock.getBean("entityManagerFactory", EntityManagerFactory.class)).thenReturn(entityManagerFactoryMock); + } + + @Test + void testGetConnectionException() throws Exception { + assertThatThrownBy(() -> { DbSingleJpaConn.getConnection(); }) + .isInstanceOf(OHException.class); + } +} diff --git a/src/test/java/org/isf/utils/db/TestNormalizeString.java b/src/test/java/org/isf/utils/db/TestNormalizeString.java new file mode 100644 index 000000000..7aa113412 --- /dev/null +++ b/src/test/java/org/isf/utils/db/TestNormalizeString.java @@ -0,0 +1,54 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.db; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class TestNormalizeString { + + @Test + void testNormalizeString() throws Exception { + assertThat(NormalizeString.normalizeString("touch" + "\u00e9")).isEqualTo("touche"); + assertThat(NormalizeString.normalizeString("a" + "\ufb03" + "ance")).isEqualTo("aance"); + assertThat(NormalizeString.normalizeString("fa" + "\u00e7" + "ade")).isEqualTo("facade"); + } + + @Test + void testNormalizeCompareTo() throws Exception { + assertThat(NormalizeString.normalizeCompareTo("touch" + "\u00e9", "fa" + "\u00e7" + "ade")).isGreaterThan(0); + assertThat(NormalizeString.normalizeCompareTo("touch" + "\u00e9", "touche")).isZero(); + } + + @Test + void testNormalizeCompareToIgnoreCase() throws Exception { + assertThat(NormalizeString.normalizeCompareToIgnorecase("touch" + "\u00e9", "fa" + "\u00e7" + "ade")).isGreaterThan(0); + assertThat(NormalizeString.normalizeCompareToIgnorecase("touch" + "\u00e9", "ToUcHe")).isZero(); + } + + @Test + void testNormalizeContains() throws Exception { + assertThat(NormalizeString.normalizeContains("touch" + "\u00e9", "fa" + "\u00e7" + "ade")).isFalse(); + assertThat(NormalizeString.normalizeContains("touch" + "\u00e9", "\u00e9")).isTrue(); + } +} diff --git a/src/test/java/org/isf/utils/db/TestRememberData.java b/src/test/java/org/isf/utils/db/TestRememberData.java new file mode 100644 index 000000000..d5e4deea0 --- /dev/null +++ b/src/test/java/org/isf/utils/db/TestRememberData.java @@ -0,0 +1,41 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.db; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.isf.ward.TestWard; +import org.isf.ward.model.Ward; +import org.junit.jupiter.api.Test; + +class TestRememberData { + + private static TestWard testWard = new TestWard(); + + @Test + void testSetGet() throws Exception { + Ward ward = testWard.setup(false); + RememberData.setLastOpdWard(ward); + assertThat(RememberData.getLastOpdWard()).isSameAs(ward); + } + +} diff --git a/src/test/java/org/isf/utils/excel/MockResultSet.java b/src/test/java/org/isf/utils/excel/MockResultSet.java new file mode 100644 index 000000000..efb8c78ee --- /dev/null +++ b/src/test/java/org/isf/utils/excel/MockResultSet.java @@ -0,0 +1,114 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.excel; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class MockResultSet { + + private final Map columnIndices; + private final Object[][] data; + private int rowIndex; + private String[] columnNames; + + private MockResultSet(String[] columnNames, Object[][] data) { + // create a map of column name to column index + Object LinkedHashMap; + this.columnIndices = IntStream.range(0, columnNames.length) + .boxed() + .collect(Collectors.toMap( + k -> columnNames[k], + Function.identity(), + (a, b) -> { + throw new RuntimeException("Duplicate column " + a); + }, + java.util.LinkedHashMap::new + )); + this.data = data; + this.columnNames = columnNames; + this.rowIndex = -1; + } + + private ResultSet buildMock() throws SQLException { + final ResultSet rs = mock(ResultSet.class); + + // mock rs.next() + doAnswer(invocation -> { + rowIndex++; + return rowIndex < data.length; + }).when(rs).next(); + + // mock rs.getString(columnName) + doAnswer(invocation -> { + String columnName = invocation.getArgument(0, String.class); + int columnIndex = columnIndices.get(columnName); + return (String) data[rowIndex][columnIndex]; + }).when(rs).getString(anyString()); + + // mock rs.getObject(columnIndex) + doAnswer(invocation -> { + int index = invocation.getArgument(0, Integer.class); + return data[rowIndex][index - 1]; + }).when(rs).getObject(anyInt()); + + ResultSetMetaData rsmd = mock(ResultSetMetaData.class); + + // mock rsmd.getColumnCount() + doReturn(columnIndices.size()).when(rsmd).getColumnCount(); + + // mock rs.getMetaData() + doReturn(rsmd).when(rs).getMetaData(); + + doAnswer(invocation -> { + int index = invocation.getArgument(0, Integer.class); + return columnNames[index - 1]; + }).when(rsmd).getColumnName(anyInt()); + + return rs; + } + + /** + * Creates the mock ResultSet. + * @param columnNames the names of the columns + * @param data + * @return a mocked ResultSet + * @throws SQLException + */ + static ResultSet create( + final String[] columnNames, + final Object[][] data) + throws SQLException { + return new MockResultSet(columnNames, data).buildMock(); + } +} diff --git a/src/test/java/org/isf/utils/excel/TestExcelExporter.java b/src/test/java/org/isf/utils/excel/TestExcelExporter.java new file mode 100644 index 000000000..44174a638 --- /dev/null +++ b/src/test/java/org/isf/utils/excel/TestExcelExporter.java @@ -0,0 +1,247 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.excel; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.FileOutputStream; +import java.math.BigDecimal; +import java.nio.file.Files; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.util.Collection; +import java.util.GregorianCalendar; +import java.util.Iterator; +import java.util.Map; + +import javax.swing.JTable; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +class TestExcelExporter { + + private Timestamp timeStamp = new Timestamp(new GregorianCalendar(2024, 1, 1).getTimeInMillis()); + private BigDecimal bigDecimal = new BigDecimal(98); + private Date date = new Date(1234567l); + + String[] columns = new String[] { "Id", "Name", "Hourly Rate", "Part Time", "TimeStamp", "BigDecimal", "Long", "Date" }; + + Object[][] tableData = new Object[][] { + { 1, "John", 40.0, false, timeStamp, bigDecimal, -1l, date }, + { 2, "Rambo", 70.0, false, timeStamp, bigDecimal, -1l, date }, + { 3, "Zorro", 60.0, true, timeStamp, bigDecimal, -1l, date}, + }; + JTable table; + ExcelExporter excelExporter; + + @Mock + FileOutputStream fileOutputStream; + + @TempDir + File tempDir; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + table = new JTable(tableData, columns); + excelExporter = new ExcelExporter(); + } + + @Test + void testExportTableToCSV() throws Exception { + File outputFile = new File(tempDir, "exportTableToCSV"); + excelExporter.exportTableToCSV(table, outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportTableToExcel() throws Exception { + File outputFile = new File(tempDir, "exportTableToExcel"); + excelExporter.exportTableToExcel(table, outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportTableToExcelOLD() throws Exception { + File outputFile = new File(tempDir, "exportTableToExcelOLD"); + excelExporter.exportTableToExcelOLD(table, outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportDataToExcel() throws Exception { + File outputFile = new File(tempDir, "exportDataToExcel"); + excelExporter.exportDataToExcel(new MyCollection(), outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportDataToExcelOLD() throws Exception { + File outputFile = new File(tempDir, "exportDataToExcelOLD"); + excelExporter.exportDataToExcelOLD(new MyCollection(), outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportResultSetToExcel() throws Exception { + ResultSet mockResultSet = MockResultSet.create( + new String[] { "name", "age", "weight", "empty", "timestamp", "long" }, //columns + new Object[][] { // data + { "Alice", 20, 100.0, null, timeStamp, 99l }, + { "Bob", 35, 175.0, null, timeStamp, 99l }, + { "Charles", 50, 150.0, null, timeStamp, 99l }, + { "Frank", 44, 212.0, null, timeStamp, 99l }, + { "Jane", 22, 112.5, null, timeStamp, 99l } + }); + File outputFile = new File(tempDir, "exportResultSetToExcel"); + excelExporter.exportResultsetToExcel(mockResultSet, outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportResultSetToExcelOLD() throws Exception { + ResultSet mockResultSet = MockResultSet.create( + new String[] { "name", "age", "weight", "empty" }, //columns + new Object[][] { // data + { "Alice", 20, 100.0, null }, + { "Bob", 35, 175.0, null }, + { "Charles", 50, 150.0, null }, + { "Frank", 44, 212.0, null }, + { "Jane", 22, 112.5, null } + }); + File outputFile = new File(tempDir, "exportResultSetToExcelOLD"); + excelExporter.exportResultsetToExcelOLD(mockResultSet, outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportResultSetToCSV() throws Exception { + ResultSet mockResultSet = MockResultSet.create( + new String[] { "name", "age", "weight", "empty", "timestamp" }, //columns + new Object[][] { // data + { "Alice", 20, 100.0, null, timeStamp }, + { "Bob", 35, 175.0, null, timeStamp }, + { "Charles", 50, 150.0, null, timeStamp }, + { "Frank", 44, 212.0, null, timeStamp }, + { "Jane", 22, 112.5, null, timeStamp } + }); + File outputFile = new File(tempDir, "exportResultSetToCSV"); + excelExporter.exportResultsetToCSV(mockResultSet, outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + @Test + void testExportDataToCSV() throws Exception { + File outputFile = new File(tempDir, "exportDataToCSV"); + excelExporter.exportDataToCSV(new MyCollection(), outputFile); + assertThat(Files.exists(outputFile.toPath())).isTrue(); + } + + class MyCollection implements Collection { + + int rows = 2; + int currentRow = 0; + Map data = Map.of( + "one", "b", + "two", "c", + "three", 0d, + "four", timeStamp, + "five", 99l, + "six", bigDecimal, + "seven", date + ); + + @Override + public int size() { + return 0; + } + @Override + public boolean isEmpty() { + return false; + } + @Override + public boolean contains(Object o) { + return false; + } + @Override + public Iterator iterator() { + return new Iterator() { + + @Override + public boolean hasNext() { + currentRow++; + if (currentRow > rows) { + return false; + } + return true; + } + @Override + public Object next() { + return data; + } + }; + } + @Override + public Object[] toArray() { + return new Object[0]; + } + @Override + public boolean add(Object o) { + return false; + } + @Override + public boolean remove(Object o) { + return false; + } + @Override + public boolean addAll(Collection c) { + return false; + } + @Override + public void clear() { + + } + @Override + public boolean retainAll(Collection c) { + return false; + } + @Override + public boolean removeAll(Collection c) { + return false; + } + @Override + public boolean containsAll(Collection c) { + return false; + } + @Override + public Object[] toArray(Object[] a) { + return new Object[0]; + } + } + +} diff --git a/src/test/java/org/isf/utils/exception/TestExceptions.java b/src/test/java/org/isf/utils/exception/TestExceptions.java new file mode 100644 index 000000000..cb4ad712b --- /dev/null +++ b/src/test/java/org/isf/utils/exception/TestExceptions.java @@ -0,0 +1,81 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.exception; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.isf.utils.exception.model.OHExceptionMessage; +import org.junit.jupiter.api.Test; + +class TestExceptions { + + @Test + void testOHDataLockFailureException() { + assertThat(new OHDataLockFailureException(new OHExceptionMessage("message"))).isNotNull(); + assertThat(new OHDataLockFailureException(new Throwable(), new OHExceptionMessage("message"))).isNotNull(); + } + + @Test + void testOHDBConnectionException() { + assertThat(new OHDBConnectionException(new OHExceptionMessage("message"))).isNotNull(); + assertThat(new OHDBConnectionException(new Throwable(), new OHExceptionMessage("message"))).isNotNull(); + } + + @Test + void testOHDicomException() { + List ohExceptionMessages = new ArrayList<>(); + ohExceptionMessages.add(new OHExceptionMessage("message")); + assertThat(new OHDicomException(ohExceptionMessages)).isNotNull(); + + assertThat(new OHDicomException(new Throwable(), ohExceptionMessages)).isNotNull(); + } + + @Test + void testOHException() { + assertThat(new OHException("message", new Throwable())).isNotNull(); + + assertThat(new OHException("message")).isNotNull(); + } + + @Test + void testOHInvalidSQLException() { + assertThat(new OHInvalidSQLException(new OHExceptionMessage("message"))).isNotNull(); + assertThat(new OHInvalidSQLException(new Throwable(), new OHExceptionMessage("message"))).isNotNull(); + } + + @Test + void testOHReportException() { + assertThat(new OHReportException(new Throwable(), new OHExceptionMessage("message"))).isNotNull(); + } + + @Test + void testOHServiceException() { + List ohExceptionMessages = new ArrayList<>(); + ohExceptionMessages.add(new OHExceptionMessage("message")); + assertThat(new OHServiceException(ohExceptionMessages)).isNotNull(); + + assertThat(new OHServiceException(new Throwable(), ohExceptionMessages)).isNotNull(); + } +} diff --git a/src/test/java/org/isf/utils/exception/model/TestExceptionModel.java b/src/test/java/org/isf/utils/exception/model/TestExceptionModel.java new file mode 100644 index 000000000..403f5bbd0 --- /dev/null +++ b/src/test/java/org/isf/utils/exception/model/TestExceptionModel.java @@ -0,0 +1,62 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.exception.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class TestExceptionModel { + + @Test + void testConstructors() { + assertThat(setup()).isNotNull(); + assertThat(setupWithDescription()).isNotNull(); + } + + @Test + void testSetGet() { + OHExceptionMessage ohExceptionMessage = new OHExceptionMessage("Some Message"); + + ohExceptionMessage.setTitle("title"); + assertThat(ohExceptionMessage.getTitle()).isEqualTo("title"); + + ohExceptionMessage.setMessage("message"); + assertThat(ohExceptionMessage.getMessage()).isEqualTo("message"); + + ohExceptionMessage.setLevel(OHSeverityLevel.INFO); + assertThat(ohExceptionMessage.getLevel()).isEqualTo(OHSeverityLevel.INFO); + + ohExceptionMessage.setDescription(ErrorDescription.PASSWORD_TOO_SHORT); + assertThat(ohExceptionMessage.getDescription()).isEqualTo(ErrorDescription.PASSWORD_TOO_SHORT); + } + + protected OHExceptionMessage setup() { + OHExceptionMessage ohExceptionMessage = new OHExceptionMessage("title", "message", OHSeverityLevel.ERROR); + return ohExceptionMessage; + } + + protected OHExceptionMessage setupWithDescription() { + OHExceptionMessage ohExceptionMessage = new OHExceptionMessage("title", ErrorDescription.PASSWORD_TOO_SHORT,"message", OHSeverityLevel.ERROR); + return ohExceptionMessage; + } +} diff --git a/src/test/java/org/isf/utils/file/TestFileTools.java b/src/test/java/org/isf/utils/file/TestFileTools.java index b92ae3581..1f76109da 100644 --- a/src/test/java/org/isf/utils/file/TestFileTools.java +++ b/src/test/java/org/isf/utils/file/TestFileTools.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; +import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -35,7 +36,7 @@ class TestFileTools { - // The ultimate goal is to return a single Date object instead of an List of Dates. + // The ultimate goal is to return a single Date object instead of a List of Dates. // Until that change is made and the corresponding changes in the GUI project // this helper class means we don't have to modify the tests for the change private Date getTimestampFromName(String fileName) { @@ -565,6 +566,31 @@ void testReadNonExistentFile() { assertThrows(IllegalArgumentException.class, () -> FileTools.readFileToStringLineByLine("nonexistent.txt", true)); } + @Test + void testGetTimestampNullFile() { + assertThat(FileTools.getTimestamp(null)).isNull(); + } + + @Test + void testGetTimestamp() { + File file = getFile("testFile.txt"); + LocalDateTime timeStamp = FileTools.getTimestamp(file); + assertThat(timeStamp).isNotNull(); + assertThat(timeStamp.getYear()).isGreaterThanOrEqualTo(2024); + } + + @Test + void testGetTimestampFromName() { + File file = getFile("testFile.txt"); + List dates = FileTools.getTimestampFromName(file); + assertThat(dates).isEmpty(); + } + + @Test + void testGetFile() { + assertThat(FileTools.getFile("badTestFile.txt")).isNull(); + } + private File getFile(String fileName) { return new File(getClass().getResource(fileName).getFile()); } diff --git a/src/test/java/org/isf/utils/log/TestLogUtil.java b/src/test/java/org/isf/utils/log/TestLogUtil.java new file mode 100644 index 000000000..12cbf90bd --- /dev/null +++ b/src/test/java/org/isf/utils/log/TestLogUtil.java @@ -0,0 +1,35 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.log; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class TestLogUtil { + + @Test + void testGetLogFileAbsolutePath() { + // depending on the testing setup the value is either null or the value in the properties file + assertThat(LogUtil.getLogFileAbsolutePath()).isIn(null, "logs/openhospital.log"); + } +} diff --git a/src/test/java/org/isf/utils/pagination/TestPageInfo.java b/src/test/java/org/isf/utils/pagination/TestPageInfo.java new file mode 100644 index 000000000..d7ed34a7c --- /dev/null +++ b/src/test/java/org/isf/utils/pagination/TestPageInfo.java @@ -0,0 +1,65 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.pagination; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class TestPageInfo { + + @Test + void testConstructor() { + assertThat(setupPageInfo()).isNotNull(); + } + + @Test + void testSetGet() { + PageInfo pageInfo = new PageInfo(); + + pageInfo.setSize(-9); + assertThat(pageInfo.getSize()).isEqualTo(-9); + + pageInfo.setPage(-8); + assertThat(pageInfo.getPage()).isEqualTo(-8); + + pageInfo.setNbOfElements(-7); + assertThat(pageInfo.getNbOfElements()).isEqualTo(-7); + + pageInfo.setHasPreviousPage(true); + assertThat(pageInfo.isHasPreviousPage()).isTrue(); + + pageInfo.setHasNextPage(false); + assertThat(pageInfo.isHasNextPage()).isFalse(); + + pageInfo.setTotalNbOfElements(0); + assertThat(pageInfo.getTotalNbOfElements()).isZero(); + + pageInfo.setTotalPages(1); + assertThat(pageInfo.getTotalPages()).isEqualTo(1); + } + + protected static PageInfo setupPageInfo() { + PageInfo pageInfo = new PageInfo(1, 2, 3, 4, 5, false, true); + return pageInfo; + } +} diff --git a/src/test/java/org/isf/utils/pagination/TestPageResponse.java b/src/test/java/org/isf/utils/pagination/TestPageResponse.java new file mode 100644 index 000000000..223a6c481 --- /dev/null +++ b/src/test/java/org/isf/utils/pagination/TestPageResponse.java @@ -0,0 +1,49 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.pagination; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; + +class TestPageResponse { + + @Test + void testSetGet() { + PageInfo pageInfo = TestPageInfo.setupPageInfo(); + + PagedResponse pagedResponse = new PagedResponse(); + + pagedResponse.setPageInfo(pageInfo); + assertThat(pagedResponse.getPageInfo()).isSameAs(pageInfo); + + List data = new ArrayList<>(); + data.add("a"); + data.add("b"); + + pagedResponse.setData(data); + assertThat(pagedResponse.getData()).isSameAs(data); + } +} diff --git a/src/test/java/org/isf/utils/time/TestDelayTimer.java b/src/test/java/org/isf/utils/time/TestDelayTimer.java new file mode 100644 index 000000000..2a29158cd --- /dev/null +++ b/src/test/java/org/isf/utils/time/TestDelayTimer.java @@ -0,0 +1,45 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.time; + +import org.junit.jupiter.api.Test; + +class TestDelayTimer { + + @Test + void testDelayTimer() throws Exception { + // Nothing really to check; if the code doesn't error out then it is as good as it gets + DelayTimer delayTimer = new DelayTimer(new Callback(), 3L); + delayTimer.startTimer(); + delayTimer.startTimer(); + new Thread(delayTimer::run); + delayTimer.stopTimer(); + delayTimer.quit(); + } + + class Callback implements DelayTimerCallback { + + @Override + public void trigger() { + } + } +} diff --git a/src/test/java/org/isf/utils/time/TestRememberDates.java b/src/test/java/org/isf/utils/time/TestRememberDates.java new file mode 100644 index 000000000..c8f4f768d --- /dev/null +++ b/src/test/java/org/isf/utils/time/TestRememberDates.java @@ -0,0 +1,66 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.time; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.LocalDateTime; + +import org.junit.jupiter.api.Test; + +class TestRememberDates { + + @Test + void testOpdVisitDate() { + LocalDateTime date = LocalDateTime.of(2014, 10, 3, 0, 0, 0); + RememberDates.setLastOpdVisitDate(date); + assertThat(RememberDates.getLastOpdVisitDate()).isEqualTo(date); + } + + @Test + void testLabExamDate() { + LocalDateTime date = LocalDateTime.of(2014, 11, 3, 0, 0, 0); + RememberDates.setLastLabExamDate(date); + assertThat(RememberDates.getLastLabExamDate()).isEqualTo(date); + } + + @Test + void testAdmInDate() { + LocalDateTime date = LocalDateTime.of(2016, 11, 3, 0, 0, 0); + RememberDates.setLastAdmInDate(date); + assertThat(RememberDates.getLastAdmInDate()).isEqualTo(date); + } + + @Test + void testBillDate() { + LocalDateTime date = LocalDateTime.of(2016, 1, 3, 0, 0, 0); + RememberDates.setLastBillDate(date); + assertThat(RememberDates.getLastBillDate()).isEqualTo(date); + } + + @Test + void testPatientVaccineDate() { + LocalDateTime date = LocalDateTime.of(2016, 1, 28, 0, 0, 0); + RememberDates.setLastPatineVaccineDate(date); + assertThat(RememberDates.getLastPatientVaccineDate()).isEqualTo(date); + } +} diff --git a/src/test/java/org/isf/utils/time/TestTimeTools.java b/src/test/java/org/isf/utils/time/TestTimeTools.java index 8a3ab5ac2..6ae499cb2 100644 --- a/src/test/java/org/isf/utils/time/TestTimeTools.java +++ b/src/test/java/org/isf/utils/time/TestTimeTools.java @@ -120,5 +120,14 @@ void testParseDate() throws Exception { .isEqualTo(LocalDateTime.of(2021, 11, 3, 23, 59, 59)); assertThat(TimeTools.parseDate("2021-11-03", "yyyy-MM-dd", true)) .isEqualTo(LocalDateTime.of(2021, 11, 3, 0, 0, 0)); + assertThat(TimeTools.parseDate("2021-11-03 23:12:12", null, false)) + .isEqualTo(LocalDateTime.of(2021, 11, 3, 23, 12, 12)); + } + + @Test + void testGetDateException() throws Exception { + String date = "02/03/2024"; + LocalDateTime localDateTime = TimeTools.getDate(date, "dd/MM/yyyy"); + assertThat(localDateTime).isNull(); } } diff --git a/src/test/resources/org/isf/permissions/LoadPermissionTables.sql b/src/test/resources/org/isf/permissions/LoadPermissionTables.sql new file mode 100644 index 000000000..2970336e9 --- /dev/null +++ b/src/test/resources/org/isf/permissions/LoadPermissionTables.sql @@ -0,0 +1,75 @@ +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (1,'admin',1,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (2,'admin',2,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (3,'admin',3,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (4,'admin',4,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (5,'admin',5,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (6,'admin',6,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (7,'admin',7,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (8,'admin',8,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (9,'admin',9,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (10,'admin',10,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (11,'admin',11,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (12,'admin',12,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (13,'admin',13,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (14,'admin',14,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (15,'admin',15,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (16,'admin',16,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (17,'admin',17,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (18,'admin',18,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (19,'admin',19,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (20,'admin',20,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (21,'admin',21,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (22,'admin',22,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (23,'admin',23,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (24,'admin',24,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (25,'admin',25,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (26,'admin',26,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (27,'admin',27,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (28,'admin',28,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (29,'admin',29,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (30,'admin',30,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (215,'doctor',1,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (216,'doctor',2,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (217,'doctor',3,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (218,'doctor',4,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (219,'doctor',6,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (220,'doctor',9,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (221,'doctor',12,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (222,'doctor',16,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (223,'doctor',20,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (224,'doctor',24,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_grouppermission` (`GP_ID`, `GP_UG_ID_A`, `GP_P_ID_A`, `GP_ACTIVE`, `GP_CREATED_BY`, `GP_CREATED_DATE`, `GP_LAST_MODIFIED_BY`, `GP_LAST_MODIFIED_DATE`) VALUES (225,'doctor',28,'1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (1,'admissions.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (2,'admissions.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (3,'admissions.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (4,'admissions.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (5,'admissiontypes.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (6,'admissiontypes.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (7,'admissiontypes.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (8,'admissiontypes.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (9,'agetypes.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (10,'agetypes.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (11,'dischargetypes.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (12,'dischargetypes.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (13,'dischargetypes.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (14,'dischargetypes.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (15,'diseases.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (16,'diseases.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (17,'diseases.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (18,'diseases.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (19,'diseasetypes.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (20,'diseasetypes.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (21,'diseasetypes.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (22,'diseasetypes.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (23,'deliveryresulttypes.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (24,'deliveryresulttypes.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (25,'deliveryresulttypes.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (26,'deliveryresulttypes.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (27,'deliverytypes.create','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (28,'deliverytypes.read','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (29,'deliverytypes.update','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_permissions` (`P_ID_A`, `P_NAME`, `P_DESCRIPTION`, `P_ACTIVE`, `P_CREATED_BY`, `P_CREATED_DATE`, `P_LAST_MODIFIED_BY`, `P_LAST_MODIFIED_DATE`) VALUES (30,'deliverytypes.delete','','1',NULL,NULL,NULL,NULL); +INSERT INTO `oh_user` (`US_ID_A`, `US_UG_ID_A`, `US_PASSWD`, `US_DESC`, `US_CREATED_BY`, `US_CREATED_DATE`, `US_LAST_MODIFIED_BY`, `US_LAST_MODIFIED_DATE`, `US_ACTIVE`, `US_FAILED_ATTEMPTS`, `US_ACCOUNT_LOCKED`, `US_LOCK_TIME`, `US_LAST_LOGIN`) VALUES ('admin','admin','$2a$10$FI/PMO0oSHHosF2PX8l3QuB0DJepVfnynbLZ9Zm2711bF2ch8db2S','administrator',NULL,NULL,NULL,NULL,1,0,0,NULL,NULL); +INSERT INTO `oh_user` (`US_ID_A`, `US_UG_ID_A`, `US_PASSWD`, `US_DESC`, `US_CREATED_BY`, `US_CREATED_DATE`, `US_LAST_MODIFIED_BY`, `US_LAST_MODIFIED_DATE`, `US_ACTIVE`, `US_FAILED_ATTEMPTS`, `US_ACCOUNT_LOCKED`, `US_LOCK_TIME`, `US_LAST_LOGIN`) VALUES ('doctor','doctor','$2a$04$iqB3DZzyvQos4wCQrSHKyuf/Spr8LyOFF23dihNbS1AWpkIPu..MG','doctor',NULL,NULL,NULL,NULL,1,0,0,NULL,NULL); +INSERT INTO `oh_usergroup` (`UG_ID_A`, `UG_DESC`, `UG_CREATED_BY`, `UG_CREATED_DATE`, `UG_LAST_MODIFIED_BY`, `UG_LAST_MODIFIED_DATE`, `UG_ACTIVE`) VALUES ('admin','USER with all the privileges',NULL,NULL,NULL,NULL,1); +INSERT INTO `oh_usergroup` (`UG_ID_A`, `UG_DESC`, `UG_CREATED_BY`, `UG_CREATED_DATE`, `UG_LAST_MODIFIED_BY`, `UG_LAST_MODIFIED_DATE`, `UG_ACTIVE`) VALUES ('doctor','Access everywhere except the laboratory',NULL,NULL,NULL,NULL,1);