@Override protected void createReportParameters() { super.createReportParameters(); reportParameters.put("activityLabel", getActivityLabel()); reportParameters.put( "accessionPrefix", AccessionNumberUtil.getAccessionNumberValidator().getPrefix()); reportParameters.put( "labNumberTitle", StringUtil.getContextualMessageForKey("quick.entry.accession.number")); reportParameters.put( "labName", ConfigurationProperties.getInstance().getPropertyValue(Property.SiteName)); reportParameters.put("siteLogo", getSiteLogo()); reportParameters.put("SUBREPORT_DIR", reportPath); reportParameters.put("startDate", dateRange.getLowDateStr()); reportParameters.put("endDate", dateRange.getHighDateStr()); reportParameters.put("isReportByTest", isReportByTest()); }
public abstract class RejectionReport extends Report implements IReportCreator { private int PREFIX_LENGTH = AccessionNumberUtil.getAccessionNumberValidator().getInvarientLength(); protected List<RejectionReportBean> rejections; protected String reportPath = ""; protected DateRange dateRange; @Override public JRDataSource getReportDataSource() throws IllegalStateException { return errorFound ? new JRBeanCollectionDataSource(errorMsgs) : new JRBeanCollectionDataSource(rejections); } @Override protected void createReportParameters() { super.createReportParameters(); reportParameters.put("activityLabel", getActivityLabel()); reportParameters.put( "accessionPrefix", AccessionNumberUtil.getAccessionNumberValidator().getPrefix()); reportParameters.put( "labNumberTitle", StringUtil.getContextualMessageForKey("quick.entry.accession.number")); reportParameters.put( "labName", ConfigurationProperties.getInstance().getPropertyValue(Property.SiteName)); reportParameters.put("siteLogo", getSiteLogo()); reportParameters.put("SUBREPORT_DIR", reportPath); reportParameters.put("startDate", dateRange.getLowDateStr()); reportParameters.put("endDate", dateRange.getHighDateStr()); reportParameters.put("isReportByTest", isReportByTest()); } protected boolean isReportByTest() { return Boolean.FALSE; } protected abstract String getActivityLabel(); protected abstract void buildReportContent(ReportSpecificationList testSelection); protected String getSiteLogo() { if (ConfigurationProperties.getInstance() .isPropertyValueEqual(Property.configurationName, "Haiti LNSP")) { return "images" + File.separator + "HaitiLNSP.jpg"; } return null; } @Override public void initializeReport(BaseActionForm dynaForm) { initialized = true; ReportSpecificationList selection = (ReportSpecificationList) dynaForm.get("selectList"); String lowDateStr = dynaForm.getString("lowerDateRange"); String highDateStr = dynaForm.getString("upperDateRange"); dateRange = new DateRange(lowDateStr, highDateStr); errorFound = !validateSubmitParameters(selection); if (errorFound) { return; } buildReportContent(selection); if (rejections.size() == 0) { add1LineErrorMessage("report.error.message.noPrintableItems"); } } private boolean validateSubmitParameters(ReportSpecificationList selectList) { return (dateRange.validateHighLowDate("report.error.message.date.received.missing") && validateSelection(selectList)); } private boolean validateSelection(ReportSpecificationList selectList) { boolean complete = !GenericValidator.isBlankOrNull(selectList.getSelection()) && !"0".equals(selectList.getSelection()); if (!complete) { add1LineErrorMessage("report.error.message.activity.missing"); } return complete; } protected RejectionReportBean createRejectionReportBean( String noteText, Analysis analysis, boolean useTestName) { RejectionReportBean item = new RejectionReportBean(); AnalysisService analysisService = new AnalysisService(analysis); SampleService sampleService = new SampleService(analysisService.getAnalysis().getSampleItem().getSample()); PatientService patientService = new PatientService(sampleService.getSample()); List<Result> results = analysisService.getResults(); for (Result result : results) { String signature = new ResultService(result).getSignature(); if (!GenericValidator.isBlankOrNull(signature)) { item.setTechnician(signature); break; } } item.setAccessionNumber(sampleService.getAccessionNumber().substring(PREFIX_LENGTH)); item.setReceivedDate(sampleService.getTwoYearReceivedDateForDisplay()); item.setCollectionDate( DateUtil.convertTimestampToTwoYearStringDate( analysisService.getAnalysis().getSampleItem().getCollectionDate())); item.setRejectionReason(noteText); StringBuilder nameBuilder = new StringBuilder(patientService.getLastName().toUpperCase()); if (!GenericValidator.isBlankOrNull(patientService.getNationalId())) { if (nameBuilder.length() > 0) { nameBuilder.append(" / "); } nameBuilder.append(patientService.getNationalId()); } if (useTestName) { item.setPatientOrTestName(analysisService.getTest().getLocalizedName()); item.setNonPrintingPatient(nameBuilder.toString()); } else { item.setPatientOrTestName(nameBuilder.toString()); } return item; } @Override protected String reportFileName() { return "RejectionReport"; } @Override protected String errorReportFileName() { return "HaitiNoticeOfReportError"; } protected RejectionReportBean createIdentityRejectionBean( RejectionReportBean item, boolean blankCollectionDate) { RejectionReportBean filler = new RejectionReportBean(); filler.setAccessionNumber(item.getAccessionNumber()); filler.setReceivedDate(item.getReceivedDate()); filler.setCollectionDate(blankCollectionDate ? " " : item.getCollectionDate()); filler.setPatientOrTestName(item.getNonPrintingPatient()); return filler; } protected String getNameForId(ReportSpecificationList list) { String selection = list.getSelection(); for (IdValuePair pair : list.getList()) { if (selection.equals(pair.getId())) { return pair.getValue(); } } return ""; } protected void injectPatientLineAndCopyToFinalList(ArrayList<RejectionReportBean> rawResults) { Collections.sort( rawResults, new Comparator<RejectionReportBean>() { @Override public int compare(RejectionReportBean o1, RejectionReportBean o2) { int sortResult = o1.getAccessionNumber().compareTo(o2.getAccessionNumber()); return sortResult == 0 ? o1.getPatientOrTestName().compareTo(o2.getPatientOrTestName()) : sortResult; } }); String currentAccessionNumber = ""; for (RejectionReportBean item : rawResults) { if (!currentAccessionNumber.equals(item.getAccessionNumber())) { rejections.add(createIdentityRejectionBean(item, false)); currentAccessionNumber = item.getAccessionNumber(); } item.setCollectionDate(null); rejections.add(item); } } }
public abstract class ActivityReport extends Report implements IReportCreator { private int PREFIX_LENGTH = AccessionNumberUtil.getAccessionNumberValidator().getInvarientLength(); protected List<ActivityReportBean> testsResults; protected String reportPath = ""; protected DateRange dateRange; @Override public JRDataSource getReportDataSource() throws IllegalStateException { return errorFound ? new JRBeanCollectionDataSource(errorMsgs) : new JRBeanCollectionDataSource(testsResults); } @Override protected void createReportParameters() { super.createReportParameters(); reportParameters.put("activityLabel", getActivityLabel()); reportParameters.put( "accessionPrefix", AccessionNumberUtil.getAccessionNumberValidator().getPrefix()); reportParameters.put( "labNumberTitle", StringUtil.getContextualMessageForKey("quick.entry.accession.number")); reportParameters.put( "labName", ConfigurationProperties.getInstance().getPropertyValue(Property.SiteName)); reportParameters.put("siteLogo", getSiteLogo()); reportParameters.put("SUBREPORT_DIR", reportPath); reportParameters.put("startDate", dateRange.getLowDateStr()); reportParameters.put("endDate", dateRange.getHighDateStr()); reportParameters.put("isReportByTest", isReportByTest()); } protected boolean isReportByTest() { return false; } protected abstract String getActivityLabel(); protected abstract void buildReportContent(ReportSpecificationList testSelection); protected String getSiteLogo() { if (ConfigurationProperties.getInstance() .isPropertyValueEqual(Property.configurationName, "Haiti LNSP")) { return "images" + File.separator + "HaitiLNSP.jpg"; } return null; } @Override public void initializeReport(BaseActionForm dynaForm) { initialized = true; ReportSpecificationList selection = (ReportSpecificationList) dynaForm.get("selectList"); String lowDateStr = dynaForm.getString("lowerDateRange"); String highDateStr = dynaForm.getString("upperDateRange"); dateRange = new DateRange(lowDateStr, highDateStr); errorFound = !validateSubmitParameters(selection); if (errorFound) { return; } buildReportContent(selection); if (testsResults.size() == 0) { add1LineErrorMessage("report.error.message.noPrintableItems"); } } private boolean validateSubmitParameters(ReportSpecificationList selectList) { return (dateRange.validateHighLowDate("report.error.message.date.received.missing") && validateSelection(selectList)); } private boolean validateSelection(ReportSpecificationList selectList) { boolean complete = !GenericValidator.isBlankOrNull(selectList.getSelection()) && !"0".equals(selectList.getSelection()); if (!complete) { add1LineErrorMessage("report.error.message.activity.missing"); } return complete; } protected ActivityReportBean createActivityReportBean(Result result, boolean useTestName) { ActivityReportBean item = new ActivityReportBean(); ResultService resultService = new ResultService(result); SampleService sampleService = new SampleService(result.getAnalysis().getSampleItem().getSample()); PatientService patientService = new PatientService(sampleService.getSample()); item.setResultValue(resultService.getResultValue("\n", true, true)); item.setTechnician(resultService.getSignature()); item.setAccessionNumber(sampleService.getAccessionNumber().substring(PREFIX_LENGTH)); item.setReceivedDate(sampleService.getReceivedDateWithTwoYearDisplay()); item.setResultDate(DateUtil.convertTimestampToTwoYearStringDate(result.getLastupdated())); item.setCollectionDate( DateUtil.convertTimestampToTwoYearStringDate( result.getAnalysis().getSampleItem().getCollectionDate())); List<String> values = new ArrayList<String>(); values.add( patientService.getLastName() == null ? "" : patientService.getLastName().toUpperCase()); values.add(patientService.getNationalId()); String referringPatientId = ObservationHistoryService.getValueForSample( ObservationType.REFERRERS_PATIENT_ID, sampleService.getSample().getId()); values.add(referringPatientId == null ? "" : referringPatientId); String name = StringUtil.buildDelimitedStringFromList(values, " / ", true); if (useTestName) { item.setPatientOrTestName(resultService.getTestName()); item.setNonPrintingPatient(name); } else { item.setPatientOrTestName(name); } return item; } @Override protected String reportFileName() { return "ActivityReport"; } @Override protected String errorReportFileName() { return "HaitiNoticeOfReportError"; } protected ActivityReportBean createIdentityActivityBean( ActivityReportBean item, boolean blankCollectionDate) { ActivityReportBean filler = new ActivityReportBean(); filler.setAccessionNumber(item.getAccessionNumber()); filler.setReceivedDate(item.getReceivedDate()); filler.setCollectionDate(blankCollectionDate ? " " : item.getCollectionDate()); filler.setPatientOrTestName(item.getNonPrintingPatient()); return filler; } protected String getNameForId(ReportSpecificationList list) { String selection = list.getSelection(); for (IdValuePair pair : list.getList()) { if (selection.equals(pair.getId())) { return pair.getValue(); } } return ""; } }