Skip to content

Commit

Permalink
Merge pull request #108 from OHDSI/release-1.4.1
Browse files Browse the repository at this point in the history
Release 1.4.1
  • Loading branch information
Maxim Moinat authored Mar 11, 2021
2 parents 7f0fb49 + 2246472 commit 80df517
Show file tree
Hide file tree
Showing 31 changed files with 1,515 additions and 830 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ DomainIds.txt
VocabularyIds.txt
vocabularyVersion.txt

local_files/

### Intellij ###
# Created by https://www.gitignore.io/api/intellij
# Edit at https://www.gitignore.io/?templates=intellij
Expand Down
138 changes: 121 additions & 17 deletions src/org/ohdsi/usagi/CodeMapping.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2019 Observational Health Data Sciences and Informatics
*
* Copyright 2020 Observational Health Data Sciences and Informatics & The Hyve
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -15,28 +15,132 @@
******************************************************************************/
package org.ohdsi.usagi;

import org.ohdsi.usagi.ui.Global;

import java.util.ArrayList;
import java.util.List;

/**
* Data class for holding information on a single source code and its mapping
*
*
* @author MSCHUEMI
*
*/
public class CodeMapping {
public static enum MappingStatus {
APPROVED, UNCHECKED, AUTO_MAPPED, AUTO_MAPPED_TO_1, INVALID_TARGET
};
public enum MappingStatus {
// Includes IGNORED for backwards compatibility
APPROVED, UNCHECKED, AUTO_MAPPED, AUTO_MAPPED_TO_1, INVALID_TARGET, FLAGGED, IGNORED
}

public enum Equivalence {
EQUAL, EQUIVALENT, WIDER, NARROWER, INEXACT, UNMATCHED, UNREVIEWED
}

private SourceCode sourceCode;
private double matchScore;
private MappingStatus mappingStatus;
private Equivalence equivalence;
private List<MappingTarget> targetConcepts = new ArrayList<>(1);
private String comment;
private String statusSetBy;
private long statusSetOn;
private String assignedReviewer;

public CodeMapping(SourceCode sourceCode) {
this.setSourceCode(sourceCode);
}

public void approve(Equivalence equivalence) {
setStatus(MappingStatus.APPROVED);
this.setEquivalence(equivalence);
}

public void flag(Equivalence equivalence) {
setStatus(MappingStatus.FLAGGED);
this.setEquivalence(equivalence);
}

public void setStatus(MappingStatus mappingStatus) {
this.setMappingStatus(mappingStatus);
this.setStatusSetOn(System.currentTimeMillis());
this.setStatusSetBy(Global.author);
}

public void setUnchecked() {
this.setMappingStatus(MappingStatus.UNCHECKED);
this.setEquivalence(Equivalence.UNREVIEWED);
this.setStatusSetOn(0);
this.setStatusSetBy("");
}

public SourceCode getSourceCode() {
return sourceCode;
}

public void setSourceCode(SourceCode sourceCode) {
this.sourceCode = sourceCode;
}

public double getMatchScore() {
return matchScore;
}

public void setMatchScore(double matchScore) {
this.matchScore = matchScore;
}

public MappingStatus getMappingStatus() {
return mappingStatus;
}

public void setMappingStatus(MappingStatus mappingStatus) {
this.mappingStatus = mappingStatus;
}

public Equivalence getEquivalence() {
return equivalence;
}

public void setEquivalence(Equivalence equivalence) {
this.equivalence = equivalence;
}

public List<MappingTarget> getTargetConcepts() {
return targetConcepts;
}

public void setTargetConcepts(List<MappingTarget> targetConcepts) {
this.targetConcepts = targetConcepts;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public String getStatusSetBy() {
return statusSetBy;
}

public void setStatusSetBy(String statusSetBy) {
this.statusSetBy = statusSetBy;
}

public long getStatusSetOn() {
return statusSetOn;
}

public SourceCode sourceCode;
public double matchScore;
public MappingStatus mappingStatus;
public List<Concept> targetConcepts = new ArrayList<Concept>(1);
public String comment;
public void setStatusSetOn(long statusSetOn) {
this.statusSetOn = statusSetOn;
}

public CodeMapping(SourceCode sourceCode) {
this.sourceCode = sourceCode;
}
public String getAssignedReviewer() {
return assignedReviewer;
}

public void setAssignedReviewer(String assignedReviewer) {
this.assignedReviewer = assignedReviewer;
}
}
75 changes: 75 additions & 0 deletions src/org/ohdsi/usagi/MappingTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright 2020 Observational Health Data Sciences and Informatics & The Hyve
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.ohdsi.usagi;

/**
* 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
}

private final Concept concept;
private final String createdBy;
private final long createdTime;
private Type mappingType;

public MappingTarget() {
this.concept = Concept.createEmptyConcept();
this.mappingType = Type.MAPS_TO;
this.createdBy = "";
this.createdTime = 0;
}

public MappingTarget(Concept concept, String createdBy) {
this(concept, Type.MAPS_TO, createdBy);
}

public MappingTarget(Concept concept, Type mappingType, String createdBy) {
this.concept = concept;
this.mappingType = mappingType;
this.createdBy = createdBy;
this.createdTime = System.currentTimeMillis();
}

public MappingTarget(Concept concept, Type mappingType, String createdBy, long createdTime) {
this.concept = concept;
this.mappingType = mappingType;
this.createdBy = createdBy;
this.createdTime = createdTime;
}

public Concept getConcept() {
return concept;
}

public String getCreatedBy() {
return createdBy;
}

public long getCreatedTime() {
return createdTime;
}

public Type getMappingType() {
return mappingType;
}

public void setMappingType(Type mappingType) {
this.mappingType = mappingType;
}
}
57 changes: 36 additions & 21 deletions src/org/ohdsi/usagi/ReadCodeMappingsFromFile.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2019 Observational Health Data Sciences and Informatics
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,12 +18,13 @@
import java.util.Iterator;

import org.ohdsi.usagi.CodeMapping.MappingStatus;
import org.ohdsi.usagi.CodeMapping.Equivalence;
import org.ohdsi.usagi.ui.Global;
import org.ohdsi.utilities.files.ReadCSVFileWithHeader;
import org.ohdsi.utilities.files.Row;

public class ReadCodeMappingsFromFile implements Iterable<CodeMapping> {
private String filename;
private final String filename;

public ReadCodeMappingsFromFile(String filename) {
this.filename = filename;
Expand All @@ -36,9 +37,9 @@ public Iterator<CodeMapping> iterator() {

public class RowIterator implements Iterator<CodeMapping> {

private Iterator<Row> iterator;
private CodeMapping buffer;
private Row row;
private Iterator<Row> iterator;
private CodeMapping buffer;
private Row row;

public RowIterator() {
iterator = new ReadCSVFileWithHeader(filename).iterator();
Expand All @@ -56,22 +57,38 @@ private void readNext() {
buffer = null;
} else {
buffer = new CodeMapping(new SourceCode(row));
buffer.matchScore = row.getDouble("matchScore");
buffer.mappingStatus = MappingStatus.valueOf(row.get("mappingStatus"));
try {
buffer.comment = row.get("comment");
} catch (Exception e) {
buffer.comment = "";
}
while (row != null && new SourceCode(row).sourceCode.equals(buffer.sourceCode.sourceCode)
&& new SourceCode(row).sourceName.equals(buffer.sourceCode.sourceName)) {
buffer.setMatchScore(row.getDouble("matchScore"));
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
buffer.setStatusSetBy(row.get("statusSetBy", ""));
buffer.setStatusSetOn(row.getLong("statusSetOn", "0"));
buffer.setEquivalence(Equivalence.valueOf(row.get("equivalence", "UNREVIEWED")));
buffer.setAssignedReviewer(row.get("assignedReviewer", ""));
buffer.setComment(row.get("comment", ""));

while (row != null
&& new SourceCode(row).sourceCode.equals(buffer.getSourceCode().sourceCode)
&& new SourceCode(row).sourceName.equals(buffer.getSourceCode().sourceName)) {
if (row.getInt("conceptId") != 0) {
Concept concept = Global.dbEngine.getConcept(row.getInt("conceptId"));

if (concept == null) {
buffer.mappingStatus = MappingStatus.INVALID_TARGET;
buffer.comment = "Invalid existing target: " + row.get("conceptId");
buffer.setMappingStatus(MappingStatus.INVALID_TARGET);
buffer.setComment("Invalid existing target: " + row.get("conceptId"));
} else {
buffer.targetConcepts.add(concept);
// 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")
),
row.get("createdBy", ""),
row.getLong("createdOn", "0")
);
buffer.getTargetConcepts().add(mappingTarget);
}
}
if (iterator.hasNext())
Expand All @@ -98,7 +115,5 @@ public CodeMapping next() {
public void remove() {
throw new RuntimeException("Remove not supported");
}

}

}
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/SourceCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SourceCode {
public Set<Integer> sourceAutoAssignedConceptIds = new HashSet<Integer>();
public List<Pair<String, String>> sourceAdditionalInfo = new ArrayList<Pair<String, String>>();

private static String ADDITIONAL_INFO_PREFIX = "ADD_INFO:";
private final static String ADDITIONAL_INFO_PREFIX = "ADD_INFO:";

public Row toRow() {
Row row = new Row();
Expand Down
Loading

0 comments on commit 80df517

Please sign in to comment.