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

Fix compatibility issue #123

Merged
merged 6 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions src/org/ohdsi/usagi/Concept.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ public static Concept createEmptyConcept() {

public Concept() {
}

@Override
public boolean equals(Object o) {
MaximMoinat marked this conversation as resolved.
Show resolved Hide resolved
// Only compare conceptId
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Concept concept = (Concept) o;
return conceptId == concept.conceptId;
}
}
12 changes: 12 additions & 0 deletions src/org/ohdsi/usagi/MappingTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
******************************************************************************/
package org.ohdsi.usagi;

import java.util.Objects;

/**
* Class for holding information about a single (target) concept in the Vocabulary
*/
Expand Down Expand Up @@ -72,4 +74,14 @@ public Type getMappingType() {
public void setMappingType(Type mappingType) {
this.mappingType = mappingType;
}

@Override
public boolean equals(Object o) {
MaximMoinat marked this conversation as resolved.
Show resolved Hide resolved
// 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;
}

}
16 changes: 10 additions & 6 deletions src/org/ohdsi/usagi/ReadCodeMappingsFromFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ && 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
String mappingTypeString = row.get("mappingType", "MAPS_TO");
if (!mappingTypeString.startsWith("MAPS_TO")) {
// For backwards compatibility with files using event/value/unit
mappingTypeString = mappingTypeString
.replace("EVENT", "MAPS_TO")
.replace("VALUE", "MAPS_TO_VALUE")
.replace("UNIT", "MAPS_TO_UNIT");
}
MaximMoinat marked this conversation as resolved.
Show resolved Hide resolved

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.valueOf(mappingTypeString),
row.get("createdBy", ""),
row.getLong("createdOn", "0")
);
Expand Down
47 changes: 45 additions & 2 deletions src/org/ohdsi/usagi/ui/actions/ApplyPreviousMappingAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public void actionPerformed(ActionEvent arg0) {
mappingToBeApplied.loadFromFile(file.getAbsolutePath());

// Apply mapping. Add mappings not currently present
ApplyPreviousChangeSummary summary = new ApplyPreviousChangeSummary();
for (CodeMapping codeMappingToBeApplied : mappingToBeApplied) {
CodeMapping existingMapping = codeToMapping.get(codeMappingToBeApplied.getSourceCode().sourceCode);
if (existingMapping != null) {
summary.compare(existingMapping, codeMappingToBeApplied);
existingMapping.getSourceCode().sourceName = codeMappingToBeApplied.getSourceCode().sourceName;
existingMapping.setTargetConcepts(codeMappingToBeApplied.getTargetConcepts());
existingMapping.setMappingStatus(codeMappingToBeApplied.getMappingStatus());
Expand All @@ -82,7 +84,7 @@ public void actionPerformed(ActionEvent arg0) {
}

String message = "The applied mapping contained " + mappingToBeApplied.size() + " mappings of which " + mappingsApplied
+ " were applied to the current mapping and " + mappingsAdded + " were newly added.";
+ " were applied to the current mapping and " + mappingsAdded + " were newly added.\n\n" + summary.createReport();
Global.mappingTablePanel.updateUI();
Global.mappingDetailPanel.updateUI();
Global.mapping.fireDataChanged(APPROVE_EVENT); // To update the footer
Expand All @@ -91,7 +93,48 @@ public void actionPerformed(ActionEvent arg0) {
Global.usagiSearchEngine.createDerivedIndex(Global.mapping.getSourceCodes(), Global.frame);
Global.mappingDetailPanel.doSearch();
}
JOptionPane.showMessageDialog(Global.frame, message);
JOptionPane.showMessageDialog(Global.frame, message, "Summary", JOptionPane.INFORMATION_MESSAGE);
}
}

private static class ApplyPreviousChangeSummary {
private int nChanged = 0;
private int nSourceNameChanged = 0;
private int nTargetConceptsChanged = 0;
private int nMappingStatusChanged = 0;
private int nEquivalenceChanged = 0;

private void compare(CodeMapping A, CodeMapping B) {
boolean hasChanged = false;
if (!A.getSourceCode().sourceName.equals(B.getSourceCode().sourceName)) {
nSourceNameChanged++;
hasChanged = true;
}
if (!A.getTargetConcepts().equals(B.getTargetConcepts())) {
nTargetConceptsChanged++; // This could be target concept, size OR type
hasChanged = true;
}
if (!A.getMappingStatus().equals(B.getMappingStatus())) {
nMappingStatusChanged++;
hasChanged = true;
}
if (!A.getEquivalence().equals(B.getEquivalence())) {
nEquivalenceChanged++;
hasChanged = true;
}
if (hasChanged) {
nChanged++;
}
}

private String createReport() {
StringBuilder report = new StringBuilder();
report.append("Of the applied mappings, " + nChanged + " mappings changed.");
report.append("\n\tSource name: " + nSourceNameChanged);
report.append("\n\tTarget concept: " + nTargetConceptsChanged + "\t(changed target concept, target type AND/OR number of targets)");
report.append("\n\tMapping status: " + nMappingStatusChanged);
report.append("\n\tMapping equivalence: " + nEquivalenceChanged);
return report.toString();
}
}
}