private String getSendDateOrDefault(Referral referral) { if (referral.getSentDate() == null) { return DateUtil.getCurrentDateAsText(); } else { return DateUtil.convertTimestampToStringDate(referral.getSentDate()); } }
private ReferralItem getReferralItem(Referral referral) { boolean allReferralResultsHaveResults = true; List<ReferralResult> referralResults = referralResultDAO.getReferralResultsForReferral(referral.getId()); for (ReferralResult referralResult : referralResults) { if (referralResult.getResult() == null || GenericValidator.isBlankOrNull(referralResult.getResult().getValue())) { allReferralResultsHaveResults = false; break; } } if (allReferralResultsHaveResults) { return null; } ReferralItem referralItem = new ReferralItem(); AnalysisService analysisService = new AnalysisService(referral.getAnalysis()); referralItem.setCanceled(false); referralItem.setReferredResultType("N"); referralItem.setAccessionNumber(analysisService.getOrderAccessionNumber()); TypeOfSample typeOfSample = analysisService.getTypeOfSample(); referralItem.setSampleType(typeOfSample.getLocalizedName()); referralItem.setReferringTestName( TestService.getUserLocalizedTestName(analysisService.getAnalysis().getTest())); List<Result> resultList = analysisService.getResults(); String resultString = ""; if (!resultList.isEmpty()) { Result result = resultList.get(0); resultString = getAppropriateResultValue(resultList); referralItem.setInLabResultId(result.getId()); } referralItem.setReferralId(referral.getId()); if (!referralResults.isEmpty()) { referralResults = setReferralItemForNextTest(referralItem, referralResults); if (!referralResults.isEmpty()) { referralItem.setAdditionalTests(getAdditionalReferralTests(referralResults)); } } referralItem.setReferralResults(resultString); referralItem.setReferralDate(DateUtil.convertTimestampToStringDate(referral.getRequestDate())); referralItem.setReferredSendDate(getSendDateOrDefault(referral)); referralItem.setReferrer(referral.getRequesterName()); referralItem.setReferralReasonId(referral.getReferralReasonId()); referralItem.setTestSelectionList(getTestsForTypeOfSample(typeOfSample)); referralItem.setReferralId(referral.getId()); if (referral.getOrganization() != null) { referralItem.setReferredInstituteId(referral.getOrganization().getId()); } String notes = analysisService.getNotesAsString(true, true, "<br/>", false); if (notes != null) { referralItem.setPastNotes(notes); } return referralItem; }