Skip to content

Commit

Permalink
Fix stem_table mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
janblom committed Jan 31, 2025
1 parent ff4a2c4 commit 1730f56
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,22 @@ public enum CDMVersion {
private static final String CONCEPT_ID_HINTS_FILE_NAME = "CDMConceptIDHints.csv";
public String conceptIdHintsVocabularyVersion;
private List<Integer> selectedIndices;
private boolean hasStemTable = false;
private Table stemTable;

public List<Table> getTables() {
if(selectedIndices != null){
List<Table> maskedTables = new ArrayList<>();
for (Integer selectedIndex : selectedIndices) {
maskedTables.add(tables.get(selectedIndex));
}
if (hasStemTable) {
maskedTables.add(stemTable);
}
return maskedTables;
} else {
return tables;
}
return tables;
}

public List<Table> getUnmaskedTables() {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ public List<String> getMappingsToTargetField(Field targetField) {
}

public boolean isSelectedTable(MappableItem item) {
if (item.isStem()) {
return true;
}
List<Integer> indices = sourceDb.getSelectedIndices();
for(int i : indices){
if(sourceDb.getUnmaskedTables().get(i) == item){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Table> mapping = etl.getTableToTableMapping();
Map<String, Table> nameToTable = new HashMap<>();
Expand All @@ -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) {
Expand All @@ -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<Table> 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<Table> newTargetTables = new ArrayList<>();
for (Table table : targetDatabase.getTables()) {
if (!table.isStem()) {
newTargetTables.add(table);
}
}
targetDatabase.setTables(newTargetTables);
etl.getSourceDatabase().removeStemTable();
etl.getTargetDatabase().removeStemTable();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@
* 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

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)) {
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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 &&
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1730f56

Please sign in to comment.