diff --git a/rabbit-core/src/main/java/org/ohdsi/rabbitInAHat/dataModel/Database.java b/rabbit-core/src/main/java/org/ohdsi/rabbitInAHat/dataModel/Database.java index ff67e8ea..01ab94c3 100644 --- a/rabbit-core/src/main/java/org/ohdsi/rabbitInAHat/dataModel/Database.java +++ b/rabbit-core/src/main/java/org/ohdsi/rabbitInAHat/dataModel/Database.java @@ -56,6 +56,8 @@ public enum CDMVersion { private static final String CONCEPT_ID_HINTS_FILE_NAME = "CDMConceptIDHints.csv"; public String conceptIdHintsVocabularyVersion; private List selectedIndices; + private boolean hasStemTable = false; + private Table stemTable; public List getTables() { if(selectedIndices != null){ @@ -63,9 +65,13 @@ public List
getTables() { for (Integer selectedIndex : selectedIndices) { maskedTables.add(tables.get(selectedIndex)); } + if (hasStemTable) { + maskedTables.add(stemTable); + } return maskedTables; + } else { + return tables; } - return tables; } public List
getUnmaskedTables() { @@ -87,6 +93,16 @@ public void addTable(Table table) { this.tables.add(table); } + public void addStemTable(Table stemTable) { + this.stemTable = stemTable; + this.hasStemTable = true; + } + + public void removeStemTable() { + this.hasStemTable = false; + this.stemTable = null; + } + public String getDbName() { return dbName; } diff --git a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java index 647584e8..8971e8e9 100644 --- a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java +++ b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java @@ -930,6 +930,6 @@ public boolean isBeingFiltered() { } private boolean isTableAndSelected(MappableItem item) { - return mappingType == MappingType.FIELDS || ObjectExchange.etl.isSelectedTable(item); + return mappingType == MappingType.FIELDS || item.isStem() || ObjectExchange.etl.isSelectedTable(item); } } diff --git a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/RabbitInAHatMain.java b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/RabbitInAHatMain.java index ac4c19d0..050a8300 100644 --- a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/RabbitInAHatMain.java +++ b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/RabbitInAHatMain.java @@ -255,8 +255,8 @@ private JMenuBar createMenuBar() { menuBar.add(editMenu); addMenuItem(editMenu, ACTION_DISCARD_COUNTS, evt -> this.doDiscardCounts()); addMenuItem(editMenu, ACTION_FILTER, evt -> this.doOpenFilterDialog(), KeyEvent.VK_F); - addMenuItem(editMenu, ACTION_ADD_STEM_TABLE, evt -> this.doAddStemTable()); - addMenuItem(editMenu, ACTION_REMOVE_STEM_TABLE, evt -> this.doRemoveStemTable()); + addMenuItem(editMenu, ACTION_ADD_STEM_TABLE, evt -> this.doAddStemTable()).setName(ACTION_ADD_STEM_TABLE); + addMenuItem(editMenu, ACTION_REMOVE_STEM_TABLE, evt -> this.doRemoveStemTable()).setName(ACTION_REMOVE_STEM_TABLE); addMenuItem(editMenu, ACTION_HIDE_TABLES, evt -> this.doHideTables()).setName(ACTION_HIDE_TABLES); JMenu targetDatabaseMenu = new JMenu("Set Target Database"); diff --git a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/ETL.java b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/ETL.java index eb52c9c2..c8e89f72 100644 --- a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/ETL.java +++ b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/ETL.java @@ -249,6 +249,9 @@ public List getMappingsToTargetField(Field targetField) { } public boolean isSelectedTable(MappableItem item) { + if (item.isStem()) { + return true; + } List indices = sourceDb.getSelectedIndices(); for(int i : indices){ if(sourceDb.getUnmaskedTables().get(i) == item){ diff --git a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/StemTableFactory.java b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/StemTableFactory.java index 250265b3..19a3f7fc 100644 --- a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/StemTableFactory.java +++ b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/dataModel/StemTableFactory.java @@ -33,7 +33,7 @@ public class StemTableFactory { - private static final String STEM_TABLE_NAME = "stem_table"; + public static final String STEM_TABLE_NAME = "stem_table"; public static void addStemTable(ETL etl) { Database sourceDatabase = etl.getSourceDatabase(); @@ -76,10 +76,10 @@ public static void addStemTable(ETL etl) { field.setStem(true); sourceStemTable.getFields().add(field); } - sourceDatabase.getTables().add(sourceStemTable); + sourceDatabase.addStemTable(sourceStemTable); Table targetStemTable = new Table(sourceStemTable); targetStemTable.setDb(targetDatabase); - targetDatabase.getTables().add(targetStemTable); + targetDatabase.addStemTable(targetStemTable); Mapping
mapping = etl.getTableToTableMapping(); Map nameToTable = new HashMap<>(); @@ -96,11 +96,9 @@ public static void addStemTable(ETL etl) { Field targetField = targetTable.getFieldByName(row.get("TARGET_FIELD")); fieldToFieldMapping.addSourceToTargetMap(sourceField, targetField); } - } catch (IOException e) { throw new RuntimeException(e.getMessage()); } - } public static void removeStemTable(ETL etl) { @@ -121,25 +119,8 @@ public static void removeStemTable(ETL etl) { mapping.removeSourceToTargetMap(tableTablePair.getItem1(), tableTablePair.getItem2()); } - // Remove stem source table - Database sourceDatabase = etl.getSourceDatabase(); - List
newSourceTables = new ArrayList<>(); - for (Table table : sourceDatabase.getTables()) { - if (!table.isStem()) { - newSourceTables.add(table); - } - } - sourceDatabase.setTables(newSourceTables); - - // Remove stem target table - Database targetDatabase = etl.getTargetDatabase(); - List
newTargetTables = new ArrayList<>(); - for (Table table : targetDatabase.getTables()) { - if (!table.isStem()) { - newTargetTables.add(table); - } - } - targetDatabase.setTables(newTargetTables); + etl.getSourceDatabase().removeStemTable(); + etl.getTargetDatabase().removeStemTable(); } } diff --git a/rabbitinahat/src/test/java/org/ohdsi/rabbitInAHat/RabbitInAHatIT.java b/rabbitinahat/src/test/java/org/ohdsi/rabbitInAHat/RabbitInAHatIT.java index fa0cdda0..09cb49ac 100644 --- a/rabbitinahat/src/test/java/org/ohdsi/rabbitInAHat/RabbitInAHatIT.java +++ b/rabbitinahat/src/test/java/org/ohdsi/rabbitInAHat/RabbitInAHatIT.java @@ -55,6 +55,8 @@ * disrupted by unrelated user activity on workstations/laptops (any keyboard or mouse action). * For debugging purposes, you can disable the annotation below to have the tests run on your screen. Be aware that * any interaction with mouse or keyboard can (will) disrupt the tests if they run on your screen. + * Also keep in mind that the tests may fail if your screen has different dimensions than the virtual screen (as defined by + * VIRTUAL_SCREEN_WIDTH and VIRTUAL_SCREEN_HEIGHT below). */ @CacioTest @@ -62,11 +64,11 @@ public class RabbitInAHatIT { private static FrameFixture window; - private final static int WIDTH = 1920; - private final static int HEIGHT = 1080; + private final static int VIRTUAL_SCREEN_WIDTH = 1920; + private final static int VIRTUAL_SCREEN_HEIGHT = 1080; @BeforeAll public static void setupOnce() throws IOException { - System.setProperty("cacio.managed.screensize", String.format("%sx%s", WIDTH, HEIGHT)); + System.setProperty("cacio.managed.screensize", String.format("%sx%s", VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT)); // unzip examples.zip into target resources Path examplesPath = Paths.get("examples.zip"); if (!Files.exists(examplesPath)) { @@ -80,7 +82,8 @@ public void setUp() { String[] args = {}; RabbitInAHatMain rabbitInAHatMain = GuiActionRunner.execute(() -> new RabbitInAHatMain(args)); window = new FrameFixture(rabbitInAHatMain.getFrame()); - window.splitPane("splitpane").target().setDividerLocation(WIDTH / 2); + window.splitPane("splitpane").target().setDividerLocation(VIRTUAL_SCREEN_WIDTH / 2); + // window.robot().settings().delayBetweenEvents(150); // increase delay between events to make it easier to follow the tests window.show(); // shows the frame to test } @@ -104,12 +107,19 @@ public void openApp() { } @Test - public void openReport() throws URISyntaxException { - window.menuItem(ACTION_OPEN_SCAN_REPORT).click(); - JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().using(window.robot()); - assertEquals(TITLE_SELECT_FILE, fileChooser.target().getDialogTitle()); - URL scanReportUrl = RabbitInAHatIT.class.getClassLoader().getResource("examples/test_scanreports/ScanReport_minimal.xlsx"); - fileChooser.selectFile(new File(Objects.requireNonNull(scanReportUrl).toURI())).approve(); + void openScanReportAndAddStemTable() throws URISyntaxException { + openScanReport("examples/test_scanreports/ScanReport_minimal.xlsx"); + MappingPanel tablesPanel = getTablesPanel(); + + window.menuItem(ACTION_ADD_STEM_TABLE).click(); + + verifyMapping(tablesPanel, "stem_table", "condition_occurrence"); + verifyMapping(tablesPanel, "stem_table", "drug_exposure"); + verifyMapping(tablesPanel, "stem_table", "procedure_occurrence"); + verifyMapping(tablesPanel, "stem_table", "device_exposure"); + verifyMapping(tablesPanel, "stem_table", "measurement"); + verifyMapping(tablesPanel, "stem_table", "observation"); + // there are more mappings, but these may not be visible depending on the actual screen size } @Test @@ -131,7 +141,7 @@ public void openAndVerifySavedETLSpecs() throws URISyntaxException { } @Test - void openSavedETLSpecsAndSelectMapping() throws URISyntaxException { + void openSavedETLSpecsAndSelectMapping() throws URISyntaxException, InterruptedException { // open the test ETL specification openETLSpecs("scan/etl-specs.json.gz"); MappingPanel tablesPanel = getTablesPanel(); @@ -148,7 +158,6 @@ void openSavedETLSpecsAndSelectMapping() throws URISyntaxException { // double click the mapping (arrow) window.robot().click(tablesPanel, mapping.getPointInside(), MouseButton.LEFT_BUTTON, 2); MappingPanel fieldsPanel = getPanel(PANEL_FIELD_MAPPING); - //pause(10000); pause(new Condition("wait for source items to appear in the items panel") { public boolean test() { return fieldsPanel.getVisibleSourceComponents().size() != 0 && @@ -229,6 +238,18 @@ public boolean test() { assertFalse("There should be target items", tablesPanel.getVisibleTargetComponents().isEmpty()); } + private void openScanReport(String reportPath) throws URISyntaxException { + window.menuItem(ACTION_OPEN_SCAN_REPORT).click(); + JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().using(window.robot()); + assertEquals(TITLE_SELECT_FILE, fileChooser.target().getDialogTitle()); + URL scanReportUrl = RabbitInAHatIT.class.getClassLoader().getResource(reportPath); + File scanReport = new File(Objects.requireNonNull(scanReportUrl).toURI()); + fileChooser.setCurrentDirectory(scanReport.getParentFile()); + fileChooser.selectFile(scanReport).approve(); + //fileChooser.selectFile(new File(Objects.requireNonNull(scanReportUrl).toURI())).approve(); + } + + private void verifyMapping(MappingPanel tablesPanel, String sourceName, String targetName, String... details) { LabeledRectangle sourceTable = findMappableItem(tablesPanel.getVisibleSourceComponents(), sourceName); LabeledRectangle targetTable = findMappableItem(tablesPanel.getVisibleTargetComponents(), targetName);