Skip to content

Commit

Permalink
Fixing special situation when a table (not MedCit) has fiels called "…
Browse files Browse the repository at this point in the history
…PMID" and "PMID_Version". Addresses #8.
  • Loading branch information
schuemie committed Jan 19, 2018
1 parent ce9e4b3 commit 4a47464
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
19 changes: 18 additions & 1 deletion src/org/ohdsi/medlineXmlToDatabase/MedlineCitationAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,25 @@ private void addKeys() {
}
}
if (!table.equals(MEDLINE_CITATION)) {
table2Fields.get(table).add(table + ORDER_POSTFIX);
Set<String> fields = table2Fields.get(table);
fields.add(table + ORDER_POSTFIX);
field2VariableType.put(concatenate(table, table + ORDER_POSTFIX), new VariableType(true, 3));
if (fields.contains("PMID")) {
// A PMID field is encountered in a table that is not MEDLINE_CITATION. Need to rename to avoid collision with key
fields.add("Other_PMID");
fields.remove("PMID");
VariableType variableType = field2VariableType.get(concatenate(table, "PMID"));
field2VariableType.put(concatenate(table, "Other_PMID"), variableType);
field2VariableType.remove(concatenate(table, "PMID"));
}
if (fields.contains("PMID_Version")) {
// A PMID_Version field is encountered in a table that is not MEDLINE_CITATION. Need to rename to avoid collision with key
fields.add("Other_PMID_Version");
fields.remove("PMID_Version");
VariableType variableType = field2VariableType.get(concatenate(table, "PMID_Version"));
field2VariableType.put(concatenate(table, "Other_PMID_Version"), variableType);
field2VariableType.remove(concatenate(table, "OtPMID_Versionher_PMID"));
}
}
table2Fields.get(table).add("PMID");
field2VariableType.put(concatenate(table, "PMID"), new VariableType(true, 8));
Expand Down
25 changes: 19 additions & 6 deletions src/org/ohdsi/medlineXmlToDatabase/MedlineCitationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
*/
public class MedlineCitationParser {

private OneToManySet<String, String> tables2Fields = new OneToManySet<String, String>();
private static String MEDLINE_CITATION = "MedlineCitation";
private OneToManySet<String, String> tables2Fields = new OneToManySet<String, String>();
private String pmid;
private String pmid_version;
private ConnectionWrapper connectionWrapper;
Expand Down Expand Up @@ -82,10 +83,10 @@ private void deleteAllForPmidAndVersion() {

private void insertIntoDB(String table, Map<String, String> field2Value) {
removeFieldsNotInDb(table, field2Value);
// Map<String, String> unAbbrField2Value = new HashMap<String, String>();
// for (Map.Entry<String, String> entry : field2Value.entrySet())
// unAbbrField2Value.put(Abbreviator.unAbbreviate(entry.getKey()), entry.getValue());
// connectionWrapper.insertIntoTable(table, unAbbrField2Value);
// Map<String, String> unAbbrField2Value = new HashMap<String, String>();
// for (Map.Entry<String, String> entry : field2Value.entrySet())
// unAbbrField2Value.put(Abbreviator.unAbbreviate(entry.getKey()), entry.getValue());
// connectionWrapper.insertIntoTable(table, unAbbrField2Value);
connectionWrapper.insertIntoTable(table, field2Value);
}

Expand Down Expand Up @@ -132,7 +133,7 @@ private void parseNode(Node node, String name, String tableName, HashMap<String,
}

if (XmlTools.isTextNode(node)) {
field2Value.put(name.length() == 0 ? "Value" : name, node.getTextContent());
field2Value.put(name.length() == 0 ? "Value" : name, node.getTextContent());
} else {
// Add children
NodeList children = node.getChildNodes();
Expand All @@ -154,6 +155,18 @@ private void parseNode(Node node, String name, String tableName, HashMap<String,
}
}
if (tableRoot) { // Bottom level completed: write values to database
if (!tableName.equals(MEDLINE_CITATION)) {
if (field2Value.containsKey("PMID")) {
// A PMID field is encountered in a table that is not MEDLINE_CITATION. Need to rename to avoid collision with key
field2Value.put("Other_PMID", field2Value.get("PMID"));
field2Value.remove("PMID");
}
if (field2Value.containsKey("PMID_Version")) {
// A PMID_Version field is encountered in a table that is not MEDLINE_CITATION. Need to rename to avoid collision with key
field2Value.put("Other_PMID_Version", field2Value.get("PMID_Version"));
field2Value.remove("PMID_Version");
}
}
field2Value.putAll(keys);
insertIntoDB(tableName, field2Value);
}
Expand Down

0 comments on commit 4a47464

Please sign in to comment.