Skip to content

Commit

Permalink
Full error reporting when error occurs during index building. Updated
Browse files Browse the repository at this point in the history
copyright year.
  • Loading branch information
schuemie committed Feb 23, 2016
1 parent cef772c commit eca8418
Show file tree
Hide file tree
Showing 52 changed files with 233 additions and 133 deletions.
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/CodeMapping.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
91 changes: 91 additions & 0 deletions src/org/ohdsi/usagi/ErrorReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* This file is part of Usagi
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.ohdsi.usagi;

import java.io.File;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;

import org.ohdsi.utilities.StringUtilities;
import org.ohdsi.utilities.files.WriteTextFile;

public class ErrorReport {
public static String generate(String folder, Exception e) {
String filename = folder + "/Error.txt";
int i = 1;
while (new File(filename).exists())
filename = folder + "/Error" + (i++) + ".txt";
DecimalFormat df = new DecimalFormat();
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setGroupingSeparator(',');
df.setDecimalFormatSymbols(dfs);

WriteTextFile out = new WriteTextFile(filename);

out.writeln("*** Generic error information ***");
out.writeln("Message: " + e.getMessage());
out.writeln("Time: " + StringUtilities.now());
Runtime runTime = Runtime.getRuntime();
out.writeln("Processor type: " + System.getProperty("sun.cpu.isalist"));
out.writeln("Available processors: " + runTime.availableProcessors());
out.writeln("Maximum available memory: " + df.format(runTime.maxMemory()) + " bytes");
out.writeln("Used memory: " + df.format(runTime.totalMemory() - runTime.freeMemory()) + " bytes");
out.writeln("Java version: " + System.getProperty("java.version"));
out.writeln("Java vendor: " + System.getProperty("java.vendor"));
out.writeln("OS architecture: " + System.getProperty("os.arch"));
out.writeln("OS name: " + System.getProperty("os.name"));
out.writeln("OS version: " + System.getProperty("os.version"));
out.writeln("OS patch level: " + System.getProperty("sun.os.patch.level"));
out.writeln("");
out.writeln("*** Stack trace ***");
for (StackTraceElement element : e.getStackTrace())
out.writeln(element.toString());
out.writeln("");
out.writeln("");
out.writeln("*** Working folder contents ***");
out.writeln("Directory of " + folder);
out.writeln("");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
File[] files = new File(folder).listFiles();
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return Long.valueOf(o1.lastModified()).compareTo(o2.lastModified());
}
});

