Skip to content

Commit

Permalink
Vocabulary IDs, domain IDs and concept class IDs in the UI are now
Browse files Browse the repository at this point in the history
automatically derived from standard concepts in the vocabulary (instead
of being hard-coded).
  • Loading branch information
schuemie committed Jun 22, 2015
1 parent 4f39747 commit 3156b44
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 41 deletions.
5 changes: 4 additions & 1 deletion src/org/ohdsi/usagi/TargetConcept.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public Row toRow() {
row.add("validEndDate", validEndDate);
row.add("invalidReason", invalidReason);
row.add("domains", StringUtilities.join(domains, "/"));
row.add("additionalInformation", additionalInformation);
if (additionalInformation == null)
row.add("additionalInformation", "");
else
row.add("additionalInformation", additionalInformation);
return row;
}

Expand Down
5 changes: 3 additions & 2 deletions src/org/ohdsi/usagi/dataImport/ImportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ private SourceCode convertToSourceCode(Row row, ImportSettings settings) {
if (settings.sourceFrequencyColumn != null)
sourceCode.sourceFrequency = row.getInt(settings.sourceFrequencyColumn);
if (settings.autoConceptIdsColumn != null)
for (String conceptId : row.get(settings.autoConceptIdsColumn).split(";"))
sourceCode.sourceAutoAssignedConceptIds.add(Integer.parseInt(conceptId));
if (!row.get(settings.autoConceptIdsColumn).equals(""))
for (String conceptId : row.get(settings.autoConceptIdsColumn).split(";"))
sourceCode.sourceAutoAssignedConceptIds.add(Integer.parseInt(conceptId));
for (String additionalInfoColumn : settings.additionalInfoColumns)
sourceCode.sourceAdditionalInfo.add(new Pair<String, String>(additionalInfoColumn, row.get(additionalInfoColumn)));
return sourceCode;
Expand Down
50 changes: 26 additions & 24 deletions src/org/ohdsi/usagi/indexBuilding/BuildIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
******************************************************************************/
package org.ohdsi.usagi.indexBuilding;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -26,13 +28,15 @@
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.ohdsi.usagi.TargetConcept;
import org.ohdsi.usagi.UsagiSearchEngine;
import org.ohdsi.usagi.ui.Global;
import org.ohdsi.utilities.files.FileSorter;
import org.ohdsi.utilities.files.MultiRowIterator;
import org.ohdsi.utilities.files.WriteTextFile;
import org.ohdsi.utilities.files.MultiRowIterator.MultiRowSet;
import org.ohdsi.utilities.files.ReadCSVFileWithHeader;
import org.ohdsi.utilities.files.Row;
Expand All @@ -42,9 +46,6 @@
*/
public class BuildIndex {

public static String[] vocabularyIds = new String[] { "ATC", "APC", "CPT4", "DRG", "HCPCS", "HES Specialty", "ICD9Proc", "LOINC", "LOINC Hierarchy",
"MDC", "Multilex", "NUCC", "OPCS4", "Place of Service", "Race", "Revenue Code", "RxNorm", "SNOMED", "Specialty", "UCUM" };

public static void main(String[] args) {
Global.folder = "S:/Data/Usagi/";
BuildIndex buildIndex = new BuildIndex();
Expand Down Expand Up @@ -83,6 +84,8 @@ public void buildIndex(String vocabFolder, String loincFile) {
dialog.setVisible(true);
try {
thread.join();
JOptionPane.showMessageDialog(Global.frame, "Please restart Usagi to use the new index");
System.exit(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -128,16 +131,19 @@ public void run() {
@SuppressWarnings("unchecked")
MultiRowIterator iterator = new MultiRowIterator("CONCEPT_ID", true, new String[] { "concept", "concept_synonym" }, new Iterator[] {
conceptIterator, conceptSynIterator });
Set<String> allowedVocabularies = new HashSet<String>();
for (String allowedVocabulary : vocabularyIds)
allowedVocabularies.add(allowedVocabulary);
Set<String> vocabularies = new HashSet<String>();
Set<String> conceptClassIds = new HashSet<String>();
Set<String> domainIds = new HashSet<String>();
while (iterator.hasNext()) {
MultiRowSet multiRowSet = iterator.next();
if (multiRowSet.get("concept").size() == 0)
System.out.println("No concept found for concept ID " + multiRowSet.linkingId);
Row conceptRow = multiRowSet.get("concept").get(0);
if (conceptRow.getCells().size() > 2) // Extra check to catch badly formatted rows (which are in a vocab we don't care about)
if (conceptRow.get("STANDARD_CONCEPT").equals("S") && allowedVocabularies.contains(conceptRow.get("VOCABULARY_ID"))) {
if (conceptRow.get("STANDARD_CONCEPT").equals("S")) {
vocabularies.add(conceptRow.get("VOCABULARY_ID"));
conceptClassIds.add(conceptRow.get("CONCEPT_CLASS_ID"));
domainIds.add(conceptRow.get("DOMAIN_ID"));
List<Row> synonymRows = multiRowSet.get("concept_synonym");

// Adding concept name as synonym:
Expand Down Expand Up @@ -175,10 +181,22 @@ public void run() {
}
}
usagiSearchEngine.close();
if (dialog != null)
saveSorted(vocabularies, Global.folder + "/VocabularyIds.txt");
saveSorted(conceptClassIds, Global.folder + "/ConceptClassIds.txt");
saveSorted(domainIds, Global.folder + "/DomainIds.txt");
if (dialog != null)
dialog.setVisible(false);
}

private void saveSorted(Set<String> set, String fileName) {
List<String> list = new ArrayList<String>(set);
Collections.sort(list);
WriteTextFile out = new WriteTextFile(fileName);
for (String item : list)
out.writeln(item);
out.close();
}

private Map<String, String> loadLoincInfo(String loincFile) {
Map<String, String> loincToInfo = new HashMap<String, String>();
for (Row row : new ReadCSVFileWithHeader(loincFile)) {
Expand Down Expand Up @@ -216,20 +234,4 @@ private Map<String, String> loadLoincInfo(String loincFile) {
return loincToInfo;
}
}

// private void process() {
// StringUtilities.outputWithTime("Indexing terms");
// UsagiSearchEngine usagiSearchEngine = new UsagiSearchEngine(folder);
// usagiSearchEngine.createNewMainIndex();
// CountingSet<String> vocCounts = new CountingSet<String>();
// for (Row row : new ReadCSVFileWithHeader(termfile)) {
// TargetConcept concept = new TargetConcept(row);
// usagiSearchEngine.addConceptToIndex(concept);
// vocCounts.add(concept.vocabulary);
// }
// usagiSearchEngine.close();
// StringUtilities.outputWithTime("Indexed terms for vocabularies:");
// vocCounts.printCounts();
// }

}
30 changes: 17 additions & 13 deletions src/org/ohdsi/usagi/ui/FilterPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;

import org.ohdsi.utilities.files.ReadTextFile;

public class FilterPanel extends JPanel {

private static final long serialVersionUID = 1378433878412231259L;
Expand All @@ -44,7 +48,6 @@ public FilterPanel() {
setBorder(BorderFactory.createTitledBorder("Filters"));
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
// c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.NORTHWEST;

c.gridx = 0;
Expand Down Expand Up @@ -98,12 +101,7 @@ public void actionPerformed(ActionEvent arg0) {
c.gridy = 1;
c.weightx = 1;
c.gridwidth = 1;
filterConceptClassComboBox = new JComboBox<String>(new String[] { "Admin Concept", "APC", "Attribute", "Body Structure", "Brand Name", "Branded Drug",
"Branded Drug Comp", "Branded Drug Form", "Branded Pack", "Canonical Unit", "Clinical Drug", "Clinical Drug Comp", "Clinical Drug Form",
"Clinical Finding", "Clinical Pack", "Context-dependent", "CPT4", "Dose Form", "DRG", "Event", "HCPCS", "HES Specialty", "Ingredient",
"Location", "LOINC", "LOINC Hierarchy", "MDC", "Model Comp", "Morph Abnormality", "Namespace Concept", "NUCC", "Observable Entity", "Organism",
"Pharma/Biol Product", "Physical Force", "Physical Object", "Place of Service", "Procedure", "Qualifier Value", "Race", "Record Artifact",
"Revenue Code", "Social Context", "Special Concept", "Specialty", "Specimen", "Staging / Scales", "Substance", "Undefined", "Unit", });
filterConceptClassComboBox = new JComboBox<String>(loadVectorFromFile(Global.folder + "/ConceptClassIds.txt"));
filterConceptClassComboBox.addActionListener(new ActionListener() {

@Override
Expand Down Expand Up @@ -133,8 +131,7 @@ public void actionPerformed(ActionEvent arg0) {
c.gridy = 1;
c.weightx = 1;
c.gridwidth = 1;
filterVocabularyComboBox = new JComboBox<String>(new String[] { "APC", "CPT4", "DRG", "HCPCS", "HES Specialty", "ICD9Proc", "LOINC", "LOINC Hierarchy",
"MDC", "Multilex", "NUCC", "OPCS4", "Place of Service", "Race", "Revenue Code", "RxNorm", "SNOMED", "Specialty", "UCUM" });
filterVocabularyComboBox = new JComboBox<String>(loadVectorFromFile(Global.folder + "/VocabularyIds.txt"));
filterVocabularyComboBox.addActionListener(new ActionListener() {

@Override
Expand Down Expand Up @@ -164,9 +161,7 @@ public void actionPerformed(ActionEvent arg0) {
c.gridy = 2;
c.weightx = 1;
c.gridwidth = 1;
filterDomainComboBox = new JComboBox<String>(new String[] { "Condition", "Device", "Drug", "Meas Value", "Meas Value Operator", "Measurement",
"Observation", "Place of Service", "Procedure", "Provider Specialty", "Race", "Relationship", "Revenue Code", "Route", "Spec Anatomic Site",
"Specimen", "Unit" });
filterDomainComboBox = new JComboBox<String>(loadVectorFromFile(Global.folder + "/DomainIds.txt"));
filterDomainComboBox.addActionListener(new ActionListener() {

@Override
Expand All @@ -179,6 +174,16 @@ public void actionPerformed(ActionEvent arg0) {

}

private Vector<String> loadVectorFromFile(String fileName) {
if (new File(fileName).exists()) {
Vector<String> vector = new Vector<String>();
for (String line : new ReadTextFile(fileName))
vector.add(line);
return vector;
} else
return new Vector<String>();
}

private void notifyListeners() {
for (FilterChangeListener listener : listeners)
listener.filterChanged();
Expand Down Expand Up @@ -219,5 +224,4 @@ public String getVocabulary() {
public String getDomain() {
return filterDomainComboBox.getSelectedItem().toString();
}

}
2 changes: 1 addition & 1 deletion src/org/ohdsi/usagi/ui/MappingDetailPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public void setValueAt(Object value, int row, int col) {

}
}

@Override
public void filterChanged() {
doSearch();
Expand Down

0 comments on commit 3156b44

Please sign in to comment.