diff --git a/.gitignore b/.gitignore
index 04d4786..dd64606 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,104 @@
/bin
build/
dist/
+
+### Usagi index files ###
+derivedIndex/
+mainIndex/
+sleepyCat/
+ConceptClassIds.txt
+DomainIds.txt
+VocabularyIds.txt
+vocabularyVersion.txt
+
+### Intellij ###
+# Created by https://www.gitignore.io/api/intellij
+# Edit at https://www.gitignore.io/?templates=intellij
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+.idea/
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator/
+
+# End of https://www.gitignore.io/api/intellij
\ No newline at end of file
diff --git a/Usagi.iml b/Usagi.iml
new file mode 100644
index 0000000..361dee2
--- /dev/null
+++ b/Usagi.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/org/ohdsi/usagi/ui/ExportSourceToConceptMapDialog.java b/src/org/ohdsi/usagi/ui/ExportSourceToConceptMapDialog.java
index b1da340..0f14318 100644
--- a/src/org/ohdsi/usagi/ui/ExportSourceToConceptMapDialog.java
+++ b/src/org/ohdsi/usagi/ui/ExportSourceToConceptMapDialog.java
@@ -45,6 +45,7 @@ public class ExportSourceToConceptMapDialog extends JDialog {
private JTextField sourceVocabularyIdField;
private static final long serialVersionUID = -6846083121849826818L;
+ private boolean exportUnapproved = false;
public ExportSourceToConceptMapDialog() {
setTitle("Export to source_to_concept_map");
@@ -73,23 +74,11 @@ public ExportSourceToConceptMapDialog() {
buttonPanel.add(Box.createHorizontalGlue());
JButton cancelButton = new JButton("Cancel");
cancelButton.setToolTipText("Cancel the export");
- cancelButton.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent arg0) {
- setVisible(false);
- }
- });
+ cancelButton.addActionListener(arg0 -> setVisible(false));
buttonPanel.add(cancelButton);
JButton exportButton = new JButton("Export");
exportButton.setToolTipText("Select the filename and export using these settings");
- exportButton.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent arg0) {
- export();
- }
- });
+ exportButton.addActionListener(arg0 -> export());
buttonPanel.add(exportButton);
add(buttonPanel, g);
@@ -98,6 +87,10 @@ public void actionPerformed(ActionEvent arg0) {
setLocationRelativeTo(Global.frame);
}
+ public void setExportUnapproved(boolean exportUnapproved) {
+ this.exportUnapproved = exportUnapproved;
+ }
+
private void export() {
JFileChooser fileChooser = new JFileChooser(Global.folder);
FileFilter csvFilter = new FileNameExtensionFilter("CSV files", "csv");
@@ -105,6 +98,7 @@ private void export() {
fileChooser.setDialogTitle("Export");
if (fileChooser.showSaveDialog(Global.frame) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
+ Global.folder = file.getParentFile().getAbsolutePath();
if (!file.getName().toLowerCase().endsWith(".csv"))
file = new File(file.getAbsolutePath() + ".csv");
@@ -116,7 +110,7 @@ private void export() {
private void writeToCsvFile(String filename) {
WriteCSVFileWithHeader out = new WriteCSVFileWithHeader(filename);
for (CodeMapping mapping : Global.mapping)
- if (mapping.mappingStatus == MappingStatus.APPROVED) {
+ if (exportUnapproved || mapping.mappingStatus == MappingStatus.APPROVED) {
List targetConcepts;
if (mapping.targetConcepts.size() == 0) {
targetConcepts = new ArrayList(1);
@@ -131,7 +125,7 @@ private void writeToCsvFile(String filename) {
row.add("source_vocabulary_id", sourceVocabularyIdField.getText());
row.add("source_code_description", mapping.sourceCode.sourceName);
row.add("target_concept_id", targetConcept.conceptId);
- row.add("target_vocabulary_id", targetConcept.vocabularyId);
+ row.add("target_vocabulary_id", targetConcept.conceptId == 0 ? "None" : targetConcept.vocabularyId );
row.add("valid_start_date", "1970-01-01");
row.add("valid_end_date", "2099-12-31");
row.add("invalid_reason", "");
diff --git a/src/org/ohdsi/usagi/ui/UsagiMain.java b/src/org/ohdsi/usagi/ui/UsagiMain.java
index b8a567f..bcb121d 100644
--- a/src/org/ohdsi/usagi/ui/UsagiMain.java
+++ b/src/org/ohdsi/usagi/ui/UsagiMain.java
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2019 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.
* 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.
@@ -28,27 +28,11 @@
import java.util.ArrayList;
import java.util.List;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JSplitPane;
+import javax.swing.*;
import org.ohdsi.usagi.BerkeleyDbEngine;
import org.ohdsi.usagi.UsagiSearchEngine;
-import org.ohdsi.usagi.ui.actions.AboutAction;
-import org.ohdsi.usagi.ui.actions.ApplyPreviousMappingAction;
-import org.ohdsi.usagi.ui.actions.ApproveAction;
-import org.ohdsi.usagi.ui.actions.ApproveAllAction;
-import org.ohdsi.usagi.ui.actions.ClearAllAction;
-import org.ohdsi.usagi.ui.actions.ConceptInformationAction;
-import org.ohdsi.usagi.ui.actions.ExitAction;
-import org.ohdsi.usagi.ui.actions.ExportForReviewAction;
-import org.ohdsi.usagi.ui.actions.ExportSourceToConceptMapAction;
-import org.ohdsi.usagi.ui.actions.ImportAction;
-import org.ohdsi.usagi.ui.actions.OpenAction;
-import org.ohdsi.usagi.ui.actions.RebuildIndexAction;
-import org.ohdsi.usagi.ui.actions.SaveAction;
-import org.ohdsi.usagi.ui.actions.SaveAsAction;
-import org.ohdsi.usagi.ui.actions.ShowStatsAction;
+import org.ohdsi.usagi.ui.actions.*;
import org.ohdsi.utilities.files.ReadTextFile;
/**
@@ -56,22 +40,16 @@
*/
public class UsagiMain implements ActionListener {
- private JFrame frame;
-
public static void main(String[] args) {
new UsagiMain(args);
}
public UsagiMain(String[] args) {
- frame = new JFrame("Usagi");
+ JFrame frame = new JFrame("Usagi");
// Initialize global variables:
Global.mapping = new Mapping();
- if (args.length != 0)
- Global.folder = args[0];
- else
- Global.folder = new File("").getAbsolutePath();
-
+ Global.folder = new File("").getAbsolutePath();
Global.usagiSearchEngine = new UsagiSearchEngine(Global.folder);
Global.dbEngine = new BerkeleyDbEngine(Global.folder);
if (Global.usagiSearchEngine.mainIndexExists()) {
@@ -107,10 +85,13 @@ public UsagiMain(String[] args) {
Global.clearAllAction.setEnabled(false);
Global.conceptInfoAction.setEnabled(false);
+ frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
- Global.dbEngine.shutdown();
- System.exit(0);
+ if (UsagiDialogs.askBeforeExit()) {
+ Global.dbEngine.shutdown();
+ System.exit(0);
+ }
}
});
frame.setLayout(new BorderLayout());
@@ -139,6 +120,12 @@ public void windowClosing(WindowEvent e) {
if (!Global.usagiSearchEngine.mainIndexExists())
Global.rebuildIndexAction.actionPerformed(null);
+
+ if (args.length == 1) {
+ Global.folder = args[0];
+ } else if (args.length > 1 && args[0].equals("--file")) {
+ OpenAction.open(new File(args[1]));
+ }
}
private String loadVocabularyVersion(String folder) {
@@ -147,7 +134,7 @@ private String loadVocabularyVersion(String folder) {
if (new File(versionFileName).exists()) {
for (String line : new ReadTextFile(versionFileName))
version = line;
- }
+ }
return version;
}
diff --git a/src/org/ohdsi/usagi/ui/actions/ExitAction.java b/src/org/ohdsi/usagi/ui/actions/ExitAction.java
index 234e32f..123179a 100644
--- a/src/org/ohdsi/usagi/ui/actions/ExitAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/ExitAction.java
@@ -15,10 +15,11 @@
******************************************************************************/
package org.ohdsi.usagi.ui.actions;
+import org.ohdsi.usagi.ui.Global;
+
import java.awt.event.ActionEvent;
-import javax.swing.AbstractAction;
-import javax.swing.Action;
+import javax.swing.*;
public class ExitAction extends AbstractAction {
@@ -31,7 +32,10 @@ public ExitAction() {
@Override
public void actionPerformed(ActionEvent arg0) {
- System.exit(0);
+ if (UsagiDialogs.askBeforeExit()) {
+ Global.dbEngine.shutdown();
+ System.exit(0);
+ }
}
}
diff --git a/src/org/ohdsi/usagi/ui/actions/ExportForReviewAction.java b/src/org/ohdsi/usagi/ui/actions/ExportForReviewAction.java
index b40391c..9c5fb32 100644
--- a/src/org/ohdsi/usagi/ui/actions/ExportForReviewAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/ExportForReviewAction.java
@@ -15,16 +15,14 @@
******************************************************************************/
package org.ohdsi.usagi.ui.actions;
-import java.awt.Cursor;
+import java.awt.*;
import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
+import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
@@ -42,58 +40,67 @@ public class ExportForReviewAction extends AbstractAction {
public ExportForReviewAction() {
putValue(Action.NAME, "Export for review");
putValue(Action.SHORT_DESCRIPTION, "Export mapping to a human readable format for reviewing");
+ putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
+ putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
@Override
public void actionPerformed(ActionEvent arg0) {
+ boolean exportUnapproved = UsagiDialogs.askExportUnapprovedMappings();
+
boolean hasApprovedMappings = false;
- for (CodeMapping mapping : Global.mapping)
+ for (CodeMapping mapping : Global.mapping) {
if (mapping.mappingStatus == MappingStatus.APPROVED) {
hasApprovedMappings = true;
break;
}
- if (hasApprovedMappings) {
- JFileChooser fileChooser = new JFileChooser(Global.folder);
- FileFilter csvFilter = new FileNameExtensionFilter("CSV files", "csv");
- fileChooser.setFileFilter(csvFilter);
- if (fileChooser.showSaveDialog(Global.frame) == JFileChooser.APPROVE_OPTION) {
- File file = fileChooser.getSelectedFile();
- if (!file.getName().toLowerCase().endsWith(".csv"))
- file = new File(file.getAbsolutePath() + ".csv");
- Global.frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- WriteCSVFileWithHeader out = new WriteCSVFileWithHeader(file.getAbsolutePath());
- for (CodeMapping mapping : Global.mapping)
- if (mapping.mappingStatus == MappingStatus.APPROVED) {
- List targetConcepts;
- if (mapping.targetConcepts.size() == 0) {
- targetConcepts = new ArrayList(1);
- targetConcepts.add(Concept.EMPTY_CONCEPT);
- } else
- targetConcepts = mapping.targetConcepts;
+ }
+
+ if (!exportUnapproved && !hasApprovedMappings) {
+ UsagiDialogs.warningNothingToExport();
+ return;
+ }
+
+ JFileChooser fileChooser = new JFileChooser(Global.folder);
+ FileFilter csvFilter = new FileNameExtensionFilter("CSV files", "csv");
+ fileChooser.setFileFilter(csvFilter);
+ if (fileChooser.showSaveDialog(Global.frame) == JFileChooser.APPROVE_OPTION) {
+ File file = fileChooser.getSelectedFile();
+ Global.folder = file.getParentFile().getAbsolutePath();
+ if (!file.getName().toLowerCase().endsWith(".csv"))
+ file = new File(file.getAbsolutePath() + ".csv");
+ Global.frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ WriteCSVFileWithHeader out = new WriteCSVFileWithHeader(file.getAbsolutePath());
+ for (CodeMapping mapping : Global.mapping)
+ if (exportUnapproved || mapping.mappingStatus == MappingStatus.APPROVED) {
+ List targetConcepts;
+ if (mapping.targetConcepts.size() == 0) {
+ targetConcepts = new ArrayList(1);
+ targetConcepts.add(Concept.EMPTY_CONCEPT);
+ } else
+ targetConcepts = mapping.targetConcepts;
- for (Concept targetConcept : targetConcepts) {
- Row row = mapping.sourceCode.toRow();
- row.add("matchScore", mapping.matchScore);
- row.add("targetConceptId", targetConcept.conceptId);
- row.add("targetConceptName", targetConcept.conceptName);
- row.add("targetVocabularyId", targetConcept.vocabularyId);
- row.add("targetDomainId", targetConcept.domainId);
- row.add("targetStandardConcept", targetConcept.standardConcept);
- row.add("targetChildCount", targetConcept.childCount);
- row.add("targetParentCount", targetConcept.parentCount);
- row.add("targetConceptClassId", targetConcept.conceptClassId);
- row.add("targetConceptCode", targetConcept.conceptCode);
- row.add("targetValidStartDate", targetConcept.validStartDate);
- row.add("targetValidEndDate", targetConcept.validEndDate);
- row.add("targetInvalidReason", targetConcept.invalidReason);
- out.write(row);
- }
+ for (Concept targetConcept : targetConcepts) {
+ Row row = mapping.sourceCode.toRow();
+ row.add("matchScore", mapping.matchScore);
+ if (exportUnapproved) row.add("mappingStatus", mapping.mappingStatus.toString());
+ row.add("targetConceptId", targetConcept.conceptId);
+ row.add("targetConceptName", targetConcept.conceptName);
+ row.add("targetVocabularyId", targetConcept.vocabularyId);
+ row.add("targetDomainId", targetConcept.domainId);
+ row.add("targetStandardConcept", targetConcept.standardConcept);
+ row.add("targetChildCount", targetConcept.childCount);
+ row.add("targetParentCount", targetConcept.parentCount);
+ row.add("targetConceptClassId", targetConcept.conceptClassId);
+ row.add("targetConceptCode", targetConcept.conceptCode);
+ row.add("targetValidStartDate", targetConcept.validStartDate);
+ row.add("targetValidEndDate", targetConcept.validEndDate);
+ row.add("targetInvalidReason", targetConcept.invalidReason);
+ out.write(row);
}
- out.close();
- Global.frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- } else {
- JOptionPane.showMessageDialog(Global.frame, "There are no approved mappings, so nothing to export", "Warning", JOptionPane.WARNING_MESSAGE);
+ }
+ out.close();
+ Global.frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
diff --git a/src/org/ohdsi/usagi/ui/actions/ExportSourceToConceptMapAction.java b/src/org/ohdsi/usagi/ui/actions/ExportSourceToConceptMapAction.java
index ad91725..174732a 100644
--- a/src/org/ohdsi/usagi/ui/actions/ExportSourceToConceptMapAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/ExportSourceToConceptMapAction.java
@@ -15,12 +15,11 @@
******************************************************************************/
package org.ohdsi.usagi.ui.actions;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JOptionPane;
+import javax.swing.*;
import org.ohdsi.usagi.CodeMapping;
import org.ohdsi.usagi.CodeMapping.MappingStatus;
@@ -34,23 +33,30 @@ public class ExportSourceToConceptMapAction extends AbstractAction {
public ExportSourceToConceptMapAction() {
putValue(Action.NAME, "Export source_to_concept_map");
putValue(Action.SHORT_DESCRIPTION, "Export mapping to source_to_concept_map");
- putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_E));
+ putValue(Action.MNEMONIC_KEY, KeyEvent.VK_E);
+ putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
@Override
public void actionPerformed(ActionEvent arg0) {
+ boolean exportUnapproved = UsagiDialogs.askExportUnapprovedMappings();
+
boolean hasApprovedMappings = false;
- for (CodeMapping mapping : Global.mapping)
+ for (CodeMapping mapping : Global.mapping) {
if (mapping.mappingStatus == MappingStatus.APPROVED) {
hasApprovedMappings = true;
break;
}
- if (hasApprovedMappings) {
- ExportSourceToConceptMapDialog dialog = new ExportSourceToConceptMapDialog();
- dialog.setVisible(true);
- } else {
- JOptionPane.showMessageDialog(Global.frame, "There are no approved mappings, so nothing to export", "Warning", JOptionPane.WARNING_MESSAGE);
}
+
+ if (!exportUnapproved && !hasApprovedMappings) {
+ UsagiDialogs.warningNothingToExport();
+ return;
+ }
+
+ ExportSourceToConceptMapDialog exportDialog = new ExportSourceToConceptMapDialog();
+ exportDialog.setExportUnapproved(exportUnapproved);
+ exportDialog.setVisible(true);
}
}
diff --git a/src/org/ohdsi/usagi/ui/actions/ImportAction.java b/src/org/ohdsi/usagi/ui/actions/ImportAction.java
index 82b3836..d153d9b 100644
--- a/src/org/ohdsi/usagi/ui/actions/ImportAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/ImportAction.java
@@ -15,6 +15,7 @@
******************************************************************************/
package org.ohdsi.usagi.ui.actions;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
@@ -36,8 +37,8 @@ public class ImportAction extends AbstractAction {
public ImportAction() {
putValue(Action.NAME, "Import codes");
putValue(Action.SHORT_DESCRIPTION, "Import a file containing codes");
- putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_I));
- putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK));
+ putValue(Action.MNEMONIC_KEY, KeyEvent.VK_I);
+ putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
@Override
@@ -53,6 +54,7 @@ public void actionPerformed(ActionEvent arg0) {
fileChooser.setAcceptAllFileFilterUsed(false);
if (fileChooser.showOpenDialog(Global.frame) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
+ Global.folder = file.getParentFile().getAbsolutePath();
new ImportDialog(file.getAbsolutePath());
}
}
diff --git a/src/org/ohdsi/usagi/ui/actions/OpenAction.java b/src/org/ohdsi/usagi/ui/actions/OpenAction.java
index 574125a..20fe1c5 100644
--- a/src/org/ohdsi/usagi/ui/actions/OpenAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/OpenAction.java
@@ -15,6 +15,7 @@
******************************************************************************/
package org.ohdsi.usagi.ui.actions;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
@@ -35,8 +36,8 @@ public class OpenAction extends AbstractAction {
public OpenAction() {
putValue(Action.NAME, "Open");
putValue(Action.SHORT_DESCRIPTION, "Open mapping file");
- putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
- putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
+ putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O);
+ putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
@Override
@@ -46,18 +47,24 @@ public void actionPerformed(ActionEvent arg0) {
fileChooser.setFileFilter(csvFilter);
if (fileChooser.showOpenDialog(Global.frame) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
- Global.frame.setTitle("Usagi - " + file.getName());
- Global.filename = file.getAbsolutePath();
- Global.mapping.loadFromFile(Global.filename);
- Global.usagiSearchEngine.close();
- Global.usagiSearchEngine.createDerivedIndex(Global.mapping.getSourceCodes(), Global.frame);
- Global.mappingDetailPanel.doSearch();
- Global.applyPreviousMappingAction.setEnabled(true);
- Global.saveAction.setEnabled(true);
- Global.saveAsAction.setEnabled(true);
- Global.exportAction.setEnabled(true);
- Global.exportForReviewAction.setEnabled(true);
+ open(file);
}
}
+ public static void open(File file) {
+ String a = file.getName();
+ Global.frame.setTitle("Usagi - " + file.getName());
+ Global.filename = file.getAbsolutePath();
+ Global.folder = file.getParentFile().getAbsolutePath();
+ Global.mapping.loadFromFile(Global.filename);
+ Global.usagiSearchEngine.close();
+ Global.usagiSearchEngine.createDerivedIndex(Global.mapping.getSourceCodes(), Global.frame);
+ Global.mappingDetailPanel.doSearch();
+ Global.applyPreviousMappingAction.setEnabled(true);
+ Global.saveAction.setEnabled(true);
+ Global.saveAsAction.setEnabled(true);
+ Global.exportAction.setEnabled(true);
+ Global.exportForReviewAction.setEnabled(true);
+ }
+
}
diff --git a/src/org/ohdsi/usagi/ui/actions/SaveAction.java b/src/org/ohdsi/usagi/ui/actions/SaveAction.java
index a6a1d6b..c1bed93 100644
--- a/src/org/ohdsi/usagi/ui/actions/SaveAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/SaveAction.java
@@ -15,8 +15,9 @@
******************************************************************************/
package org.ohdsi.usagi.ui.actions;
-import java.awt.Cursor;
+import java.awt.*;
import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.File;
@@ -36,8 +37,8 @@ public class SaveAction extends AbstractAction {
public SaveAction() {
putValue(Action.NAME, "Save");
putValue(Action.SHORT_DESCRIPTION, "Save mapping file");
- putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
- putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
+ putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
+ putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
@Override
@@ -52,6 +53,7 @@ public void actionPerformed(ActionEvent arg0) {
file = new File(file.getAbsolutePath() + ".csv");
Global.frame.setTitle("Usagi - " + file.getName());
Global.filename = file.getAbsolutePath();
+ Global.folder = file.getParentFile().getAbsolutePath();
}
}
if (Global.filename != null) {
diff --git a/src/org/ohdsi/usagi/ui/actions/SaveAsAction.java b/src/org/ohdsi/usagi/ui/actions/SaveAsAction.java
index 0da50ba..b26ba43 100644
--- a/src/org/ohdsi/usagi/ui/actions/SaveAsAction.java
+++ b/src/org/ohdsi/usagi/ui/actions/SaveAsAction.java
@@ -47,6 +47,7 @@ public void actionPerformed(ActionEvent arg0) {
file = new File(file.getAbsolutePath() + ".csv");
Global.frame.setTitle("Usagi - " + file.getName());
Global.filename = file.getAbsolutePath();
+ Global.folder = file.getParentFile().getAbsolutePath();
Global.frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Global.mapping.saveToFile(Global.filename);
Global.frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
diff --git a/src/org/ohdsi/usagi/ui/actions/UsagiDialogs.java b/src/org/ohdsi/usagi/ui/actions/UsagiDialogs.java
new file mode 100644
index 0000000..4e52c20
--- /dev/null
+++ b/src/org/ohdsi/usagi/ui/actions/UsagiDialogs.java
@@ -0,0 +1,45 @@
+package org.ohdsi.usagi.ui.actions;
+
+import org.ohdsi.usagi.ui.Global;
+
+import javax.swing.*;
+
+public class UsagiDialogs {
+ public static boolean askExportUnapprovedMappings() {
+ String[] options = {"Only approved","Approved and Unapproved"};
+ int PromptResult = JOptionPane.showOptionDialog(
+ Global.frame,
+ "Do you want to export both approved and unapproved mappings?",
+ "Export for review",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ options,
+ options[0]
+ );
+ return PromptResult == 1;
+ }
+
+ public static void warningNothingToExport() {
+ JOptionPane.showMessageDialog(
+ Global.frame,
+ "There are no approved mappings, so nothing to export",
+ "Nothing to export",
+ JOptionPane.WARNING_MESSAGE
+ );
+ }
+
+ public static boolean askBeforeExit() {
+ String[] objButtons = {"Yes","No"};
+ int PromptResult = JOptionPane.showOptionDialog(
+ Global.frame,
+ "Do you want to exit?\nPlease make sure that any work is saved",
+ "Usagi",
+ JOptionPane.DEFAULT_OPTION,
+ JOptionPane.WARNING_MESSAGE,
+ null, objButtons, objButtons[1]
+ );
+ return PromptResult == JOptionPane.YES_OPTION;
+ }
+
+}
diff --git a/src/org/ohdsi/utilities/files/WriteCSVFile.java b/src/org/ohdsi/utilities/files/WriteCSVFile.java
index 6a7646b..f16b7d9 100644
--- a/src/org/ohdsi/utilities/files/WriteCSVFile.java
+++ b/src/org/ohdsi/utilities/files/WriteCSVFile.java
@@ -86,15 +86,17 @@ public String columns2line(List columns) {
Iterator iterator = columns.iterator();
while (iterator.hasNext()) {
String column = iterator.next();
- boolean hasQuotes = column.contains("\"");
- column = column.replaceAll("\\\\", "\\\\\\\\");
- if (hasQuotes)
- column = column.replaceAll("\"", "\\\\\"");
- column = column.replaceAll("\r", "");
- column = column.replaceAll("\n", "\\\\n");
- if (hasQuotes || column.contains(Character.toString(delimiter)))
- column = "\"" + column + "\"";
- sb.append(column);
+ if (column != null) {
+ boolean hasQuotes = column.contains("\"");
+ column = column.replaceAll("\\\\", "\\\\\\\\");
+ if (hasQuotes)
+ column = column.replaceAll("\"", "\\\\\"");
+ column = column.replaceAll("\r", "");
+ column = column.replaceAll("\n", "\\\\n");
+ if (hasQuotes || column.contains(Character.toString(delimiter)))
+ column = "\"" + column + "\"";
+ sb.append(column);
+ }
if (iterator.hasNext())
sb.append(delimiter);
}