Skip to content

Commit

Permalink
OP-1157 use enhanced switch (JDK 14) (#1447)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmalkovsky authored Nov 9, 2024
1 parent 31e3b1d commit 74cf74b
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions src/main/java/org/isf/lab/manager/LabManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,17 @@ public Laboratory newLaboratory(Laboratory laboratory, List<String> labRow) thro
validateLaboratory(laboratory);
setPatientConsistency(laboratory);
procedure = laboratory.getExam().getProcedure();
switch (procedure) {
case 1:
return ioOperations.newLabFirstProcedure(laboratory);
case 2:
return switch (procedure) {
case 1 -> ioOperations.newLabFirstProcedure(laboratory);
case 2 -> {
if (labRow == null || labRow.isEmpty()) {
throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.labnew.someexamswithoutresultpleasecheck.msg")));
}
return ioOperations.newLabSecondProcedure(laboratory, labRow);
case 3:
return ioOperations.newLabFirstProcedure(laboratory);
default:
throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.lab.unknownprocedure.msg")));
}
yield ioOperations.newLabSecondProcedure(laboratory, labRow);
}
case 3 -> ioOperations.newLabFirstProcedure(laboratory);
default -> throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.lab.unknownprocedure.msg")));
};
}

/**
Expand All @@ -245,16 +243,12 @@ public Laboratory newLaboratory2(Laboratory laboratory, List<LaboratoryRow> labR
validateLaboratory(laboratory);
setPatientConsistency(laboratory);
procedure = laboratory.getExam().getProcedure();
switch (procedure) {
case 1:
return ioOperations.newLabFirstProcedure(laboratory);
case 2:
return ioOperations.newLabSecondProcedure2(laboratory, labRow);
case 3:
return ioOperations.newLabFirstProcedure(laboratory);
default:
throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.lab.unknownprocedure.msg")));
}
return switch (procedure) {
case 1 -> ioOperations.newLabFirstProcedure(laboratory);
case 2 -> ioOperations.newLabSecondProcedure2(laboratory, labRow);
case 3 -> ioOperations.newLabFirstProcedure(laboratory);
default -> throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.lab.unknownprocedure.msg")));
};
}

/**
Expand Down Expand Up @@ -298,20 +292,19 @@ public Laboratory updateExamRequest(int code, String status) throws OHServiceExc
public Laboratory updateLaboratory(Laboratory laboratory, List<String> labRow) throws OHServiceException {
validateLaboratory(laboratory);
Integer procedure = laboratory.getExam().getProcedure();
switch (procedure) {
case 1:
return ioOperations.updateLabFirstProcedure(laboratory);
case 2:
return switch (procedure) {
case 1 -> ioOperations.updateLabFirstProcedure(laboratory);
case 2 -> {
if (labRow == null || labRow.isEmpty()) {
throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.labnew.someexamswithoutresultpleasecheck.msg")));
}
return ioOperations.updateLabSecondProcedure(laboratory, labRow);
case 3:
yield ioOperations.updateLabSecondProcedure(laboratory, labRow);
}
case 3 ->
// TODO: is it enough to call FirstProcedure?
return ioOperations.updateLabFirstProcedure(laboratory);
default:
throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.lab.unknownprocedure.msg")));
}
ioOperations.updateLabFirstProcedure(laboratory);
default -> throw new OHDataValidationException(new OHExceptionMessage(MessageBundle.getMessage("angal.lab.unknownprocedure.msg")));
};
}

/**
Expand Down

0 comments on commit 74cf74b

Please sign in to comment.