Skip to content

Instantly share code, notes, and snippets.

@kaicode
Created July 16, 2020 19:39
Show Gist options
  • Save kaicode/52e584f503041da0da0d1c850caea807 to your computer and use it in GitHub Desktop.
Save kaicode/52e584f503041da0da0d1c850caea807 to your computer and use it in GitHub Desktop.
Join active snomed concept FSNs to a TSV list of codes.
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.io.*;
import java.util.Map;
public class Temp {
public static void main(String[] args) throws IOException {
run();
}
private static void run() throws IOException {
Map<Long, String> conceptFsn = new Long2ObjectOpenHashMap<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("SnomedCT_USEditionRF2_PRODUCTION_20200301T120000Z/Snapshot/Terminology/sct2_Description_Snapshot-en_US1000124_20200301.txt")))) {
String line;
while ((line = reader.readLine()) != null) {
// id effectiveTime active moduleId conceptId languageCode typeId term caseSignificanceId
// 0 1 2 3 4 5 6 7 8
String[] split = line.split("\t");
if (split[2].equals("1") && split[6].equals("900000000000003001")) {
conceptFsn.put(Long.parseLong(split[4]), split[7]);
}
}
}
System.out.println(conceptFsn.size() + " terms read");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("frequencies-of-sct-codes.tsv")));
BufferedWriter writer = new BufferedWriter(new FileWriter("out.txt"))) {
String line;
writer.write(reader.readLine());
writer.newLine();
while ((line = reader.readLine()) != null) {
// concept_code group
// 0 1
String[] split = line.split("\t");
Long conceptId = Long.parseLong(split[0]);
String term = conceptFsn.get(conceptId);
if (term == null) {
term = "";
}
writer.write(String.join("\t", split[0], term, split[1]));
writer.newLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment