diff --git a/src/main/java/org/openelisglobal/testcalculated/action/util/TestCalculatedUtil.java b/src/main/java/org/openelisglobal/testcalculated/action/util/TestCalculatedUtil.java index 7548820830..035f050f84 100644 --- a/src/main/java/org/openelisglobal/testcalculated/action/util/TestCalculatedUtil.java +++ b/src/main/java/org/openelisglobal/testcalculated/action/util/TestCalculatedUtil.java @@ -113,20 +113,27 @@ public List addNewTestsToDBForCalculatedTests( map.put(Integer.valueOf(test.getId()), null); }); // insert innitial result value - map.put( - Integer.valueOf(resultSet.result.getTestResult().getTest().getId()), - Integer.valueOf(resultSet.result.getId())); + if (resultSet.result.getTestResult().getTest().getId() != null + && resultSet.result.getId() != null) { + map.put( + Integer.valueOf(resultSet.result.getTestResult().getTest().getId()), + Integer.valueOf(resultSet.result.getId())); + } calc.setTestResultMap(map); resultcalculationService.insert(calc); } } else { for (ResultCalculation resultCalculation : resultCalculations) { - resultCalculation - .getTestResultMap() - .put( - Integer.valueOf(resultSet.result.getTestResult().getTest().getId()), - Integer.valueOf(resultSet.result.getId())); + if (resultSet.result.getTestResult().getTest().getId() != null + && resultSet.result.getId() != null) { + resultCalculation + .getTestResultMap() + .put( + Integer.valueOf(resultSet.result.getTestResult().getTest().getId()), + Integer.valueOf(resultSet.result.getId())); + } + resultcalculationService.update(resultCalculation); } } @@ -181,7 +188,7 @@ public List addNewTestsToDBForCalculatedTests( function.append(number).append(" "); } } catch (NumberFormatException e) { - + } break; case MATH_FUNCTION: @@ -530,9 +537,18 @@ private Analysis createCalculatedAnalysis( generatedAnalysis.setSysUserId(systemUserId); generatedAnalysis.setResultCalculated(resultCalculated); if (existingAnalysis != null) { - analysisService.update(generatedAnalysis); + try { + analysisService.update(generatedAnalysis); + } catch (Exception e) { + return null; + } + } else { - analysisService.insert(generatedAnalysis); + try { + analysisService.insert(generatedAnalysis); + } catch (Exception e) { + return null; + } } if (resultCalculated) { createInternalNote( diff --git a/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java b/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java index 53a23c05f1..4d1088bfd1 100644 --- a/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java +++ b/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java @@ -704,8 +704,12 @@ private Optional addReflexTest( currentAnalysis.setSysUserId(sysUserId); currentAnalysis.setTriggeredReflex(Boolean.TRUE); - analysisService.insert(newAnalysis); - analysisService.update(currentAnalysis); + try { + analysisService.insert(newAnalysis); + analysisService.update(currentAnalysis); + } catch (Exception e) { + return Optional.empty(); + } List notes = new ArrayList<>(); notes.add(