diff --git a/src/org/ohdsi/usagi/TargetConcept.java b/src/org/ohdsi/usagi/TargetConcept.java index 5f77922..2376ac0 100644 --- a/src/org/ohdsi/usagi/TargetConcept.java +++ b/src/org/ohdsi/usagi/TargetConcept.java @@ -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; } diff --git a/src/org/ohdsi/usagi/dataImport/ImportData.java b/src/org/ohdsi/usagi/dataImport/ImportData.java index d05fbcc..e652995 100644 --- a/src/org/ohdsi/usagi/dataImport/ImportData.java +++ b/src/org/ohdsi/usagi/dataImport/ImportData.java @@ -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(additionalInfoColumn, row.get(additionalInfoColumn))); return sourceCode; diff --git a/src/org/ohdsi/usagi/indexBuilding/BuildIndex.java b/src/org/ohdsi/usagi/indexBuilding/BuildIndex.java index a724739..60b927b 100644 --- a/src/org/ohdsi/usagi/indexBuilding/BuildIndex.java +++ b/src/org/ohdsi/usagi/indexBuilding/BuildIndex.java @@ -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; @@ -26,6 +28,7 @@ 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; @@ -33,6 +36,7 @@ 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; @@ -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(); @@ -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(); } @@ -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 allowedVocabularies = new HashSet(); - for (String allowedVocabulary : vocabularyIds) - allowedVocabularies.add(allowedVocabulary); + Set vocabularies = new HashSet(); + Set conceptClassIds = new HashSet(); + Set domainIds = new HashSet(); 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 synonymRows = multiRowSet.get("concept_synonym"); // Adding concept name as synonym: @@ -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 set, String fileName) { + List list = new ArrayList(set); + Collections.sort(list); + WriteTextFile out = new WriteTextFile(fileName); + for (String item : list) + out.writeln(item); + out.close(); + } + private Map loadLoincInfo(String loincFile) { Map loincToInfo = new HashMap(); for (Row row : new ReadCSVFileWithHeader(loincFile)) { @@ -216,20 +234,4 @@ private Map loadLoincInfo(String loincFile) { return loincToInfo; } } - - // private void process() { - // StringUtilities.outputWithTime("Indexing terms"); - // UsagiSearchEngine usagiSearchEngine = new UsagiSearchEngine(folder); - // usagiSearchEngine.createNewMainIndex(); - // CountingSet vocCounts = new CountingSet(); - // 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(); - // } - } diff --git a/src/org/ohdsi/usagi/ui/FilterPanel.java b/src/org/ohdsi/usagi/ui/FilterPanel.java index f521440..71d8dc5 100644 --- a/src/org/ohdsi/usagi/ui/FilterPanel.java +++ b/src/org/ohdsi/usagi/ui/FilterPanel.java @@ -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; @@ -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; @@ -98,12 +101,7 @@ public void actionPerformed(ActionEvent arg0) { c.gridy = 1; c.weightx = 1; c.gridwidth = 1; - filterConceptClassComboBox = new JComboBox(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(loadVectorFromFile(Global.folder + "/ConceptClassIds.txt")); filterConceptClassComboBox.addActionListener(new ActionListener() { @Override @@ -133,8 +131,7 @@ public void actionPerformed(ActionEvent arg0) { c.gridy = 1; c.weightx = 1; c.gridwidth = 1; - filterVocabularyComboBox = new JComboBox(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(loadVectorFromFile(Global.folder + "/VocabularyIds.txt")); filterVocabularyComboBox.addActionListener(new ActionListener() { @Override @@ -164,9 +161,7 @@ public void actionPerformed(ActionEvent arg0) { c.gridy = 2; c.weightx = 1; c.gridwidth = 1; - filterDomainComboBox = new JComboBox(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(loadVectorFromFile(Global.folder + "/DomainIds.txt")); filterDomainComboBox.addActionListener(new ActionListener() { @Override @@ -179,6 +174,16 @@ public void actionPerformed(ActionEvent arg0) { } + private Vector loadVectorFromFile(String fileName) { + if (new File(fileName).exists()) { + Vector vector = new Vector(); + for (String line : new ReadTextFile(fileName)) + vector.add(line); + return vector; + } else + return new Vector(); + } + private void notifyListeners() { for (FilterChangeListener listener : listeners) listener.filterChanged(); @@ -219,5 +224,4 @@ public String getVocabulary() { public String getDomain() { return filterDomainComboBox.getSelectedItem().toString(); } - } diff --git a/src/org/ohdsi/usagi/ui/MappingDetailPanel.java b/src/org/ohdsi/usagi/ui/MappingDetailPanel.java index bbd9b95..6c5f80f 100644 --- a/src/org/ohdsi/usagi/ui/MappingDetailPanel.java +++ b/src/org/ohdsi/usagi/ui/MappingDetailPanel.java @@ -613,7 +613,7 @@ public void setValueAt(Object value, int row, int col) { } } - + @Override public void filterChanged() { doSearch();