Skip to content

Commit

Permalink
Merge pull request #125 from OHDSI/release-1.4.3
Browse files Browse the repository at this point in the history
Release 1.4.3
  • Loading branch information
Maxim Moinat authored Apr 9, 2021
2 parents 0d157f4 + ee43567 commit b2ecfac
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ConceptClassIds.txt
DomainIds.txt
VocabularyIds.txt
vocabularyVersion.txt
authorName.txt

local_files/

Expand Down
16 changes: 16 additions & 0 deletions src/org/ohdsi/usagi/Concept.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;

import java.util.Objects;

/**
* Class for holding information about a single (target) concept in the Vocabulary
*/
Expand Down Expand Up @@ -77,4 +79,18 @@ public static Concept createEmptyConcept() {

public Concept() {
}

@Override
public boolean equals(Object o) {
// Only compare conceptId
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Concept concept = (Concept) o;
return conceptId == concept.conceptId;
}

@Override
public int hashCode() {
return Objects.hash(conceptId);
}
}
28 changes: 27 additions & 1 deletion src/org/ohdsi/usagi/MappingTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@
******************************************************************************/
package org.ohdsi.usagi;

import java.util.Objects;

/**
* Class for holding information about a single (target) concept in the Vocabulary
*/
public class MappingTarget{
public enum Type {
MAPS_TO, MAPS_TO_VALUE, MAPS_TO_UNIT
MAPS_TO, MAPS_TO_VALUE, MAPS_TO_UNIT, MAPS_TO_OPERATOR, MAPS_TO_TYPE, MAPS_TO_NUMBER;

public static Type valueOfCompat(String value) {
// For backwards compatibility with old types
switch (value) {
case "EVENT": return MAPS_TO;
case "VALUE": return MAPS_TO_VALUE;
case "UNIT": return MAPS_TO_UNIT;
default: return valueOf(value);
}
}
}

private final Concept concept;
Expand Down Expand Up @@ -72,4 +84,18 @@ public Type getMappingType() {
public void setMappingType(Type mappingType) {
this.mappingType = mappingType;
}

@Override
public boolean equals(Object o) {
// Only compares target concept and mappingType.
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MappingTarget that = (MappingTarget) o;
return Objects.equals(concept, that.concept) && mappingType == that.mappingType;
}

@Override
public int hashCode() {
return Objects.hash(concept, mappingType);
}
}
9 changes: 2 additions & 7 deletions src/org/ohdsi/usagi/ReadCodeMappingsFromFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void readNext() {
buffer = null;
} else {
buffer = new CodeMapping(new SourceCode(row));
buffer.setMatchScore(row.getDouble("matchScore"));
buffer.setMatchScore(row.getDouble("matchScore", "0"));
buffer.setMappingStatus(MappingStatus.valueOf(row.get("mappingStatus")));

// Status provenance and review need a default as these fields might not be available in older Usagi files
Expand All @@ -77,14 +77,9 @@ && new SourceCode(row).sourceName.equals(buffer.getSourceCode().sourceName)) {
buffer.setMappingStatus(MappingStatus.INVALID_TARGET);
buffer.setComment("Invalid existing target: " + row.get("conceptId"));
} else {
// Type and provenance might not be available in older Usagi files
MappingTarget mappingTarget = new MappingTarget(
concept,
MappingTarget.Type.valueOf(row.get("mappingType", "MAPS_TO")
.replace("EVENT", "MAPS_TO")
.replace("VALUE", "MAPS_TO_VALUE")
.replace("UNIT", "MAPS_TO_UNIT")
),
MappingTarget.Type.valueOfCompat(row.get("mappingType", "MAPS_TO")),
row.get("createdBy", ""),
row.getLong("createdOn", "0")
);
Expand Down
3 changes: 2 additions & 1 deletion src/org/ohdsi/usagi/WriteCodeMappingsToFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void write(CodeMapping codeMapping) {
row.add("statusSetBy", codeMapping.getStatusSetBy());
row.add("statusSetOn", codeMapping.getStatusSetOn());
row.add("conceptId", targetConcept.getConcept().conceptId);
row.add("conceptName", targetConcept.getConcept().conceptName); // Never read in.
row.add("conceptName", targetConcept.getConcept().conceptName); // Redundant, not read in
row.add("domainId", targetConcept.getConcept().domainId); // Redundant, not read in
row.add("mappingType", targetConcept.getMappingType().toString());
row.add("comment", codeMapping.getComment());
row.add("createdBy", targetConcept.getCreatedBy());
Expand Down
25 changes: 22 additions & 3 deletions src/org/ohdsi/usagi/ui/AuthorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
******************************************************************************/
package org.ohdsi.usagi.ui;

import org.ohdsi.utilities.files.WriteTextFile;

import javax.swing.*;
import java.awt.*;

public class AuthorDialog extends JDialog {

private static final long serialVersionUID = 8239922540117895957L;
private static final long serialVersionUID = 8239922540117895957L;
private String authorFileName;

public AuthorDialog() {
setTitle("Author");
setTitle("Usagi v" + UsagiMain.version);
setLayout(new GridBagLayout());
GridBagConstraints g = new GridBagConstraints();
g.fill = GridBagConstraints.BOTH;
Expand All @@ -32,7 +35,7 @@ public AuthorDialog() {

g.gridx = 0;
g.gridy = 0;
add(new JLabel("Author:"), g);
add(new JLabel(" Author:"), g);

g.gridx = 1;
g.gridy = 0;
Expand All @@ -41,6 +44,12 @@ public AuthorDialog() {
authorField.setPreferredSize(new Dimension(100, 10));
add(authorField, g);

g.gridx = 0;
g.gridy = 1;
g.gridwidth = 2;
JCheckBox saveBox = new JCheckBox("Remember me?");
add(saveBox, g);

g.gridx = 0;
g.gridy = 2;
g.gridwidth = 2;
Expand All @@ -52,6 +61,11 @@ public AuthorDialog() {
saveButton.addActionListener(event -> {
Global.author = authorField.getText();
setVisible(false);
if (saveBox.isSelected() && authorFileName != null) {
WriteTextFile out = new WriteTextFile(authorFileName);
out.writeln(authorField.getText());
out.close();
}
});
buttonPanel.add(saveButton);
add(buttonPanel, g);
Expand All @@ -60,4 +74,9 @@ public AuthorDialog() {
setModal(true);
setLocationRelativeTo(Global.frame);
}

public void setAuthorFileName(String authorFileName) {
this.authorFileName = authorFileName;
}

}
11 changes: 8 additions & 3 deletions src/org/ohdsi/usagi/ui/ImportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ private void loadData(String filename) {
if (!iterator.hasNext())
throw new RuntimeException("File contains no data");
columnNames = iterator.next();
Set<String> uniqueNames = new HashSet<String>();
for (String columnName : columnNames)
if (!uniqueNames.add(columnName))
Set<String> uniqueNames = new HashSet<>();
for (String columnName : columnNames) {
if (columnName.isEmpty()) {
continue;
}
if (!uniqueNames.add(columnName)) {
throw new RuntimeException("Found duplicate column name '" + columnName + "', duplicates are not allowed.");
}
}
comboBoxOptions = new String[columnNames.size() + 1];
comboBoxOptions[0] = "";
for (int i = 0; i < columnNames.size(); i++)
Expand Down
16 changes: 12 additions & 4 deletions src/org/ohdsi/usagi/ui/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;

import org.ohdsi.usagi.CodeMapping;
import org.ohdsi.usagi.ReadCodeMappingsFromFile;
import org.ohdsi.usagi.SourceCode;
import org.ohdsi.usagi.WriteCodeMappingsToFile;
import org.ohdsi.utilities.collections.Pair;

import static org.ohdsi.usagi.ui.DataChangeEvent.*;

Expand Down Expand Up @@ -83,9 +85,15 @@ public void saveToFile(String filename) {
}

public List<SourceCode> getSourceCodes() {
List<SourceCode> sourceCodes = new ArrayList<SourceCode>(size());
for (CodeMapping codeMapping : this)
sourceCodes.add(codeMapping.getSourceCode());
return sourceCodes;
return this.stream()
.map(CodeMapping::getSourceCode)
.collect(Collectors.toList());
}

public List<String> getAdditionalColumnNames() {
CodeMapping codeMapping = Global.mapping.get(0);
return codeMapping.getSourceCode().sourceAdditionalInfo.stream()
.map(Pair::getItem1)
.collect(Collectors.toList());
}
}
69 changes: 34 additions & 35 deletions src/org/ohdsi/usagi/ui/MappingDetailPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class MappingDetailPanel extends JPanel implements CodeSelectedListener,
private JComboBox equivalenceOptionChooser;
private JTextField commentField;
private JButton removeButton;
private JComboBox typesChooser;
private JComboBox targetMappingTypesChooser;
private JComboBox addMappingsTypesChooser;
private JButton replaceButton;
private List<JButton> addButtons;
private JRadioButton autoQueryCodeButton;
Expand Down Expand Up @@ -179,9 +180,11 @@ private Component createSearchResultsPanel() {
if (viewRow == -1 || codeMapping.getMappingStatus() == MappingStatus.APPROVED) {
addButtons.forEach(x -> x.setEnabled(false));
replaceButton.setEnabled(false);
addMappingsTypesChooser.setEnabled(false);
} else {
addButtons.forEach(x -> x.setEnabled(true));
replaceButton.setEnabled(true);
addMappingsTypesChooser.setEnabled(true);
int modelRow = searchTable.convertRowIndexToModel(viewRow);
Global.conceptInfoAction.setEnabled(true);
Global.conceptInformationDialog.setActiveConcept(searchTableModel.getConcept(modelRow));
Expand Down Expand Up @@ -211,28 +214,23 @@ private Component createSearchResultsPanel() {
buttonPanel.add(replaceButton);

JButton button;
addButtons = new ArrayList<>();
for (MappingTarget.Type mappingType : MappingTarget.Type.values()) {
if (mappingType.equals(MappingTarget.Type.MAPS_TO)) {
button = new JButton("Add concept");
} else {
button = new JButton(String.format("Add %s", mappingType));
}
button.setToolTipText(String.format("Add selected concept as %s", mappingType));
button.addActionListener(e -> {
int viewRow = searchTable.getSelectedRow();
int modelRow = searchTable.convertRowIndexToModel(viewRow);
addConcept(searchTableModel.getConcept(modelRow), mappingType);
});
button.setEnabled(false);
addButtons.add(button);
// Add Maps_to button on the right, the other on the left.
if (mappingType.equals(MappingTarget.Type.MAPS_TO)) {
buttonPanel.add(button);
} else {
buttonPanel.add(button, 0);
}
}
button = new JButton("Add concept");
button.setToolTipText(String.format("Add selected concept"));
button.addActionListener(e -> {
int viewRow = searchTable.getSelectedRow();
int modelRow = searchTable.convertRowIndexToModel(viewRow);
addConcept(searchTableModel.getConcept(modelRow), (MappingTarget.Type) addMappingsTypesChooser.getSelectedItem());
});
button.setEnabled(false);
buttonPanel.add(button);
addButtons = new ArrayList<>(); // There used to be an add button for each mapping type
addButtons.add(button);

addMappingsTypesChooser = new JComboBox<>(MappingTarget.Type.values());
addMappingsTypesChooser.setToolTipText("Set type of the mapping to be added");
addMappingsTypesChooser.setMaximumSize(addMappingsTypesChooser.getPreferredSize());
addMappingsTypesChooser.setEnabled(false);
buttonPanel.add(addMappingsTypesChooser, 0);

panel.add(buttonPanel);

Expand Down Expand Up @@ -322,13 +320,13 @@ private JPanel createTargetConceptsPanel() {
int viewRow = targetConceptTable.getSelectedRow();
if (viewRow == -1 || codeMapping.getMappingStatus() == MappingStatus.APPROVED) {
removeButton.setEnabled(false);
typesChooser.setEnabled(false);
targetMappingTypesChooser.setEnabled(false);
} else {
removeButton.setEnabled(true);
typesChooser.setEnabled(true);
targetMappingTypesChooser.setEnabled(true);
int modelRow = targetConceptTable.convertRowIndexToModel(viewRow);
MappingTarget mappingTarget = targetConceptTableModel.getMappingTarget(modelRow);
typesChooser.setSelectedItem(mappingTarget.getMappingType());
targetMappingTypesChooser.setSelectedItem(mappingTarget.getMappingType());
Global.conceptInfoAction.setEnabled(true);
Global.conceptInformationDialog.setActiveConcept(mappingTarget.getConcept());
Global.athenaAction.setEnabled(true);
Expand All @@ -342,22 +340,22 @@ private JPanel createTargetConceptsPanel() {

JScrollPane pane = new JScrollPane(targetConceptTable);
pane.setBorder(BorderFactory.createEmptyBorder());
pane.setMinimumSize(new Dimension(500, 50));
pane.setPreferredSize(new Dimension(500, 50));
pane.setMinimumSize(new Dimension(500, 75));
pane.setPreferredSize(new Dimension(500, 75));
panel.add(pane);

JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));

typesChooser = new JComboBox<>(MappingTarget.Type.values());
typesChooser.setToolTipText("Set type of the mapping");
typesChooser.addActionListener(e -> {
targetMappingTypesChooser = new JComboBox<>(MappingTarget.Type.values());
targetMappingTypesChooser.setToolTipText("Set type of the mapping");
targetMappingTypesChooser.addActionListener(e -> {
if (((JComboBox)e.getSource()).hasFocus())
changeTargetType();
});
typesChooser.setMaximumSize(typesChooser.getPreferredSize());
typesChooser.setEnabled(false);
buttonPanel.add(typesChooser);
targetMappingTypesChooser.setMaximumSize(targetMappingTypesChooser.getPreferredSize());
targetMappingTypesChooser.setEnabled(false);
buttonPanel.add(targetMappingTypesChooser);

buttonPanel.add(Box.createHorizontalGlue());

Expand Down Expand Up @@ -448,6 +446,7 @@ public void uncheckSelected() {
if (searchTable.getSelectedRow() != -1) {
replaceButton.setEnabled(true);
addButtons.forEach(x -> x.setEnabled(true));
addMappingsTypesChooser.setEnabled(true);
}
}

Expand Down Expand Up @@ -523,7 +522,7 @@ private void remove() {
private void changeTargetType() {
for (int row : targetConceptTable.getSelectedRows()) {
MappingTarget mappingTarget = codeMapping.getTargetConcepts().get(row);
mappingTarget.setMappingType((MappingTarget.Type) typesChooser.getSelectedItem());
mappingTarget.setMappingType((MappingTarget.Type) targetMappingTypesChooser.getSelectedItem());
}

targetConceptTableModel.fireTableDataChanged();
Expand Down
Loading

0 comments on commit b2ecfac

Please sign in to comment.