private List<Result> createResultFromAnalysisItem( AnalysisItem analysisItem, AnalysisService analysisService, NoteService noteService) { ResultSaveBean bean = ResultSaveBeanAdapter.fromAnalysisItem(analysisItem); ResultSaveService resultSaveService = new ResultSaveService(analysisService.getAnalysis(), currentUserId); List<Result> results = resultSaveService.createResultsFromTestResultItem(bean, deletableList); if (analysisService.patientReportHasBeenDone() && resultSaveService.isUpdatedResult()) { analysisService.getAnalysis().setCorrectedSincePatientReport(true); noteUpdateList.add( noteService.createSavableNote( NoteType.EXTERNAL, StringUtil.getMessageForKey("note.corrected.result"), RESULT_SUBJECT, currentUserId)); } return results; }
@Override protected ActionForward performAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; List<IResultUpdate> updaters = ValidationUpdateRegister.getRegisteredUpdaters(); boolean areListeners = updaters != null && !updaters.isEmpty(); request.getSession().setAttribute(SAVE_DISABLED, "true"); BaseActionForm dynaForm = (BaseActionForm) form; ResultValidationPaging paging = new ResultValidationPaging(); paging.updatePagedResults(request, dynaForm); List<AnalysisItem> resultItemList = paging.getResults(request); String testSectionName = (String) dynaForm.get("testSection"); String testName = (String) dynaForm.get("testName"); setRequestType(testSectionName); ActionMessages errors = validateModifiedItems(resultItemList); if (errors.size() > 0) { saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); return mapping.findForward(FWD_VALIDATION_ERROR); } createSystemUser(); setSampleFinishedStatuses(); noteUpdateList = new ArrayList<Note>(); resultUpdateList = new ArrayList<Result>(); analysisUpdateList = new ArrayList<Analysis>(); modifiedResultSet = new ArrayList<ResultSet>(); newResultSet = new ArrayList<ResultSet>(); deletableList = new ArrayList<Result>(); if (testSectionName.equals("serology")) { createUpdateElisaList(resultItemList); } else { createUpdateList(resultItemList, areListeners); } Transaction tx = HibernateUtil.getSession().beginTransaction(); try { ResultSaveService.removeDeletedResultsInTransaction(deletableList, currentUserId); // update analysis for (Analysis analysis : analysisUpdateList) { analysisDAO.updateData(analysis); } for (Result result : resultUpdateList) { if (result.getId() != null) { resultDAO.updateData(result); } else { resultDAO.insertData(result); } } checkIfSamplesFinished(resultItemList); // update finished samples for (Sample sample : sampleUpdateList) { sampleDAO.updateData(sample); } // create or update notes for (Note note : noteUpdateList) { if (note != null) { if (note.getId() == null) { noteDAO.insertData(note); } else { noteDAO.updateData(note); } } } for (IResultUpdate updater : updaters) { updater.transactionalUpdate(this); } tx.commit(); } catch (LIMSRuntimeException lre) { tx.rollback(); } for (IResultUpdate updater : updaters) { updater.postTransactionalCommitUpdate(this); } if (isBlankOrNull(testSectionName)) { return mapping.findForward(forward); } else { Map<String, String> params = new HashMap<String, String>(); params.put("type", testSectionName); params.put("test", testName); params.put("forward", forward); return getForwardWithParameters(mapping.findForward(forward), params); } }