From 74cf74bfd2786d80e983254764ed653e54204cd5 Mon Sep 17 00:00:00 2001 From: David B Malkovsky Date: Sat, 9 Nov 2024 05:35:59 -0500 Subject: [PATCH] OP-1157 use enhanced switch (JDK 14) (#1447) --- .../java/org/isf/lab/manager/LabManager.java | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/isf/lab/manager/LabManager.java b/src/main/java/org/isf/lab/manager/LabManager.java index 7b24c2956..8dce0ef4f 100644 --- a/src/main/java/org/isf/lab/manager/LabManager.java +++ b/src/main/java/org/isf/lab/manager/LabManager.java @@ -218,19 +218,17 @@ public Laboratory newLaboratory(Laboratory laboratory, List 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"))); + }; } /** @@ -245,16 +243,12 @@ public Laboratory newLaboratory2(Laboratory laboratory, List 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"))); + }; } /** @@ -298,20 +292,19 @@ public Laboratory updateExamRequest(int code, String status) throws OHServiceExc public Laboratory updateLaboratory(Laboratory laboratory, List 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"))); + }; } /**