Skip to content

Commit

Permalink
Added option to load field values from scanreport into existing ETL
Browse files Browse the repository at this point in the history
specification.
  • Loading branch information
schuemie committed Jul 20, 2016
1 parent ac207fb commit fbfcf00
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions src/org/ohdsi/rabbitInAHat/RabbitInAHatMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import org.ohdsi.rabbitInAHat.dataModel.Database;
import org.ohdsi.rabbitInAHat.dataModel.Database.CDMVersion;
import org.ohdsi.rabbitInAHat.dataModel.ETL;
import org.ohdsi.rabbitInAHat.dataModel.Field;
import org.ohdsi.rabbitInAHat.dataModel.MappableItem;
import org.ohdsi.rabbitInAHat.dataModel.Table;
import org.ohdsi.whiteRabbit.ObjectExchange;

/**
Expand Down Expand Up @@ -77,6 +80,8 @@ public class RabbitInAHatMain implements ResizeListener, ActionListener {
private final static FileFilter FILE_FILTER_DOCX = new FileNameExtensionFilter("Microsoft Word documents (*.docx)", "docx");
private final static FileFilter FILE_FILTER_CSV = new FileNameExtensionFilter("Text Files (*.csv)", "csv");
private final static FileFilter FILE_FILTER_R = new FileNameExtensionFilter("R script (*.r)", "r");
private final static FileFilter FILE_FILTER_XLSX = new FileNameExtensionFilter("XLSX files (*.xlsx)", "xlsx");

private JFrame frame;
private JScrollPane scrollPane1;
private JScrollPane scrollPane2;
Expand Down Expand Up @@ -329,6 +334,7 @@ private String choosePath(boolean saveMode, FileFilter... filter) {
if (chooser == null) {
chooser = new JFileChooser();
}
chooser.resetChoosableFileFilters();
chooser.setFileFilter(filter[0]);
for (int i = 1; i < filter.length; i++)
chooser.addChoosableFileFilter(filter[i]);
Expand All @@ -352,10 +358,6 @@ private String chooseOpenPath(FileFilter... fileFilter) {
return choosePath(false, fileFilter);
}

private String chooseOpenPath() {
return chooseOpenPath(null);
}

@Override
public void actionPerformed(ActionEvent event) {
switch (event.getActionCommand()) {
Expand All @@ -370,7 +372,7 @@ public void actionPerformed(ActionEvent event) {
doOpenSpecs(chooseOpenPath(FILE_FILTER_GZ, FILE_FILTER_JSON));
break;
case ACTION_CMD_OPEN_SCAN_REPORT:
doOpenScanReport(chooseOpenPath());
doOpenScanReport(chooseOpenPath(FILE_FILTER_XLSX));
break;
case ACTION_CMD_GENERATE_ETL_DOCUMENT:
doGenerateEtlDoc(chooseSavePath(FILE_FILTER_DOCX));
Expand Down Expand Up @@ -521,20 +523,59 @@ private void doOpenSpecs(String filename) {

private void doOpenScanReport(String filename) {
if (filename != null) {
boolean replace = true;
if (ObjectExchange.etl.getSourceDatabase().getTables().size() != 0){
Object[] options = {"Replace current data",
"Load data on field values only"};
int result = JOptionPane.showOptionDialog(frame, "You already have source data loaded. Do you want to", "Replace source data?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (result == -1)
return;
if (result == 1)
replace = false;
}
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
ETL etl = new ETL();
try {
etl.setSourceDatabase(Database.generateModelFromScanReport(filename));
etl.setTargetDatabase(ObjectExchange.etl.getTargetDatabase());
tableMappingPanel.setMapping(etl.getTableToTableMapping());
ObjectExchange.etl = etl;
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Invalid File Format", "Error", JOptionPane.ERROR_MESSAGE);
if (replace) {
ETL etl = new ETL();
try {
etl.setSourceDatabase(Database.generateModelFromScanReport(filename));
etl.setTargetDatabase(ObjectExchange.etl.getTargetDatabase());
tableMappingPanel.setMapping(etl.getTableToTableMapping());
ObjectExchange.etl = etl;
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Invalid File Format", "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
try {
Database newData = Database.generateModelFromScanReport(filename);
Database oldData = ObjectExchange.etl.getSourceDatabase();
for (Table newTable : newData.getTables()) {
Table oldTable = (Table)findByName(newTable.getName(), oldData.getTables());
if (oldTable != null) {
for (Field newField : newTable.getFields()) {
Field oldField = (Field)findByName(newField.getName(), oldTable.getFields());
if (oldField != null) {
oldField.setValueCounts(newField.getValueCounts());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Invalid File Format", "Error", JOptionPane.ERROR_MESSAGE);
}

}
frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}

private MappableItem findByName(String name, List<? extends MappableItem> list) {
for (MappableItem item : list)
if (item.getName().toLowerCase().equals(name.toLowerCase()))
return item;
return null;
}

private void doGenerateEtlDoc(String filename) {
if (filename != null) {
Expand Down

0 comments on commit fbfcf00

Please sign in to comment.