diff --git a/opp/core/src/main/java/OPStaff.java b/opp/core/src/main/java/OPStaff.java index 3476a1e206944fdc5b81516a29c21d319fc6448f..8deabe15f777d9506ea9e0d793cd8f650c360a68 100644 --- a/opp/core/src/main/java/OPStaff.java +++ b/opp/core/src/main/java/OPStaff.java @@ -13,25 +13,25 @@ public record OPStaff( /** * OPStaff commands */ - public static sealed interface Command permits OPStaff.CreateOPStaff, OPStaff.DeleteOPStaff, OPStaff.UpdateOPStaff { } + public static sealed interface Command permits Create, Delete, Update { } /** * Create command to create a new Operation * @param role if the Personal is a surgeon or an assistant * @param specialty the hospital specialties */ - public static record CreateOPStaff( + public static record Create( Role role, Specialty specialty ) implements Command {} - public static record UpdateOPStaff( + public static record Update( Id<OPStaff> id, Optional<Role> role, Optional<Specialty> specialty ) implements Command {} - public static record DeleteOPStaff( + public static record Delete( Id<OPStaff> id ) implements Command {} diff --git a/opp/core/src/main/java/OPStaffService.java b/opp/core/src/main/java/OPStaffService.java index bde0fb8275ba7c5583e12824fa7a8de0fbb60ca0..5159832112ead9bbfd5d8758dc0e069eb6f4d0d0 100644 --- a/opp/core/src/main/java/OPStaffService.java +++ b/opp/core/src/main/java/OPStaffService.java @@ -20,6 +20,6 @@ public interface OPStaffService { */ public Optional<OPStaff> getOPStaff(Id<OPStaff> id); - public List<OPStaff> getOPStaffs(); + public List<OPStaff> getAllOPStaffs(); } \ No newline at end of file diff --git a/opp/core/src/main/java/OPStaffServiceImpl.java b/opp/core/src/main/java/OPStaffServiceImpl.java index 87065af74edfa2bb6becf5ac36407675d29ccc03..b725b2244f61bbf1cc9ae510315d375c03579f96 100644 --- a/opp/core/src/main/java/OPStaffServiceImpl.java +++ b/opp/core/src/main/java/OPStaffServiceImpl.java @@ -13,13 +13,13 @@ public class OPStaffServiceImpl implements OPStaffService{ @Override public OPStaff process(OPStaff.Command cmd) throws Exception { return switch (cmd){ - case OPStaff.CreateOPStaff cr -> create(cr); - case OPStaff.UpdateOPStaff up -> update(up); - case OPStaff.DeleteOPStaff del -> delete(del); + case OPStaff.Create cr -> create(cr); + case OPStaff.Update up -> update(up); + case OPStaff.Delete del -> delete(del); }; } - public OPStaff create(OPStaff.CreateOPStaff cr) throws Exception { + public OPStaff create(OPStaff.Create cr) throws Exception { OPStaff opStaff = new OPStaff( repo.opStaffId(), @@ -32,7 +32,7 @@ public class OPStaffServiceImpl implements OPStaffService{ return opStaff; } - public OPStaff update(OPStaff.UpdateOPStaff up) throws Exception{ + public OPStaff update(OPStaff.Update up) throws Exception{ OPStaff currentOPStaff = repo.findOPStaff(up.id()).get(); OPStaff opStaff = @@ -47,19 +47,20 @@ public class OPStaffServiceImpl implements OPStaffService{ return opStaff; } - public OPStaff delete(OPStaff.DeleteOPStaff del) throws Exception{ + public OPStaff delete(OPStaff.Delete del) throws Exception{ return repo.deleteOPStaff(del.id()); } + @Override public Optional<OPStaff> getOPStaff(Id<OPStaff> id) { return repo.findOPStaff(id); } - public List<OPStaff> getOPStaffs(){ - return repo.findOPStaffs(); + public List<OPStaff> getAllOPStaffs(){ + return repo.findAllOPStaffs(); } diff --git a/opp/core/src/main/java/Repository.java b/opp/core/src/main/java/Repository.java index 6b4b527e6bc6fd14ae3d6592204893da38dba54d..f2e6766660638296c50cd661dc6abef14581fd80 100644 --- a/opp/core/src/main/java/Repository.java +++ b/opp/core/src/main/java/Repository.java @@ -71,7 +71,7 @@ public interface Repository { Optional<OPStaff> findOPStaff(Id<OPStaff> id); - List<OPStaff> findOPStaffs(); + List<OPStaff> findAllOPStaffs(); OPStaff deleteOPStaff(Id<OPStaff> id) throws SQLException; diff --git a/opp/core/src/main/java/Specialty.java b/opp/core/src/main/java/Specialty.java index 4a48eed6aaa122d2505684453dacef7ae93da4e3..62c9515ddeb9feaa6d6a2524c93311ed5274eb90 100644 --- a/opp/core/src/main/java/Specialty.java +++ b/opp/core/src/main/java/Specialty.java @@ -1,6 +1,6 @@ public enum Specialty { - Orthopedics, - cardiology, - urology, - Gastroenterology + ORTHOPEDICS, + CARDIOLOGY, + UROLOGY, + GASTROENTEROLOGY } diff --git a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java index b1ead71cdc5ce064fb46084560b60bc7ab782631..da68b162418cc3c525fee2e529d36a1ae3a3d863 100644 --- a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java +++ b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java @@ -501,7 +501,7 @@ class JDBCRepository implements Repository * @return all opStaffs */ @Override - public List<OPStaff> findOPStaffs(){ + public List<OPStaff> findAllOPStaffs(){ try ( var result = conn.createStatement() diff --git a/opp/jdbc-repo-impl/src/test/java/Tests.java b/opp/jdbc-repo-impl/src/test/java/Tests.java index dc127866ab256d512af4788ab27efc2eb78b8880..c36e746eee448b84623852d9b473e84a4a283304 100644 --- a/opp/jdbc-repo-impl/src/test/java/Tests.java +++ b/opp/jdbc-repo-impl/src/test/java/Tests.java @@ -8,6 +8,7 @@ import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import static org.junit.Assert.*; @@ -33,10 +34,6 @@ public final class Tests private static OperationTeamService operationTeamService; - private static TeamMember testTeamMember = null; - - private static TeamMemberService teamMemberService; - @BeforeClass public static void init() throws Exception { @@ -53,7 +50,7 @@ public final class Tests testOPStaff = new OPStaff( new Id<>("opStaff1111"), Role.ASSISTANT, - Specialty.urology, + Specialty.UROLOGY, Instant.now() ); @@ -83,14 +80,6 @@ public final class Tests operationTeamService = new OperationTeamImpl(repo); - testTeamMember = new TeamMember( - testOperationTeam.id(), - testOPStaff.id(), - Instant.now() - ); - - teamMemberService = new TeamMemberImpl(repo); - } @Test @@ -165,6 +154,8 @@ public final class Tests @Test public void testCreateOperation() throws Exception { + repo.save(testOperationTeam); + Operation.Create createCommand = new Operation.Create( LocalDate.of(2025, 5, 11), LocalTime.of(10, 30, 0), @@ -183,6 +174,7 @@ public final class Tests @Test public void testUpdateOperation() throws Exception { + repo.save(testOperationTeam); repo.save(testOperation); Operation.Update updateCommand = new Operation.Update( @@ -214,6 +206,7 @@ public final class Tests @Test public void testDeleteOperation() throws Exception { + repo.save(testOperationTeam); repo.save(testOperation); Operation.Delete deleteCommand = new Operation.Delete( @@ -225,15 +218,20 @@ public final class Tests assertFalse(repo.findOperation(deleteOperation.id()).isPresent()); } - @Ignore @Test public void testGetOperation() throws Exception { + repo.save(testOperationTeam); repo.save(testOperation); Optional<Operation> readOperation = operationService.getOperation(testOperation.id()); if (readOperation.isPresent()) { - assertEquals(testOperation, readOperation.get()); + assertEquals(testOperation.id(), readOperation.get().id()); + assertEquals(testOperation.date(), readOperation.get().date()); + assertEquals(testOperation.startTime(), readOperation.get().startTime()); + assertEquals(testOperation.endTime(), readOperation.get().endTime()); + assertEquals(testOperation.patientId(), readOperation.get().patientId()); + assertEquals(testOperation.operationTeamId(), readOperation.get().operationTeamId()); } else { throw new Exception(); } @@ -242,6 +240,7 @@ public final class Tests @Test public void testGetOperations() throws Exception { + repo.save(testOperationTeam); repo.save(testOperation); LocalDate testDate = LocalDate.of(2024, 5, 24); @@ -256,222 +255,208 @@ public final class Tests } } - -@Ignore - @Test - public void testAssignStaffToOperationTeam() throws Exception { - - repo.save(testOperationTeam); - repo.save(testOPStaff); - - Boolean result = repo.assignOPStaffToOperationTeam(testOperationTeam.id(), testOPStaff.id()); - - assertTrue(result); - } - @Test - public void testAssignStaffToOperationTeamProcess() throws Exception { - - OPStaff.CreateOPStaff createOPStaffCommand = new OPStaff.CreateOPStaff( - Role.SURGEON, - Specialty.Gastroenterology - ); + public void testRepoOPStaffSave(){ - OPStaff createdOPStaff = opStaffService.process(createOPStaffCommand); + try { + repo.save(testOPStaff); + } catch (Exception e){ + e.printStackTrace(); + } - OperationTeam.AssignStaff operationTeamCommand = new OperationTeam.AssignStaff( - testOperationTeam.id(), - createdOPStaff + assertTrue( + repo.findOPStaff(testOPStaff.id()).isPresent() ); - - OperationTeam returnedOperationTeam = operationTeamService.process(operationTeamCommand); - - Boolean result = repo.findOperationTeamOPStaffImpl(returnedOperationTeam.id(),createdOPStaff.id()); - - assertTrue(result); } + @Test + public void testRepoOPStaffUpdate() throws Exception { - - //@Test - public void testCreateOPStaff_1() { try { repo.save(testOPStaff); } catch (Exception e){ e.printStackTrace(); } - } - //@Test - public void testCreateOPStaff_2() throws Exception { - OPStaff.CreateOPStaff createCommand = new OPStaff.CreateOPStaff( + OPStaff updatedTestOPStaff = new OPStaff( + testOPStaff.id(), Role.SURGEON, - Specialty.cardiology + testOPStaff.specialty(), + Instant.now() ); - OPStaff createOPStaff = opStaffService.process(createCommand); - } - - //@Test - public void testGetOPStaff() { - - try{ - var id = new Id<OPStaff>("3333"); - Optional<OPStaff> opStaff = opStaffService.getOPStaff(id); - System.out.println(opStaff); + try { + repo.save(updatedTestOPStaff); } catch (Exception e){ e.printStackTrace(); } - //assertEquals(operation.date(), testDate); - } - - //@Test //getting all the OPStaffs - public void testGetOPStaffs() { - try{ - List<OPStaff> opStaff = opStaffService.getOPStaffs(); - - for(OPStaff opStaff1 : opStaff){ - System.out.println(opStaff1); - } + Optional<OPStaff> readOPStaff = repo.findOPStaff(updatedTestOPStaff.id()); + if (readOPStaff.isPresent()) { + assertNotEquals(readOPStaff.get().role(), testOPStaff.role()); + assertNotEquals(readOPStaff.get().lastUpdate(), testOPStaff.lastUpdate()); + } else { + throw new Exception(); + } + } + @Test + public void testRepoOPStaffDelete() { + try { + repo.save(testOPStaff); } catch (Exception e){ e.printStackTrace(); } - //assertEquals(operation.date(), testDate); + + try { + repo.deleteOPStaff(testOPStaff.id()); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + assertFalse(repo.findOPStaff(testOPStaff.id()).isPresent()); } - //@Test - public void testUpdateOPStaff() throws Exception{ + @Test + public void testCreateOPStaff() throws Exception { - OPStaff.UpdateOPStaff updateCommand = new OPStaff.UpdateOPStaff( - testOPStaff.id(), - Optional.empty(), - Optional.of(Specialty.Orthopedics) + OPStaff.Create createCommand = new OPStaff.Create( + Role.ASSISTANT, + Specialty.GASTROENTEROLOGY ); - OPStaff updateOPStaff = opStaffService.process(updateCommand); + OPStaff createdOPStaff = opStaffService.process(createCommand); + assertTrue( + repo.findOPStaff(createdOPStaff.id()).isPresent() + ); } - //@Test - public void testDeleteOPStaff() throws Exception{ + @Test + public void testUpdateOPStaff() throws Exception { - var id = new Id<OPStaff>("b940de7b-a9a3-40e5-b465-12b018390061"); + repo.save(testOPStaff); - OPStaff.DeleteOPStaff deleteCommand = new OPStaff.DeleteOPStaff( - id + OPStaff.Update updateCommand = new OPStaff.Update( + testOPStaff.id(), + Optional.empty(), + Optional.of(Specialty.CARDIOLOGY) ); - OPStaff deleteOPStaff = opStaffService.process(deleteCommand); + OPStaff updatedOperation = opStaffService.process(updateCommand); - } + Optional<OPStaff> readOPStaff = repo.findOPStaff(updatedOperation.id()); - //@Test - public void testCreateOperationTeam() throws Exception{ + if (readOPStaff.isPresent()) { + assertNotEquals(readOPStaff.get().specialty(), testOPStaff.specialty()); - try { - repo.save(testOperationTeam); - } catch (Exception e){ - e.printStackTrace(); + assertEquals(readOPStaff.get().role(), testOPStaff.role()); + + assertNotEquals(readOPStaff.get().lastUpdate(), testOPStaff.lastUpdate()); + } else { + throw new Exception(); } } - //@Test - public void testDeleteOperationTeam() throws Exception{ + @Test + public void testDeleteOPStaff() throws Exception { - var id = new Id<OperationTeam>("1212"); + repo.save(testOPStaff); - OperationTeam.DeleteTeam deleteCommand = new OperationTeam.DeleteTeam( - id + OPStaff.Delete deleteCommand = new OPStaff.Delete( + testOPStaff.id() ); - OperationTeam deleteOperationTeam = operationTeamService.process(deleteCommand); - } + OPStaff deletedOPStaff = opStaffService.process(deleteCommand); - //@Test - public void testInsertTeamMember1() throws Exception{ + assertFalse(repo.findOPStaff(deletedOPStaff.id()).isPresent()); + } - TeamMember.AssignStaff assignCommand = new TeamMember.AssignStaff( - new Id<OperationTeam>("31"), - new Id<OPStaff>("4444") - ); + @Test + public void testGetOPStaff() throws Exception { + repo.save(testOPStaff); - TeamMember assignStaff = teamMemberService.process(assignCommand); + Optional<OPStaff> readOPStaff = opStaffService.getOPStaff(testOPStaff.id()); - /*try { - repo.saveTeamMember(testTeamMember); - } catch (Exception e){ - e.printStackTrace(); - }*/ + if (readOPStaff.isPresent()) { + assertEquals(testOPStaff.id(), readOPStaff.get().id()); + assertEquals(testOPStaff.role(), readOPStaff.get().role()); + assertEquals(testOPStaff.specialty(), readOPStaff.get().specialty()); + } else { + throw new Exception(); + } } - @Test - public void testRemoveopStaffsInOperationTeams() throws Exception{ - - OperationTeam.RemoveStaff removeStaffCommand= new OperationTeam.RemoveStaff( - testOperationTeam.id(), - testOPStaff - ); - - OperationTeam removedTeam = operationTeamService.process(removeStaffCommand); + public void testGetOPStaffs() throws Exception { - assertEquals(testOperationTeam.id().value(), removedTeam.id().value()); - } + repo.save(testOPStaff); - //@Test - public void testGetOperationTeam() throws Exception{ + OPStaff testOPStaff2 = new OPStaff( + new Id<>("opStaff2222"), + Role.ASSISTANT, + Specialty.CARDIOLOGY, + Instant.now()); - var id = new Id<OperationTeam>("31"); + repo.save(testOPStaff2); - try{ - Optional<OperationTeam> operationTeam = operationTeamService.getOperationTeam(id); + List<OPStaff> opStaffs = opStaffService.getAllOPStaffs(); - //for(OPStaff opStaff1 : opStaff){ - System.out.println(operationTeam); - //} + List<OPStaff> filteredList = opStaffs.stream() + .filter(opStaff -> Objects.equals(opStaff.id().value(), testOPStaff.id().value()) || Objects.equals(opStaff.id().value(), testOPStaff2.id().value())) + .toList(); - } catch (Exception e){ - e.printStackTrace(); - } + assertEquals(2, filteredList.size()); } - //@Test - public void testGetMultipleOperationTeams() throws Exception{ - + @Ignore + @Test + public void testAssignStaffToOperationTeam() throws Exception { - try{ - List<OperationTeam> operationTeam = operationTeamService.getOperationTeams(); + repo.save(testOperationTeam); + repo.save(testOPStaff); - for(OperationTeam operationTeam1 : operationTeam){ - System.out.println(operationTeam1); - } + Boolean result = repo.assignOPStaffToOperationTeam(testOperationTeam.id(), testOPStaff.id()); - } catch (Exception e){ - e.printStackTrace(); - } + assertTrue(result); } - //@Test - public void testGetTeamMemberFromTeam() throws Exception{ + @Ignore + @Test + public void testAssignStaffToOperationTeamProcess() throws Exception { - var id = new Id<OperationTeam>("31"); + OPStaff.Create createOPStaffCommand = new OPStaff.Create( + Role.SURGEON, + Specialty.GASTROENTEROLOGY + ); - try{ - List<OPStaff> opStaff = teamMemberService.getOperationTeamOPStaff(id); + OPStaff createdOPStaff = opStaffService.process(createOPStaffCommand); - for(OPStaff opStaffs1 : opStaff){ - System.out.println(opStaffs1); - } + OperationTeam.AssignStaff operationTeamCommand = new OperationTeam.AssignStaff( + testOperationTeam.id(), + createdOPStaff + ); - } catch (Exception e){ - e.printStackTrace(); - } + OperationTeam returnedOperationTeam = operationTeamService.process(operationTeamCommand); + + Boolean result = repo.findOperationTeamOPStaffImpl(returnedOperationTeam.id(),createdOPStaff.id()); + + assertTrue(result); } + @Ignore + @Test + public void testRemoveOPStaffsInOperationTeams() throws Exception{ + OperationTeam.RemoveStaff removeStaffCommand= new OperationTeam.RemoveStaff( + testOperationTeam.id(), + testOPStaff + ); + OperationTeam removedTeam = operationTeamService.process(removeStaffCommand); + + assertEquals(testOperationTeam.id().value(), removedTeam.id().value()); + } }