From 2a93e62abb940b322fd7fd49937308e260cd2dc5 Mon Sep 17 00:00:00 2001 From: Andre Hartig <andre.hartig@student.reutlingen-university.de> Date: Fri, 28 Jun 2024 19:28:57 +0200 Subject: [PATCH] added comments and removed unnecessary classes. --- opp/core/src/main/java/Address.java | 7 --- opp/core/src/main/java/Gender.java | 6 --- opp/core/src/main/java/Id.java | 5 +++ opp/core/src/main/java/Operation.java | 44 ++++++++++++++++--- opp/core/src/main/java/OperationService.java | 16 +++---- .../src/main/java/OperationServiceImpl.java | 27 +++++++++++- 6 files changed, 76 insertions(+), 29 deletions(-) delete mode 100644 opp/core/src/main/java/Address.java delete mode 100644 opp/core/src/main/java/Gender.java diff --git a/opp/core/src/main/java/Address.java b/opp/core/src/main/java/Address.java deleted file mode 100644 index 4ba3cb7..0000000 --- a/opp/core/src/main/java/Address.java +++ /dev/null @@ -1,7 +0,0 @@ -public record Address( - String street, - String house, - String postalCode, - String city -) { -} diff --git a/opp/core/src/main/java/Gender.java b/opp/core/src/main/java/Gender.java deleted file mode 100644 index be02c28..0000000 --- a/opp/core/src/main/java/Gender.java +++ /dev/null @@ -1,6 +0,0 @@ -public enum Gender { - MALE, - FEMALE, - OTHER, - UNKNOWN -} diff --git a/opp/core/src/main/java/Id.java b/opp/core/src/main/java/Id.java index 8182ef8..5f212be 100644 --- a/opp/core/src/main/java/Id.java +++ b/opp/core/src/main/java/Id.java @@ -1,3 +1,8 @@ +/** + * Used to give each individual class it's id + * @param value the id + * @param <T> the class + */ public record Id<T>(String value) { @Override diff --git a/opp/core/src/main/java/Operation.java b/opp/core/src/main/java/Operation.java index 15ec5bd..1c086a3 100644 --- a/opp/core/src/main/java/Operation.java +++ b/opp/core/src/main/java/Operation.java @@ -9,6 +9,11 @@ import java.util.Optional; * @param date the planned date of the operation * @param startTime the planned starting time of the operation * @param endTime the planned ending time of the operation + * @param patientId the id of the patient + * @param operationTeamId the id of the operationTeam + * @param preparationNoteId the id of the preparationNote + * @param roomId the id of the room + * @param lastUpdate the last time this object was changed */ public record Operation( Id<Operation> id, @@ -17,6 +22,8 @@ public record Operation( LocalTime endTime, Id<Patient> patientId, Id<OperationTeam> operationTeamId, + Id<PreparationNote> preparationNoteId, + Id<Room> roomId, Instant lastUpdate ) { @@ -24,7 +31,7 @@ public record Operation( * Operation filter * @param date filter with date */ - public static final record Filter( + public record Filter( Optional<LocalDate> date ) { public static final Filter NONE = @@ -36,32 +43,55 @@ public record Operation( /** * Operation commands */ - public static sealed interface Command permits Create, Update, Delete { } + public sealed interface Command permits Create, Update, Delete { } /** * Create command to create a new Operation * @param date the date of the new Operation * @param startTime the starting time of the new Operation * @param endTime the ending time of the new Operation + * @param patientId the id of the patient + * @param operationTeamId the id of the operationTeam + * @param preparationNoteId the id of the preparationNote + * @param roomId the id of the room */ - public static record Create( + public record Create( LocalDate date, LocalTime startTime, LocalTime endTime, Id<Patient> patientId, - Id<OperationTeam> operationTeamId + Id<OperationTeam> operationTeamId, + Id<PreparationNote> preparationNoteId, + Id<Room> roomId ) implements Command {} - public static record Update( + /** + * Create command to update an already existing operation. + * @param id the id of the already existing operation + * @param date optional new date + * @param startTime optional new start time + * @param endTime optional new end time + * @param patientId optional new patient id + * @param operationTeamId optional new operation team + * @param preparationNoteId optional new preparation note + * @param roomId optional new room + */ + public record Update( Id<Operation> id, Optional<LocalDate> date, Optional<LocalTime> startTime, Optional<LocalTime> endTime, Optional<Id<Patient>> patientId, - Optional<Id<OperationTeam>> operationTeamId + Optional<Id<OperationTeam>> operationTeamId, + Optional<Id<PreparationNote>> preparationNoteId, + Optional<Id<Room>> roomId ) implements Command {} - public static record Delete( + /** + * Command to delete an existing operation + * @param id the id of the already existing operation + */ + public record Delete( Id<Operation> id ) implements Command {} diff --git a/opp/core/src/main/java/OperationService.java b/opp/core/src/main/java/OperationService.java index f0c474d..ef8949a 100644 --- a/opp/core/src/main/java/OperationService.java +++ b/opp/core/src/main/java/OperationService.java @@ -2,28 +2,28 @@ import java.util.List; import java.util.Optional; /** - * Available Services for Operations + * Available Services for operations */ public interface OperationService { /** - * Processes the possible commands for an Operation + * Processes the possible commands for an operation * @param cmd the command to process - * @return the processed Operation + * @return the processed operation */ Operation process(Operation.Command cmd) throws Exception; /** - * Gets the Operation by ID - * @param id the ID of the Operation - * @return the Operation + * Gets the operation by id + * @param id the id of the operation + * @return the operation */ Optional<Operation> getOperation(Id<Operation> id); /** - * Gets a list of Operations that are matching the filter + * Gets a list of operations that are matching the filter * @param filter the filter to match - * @return the matching Operations + * @return the matching operations */ 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 5d21f74..20c683e 100644 --- a/opp/core/src/main/java/OperationServiceImpl.java +++ b/opp/core/src/main/java/OperationServiceImpl.java @@ -9,11 +9,14 @@ public class OperationServiceImpl implements OperationService { private final Repository repo; + /** + * Initializes the repository to operate the services + * @param repo the repository to work with + */ public OperationServiceImpl(Repository repo) { this.repo = repo; } - @Override public Operation process(Operation.Command cmd) throws Exception { return switch (cmd){ @@ -33,6 +36,12 @@ public class OperationServiceImpl implements OperationService { return repo.findOperations(filter); } + /** + * Creates a new operation with the set parameters + * @param cr the create command that includes the parameters to create the operation with + * @return the created operation + * @throws Exception if the save in the repository failed + */ public Operation create(Operation.Create cr) throws Exception { Operation operation = new Operation( @@ -42,6 +51,8 @@ public class OperationServiceImpl implements OperationService { cr.endTime(), cr.patientId(), cr.operationTeamId(), + cr.preparationNoteId(), + cr.roomId(), Instant.now()); repo.save(operation); @@ -49,6 +60,12 @@ public class OperationServiceImpl implements OperationService { return operation; } + /** + * Updates an existing operation with the set parameters + * @param up the update command that includes the parameters to update the operation with + * @return the updated operation + * @throws Exception if the update in the repository failed + */ public Operation update(Operation.Update up) throws Exception { Optional<Operation> foundOperation = repo.findOperation(up.id()); @@ -65,6 +82,8 @@ public class OperationServiceImpl implements OperationService { up.endTime().orElse(currentOperation.endTime()), up.patientId().orElse(currentOperation.patientId()), up.operationTeamId().orElse(currentOperation.operationTeamId()), + up.preparationNoteId().orElse(currentOperation.preparationNoteId()), + up.roomId().orElse(currentOperation.roomId()), Instant.now()); repo.save(operation); @@ -73,6 +92,12 @@ public class OperationServiceImpl implements OperationService { return operation; } + /** + * Deletes an existing operation with the given id + * @param del the delete command that includes the id to delete the operation with + * @return the deleted operation + * @throws Exception if delete in the repository failed + */ public Operation delete(Operation.Delete del) throws Exception { return repo.deleteOperation(del.id()); -- GitLab