diff --git a/analyzers/AB7500Fast/pom.xml b/analyzers/AB7500Fast/pom.xml new file mode 100644 index 0000000..f918d82 --- /dev/null +++ b/analyzers/AB7500Fast/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + AB7500Fast + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + \ No newline at end of file diff --git a/analyzers/AB7500Fast/src/main/java/AB7500Fast.xml b/analyzers/AB7500Fast/src/main/java/AB7500Fast.xml new file mode 100644 index 0000000..aeb4cc7 --- /dev/null +++ b/analyzers/AB7500Fast/src/main/java/AB7500Fast.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLAnalyzer.java b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLAnalyzer.java new file mode 100644 index 0000000..35e8057 --- /dev/null +++ b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLAnalyzer.java @@ -0,0 +1,58 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +public class AB7500VLAnalyzer implements AnalyzerImporterPlugin { +//private static final String DELIMITER = ","; + private static final CharSequence AB7500VL_INDICATOR = "sds7500fast"; + + int InstrumentIndex = -1; + + public boolean connect() { +// List nameMappinng = new ArrayList(); + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Quantity", "Viral Load")); + + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("AB7500VLAnalyzer", "Plugin for AB 7500 analyzer", + nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + + return true; + } + + public boolean isTargetAnalyzer(List lines) { + for (int j = 0; j < lines.size(); j++) { + if (lines.get(j).contains(AB7500VL_INDICATOR)) + return true; + + } + + return false; + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new AB7500VLAnalyzerImplementation(); + } + +} \ No newline at end of file diff --git a/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLAnalyzerImplementation.java b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLAnalyzerImplementation.java new file mode 100644 index 0000000..6e4cce5 --- /dev/null +++ b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLAnalyzerImplementation.java @@ -0,0 +1,255 @@ +/** + * 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 oe.plugin.analyzer; + +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analysis.dao.AnalysisDAO; +import org.openelisglobal.analysis.daoimpl.AnalysisDAOImpl; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +import java.util.HashMap; + +public class AB7500VLAnalyzerImplementation extends AnalyzerLineInserter { + + private int ORDER_NUMBER = 0; + private int TARGET_NUMBER = 0; + private int VALUE_NUMBER = 0; + String result = ""; + private boolean isControl = false; + private static final String DELIMITER = ","; + private static final String DATE_PATTERN = "yyyy-MM-dd HH:mm"; + static String ANALYZER_ID; + + static HashMap testHeaderNameMap = new HashMap(); + HashMap indexTestMap = new HashMap(); + static HashMap unitsIndexMap = new HashMap(); + + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + private String error; + String dateTime = ""; + + private final String accession_number_prefix = MessageUtil.getMessage("sample.entry.project.LART"); + // private final String accession_number_prefix = + // ConfigurationProperties.getInstance().getPropertyValue(Property.ACCESSION_NUMBER_PREFIX); + + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisDAO analysisDao = new AnalysisDAOImpl(); + Test test = (Test) SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0); + + static { + + testHeaderNameMap.put("Quantity", SpringContext.getBean(TestService.class).getTestByName("Viral Load")); + + unitsIndexMap.put("Quantity", "cp/ml"); + + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("AB7500VLAnalyzer"); + ANALYZER_ID = analyzer.getId(); + + } + + public boolean insert(List lines, String currentUserId) { + this.error = null; + List columnsList = getColumnsLines(lines); + + if (columnsList == null) + return false; + + List results = new ArrayList(); + + for (int j : columnsList) + getResultsForSampleType(lines, j, results); + + return persistImport(currentUserId, results); + } + + private boolean manageColumnsIndex(int columsLine, List lines) { + indexTestMap = new HashMap(); + String[] headers = lines.get(columsLine).split(DELIMITER); + + for (Integer i = 0; i < headers.length; i++) { + String header = headers[i]; + + if (testHeaderNameMap.containsKey(headers[i])) { + indexTestMap.put(i.toString(), headers[i]); + } else if ("Sample Name".equals(header)) { + ORDER_NUMBER = i; + } + + else if ("Target Name".equals(header)) { + TARGET_NUMBER = i; + } + + else if (("C?".equals(header)) || ("Cт".equals(header)) || ("CÑ,".equals(header))) { + VALUE_NUMBER = i; + } + + } + + return (indexTestMap.size() > 0); + } + + public String getError() { + return this.error; + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + /* + * if (result.getIsControl()){ resultList.add(result); return; } + */ + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(accession_number_prefix) || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + + List analyses = analysisDao.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Analysis analysis : analyses) { + if (analysis.getStatusId().equals(validStatusId)) + return; + } + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + + String[] fields = line.split(DELIMITER); + + for (Integer k = 0; k < fields.length; k++) { + + if (indexTestMap.containsKey(k.toString())) { + String testKey = indexTestMap.get(k.toString()); + AnalyzerResults aResult = new AnalyzerResults(); + Double resultAsDouble; + String AccessionNumber = ""; + String resultfinal = ""; + aResult.setTestId(testHeaderNameMap.get(testKey).getId()); + aResult.setTestName(testHeaderNameMap.get(testKey).getName()); + + // ----for result + if (fields[VALUE_NUMBER].contains("Undetermined") && fields[k].isEmpty()) { + result = fields[VALUE_NUMBER].trim(); + + } else if (!fields[k].isEmpty()) { + result = fields[k].trim(); + resultAsDouble = Math.log10(Double.parseDouble(result)); + DecimalFormat df = new DecimalFormat("#.##"); + resultfinal = result + "(" + df.format(resultAsDouble).toString() + ")"; + result = resultfinal; + + } + + // ----for accession number + if (!fields[ORDER_NUMBER].isEmpty()) { + AccessionNumber = fields[ORDER_NUMBER].trim(); + + } else { + AccessionNumber = fields[TARGET_NUMBER].trim(); + + } + + if (AccessionNumber.startsWith("BIOCENTRIC")) { + + isControl = true; + } else { + isControl = false; + } + + aResult.setResult(result); + aResult.setAnalyzerId(ANALYZER_ID); + aResult.setAccessionNumber(AccessionNumber); + aResult.setUnits(unitsIndexMap.get(testKey)); + aResult.setIsControl(isControl); + aResult.setResultType("A"); + + dateTime = dateTime.replaceAll("A", ""); + dateTime = dateTime.replaceAll("P", ""); + dateTime = dateTime.replaceAll("M", ""); + dateTime = dateTime.replaceAll("G", ""); + dateTime = dateTime.replaceAll("T", ""); + + aResult.setCompleteDate(getTimestampFromDate(dateTime.trim())); + + // System.out.print(" date: "+aResult.getCompleteDate() + " AccessionNumber: + // "+aResult.getAccessionNumber() + " Result: "+aResult.getResult()); + + addValueToResults(resultList, aResult); + } + + } + + } + + public List getColumnsLines(List lines) { + List linesList = new ArrayList(); + for (int i = 0; i < lines.size(); i++) { + System.out.print("******* line:" + i); + System.out.println(":" + lines.get(i)); + + if (lines.get(i).contains("Sample Name")) { + System.out.print("============== line:" + i); + System.out.println(":" + lines.get(i)); + linesList.add(i); + + } + + // i=i+1; + } + + return linesList.size() == 0 ? null : linesList; + } + + private Timestamp getTimestampFromDate(String dateTime) { + return DateUtil.convertStringDateToTimestampWithPattern(dateTime, DATE_PATTERN); + } + + public void getResultsForSampleType(List lines, int columsLine, List results) { + + boolean columnsFound = manageColumnsIndex(columsLine, lines); + + if (!columnsFound) + System.out.println("AB 7500 analyzer: Unable to find correct columns in file"); + + for (int i = columsLine + 1; i < lines.size(); ++i) { + if (lines.get(i).startsWith(",,,,,,")) + break; + createAnalyzerResultFromLine(lines.get(i), results); + } + + } + +} \ No newline at end of file diff --git a/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLMenu.java b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLMenu.java new file mode 100644 index 0000000..bad868a --- /dev/null +++ b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLMenu.java @@ -0,0 +1,48 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class AB7500VLMenu extends MenuPlugin +{ + protected void insertMenu() + { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + + menu.setParent(PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + + menu.setPresentationOrder(32); + + menu.setElementId("AB7500_vl_analyzer_plugin"); + + menu.setActionURL("/AnalyzerResults?type=AB7500VLAnalyzer"); + menu.setDisplayKey("banner.menu.results.AB7500vlanalyzer"); + menu.setOpenInNewWindow(false); + + service.addMenu(menu); + + service.insertLanguageKeyValue("banner.menu.results.AB7500vlanalyzer", "Virology: AB 7500 : Viral Load", Locale.ENGLISH.toLanguageTag()); + + service.insertLanguageKeyValue("banner.menu.results.AB7500vlanalyzer", "Virologie: AB 7500 : Charge Virale", Locale.FRENCH.toLanguageTag()); + } +} \ No newline at end of file diff --git a/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLPermission.java b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLPermission.java new file mode 100644 index 0000000..3d7e92a --- /dev/null +++ b/analyzers/AB7500Fast/src/main/java/oe/plugin/analyzer/AB7500VLPermission.java @@ -0,0 +1,37 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModule; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +/** + */ +public class AB7500VLPermission extends PermissionPlugin +{ + protected boolean insertPermission() + { + PluginPermissionService service = new PluginPermissionService(); + SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "AB7500VLAnalyzer", "Results->Analyzer->AB7500VLAnalyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole( "Results" ); + return service.bindRoleToModule(role, module,moduleUrl); + } +} \ No newline at end of file diff --git a/analyzers/Cobas4800/pom.xml b/analyzers/Cobas4800/pom.xml new file mode 100644 index 0000000..81939a7 --- /dev/null +++ b/analyzers/Cobas4800/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + Cobas4800 + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + \ No newline at end of file diff --git a/analyzers/Cobas4800/src/main/java/Cobas4800.xml b/analyzers/Cobas4800/src/main/java/Cobas4800.xml new file mode 100644 index 0000000..7a84829 --- /dev/null +++ b/analyzers/Cobas4800/src/main/java/Cobas4800.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Analyzer.java b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Analyzer.java new file mode 100644 index 0000000..cf4f21c --- /dev/null +++ b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Analyzer.java @@ -0,0 +1,61 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +public class Cobas4800Analyzer implements AnalyzerImporterPlugin +{ +//private static final String DELIMITER = "\\t"; +//private static String DELIMITER = "\\t"; +private static final CharSequence COBAS_4800_INDICATOR = "cobas 4800"; + +int InstrumentIndex = -1; + +public boolean connect() { +// List nameMappinng = new ArrayList(); + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Result", "Viral Load")); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("Cobas4800VLAnalyzer", "Plugin for Cobas4800 VL analyzer", nameMappinng); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("Cobas4800EIDAnalyzer", "Plugin for Cobas4800 EID analyzer", nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + + return true; +} + +public AnalyzerLineInserter getAnalyzerLineInserter() +{ + return new Cobas4800AnalyzerImplementation(); +} + +public boolean isTargetAnalyzer(List lines) { + + for (int j = 0; j < lines.size();j++){ + if(lines.get(j).contains(COBAS_4800_INDICATOR)) + return true; + + } + + return false; +} + +} \ No newline at end of file diff --git a/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800AnalyzerImplementation.java b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800AnalyzerImplementation.java new file mode 100644 index 0000000..413efe8 --- /dev/null +++ b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800AnalyzerImplementation.java @@ -0,0 +1,338 @@ +/** + * 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 oe.plugin.analyzer; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.dictionary.service.DictionaryService; +import org.openelisglobal.dictionary.valueholder.Dictionary; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; +import org.openelisglobal.testresult.service.TestResultService; +import org.openelisglobal.testresult.valueholder.TestResult; + + + + +public class Cobas4800AnalyzerImplementation extends AnalyzerLineInserter +{ + private static final String UNDER_THREASHOLD = "< LL"; + private static final double THREASHOLD = 20.0; + + private static String RESULT_FLAG = "Result Name"; + private static String RESULT_VALUE_FLAG = "Value"; + private static String VL_FLAG = "HIV-1"; + private static String EID_FLAG = "HIV-1-qual-DBS"; + private static String TEST_FLAG = "TestType"; + private static String ACCESSION_FLAG = "SpecimenId"; + private static String ACCEPTED_DATE_FLAG = "AcceptedDateTime"; + private static String TEST_TYPE_FLAG = "TestType"; + private static String CONTROL_FLAG="SpecimenType"; + + private static String NEGATIVE_ID; + private static String POSITIVE_ID; + private static String INDETERMINATE_ID; + private static String INVALID_ID; + private static String VALID_ID; + + private static final String DATE_PATTERN = "yyyy-MM-dd HH:mm:ss"; + static String VL_ANALYZER_ID ; + static String EID_ANALYZER_ID ; + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LART")+":"+MessageUtil.getMessage("sample.entry.project.LDBS"); + + static HashMap testHeaderNameMap = new HashMap(); + static HashMap indexAnalyzerMap = new HashMap(); + static HashMap resultsTypeMap = new HashMap(); + + + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + private String error; +// Test test = (Test)SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0); + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + + static + { + testHeaderNameMap.put(VL_FLAG, SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0));//.getTestByGUID("0e240569-c095-41c7-bfd2-049527452f16")); + testHeaderNameMap.put(EID_FLAG, SpringContext.getBean(TestService.class).getActiveTestByName("DNA PCR").get(0));//.getTestByGUID("fe6405c8-f96b-491b-95c9-b1f635339d6a")); + + resultsTypeMap.put(VL_FLAG, "A"); + resultsTypeMap.put(EID_FLAG, "D"); + + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("Cobas4800VLAnalyzer"); + VL_ANALYZER_ID =analyzer.getId(); + + analyzer = analyzerService.getAnalyzerByName("Cobas4800EIDAnalyzer"); + EID_ANALYZER_ID =analyzer.getId(); + + indexAnalyzerMap.put(VL_FLAG,VL_ANALYZER_ID); + indexAnalyzerMap.put(EID_FLAG,EID_ANALYZER_ID); + + DictionaryService dictionaryService = SpringContext.getBean(DictionaryService.class); + Test test = SpringContext.getBean(TestService.class).getActiveTestByName("DNA PCR").get(0); + List testResults = SpringContext.getBean(TestResultService.class).getActiveTestResultsByTest(test.getId()); + + for (TestResult testResult : testResults) { + Dictionary dictionary = dictionaryService.getDataForId(testResult.getValue()); + if ("Positive".equals(dictionary.getDictEntry())) + POSITIVE_ID = dictionary.getId(); + else if ("Negative".equals(dictionary.getDictEntry())) + NEGATIVE_ID = dictionary.getId(); + else if ("Invalid".equals(dictionary.getDictEntry())) + INVALID_ID = dictionary.getId(); + else if ("Valid".equals(dictionary.getDictEntry())) + VALID_ID = dictionary.getId(); + else if ("Indeterminate".equals(dictionary.getDictEntry())) + INDETERMINATE_ID = dictionary.getId(); + } + } + + public String getError() { + return this.error; + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + if (result.getIsControl()){ + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + String labPrefix=result.getAccessionNumber().substring(0, 4); + + if (!projectCode.contains(labPrefix) || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber())==null ) + return; + + List analyses=analysisService.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), result.getTestId()); + for(Analysis analysis :analyses) { + if(analysis.getStatusId().equals(validStatusId)) + return; + + } + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + } + + public boolean filterOrdersExport(List results,String labno) { + for(AnalyzerResults ar :results){ + if (ar.getAccessionNumber().equalsIgnoreCase(labno)) + return true; + } + return false; + + } + +public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && + lines.get(k).contains("Patient ID") && + lines.get(k).contains("Order Number") && + lines.get(k).contains("Sample ID") && + lines.get(k).contains("Test") && + lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } + +public boolean insert(List lines, String currentUserId) { + List results = new ArrayList(); + for (Entry entry : getResultsLines(lines,ACCESSION_FLAG,TEST_FLAG,RESULT_FLAG).entrySet()) { + createResultFromEntry(lines,entry, results); + } + Collections.sort(results, new Comparator(){ + public int compare(AnalyzerResults o1, AnalyzerResults o2) { + return o1.getAccessionNumber().compareTo(o2.getAccessionNumber()); + }}); + // ordersExport(results); + return persistImport(currentUserId, results); + } + +public HashMap getResultsLines(List lines, String LABNO_FLAG, String TEST_FLAG, String RESULT_FLAG) { + HashMap IdValuePair = new HashMap(); + + for(int i=0;i lines,Entry entry,List resultList){ + + AnalyzerResults analyzerResults = new AnalyzerResults(); + //LABNO processing + String line=lines.get(entry.getKey()); + + String accessionNumber=line.split(ACCESSION_FLAG)[1].substring(2,11); + + accessionNumber=accessionNumber.trim(); + accessionNumber=accessionNumber.replace(" ", ""); + String labPrefix=accessionNumber.substring(0, 4); + + if(!projectCode.contains(labPrefix) && accessionNumber.length()>=9) + accessionNumber=accessionNumber.substring(0, 9); + + analyzerResults.setAccessionNumber(accessionNumber); + + //COMPLETED_DATE processing + String completedDate=line.split(ACCEPTED_DATE_FLAG)[1].substring(2,12)+" 00:00:00"; + analyzerResults.setCompleteDate(getTimestampFromDate(completedDate)); + + //CONTROL CHECKING + String controlStatus = line.split(CONTROL_FLAG)[1]; + analyzerResults.setIsControl(controlStatus.contains("Control")); + + //TEST_TYPE processing + String testKey=line.split(TEST_TYPE_FLAG)[1]; + testKey=testKey.split("LisOrderId")[0].trim().substring(2); + testKey=testKey.substring(0,testKey.length()-1); + analyzerResults.setTestId(testHeaderNameMap.get(testKey).getId()); + analyzerResults.setTestName(testHeaderNameMap.get(testKey).getName()); + + //ANALYZER_ID processing + analyzerResults.setAnalyzerId(indexAnalyzerMap.get(testKey)); + + //RESULT_TYPE processing + analyzerResults.setResultType(resultsTypeMap.get(testKey)); + + //RESULT processing + line=lines.get(entry.getValue()); + String result=line.split(RESULT_VALUE_FLAG)[1].substring(2); + result=result.split("CodingSystemId")[0].trim(); + result=result.substring(0,result.length()-1); + result = testKey.equalsIgnoreCase(VL_FLAG)?getVLResults(result):testKey.equalsIgnoreCase(EID_FLAG)?getEIDResults(result):"XXXX"; + analyzerResults.setResult(result); + + //RESULT UNITS processing + if(testKey.equalsIgnoreCase(VL_FLAG)) + analyzerResults.setUnits(UNDER_THREASHOLD.equals(result) ? "" : "cp/ml"); + + + addValueToResults(resultList, analyzerResults); + +} + +private String getAppropriateResults(String result){ + result = result.replace("\"", "").trim(); + if(result.contains("Target Not Detected") || result.contains("Titer min")){ + result = UNDER_THREASHOLD; + }else{ + + String workingResult = result.replace("E", ""); + String[] splitResult = workingResult.split("\\+"); + + try{ + Double resultAsDouble = Double.parseDouble(splitResult[0]) * Math.pow(10, Double.parseDouble(splitResult[1])); + + if(resultAsDouble <= THREASHOLD){ + result = UNDER_THREASHOLD; + }else{ + result = String.valueOf((int)(Math.round(resultAsDouble))) ;//+ result.substring(result.indexOf("(")); + result=result+"("+String.format("%.3g%n", Math.log10(resultAsDouble)); + result=result+")"; + } + }catch(NumberFormatException e){ + return "XXXX"; + } + } + + return result; +} + +private Timestamp getTimestampFromDate(String dateTime) { + return DateUtil.convertStringDateToTimestampWithPattern(dateTime, DATE_PATTERN); +} + +private String getVLResults(String result){ + //result = result.replace("\"", "").trim(); + result=result.split("cp/mL")[0].trim(); + // System.out.print("RES="+result); + if(result.contains("Target Not Detected") || result.contains("Titer min")){ + result = UNDER_THREASHOLD; + }else{ + + String workingResult = result.replace("E", ""); + String[] splitResult = workingResult.split("\\+"); + + try{ + Double resultAsDouble = Double.parseDouble(splitResult[0]) * Math.pow(10, Double.parseDouble(splitResult[1])); + + if(resultAsDouble <= THREASHOLD){ + result = UNDER_THREASHOLD; + }else{ + result = String.valueOf((int)(Math.round(resultAsDouble))) ;//+ result.substring(result.indexOf("(")); + result=result+"("+String.format("%.3g%n", Math.log10(resultAsDouble)); + result=result+")"; + } + }catch(NumberFormatException e){ + return "XXXX"; + } + } + + return result; +} + +private String getEIDResults(String result) { + result = result.replace("\"", "").trim(); + + if (result.toLowerCase().equals("not detected")) + result = NEGATIVE_ID; + else if (result.toLowerCase().equals("detected")) + result = POSITIVE_ID; + else if (result.toLowerCase().equals("invalid")) + result = INVALID_ID; + else if (result.toLowerCase().equals("valid")) + result = VALID_ID; + else result = INDETERMINATE_ID; + + return result; + } + +} \ No newline at end of file diff --git a/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Menu.java b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Menu.java new file mode 100644 index 0000000..3fed2d3 --- /dev/null +++ b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Menu.java @@ -0,0 +1,59 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class Cobas4800Menu extends MenuPlugin +{ + protected void insertMenu() + { + PluginMenuService service = PluginMenuService.getInstance(); + + Menu menu = new Menu(); + menu.setParent(PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + menu.setPresentationOrder(132); + menu.setElementId("taqman4800_vl_analyzer_plugin"); + menu.setActionURL("/AnalyzerResults?type=Cobas4800VLAnalyzer"); + menu.setDisplayKey("banner.menu.results.cobas4800vlanalyzer"); + menu.setOpenInNewWindow(false); + + service.addMenu(menu); + + menu = new Menu(); + menu.setParent(PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + menu.setPresentationOrder(133); + menu.setElementId("taqman4800_eid_analyzer_plugin"); + menu.setActionURL("/AnalyzerResults?type=Cobas4800EIDAnalyzer"); + menu.setDisplayKey("banner.menu.results.cobas4800eidanalyzer"); + menu.setOpenInNewWindow(false); + + service.addMenu(menu); + + service.insertLanguageKeyValue("banner.menu.results.cobas4800vlanalyzer", "Virology: Cobas4800: Viral Load", Locale.ENGLISH.toLanguageTag()); + service.insertLanguageKeyValue("banner.menu.results.cobas4800vlanalyzer", "Virologie: Cobas4800: Charge Virale", Locale.FRENCH.toLanguageTag()); + + service.insertLanguageKeyValue("banner.menu.results.cobas4800eidanalyzer", "Virology: Cobas4800: EID", Locale.ENGLISH.toLanguageTag()); + service.insertLanguageKeyValue("banner.menu.results.cobas4800eidanalyzer", "Virologie: Cobas4800: EID", Locale.FRENCH.toLanguageTag()); + + + } +} \ No newline at end of file diff --git a/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Permission.java b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Permission.java new file mode 100644 index 0000000..cc0d583 --- /dev/null +++ b/analyzers/Cobas4800/src/main/java/oe/plugin/analyzer/Cobas4800Permission.java @@ -0,0 +1,43 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModule; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +/** + */ +public class Cobas4800Permission extends PermissionPlugin { + protected boolean insertPermission() { + PluginPermissionService service = new PluginPermissionService(); + SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "Cobas4800VLAnalyzer", + "Results->Analyzer->Cobas4800VLAnalyzer"); + Role role = service.getSystemRole("Virology automatic"); + + PluginPermissionService service2 = new PluginPermissionService(); + SystemModule module2 = service2.getOrCreateSystemModule("AnalyzerResults", "Cobas4800EIDAnalyzer", + "Results->Analyzer->Cobas4800EIDAnalyzer"); + Role role2 = service2.getSystemRole("Virology automatic"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + + return service.bindRoleToModule(role, module, moduleUrl) + && service2.bindRoleToModule(role2, module2, moduleUrl); + } +} \ No newline at end of file diff --git a/analyzers/Cobas6800VL/pom.xml b/analyzers/Cobas6800VL/pom.xml new file mode 100644 index 0000000..e9582f1 --- /dev/null +++ b/analyzers/Cobas6800VL/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + Cobas6800VL + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + \ No newline at end of file diff --git a/analyzers/Cobas6800VL/src/main/java/Cobas6800VL.xml b/analyzers/Cobas6800VL/src/main/java/Cobas6800VL.xml new file mode 100644 index 0000000..3410d9e --- /dev/null +++ b/analyzers/Cobas6800VL/src/main/java/Cobas6800VL.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLAnalyzer.java b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLAnalyzer.java new file mode 100644 index 0000000..2816895 --- /dev/null +++ b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLAnalyzer.java @@ -0,0 +1,44 @@ + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +// Referenced classes of package oe.plugin.analyzer: +// Cobas6800VLAnalyzerImplementation + +public class Cobas6800VLAnalyzer implements AnalyzerImporterPlugin { + + public Cobas6800VLAnalyzer() { + InstrumentIndex = -1; + } + + public boolean connect() { + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Result", "Viral Load")); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("Cobas6800VLAnalyzer", + "Plugin for Cobas6800 VL analyzer", nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + return true; + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new Cobas6800VLAnalyzerImplementation(); + } + + public boolean isTargetAnalyzer(List lines) { + for (int j = 0; j < lines.size(); j++) + if (((String) lines.get(j)).contains("Viral Load")) + return ((String) lines.get(0)).contains(COBAS_6800_VL_INDICATOR); + + return false; + } + + private static final CharSequence COBAS_6800_VL_INDICATOR = "^MPL"; + int InstrumentIndex; + +} diff --git a/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLAnalyzerImplementation.java b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLAnalyzerImplementation.java new file mode 100644 index 0000000..1d2af7f --- /dev/null +++ b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLAnalyzerImplementation.java @@ -0,0 +1,295 @@ +package oe.plugin.analyzer; + +import java.io.FileWriter; +import java.sql.*; +import java.util.*; + +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +public class Cobas6800VLAnalyzerImplementation extends AnalyzerLineInserter { + + public Cobas6800VLAnalyzerImplementation() { + indexTestMap = new HashMap(); + readerUtil = new AnalyzerReaderUtil(); + test = SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0); + validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + analysisService = SpringContext.getBean(AnalysisService.class); + } + + public String getError() { + return error; + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + if (result.getIsControl()) { + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(projectCode) + || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + List analyses = analysisService.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Iterator iterator = analyses.iterator(); iterator.hasNext();) { + Analysis analysis = (Analysis) iterator.next(); + if (analysis.getStatusId().equals(validStatusId)) + return; + } + + resultList.add(result); + AnalyzerResults resultFromDB = readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + } + + public void ordersExport(List results) { + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.postgresql.Driver"); + c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/clinlims", "clinlims", "clinlims"); + c.setAutoCommit(false); + System.out.println("Opened database successfully"); + String sql = (new StringBuilder( + "SELECT s.accession_number, a.test_id,pat.national_id,pat.external_id,pat.gender,pat.birth_date FROM clinlims.sample s,clinlims.sample_item si,clinlims.analysis a,clinlims.sample_human sh,clinlims.patient pat WHERE a.status_id=13 AND a.test_id IN (")) + .append(test.getId()).append(") AND ").append("a.sampitem_id=si.id AND ") + .append("si.samp_id=s.id AND ").append("sh.samp_id=s.id AND ").append("sh.patient_id=pat.id ") + .append("ORDER BY 1").toString(); + stmt = c.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + FileWriter writer = new FileWriter("/home/oeserver/Desktop/Prescriptions/ARVPRESC.AST", false); + writer.write("H|^~\\&|||GLIMS||ORM|||MPL|||A2.2|200712120754|"); + writer.write("\r\n"); + int inc = 0; + for (; rs.next(); writer.write("\r\n")) { + inc++; + String labno = rs.getString("accession_number"); + String sujetno = rs.getString("national_id"); + String external_id = rs.getString("external_id"); + String sexe = rs.getString("gender"); + String birth_date = rs.getString("birth_date"); + String patID = sujetno != null ? sujetno : external_id; + writer.write((new StringBuilder("P|")).append(inc).append("|").append(labno) + .append("|||Patient-XXXXX||").append(birth_date.substring(0, 10).replace("-", "")).append("|") + .append(sexe).append("||||||||||||||||||").toString()); + writer.write("\r\n"); + writer.write((new StringBuilder("OBR|1|")).append(labno).append("||Viral Load|R|||||||||||||") + .append(patID).append("||||||||||").toString()); + } + + writer.write("L|1|"); + rs.close(); + stmt.close(); + c.close(); + writer.close(); + } catch (Exception e) { + System.err.println((new StringBuilder(String.valueOf(e.getClass().getName()))).append(": ") + .append(e.getMessage()).toString()); + } + System.out.println("Operation done successfully"); + } + + public boolean filterOrdersExport(List results, String labno) { + for (Iterator iterator = results.iterator(); iterator.hasNext();) { + AnalyzerResults ar = (AnalyzerResults) iterator.next(); + if (ar.getAccessionNumber().equalsIgnoreCase(labno)) + return true; + } + + return false; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) + if (((String) lines.get(k)).contains("Patient Name") && ((String) lines.get(k)).contains("Patient ID") + && ((String) lines.get(k)).contains("Order Number") && ((String) lines.get(k)).contains("Sample ID") + && ((String) lines.get(k)).contains("Test") && ((String) lines.get(k)).contains("Result")) + return k; + + return -1; + } + + public boolean insert(List lines, String currentUserId) { + List results = new ArrayList(); + java.util.Map.Entry entry; + for (Iterator iterator = getResultsLines(lines, RESULT_FLAG, VL_FLAG).entrySet().iterator(); iterator + .hasNext(); createVLResultFromEntry(lines, entry, results)) + entry = (java.util.Map.Entry) iterator.next(); + + Collections.sort(results, new Comparator() { + + public int compare(AnalyzerResults o1, AnalyzerResults o2) { + return o1.getAccessionNumber().compareTo(o2.getAccessionNumber()); + } + + }); + return persistImport(currentUserId, results); + } + + public HashMap getResultsLines(List lines, String RESULT_FLAG, String TEST_FLAG) { + HashMap IdValuePair = new HashMap(); + for (int i = 0; i < lines.size(); i++) + if (((String) lines.get(i)).startsWith("P|")) { + int j; + for (j = i; !((String) lines.get(j)).contains(RESULT_FLAG) + || !((String) lines.get(j)).contains(TEST_FLAG); j++) + ; + IdValuePair.put(Integer.valueOf(i), Integer.valueOf(j)); + } + + return IdValuePair.size() != 0 ? IdValuePair : null; + } + + public void createVLResultFromEntry(List lines, java.util.Map.Entry entry, List resultList) { + AnalyzerResults analyzerResults = new AnalyzerResults(); + String line = (String) lines.get(((Integer) entry.getKey()).intValue()); + for (int i = 1; i <= 2; i++) + line = line.substring(1 + line.indexOf("|")); + + String accessionNumber = line.substring(0, line.indexOf("|")); + accessionNumber = accessionNumber.trim(); + accessionNumber = accessionNumber.replace(" ", ""); + if (accessionNumber.startsWith(projectCode) && accessionNumber.length() >= 9) + accessionNumber = accessionNumber.substring(0, 9); + line = (String) lines.get(((Integer) entry.getValue()).intValue()); + for (int i = 1; i <= 5; i++) + line = line.substring(1 + line.indexOf("|")); + + String result = line.substring(0, line.indexOf("|")); + result = getAppropriateResults(result); + for (int i = 1; i <= 7; i++) + line = line.substring(1 + line.indexOf("|")); + + String completedDate = line.substring(0, line.indexOf("|")); + analyzerResults.setAnalyzerId(ANALYZER_ID); + analyzerResults.setResult(result); + analyzerResults.setUnits("< LL".equals(result) ? "" : "cp/ml"); + analyzerResults + .setCompleteDate( + DateUtil.convertStringDateToTimestampWithPattern( + (new StringBuilder(String.valueOf(completedDate.substring(0, 4)))).append("/") + .append(completedDate.substring(4, 6)).append("/") + .append(completedDate.substring(6, 8)).append(" 00:00:00").toString(), + "yyyy/MM/dd HH:mm:ss")); + analyzerResults.setTestId(test.getId()); + analyzerResults.setIsControl(false); + analyzerResults.setTestName(test.getName()); + analyzerResults.setResultType("A"); + analyzerResults.setAccessionNumber(accessionNumber); + addValueToResults(resultList, analyzerResults); + } + + public void ordersExport2(List results) { + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.postgresql.Driver"); + c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/clinlims", "clinlims", "clinlims"); + c.setAutoCommit(false); + System.out.println("Opened database successfully"); + String sql = (new StringBuilder( + "SELECT s.accession_number, a.test_id,pat.national_id,pat.external_id,pat.gender,pat.birth_date FROM clinlims.sample s,clinlims.sample_item si,clinlims.analysis a,clinlims.sample_human sh,clinlims.patient pat WHERE a.status_id=13 AND a.test_id IN (")) + .append(test.getId()).append(") AND ").append("a.sampitem_id=si.id AND ") + .append("si.samp_id=s.id AND ").append("sh.samp_id=s.id AND ").append("sh.patient_id=pat.id ") + .append("ORDER BY 1").toString(); + stmt = c.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + FileWriter writer = new FileWriter("/home/oeserver/Desktop/Prescriptions/ARVPRESC.AST", false); + writer.write("H|^~\\&|||GLIMS||ORM|||MPL|||A2.2|200712120754|"); + writer.write("\r\n"); + int inc = 0; + for (; rs.next(); writer.write("\r\n")) { + inc++; + String labno = rs.getString("accession_number"); + String sujetno = rs.getString("national_id"); + String external_id = rs.getString("external_id"); + String sexe = rs.getString("gender"); + String birth_date = rs.getString("birth_date"); + String patID = sujetno != null ? sujetno : external_id; + writer.write((new StringBuilder("P|")).append(inc).append("|").append(labno) + .append("|||Patient-XXXXX||").append(birth_date.substring(0, 10).replace("-", "")).append("|") + .append(sexe).append("||||||||||||||||||").toString()); + writer.write("\r\n"); + writer.write((new StringBuilder("OBR|1|")).append(labno).append("||Viral Load|R|||||||||||||") + .append(patID).append("||||||||||").toString()); + } + + writer.write("L|1|"); + rs.close(); + stmt.close(); + c.close(); + writer.close(); + } catch (Exception e) { + System.err.println((new StringBuilder(String.valueOf(e.getClass().getName()))).append(": ") + .append(e.getMessage()).toString()); + } + System.out.println("Operation done successfully"); + } + + private String getAppropriateResults(String result) { + result = result.replace("\"", "").trim(); + if (result.contains("BT") || result.contains("ND") || result.contains("<20")) + result = "< LL"; + else + try { + Double resultAsDouble = Double.valueOf(Double.parseDouble(result)); + if (resultAsDouble.doubleValue() <= 20D) { + result = "< LL"; + } else { + result = String.valueOf((int) Math.round(resultAsDouble.doubleValue())); + result = (new StringBuilder(String.valueOf(result))).append("(") + .append(String.format("%.3g%n", + new Object[] { Double.valueOf(Math.log10(resultAsDouble.doubleValue())) })) + .toString(); + result = (new StringBuilder(String.valueOf(result))).append(")").toString(); + } + } catch (NumberFormatException e) { + return "XXXX"; + } + return result; + } + + private static final String UNDER_THREASHOLD = "< LL"; + private static final double THREASHOLD = 20D; + private static String RESULT_FLAG = "OBX"; + private static String VL_FLAG = "Viral Load"; + private static final String DATE_PATTERN = "yyyy/MM/dd HH:mm:ss"; + static String ANALYZER_ID; + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LART"); + static HashMap testHeaderNameMap; + HashMap indexTestMap; + static HashMap unitsIndexMap; + private AnalyzerReaderUtil readerUtil; + private String error; + Test test; + String validStatusId; + AnalysisService analysisService; + + static { + testHeaderNameMap = new HashMap(); + unitsIndexMap = new HashMap(); + testHeaderNameMap.put("Viral Load", + SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0)); + testHeaderNameMap.put("DNA PCR", + SpringContext.getBean(TestService.class).getActiveTestByName("DNA PCR").get(0)); + unitsIndexMap.put("CD4", ""); + unitsIndexMap.put("%CD4", "%"); + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("Cobas6800VLAnalyzer"); + ANALYZER_ID = analyzer.getId(); + } +} diff --git a/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLMenu.java b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLMenu.java new file mode 100644 index 0000000..c0ecd16 --- /dev/null +++ b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLMenu.java @@ -0,0 +1,30 @@ +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class Cobas6800VLMenu extends MenuPlugin +{ + + public Cobas6800VLMenu() + { + } + + protected void insertMenu() + { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + menu.setParent(PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + menu.setPresentationOrder(134); + menu.setElementId("cobas6800_vl_analyzer_plugin"); + menu.setActionURL("/AnalyzerResults?type=Cobas6800VLAnalyzer"); + menu.setDisplayKey("banner.menu.results.cobas6800vlanalyzer"); + menu.setOpenInNewWindow(false); + service.addMenu(menu); + service.insertLanguageKeyValue("banner.menu.results.cobas6800vlanalyzer", "Virology: Cobas6800: Viral Load", Locale.ENGLISH.toLanguageTag()); + service.insertLanguageKeyValue("banner.menu.results.cobas6800vlanalyzer", "Virologie: Cobas6800: Charge Virale", Locale.FRENCH.toLanguageTag()); + } +} diff --git a/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLPermission.java b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLPermission.java new file mode 100644 index 0000000..a5200fb --- /dev/null +++ b/analyzers/Cobas6800VL/src/main/java/oe/plugin/analyzer/Cobas6800VLPermission.java @@ -0,0 +1,24 @@ +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModule; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +public class Cobas6800VLPermission extends PermissionPlugin +{ + + public Cobas6800VLPermission() + { + } + + protected boolean insertPermission() + { + PluginPermissionService service = new PluginPermissionService(); + SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "Cobas6800VLAnalyzer", "Results->Analyzer->Cobas6800VLAnalyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} diff --git a/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111AnalyzerImplementation.java b/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111AnalyzerImplementation.java index 153ddfd..9df7866 100644 --- a/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111AnalyzerImplementation.java +++ b/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111AnalyzerImplementation.java @@ -55,6 +55,10 @@ public class CobasC111AnalyzerImplementation extends AnalyzerLineInserter { testNameMap.put("GLU2", SpringContext.getBean(TestService.class).getTestByName("Glucose")); testNameMap.put("CREJ2", SpringContext.getBean(TestService.class).getTestByName("Créatinine")); testNameMap.put("ALTL", SpringContext.getBean(TestService.class).getTestByName("Transaminases GPT (37°C)")); + testNameMap.put("ASTL", SpringContext.getBean(TestService.class).getTestByName("Transaminases G0T (37°C)")); + testNameMap.put("CHOL2", SpringContext.getBean(TestService.class).getTestByName("Cholestérol total")); + testNameMap.put("HDLC3", SpringContext.getBean(TestService.class).getTestByName("Cholestérol HDL")); + testNameMap.put("TRIGL", SpringContext.getBean(TestService.class).getTestByName("Triglycérides")); System.out.println(testNameMap); @@ -71,6 +75,10 @@ public class CobasC111AnalyzerImplementation extends AnalyzerLineInserter { testUnitMap.put("GLU2", "/1|10^3/uL"); testUnitMap.put("CREJ2", "/1|10^6/uL"); testUnitMap.put("ALTL", "/1|g/dL"); + testUnitMap.put("ASTL", "/1|g/dL"); + testUnitMap.put("CHOL2", "/1|g/L"); + testUnitMap.put("HDLC3", "/1|g/L"); + testUnitMap.put("TRIGL", "/1|g/L"); System.out.println(testUnitMap); diff --git a/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111Permission.java b/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111Permission.java index a13db88..d6a007d 100644 --- a/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111Permission.java +++ b/analyzers/CobasC111/src/oe/plugin/analyzer/CobasC111Permission.java @@ -29,6 +29,7 @@ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "CobasC111Analyzer", "Results->Analyzer->CobasC111Analyzer" ); Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/importAnalyzer"); + return service.bindRoleToModule( role, module, moduleUrl ); } } diff --git a/analyzers/CobasIntegra400/src/oe/plugin/analyzer/CobasIntegra400Permission.java b/analyzers/CobasIntegra400/src/oe/plugin/analyzer/CobasIntegra400Permission.java index a7df8f6..84336e5 100644 --- a/analyzers/CobasIntegra400/src/oe/plugin/analyzer/CobasIntegra400Permission.java +++ b/analyzers/CobasIntegra400/src/oe/plugin/analyzer/CobasIntegra400Permission.java @@ -28,8 +28,8 @@ public class CobasIntegra400Permission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "CobasIntegra400", "Results->Analyzer->CobasIntegra400" ); - Role role = service.getSystemRole( "Results Admin" ); - //Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } \ No newline at end of file diff --git a/analyzers/CobasTaqMan48DBS/src/oe/plugin/analyzer/TaqMan48DBSPermission.java b/analyzers/CobasTaqMan48DBS/src/oe/plugin/analyzer/TaqMan48DBSPermission.java index aa280e7..8cb0c65 100644 --- a/analyzers/CobasTaqMan48DBS/src/oe/plugin/analyzer/TaqMan48DBSPermission.java +++ b/analyzers/CobasTaqMan48DBS/src/oe/plugin/analyzer/TaqMan48DBSPermission.java @@ -28,7 +28,8 @@ public class TaqMan48DBSPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "TaqMan48DBSAnalyzer", "Results->Analyzer->TaqMan48DBSAnalyzer" ); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/CobasTaqMan48VL/pom.xml b/analyzers/CobasTaqMan48VL/pom.xml new file mode 100644 index 0000000..74ca0d4 --- /dev/null +++ b/analyzers/CobasTaqMan48VL/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + CobasTaqMan48VL + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/CobasTaqMan48VL/src/main/java/CobasTaqMan48VL.xml b/analyzers/CobasTaqMan48VL/src/main/java/CobasTaqMan48VL.xml new file mode 100644 index 0000000..37b017c --- /dev/null +++ b/analyzers/CobasTaqMan48VL/src/main/java/CobasTaqMan48VL.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLAnalyzer.java b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLAnalyzer.java new file mode 100644 index 0000000..2a0d803 --- /dev/null +++ b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLAnalyzer.java @@ -0,0 +1,86 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +public class TaqMan48VLAnalyzer implements AnalyzerImporterPlugin { +//private static final String DELIMITER = "\\t"; + private static String DELIMITER = "\\t"; + private static final CharSequence COBAS_TAQMAN_VL_INDICATOR = "HI2CAP48"; + private static final CharSequence COBAS_TAQMAN_VL_INDICATOR2 = "IFS48CDC"; + + int InstrumentIndex = -1; + + public boolean connect() { +// List nameMappinng = new ArrayList(); + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Result", "Viral Load")); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("TaqMan48VLAnalyzer", + "Plugin for Cobas TaqMan48 VL analyzer", nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + + return true; + } + + public boolean isTargetAnalyzer(List lines) { + if (getColumnsLine(lines) < 0) + return false; + DELIMITER = ((String) lines.get(getColumnsLine(lines))).substring(14, 15); + String[] data = ((String) lines.get(getColumnsLine(lines))).split(DELIMITER); + for (int j = 0; j < data.length; j++) { + if (data[j].contains("Test")) { + this.InstrumentIndex = j; + break; + } + + } + + if (lines.size() > getColumnsLine(lines) + 1) { + data = ((String) lines.get(getColumnsLine(lines) + 1)).split(DELIMITER); + if ((data[this.InstrumentIndex].contains(COBAS_TAQMAN_VL_INDICATOR)) + || (data[this.InstrumentIndex].contains(COBAS_TAQMAN_VL_INDICATOR2))) { + return true; + } + } + + return false; + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new TaqMan48VLAnalyzerImplementation(); + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && lines.get(k).contains("Patient ID") + && lines.get(k).contains("Order Number") && lines.get(k).contains("Sample ID") + && lines.get(k).contains("Test") && lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } + +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLAnalyzerImplementation.java b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLAnalyzerImplementation.java new file mode 100644 index 0000000..576b60f --- /dev/null +++ b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLAnalyzerImplementation.java @@ -0,0 +1,209 @@ +/** + * 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 oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +public class TaqMan48VLAnalyzerImplementation extends AnalyzerLineInserter { + private static final String UNDER_THREASHOLD = "< LL"; + private static final double THREASHOLD = 20.0; + private int ORDER_NUMBER = 0; + private int ORDER_DATE = 0; + private int RESULT = 0; + private int SAMPLE_TYPE = 0; + private int UNIT = 0; + // private static final String DELIMITER = "\\t"; + private static String DELIMITER = "\\t"; + private static final String DATE_PATTERN = "yyyy/MM/dd HH:mm:ss"; + static String ANALYZER_ID; + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LART"); + + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + private String error; + Test test = SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0); + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + + static { + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("TaqMan48VLAnalyzer"); + ANALYZER_ID = analyzer.getId(); + } + + public boolean insert(List lines, String currentUserId) { + this.error = null; + + List results = new ArrayList(); + + boolean columnsFound = manageColumnsIndex(lines); + + if (!columnsFound) { + this.error = "Cobas Taqman VL analyzer: Unable to find correct columns in file"; + return false; + } + + for (int i = getColumnsLine(lines) + 1; i < lines.size(); i++) { + createAnalyzerResultFromLine((String) lines.get(i), results); + } + + return persistImport(currentUserId, results); + } + + private boolean manageColumnsIndex(List lines) { + if (getColumnsLine(lines) < 0) + return false; + DELIMITER = ((String) lines.get(getColumnsLine(lines))).substring(14, 15); + String[] fields = ((String) lines.get(getColumnsLine(lines))).split(DELIMITER); + + for (int i = 0; i < fields.length; i++) { + String header = fields[i].replace("\"", ""); + + if ("Order Number".equals(header)) + ORDER_NUMBER = i; + else if ("Order Date/Time".equals(header)) + ORDER_DATE = i; + else if ("Result".equals(header)) + RESULT = i; + else if ("Sample Type".equals(header)) { + SAMPLE_TYPE = i; + } else if ("Unit".equals(header)) { + UNIT = i; + } + } + + return (ORDER_DATE != 0) && (ORDER_NUMBER != 0) && (RESULT != 0) && (SAMPLE_TYPE != 0) && (UNIT != 0); + } + + public String getError() { + return this.error; + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + + if (result.getIsControl()) { + resultList.add(result); + return; + } + AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(projectCode) + || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + + List analyses = analysisService.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Analysis analysis : analyses) { + if (analysis.getStatusId().equals(validStatusId)) + return; + } + + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + String[] fields = line.split(DELIMITER); + + AnalyzerResults analyzerResults = new AnalyzerResults(); + + String result = getAppropriateResults(fields[RESULT]); + String accessionNumber = fields[this.ORDER_NUMBER].replace("\"", "").trim(); + accessionNumber = accessionNumber.replace(" ", ""); + if (accessionNumber.startsWith(projectCode) && accessionNumber.length() >= 9) + accessionNumber = accessionNumber.substring(0, 9); + + analyzerResults.setAnalyzerId(ANALYZER_ID); + analyzerResults.setResult(result); + analyzerResults.setUnits(UNDER_THREASHOLD.equals(result) ? "" : fields[UNIT].replace("\"", "").trim()); + analyzerResults.setCompleteDate(DateUtil + .convertStringDateToTimestampWithPattern(fields[ORDER_DATE].replace("\"", "").trim(), DATE_PATTERN)); + analyzerResults.setTestId(test.getId()); + analyzerResults.setIsControl(!"S".equals(fields[SAMPLE_TYPE].replace("\"", "").trim())); + analyzerResults.setTestName(test.getName()); + analyzerResults.setResultType("A"); + + if (analyzerResults.getIsControl()) { + accessionNumber = accessionNumber + ":" + fields[this.SAMPLE_TYPE].replace("\"", "").trim(); + } + + analyzerResults.setAccessionNumber(accessionNumber); + + // System.out.println("***" + analyzerResults.getAccessionNumber() + " " + + // analyzerResults.getTestName() + " " + analyzerResults.getResult()); + + addValueToResults(resultList, analyzerResults); + } + + private String getAppropriateResults(String result) { + result = result.replace("\"", "").trim(); + if ("Target Not Detected".equalsIgnoreCase(result) || "Below range".equalsIgnoreCase(result)) { + result = UNDER_THREASHOLD; + } else { + + String workingResult = result.split("\\(")[0].replace("<", "").replace("E", ""); + String[] splitResult = workingResult.split("\\+"); + + try { + Double resultAsDouble = Double.parseDouble(splitResult[0]) + * Math.pow(10, Double.parseDouble(splitResult[1])); + + if (resultAsDouble <= THREASHOLD) { + result = UNDER_THREASHOLD; + } else { + result = String.valueOf((int) (Math.round(resultAsDouble))) + result.substring(result.indexOf("(")); + } + } catch (NumberFormatException e) { + return "XXXX"; + } + } + + return result; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && lines.get(k).contains("Patient ID") + && lines.get(k).contains("Order Number") && lines.get(k).contains("Sample ID") + && lines.get(k).contains("Test") && lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLMenu.java b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLMenu.java new file mode 100644 index 0000000..501691b --- /dev/null +++ b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLMenu.java @@ -0,0 +1,49 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class TaqMan48VLMenu extends MenuPlugin { + protected void insertMenu() { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + + menu.setParent( + PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + + menu.setPresentationOrder(30); + + menu.setElementId("taqman48_vl_analyzer_plugin"); + + menu.setActionURL("/AnalyzerResults?type=TaqMan48VLAnalyzer"); + menu.setDisplayKey("banner.menu.results.taqman48vlanalyzer"); + menu.setOpenInNewWindow(false); + + service.addMenu(menu); + + service.insertLanguageKeyValue("banner.menu.results.taqman48vlanalyzer", "Virology: Cobas TaqMan48: Viral Load", + Locale.FRENCH.toLanguageTag()); + + service.insertLanguageKeyValue("banner.menu.results.taqman48vlanalyzer", + "Virologie: Cobas TaqMan48: Charge Virale", Locale.FRENCH.toLanguageTag()); + } +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLPermission.java b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLPermission.java new file mode 100644 index 0000000..a16afc6 --- /dev/null +++ b/analyzers/CobasTaqMan48VL/src/main/java/oe/plugin/analyzer/TaqMan48VLPermission.java @@ -0,0 +1,36 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModule; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +/** + */ +public class TaqMan48VLPermission extends PermissionPlugin { + protected boolean insertPermission() { + PluginPermissionService service = new PluginPermissionService(); + SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "TaqMan48VLAnalyzer", + "Results->Analyzer->TaqMan48VLAnalyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan96DBS/pom.xml b/analyzers/CobasTaqMan96DBS/pom.xml new file mode 100644 index 0000000..32a080c --- /dev/null +++ b/analyzers/CobasTaqMan96DBS/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + CobasTaqMan96DBS + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/CobasTaqMan96DBS/src/main/java/CobasTaqMan96DBS.xml b/analyzers/CobasTaqMan96DBS/src/main/java/CobasTaqMan96DBS.xml new file mode 100644 index 0000000..53736fa --- /dev/null +++ b/analyzers/CobasTaqMan96DBS/src/main/java/CobasTaqMan96DBS.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSAnalyzer.java b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSAnalyzer.java new file mode 100644 index 0000000..f5f9999 --- /dev/null +++ b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSAnalyzer.java @@ -0,0 +1,86 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +public class TaqMan96DBSAnalyzer implements AnalyzerImporterPlugin { +//private static final String DELIMITER = "\\t"; + private static String DELIMITER = "\\t"; + private static final CharSequence COBAS_TAQMAN_DBS_INDICATOR = "HI2QLD96"; + + int InstrumentIndex = -1; + int colunmsLine = -1; + + public boolean connect() { + // List nameMappinng = new ArrayList(); + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Result", "DNA PCR")); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("TaqMan96DBSAnalyzer", + "Plugin for Cobas TaqMan96 DBS analyzer", nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + + return true; + } + + public boolean isTargetAnalyzer(List lines) { + if (getColumnsLine(lines) < 0) + return false; + DELIMITER = ((String) lines.get(getColumnsLine(lines))).substring(14, 15); + String[] data = ((String) lines.get(getColumnsLine(lines))).split(DELIMITER); + for (int j = 0; j < data.length; j++) { + if (data[j].contains("Test")) { + this.InstrumentIndex = j; + break; + } + + } + + if (lines.size() > getColumnsLine(lines) + 1) { + data = ((String) lines.get(getColumnsLine(lines) + 1)).split(DELIMITER); + if (data[this.InstrumentIndex].contains(COBAS_TAQMAN_DBS_INDICATOR)) { + return true; + } + } + + return false; + + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new TaqMan96DBSAnalyzerImplementation(); + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && lines.get(k).contains("Patient ID") + && lines.get(k).contains("Order Number") && lines.get(k).contains("Sample ID") + && lines.get(k).contains("Test") && lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } + +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSAnalyzerImplementation.java b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSAnalyzerImplementation.java new file mode 100644 index 0000000..3725b2f --- /dev/null +++ b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSAnalyzerImplementation.java @@ -0,0 +1,218 @@ +/** + * 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 oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.dictionary.service.DictionaryService; +import org.openelisglobal.dictionary.valueholder.Dictionary; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; +import org.openelisglobal.testresult.service.TestResultService; +import org.openelisglobal.testresult.valueholder.TestResult; + +public class TaqMan96DBSAnalyzerImplementation extends AnalyzerLineInserter { + private int ORDER_NUMBER = 0; + private int ORDER_DATE = 0; + private int RESULT = 0; + private int SAMPLE_TYPE = 0; + + // private static final String DELIMITER = "\\t"; + private static String DELIMITER = "\\t"; + private static final String DATE_PATTERN = "yyyy/MM/dd HH:mm:ss"; + private static String NEGATIVE_ID; + private static String POSITIVE_ID; + private static String INDETERMINATE_ID; + private static String INVALID_ID; + private static String VALID_ID; + static String ANALYZER_ID; + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + private String error; + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LDBS"); + + static Test test = SpringContext.getBean(TestService.class).getActiveTestByName("DNA PCR").get(0); + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + static { + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("TaqMan96DBSAnalyzer"); + ANALYZER_ID = analyzer.getId(); + + DictionaryService dictionaryService = SpringContext.getBean(DictionaryService.class); + List testResults = SpringContext.getBean(TestResultService.class) + .getActiveTestResultsByTest(test.getId()); + + for (TestResult testResult : testResults) { + Dictionary dictionary = dictionaryService.getDataForId(testResult.getValue()); + if ("Positive".equals(dictionary.getDictEntry())) + POSITIVE_ID = dictionary.getId(); + else if ("Negative".equals(dictionary.getDictEntry())) + NEGATIVE_ID = dictionary.getId(); + else if ("Invalid".equals(dictionary.getDictEntry())) + INVALID_ID = dictionary.getId(); + else if ("Valid".equals(dictionary.getDictEntry())) + VALID_ID = dictionary.getId(); + else if ("Indeterminate".equals(dictionary.getDictEntry())) + INDETERMINATE_ID = dictionary.getId(); + } + } + + public boolean insert(List lines, String currentUserId) { + this.error = null; + + List results = new ArrayList(); + + boolean columnsFound = manageColumnsIndex(lines); + + if (!columnsFound) { + this.error = "Cobas Taqman DBS analyzer: Unable to find correct columns in file"; + return false; + } + + for (int i = getColumnsLine(lines) + 1; i < lines.size(); i++) { + createAnalyzerResultFromLine((String) lines.get(i), results); + } + + return persistImport(currentUserId, results); + + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + String[] fields = line.split(DELIMITER); + + AnalyzerResults analyzerResults = new AnalyzerResults(); + + String result = getAppropriateResults(fields[this.RESULT]); + String accessionNumber = fields[this.ORDER_NUMBER].replace("\"", "").trim(); + accessionNumber = accessionNumber.replace(" ", ""); + if (accessionNumber.startsWith(projectCode) && accessionNumber.length() >= 9) + accessionNumber = accessionNumber.substring(0, 9); + + analyzerResults.setAnalyzerId(ANALYZER_ID); + analyzerResults.setResult(result); + analyzerResults.setCompleteDate(DateUtil.convertStringDateToTimestampWithPattern( + fields[this.ORDER_DATE].replace("\"", "").trim(), DATE_PATTERN)); + analyzerResults.setTestId(test.getId()); + analyzerResults.setIsControl(fields[this.RESULT].replace("\"", "").trim().toUpperCase().equals("VALID")); + analyzerResults.setTestName(test.getName()); + analyzerResults.setResultType("D"); + + if (analyzerResults.getIsControl()) { + accessionNumber = accessionNumber + ":" + fields[this.SAMPLE_TYPE].replace("\"", "").trim(); + } + System.out.println("***" + accessionNumber + " " + result); + analyzerResults.setAccessionNumber(accessionNumber); + + addValueToResults(resultList, analyzerResults); + } + + private String getAppropriateResults(String result) { + result = result.replace("\"", "").trim(); + + if (result.toLowerCase().equals("not detected dbs")) + result = NEGATIVE_ID; + else if (result.toLowerCase().equals("detected dbs")) + result = POSITIVE_ID; + else if (result.toLowerCase().equals("invalid")) + result = INVALID_ID; + else if (result.toLowerCase().equals("valid")) + result = VALID_ID; + else + result = INDETERMINATE_ID; + + return result; + } + + public String getError() { + return this.error; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && lines.get(k).contains("Patient ID") + && lines.get(k).contains("Order Number") && lines.get(k).contains("Sample ID") + && lines.get(k).contains("Test") && lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } + + private boolean manageColumnsIndex(List lines) { + if (getColumnsLine(lines) < 0) + return false; + DELIMITER = ((String) lines.get(getColumnsLine(lines))).substring(14, 15); + String[] fields = ((String) lines.get(getColumnsLine(lines))).split(DELIMITER); + + for (int i = 0; i < fields.length; i++) { + String header = fields[i].replace("\"", ""); + + if ("Order Number".equals(header)) + ORDER_NUMBER = i; + else if ("Order Date/Time".equals(header)) + ORDER_DATE = i; + else if ("Result".equals(header)) + RESULT = i; + else if ("Sample Type".equals(header)) { + SAMPLE_TYPE = i; + } + + } + + return (ORDER_DATE != 0) && (ORDER_NUMBER != 0) && (RESULT != 0) && (SAMPLE_TYPE != 0); + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + + if (result.getIsControl()) { + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(projectCode) || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + + List analyses = analysisService.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Analysis analysis : analyses) { + if (analysis.getStatusId().equals(validStatusId)) + return; + } + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + + } + +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSMenu.java b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSMenu.java new file mode 100644 index 0000000..c11e535 --- /dev/null +++ b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSMenu.java @@ -0,0 +1,49 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class TaqMan96DBSMenu extends MenuPlugin { + protected void insertMenu() { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + + menu.setParent( + PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + + menu.setPresentationOrder(33); + + menu.setElementId("taqman96_dbs_analyzer_plugin"); + + menu.setActionURL("/AnalyzerResults?type=TaqMan96DBSAnalyzer"); + menu.setDisplayKey("banner.menu.results.taqman96dbsanalyzer"); + menu.setOpenInNewWindow(false); + + service.addMenu(menu); + + service.insertLanguageKeyValue("banner.menu.results.taqman96dbsanalyzer", "Virology: Cobas TaqMan96: DNA PCR", + Locale.ENGLISH.toLanguageTag()); + + service.insertLanguageKeyValue("banner.menu.results.taqman96dbsanalyzer", "Virologie: Cobas TaqMan96: DNA PCR", + Locale.FRENCH.toLanguageTag()); + } +} \ No newline at end of file diff --git a/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSPermission.java b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSPermission.java new file mode 100644 index 0000000..918daf9 --- /dev/null +++ b/analyzers/CobasTaqMan96DBS/src/main/java/oe/plugin/analyzer/TaqMan96DBSPermission.java @@ -0,0 +1,36 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModule; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +/** + */ +public class TaqMan96DBSPermission extends PermissionPlugin { + protected boolean insertPermission() { + PluginPermissionService service = new PluginPermissionService(); + SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "TaqMan96DBSAnalyzer", + "Results->Analyzer->TaqMan96DBSAnalyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} diff --git a/analyzers/CobasTaqman96VL/pom.xml b/analyzers/CobasTaqman96VL/pom.xml new file mode 100644 index 0000000..25fd000 --- /dev/null +++ b/analyzers/CobasTaqman96VL/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + CobasTaqman96VL + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/CobasTaqman96VL/src/main/java/CobasTaqman96VL.xml b/analyzers/CobasTaqman96VL/src/main/java/CobasTaqman96VL.xml new file mode 100644 index 0000000..c859b14 --- /dev/null +++ b/analyzers/CobasTaqman96VL/src/main/java/CobasTaqman96VL.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLAnalyzer.java b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLAnalyzer.java new file mode 100644 index 0000000..f3231db --- /dev/null +++ b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLAnalyzer.java @@ -0,0 +1,87 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +public class TaqMan96VLAnalyzer implements AnalyzerImporterPlugin { +//private static final String DELIMITER = "\\t"; + private static String DELIMITER = "\\t"; + private static final CharSequence COBAS_TAQMAN_VL_INDICATOR = "HI2CAP96"; + private static final CharSequence COBAS_TAQMAN_VL_INDICATOR2 = "IFS96CDC"; + + int InstrumentIndex = -1; + + public boolean connect() { +// List nameMappinng = new ArrayList(); + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Result", "Viral Load")); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("TaqMan96VLAnalyzer", + "Plugin for Cobas TaqMan96 VL analyzer", nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + + return true; + } + + public boolean isTargetAnalyzer(List lines) { + if (getColumnsLine(lines) < 0) + return false; + DELIMITER = ((String) lines.get(getColumnsLine(lines))).substring(14, 15); + // System.out.println("DELIMITER:"+DELIMITER+"/"); + String[] data = ((String) lines.get(getColumnsLine(lines))).split(DELIMITER); + for (int j = 0; j < data.length; j++) { + if (data[j].contains("Test")) { + this.InstrumentIndex = j; + break; + } + + } + + if (lines.size() > getColumnsLine(lines) + 1) { + data = ((String) lines.get(getColumnsLine(lines) + 1)).split(DELIMITER); + if ((data[this.InstrumentIndex].contains(COBAS_TAQMAN_VL_INDICATOR)) + || (data[this.InstrumentIndex].contains(COBAS_TAQMAN_VL_INDICATOR2))) { + return true; + } + } + + return false; + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new TaqMan96VLAnalyzerImplementation(); + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && lines.get(k).contains("Patient ID") + && lines.get(k).contains("Order Number") && lines.get(k).contains("Sample ID") + && lines.get(k).contains("Test") && lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } + +} \ No newline at end of file diff --git a/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLAnalyzerImplementation.java b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLAnalyzerImplementation.java new file mode 100644 index 0000000..bc65657 --- /dev/null +++ b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLAnalyzerImplementation.java @@ -0,0 +1,219 @@ +/** + * 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 oe.plugin.analyzer; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +@SuppressWarnings("unused") +public class TaqMan96VLAnalyzerImplementation extends AnalyzerLineInserter { + private static final String UNDER_THREASHOLD = "< LL"; + private static final double THREASHOLD = 20.0; + private int ORDER_NUMBER = 0; + private int ORDER_DATE = 0; + private int RESULT = 0; + private int SAMPLE_TYPE = 0; + private int UNIT = 0; + // private static final String DELIMITER = "\\t"; + private static String DELIMITER = "\\t"; + private static final String DATE_PATTERN = "yyyy/MM/dd HH:mm:ss"; + static String ANALYZER_ID; + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LART"); + + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + private String error; + Test test = SpringContext.getBean(TestService.class).getActiveTestByName("Viral Load").get(0); + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + + static { + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("TaqMan96VLAnalyzer"); + ANALYZER_ID = analyzer.getId(); + } + + public boolean insert(List lines, String currentUserId) { + this.error = null; + + List results = new ArrayList(); + + boolean columnsFound = manageColumnsIndex(lines); + + if (!columnsFound) { + this.error = "Cobas Taqman 96 VL analyzer: Unable to find correct columns in file"; + return false; + } + + for (int i = getColumnsLine(lines) + 1; i < lines.size(); i++) { + createAnalyzerResultFromLine((String) lines.get(i), results); + } + + return persistImport(currentUserId, results); + } + + private boolean manageColumnsIndex(List lines) { + if (getColumnsLine(lines) < 0) + return false; + DELIMITER = ((String) lines.get(getColumnsLine(lines))).substring(14, 15); + String[] fields = ((String) lines.get(getColumnsLine(lines))).split(DELIMITER); + + for (int i = 0; i < fields.length; i++) { + String header = fields[i].replace("\"", ""); + + if ("Order Number".equals(header)) + ORDER_NUMBER = i; + else if ("Order Date/Time".equals(header)) + ORDER_DATE = i; + else if ("Result".equals(header)) + RESULT = i; + else if ("Sample Type".equals(header)) { + SAMPLE_TYPE = i; + } else if ("Unit".equals(header)) { + UNIT = i; + } + } + + return (ORDER_DATE != 0) && (ORDER_NUMBER != 0) && (RESULT != 0) && (SAMPLE_TYPE != 0) && (UNIT != 0); + } + + public String getError() { + return this.error; + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + + if (result.getIsControl()) { + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(projectCode) || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + + List analyses = analysisService.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Analysis analysis : analyses) { + if (analysis.getStatusId().equals(validStatusId)) + return; + + } + + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + String[] fields = line.split(DELIMITER); + + AnalyzerResults analyzerResults = new AnalyzerResults(); + + String result = getAppropriateResults(fields[RESULT]); + String accessionNumber = fields[this.ORDER_NUMBER].replace("\"", "").trim(); + accessionNumber = accessionNumber.replace(" ", ""); + if (accessionNumber.startsWith(projectCode) && accessionNumber.length() >= 9) + accessionNumber = accessionNumber.substring(0, 9); + + analyzerResults.setAnalyzerId(ANALYZER_ID); + analyzerResults.setResult(result); + analyzerResults.setUnits(UNDER_THREASHOLD.equals(result) ? "" : fields[UNIT].replace("\"", "").trim()); + analyzerResults.setCompleteDate(DateUtil + .convertStringDateToTimestampWithPattern(fields[ORDER_DATE].replace("\"", "").trim(), DATE_PATTERN)); + analyzerResults.setTestId(test.getId()); + analyzerResults.setIsControl(!"S".equals(fields[SAMPLE_TYPE].replace("\"", "").trim())); + analyzerResults.setTestName(test.getName()); + analyzerResults.setResultType("A"); + + if (analyzerResults.getIsControl()) { + accessionNumber = accessionNumber + ":" + fields[this.SAMPLE_TYPE].replace("\"", "").trim(); + } + + analyzerResults.setAccessionNumber(accessionNumber); + + addValueToResults(resultList, analyzerResults); + } + + private String getAppropriateResults(String result) { + result = result.replace("\"", "").trim(); + if ("Target Not Detected".equalsIgnoreCase(result) || "Below range".equalsIgnoreCase(result)) { + result = UNDER_THREASHOLD; + } else { + + String workingResult = result.split("\\(")[0].replace("<", "").replace("E", ""); + String[] splitResult = workingResult.split("\\+"); + + try { + Double resultAsDouble = Double.parseDouble(splitResult[0]) + * Math.pow(10, Double.parseDouble(splitResult[1])); + + if (resultAsDouble <= THREASHOLD) { + result = UNDER_THREASHOLD; + } else { + result = String.valueOf((int) (Math.round(resultAsDouble))) + result.substring(result.indexOf("(")); + } + } catch (NumberFormatException e) { + return "XXXX"; + } + } + + return result; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("Patient Name") && lines.get(k).contains("Patient ID") + && lines.get(k).contains("Order Number") && lines.get(k).contains("Sample ID") + && lines.get(k).contains("Test") && lines.get(k).contains("Result")) + + return k; + + } + + return -1; + } + +} \ No newline at end of file diff --git a/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLMenu.java b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLMenu.java new file mode 100644 index 0000000..dc2e84f --- /dev/null +++ b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLMenu.java @@ -0,0 +1,49 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class TaqMan96VLMenu extends MenuPlugin { + protected void insertMenu() { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + + menu.setParent( + PluginMenuService.getInstance().getKnownMenu(PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + + menu.setPresentationOrder(32); + + menu.setElementId("taqman96_vl_analyzer_plugin"); + + menu.setActionURL("/AnalyzerResults?type=TaqMan96VLAnalyzer"); + menu.setDisplayKey("banner.menu.results.taqman96vlanalyzer"); + menu.setOpenInNewWindow(false); + + service.addMenu(menu); + + service.insertLanguageKeyValue("banner.menu.results.taqman96vlanalyzer", "Virology: Cobas TaqMan96: Viral Load", + Locale.ENGLISH.toLanguageTag()); + + service.insertLanguageKeyValue("banner.menu.results.taqman96vlanalyzer", + "Virologie: Cobas TaqMan96: Charge Virale", Locale.FRENCH.toLanguageTag()); + } +} \ No newline at end of file diff --git a/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLPermission.java b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLPermission.java new file mode 100644 index 0000000..ec6a9ea --- /dev/null +++ b/analyzers/CobasTaqman96VL/src/main/java/oe/plugin/analyzer/TaqMan96VLPermission.java @@ -0,0 +1,36 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModule; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +/** + */ +public class TaqMan96VLPermission extends PermissionPlugin { + protected boolean insertPermission() { + PluginPermissionService service = new PluginPermissionService(); + SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "TaqMan96VLAnalyzer", + "Results->Analyzer->TaqMan96VLAnalyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} \ No newline at end of file diff --git a/analyzers/FacsCalibur/src/oe/plugin/analyzer/FacsCaliburPermission.java b/analyzers/FacsCalibur/src/oe/plugin/analyzer/FacsCaliburPermission.java index 8e87467..0e9e09a 100644 --- a/analyzers/FacsCalibur/src/oe/plugin/analyzer/FacsCaliburPermission.java +++ b/analyzers/FacsCalibur/src/oe/plugin/analyzer/FacsCaliburPermission.java @@ -28,7 +28,8 @@ public class FacsCaliburPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "FacsCalibur", "Results->Analyzer->FacsCalibur" ); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } \ No newline at end of file diff --git a/analyzers/FacsCantoII/src/oe/plugin/analyzer/FacsCantoIIPermission.java b/analyzers/FacsCantoII/src/oe/plugin/analyzer/FacsCantoIIPermission.java index 20cf39e..8fe0307 100644 --- a/analyzers/FacsCantoII/src/oe/plugin/analyzer/FacsCantoIIPermission.java +++ b/analyzers/FacsCantoII/src/oe/plugin/analyzer/FacsCantoIIPermission.java @@ -28,8 +28,10 @@ public class FacsCantoIIPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "FacsCantoII", "Results->Analyzer->FacsCantoII" ); - Role role = service.getSystemRole( "Results Admin" ); + //Role role = service.getSystemRole( "Results Admin" ); //Role role = service.getSystemRole( "Results Entry" ); - return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } \ No newline at end of file diff --git a/analyzers/FacsPresto/src/oe/plugin/analyzer/FacsPrestoPermission.java b/analyzers/FacsPresto/src/oe/plugin/analyzer/FacsPrestoPermission.java index 7630387..a337f53 100644 --- a/analyzers/FacsPresto/src/oe/plugin/analyzer/FacsPrestoPermission.java +++ b/analyzers/FacsPresto/src/oe/plugin/analyzer/FacsPrestoPermission.java @@ -28,7 +28,9 @@ public class FacsPrestoPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "FacsPrestoAnalyzer", "Results->Analyzer->FacsPrestoAnalyzer" ); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + //Role role = service.getSystemRole( "Results entry" ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/Fully/src/oe/plugin/analyzer/FullyPermission.java b/analyzers/Fully/src/oe/plugin/analyzer/FullyPermission.java index b13ab03..8c9a44a 100644 --- a/analyzers/Fully/src/oe/plugin/analyzer/FullyPermission.java +++ b/analyzers/Fully/src/oe/plugin/analyzer/FullyPermission.java @@ -28,7 +28,9 @@ public class FullyPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "FullyAnalyzer", "Results->Analyzer->FullyAnalyzer" ); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + //Role role = service.getSystemRole( "Results entry" ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/GeneXpert/src/main/java/oe/plugin/analyzer/GeneXpertPermission.java b/analyzers/GeneXpert/src/main/java/oe/plugin/analyzer/GeneXpertPermission.java index 748e67d..40c5991 100644 --- a/analyzers/GeneXpert/src/main/java/oe/plugin/analyzer/GeneXpertPermission.java +++ b/analyzers/GeneXpert/src/main/java/oe/plugin/analyzer/GeneXpertPermission.java @@ -30,7 +30,9 @@ protected boolean insertPermission(){ IPluginPermissionService service = SpringContext.getBean(IPluginPermissionService.class); SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "GeneXpertAnalyzer", "Results->Analyzer->GeneXpertAnalyzer"); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + //Role role = service.getSystemRole( "Results entry" ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/GeneXpertFile/src/oe/plugin/analyzer/GeneXpertAnalyzerPermission.java b/analyzers/GeneXpertFile/src/oe/plugin/analyzer/GeneXpertAnalyzerPermission.java index 7e04927..4f2e33b 100644 --- a/analyzers/GeneXpertFile/src/oe/plugin/analyzer/GeneXpertAnalyzerPermission.java +++ b/analyzers/GeneXpertFile/src/oe/plugin/analyzer/GeneXpertAnalyzerPermission.java @@ -29,7 +29,9 @@ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "GeneXpertAnalyzer", "Results->Analyzer->GeneXpertAnalyzer"); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + //Role role = service.getSystemRole( "Results entry" ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/Mindray/src/main/java/oe/plugin/analyzer/MindrayPermission.java b/analyzers/Mindray/src/main/java/oe/plugin/analyzer/MindrayPermission.java index a7adcfa..c0e1781 100644 --- a/analyzers/Mindray/src/main/java/oe/plugin/analyzer/MindrayPermission.java +++ b/analyzers/Mindray/src/main/java/oe/plugin/analyzer/MindrayPermission.java @@ -30,7 +30,9 @@ protected boolean insertPermission(){ IPluginPermissionService service = SpringContext.getBean(IPluginPermissionService.class); SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "MindrayAnalyzer", "Results->Analyzer->MindrayAnalyzer"); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); + //Role role = service.getSystemRole( "Results entry" ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/QuantStudio3/src/oe/plugin/analyzer/QuantStudio3Permission.java b/analyzers/QuantStudio3/src/oe/plugin/analyzer/QuantStudio3Permission.java index 49e27bc..8352b2a 100644 --- a/analyzers/QuantStudio3/src/oe/plugin/analyzer/QuantStudio3Permission.java +++ b/analyzers/QuantStudio3/src/oe/plugin/analyzer/QuantStudio3Permission.java @@ -31,7 +31,8 @@ protected boolean insertPermission(){ IPluginPermissionService service = SpringContext.getBean(IPluginPermissionService.class); SystemModule module = service.getOrCreateSystemModule("AnalyzerResults", "QuantStudio3Analyzer", "Results->Analyzer->QuantStudio3Analyzer"); - Role role = service.getSystemRole( "Results entry" ); + //Role role = service.getSystemRole( "Results entry" ); + Role role = service.getSystemRole( "Results" ); SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/importAnalyzer"); return service.bindRoleToModule( role, module, moduleUrl ); } diff --git a/analyzers/Sysmex2000i/src/oe/plugin/analyzer/SysmexPermission.java b/analyzers/Sysmex2000i/src/oe/plugin/analyzer/SysmexPermission.java index e811968..ec7e15c 100644 --- a/analyzers/Sysmex2000i/src/oe/plugin/analyzer/SysmexPermission.java +++ b/analyzers/Sysmex2000i/src/oe/plugin/analyzer/SysmexPermission.java @@ -28,7 +28,10 @@ public class SysmexPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "SysmexAnalyzer", "Results->Analyzer->SysmexAnalyzer" ); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); +// Role role = service.getSystemRole( "Results entry" ); +// return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/Sysmex4000i/pom.xml b/analyzers/Sysmex4000i/pom.xml new file mode 100644 index 0000000..fde62cf --- /dev/null +++ b/analyzers/Sysmex4000i/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + Sysmex4000i + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/Sysmex4000i/src/main/java/Sysmex4000i.xml b/analyzers/Sysmex4000i/src/main/java/Sysmex4000i.xml new file mode 100644 index 0000000..33cefe0 --- /dev/null +++ b/analyzers/Sysmex4000i/src/main/java/Sysmex4000i.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTAnalyzer.java b/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTAnalyzer.java new file mode 100644 index 0000000..52e3ed6 --- /dev/null +++ b/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTAnalyzer.java @@ -0,0 +1,93 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; +import java.util.ArrayList; +import java.util.List; + +import static org.openelisglobal.common.services.PluginAnalyzerService.getInstance; + +public class SysmexXTAnalyzer implements AnalyzerImporterPlugin { + private static final String DELIMITER = ","; + private static final CharSequence SYSMEX_XT_4000i_INDICATOR = "XT-4000i"; + int InstrumentIndex = -1; + + public boolean connect() { + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("GB(10/uL)", "GB")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("GR(10^4/uL)", "GR")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("HBG(g/L)", "Hb")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("HCT(10^(-1)%)", "HCT")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("VGM(10^(-1)fL)", "VGM")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("TCMH(10^(-1)pg)", "TCMH")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("CCMH(g/L)", "CCMH")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("PLQ(10^3/uL)", "PLQ")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("NEUT%(10^(-1)%)", "Neut %")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("LYMPH%(10^(-1)%)", "Lymph %")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("MONO%(10^(-1)%)", "Mono %")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("EO%(10^(-1)%)", "Eo %")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("BASO%(10^(-1)%)", "Baso %")); + getInstance().addAnalyzerDatabaseParts("Sysmex4000iAnalyzer", "Plugin for Sysmex XT 4000 i analyzer", + nameMappinng); + getInstance().registerAnalyzer(this); + return true; + } + + public boolean isTargetAnalyzer(List lines) { + int columnsLineIndex = getColumnsLine(lines); + if (columnsLineIndex < 0) + return false; + String[] fields = lines.get(columnsLineIndex).split(DELIMITER); + for (int j = 0; j < fields.length; j++) { + if (fields[j].contains("ID Instrument")) { + InstrumentIndex = j; + break; + } + + } + + if (lines.size() > columnsLineIndex + 1) { + fields = lines.get(columnsLineIndex + 1).split(DELIMITER); + if (fields[InstrumentIndex].contains(SYSMEX_XT_4000i_INDICATOR)) { + return true; + } + + } + return false; + + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new SysmexXTAnalyzerImplementation(); + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("ID Instrument") && lines.get(k).contains("N' Echantillon") + && lines.get(k).contains("Ana. Jour") && lines.get(k).contains("Ana. Heure") + && lines.get(k).contains("N' Rack") && lines.get(k).contains("Pos. Tube")) + + return k; + + } + + return -1; + } +} diff --git a/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTAnalyzerImplementation.java b/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTAnalyzerImplementation.java new file mode 100644 index 0000000..d90a693 --- /dev/null +++ b/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTAnalyzerImplementation.java @@ -0,0 +1,253 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +public class SysmexXTAnalyzerImplementation extends AnalyzerLineInserter { + private int ORDER_NUMBER_INDEX = 0; + private int ORDER_DAY_INDEX = 0; + private int ORDER_HOUR_INDEX = 0; + + private static final String DELIMITER = ","; + static String ANALYZER_ID; + private static final String CONTROL_ACCESSION_PREFIX = "QC-"; + static String DATE_PATTERN = "dd/MM/yyyy HH:mm:ss"; + static HashMap testHeaderNameMap = new HashMap(); + HashMap indexTestMap = new HashMap(); + static HashMap scaleIndexMap = new HashMap(); + + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LART"); + // private final String accession_number = + // ConfigurationProperties.getInstance().getPropertyValue(Property.ACCESSION_NUMBER_PREFIX); + + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + + static { + + testHeaderNameMap.put("GB(10/uL)", SpringContext.getBean(TestService.class).getTestByName("GB"));// .getTestByGUID("0e240569-c095-41c7-bfd2-049527452f16")); + testHeaderNameMap.put("GR(10^4/uL)", SpringContext.getBean(TestService.class).getTestByName("GR"));// .getTestByGUID("fe6405c8-f96b-491b-95c9-b1f635339d6a")); + testHeaderNameMap.put("HBG(g/L)", SpringContext.getBean(TestService.class).getTestByName("Hb"));// .getTestByGUID("cecea358-1fa0-44b2-8185-d8c010315f78")); + testHeaderNameMap.put("HCT(10^(-1)%)", SpringContext.getBean(TestService.class).getTestByName("HCT"));// .getTestByGUID("6792a51e-050b-4493-88ca-6f490c20cc5c")); + testHeaderNameMap.put("VGM(10^(-1)fL)", SpringContext.getBean(TestService.class).getTestByName("VGM"));// .getTestByGUID("ddce6c12-e319-455f-9f48-2f6ff363a246")); + testHeaderNameMap.put("TCMH(10^(-1)pg)", SpringContext.getBean(TestService.class).getTestByName("TCMH"));// .getTestByGUID("bf497153-ba88-4fe8-83ee-c144229d7628")); + testHeaderNameMap.put("CCMH(g/L)", SpringContext.getBean(TestService.class).getTestByName("CCMH"));// .getTestByGUID("8ab87a81-6b6b-4d4b-b53b-fac57109e393")); + testHeaderNameMap.put("PLQ(10^3/uL)", SpringContext.getBean(TestService.class).getTestByName("PLQ"));// .getTestByGUID("88b7d8d3-e82b-441f-aff3-1410ba2850a5")); + testHeaderNameMap.put("NEUT%(10^(-1)%)", SpringContext.getBean(TestService.class).getTestByName("Neut %"));// .getTestByGUID("0c25692f-a321-4e9c-9722-ca73f6625cb9")); + testHeaderNameMap.put("LYMPH%(10^(-1)%)", SpringContext.getBean(TestService.class).getTestByName("Lymph %"));// .getTestByGUID("eede92e7-d141-4c76-ab6e-b24ccfc84215")); + testHeaderNameMap.put("MONO%(10^(-1)%)", SpringContext.getBean(TestService.class).getTestByName("Mono %"));// .getTestByGUID("9eece97f-04f3-4381-b378-2a9ac08a535a")); + testHeaderNameMap.put("EO%(10^(-1)%)", SpringContext.getBean(TestService.class).getTestByName("Eo %"));// .getTestByGUID("50b568e8-e9da-428d-9697-8080bca7377b")); + testHeaderNameMap.put("BASO%(10^(-1)%)", SpringContext.getBean(TestService.class).getTestByName("Baso %"));// .getTestByGUID("a41fcfb4-e3ba-4add-ac5d-56fae322cb9e")); + + System.out.println(testHeaderNameMap); + + scaleIndexMap.put("GB(10/uL)", "100,10^3uL"); + scaleIndexMap.put("GR(10^4/uL)", "100,10^6uL"); + scaleIndexMap.put("HBG(g/L)", "10,g/dL"); + scaleIndexMap.put("HCT(10^(-1)%)", "10,%"); + scaleIndexMap.put("VGM(10^(-1)fL)", "10,fL"); + scaleIndexMap.put("TCMH(10^(-1)pg)", "10,pg"); + scaleIndexMap.put("CCMH(g/L)", "10,g/dL"); + scaleIndexMap.put("PLQ(10^3/uL)", "1,10^3/uL"); + scaleIndexMap.put("NEUT%(10^(-1)%)", "10,%"); + scaleIndexMap.put("LYMPH%(10^(-1)%)", "10,%"); + scaleIndexMap.put("MONO%(10^(-1)%)", "10,%"); + scaleIndexMap.put("EO%(10^(-1)%)", "10,%"); + scaleIndexMap.put("BASO%(10^(-1)%)", "10,%"); + + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("Sysmex4000iAnalyzer"); + ANALYZER_ID = analyzer.getId(); + + } + + /* + * (non-Javadoc) + * + * @see + * org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter#insert + * (java.util.List, java.lang.String) + */ + @Override + public boolean insert(List lines, String currentUserId) { + + List results = new ArrayList(); + + boolean columnsFound = manageColumnsIndex(lines); + + if (!columnsFound) { + System.out.println("Sysmex XT 4000i analyzer: Unable to find correct columns in file"); + return false; + } + + for (int i = getColumnsLine(lines) + 1; i < lines.size(); ++i) { + createAnalyzerResultFromLine(lines.get(i), results); + } + + return persistImport(currentUserId, results); + + } + + private Timestamp getTimestampFromDate(String dateTime) { + return DateUtil.convertStringDateToTimestampWithPattern(dateTime, DATE_PATTERN); + } + + @Override + public String getError() { + return "SysmexXT analyzer unable to write to database"; + } + + private String[] getAppropriateResults(String result, String testKey) { + result = result.trim(); + String scale = scaleIndexMap.get(testKey); + String[] results = scale.split(","); + + int dem = Integer.parseInt(results[0]); + + double d = Double.NaN; + + try { + d = Double.parseDouble(result) / dem; + } catch (NumberFormatException nfe) { + // no-op -- defaults to NAN + } + if (dem == 1) + results[0] = result; + else + results[0] = String.valueOf(d); + return results; + } + + private boolean manageColumnsIndex(List lines) { + if (getColumnsLine(lines) < 0) + return false; + + String[] headers = lines.get(getColumnsLine(lines)).split(DELIMITER); + + for (Integer i = 0; i < headers.length; i++) { + String header = headers[i].trim(); + if (testHeaderNameMap.containsKey(header)) { + indexTestMap.put(i.toString(), header); + } else if ("N' Echantillon".equals(header)) { + ORDER_NUMBER_INDEX = i; + } else if ("Ana. Jour".equals(header)) { + ORDER_DAY_INDEX = i; + } else if ("Ana. Heure".equals(header)) { + ORDER_HOUR_INDEX = i; + } + } + + return ORDER_NUMBER_INDEX != 0 && ORDER_DAY_INDEX != 0 && ORDER_HOUR_INDEX != 0; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("ID Instrument") && lines.get(k).contains("N' Echantillon") + && lines.get(k).contains("Ana. Jour") && lines.get(k).contains("Ana. Heure") + && lines.get(k).contains("N' Rack") && lines.get(k).contains("Pos. Tube")) + + return k; + + } + + return -1; + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + String[] fields = line.split(DELIMITER); + + for (Integer k = 0; k < fields.length; k++) { + + if (indexTestMap.containsKey(k.toString())) { + String testKey = indexTestMap.get(k.toString()); + AnalyzerResults aResult = new AnalyzerResults(); + aResult.setTestId(testHeaderNameMap.get(testKey).getId()); + aResult.setTestName(testHeaderNameMap.get(testKey).getName()); + + String[] result = getAppropriateResults(fields[k], testKey); + aResult.setResult(result[0]); + aResult.setUnits(result[1]); + aResult.setAnalyzerId(ANALYZER_ID); + aResult.setAccessionNumber(fields[ORDER_NUMBER_INDEX].trim()); + aResult.setResultType("N"); + + String dateTime = fields[ORDER_DAY_INDEX].trim(); + dateTime = dateTime + " " + fields[ORDER_HOUR_INDEX].trim(); + aResult.setCompleteDate(getTimestampFromDate(dateTime)); + + System.out.println("***" + aResult.getAccessionNumber() + " " + aResult.getCompleteDate() + " " + + aResult.getResult()); + + if (aResult.getAccessionNumber() != null) { + aResult.setIsControl(aResult.getAccessionNumber().startsWith(CONTROL_ACCESSION_PREFIX)); + } else { + aResult.setIsControl(false); + } + + addValueToResults(resultList, aResult); + } + + } + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + + if (result.getIsControl()) { + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + ; + if (!result.getAccessionNumber().startsWith(projectCode) + || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + + List analyses = analysisService.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Analysis analysis : analyses) { + if (analysis.getStatusId().equals(validStatusId)) + return; + } + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + + } + +} diff --git a/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTMenu.java b/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTMenu.java new file mode 100644 index 0000000..3818293 --- /dev/null +++ b/analyzers/Sysmex4000i/src/main/java/oe/plugin/analyzer/SysmexXTMenu.java @@ -0,0 +1,56 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.common.services.PluginMenuService.KnownMenu; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class SysmexXTMenu extends MenuPlugin { + + @Override + protected void insertMenu() { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + + menu.setParent(PluginMenuService.getInstance().getKnownMenu(KnownMenu.ANALYZER, "menu_results")); + // The order this analyzer will show on the menu relative to other analyzers + menu.setPresentationOrder(50); + // The id needs to be unique in the system + menu.setElementId("sysmex_xt_analyzer_plugin"); + // This will always be "/AnalyzerResults.do?type=Analyzer->Sysmex4000iAnalyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} diff --git a/analyzers/SysmexKX21/pom.xml b/analyzers/SysmexKX21/pom.xml new file mode 100644 index 0000000..2639a71 --- /dev/null +++ b/analyzers/SysmexKX21/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + SysmexKX21 + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/SysmexKX21/src/main/java/SysmexKX21.xml b/analyzers/SysmexKX21/src/main/java/SysmexKX21.xml new file mode 100644 index 0000000..641d670 --- /dev/null +++ b/analyzers/SysmexKX21/src/main/java/SysmexKX21.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21Analyzer.java b/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21Analyzer.java new file mode 100644 index 0000000..9bd9c79 --- /dev/null +++ b/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21Analyzer.java @@ -0,0 +1,107 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +import java.util.ArrayList; +import java.util.List; + +import static org.openelisglobal.common.services.PluginAnalyzerService.getInstance; + +public class SysmexKX21Analyzer implements AnalyzerImporterPlugin { + + private static final CharSequence KX21_INDICATOR = "KX21-NERG"; + int InstrumentIndex = -1; + + public boolean connect() { + List nameMappinng = new ArrayList(); + nameMappinng.add(new PluginAnalyzerService.TestMapping("GB", "Numération des globules blancs")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("GR", "Numération des globules rouges")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("HB", "Hémoglobine")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("Hct", "Hématocrite")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("VGM", "Volume Globulaire Moyen")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("TCMH", "Teneur Corpusculaire Moyenne en Hémoglobine")); + nameMappinng.add( + new PluginAnalyzerService.TestMapping("CCMH", "Concentration Corpusculaire Moyenne en Hémoglobine")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("PLT", "Plaquette")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("GRAN%", "Polynucléaires Neutrophiles (%)")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("LYM%", "Lymphocytes (%)")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("MONO%", "Monocytes (%)")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("GRAN#", "Polynucléaires Neutrophiles (Abs)")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("LYM#", "Lymphocytes (Abs)")); + nameMappinng.add(new PluginAnalyzerService.TestMapping("MONO#", "Monocytes (Abs)")); + getInstance().addAnalyzerDatabaseParts("SysmexKX21Analyzer", "Plugin for KX21 analyzer", nameMappinng); + getInstance().registerAnalyzer(this); + + /* + * List nameMappinng = new + * ArrayList(); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("GB(10/uL)", "GB")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("GR(10^4/uL)", "GR")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("HBG(g/L)", "Hb")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("HCT(10^(-1)%)", "HCT")); + * nameMappinng.add(new PluginAnalyzerService.TestMapping("VGM(10^(-1)fL)", + * "VGM")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("TCMH(10^(-1)pg)", "TCMH")); + * nameMappinng.add(new PluginAnalyzerService.TestMapping("CCMH(g/L)", "CCMH")); + * nameMappinng.add(new PluginAnalyzerService.TestMapping("PLQ(10^3/uL)", + * "PLQ")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("NEUT%(10^(-1)%)", "Neut %")); + * nameMappinng.add(new PluginAnalyzerService.TestMapping("LYMPH%(10^(-1)%)", + * "Lymph %")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("MONO%(10^(-1)%)", "Mono %")); + * nameMappinng.add(new PluginAnalyzerService.TestMapping("EO%(10^(-1)%)", + * "Eo %")); nameMappinng.add(new + * PluginAnalyzerService.TestMapping("BASO%(10^(-1)%)", "Baso %")); + * getInstance().addAnalyzerDatabaseParts("Sysmex4000iAnalyzer", + * "Plugin for Sysmex XT 4000 i analyzer",nameMappinng); + * getInstance().registerAnalyzer(this); + */ + + return true; + } + + @Override + public boolean isTargetAnalyzer(List lines) { + for (int j = 0; j < lines.size(); j++) { + if (lines.get(j).contains(KX21_INDICATOR)) + return true; + + } + return false; + + } + + @Override + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new SysmexKX21AnalyzerImplementation(); + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("KX21") && lines.get(k).contains("LYM%") && lines.get(k).contains("GRAN%")) + + return k; + + } + + return -1; + } +} \ No newline at end of file diff --git a/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21AnalyzerImplementation.java b/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21AnalyzerImplementation.java new file mode 100644 index 0000000..41029a8 --- /dev/null +++ b/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21AnalyzerImplementation.java @@ -0,0 +1,276 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.openelisglobal.analysis.dao.AnalysisDAO; +import org.openelisglobal.analysis.daoimpl.AnalysisDAOImpl; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.ConfigurationProperties; +import org.openelisglobal.common.util.ConfigurationProperties.Property; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +public class SysmexKX21AnalyzerImplementation extends AnalyzerLineInserter { + private int ORDER_NUMBER_INDEX = -1; + private int ORDER_DAY_INDEX = -1; + private int ORDER_HOUR_INDEX = -1; + + private static String DELIMITER = ";"; + static String ANALYZER_ID; + private static final String CONTROL_ACCESSION_PREFIX = "QC-"; + static String DATE_PATTERN = "dd/MM/yyyy hh:mm"; + static HashMap testHeaderNameMap = new HashMap(); + HashMap indexTestMap = new HashMap(); + static HashMap scaleIndexMap = new HashMap(); + + private AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); + // private final String projectCode = + // StringUtil.getMessageForKey("sample.entry.project.LART"); + private final String projectCode = ConfigurationProperties.getInstance() + .getPropertyValue(Property.ACCESSION_NUMBER_PREFIX); + + String validStatusId = StatusService.getInstance().getStatusID(StatusService.AnalysisStatus.Finalized); + AnalysisDAO analysisDao = new AnalysisDAOImpl(); + + static { + + testHeaderNameMap.put("GB", + SpringContext.getBean(TestService.class).getTestByName("Numération des globules blancs"));// .getTestByGUID("0e240569-c095-41c7-bfd2-049527452f16")); + testHeaderNameMap.put("GR", + SpringContext.getBean(TestService.class).getTestByName("Numération des globules rouges"));// .getTestByGUID("fe6405c8-f96b-491b-95c9-b1f635339d6a")); + testHeaderNameMap.put("HB", SpringContext.getBean(TestService.class).getTestByName("Hémoglobine"));// .getTestByGUID("cecea358-1fa0-44b2-8185-d8c010315f78")); + testHeaderNameMap.put("Hct", SpringContext.getBean(TestService.class).getTestByName("Hématocrite"));// .getTestByGUID("6792a51e-050b-4493-88ca-6f490c20cc5c")); + testHeaderNameMap.put("VGM", SpringContext.getBean(TestService.class).getTestByName("Volume Globulaire Moyen"));// .getTestByGUID("ddce6c12-e319-455f-9f48-2f6ff363a246")); + testHeaderNameMap.put("TCMH", + SpringContext.getBean(TestService.class).getTestByName("Teneur Corpusculaire Moyenne en Hémoglobine"));// .getTestByGUID("bf497153-ba88-4fe8-83ee-c144229d7628")); + testHeaderNameMap.put("CCMH", SpringContext.getBean(TestService.class) + .getTestByName("Concentration Corpusculaire Moyenne en Hémoglobine"));// .getTestByGUID("8ab87a81-6b6b-4d4b-b53b-fac57109e393")); + testHeaderNameMap.put("PLT", SpringContext.getBean(TestService.class).getTestByName("Plaquette"));// .getTestByGUID("88b7d8d3-e82b-441f-aff3-1410ba2850a5")); + testHeaderNameMap.put("GRAN%", + SpringContext.getBean(TestService.class).getTestByName("Polynucléaires Neutrophiles (%)"));// .getTestByGUID("0c25692f-a321-4e9c-9722-ca73f6625cb9")); + testHeaderNameMap.put("LYM%", SpringContext.getBean(TestService.class).getTestByName("Lymphocytes (%)"));// .getTestByGUID("eede92e7-d141-4c76-ab6e-b24ccfc84215")); + testHeaderNameMap.put("MONO%", SpringContext.getBean(TestService.class).getTestByName("Monocytes (%)"));// .getTestByGUID("9eece97f-04f3-4381-b378-2a9ac08a535a")); + testHeaderNameMap.put("GRAN#", + SpringContext.getBean(TestService.class).getTestByName("Polynucléaires Neutrophiles (Abs)"));// .getTestByGUID("9eece97f-04f3-4381-b378-2a9ac08a535a")); + testHeaderNameMap.put("LYM#", SpringContext.getBean(TestService.class).getTestByName("Lymphocytes (Abs)"));// .getTestByGUID("eede92e7-d141-4c76-ab6e-b24ccfc84215")); + testHeaderNameMap.put("MONO#", SpringContext.getBean(TestService.class).getTestByName("Monocytes (Abs)"));// .getTestByGUID("9eece97f-04f3-4381-b378-2a9ac08a535a")); + + // testHeaderNameMap.put("EO%(10^(-1)%)", + // SpringContext.getBean(TestService.class).getTestByName("Eo + // %"));//.getTestByGUID("50b568e8-e9da-428d-9697-8080bca7377b")); + // testHeaderNameMap.put("BASO%(10^(-1)%)", + // SpringContext.getBean(TestService.class).getTestByName("Baso + // %"));//.getTestByGUID("a41fcfb4-e3ba-4add-ac5d-56fae322cb9e")); + + // System.out.println(testHeaderNameMap); + + scaleIndexMap.put("GB", "1,10^3uL"); + scaleIndexMap.put("GR", "1,10^6uL"); + scaleIndexMap.put("HB", "1,g/dL"); + scaleIndexMap.put("Hct", "1,%"); + scaleIndexMap.put("VGM", "1,fL"); + scaleIndexMap.put("TCMH", "1,pg"); + scaleIndexMap.put("CCMH", "1,g/dL"); + scaleIndexMap.put("PLT", "1,10^3/uL"); + scaleIndexMap.put("GRAN%", "1,%"); + scaleIndexMap.put("LYM%", "1,%"); + scaleIndexMap.put("MONO%", "1,%"); + scaleIndexMap.put("GRAN#", "1000,/mm3"); + scaleIndexMap.put("LYM#", "1000,/mm3"); + scaleIndexMap.put("MONO#", "1000,/mm3"); + + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("SysmexKX21Analyzer"); + ANALYZER_ID = analyzer.getId(); + + } + + /* + * (non-Javadoc) + * + * @see + * org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter#insert + * (java.util.List, java.lang.String) + */ + @Override + public boolean insert(List lines, String currentUserId) { + + List results = new ArrayList(); + + boolean columnsFound = manageColumnsIndex(lines); + + if (!columnsFound) { + System.out.println("Sysmex KX21 analyzer: Unable to find correct columns in file"); + return false; + } + + for (int i = getColumnsLine(lines) + 1; i < lines.size(); ++i) { + createAnalyzerResultFromLine(lines.get(i), results); + } + + return persistImport(currentUserId, results); + + } + + private Timestamp getTimestampFromDate(String dateTime) { + return DateUtil.convertStringDateToTimestampWithPattern(dateTime, DATE_PATTERN); + } + + @Override + public String getError() { + return "KX21 analyzer unable to write to database"; + } + + private String[] getAppropriateResults(String result, String testKey) { + result = result.trim().replace(",", "."); + String scale = scaleIndexMap.get(testKey); + String[] results = scale.split(","); + double d = Double.NaN; + if (!result.equals("")) { + int dem = Integer.parseInt(results[0]); + + // System.out.println(dem); + + try { + d = Double.parseDouble(result) * Double.valueOf(dem); + } catch (NumberFormatException nfe) { + // no-op -- defaults to NAN + } + if (dem == 1) + results[0] = result; + else + results[0] = String.valueOf(d); + // System.out.println("result="+d); + } + + else { + results[0] = result; + } + + return results; + } + + private boolean manageColumnsIndex(List lines) { + if (getColumnsLine(lines) < 0) + return false; + // DELIMITER=((String)lines.get(getColumnsLine(lines))).substring(5, 6); + String[] headers = lines.get(getColumnsLine(lines)).split(DELIMITER); + + for (Integer i = 0; i < headers.length; i++) { + String header = headers[i].trim(); + if (testHeaderNameMap.containsKey(header)) { + indexTestMap.put(i.toString(), header); + } else if (header.contains("KX21-NERG")) { + ORDER_NUMBER_INDEX = i; + } else if (header.contains("DATE")) { + ORDER_DAY_INDEX = i; + } else if (header.contains("HEURE")) { + ORDER_HOUR_INDEX = i; + } + } + + return ORDER_NUMBER_INDEX != -1 && ORDER_DAY_INDEX != -1 && ORDER_HOUR_INDEX != -1; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) { + if (lines.get(k).contains("KX21") && lines.get(k).contains("LYM%") && lines.get(k).contains("GRAN%")) + + return k; + + } + + return -1; + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + String[] fields = line.split(DELIMITER); + + for (Integer k = 0; k < fields.length; k++) { + + if (indexTestMap.containsKey(k.toString())) { + String testKey = indexTestMap.get(k.toString()); + AnalyzerResults aResult = new AnalyzerResults(); + aResult.setTestId(testHeaderNameMap.get(testKey).getId()); + aResult.setTestName(testHeaderNameMap.get(testKey).getName()); + + String[] result = getAppropriateResults(fields[k], testKey); + aResult.setResult(result[0]); + aResult.setUnits(result[1]); + aResult.setAnalyzerId(ANALYZER_ID); + aResult.setAccessionNumber(fields[ORDER_NUMBER_INDEX].trim()); + aResult.setResultType("N"); + + String dateTime = fields[ORDER_DAY_INDEX].trim(); + dateTime = dateTime + " " + fields[ORDER_HOUR_INDEX].trim(); + aResult.setCompleteDate(getTimestampFromDate(dateTime)); + + // System.out.println("***" + aResult.getAccessionNumber() + " " + + // aResult.getCompleteDate() + " " + aResult.getResult()); + + if (aResult.getAccessionNumber() != null) { + aResult.setIsControl(aResult.getAccessionNumber().startsWith(CONTROL_ACCESSION_PREFIX)); + } else { + aResult.setIsControl(false); + } + + addValueToResults(resultList, aResult); + } + + } + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + + if (result.getIsControl()) { + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(projectCode) + || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + + List analyses = analysisDao.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), + result.getTestId()); + for (Analysis analysis : analyses) { + if (analysis.getStatusId().equals(validStatusId)) + return; + } + resultList.add(result); + + AnalyzerResults resultFromDB = this.readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + + } + +} diff --git a/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21Menu.java b/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21Menu.java new file mode 100644 index 0000000..d181b44 --- /dev/null +++ b/analyzers/SysmexKX21/src/main/java/oe/plugin/analyzer/SysmexKX21Menu.java @@ -0,0 +1,56 @@ +/* + * 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) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.common.services.PluginMenuService.KnownMenu; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class SysmexKX21Menu extends MenuPlugin { + + @Override + protected void insertMenu() { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + + menu.setParent(PluginMenuService.getInstance().getKnownMenu(KnownMenu.ANALYZER, "menu_results")); + // The order this analyzer will show on the menu relative to other analyzers + menu.setPresentationOrder(50); + // The id needs to be unique in the system + menu.setElementId("sysmex_kx21_analyzer_plugin"); + // This will always be "/AnalyzerResults.do?type=Analyzer->SysmexKX21Analyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} diff --git a/analyzers/SysmexXN1000/pom.xml b/analyzers/SysmexXN1000/pom.xml new file mode 100644 index 0000000..0633551 --- /dev/null +++ b/analyzers/SysmexXN1000/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + + org.openelisglobal + openelisglobal-plugins + 0.0.1 + ../../pom.xml + + org.openelisglobal.plugins + SysmexXN1000 + jar + + + UTF-8 + + + + + commons-logging + commons-logging + 1.2 + + + commons-validator + commons-validator + 1.6 + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + maven-resources-plugin + 2.4.3 + + + copy-resources + + install + + copy-resources + + + ${project.basedir}/../../plugins + + + + target/ + + ${project.build.finalName}.jar + + + false + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/SysmexXN1000/src/main/java/SysmexXN1000.xml b/analyzers/SysmexXN1000/src/main/java/SysmexXN1000.xml new file mode 100644 index 0000000..e7197d4 --- /dev/null +++ b/analyzers/SysmexXN1000/src/main/java/SysmexXN1000.xml @@ -0,0 +1,22 @@ + + +1.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Analyzer.java b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Analyzer.java new file mode 100644 index 0000000..2cbf7d5 --- /dev/null +++ b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Analyzer.java @@ -0,0 +1,78 @@ +// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. +// Jad home page: http://www.geocities.com/kpdus/jad.html +// Decompiler options: packimports(3) +// Source File Name: SysmexXN1000Analyzer.java + +package oe.plugin.analyzer; + +import java.util.ArrayList; +import java.util.List; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.common.services.PluginAnalyzerService; +import org.openelisglobal.plugin.AnalyzerImporterPlugin; + +// Referenced classes of package oe.plugin.analyzer: +// SysmexXN1000AnalyzerImplementation + +public class SysmexXN1000Analyzer implements AnalyzerImporterPlugin { + + public SysmexXN1000Analyzer() { + InstrumentIndex = -1; + } + + public boolean connect() { + List nameMappinng = new ArrayList(); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("WBC(10^3/uL)", "GB")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("RBC(10^6/uL)", "GR")); + nameMappinng.add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("HGB(g/dL)", "Hb")); + nameMappinng.add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("HCT(%)", "HCT")); + nameMappinng.add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("MCV(fL)", "VGM")); + nameMappinng.add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("MCH(pg)", "TCMH")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("MCHC(g/dL)", "CCMH")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("PLT(10^3/uL)", "PLQ")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("NEUT%(%)", "Neut %")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("LYMPH%(%)", "Lymph %")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("MONO%(%)", "Mono %")); + nameMappinng.add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("EO%(%)", "Eo %")); + nameMappinng + .add(new org.openelisglobal.common.services.PluginAnalyzerService.TestMapping("BASO%(%)", "Baso %")); + PluginAnalyzerService.getInstance().addAnalyzerDatabaseParts("SysmexXN1000Analyzer", + "Plugin for Sysmex XN1000 analyzer", nameMappinng); + PluginAnalyzerService.getInstance().registerAnalyzer(this); + return true; + } + + public boolean isTargetAnalyzer(List lines) { + for (int j = 0; j < lines.size(); j++) + if (((String) lines.get(j)).contains(SYSMEX_XN1000_INDICATOR)) + return true; + + return false; + } + + public AnalyzerLineInserter getAnalyzerLineInserter() { + return new SysmexXN1000AnalyzerImplementation(); + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) + if (((String) lines.get(k)).contains("ID Instrument") && ((String) lines.get(k)).contains("N' Echantillon") + && ((String) lines.get(k)).contains("Ana. Jour") && ((String) lines.get(k)).contains("Ana. Heure") + && ((String) lines.get(k)).contains("N' Rack") && ((String) lines.get(k)).contains("Pos. Tube")) + return k; + + return -1; + } + + private static final String DELIMITER = ","; + private static final CharSequence SYSMEX_XN1000_INDICATOR = "XN-10^23865"; + int InstrumentIndex; + +} diff --git a/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000AnalyzerImplementation.java b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000AnalyzerImplementation.java new file mode 100644 index 0000000..e293ae6 --- /dev/null +++ b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000AnalyzerImplementation.java @@ -0,0 +1,209 @@ +// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. +// Jad home page: http://www.geocities.com/kpdus/jad.html +// Decompiler options: packimports(3) +// Source File Name: SysmexXN1000AnalyzerImplementation.java + +package oe.plugin.analyzer; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.openelisglobal.analysis.dao.AnalysisDAO; +import org.openelisglobal.analysis.daoimpl.AnalysisDAOImpl; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.analyzer.service.AnalyzerService; +import org.openelisglobal.analyzer.valueholder.Analyzer; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerLineInserter; +import org.openelisglobal.analyzerimport.analyzerreaders.AnalyzerReaderUtil; +import org.openelisglobal.analyzerresults.valueholder.AnalyzerResults; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.common.util.DateUtil; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.sample.service.SampleService; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.valueholder.Test; + +public class SysmexXN1000AnalyzerImplementation extends AnalyzerLineInserter { + + public SysmexXN1000AnalyzerImplementation() { + ORDER_NUMBER_INDEX = 0; + ORDER_DAY_INDEX = 0; + ORDER_HOUR_INDEX = 0; + indexTestMap = new HashMap(); + readerUtil = new AnalyzerReaderUtil(); + validStatusId = StatusService.getInstance() + .getStatusID(org.openelisglobal.common.services.StatusService.AnalysisStatus.Finalized); + analysisDao = new AnalysisDAOImpl(); + } + + public boolean insert(List lines, String currentUserId) { + List results = new ArrayList(); + boolean columnsFound = manageColumnsIndex(lines); + if (!columnsFound) { + System.out.println("Sysmex XN1000 analyzer: Unable to find correct columns in file"); + return false; + } + for (int i = getColumnsLine(lines) + 1; i < lines.size(); i++) + createAnalyzerResultFromLine((String) lines.get(i), results); + + return persistImport(currentUserId, results); + } + + private Timestamp getTimestampFromDate(String dateTime) { + return DateUtil.convertStringDateToTimestampWithPattern(dateTime, DATE_PATTERN); + } + + public String getError() { + return "SysmexXT analyzer unable to write to database"; + } + + private String[] getAppropriateResults(String result, String testKey) { + result = result.trim(); + String scale = (String) scaleIndexMap.get(testKey); + String results[] = scale.split(","); + int dem = Integer.parseInt(results[0]); + double d = (0.0D / 0.0D); + try { + d = Double.parseDouble(result) / (double) dem; + } catch (NumberFormatException numberformatexception) { + } + if (dem == 1) + results[0] = result; + else + results[0] = String.valueOf(d); + return results; + } + + private boolean manageColumnsIndex(List lines) { + if (getColumnsLine(lines) < 0) + return false; + String headers[] = ((String) lines.get(getColumnsLine(lines))).split(","); + for (Integer i = Integer.valueOf(0); i.intValue() < headers.length; i = Integer.valueOf(i.intValue() + 1)) { + String header = headers[i.intValue()].trim(); + if (testHeaderNameMap.containsKey(header)) + indexTestMap.put(i.toString(), header); + else if ("Sample No.".equals(header)) + ORDER_NUMBER_INDEX = i.intValue(); + else if ("Date".equals(header)) + ORDER_DAY_INDEX = i.intValue(); + else if ("Time".equals(header)) + ORDER_HOUR_INDEX = i.intValue(); + } + + return ORDER_NUMBER_INDEX != 0 && ORDER_DAY_INDEX != 0 && ORDER_HOUR_INDEX != 0; + } + + public int getColumnsLine(List lines) { + for (int k = 0; k < lines.size(); k++) + if (((String) lines.get(k)).contains("Nickname") && ((String) lines.get(k)).contains("Analyzer ID") + && ((String) lines.get(k)).contains("Date") && ((String) lines.get(k)).contains("Time") + && ((String) lines.get(k)).contains("Rack") && ((String) lines.get(k)).contains("Sample No.")) + return k; + + return -1; + } + + private void createAnalyzerResultFromLine(String line, List resultList) { + String fields[] = line.split(","); + for (Integer k = Integer.valueOf(0); k.intValue() < fields.length; k = Integer.valueOf(k.intValue() + 1)) + if (indexTestMap.containsKey(k.toString())) { + String testKey = (String) indexTestMap.get(k.toString()); + AnalyzerResults aResult = new AnalyzerResults(); + aResult.setTestId(((Test) testHeaderNameMap.get(testKey)).getId()); + aResult.setTestName(((Test) testHeaderNameMap.get(testKey)).getName()); + String result[] = getAppropriateResults(fields[k.intValue()], testKey); + aResult.setResult(result[0]); + aResult.setUnits(result[1]); + aResult.setAnalyzerId(ANALYZER_ID); + aResult.setAccessionNumber(fields[ORDER_NUMBER_INDEX].trim()); + aResult.setResultType("N"); + String dateTime = fields[ORDER_DAY_INDEX].trim(); + dateTime = (new StringBuilder(String.valueOf(dateTime))).append(" ") + .append(fields[ORDER_HOUR_INDEX].trim()).toString(); + aResult.setCompleteDate(getTimestampFromDate(dateTime)); + System.out.println((new StringBuilder("***")).append(aResult.getAccessionNumber()).append(" ") + .append(aResult.getCompleteDate()).append(" ").append(aResult.getResult()).toString()); + if (aResult.getAccessionNumber() != null) + aResult.setIsControl(aResult.getAccessionNumber().startsWith("QC-")); + else + aResult.setIsControl(false); + addValueToResults(resultList, aResult); + } + + } + + private void addValueToResults(List resultList, AnalyzerResults result) { + if (result.getIsControl()) { + resultList.add(result); + return; + } + SampleService sampleServ = SpringContext.getBean(SampleService.class); + if (!result.getAccessionNumber().startsWith(projectCode) + || sampleServ.getSampleByAccessionNumber(result.getAccessionNumber()) == null) + return; + List analyses = analysisDao.getAnalysisByAccessionAndTestId(result.getAccessionNumber(), result.getTestId()); + for (Iterator iterator = analyses.iterator(); iterator.hasNext();) { + Analysis analysis = (Analysis) iterator.next(); + if (analysis.getStatusId().equals(validStatusId)) + return; + } + + resultList.add(result); + AnalyzerResults resultFromDB = readerUtil.createAnalyzerResultFromDB(result); + if (resultFromDB != null) + resultList.add(resultFromDB); + } + + private int ORDER_NUMBER_INDEX; + private int ORDER_DAY_INDEX; + private int ORDER_HOUR_INDEX; + private static final String DELIMITER = ","; + static String ANALYZER_ID; + private static final String CONTROL_ACCESSION_PREFIX = "QC-"; + static String DATE_PATTERN = "dd/MM/yyyy HH:mm:ss"; + static HashMap testHeaderNameMap; + HashMap indexTestMap; + static HashMap scaleIndexMap; + private AnalyzerReaderUtil readerUtil; + private final String projectCode = MessageUtil.getMessage("sample.entry.project.LART"); + String validStatusId; + AnalysisDAO analysisDao; + + static { + testHeaderNameMap = new HashMap(); + scaleIndexMap = new HashMap(); + testHeaderNameMap.put("WBC(10^3/uL)", (SpringContext.getBean(TestService.class)).getTestByName("GB")); + testHeaderNameMap.put("RBC(10^6/uL)", (SpringContext.getBean(TestService.class)).getTestByName("GR")); + testHeaderNameMap.put("HGB(g/dL)", (SpringContext.getBean(TestService.class)).getTestByName("Hb")); + testHeaderNameMap.put("HCT(%)", (SpringContext.getBean(TestService.class)).getTestByName("HCT")); + testHeaderNameMap.put("MCV(fL)", (SpringContext.getBean(TestService.class)).getTestByName("VGM")); + testHeaderNameMap.put("MCH(pg)", (SpringContext.getBean(TestService.class)).getTestByName("TCMH")); + testHeaderNameMap.put("MCHC(g/dL)", (SpringContext.getBean(TestService.class)).getTestByName("CCMH")); + testHeaderNameMap.put("PLT(10^3/uL)", (SpringContext.getBean(TestService.class)).getTestByName("PLQ")); + testHeaderNameMap.put("NEUT%(%)", (SpringContext.getBean(TestService.class)).getTestByName("Neut %")); + testHeaderNameMap.put("LYMPH%(%)", (SpringContext.getBean(TestService.class)).getTestByName("Lymph %")); + testHeaderNameMap.put("MONO%(%)", (SpringContext.getBean(TestService.class)).getTestByName("Mono %")); + testHeaderNameMap.put("EO%(%)", (SpringContext.getBean(TestService.class)).getTestByName("Eo %")); + testHeaderNameMap.put("BASO%(%)", (SpringContext.getBean(TestService.class)).getTestByName("Baso %")); + scaleIndexMap.put("WBC(10^3/uL)", "1,10^3uL"); + scaleIndexMap.put("RBC(10^6/uL)", "1,10^6uL"); + scaleIndexMap.put("HGB(g/dL)", "1,g/dL"); + scaleIndexMap.put("HCT(%)", "1,%"); + scaleIndexMap.put("MCV(fL)", "1,fL"); + scaleIndexMap.put("MCH(pg)", "1,pg"); + scaleIndexMap.put("MCHC(g/dL)", "1,g/dL"); + scaleIndexMap.put("PLT(10^3/uL)", "1,10^3/uL"); + scaleIndexMap.put("NEUT%(%)", "1,%"); + scaleIndexMap.put("LYMPH%(%)", "1,%"); + scaleIndexMap.put("MONO%(%)", "1,%"); + scaleIndexMap.put("EO%(%)", "1,%"); + scaleIndexMap.put("BASO%(%)", "1,%"); + AnalyzerService analyzerService = SpringContext.getBean(AnalyzerService.class); + Analyzer analyzer = analyzerService.getAnalyzerByName("SysmexXN1000Analyzer"); + ANALYZER_ID = analyzer.getId(); + } +} diff --git a/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Menu.java b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Menu.java new file mode 100644 index 0000000..c39a352 --- /dev/null +++ b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Menu.java @@ -0,0 +1,35 @@ +// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. +// Jad home page: http://www.geocities.com/kpdus/jad.html +// Decompiler options: packimports(3) +// Source File Name: SysmexXN1000Menu.java + +package oe.plugin.analyzer; + +import java.util.Locale; + +import org.openelisglobal.common.services.PluginMenuService; +import org.openelisglobal.menu.valueholder.Menu; +import org.openelisglobal.plugin.MenuPlugin; + +public class SysmexXN1000Menu extends MenuPlugin { + + public SysmexXN1000Menu() { + } + + protected void insertMenu() { + PluginMenuService service = PluginMenuService.getInstance(); + Menu menu = new Menu(); + menu.setParent(PluginMenuService.getInstance() + .getKnownMenu(org.openelisglobal.common.services.PluginMenuService.KnownMenu.ANALYZER, "menu_results")); + menu.setPresentationOrder(50); + menu.setElementId("sysmex_xt_analyzer_plugin"); + menu.setActionURL("/AnalyzerResults?type=SysmexXN1000Analyzer"); + menu.setDisplayKey("banner.menu.results.sysmexxn1000analyzer"); + menu.setOpenInNewWindow(false); + service.addMenu(menu); + service.insertLanguageKeyValue("banner.menu.results.sysmexxn1000analyzer", + "Hematology: Sysmex XN1000 analyzer importer", Locale.ENGLISH.toLanguageTag()); + service.insertLanguageKeyValue("banner.menu.results.sysmexxn1000analyzer", "H\351matologie: Sysmex XN1000", + Locale.FRENCH.toLanguageTag()); + } +} diff --git a/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Permission.java b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Permission.java new file mode 100644 index 0000000..f47307e --- /dev/null +++ b/analyzers/SysmexXN1000/src/main/java/oe/plugin/analyzer/SysmexXN1000Permission.java @@ -0,0 +1,26 @@ +// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. +// Jad home page: http://www.geocities.com/kpdus/jad.html +// Decompiler options: packimports(3) +// Source File Name: SysmexXN1000Permission.java + +package oe.plugin.analyzer; + +import org.openelisglobal.common.services.PluginPermissionService; +import org.openelisglobal.plugin.PermissionPlugin; +import org.openelisglobal.role.valueholder.Role; +import org.openelisglobal.systemmodule.valueholder.SystemModuleUrl; + +public class SysmexXN1000Permission extends PermissionPlugin { + + public SysmexXN1000Permission() { + } + + protected boolean insertPermission() { + PluginPermissionService service = new PluginPermissionService(); + org.openelisglobal.systemmodule.valueholder.SystemModule module = service.getOrCreateSystemModule( + "AnalyzerResults", "SysmexXN1000Analyzer", "Results->Analyzer->SysmexXN1000Analyzer"); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); + } +} diff --git a/analyzers/SysmexXT4000i/src/oe/plugin/analyzer/SysmexXTPermission.java b/analyzers/SysmexXT4000i/src/oe/plugin/analyzer/SysmexXTPermission.java index 5458840..4702e15 100644 --- a/analyzers/SysmexXT4000i/src/oe/plugin/analyzer/SysmexXTPermission.java +++ b/analyzers/SysmexXT4000i/src/oe/plugin/analyzer/SysmexXTPermission.java @@ -28,7 +28,10 @@ public class SysmexXTPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "SysmexXTAnalyzer", "Results->Analyzer->SysmexXTAnalyzer" ); - Role role = service.getSystemRole( "Results Admin" ); - return service.bindRoleToModule( role, module ); +// Role role = service.getSystemRole( "Results Admin" ); +// return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } diff --git a/analyzers/weberAnalyzer/src/oe/plugin/analyzer/WeberPermission.java b/analyzers/weberAnalyzer/src/oe/plugin/analyzer/WeberPermission.java index c66d723..b3e4461 100644 --- a/analyzers/weberAnalyzer/src/oe/plugin/analyzer/WeberPermission.java +++ b/analyzers/weberAnalyzer/src/oe/plugin/analyzer/WeberPermission.java @@ -28,7 +28,10 @@ public class WeberPermission extends PermissionPlugin{ protected boolean insertPermission(){ PluginPermissionService service = new PluginPermissionService(); SystemModule module = service.getOrCreateSystemModule( "AnalyzerResults", "WeberAnalyzer", "Results->Analyzer->WeberAnalyzer" ); - Role role = service.getSystemRole( "Results entry" ); - return service.bindRoleToModule( role, module ); +// Role role = service.getSystemRole( "Results entry" ); +// return service.bindRoleToModule( role, module ); + SystemModuleUrl moduleUrl = service.getOrCreateSystemModuleUrl(module, "/AnalyzerResults"); + Role role = service.getSystemRole("Results"); + return service.bindRoleToModule(role, module, moduleUrl); } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5cb0c86..cb93e26 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,16 @@ ./analyzers/GeneXpert ./analyzers/Mindray ./analyzers/GeneXpertFile + ./analyzers/SysmexKX21 + ./analyzers/Cobas4800 + ./analyzers/CobasTaqman96VL + ./analyzers/CobasTaqMan96DBS + ./analyzers/CobasTaqMan48VL + ./analyzers/AB7500Fast + ./analyzers/Cobas6800VL + ./analyzers/Sysmex4000i + ./analyzers/SysmexXN1000 + @@ -33,9 +43,7 @@ org.openelisglobal openelisglobal - 2.4.2.2 - system - /home/caleb/eclipse-ee-workspace/OpenELIS-Projects/openelisglobal-plugins/lib/openelisglobal-2.5.0.0.jar + 2.7.0.26 commons-validator