diff --git a/opp/core/src/main/java/Gender.java b/opp/core/src/main/java/Gender.java index 986e6895e75fae933bdccdb116aecce11ffe3d05..be02c28a918b62b38e13cd196669f3c3e6df8c79 100644 --- a/opp/core/src/main/java/Gender.java +++ b/opp/core/src/main/java/Gender.java @@ -2,5 +2,5 @@ public enum Gender { MALE, FEMALE, OTHER, - UNKNOWN; + UNKNOWN } diff --git a/opp/core/src/main/java/OPStaff.java b/opp/core/src/main/java/OPStaff.java index 8deabe15f777d9506ea9e0d793cd8f650c360a68..e0c45fb4bae45e753891cb0a4e8bbd81ce4b4d65 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 Create, Delete, Update { } + public 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 Create( + public record Create( Role role, Specialty specialty ) implements Command {} - public static record Update( + public record Update( Id<OPStaff> id, Optional<Role> role, Optional<Specialty> specialty ) implements Command {} - public static record Delete( + public 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 5159832112ead9bbfd5d8758dc0e069eb6f4d0d0..762e4407eaaeb23449e85a5995ea5ab3ec4db524 100644 --- a/opp/core/src/main/java/OPStaffService.java +++ b/opp/core/src/main/java/OPStaffService.java @@ -11,15 +11,15 @@ public interface OPStaffService { * @param cmd the command to process * @return the processed OPStaff */ - public OPStaff process(OPStaff.Command cmd) throws Exception; + OPStaff process(OPStaff.Command cmd) throws Exception; /** * Gets the Operation by ID * @param id the ID of the OPStaff * @return the OPStaff */ - public Optional<OPStaff> getOPStaff(Id<OPStaff> id); + Optional<OPStaff> getOPStaff(Id<OPStaff> id); - public List<OPStaff> getAllOPStaffs(); + 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 b725b2244f61bbf1cc9ae510315d375c03579f96..f3b67efcf1b0ed29c7939cb068a84e58ae4e9dff 100644 --- a/opp/core/src/main/java/OPStaffServiceImpl.java +++ b/opp/core/src/main/java/OPStaffServiceImpl.java @@ -33,16 +33,22 @@ public class OPStaffServiceImpl implements OPStaffService{ } public OPStaff update(OPStaff.Update up) throws Exception{ - OPStaff currentOPStaff = repo.findOPStaff(up.id()).get(); - OPStaff opStaff = - new OPStaff( - currentOPStaff.id(), - up.role().orElse(currentOPStaff.role()), - up.specialty().orElse((currentOPStaff.specialty())), - Instant.now() - ); - repo.save(opStaff); + Optional<OPStaff> foundOPStaff = repo.findOPStaff(up.id()); + + OPStaff opStaff = null; + if (foundOPStaff.isPresent()) { + OPStaff currentOPStaff = foundOPStaff.get(); + + opStaff = + new OPStaff( + currentOPStaff.id(), + up.role().orElse(currentOPStaff.role()), + up.specialty().orElse((currentOPStaff.specialty())), + Instant.now() + ); + repo.save(opStaff); + } return opStaff; } @@ -58,7 +64,7 @@ public class OPStaffServiceImpl implements OPStaffService{ return repo.findOPStaff(id); } - + @Override public List<OPStaff> getAllOPStaffs(){ return repo.findAllOPStaffs(); } diff --git a/opp/core/src/main/java/OperationService.java b/opp/core/src/main/java/OperationService.java index a3cb26389370b4161d380c674f31edffe2caaccb..f0c474d7ae70a824a4191b3a3c436449267e8e2d 100644 --- a/opp/core/src/main/java/OperationService.java +++ b/opp/core/src/main/java/OperationService.java @@ -11,19 +11,19 @@ public interface OperationService { * @param cmd the command to process * @return the processed Operation */ - public Operation process(Operation.Command cmd) throws Exception; + Operation process(Operation.Command cmd) throws Exception; /** * Gets the Operation by ID * @param id the ID of the Operation * @return the Operation */ - public Optional<Operation> getOperation(Id<Operation> id); + Optional<Operation> getOperation(Id<Operation> id); /** * Gets a list of Operations that are matching the filter * @param filter the filter to match * @return the matching Operations */ - public List<Operation> getOperations(Operation.Filter filter); + List<Operation> getOperations(Operation.Filter filter); } diff --git a/opp/core/src/main/java/OperationServiceImpl.java b/opp/core/src/main/java/OperationServiceImpl.java index 20ea47df336adbf16b1e74e03eb7e41df76508e3..5d21f74ba4f29e6a3c918ed538fefa95dfbb6689 100644 --- a/opp/core/src/main/java/OperationServiceImpl.java +++ b/opp/core/src/main/java/OperationServiceImpl.java @@ -51,19 +51,24 @@ public class OperationServiceImpl implements OperationService { public Operation update(Operation.Update up) throws Exception { - Operation currentOperation = repo.findOperation(up.id()).get(); - - Operation operation = - new Operation( - currentOperation.id(), - up.date().orElse(currentOperation.date()), - up.startTime().orElse(currentOperation.startTime()), - up.endTime().orElse(currentOperation.endTime()), - up.patientId().orElse(currentOperation.patientId()), - up.operationTeamId().orElse(currentOperation.operationTeamId()), - Instant.now()); - - repo.save(operation); + Optional<Operation> foundOperation = repo.findOperation(up.id()); + + Operation operation = null; + if (foundOperation.isPresent()) { + Operation currentOperation = foundOperation.get(); + + operation = + new Operation( + currentOperation.id(), + up.date().orElse(currentOperation.date()), + up.startTime().orElse(currentOperation.startTime()), + up.endTime().orElse(currentOperation.endTime()), + up.patientId().orElse(currentOperation.patientId()), + up.operationTeamId().orElse(currentOperation.operationTeamId()), + Instant.now()); + + repo.save(operation); + } return operation; } diff --git a/opp/core/src/main/java/OperationTeam.java b/opp/core/src/main/java/OperationTeam.java index 4f7cf921e71ff5f57b039ed195338f6eff8a27b2..090adc55d1221c914687721058c4612131b8b6ef 100644 --- a/opp/core/src/main/java/OperationTeam.java +++ b/opp/core/src/main/java/OperationTeam.java @@ -8,30 +8,30 @@ public record OperationTeam( Instant lastUpdate ) { - public static sealed interface Command permits - CreateTeam, - DeleteTeam, + public sealed interface Command permits + Create, + Delete, AssignStaff, RemoveStaff {} - public static record CreateTeam( + public record Create( String teamName, List<OPStaff> opStaffs ) implements Command {} - public static record DeleteTeam( + public record Delete( Id<OperationTeam> operationTeamId ) implements Command {} - public static record AssignStaff( + public record AssignStaff( Id<OperationTeam> operationTeamId, - OPStaff opStaff + Id<OPStaff> opStaffId ) implements Command {} - public static record RemoveStaff( + public record RemoveStaff( Id<OperationTeam> operationTeamId, - OPStaff opStaff + Id<OPStaff> opStaffId ) implements Command {} } diff --git a/opp/core/src/main/java/OperationTeamImpl.java b/opp/core/src/main/java/OperationTeamImpl.java index 83073d2f118ae541def50d909c7e1dd53e3ab353..5305756c6dac43de643aa59c265b5c37f7d768e1 100644 --- a/opp/core/src/main/java/OperationTeamImpl.java +++ b/opp/core/src/main/java/OperationTeamImpl.java @@ -15,32 +15,49 @@ public class OperationTeamImpl implements OperationTeamService{ @Override public OperationTeam process(OperationTeam.Command cmd) throws Exception { return switch(cmd){ - case OperationTeam.CreateTeam cr -> create(cr); - case OperationTeam.DeleteTeam del -> delete(del); + case OperationTeam.Create cr -> create(cr); + case OperationTeam.Delete del -> delete(del); case OperationTeam.AssignStaff as -> assignStaff(as); case OperationTeam.RemoveStaff rs -> removeStaff(rs); }; } - private OperationTeam delete(OperationTeam.DeleteTeam del) throws SQLException { + private OperationTeam delete(OperationTeam.Delete del) throws SQLException { return repo.deleteOperationTeam(del.operationTeamId()); } - private OperationTeam create(OperationTeam.CreateTeam cr) { - OperationTeam operationTeam = - new OperationTeam( - repo.operationTeamId(), - cr.opStaffs(), - cr.teamName(), - Instant.now() - ); + //Only creates a connection between the newly created operationTeam and the already existing opStaffs. + //Does not save the opStaffs included in operationTeam to database. + private OperationTeam create(OperationTeam.Create cr) throws Exception { + + Id<OperationTeam> generatedOperationTeamId = repo.operationTeamId(); + OperationTeam operationTeam = new OperationTeam( + generatedOperationTeamId, + cr.opStaffs(), + cr.teamName(), + Instant.now() + ); + + repo.save(operationTeam); + + for(OPStaff opstaff : cr.opStaffs()) { + repo.assignOPStaffToOperationTeam(generatedOperationTeamId, opstaff.id()); + } + return operationTeam; } - private OperationTeam assignStaff(OperationTeam.AssignStaff as) { + private OperationTeam assignStaff(OperationTeam.AssignStaff as) throws Exception { + + OPStaff opStaffToAssign = repo.findOPStaff(as.opStaffId()).get(); + + OperationTeam operationTeamToAssignStaff = repo.findOperationTeam(as.operationTeamId()).get(); - if (repo.assignOPStaffToOperationTeam(as.operationTeamId(), as.opStaff().id())) { - return repo.findOperationTeam(as.operationTeamId()).get(); + // Add Staff to OperationTeam Object and save it into database + if(repo.assignOPStaffToOperationTeam(as.operationTeamId(), as.opStaffId())) { + operationTeamToAssignStaff.opStaffs().add(opStaffToAssign); + //repo.save(operationTeamToAssignStaff); + return operationTeamToAssignStaff; } else { return null; } @@ -50,14 +67,14 @@ public class OperationTeamImpl implements OperationTeamService{ OperationTeam findOperationTeam = repo.getOperationTeam(rs.operationTeamId()); - if(repo.removeopStaffsInOperationTeams(rs.operationTeamId(), rs.opStaff().id())){ + if(repo.removeOPStaffInOperationTeam(rs.operationTeamId(), rs.opStaffId())){ return findOperationTeam; } return null; } @Override - public List<OperationTeam> getOperationTeams() throws SQLException { + public List<OperationTeam> getAllOperationTeams() throws SQLException { return repo.findOperationTeams(); } diff --git a/opp/core/src/main/java/OperationTeamService.java b/opp/core/src/main/java/OperationTeamService.java index 4a77bbdcb379cc75a67c447d48dea6fcbdb72b12..88d3ae2f2b43156dd371045e2319fbb7a9691ce3 100644 --- a/opp/core/src/main/java/OperationTeamService.java +++ b/opp/core/src/main/java/OperationTeamService.java @@ -8,6 +8,6 @@ public interface OperationTeamService { public Optional<OperationTeam> getOperationTeam(Id<OperationTeam> operationTeamId) throws SQLException; - public List<OperationTeam> getOperationTeams() throws SQLException; + public List<OperationTeam> getAllOperationTeams() throws SQLException; } diff --git a/opp/core/src/main/java/Patient.java b/opp/core/src/main/java/Patient.java index 6f1bce5076019427bec4b19d5879d3023b19b0ea..50b70ff06e476470308033049879b7de1e597a79 100644 --- a/opp/core/src/main/java/Patient.java +++ b/opp/core/src/main/java/Patient.java @@ -1,5 +1,3 @@ -import java.time.LocalDate; - public record Patient ( Id<Patient> id ) { diff --git a/opp/core/src/main/java/Repository.java b/opp/core/src/main/java/Repository.java index f2e6766660638296c50cd661dc6abef14581fd80..65b87c926e06c922bad6e09720cac0af70e1a60a 100644 --- a/opp/core/src/main/java/Repository.java +++ b/opp/core/src/main/java/Repository.java @@ -1,6 +1,5 @@ import java.sql.SQLException; import java.util.List; -import java.util.Map; import java.util.Optional; public interface Repository { @@ -92,22 +91,10 @@ public interface Repository { OperationTeam getOperationTeam(Id<OperationTeam> id); - //Id<String> opStaffsInOperationTeamsId(); - - //Optional<Map<OperationTeam, OPStaff>> findOPStaffsInOperationTeam(Id<String> id); Boolean assignOPStaffToOperationTeam(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId); - Boolean findOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId); - - - - - - Id<TeamMember> teamMemberId(); - - TeamMember saveTeamMember(TeamMember TeamMember) throws Exception; + Boolean removeOPStaffInOperationTeam(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId) throws Exception; - Boolean removeopStaffsInOperationTeams(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId) throws Exception; - List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId); + Boolean findOperationTeamOPStaff(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId); } diff --git a/opp/core/src/main/java/TeamMember.java b/opp/core/src/main/java/TeamMember.java deleted file mode 100644 index 75255504a308038d0c3c817a5a6f2c4f7d21e606..0000000000000000000000000000000000000000 --- a/opp/core/src/main/java/TeamMember.java +++ /dev/null @@ -1,24 +0,0 @@ -import java.time.Instant; - -public record TeamMember( - - Id<OperationTeam> operationTeamId, - - Id<OPStaff> opStaffId, - - Instant lastUpdate -) { - - public sealed interface Command permits TeamMember.AssignStaff, TeamMember.RemoveStaff{} - - public static record AssignStaff( - Id<OperationTeam> operationTeamId, - Id<OPStaff> opStaffId - ) implements TeamMember.Command {} - - public static record RemoveStaff( - Id<OperationTeam> operationTeamId, - Id<OPStaff> opStaffId - ) implements TeamMember.Command {} - -} diff --git a/opp/core/src/main/java/TeamMemberImpl.java b/opp/core/src/main/java/TeamMemberImpl.java deleted file mode 100644 index a2cdd6f83ee3d8e2467e697c64c7cf2478a913c5..0000000000000000000000000000000000000000 --- a/opp/core/src/main/java/TeamMemberImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -import java.time.Instant; -import java.util.List; - -public class TeamMemberImpl implements TeamMemberService{ - - private final Repository repo; - - public TeamMemberImpl(Repository repo) { - this.repo = repo; - } - - public TeamMember process(TeamMember.Command cmd) throws Exception { - return switch(cmd){ - case TeamMember.AssignStaff as -> assignStaffimpl(as); - case TeamMember.RemoveStaff rs -> removeStaffimpl(rs); - }; - } - - @Override - public List<OPStaff> getOperationTeamOPStaff(Id<OperationTeam> operationTeamId) { - return repo.getOperationTeamOPStaffImpl(operationTeamId); - } - - private TeamMember assignStaffimpl(TeamMember.AssignStaff as) throws Exception { - TeamMember teammember = - new TeamMember( - as.operationTeamId(), - as.opStaffId(), - Instant.now() - ); - return repo.saveTeamMember(teammember); - } - - - - private TeamMember removeStaffimpl(TeamMember.RemoveStaff rs) throws Exception { - return null; //repo.removeTeamMember(rs.operationTeamId(), rs.opStaffId()); - - } -} diff --git a/opp/core/src/main/java/TeamMemberService.java b/opp/core/src/main/java/TeamMemberService.java deleted file mode 100644 index ac7320163584f98d9c8e818f5e86fad7848fb3bf..0000000000000000000000000000000000000000 --- a/opp/core/src/main/java/TeamMemberService.java +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.List; - -public interface TeamMemberService { - - public TeamMember process(TeamMember.Command cmd) throws Exception; - - List<OPStaff> getOperationTeamOPStaff(Id<OperationTeam> operationTeamId); -} diff --git a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java index da68b162418cc3c525fee2e529d36a1ae3a3d863..ed90a19e108a2ca189476faf3a7f2c5d90d44f6b 100644 --- a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java +++ b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java @@ -253,23 +253,6 @@ class JDBCRepository implements Repository ");"; } - /** - * Creates the insert statement of the given teamMember for SQL. - * @param teamMember the operationTeam to turn into an insert SQL statement - * @return the SQL statement - */ - private static String insertSQL(TeamMember teamMember){ - return - "INSERT INTO opStaffsInOperationTeams(" + - "operationTeamId,opStaffId,lastUpdate" + - ") VALUES (" + - sqlValue(teamMember.operationTeamId()) + "," + - sqlValue(teamMember.opStaffId()) + "," + - sqlValue(teamMember.lastUpdate()) + - ");"; - } - //INSERT INTO opStaffsInOperationTeams ("operationteamid","opstaffid","lastupdate") VALUES ('31','4444','2024-06-21 20:55:39.991047'); - /** * Creates an Operation object with the given result of a read SQL-Row. * @param rs the result of a read SQL-Row @@ -634,13 +617,13 @@ class JDBCRepository implements Repository throw new RuntimeException(e); } } -//.executeQuery("SELECT * FROM operationTeams WHERE id = " + sqlValue(id.value()) + ";") + @Override public List<OperationTeam> findOperationTeams() { try( var result = conn.createStatement() - .executeQuery("SELECT * FROM operationTeams;"); + .executeQuery("SELECT * FROM operationTeams;") ) { var operationTeams = new ArrayList<OperationTeam>(); @@ -720,13 +703,16 @@ class JDBCRepository implements Repository } }*/ + //TODO Check what exactly happens when assigning the same staff to the same team twice. @Override public Boolean assignOPStaffToOperationTeam(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId) { try ( var stmt = conn.createStatement() ){ var sql = - findOperationTeam(operationTeamId).isPresent() && findOPStaff(opStaffId).isPresent() ? + findOperationTeam(operationTeamId).isPresent() && + findOPStaff(opStaffId).isPresent() && + !findOperationTeamOPStaff(operationTeamId, opStaffId) ? insertSQL(operationTeamId, opStaffId) : null; @@ -742,48 +728,14 @@ class JDBCRepository implements Repository } } - /** - * Returns a new generated ID in the teammember-SQLTable - * If the generated ID is already used, generate another one. - * @return teammemberID - */ @Override - public Id<TeamMember> teamMemberId() { - - return new Id<TeamMember>(randomUUID().toString()); //TODO findOperation(id).isEmpty() ? id : operationId(); - } - - public TeamMember saveTeamMember(TeamMember TeamMember) throws Exception{ + public Boolean removeOPStaffInOperationTeam(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId) throws Exception{ try( var stmt = conn.createStatement() ){ - //TODO - /*var sql = - findOPStaff(opStaff.id()).isPresent() ? - updateOPStaffSQL(opStaff) : - insertOPStaffSQL(opStaff);*/ - var sql = insertSQL(TeamMember); - - stmt.executeUpdate(sql); - - }catch(SQLException e){ - throw new RuntimeException(e); - } - return TeamMember; - } - - public Boolean removeopStaffsInOperationTeams(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId) throws Exception{ - - try( - var stmt = conn.createStatement() - ){ - //TODO - /*var sql = - findOPStaff(opStaff.id()).isPresent() ? - updateOPStaffSQL(opStaff) : - insertOPStaffSQL(opStaff);*/ - var sql = "DELETE FROM opStaffsInOperationTeams WHERE operationTeamId = '"+ operationTeamId.value() +"' AND opStaffId = '"+opStaffId.value()+"';"; + var sql = "DELETE FROM opStaffsInOperationTeams WHERE operationTeamId = " + quoted(operationTeamId.value()) + + " AND opStaffId = " + quoted(opStaffId.value()) + ";"; stmt.executeUpdate(sql); @@ -795,33 +747,25 @@ class JDBCRepository implements Repository } @Override - public List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId){ + public Boolean findOperationTeamOPStaff(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId){ try( var result = conn.createStatement() - .executeQuery("SELECT DISTINCT opStaffs.id, opStaffs.role, opStaffs.specialty, opStaffs.lastupdate " + - "FROM opStaffs " + - "JOIN opStaffsInOperationTeams " + - "ON (opStaffs.id = opStaffsInOperationTeams.opstaffid) " + - "WHERE opStaffsInOperationTeams.operationteamid = '"+operationTeamId.value()+"';"); - //SELECT DISTINCT opStaffs.id, opStaffs.role, opStaffs.specialty, opStaffs.lastupdate FROM opStaffs JOIN opStaffsInOperationTeams ON (opStaffs.id = '4444') WHERE opStaffsInOperationTeams.operationteamid = '31';S + .executeQuery("SELECT * " + + "FROM opStaffsInOperationTeams " + + "WHERE opStaffsInOperationTeams.operationTeamId = " + quoted(operationTeamId.value()) + " " + + "AND opStaffsInOperationTeams.opStaffId = " + quoted(opStaffId.value()) + ";") ) { - //SELECT DISTINCT opstaff.id, opstaff.role, opstaff.specialty, opstaff.lastupdate, teammember.operationteamid FROM opstaff JOIN teammember ON (opstaff.id = teammember.opstaffid); - //SELECT DISTINCT opstaff.id, opstaff.role, opstaff.specialty, opstaff.lastupdate, teammember.operationteamid FROM opstaff JOIN teammember ON (opstaff.id = teammember.opstaffid) WHERE teammember.operationteamid= '31313131'; - var opStaffs = new ArrayList<OPStaff>(); - - while (result.next()) { - opStaffs.add(readOPStaffFromRow(result)); - } - return opStaffs; + return result.next(); }catch(SQLException e){ throw new RuntimeException(e); } } - - public Boolean findOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId){ + /* + @Override + public List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId){ try( var result = @@ -830,21 +774,22 @@ class JDBCRepository implements Repository "FROM opStaffs " + "JOIN opStaffsInOperationTeams " + "ON (opStaffs.id = opStaffsInOperationTeams.opstaffid) " + - "WHERE opStaffsInOperationTeams.operationteamid = '"+operationTeamId.value()+"'" + - "AND opStaffsInOperationTeams.opStaffId = '"+opStaffId.value()+"';"); + "WHERE opStaffsInOperationTeams.operationteamid = '"+operationTeamId.value()+"';"); //SELECT DISTINCT opStaffs.id, opStaffs.role, opStaffs.specialty, opStaffs.lastupdate FROM opStaffs JOIN opStaffsInOperationTeams ON (opStaffs.id = '4444') WHERE opStaffsInOperationTeams.operationteamid = '31';S ) { //SELECT DISTINCT opstaff.id, opstaff.role, opstaff.specialty, opstaff.lastupdate, teammember.operationteamid FROM opstaff JOIN teammember ON (opstaff.id = teammember.opstaffid); //SELECT DISTINCT opstaff.id, opstaff.role, opstaff.specialty, opstaff.lastupdate, teammember.operationteamid FROM opstaff JOIN teammember ON (opstaff.id = teammember.opstaffid) WHERE teammember.operationteamid= '31313131'; + var opStaffs = new ArrayList<OPStaff>(); while (result.next()) { - return true; + opStaffs.add(readOPStaffFromRow(result)); } - return false; + return opStaffs; }catch(SQLException e){ throw new RuntimeException(e); } } + */ //endregion diff --git a/opp/jdbc-repo-impl/src/test/java/Tests.java b/opp/jdbc-repo-impl/src/test/java/Tests.java index c36e746eee448b84623852d9b473e84a4a283304..290461dd2e01f8590426ca1f7f73ee694898dac3 100644 --- a/opp/jdbc-repo-impl/src/test/java/Tests.java +++ b/opp/jdbc-repo-impl/src/test/java/Tests.java @@ -26,11 +26,13 @@ public final class Tests private static OperationService operationService; - private static OPStaff testOPStaff = null; + private static OPStaff testOPStaff1 = null; + private static OPStaff testOPStaff2 = null; private static OPStaffService opStaffService; - private static OperationTeam testOperationTeam = null; + private static OperationTeam testOperationTeam1 = null; + private static OperationTeam testOperationTeam2 = null; private static OperationTeamService operationTeamService; @@ -47,20 +49,34 @@ public final class Tests new Id<>("patient1111") ); - testOPStaff = new OPStaff( + testOPStaff1 = new OPStaff( new Id<>("opStaff1111"), Role.ASSISTANT, Specialty.UROLOGY, Instant.now() ); + testOPStaff2 = new OPStaff( + new Id<>("opStaff2222"), + Role.ASSISTANT, + Specialty.CARDIOLOGY, + Instant.now()); + List<OPStaff> opStaffList = new ArrayList<>(); - opStaffList.add(testOPStaff); + opStaffList.add(testOPStaff1); + opStaffList.add(testOPStaff2); - testOperationTeam = new OperationTeam( + testOperationTeam1 = new OperationTeam( new Id<>("operationTeam1111"), opStaffList, - ("Cool"), + ("Team1"), + Instant.now() + ); + + testOperationTeam2 = new OperationTeam( + new Id<>("operationTeam2222"), + opStaffList, + ("Team2"), Instant.now() ); @@ -70,7 +86,7 @@ public final class Tests LocalTime.of(13, 35, 0), LocalTime.of(14, 0, 0), testPatient.id(), - testOperationTeam.id(), + testOperationTeam1.id(), Instant.now() ); @@ -86,7 +102,7 @@ public final class Tests public void testRepoOperationSave(){ try { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); } catch (Exception e){ e.printStackTrace(); @@ -101,7 +117,7 @@ public final class Tests public void testRepoOperationUpdate() throws Exception { try { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); } catch (Exception e){ e.printStackTrace(); @@ -135,7 +151,7 @@ public final class Tests @Test public void testRepoOperationDelete() { try { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); } catch (Exception e){ e.printStackTrace(); @@ -154,14 +170,14 @@ public final class Tests @Test public void testCreateOperation() throws Exception { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); Operation.Create createCommand = new Operation.Create( LocalDate.of(2025, 5, 11), LocalTime.of(10, 30, 0), LocalTime.of(11, 0, 0), testPatient.id(), - testOperationTeam.id() + testOperationTeam1.id() ); Operation createdOperation = operationService.process(createCommand); @@ -174,7 +190,7 @@ public final class Tests @Test public void testUpdateOperation() throws Exception { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); Operation.Update updateCommand = new Operation.Update( @@ -206,7 +222,7 @@ public final class Tests @Test public void testDeleteOperation() throws Exception { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); Operation.Delete deleteCommand = new Operation.Delete( @@ -220,7 +236,7 @@ public final class Tests @Test public void testGetOperation() throws Exception { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); Optional<Operation> readOperation = operationService.getOperation(testOperation.id()); @@ -240,7 +256,7 @@ public final class Tests @Test public void testGetOperations() throws Exception { - repo.save(testOperationTeam); + repo.save(testOperationTeam1); repo.save(testOperation); LocalDate testDate = LocalDate.of(2024, 5, 24); @@ -259,13 +275,13 @@ public final class Tests public void testRepoOPStaffSave(){ try { - repo.save(testOPStaff); + repo.save(testOPStaff1); } catch (Exception e){ e.printStackTrace(); } assertTrue( - repo.findOPStaff(testOPStaff.id()).isPresent() + repo.findOPStaff(testOPStaff1.id()).isPresent() ); } @@ -273,15 +289,15 @@ public final class Tests public void testRepoOPStaffUpdate() throws Exception { try { - repo.save(testOPStaff); + repo.save(testOPStaff1); } catch (Exception e){ e.printStackTrace(); } OPStaff updatedTestOPStaff = new OPStaff( - testOPStaff.id(), + testOPStaff1.id(), Role.SURGEON, - testOPStaff.specialty(), + testOPStaff1.specialty(), Instant.now() ); @@ -293,8 +309,8 @@ public final class Tests Optional<OPStaff> readOPStaff = repo.findOPStaff(updatedTestOPStaff.id()); if (readOPStaff.isPresent()) { - assertNotEquals(readOPStaff.get().role(), testOPStaff.role()); - assertNotEquals(readOPStaff.get().lastUpdate(), testOPStaff.lastUpdate()); + assertNotEquals(readOPStaff.get().role(), testOPStaff1.role()); + assertNotEquals(readOPStaff.get().lastUpdate(), testOPStaff1.lastUpdate()); } else { throw new Exception(); } @@ -303,18 +319,18 @@ public final class Tests @Test public void testRepoOPStaffDelete() { try { - repo.save(testOPStaff); + repo.save(testOPStaff1); } catch (Exception e){ e.printStackTrace(); } try { - repo.deleteOPStaff(testOPStaff.id()); + repo.deleteOPStaff(testOPStaff1.id()); } catch (SQLException e) { throw new RuntimeException(e); } - assertFalse(repo.findOPStaff(testOPStaff.id()).isPresent()); + assertFalse(repo.findOPStaff(testOPStaff1.id()).isPresent()); } @Test @@ -335,10 +351,10 @@ public final class Tests @Test public void testUpdateOPStaff() throws Exception { - repo.save(testOPStaff); + repo.save(testOPStaff1); OPStaff.Update updateCommand = new OPStaff.Update( - testOPStaff.id(), + testOPStaff1.id(), Optional.empty(), Optional.of(Specialty.CARDIOLOGY) ); @@ -348,11 +364,11 @@ public final class Tests Optional<OPStaff> readOPStaff = repo.findOPStaff(updatedOperation.id()); if (readOPStaff.isPresent()) { - assertNotEquals(readOPStaff.get().specialty(), testOPStaff.specialty()); + assertNotEquals(readOPStaff.get().specialty(), testOPStaff1.specialty()); - assertEquals(readOPStaff.get().role(), testOPStaff.role()); + assertEquals(readOPStaff.get().role(), testOPStaff1.role()); - assertNotEquals(readOPStaff.get().lastUpdate(), testOPStaff.lastUpdate()); + assertNotEquals(readOPStaff.get().lastUpdate(), testOPStaff1.lastUpdate()); } else { throw new Exception(); } @@ -361,10 +377,10 @@ public final class Tests @Test public void testDeleteOPStaff() throws Exception { - repo.save(testOPStaff); + repo.save(testOPStaff1); OPStaff.Delete deleteCommand = new OPStaff.Delete( - testOPStaff.id() + testOPStaff1.id() ); OPStaff deletedOPStaff = opStaffService.process(deleteCommand); @@ -374,14 +390,14 @@ public final class Tests @Test public void testGetOPStaff() throws Exception { - repo.save(testOPStaff); + repo.save(testOPStaff1); - Optional<OPStaff> readOPStaff = opStaffService.getOPStaff(testOPStaff.id()); + Optional<OPStaff> readOPStaff = opStaffService.getOPStaff(testOPStaff1.id()); if (readOPStaff.isPresent()) { - assertEquals(testOPStaff.id(), readOPStaff.get().id()); - assertEquals(testOPStaff.role(), readOPStaff.get().role()); - assertEquals(testOPStaff.specialty(), readOPStaff.get().specialty()); + assertEquals(testOPStaff1.id(), readOPStaff.get().id()); + assertEquals(testOPStaff1.role(), readOPStaff.get().role()); + assertEquals(testOPStaff1.specialty(), readOPStaff.get().specialty()); } else { throw new Exception(); } @@ -390,56 +406,196 @@ public final class Tests @Test public void testGetOPStaffs() throws Exception { - repo.save(testOPStaff); - - OPStaff testOPStaff2 = new OPStaff( - new Id<>("opStaff2222"), - Role.ASSISTANT, - Specialty.CARDIOLOGY, - Instant.now()); + repo.save(testOPStaff1); repo.save(testOPStaff2); List<OPStaff> opStaffs = opStaffService.getAllOPStaffs(); List<OPStaff> filteredList = opStaffs.stream() - .filter(opStaff -> Objects.equals(opStaff.id().value(), testOPStaff.id().value()) || Objects.equals(opStaff.id().value(), testOPStaff2.id().value())) + .filter(opStaff -> Objects.equals(opStaff.id().value(), testOPStaff1.id().value()) || Objects.equals(opStaff.id().value(), testOPStaff2.id().value())) .toList(); assertEquals(2, filteredList.size()); } + @Test + public void testRepoOperationTeamAssignStaff(){ + + try { + repo.save(testOperationTeam1); + for(OPStaff opStaff : testOperationTeam1.opStaffs()) { + repo.save(opStaff); + repo.assignOPStaffToOperationTeam(testOperationTeam1.id(), opStaff.id()); + } + } catch (Exception e){ + e.printStackTrace(); + } + + assertTrue( + repo.findOperationTeam(testOperationTeam1.id()).isPresent() + ); + + for(OPStaff opStaff : testOperationTeam1.opStaffs()) { + assertTrue(repo.findOperationTeamOPStaff(testOperationTeam1.id(), opStaff.id())); + } + } + + @Test + public void testCreateOperationTeam() throws Exception { + + OperationTeam.Create createCommand = new OperationTeam.Create( + "Team33", + testOperationTeam1.opStaffs() + ); + + OperationTeam createdOperationTeam = operationTeamService.process(createCommand); + + assertTrue( + repo.findOperationTeam(createdOperationTeam.id()).isPresent() + ); + for(OPStaff opStaff : createdOperationTeam.opStaffs()) { + assertTrue(repo.findOperationTeamOPStaff(createdOperationTeam.id(), opStaff.id())); + } + } + @Ignore @Test - public void testAssignStaffToOperationTeam() throws Exception { + public void testRepoOperationTeamUpdate() throws Exception { - repo.save(testOperationTeam); - repo.save(testOPStaff); + try { + repo.save(testOPStaff1); + repo.save(testOPStaff2); + repo.save(testOperationTeam1); + repo.assignOPStaffToOperationTeam(testOperationTeam1.id(), testOPStaff1.id()); + repo.assignOPStaffToOperationTeam(testOperationTeam1.id(), testOPStaff2.id()); + } catch (Exception e){ + e.printStackTrace(); + } - Boolean result = repo.assignOPStaffToOperationTeam(testOperationTeam.id(), testOPStaff.id()); + OperationTeam updatedTestOperationTeam = new OperationTeam( + testOperationTeam1.id(), + testOperationTeam1.opStaffs(), + "team22", + Instant.now() + ); - assertTrue(result); + try { + repo.save(updatedTestOperationTeam); + } catch (Exception e){ + e.printStackTrace(); + } + + Optional<OperationTeam> readOperationTeam = repo.findOperationTeam(updatedTestOperationTeam.id()); + if (readOperationTeam.isPresent()) { + assertNotEquals(readOperationTeam.get().teamName(), testOperationTeam1.teamName()); + assertNotEquals(readOperationTeam.get().lastUpdate(), testOperationTeam1.lastUpdate()); + } else { + throw new Exception(); + } } @Ignore @Test - public void testAssignStaffToOperationTeamProcess() throws Exception { + public void testRepoOperationTeamDelete() { + try { + repo.save(testOPStaff1); + repo.save(testOPStaff2); + repo.save(testOperationTeam1); + repo.assignOPStaffToOperationTeam(testOperationTeam1.id(), testOPStaff1.id()); + repo.assignOPStaffToOperationTeam(testOperationTeam1.id(), testOPStaff2.id()); + } catch (Exception e){ + e.printStackTrace(); + } - OPStaff.Create createOPStaffCommand = new OPStaff.Create( - Role.SURGEON, - Specialty.GASTROENTEROLOGY + try { + repo.deleteOperationTeam(testOperationTeam1.id()); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + assertFalse(repo.findOperationTeam(testOperationTeam1.id()).isPresent()); + } + + @Ignore + @Test + public void testDeleteOperationTeam() throws Exception { + + repo.save(testOperationTeam1); + + OperationTeam.Delete deleteCommand = new OperationTeam.Delete( + testOperationTeam1.id() ); - OPStaff createdOPStaff = opStaffService.process(createOPStaffCommand); + OperationTeam deletedOperationTeam = operationTeamService.process(deleteCommand); + + assertFalse(repo.findOperationTeam(deletedOperationTeam.id()).isPresent()); + } + + @Ignore + @Test + public void testGetOperationTeam() throws Exception { + repo.save(testOperationTeam1); + + Optional<OperationTeam> readOperationTeam = operationTeamService.getOperationTeam(testOperationTeam1.id()); + + if (readOperationTeam.isPresent()) { + assertEquals(testOperationTeam1.id(), readOperationTeam.get().id()); + assertEquals(testOperationTeam1.teamName(), readOperationTeam.get().teamName()); + + for(int i = 0; i < readOperationTeam.get().opStaffs().size(); i++) { + assertEquals(testOperationTeam1.opStaffs().get(i).id(), readOperationTeam.get().opStaffs().get(i).id()); + } + } else { + throw new Exception(); + } + } + + @Ignore + @Test + public void testGetOperationTeams() throws Exception { + + repo.save(testOperationTeam1); + + repo.save(testOperationTeam2); + + List<OperationTeam> operationTeams = operationTeamService.getAllOperationTeams(); + + List<OperationTeam> filteredList = operationTeams.stream() + .filter(operationTeam -> Objects.equals(operationTeam.id().value(), testOperationTeam1.id().value()) || + Objects.equals(operationTeam.id().value(), testOperationTeam2.id().value())) + .toList(); + + assertEquals(2, filteredList.size()); + } + + @Ignore + @Test + public void testRepoAssignStaffToOperationTeam() throws Exception { + + repo.save(testOperationTeam1); + repo.save(testOPStaff1); + + Boolean result = repo.assignOPStaffToOperationTeam(testOperationTeam1.id(), testOPStaff1.id()); + + assertTrue(result); + } + + @Ignore + @Test + public void testAssignStaffToOperationTeam() throws Exception { + + repo.save(testOperationTeam1); + repo.save(testOPStaff1); - OperationTeam.AssignStaff operationTeamCommand = new OperationTeam.AssignStaff( - testOperationTeam.id(), - createdOPStaff + OperationTeam.AssignStaff assignStaffCommand = new OperationTeam.AssignStaff( + testOperationTeam1.id(), + testOPStaff1.id() ); - OperationTeam returnedOperationTeam = operationTeamService.process(operationTeamCommand); + OperationTeam assignedStaffOperationTeam = operationTeamService.process(assignStaffCommand); - Boolean result = repo.findOperationTeamOPStaffImpl(returnedOperationTeam.id(),createdOPStaff.id()); + Boolean result = repo.findOperationTeamOPStaff(assignedStaffOperationTeam.id(), testOPStaff1.id()); assertTrue(result); } @@ -449,13 +605,13 @@ public final class Tests public void testRemoveOPStaffsInOperationTeams() throws Exception{ OperationTeam.RemoveStaff removeStaffCommand= new OperationTeam.RemoveStaff( - testOperationTeam.id(), - testOPStaff + testOperationTeam1.id(), + testOPStaff1.id() ); OperationTeam removedTeam = operationTeamService.process(removeStaffCommand); - assertEquals(testOperationTeam.id().value(), removedTeam.id().value()); + assertEquals(testOperationTeam1.id().value(), removedTeam.id().value()); } }