for (File file : files) {
String name = file.getName();
String length = df.format(file.length());
String dir = file.isDirectory() ? "<DIR>" : " ";
String modifiedDate = sdf.format(new Date(file.lastModified()));
StringBuilder filler = new StringBuilder();
for (int x = 0; x < (80 - name.length() - length.length()); x++)
filler.append(' ');
out.writeln(name + filler.toString() + length + " " + dir + " " + modifiedDate);
}
out.writeln("");
out.writeln("Available disc space: " + df.format(new File(folder).getFreeSpace()) + " bytes");
out.close();
return filename;
}
}
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ReadCodeMappingsFromFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/SourceCode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/TargetConcept.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/WriteCodeMappingsToFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/dataImport/ImportData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
175 changes: 92 additions & 83 deletions src/org/ohdsi/usagi/indexBuilding/BuildIndex.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2015 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.ohdsi.usagi.ErrorReport;
import org.ohdsi.usagi.TargetConcept;
import org.ohdsi.usagi.UsagiSearchEngine;
import org.ohdsi.usagi.ui.Global;
Expand Down Expand Up @@ -116,95 +117,103 @@ private void report(String message) {
public void run() {
// Load LOINC information into memory if user wants to include it in the index:
try {
Map<String, String> loincToInfo = null;
if (loincFile != null) {
report("Loading LOINC additional information");
loincToInfo = loadLoincInfo(loincFile);
}
report("Sorting vocabulary files");
FileSorter.delimiter = '\t';
FileSorter.sort(vocabFolder + "/CONCEPT.csv", new String[] { "CONCEPT_ID" }, new boolean[] { true });
FileSorter.sort(vocabFolder + "/CONCEPT_SYNONYM.csv", new String[] { "CONCEPT_ID" }, new boolean[] { true });

report("Adding concepts to index");
UsagiSearchEngine usagiSearchEngine = new UsagiSearchEngine(Global.folder);
usagiSearchEngine.createNewMainIndex();

Iterator<Row> conceptIterator = new ReadCSVFileWithHeader(vocabFolder + "/CONCEPT.csv", '\t').iterator();
Iterator<Row> conceptSynIterator = new ReadCSVFileWithHeader(vocabFolder + "/CONCEPT_SYNONYM.csv", '\t').iterator();
@SuppressWarnings("unchecked")
MultiRowIterator iterator = new MultiRowIterator("CONCEPT_ID", true, new String[] { "concept", "concept_synonym" }, new Iterator[] {
conceptIterator, conceptSynIterator });
Set<String> vocabularies = new HashSet<String>();
Set<String> conceptClassIds = new HashSet<String>();
Set<String> domainIds = new HashSet<String>();
int warnCount = 0;
while (iterator.hasNext()) {
MultiRowSet multiRowSet = iterator.next();
if (multiRowSet.get("concept").size() == 0) {
if (warnCount < MAX_WARN_COUNT) {
warnCount++;
System.out.println("No concept found for concept ID " + multiRowSet.linkingId);
}
} else {

Row conceptRow = multiRowSet.get("concept").get(0);
if (conceptRow.getCells().size() > 2) // Extra check to catch badly formatted rows (which are in a vocab we don't care about)
if (conceptRow.get("STANDARD_CONCEPT").equals("S")) {
vocabularies.add(conceptRow.get("VOCABULARY_ID"));
conceptClassIds.add(conceptRow.get("CONCEPT_CLASS_ID"));
domainIds.add(conceptRow.get("DOMAIN_ID"));
List<Row> synonymRows = multiRowSet.get("concept_synonym");

// Adding concept name as synonym:
Row tempRow = new Row();
tempRow.add("CONCEPT_SYNONYM_NAME", conceptRow.get("CONCEPT_NAME"));
synonymRows.add(tempRow);

for (Row synonymRow : synonymRows) {
TargetConcept concept = new TargetConcept();
concept.term = synonymRow.get("CONCEPT_SYNONYM_NAME");
concept.conceptClass = conceptRow.get("CONCEPT_CLASS_ID");
concept.conceptCode = conceptRow.get("CONCEPT_CODE");
concept.conceptId = conceptRow.getInt("CONCEPT_ID");
concept.conceptName = conceptRow.get("CONCEPT_NAME");
for (String domain : conceptRow.get("DOMAIN_ID").split("/")) {
if (domain.equals("Obs"))
domain = "Observation";
if (domain.equals("Meas"))
domain = "Measurement";
concept.domains.add(domain);
}
concept.invalidReason = conceptRow.get("INVALID_REASON");
concept.validEndDate = conceptRow.get("VALID_END_DATE");
concept.validStartDate = conceptRow.get("VALID_START_DATE");
concept.vocabulary = conceptRow.get("VOCABULARY_ID");
if (loincToInfo != null && concept.vocabulary.equals("LOINC")) {
String info = loincToInfo.get(concept.conceptCode);
if (info != null)
concept.additionalInformation = info;
Map<String, String> loincToInfo = null;
if (loincFile != null) {
report("Loading LOINC additional information");
loincToInfo = loadLoincInfo(loincFile);
}
report("Sorting vocabulary files");
FileSorter.delimiter = '\t';
FileSorter.sort(vocabFolder + "/CONCEPT.csv", new String[] { "CONCEPT_ID" }, new boolean[] { true });
FileSorter.sort(vocabFolder + "/CONCEPT_SYNONYM.csv", new String[] { "CONCEPT_ID" }, new boolean[] { true });

report("Adding concepts to index");
UsagiSearchEngine usagiSearchEngine = new UsagiSearchEngine(Global.folder);
usagiSearchEngine.createNewMainIndex();

Iterator<Row> conceptIterator = new ReadCSVFileWithHeader(vocabFolder + "/CONCEPT.csv", '\t').iterator();
Iterator<Row> conceptSynIterator = new ReadCSVFileWithHeader(vocabFolder + "/CONCEPT_SYNONYM.csv", '\t').iterator();
@SuppressWarnings("unchecked")
MultiRowIterator iterator = new MultiRowIterator("CONCEPT_ID", true, new String[] { "concept", "concept_synonym" }, new Iterator[] {
conceptIterator, conceptSynIterator });
Set<String> vocabularies = new HashSet<String>();
Set<String> conceptClassIds = new HashSet<String>();
Set<String> domainIds = new HashSet<String>();
int warnCount = 0;
while (iterator.hasNext()) {
MultiRowSet multiRowSet = iterator.next();
if (multiRowSet.get("concept").size() == 0) {
if (warnCount < MAX_WARN_COUNT) {
warnCount++;
System.out.println("No concept found for concept ID " + multiRowSet.linkingId);
}
} else {

Row conceptRow = multiRowSet.get("concept").get(0);
if (conceptRow.getCells().size() > 2) // Extra check to catch badly formatted rows (which are in a vocab we don't care about)
if (conceptRow.get("STANDARD_CONCEPT").equals("S")) {
vocabularies.add(conceptRow.get("VOCABULARY_ID"));
conceptClassIds.add(conceptRow.get("CONCEPT_CLASS_ID"));
domainIds.add(conceptRow.get("DOMAIN_ID"));
List<Row> synonymRows = multiRowSet.get("concept_synonym");

// Adding concept name as synonym:
Row tempRow = new Row();
tempRow.add("CONCEPT_SYNONYM_NAME", conceptRow.get("CONCEPT_NAME"));
synonymRows.add(tempRow);

for (Row synonymRow : synonymRows) {
TargetConcept concept = new TargetConcept();
concept.term = synonymRow.get("CONCEPT_SYNONYM_NAME");
concept.conceptClass = conceptRow.get("CONCEPT_CLASS_ID");
concept.conceptCode = conceptRow.get("CONCEPT_CODE");
concept.conceptId = conceptRow.getInt("CONCEPT_ID");
concept.conceptName = conceptRow.get("CONCEPT_NAME");
for (String domain : conceptRow.get("DOMAIN_ID").split("/")) {
if (domain.equals("Obs"))
domain = "Observation";
if (domain.equals("Meas"))
domain = "Measurement";
concept.domains.add(domain);
}
concept.invalidReason = conceptRow.get("INVALID_REASON");
concept.validEndDate = conceptRow.get("VALID_END_DATE");
concept.validStartDate = conceptRow.get("VALID_START_DATE");
concept.vocabulary = conceptRow.get("VOCABULARY_ID");
if (loincToInfo != null && concept.vocabulary.equals("LOINC")) {
String info = loincToInfo.get(concept.conceptCode);
if (info != null)
concept.additionalInformation = info;
}
if (concept.additionalInformation == null)
concept.additionalInformation = "";
usagiSearchEngine.addConceptToIndex(concept);
}
if (concept.additionalInformation == null)
concept.additionalInformation = "";
usagiSearchEngine.addConceptToIndex(concept);
}
}
}
}
}
usagiSearchEngine.close();
saveSorted(vocabularies, Global.folder + "/VocabularyIds.txt");
saveSorted(conceptClassIds, Global.folder + "/ConceptClassIds.txt");
saveSorted(domainIds, Global.folder + "/DomainIds.txt");
if (dialog != null)
dialog.setVisible(false);
} catch (Exception e){
if (Global.frame != null)
JOptionPane.showMessageDialog(Global.frame, StringUtilities.wordWrap(e.getLocalizedMessage(), 80), "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
usagiSearchEngine.close();
saveSorted(vocabularies, Global.folder + "/VocabularyIds.txt");
saveSorted(conceptClassIds, Global.folder + "/ConceptClassIds.txt");
saveSorted(domainIds, Global.folder + "/DomainIds.txt");
if (dialog != null)
dialog.setVisible(false);
} catch (Exception e) {
handleError(e);
if (dialog != null)
dialog.setVisible(false);
}
}

private void handleError(Exception e) {
System.err.println("Error: " + e.getMessage());
String errorReportFilename = ErrorReport.generate(Global.folder, e);
String message = "Error: " + e.getLocalizedMessage();
message += "\nAn error report has been generated:\n" + errorReportFilename;
System.out.println(message);
if (Global.frame != null)
JOptionPane.showMessageDialog(Global.frame, StringUtilities.wordWrap(message, 80), "Error", JOptionPane.ERROR_MESSAGE);
}

private void saveSorted(Set<String> set, String fileName) {
List<String> list = new ArrayList<String>(set);
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/tests/TestLucene.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/AboutDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/CodeSelectedListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/ConceptInformationDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/DataChangeListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/ExportSourceToConceptMapDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/FilterChangeListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/FilterPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/ImportDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2014 Observational Health Data Sciences and Informatics
* Copyright 2016 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit eca8418

Please sign in to comment.