BufferedWriter mrsab = new BufferedWriter(new FileWriter(new File(dir,"MRSAB"),append));
BufferedWriter mrdef = new BufferedWriter(new FileWriter(new File(dir,"MRDEF"),append));
BufferedWriter codes = new BufferedWriter(new FileWriter(new File(dir,"CUI2CODE"),append));
Set<Source> sources = new TreeSet<Source>();
Terminology term = null;
// iterate over all concepts
for(Concept c: concepts){
String cui = getCUI(c.getCode());
String code = c.getCode();
for(Term t: c.getTerms()){
// save term information in MRCON
// C0002871|ENG|P|L0002871|VC|S0352787|ANEMIA|0|
String lat = t.getLanguage() == null?"ENG":t.getLanguage();
String ts = t.isPreferred()?"P":"S";
String lui = getLUI(t.getText());
String stt = t.isPreferred()?"PF":"VO";
String sui = getSUI(t.getText());
String str = t.getText();
String lrl = "0";
// write out
mrcon.write(cui+I+lat+I+ts+I+lui+I+stt+I+sui+I+str+I+lrl+I+"\n");
mrcon.flush();
// save term information in MRSO
// C0002871|L0002871|S0013742|SNOMEDCT|OP|154786001|9|
Source src = t.getSource();
if(src == null && c.getSources().length > 0)
src = c.getSources()[0];
String sab = src != null?src.getName():"";
String tty = t.isPreferred()?"PT":"NP";
//String tty = t.getForm() != null && !compat?t.getForm():"SY";
String scode = (c.getCodes() != null && src != null && c.getCodes().containsKey(src))?""+c.getCodes().get(src):cui;
mrso.write(cui+I+lui+I+sui+I+sab+I+tty+I+scode+I+lrl+I+"\n");
mrso.flush();
}
// save MRDEF information in MRDEF
// C0002871|CSP|subnormal levels or function of erythrocytes, resulting in symptoms of tissue hypoxia.|
for(Definition d: c.getDefinitions()){
Source src = d.getSource();
if(src == null && c.getSources().length > 0)
src = c.getSources()[0];
String sab = src != null?src.getName():"";
String def = d.getDefinition();
mrdef.write(cui+I+sab+I+def+I+"\n");
mrdef.flush();
}
// save MRSTY information
// C0000005|T121|Pharmacologic Substance||
if(compat){
String tui = "T071";
String sty = "Entity";
mrsty.write(cui+I+tui+I+sty+I+"\n");
mrsty.flush();
}else{
for(SemanticType st: c.getSemanticTypes()){
String tui = getTUI(st);
String sty = st.getName();
mrsty.write(cui+I+tui+I+sty+I+"\n");
mrsty.flush();
}
}
// add to sources
Collections.addAll(sources,c.getSources());
// save terminology
if(term == null && c.getTerminology() != null)
term = c.getTerminology();
// keep track of translation
codes.write(cui+"="+code+"\n");
codes.flush();
}
// if possible use sources from terminology, cuase they have more data
if(term != null && term.getSources().length > 0){
Set<Source> tsources = new TreeSet<Source>();
for(Source s: term.getSources()){
if(sources.contains(s)){
tsources.add(s);
}
}
sources = tsources;