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 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/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..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,6 @@ 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")) { @@ -279,8 +277,6 @@ public static IReportCreator getReportCreator(String report) { return new MauritiusProtocolSheet(); } else if (report.equals("ExportWHONETReportByDate")) { return new WHONETExportRoutineByDate(); - } else if (report.equals("WHONETReport")) { - return new WHONETReport(); } 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 index c885037fb3..64145abd40 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineExportReport.java @@ -18,10 +18,6 @@ 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 { /** @@ -74,4 +70,4 @@ public Object getFieldValue(JRField arg0) throws JRException { 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 index f880768ea6..30f3182868 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETCSVRoutineSampleExportReport.java @@ -21,7 +21,7 @@ import java.util.List; import javax.xml.ws.Response; import net.sf.jasperreports.engine.JRException; -import org.openelisglobal.reports.action.implementation.reportBeans.WHONETRoutineColumnBuilder; +import org.openelisglobal.reports.action.implementation.reportBeans.WHONETCSVRoutineColumnBuilder; public abstract class WHONETCSVRoutineSampleExportReport extends WHONETCSVRoutineExportReport { @@ -30,7 +30,7 @@ public abstract class WHONETCSVRoutineSampleExportReport extends WHONETCSVRoutin protected List reportItems; protected int iReportItem = -1; - protected WHONETRoutineColumnBuilder WHONETcsvRoutineColumnBuilder; + protected WHONETCSVRoutineColumnBuilder WHONETcsvRoutineColumnBuilder; protected DateRange dateRange; @Override @@ -77,4 +77,4 @@ protected void writeResultsToBuffer(ByteArrayOutputStream buffer) 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 index 95ae90334d..f1dccbb3b7 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/WHONETExportRoutineByDate.java @@ -13,29 +13,16 @@ */ 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.action.implementation.reportBeans.WHONETCSVRoutineColumnBuilder; 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 { +public class WHONETExportRoutineByDate extends WHONETCSVRoutineSampleExportReport implements IReportParameterSetter { protected final ProjectService projectService = SpringContext.getBean(ProjectService.class); - // private String projectStr; - // private Project project; @Override protected String reportFileName() { @@ -48,8 +35,6 @@ public void setRequestParameters(ReportForm form) { 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); } @@ -59,11 +44,6 @@ 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) { @@ -72,7 +52,6 @@ public void initializeReport(ReportForm form) { lowDateStr = form.getLowerDateRange(); highDateStr = form.getUpperDateRange(); - // projectStr = form.getProjectCode(); dateRange = new DateRange(lowDateStr, highDateStr); createReportParameters(); @@ -91,23 +70,6 @@ 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 { @@ -119,75 +81,8 @@ private void createReportItems() { } } - @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); + private WHONETCSVRoutineColumnBuilder getColumnBuilder() { + return new WHONETCSVRoutineColumnBuilder(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; } - */ -} +} \ 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/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..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,25 +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.analyte.service.AnalyteService; -import org.openelisglobal.common.util.DateUtil; -import org.openelisglobal.observationhistorytype.service.ObservationHistoryTypeService; -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; @@ -50,12 +45,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,116 +64,42 @@ 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); } } - // 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); - 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); + 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. @@ -185,9 +107,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 deleted file mode 100644 index 027bed2027..0000000000 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/WHONETRoutineColumnBuilder.java +++ /dev/null @@ -1,48 +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 WHONETCIRoutineColumnBuilder { - - /** - * @param dateRange - * @param projectStr - */ - public WHONETRoutineColumnBuilder(DateRange dateRange) { - super(dateRange); - } - - @Override - public void searchForWHONetResults() { - WHONetReportService reportService = SpringContext.getBean(WHONetReportService.class); - Date lowDate = dateRange.getLowDate(); - Date highDate = dateRange.getHighDate(); - rows = reportService.getWHONetRows(lowDate, highDate); - return; - } - -} 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/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/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java b/src/main/java/org/openelisglobal/testreflex/action/util/TestReflexUtil.java index b0433aaa80..0ff19d9a32 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; 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 + + + + +