Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export unapproved mappings #73

Merged
merged 9 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions Usagi.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="R User Library" level="project" />
<orderEntry type="library" name="R Skeletons" level="application" />
</component>
</module>
26 changes: 10 additions & 16 deletions src/org/ohdsi/usagi/ui/ExportSourceToConceptMapDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand All @@ -98,13 +87,18 @@ 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");
fileChooser.setFileFilter(csvFilter);
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");

Expand All @@ -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<Concept> targetConcepts;
if (mapping.targetConcepts.size() == 0) {
targetConcepts = new ArrayList<Concept>(1);
Expand All @@ -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", "");
Expand Down
51 changes: 19 additions & 32 deletions src/org/ohdsi/usagi/ui/UsagiMain.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -28,50 +28,28 @@
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;

/**
* The main application class
*/
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()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand All @@ -147,7 +134,7 @@ private String loadVocabularyVersion(String folder) {
if (new File(versionFileName).exists()) {
for (String line : new ReadTextFile(versionFileName))
version = line;
}
}
return version;
}

Expand Down
10 changes: 7 additions & 3 deletions src/org/ohdsi/usagi/ui/actions/ExitAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -31,7 +32,10 @@ public ExitAction() {

@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
if (UsagiDialogs.askBeforeExit()) {
Global.dbEngine.shutdown();
System.exit(0);
}
}

}
Loading