From 09767c22f9e8b766e71c5329552b6049bd7baec9 Mon Sep 17 00:00:00 2001 From: CalebSLane Date: Mon, 19 Aug 2024 11:36:31 -0700 Subject: [PATCH 1/4] add method to analysis --- .../analysis/service/AnalysisService.java | 2 + .../analysis/service/AnalysisServiceImpl.java | 5 + .../analysis/valueholder/Analysis.java | 11 + .../action/util/ResultsLoadUtility.java | 2 +- .../controller/LogbookResultsController.java | 14 +- .../rest/LogbookResultsRestController.java | 9 + .../resources/hibernate/hbm/Analysis.hbm.xml | 473 +++++++++--------- .../resources/hibernate/hbm/Method.hbm.xml | 12 +- src/main/resources/liquibase/2.8.x.x/base.xml | 1 + .../resources/liquibase/2.8.x.x/method.xml | 20 + 10 files changed, 310 insertions(+), 239 deletions(-) create mode 100644 src/main/resources/liquibase/2.8.x.x/method.xml diff --git a/src/main/java/org/openelisglobal/analysis/service/AnalysisService.java b/src/main/java/org/openelisglobal/analysis/service/AnalysisService.java index 434b04bb5a..989725665e 100644 --- a/src/main/java/org/openelisglobal/analysis/service/AnalysisService.java +++ b/src/main/java/org/openelisglobal/analysis/service/AnalysisService.java @@ -215,4 +215,6 @@ List getStudyAnalysisForSiteBetweenResultDates(String referringSiteId, int getCountOfAnalysisCompletedOnByStatusId(Date completedDate, List statusIds); int getCountOfAnalysisStartedOnByStatusId(Date startedDate, List statusIds); + + String getMethodId(Analysis analysis); } diff --git a/src/main/java/org/openelisglobal/analysis/service/AnalysisServiceImpl.java b/src/main/java/org/openelisglobal/analysis/service/AnalysisServiceImpl.java index eee9445de7..48ea706cab 100644 --- a/src/main/java/org/openelisglobal/analysis/service/AnalysisServiceImpl.java +++ b/src/main/java/org/openelisglobal/analysis/service/AnalysisServiceImpl.java @@ -772,4 +772,9 @@ public int getCountOfAnalysisStartedOnByStatusId(Date startedDate, List public List getAnalysesResultEnteredOnExcludedByStatusId(Date completedDate, Set statusIds) { return baseObjectDAO.getAnalysesResultEnteredOnExcludedByStatusId(completedDate, statusIds); } + + @Override + public String getMethodId(Analysis analysis) { + return analysis == null ? "" : analysis.getMethod() == null ? "" : analysis.getMethod().getId(); + } } diff --git a/src/main/java/org/openelisglobal/analysis/valueholder/Analysis.java b/src/main/java/org/openelisglobal/analysis/valueholder/Analysis.java index 14b4f9ce77..809f7f07a8 100644 --- a/src/main/java/org/openelisglobal/analysis/valueholder/Analysis.java +++ b/src/main/java/org/openelisglobal/analysis/valueholder/Analysis.java @@ -26,6 +26,7 @@ import org.openelisglobal.common.valueholder.BaseObject; import org.openelisglobal.common.valueholder.ValueHolder; import org.openelisglobal.common.valueholder.ValueHolderInterface; +import org.openelisglobal.method.valueholder.Method; import org.openelisglobal.note.service.NoteObject; import org.openelisglobal.note.service.NoteServiceImpl.BoundTo; import org.openelisglobal.panel.valueholder.Panel; @@ -81,6 +82,7 @@ public class Analysis extends BaseObject implements NoteObject { private String sampleTypeName; private List children; private boolean correctedSincePatientReport; + private ValueHolderInterface method; public Analysis() { super(); @@ -90,6 +92,7 @@ public Analysis() { parentAnalysis = new ValueHolder(); parentResult = new ValueHolder(); panel = new ValueHolder(); + method = new ValueHolder(); } @Override @@ -497,4 +500,12 @@ public UUID getFhirUuid() { public void setFhirUuid(UUID fhirUuid) { this.fhirUuid = fhirUuid; } + + public Method getMethod() { + return (Method) method.getValue(); + } + + public void setMethod(Method method) { + this.method.setValue(method); + } } diff --git a/src/main/java/org/openelisglobal/result/action/util/ResultsLoadUtility.java b/src/main/java/org/openelisglobal/result/action/util/ResultsLoadUtility.java index e241be673b..fa2463c184 100644 --- a/src/main/java/org/openelisglobal/result/action/util/ResultsLoadUtility.java +++ b/src/main/java/org/openelisglobal/result/action/util/ResultsLoadUtility.java @@ -703,8 +703,8 @@ private TestResultItem createTestResultItem(Analysis analysis, ResultInventory t testItem.setUnitsOfMeasure(uom); testItem.setTestDate(testDate); testItem.setResultDisplayType(resultDisplayType); - testItem.setTestMethod(testMethodName); testItem.setAnalysisMethod(analysisService.getAnalysisType(analysis)); + testItem.setTestMethod(analysisService.getMethodId(analysis)); testItem.setResult(result); testItem.setResultValue(getFormattedResultValue(result)); testItem.setMultiSelectResultValues(analysisService.getJSONMultiSelectResults(analysis)); diff --git a/src/main/java/org/openelisglobal/result/controller/LogbookResultsController.java b/src/main/java/org/openelisglobal/result/controller/LogbookResultsController.java index 642c1c056e..2b1d50e1b3 100644 --- a/src/main/java/org/openelisglobal/result/controller/LogbookResultsController.java +++ b/src/main/java/org/openelisglobal/result/controller/LogbookResultsController.java @@ -1,6 +1,5 @@ package org.openelisglobal.result.controller; -import com.fasterxml.jackson.databind.ObjectMapper; import java.lang.reflect.InvocationTargetException; import java.sql.Timestamp; import java.util.ArrayList; @@ -47,6 +46,7 @@ import org.openelisglobal.internationalization.MessageUtil; import org.openelisglobal.inventory.action.InventoryUtility; import org.openelisglobal.inventory.form.InventoryKitItem; +import org.openelisglobal.method.service.MethodService; import org.openelisglobal.note.service.NoteService; import org.openelisglobal.note.service.NoteServiceImpl.NoteType; import org.openelisglobal.note.valueholder.Note; @@ -143,6 +143,8 @@ public class LogbookResultsController extends LogbookResultsBaseController { private UserService userService; @Autowired private RoleService roleService; + @Autowired + private MethodService methodService; private final String RESULT_SUBJECT = "Result Note"; private final String REFERRAL_CONFORMATION_ID; @@ -335,10 +337,6 @@ public ModelAndView showLogbookResultsUpdate(HttpServletRequest request, boolean supportReferrals = FormFields.getInstance().useField(Field.ResultsReferral); String statusRuleSet = ConfigurationProperties.getInstance().getPropertyValueUpperCase(Property.StatusRules); - ObjectMapper mapper = new ObjectMapper(); - String jsonForm = ""; - List testResultItemList = form.getTestResult(); - // load testSections for drop down String resultsRoleId = roleService.getRoleByName(Constants.ROLE_RESULTS).getId(); List testSections = userService.getUserTestSections(getSysUserId(request), resultsRoleId); @@ -455,6 +453,9 @@ private void createAnalysisOnlyUpdates(ResultsUpdateDataSet actionDataSet) { if (testResultItem.getAnalysisMethod() != null) { analysis.setAnalysisType(testResultItem.getAnalysisMethod()); } + if (!GenericValidator.isBlankOrNull(testResultItem.getTestMethod())) { + analysis.setMethod(methodService.get(testResultItem.getTestMethod())); + } actionDataSet.getModifiedAnalysis().add(analysis); } } @@ -467,6 +468,9 @@ private void createResultsFromItems(ResultsUpdateDataSet actionDataSet, boolean Analysis analysis = analysisService.get(testResultItem.getAnalysisId()); analysis.setStatusId(getStatusForTestResult(testResultItem, alwaysValidate)); analysis.setSysUserId(getSysUserId(request)); + if (!GenericValidator.isBlankOrNull(testResultItem.getTestMethod())) { + analysis.setMethod(methodService.get(testResultItem.getTestMethod())); + } actionDataSet.getModifiedAnalysis().add(analysis); actionDataSet.addToNoteList(noteService.createSavableNote(analysis, NoteType.INTERNAL, diff --git a/src/main/java/org/openelisglobal/result/controller/rest/LogbookResultsRestController.java b/src/main/java/org/openelisglobal/result/controller/rest/LogbookResultsRestController.java index 0c2d6f4989..115fc39f43 100644 --- a/src/main/java/org/openelisglobal/result/controller/rest/LogbookResultsRestController.java +++ b/src/main/java/org/openelisglobal/result/controller/rest/LogbookResultsRestController.java @@ -47,6 +47,7 @@ import org.openelisglobal.internationalization.MessageUtil; import org.openelisglobal.inventory.action.InventoryUtility; import org.openelisglobal.inventory.form.InventoryKitItem; +import org.openelisglobal.method.service.MethodService; import org.openelisglobal.note.service.NoteService; import org.openelisglobal.note.service.NoteServiceImpl.NoteType; import org.openelisglobal.note.valueholder.Note; @@ -168,6 +169,8 @@ public class LogbookResultsRestController extends LogbookResultsBaseController { private UserRoleService userRoleService; @Autowired private SampleHumanService sampleHumanService; + @Autowired + private MethodService methodService; private final String RESULT_SUBJECT = "Result Note"; private final String REFERRAL_CONFORMATION_ID; @@ -512,6 +515,9 @@ private void createAnalysisOnlyUpdates(ResultsUpdateDataSet actionDataSet) { if (testResultItem.getAnalysisMethod() != null) { analysis.setAnalysisType(testResultItem.getAnalysisMethod()); } + if (!GenericValidator.isBlankOrNull(testResultItem.getTestMethod())) { + analysis.setMethod(methodService.get(testResultItem.getTestMethod())); + } actionDataSet.getModifiedAnalysis().add(analysis); } } @@ -524,6 +530,9 @@ private void createResultsFromItems(ResultsUpdateDataSet actionDataSet, boolean Analysis analysis = analysisService.get(testResultItem.getAnalysisId()); analysis.setStatusId(getStatusForTestResult(testResultItem, alwaysValidate)); analysis.setSysUserId(getSysUserId(request)); + if (!GenericValidator.isBlankOrNull(testResultItem.getTestMethod())) { + analysis.setMethod(methodService.get(testResultItem.getTestMethod())); + } actionDataSet.getModifiedAnalysis().add(analysis); actionDataSet.addToNoteList(noteService.createSavableNote(analysis, NoteType.INTERNAL, diff --git a/src/main/resources/hibernate/hbm/Analysis.hbm.xml b/src/main/resources/hibernate/hbm/Analysis.hbm.xml index 1a9fd255fd..aeede6335e 100644 --- a/src/main/resources/hibernate/hbm/Analysis.hbm.xml +++ b/src/main/resources/hibernate/hbm/Analysis.hbm.xml @@ -1,6 +1,5 @@ - + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/hibernate/hbm/Method.hbm.xml b/src/main/resources/hibernate/hbm/Method.hbm.xml index 0f67df949b..22b5b7ab0d 100644 --- a/src/main/resources/hibernate/hbm/Method.hbm.xml +++ b/src/main/resources/hibernate/hbm/Method.hbm.xml @@ -1,6 +1,5 @@ - + diff --git a/src/main/resources/liquibase/2.8.x.x/base.xml b/src/main/resources/liquibase/2.8.x.x/base.xml index 4798e21fe9..a1c63ed783 100644 --- a/src/main/resources/liquibase/2.8.x.x/base.xml +++ b/src/main/resources/liquibase/2.8.x.x/base.xml @@ -20,5 +20,6 @@ + diff --git a/src/main/resources/liquibase/2.8.x.x/method.xml b/src/main/resources/liquibase/2.8.x.x/method.xml new file mode 100644 index 0000000000..b7e9654f91 --- /dev/null +++ b/src/main/resources/liquibase/2.8.x.x/method.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + Add Method to analysis + + + + + From f160f114e7cb0ddfc72b033588f33c7b2ffcd10b Mon Sep 17 00:00:00 2001 From: CalebSLane Date: Mon, 19 Aug 2024 12:53:40 -0700 Subject: [PATCH 2/4] add method to WHOnet, and remove unnecessary classes --- .../method/valueholder/Method.java | 8 + .../ReportImplementationFactory.java | 4 - .../WHONETCSVRoutineExportReport.java | 77 ------- .../WHONETCSVRoutineSampleExportReport.java | 80 -------- .../WHONETExportRoutineByDate.java | 193 ------------------ .../WHONETCIRoutineColumnBuilder.java | 89 -------- .../WHONETCSVRoutineColumnBuilder.java | 16 +- .../reportBeans/WHONETColumnBuilder.java | 77 ------- .../WHONETRoutineColumnBuilder.java | 8 +- .../service/WHONetReportServiceImpl.java | 28 +-- .../action/util/TestReflexUtil.java | 42 ---- 11 files changed, 26 insertions(+), 596 deletions(-) delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCIRoutineColumnBuilder.java delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETColumnBuilder.java diff --git a/src/main/java/org/openelisglobal/method/valueholder/Method.java b/src/main/java/org/openelisglobal/method/valueholder/Method.java index 6f606bb4ab..d33d9cd213 100644 --- a/src/main/java/org/openelisglobal/method/valueholder/Method.java +++ b/src/main/java/org/openelisglobal/method/valueholder/Method.java @@ -135,4 +135,12 @@ public Localization getLocalization() { public void setLocalization(Localization localization) { this.localization.setValue(localization); } + + public String getLocalizedValue() { + if (getLocalization() == null) { + return methodName; + } else { + return getLocalization().getLocalizedValue(); + } + } } diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java b/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java index 87646f116d..ff6c55cfca 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java @@ -139,8 +139,6 @@ public static IReportParameterSetter getParameterSetter(String report) { return new ExportTrendsByDate(); } else if (report.equals("WHONETReport")) { return new WHONETReport(); - } else if (report.equals("ExportWHONETReportByDate")) { - return new WHONETExportRoutineByDate(); } else if (report.equals("covidResultsReport")) { return new CovidResultsReport(); } else if (report.equals("statisticsReport")) { @@ -277,8 +275,6 @@ public static IReportCreator getReportCreator(String report) { return new ExportTBOrdersByDate(); } else if (report.equals("MauritiusProtocolSheet")) { return new MauritiusProtocolSheet(); - } else if (report.equals("ExportWHONETReportByDate")) { - return new WHONETExportRoutineByDate(); } else if (report.equals("WHONETReport")) { return new WHONETReport(); } else if (report.equals("covidResultsReport")) { diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java deleted file mode 100644 index c885037fb3..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the - * License at http://www.mozilla.org/MPL/ - * - *

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF - * ANY KIND, either express or implied. See the License for the specific language governing rights - * and limitations under the License. - * - *

The Original Code is OpenELIS code. - * - *

Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved. - */ -package org.openelisglobal.reports.action.implementation; - -import net.sf.jasperreports.engine.JRDataSource; -import net.sf.jasperreports.engine.JRException; -import net.sf.jasperreports.engine.JRField; -import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; - -/** - * @author pahill (pahill@uw.edu) - * @since Mar 17, 2011 - */ -public abstract class WHONETCSVRoutineExportReport extends Report implements JRDataSource { - - /** - * @see org.openelisglobal.reports.action.implementation.Report#getContentType() - */ - @Override - public String getContentType() { - if (errorFound) { - return super.getContentType(); - } else { - return "text/plain; charset=UTF-8"; - } - } - - /** - * Either we generate a PDF with an error message or we generate data for a CSV - * file, but if your expecting to get JasperReport data from this class, it - * won't work. - * - * @see org.openelisglobal.reports.action.implementation.IReportCreator#getReportDataSource() - */ - @Override - public JRDataSource getReportDataSource() throws IllegalStateException { - if (!initialized) { - throw new IllegalStateException("initializeReport not called first"); - } - if (errorFound) { - return new JRBeanCollectionDataSource(errorMsgs); - } else { - throw new UnsupportedOperationException(); - } - } - - /** - * This Report can not be sent to JasperReports - * - * @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(net.sf.jasperreports.engine.JRField) - */ - @Override - public Object getFieldValue(JRField arg0) throws JRException { - throw new UnsupportedOperationException(); - } - - /** - * This Report can not be sent to JasperReports - * - * @see net.sf.jasperreports.engine.JRDataSource#next() - */ - @Override - public boolean next() throws JRException { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java deleted file mode 100644 index f880768ea6..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the - * License at http://www.mozilla.org/MPL/ - * - *

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF - * ANY KIND, either express or implied. See the License for the specific language governing rights - * and limitations under the License. - * - *

The Original Code is OpenELIS code. - * - *

Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved. - */ -package org.openelisglobal.reports.action.implementation; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.sql.SQLException; -import java.text.ParseException; -import java.util.List; -import javax.xml.ws.Response; -import net.sf.jasperreports.engine.JRException; -import org.openelisglobal.reports.action.implementation.reportBeans.WHONETRoutineColumnBuilder; - -public abstract class WHONETCSVRoutineSampleExportReport extends WHONETCSVRoutineExportReport { - - protected String lowDateStr; - protected String highDateStr; - protected List reportItems; - protected int iReportItem = -1; - - protected WHONETRoutineColumnBuilder WHONETcsvRoutineColumnBuilder; - protected DateRange dateRange; - - @Override - public String getResponseHeaderName() { - return "Content-Disposition"; - } - - @Override - public String getResponseHeaderContent() { - return "attachment;filename=" + getReportFileName() + ".csv"; - } - - /** - * Do everything necessary for to generate a CSV text file. - * - * @param reportDefinitionName full path to the definition for the report. - * @throws IOException - * @throws UnsupportedEncodingException - * @throws JRException - * @throws SQLException - * @throws IllegalStateException - * @throws ParseException - * @see org.openelisglobal.reports.action.implementation.IReportCreator#runReport(java.lang.String, - * Response) - */ - @Override - public byte[] runReport() throws UnsupportedEncodingException, IOException, IllegalStateException, SQLException, - JRException, ParseException { - if (errorFound) { - return super.runReport(); - } - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(100000); - buffer.write(WHONETcsvRoutineColumnBuilder.getColumnNamesLine().getBytes("windows-1252")); - - writeResultsToBuffer(buffer); - - return buffer.toByteArray(); - } - - protected void writeResultsToBuffer(ByteArrayOutputStream buffer) - throws IOException, UnsupportedEncodingException, SQLException, ParseException { - while (WHONETcsvRoutineColumnBuilder.next()) { - buffer.write(WHONETcsvRoutineColumnBuilder.nextLine().getBytes("windows-1252")); - } - } -} diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java deleted file mode 100644 index 95ae90334d..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the - * License at http://www.mozilla.org/MPL/ - * - *

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF - * ANY KIND, either express or implied. See the License for the specific language governing rights - * and limitations under the License. - * - *

The Original Code is OpenELIS code. - * - *

Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved. - */ -package org.openelisglobal.reports.action.implementation; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.sql.SQLException; -import java.text.ParseException; -import org.apache.commons.validator.GenericValidator; -import org.jfree.util.Log; -import org.openelisglobal.common.util.StringUtil; -import org.openelisglobal.internationalization.MessageUtil; -import org.openelisglobal.project.service.ProjectService; -import org.openelisglobal.reports.action.implementation.reportBeans.WHONETRoutineColumnBuilder; -import org.openelisglobal.reports.form.ReportForm; -import org.openelisglobal.spring.util.SpringContext; - -/** - * @author Paul A. Hill (pahill@uw.edu) - * @since Jan 26, 2011 - */ -public class WHONETExportRoutineByDate extends WHONETCSVRoutineSampleExportReport - implements IReportParameterSetter, IReportCreator { - protected final ProjectService projectService = SpringContext.getBean(ProjectService.class); - // private String projectStr; - // private Project project; - - @Override - protected String reportFileName() { - return "WHONETExportRoutineByDate"; - } - - @Override - public void setRequestParameters(ReportForm form) { - try { - form.setReportName(getReportNameForParameterPage()); - form.setUseLowerDateRange(Boolean.TRUE); - form.setUseUpperDateRange(Boolean.TRUE); - // form.setUseProjectCode(Boolean.TRUE); - // form.setProjectCodeList(getProjectList()); - } catch (RuntimeException e) { - Log.error("Error in ExportRoutineByDate.setRequestParemeters: ", e); - } - } - - protected String getReportNameForParameterPage() { - return MessageUtil.getMessage("reports.label.project.export") + " " - + MessageUtil.getContextualMessage("sample.collectionDate"); - } - /* - * protected void createReportParameters() { super.createReportParameters(); - * reportParameters.put("studyName", (project == null) ? null : - * project.getLocalizedName()); } - */ - - @Override - public void initializeReport(ReportForm form) { - super.initializeReport(); - errorFound = false; - - lowDateStr = form.getLowerDateRange(); - highDateStr = form.getUpperDateRange(); - // projectStr = form.getProjectCode(); - dateRange = new DateRange(lowDateStr, highDateStr); - - createReportParameters(); - - errorFound = !validateSubmitParameters(); - if (errorFound) { - return; - } - - createReportItems(); - } - - /** check everything */ - // ----------------------------------- - private boolean validateSubmitParameters() { - return dateRange.validateHighLowDate("report.error.message.date.received.missing"); - } - - // ------------------------------- - - /** - * @return true, if location is not blank or "0" is is found in the DB; false - * otherwise - */ - // -------------------------- - /* - * private boolean validateProject() { if (isBlankOrNull(projectStr) || - * "0".equals(Integer.getInteger(projectStr))) { - * add1LineErrorMessage("report.error.message.project.missing"); return false; } - * ProjectService Service = new ProjectServiceImpl(); project = - * Service.getProjectById(projectStr); if (project == null) { - * add1LineErrorMessage("report.error.message.project.missing"); return false; } - * return true; } - */ - // ------------------------- - /** creating the list for generation to the report */ - private void createReportItems() { - try { - WHONETcsvRoutineColumnBuilder = getColumnBuilder(); - WHONETcsvRoutineColumnBuilder.buildDataSource(); - } catch (SQLException e) { - Log.error("Error in " + this.getClass().getSimpleName() + ".createReportItems: ", e); - add1LineErrorMessage("report.error.message.general.error"); - } - } - - @Override - protected void writeResultsToBuffer(ByteArrayOutputStream buffer) - throws IOException, UnsupportedEncodingException, SQLException, ParseException { - - String currentAccessionNumber = null; - String[] splitBase = null; - while (WHONETcsvRoutineColumnBuilder.next()) { - String line = WHONETcsvRoutineColumnBuilder.nextLine(); - String[] splitLine = StringUtil.separateCSVWithMixedEmbededQuotes(line); - - if (splitLine[0].equals(currentAccessionNumber)) { - merge(splitBase, splitLine); - } else { - if (currentAccessionNumber != null) { - writeConsolidatedBaseToBuffer(buffer, splitBase); - } - splitBase = splitLine; - currentAccessionNumber = splitBase[0]; - } - } - - writeConsolidatedBaseToBuffer(buffer, splitBase); - } - - private void merge(String[] base, String[] line) { - for (int i = 0; i < base.length; ++i) { - if (GenericValidator.isBlankOrNull(base[i])) { - base[i] = line[i]; - } - } - } - - protected void writeConsolidatedBaseToBuffer(ByteArrayOutputStream buffer, String[] splitBase) - throws IOException, UnsupportedEncodingException { - - if (splitBase != null) { - StringBuffer consolidatedLine = new StringBuffer(); - for (String value : splitBase) { - consolidatedLine.append(value); - consolidatedLine.append(","); - } - - consolidatedLine.deleteCharAt(consolidatedLine.lastIndexOf(",")); - buffer.write(consolidatedLine.toString().getBytes("windows-1252")); - } - } - - private WHONETRoutineColumnBuilder getColumnBuilder() { - return new WHONETRoutineColumnBuilder(dateRange); - } - - /** - * @return a list of the correct projects for display - */ - /* - * protected List getProjectList() { List projects = new - * ArrayList(); Project project = new Project(); - * project.setProjectName("Antiretroviral Study"); - * projects.add(projectService.getProjectByName(project, false, false)); - * project.setProjectName("Antiretroviral Followup Study"); - * projects.add(projectService.getProjectByName(project, false, false)); - * project.setProjectName("Routine HIV Testing"); - * projects.add(projectService.getProjectByName(project, false, false)); - * project.setProjectName("Early Infant Diagnosis for HIV Study"); - * projects.add(projectService.getProjectByName(project, false, false)); - * project.setProjectName("Viral Load Results"); - * projects.add(projectService.getProjectByName(project, false, false)); - * project.setProjectName("Indeterminate Results"); - * projects.add(projectService.getProjectByName(project, false, false)); return - * projects; } - */ -} diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCIRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCIRoutineColumnBuilder.java deleted file mode 100644 index bb6238b3ae..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCIRoutineColumnBuilder.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.openelisglobal.reports.action.implementation.reportBeans; - -import org.openelisglobal.reports.action.implementation.Report.DateRange; - -/** - * If we had a big resultSet with various columns for CSV export, we need a few - * things defined so we can translate to a useable CSV file values. This class - * builds the SQL for the one row per CSV output and maps everything to the - * output including looking up resource names. This class also can print out - * just the XML needed for the Jasper report which helps make the CSV file (see - * the call to generateJasperXML). - * - * @author Paul A. Hill (pahill@uw.edu) - * @since Jan 28, 2011 - */ -public abstract class WHONETCIRoutineColumnBuilder extends WHONETCSVRoutineColumnBuilder { - - protected static final String WHONET_SELECT = "select r.value as result_value," // - + " s.accession_number as lab_no, s.collection_date, s.entered_date," // - + " pe.last_name, pe.first_name," // - + " pa.national_id, pa.gender, pa.birth_date," - + " t.id as test_id, t.name as test_name, t.description as test_description, t.loinc, t.guid," // - + " tos.description as sample_type" // - + " from sample_item si" + " join analysis a on a.sampitem_id = si.id" // - + " join sample s on si.samp_id = s.id" // - + " join sample_human sh on sh.samp_id = s.id" + " join sample_requester sr1 on sr1.sample_id = s.id" - + " join type_of_sample tos on si.typeosamp_id = tos.id" // - + " join patient pa on pa.id = sh.patient_id" // - + " join person pe on pe.id = pa.person_id" + " join test t on t.id = a.test_id" // - + " left join result r on r.analysis_id = a.id" // - + " where t.antimicrobial_resistance = true" - + " and sr1.requester_type_id = (SELECT id from requester_type rt where rt.requester_type = 'organization')"; - - protected DateRange dateRange; - // protected String projectStr; - - /** */ - public WHONETCIRoutineColumnBuilder(DateRange dateRange) { - super(); - this.dateRange = dateRange; - } - - @Override - public abstract void searchForWHONetResults(); - - // protected void defineBasicColumns() { - // // // patient fields - // // add("national_id", "IDENTIFIER", NONE); - // // add("first_name", "FIRST NAME", NONE); - // // add("last_name", "LAST NAME", NONE); - // // add("gender", "SEX", NONE); - // // add("birth_date", "BIRTHDATE", DATE); - // // add("entered_date", "DATE ENTERED", DATE_TIME); // interview date - - // // // add("organization_code", "CODEREFERER", NONE); - // // // add("organization_name", "REFERER", NONE); - - // // // specimen fields - // // add("lab_no", "LABNO", NONE); - // // add("collection_date", "DATE COLLECTED", DATE_TIME); // collection date - // // add("sample_type", "SPECIMEN TYPE", NONE); - - // // add("test_name", "ANTIBIOTIC", NONE); - // // add("organism", "ORGANISM", NONE); - // // add("loinc", "LOINC", NONE); - // // add("guid", "GUID", NONE); - - // } - /* - * add("accession_number", "LABNO", NONE); add("national_id", "IDENTIFIER", - * NONE); add("entered_date", "AGEYEARS", AGE_YEARS); add("entered_date", - * "AGEMONTHS", AGE_MONTHS); add("entered_date", "AGEWEEKS", AGE_WEEKS);// - * reception date add("entered_date", "DATEENTERED", DATE_TIME); // interview - * date add("collection_date", "DATECOLLECT", DATE_TIME); // collection date - */ - - // add("released_date", "DATEVALIDATION", DATE_TIME ); // validation date - - /* - * add("organization_code", "CODEREFERER", NONE); add("organization_name", - * "REFERER", NONE); add("program", "PROGRAM", PROGRAM); add("status_id", - * "STATUS", SAMPLE_STATUS); - */ - - // add("external_id", "SUJETSIT", NONE); - // add("last_name", "NOM", NONE); - // add("first_name", "PRENOM", NONE); - -} diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java index 7037747499..fb2c865ecb 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java @@ -23,9 +23,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; -import org.openelisglobal.analyte.service.AnalyteService; import org.openelisglobal.common.util.DateUtil; -import org.openelisglobal.observationhistorytype.service.ObservationHistoryTypeService; import org.openelisglobal.result.service.ResultService; import org.openelisglobal.spring.util.SpringContext; import org.openelisglobal.test.service.TestService; @@ -50,12 +48,13 @@ public static class WHONetRow { private String antibiotic; private String organism; private String result; + private String method; private String delimeter = "\t"; public WHONetRow(String nationalId, String firstName, String lastName, String sex, String birthdate, String enteredDate, String labNo, String collectionDate, String sampleType, String antibiotic, - String organism, String result) { + String organism, String result, String method) { this.nationalId = nationalId; this.firstName = firstName; this.lastName = lastName; @@ -68,11 +67,12 @@ public WHONetRow(String nationalId, String firstName, String lastName, String se this.antibiotic = antibiotic; this.organism = organism; this.result = result; + this.method = method; } public String getRow() { List rowValues = Arrays.asList(nationalId, firstName, lastName, sex, birthdate, enteredDate, labNo, - collectionDate, sampleType, antibiotic, organism, result); + collectionDate, sampleType, antibiotic, organism, result, method); return String.join(delimeter, rowValues); } } @@ -105,8 +105,6 @@ public String toString() { protected String eol = System.getProperty("line.separator"); protected ResultService resultService = SpringContext.getBean(ResultService.class); - private ObservationHistoryTypeService ohtService = SpringContext.getBean(ObservationHistoryTypeService.class); - private AnalyteService analyteService = SpringContext.getBean(AnalyteService.class); protected TestService testService = SpringContext.getBean(TestService.class); protected TestResultService testResultService = SpringContext.getBean(TestResultService.class); @@ -185,9 +183,9 @@ protected String datetimeToLocalDateTime(String value) { * @return one string with all names. */ public String getColumnNamesLine() { - return new StringBuilder() - .append(new WHONetRow("NATIONAL ID", "FIRST NAME", "LAST NAME", "SEX", "BIRTHDATE", "DATE ENTERED", - "LABNO", "DATE COLLECTED", "SPECIMEN TYPE", "ANTIBIOTIC", "ORGANISM", "RESULT").getRow()) + return new StringBuilder().append( + new WHONetRow("NATIONAL ID", "FIRST NAME", "LAST NAME", "SEX", "BIRTHDATE", "DATE ENTERED", "LABNO", + "DATE COLLECTED", "SPECIMEN TYPE", "ANTIBIOTIC", "ORGANISM", "RESULT", "METHOD").getRow()) .append(eol).toString(); } diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETColumnBuilder.java deleted file mode 100644 index 21dab556c7..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETColumnBuilder.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.openelisglobal.reports.action.implementation.reportBeans; - -public class WHONETColumnBuilder { - - private String firstName = ""; - private String lastName = ""; - private String gender = ""; - private String SpecimenType = ""; - private String SpecimenDate = ""; - private String Organism = ""; - private String Antibiotic = ""; - private String Result = ""; - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } - - public String getSpecimenType() { - return SpecimenType; - } - - public void setSpecimenType(String specimenType) { - SpecimenType = specimenType; - } - - public String getSpecimenDate() { - return SpecimenDate; - } - - public void setSpecimenDate(String specimenDate) { - SpecimenDate = specimenDate; - } - - public String getOrganism() { - return Organism; - } - - public void setOrganism(String organism) { - Organism = organism; - } - - public String getAntibiotic() { - return Antibiotic; - } - - public void setAntibiotic(String antibiotic) { - Antibiotic = antibiotic; - } - - public String getResult() { - return Result; - } - - public void setResult(String result) { - Result = result; - } -} diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java index 027bed2027..3209b0c7b0 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java @@ -26,17 +26,19 @@ * @author pahill (pahill@uw.edu) * @since May 18, 2011 */ -public class WHONETRoutineColumnBuilder extends WHONETCIRoutineColumnBuilder { +public class WHONETRoutineColumnBuilder extends WHONETCSVRoutineColumnBuilder { + + private DateRange dateRange; /** * @param dateRange * @param projectStr */ public WHONETRoutineColumnBuilder(DateRange dateRange) { - super(dateRange); + + this.dateRange = dateRange; } - @Override public void searchForWHONetResults() { WHONetReportService reportService = SpringContext.getBean(WHONetReportService.class); Date lowDate = dateRange.getLowDate(); diff --git a/src/main/java/org/openelisglobal/reports/service/WHONetReportServiceImpl.java b/src/main/java/org/openelisglobal/reports/service/WHONetReportServiceImpl.java index bcf31d3b85..d0736331c6 100644 --- a/src/main/java/org/openelisglobal/reports/service/WHONetReportServiceImpl.java +++ b/src/main/java/org/openelisglobal/reports/service/WHONetReportServiceImpl.java @@ -18,24 +18,18 @@ import org.openelisglobal.reports.action.implementation.reportBeans.WHONETCSVRoutineColumnBuilder.WHONetRow; import org.openelisglobal.result.service.ResultService; import org.openelisglobal.result.valueholder.Result; -import org.openelisglobal.sample.service.SampleService; import org.openelisglobal.sample.valueholder.Sample; import org.openelisglobal.samplehuman.service.SampleHumanService; -import org.openelisglobal.sampleitem.service.SampleItemService; import org.openelisglobal.sampleitem.valueholder.SampleItem; import org.openelisglobal.test.service.TestService; import org.openelisglobal.test.valueholder.Test; import org.openelisglobal.testreflex.action.util.TestReflexUtil; -import org.openelisglobal.testreflex.service.TestReflexService; -import org.openelisglobal.typeofsample.service.TypeOfSampleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class WHONetReportServiceImpl implements WHONetReportService { - @Autowired - private SampleService sampleService; @Autowired private AnalysisService analysisService; @Autowired @@ -45,13 +39,7 @@ public class WHONetReportServiceImpl implements WHONetReportService { @Autowired private TestService testService; @Autowired - private TypeOfSampleService sampleTypeService; - @Autowired - private SampleItemService sampleItemService; - @Autowired private IStatusService statusService; - @Autowired - private TestReflexService testReflexService; private List ANALYSIS_STATUS_IDS; private List SAMPLE_STATUS_IDS; @@ -112,20 +100,12 @@ private List createRowsFromSampleItems(List sampleItems) // for every analysis in the sampleItem, find any that are a triggering // antimicrobial resistance analysis - System.out.println("analysises" - + String.join(", ", analysises.stream().map(e -> e.getId()).collect(Collectors.toList()))); - for (Analysis potentialTriggerAnalysis : analysises) { if (triggerTestIds.contains(potentialTriggerAnalysis.getTest().getId())) { Analysis triggerAnalysis = potentialTriggerAnalysis; // find the exact result that triggers further analysis List results = resultService.getResultsByAnalysis(triggerAnalysis); - System.out.println("results" - + String.join(", ", results.stream().map(e -> e.getId()).collect(Collectors.toList()))); for (Result triggerResult : results) { - System.out.println("triggerResult" + triggerResult.getId()); - System.out.println("testResult" + triggerResult.getTestResult().getId()); - TestReflexUtil testReflexUtil = new TestReflexUtil(); // find the analysis that was triggered by the trigger test @@ -145,7 +125,9 @@ private List createRowsFromSampleItems(List sampleItems) DateUtil.convertTimestampToStringDate(sampleItem.getCollectionDate()), sampleItem.getTypeOfSample().getDescription(), reflexAnalysis.getTest().getName(), - resultService.getSimpleResultValue(triggerResult), "")); + resultService.getSimpleResultValue(triggerResult), "", + reflexAnalysis.getMethod() == null ? "" + : reflexAnalysis.getMethod().getLocalizedValue())); } else { // else add the info of both tests/results for (Result reflexResult : reflexResults) { @@ -157,7 +139,9 @@ private List createRowsFromSampleItems(List sampleItems) sampleItem.getTypeOfSample().getDescription(), reflexAnalysis.getTest().getName(), resultService.getSimpleResultValue(triggerResult), - resultService.getSimpleResultValue(reflexResult))); + resultService.getSimpleResultValue(reflexResult), + reflexAnalysis.getMethod() == null ? "" + : reflexAnalysis.getMethod().getLocalizedValue())); } } } 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 6b24402407..933838b95f 100644 --- a/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java +++ b/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java @@ -447,48 +447,6 @@ private List handleAutomaticReflexes(List parentAnalysisList return reflexAnalysises; } - private List applyDictionaryRelationRulesForReflex(Result result) { - List reflexTests = new ArrayList<>(); - reflexResolver.getTestReflexsByAnalyteAndTest(result).forEach(reflexTest -> { - if (reflexTest.getRelation() != null) { - switch (reflexTest.getRelation()) { - case EQUALS: - if (reflexTest.getTestResult().getValue().equals(result.getValue())) { - reflexTests.add(reflexTest); - } - break; - case NOT_EQUALS: - if (!(reflexTest.getTestResult().getValue().equals(result.getValue()))) { - reflexTests.add(reflexTest); - } - break; - case INSIDE_NORMAL_RANGE: - List resultLimits = SpringContext.getBean(ResultLimitService.class) - .getResultLimits(result.getTestResult().getTest()); - if (!resultLimits.isEmpty() - && StringUtils.isNotBlank(resultLimits.get(0).getDictionaryNormalId())) { - if (result.getValue().equals(resultLimits.get(0).getDictionaryNormalId())) { - reflexTests.add(reflexTest); - } - } - break; - case OUTSIDE_NORMAL_RANGE: - List limits = SpringContext.getBean(ResultLimitService.class) - .getResultLimits(result.getTestResult().getTest()); - if (!limits.isEmpty() && StringUtils.isNotBlank(limits.get(0).getDictionaryNormalId())) { - if (!(result.getValue().equals(limits.get(0).getDictionaryNormalId()))) { - reflexTests.add(reflexTest); - } - } - break; - default: - break; - } - } - }); - return reflexTests; - } - private Boolean applyNumericRelationRulesForReflex(TestReflex reflexTest, Result result) { if (reflexTest.getRelation() == null) { return false; From 522d06ced8b0a1915ec798a5290490102e73c3b8 Mon Sep 17 00:00:00 2001 From: CalebSLane Date: Mon, 19 Aug 2024 14:30:12 -0700 Subject: [PATCH 3/4] 3.0.3.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 458c7664e1..eb8390c58f 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 11 3 0 - 2 + 3 1 UTF-8 From 7b25dcc70dcc191c977b320cd4def741b78994d6 Mon Sep 17 00:00:00 2001 From: CalebSLane Date: Mon, 19 Aug 2024 15:24:55 -0700 Subject: [PATCH 4/4] delete correct WHOnet files this time and clean up files --- .../ReportImplementationFactory.java | 8 +- .../WHONETCSVRoutineExportReport.java | 73 +++++++++++ .../WHONETCSVRoutineSampleExportReport.java | 80 ++++++++++++ .../WHONETExportRoutineByDate.java | 88 ++++++++++++++ .../action/implementation/WHONETReport.java | 65 ---------- .../WHONETCSVRoutineColumnBuilder.java | 114 +++--------------- .../WHONETRoutineColumnBuilder.java | 50 -------- 7 files changed, 264 insertions(+), 214 deletions(-) create mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java create mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java create mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/WHONETReport.java delete mode 100644 src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java b/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java index ff6c55cfca..308a1c4a90 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/ReportImplementationFactory.java @@ -137,8 +137,8 @@ public static IReportParameterSetter getParameterSetter(String report) { return new TBOrderReport(); } else if (report.equals("Trends")) { return new ExportTrendsByDate(); - } else if (report.equals("WHONETReport")) { - return new WHONETReport(); + } else if (report.equals("ExportWHONETReportByDate")) { + return new WHONETExportRoutineByDate(); } else if (report.equals("covidResultsReport")) { return new CovidResultsReport(); } else if (report.equals("statisticsReport")) { @@ -275,8 +275,8 @@ public static IReportCreator getReportCreator(String report) { return new ExportTBOrdersByDate(); } else if (report.equals("MauritiusProtocolSheet")) { return new MauritiusProtocolSheet(); - } else if (report.equals("WHONETReport")) { - return new WHONETReport(); + } else if (report.equals("ExportWHONETReportByDate")) { + return new WHONETExportRoutineByDate(); } else if (report.equals("covidResultsReport")) { return new CovidResultsReport(); } else if (report.equals("statisticsReport")) { diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java new file mode 100644 index 0000000000..64145abd40 --- /dev/null +++ b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java @@ -0,0 +1,73 @@ +/** + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the + * License at http://www.mozilla.org/MPL/ + * + *

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights + * and limitations under the License. + * + *

The Original Code is OpenELIS code. + * + *

Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved. + */ +package org.openelisglobal.reports.action.implementation; + +import net.sf.jasperreports.engine.JRDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRField; +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; + +public abstract class WHONETCSVRoutineExportReport extends Report implements JRDataSource { + + /** + * @see org.openelisglobal.reports.action.implementation.Report#getContentType() + */ + @Override + public String getContentType() { + if (errorFound) { + return super.getContentType(); + } else { + return "text/plain; charset=UTF-8"; + } + } + + /** + * Either we generate a PDF with an error message or we generate data for a CSV + * file, but if your expecting to get JasperReport data from this class, it + * won't work. + * + * @see org.openelisglobal.reports.action.implementation.IReportCreator#getReportDataSource() + */ + @Override + public JRDataSource getReportDataSource() throws IllegalStateException { + if (!initialized) { + throw new IllegalStateException("initializeReport not called first"); + } + if (errorFound) { + return new JRBeanCollectionDataSource(errorMsgs); + } else { + throw new UnsupportedOperationException(); + } + } + + /** + * This Report can not be sent to JasperReports + * + * @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(net.sf.jasperreports.engine.JRField) + */ + @Override + public Object getFieldValue(JRField arg0) throws JRException { + throw new UnsupportedOperationException(); + } + + /** + * This Report can not be sent to JasperReports + * + * @see net.sf.jasperreports.engine.JRDataSource#next() + */ + @Override + public boolean next() throws JRException { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java new file mode 100644 index 0000000000..30f3182868 --- /dev/null +++ b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java @@ -0,0 +1,80 @@ +/** + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the + * License at http://www.mozilla.org/MPL/ + * + *

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights + * and limitations under the License. + * + *

The Original Code is OpenELIS code. + * + *

Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved. + */ +package org.openelisglobal.reports.action.implementation; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.sql.SQLException; +import java.text.ParseException; +import java.util.List; +import javax.xml.ws.Response; +import net.sf.jasperreports.engine.JRException; +import org.openelisglobal.reports.action.implementation.reportBeans.WHONETCSVRoutineColumnBuilder; + +public abstract class WHONETCSVRoutineSampleExportReport extends WHONETCSVRoutineExportReport { + + protected String lowDateStr; + protected String highDateStr; + protected List reportItems; + protected int iReportItem = -1; + + protected WHONETCSVRoutineColumnBuilder WHONETcsvRoutineColumnBuilder; + protected DateRange dateRange; + + @Override + public String getResponseHeaderName() { + return "Content-Disposition"; + } + + @Override + public String getResponseHeaderContent() { + return "attachment;filename=" + getReportFileName() + ".csv"; + } + + /** + * Do everything necessary for to generate a CSV text file. + * + * @param reportDefinitionName full path to the definition for the report. + * @throws IOException + * @throws UnsupportedEncodingException + * @throws JRException + * @throws SQLException + * @throws IllegalStateException + * @throws ParseException + * @see org.openelisglobal.reports.action.implementation.IReportCreator#runReport(java.lang.String, + * Response) + */ + @Override + public byte[] runReport() throws UnsupportedEncodingException, IOException, IllegalStateException, SQLException, + JRException, ParseException { + if (errorFound) { + return super.runReport(); + } + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(100000); + buffer.write(WHONETcsvRoutineColumnBuilder.getColumnNamesLine().getBytes("windows-1252")); + + writeResultsToBuffer(buffer); + + return buffer.toByteArray(); + } + + protected void writeResultsToBuffer(ByteArrayOutputStream buffer) + throws IOException, UnsupportedEncodingException, SQLException, ParseException { + while (WHONETcsvRoutineColumnBuilder.next()) { + buffer.write(WHONETcsvRoutineColumnBuilder.nextLine().getBytes("windows-1252")); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java new file mode 100644 index 0000000000..f1dccbb3b7 --- /dev/null +++ b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java @@ -0,0 +1,88 @@ +/** + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy of the + * License at http://www.mozilla.org/MPL/ + * + *

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights + * and limitations under the License. + * + *

The Original Code is OpenELIS code. + * + *

Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved. + */ +package org.openelisglobal.reports.action.implementation; + +import java.sql.SQLException; +import org.jfree.util.Log; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.project.service.ProjectService; +import org.openelisglobal.reports.action.implementation.reportBeans.WHONETCSVRoutineColumnBuilder; +import org.openelisglobal.reports.form.ReportForm; +import org.openelisglobal.spring.util.SpringContext; + +public class WHONETExportRoutineByDate extends WHONETCSVRoutineSampleExportReport implements IReportParameterSetter { + protected final ProjectService projectService = SpringContext.getBean(ProjectService.class); + + @Override + protected String reportFileName() { + return "WHONETExportRoutineByDate"; + } + + @Override + public void setRequestParameters(ReportForm form) { + try { + form.setReportName(getReportNameForParameterPage()); + form.setUseLowerDateRange(Boolean.TRUE); + form.setUseUpperDateRange(Boolean.TRUE); + } catch (RuntimeException e) { + Log.error("Error in ExportRoutineByDate.setRequestParemeters: ", e); + } + } + + protected String getReportNameForParameterPage() { + return MessageUtil.getMessage("reports.label.project.export") + " " + + MessageUtil.getContextualMessage("sample.collectionDate"); + } + + @Override + public void initializeReport(ReportForm form) { + super.initializeReport(); + errorFound = false; + + lowDateStr = form.getLowerDateRange(); + highDateStr = form.getUpperDateRange(); + dateRange = new DateRange(lowDateStr, highDateStr); + + createReportParameters(); + + errorFound = !validateSubmitParameters(); + if (errorFound) { + return; + } + + createReportItems(); + } + + /** check everything */ + // ----------------------------------- + private boolean validateSubmitParameters() { + return dateRange.validateHighLowDate("report.error.message.date.received.missing"); + } + + /** creating the list for generation to the report */ + private void createReportItems() { + try { + WHONETcsvRoutineColumnBuilder = getColumnBuilder(); + WHONETcsvRoutineColumnBuilder.buildDataSource(); + } catch (SQLException e) { + Log.error("Error in " + this.getClass().getSimpleName() + ".createReportItems: ", e); + add1LineErrorMessage("report.error.message.general.error"); + } + } + + private WHONETCSVRoutineColumnBuilder getColumnBuilder() { + return new WHONETCSVRoutineColumnBuilder(dateRange); + } + +} \ No newline at end of file diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETReport.java b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETReport.java deleted file mode 100644 index f02c432038..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETReport.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.openelisglobal.reports.action.implementation; - -import java.util.ArrayList; -import java.util.List; -import net.sf.jasperreports.engine.JRDataSource; -import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; -import org.openelisglobal.internationalization.MessageUtil; -import org.openelisglobal.reports.action.implementation.reportBeans.WHONETRoutineColumnBuilder; -import org.openelisglobal.reports.form.ReportForm; - -public class WHONETReport extends Report implements IReportParameterSetter, IReportCreator { - - protected List whonetColumnBuilder = new ArrayList<>(); - protected String reportPath = ""; - protected DateRange dateRange; - - @Override - public void initializeReport(ReportForm form) { - initialized = true; - ReportSpecificationList selection = form.getSelectList(); - dateRange = new DateRange(form.getLowerDateRange(), form.getUpperDateRange()); - - errorFound = !validateSubmitParameters(selection); - if (errorFound) { - return; - } - if (whonetColumnBuilder.size() == 0) { - add1LineErrorMessage("report.error.message.noPrintableItems"); - } - } - - private boolean validateSubmitParameters(ReportSpecificationList selectList) { - - return (dateRange.validateHighLowDate("report.error.message.date.received.missing")); - } - - @Override - public JRDataSource getReportDataSource() throws IllegalStateException { - return errorFound ? new JRBeanCollectionDataSource(errorMsgs) - : new JRBeanCollectionDataSource(whonetColumnBuilder); - } - - @Override - protected void createReportParameters() { - super.createReportParameters(); - reportParameters.put("startDate", dateRange.getLowDateStr()); - reportParameters.put("endDate", dateRange.getHighDateStr()); - } - - @Override - protected String reportFileName() { - return "WHONETReport"; - } - - @Override - public void setRequestParameters(ReportForm form) { - form.setReportName(getReportNameForParameterPage()); - form.setUseLowerDateRange(Boolean.TRUE); - form.setUseUpperDateRange(Boolean.TRUE); - } - - protected String getReportNameForParameterPage() { - return MessageUtil.getMessage("reports.label.export.whonet.report.dateType"); - } -} diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java index fb2c865ecb..c8cd323323 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETCSVRoutineColumnBuilder.java @@ -17,23 +17,20 @@ */ package org.openelisglobal.reports.action.implementation.reportBeans; +import java.sql.Date; import java.sql.SQLException; import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.Arrays; -import java.util.Date; import java.util.List; -import org.openelisglobal.common.util.DateUtil; -import org.openelisglobal.result.service.ResultService; +import org.openelisglobal.reports.action.implementation.Report.DateRange; +import org.openelisglobal.reports.service.WHONetReportService; import org.openelisglobal.spring.util.SpringContext; -import org.openelisglobal.test.service.TestService; -import org.openelisglobal.testresult.service.TestResultService; /** * @author pahill (pahill@uw.edu) * @since Mar 18, 2011 */ -public abstract class WHONETCSVRoutineColumnBuilder { +public class WHONETCSVRoutineColumnBuilder { public static class WHONetRow { private String nationalId; @@ -77,105 +74,32 @@ public String getRow() { } } - // these are used so we are not passing around strings in the methods that are - // appended to sql - // this is to cover any potential sql injection that could be introduced by a - // developer - protected enum SQLConstant { - DEMO("demo"), RESULT("result"); + private List rows; + private int index = -1; - private final String nameInSql; - - private SQLConstant(String name) { - nameInSql = name; - } - - @Override - public String toString() { - return nameInSql; - } - } - - protected static final SimpleDateFormat postgresDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - private static final SimpleDateFormat postgresDateTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); - - protected List rows; - protected int index = -1; - - protected String eol = System.getProperty("line.separator"); - - protected ResultService resultService = SpringContext.getBean(ResultService.class); - protected TestService testService = SpringContext.getBean(TestService.class); - protected TestResultService testResultService = SpringContext.getBean(TestResultService.class); + private String eol = System.getProperty("line.separator"); + private DateRange dateRange; /** - * The various ways that columns are converted for CSV export - * - * @author Paul A. Hill (pahill@uw.edu) - * @since Feb 1, 2011 + * @param dateRange + * @param projectStr */ - public enum Strategy { - DICT, // dictionary localized value - DICT_PLUS, // dictionary localized value or a string constant - DICT_RAW, // dictionary localized value, no attempts at trimming to show just code number. - DATE, // date (i.e. 01/01/2013) - DATE_TIME, // date with time (i.e. 01/01/2013 12:12:00) - NONE, GENDER, DROP_ZERO, TEST_RESULT, GEND_CD4, SAMPLE_STATUS, PROJECT, PROGRAM, // program defined in routine - // order. - LOG, // results is a real number, but display the log of it. - AGE_YEARS, AGE_MONTHS, AGE_WEEKS, DEBUG, CUSTOM, // special handling which is encapsulated in an instance of - // ICSVColumnCustomStrategy - BLANK // Will always be an empty string. Used when column is wanted but data is not + public WHONETCSVRoutineColumnBuilder(DateRange dateRange) { + this.dateRange = dateRange; } - public void buildDataSource() throws SQLException { - buildResultSet(); + public void searchForWHONetResults() { + WHONetReportService reportService = SpringContext.getBean(WHONetReportService.class); + Date lowDate = dateRange.getLowDate(); + Date highDate = dateRange.getHighDate(); + rows = reportService.getWHONetRows(lowDate, highDate); + return; } - protected void buildResultSet() throws SQLException { + public void buildDataSource() throws SQLException { searchForWHONetResults(); } - protected synchronized String formatDateForDatabaseSql(Date date) { - // SimpleDateFormat is not thread safe - return postgresDateFormat.format(date); - } - - protected synchronized Date parseDateForDatabaseSql(String date) throws ParseException { - // SimpleDateFormat is not thread safe - return postgresDateFormat.parse(date); - } - - private synchronized Date parseDateTimeForDatabaseSql(String date) throws ParseException { - // SimpleDateFormat is not thread safe - return postgresDateTime.parse(date); - } - - /** - * @param value - * @return - */ - protected String datetimeToLocalDate(String value) { - try { - Date parsed = parseDateTimeForDatabaseSql(value); - java.sql.Date date = new java.sql.Date(parsed.getTime()); - return DateUtil.convertSqlDateToStringDate(date); - } catch (ParseException e) { - return value; - } - } - - protected String datetimeToLocalDateTime(String value) { - try { - Date parsed = parseDateTimeForDatabaseSql(value); - return DateUtil.formatDateTimeAsText(parsed); - } catch (ParseException e) { - return value; - } - } - - public abstract void searchForWHONetResults(); - /** * Useful for the 1st line of a CSV files. This produces a completely escaped * for MSExcel comma separated list of columns. diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java deleted file mode 100644 index 3209b0c7b0..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations under - * the License. - * - * The Original Code is OpenELIS code. - * - * Copyright (C) The Minnesota Department of Health. All Rights Reserved. - * - * Contributor(s): CIRG, University of Washington, Seattle WA. - */ -package org.openelisglobal.reports.action.implementation.reportBeans; - -import java.sql.Date; -import org.openelisglobal.reports.action.implementation.Report.DateRange; -import org.openelisglobal.reports.service.WHONetReportService; -import org.openelisglobal.spring.util.SpringContext; - -/** - * @author pahill (pahill@uw.edu) - * @since May 18, 2011 - */ -public class WHONETRoutineColumnBuilder extends WHONETCSVRoutineColumnBuilder { - - private DateRange dateRange; - - /** - * @param dateRange - * @param projectStr - */ - public WHONETRoutineColumnBuilder(DateRange dateRange) { - - this.dateRange = dateRange; - } - - public void searchForWHONetResults() { - WHONetReportService reportService = SpringContext.getBean(WHONetReportService.class); - Date lowDate = dateRange.getLowDate(); - Date highDate = dateRange.getHighDate(); - rows = reportService.getWHONetRows(lowDate, highDate); - return; - } - -}