25
25
import org .mskcc .oncotree .topbraid .OncoTreeNode ;
26
26
import org .mskcc .oncotree .topbraid .OncoTreeRepository ;
27
27
import org .mskcc .oncotree .utils .VersionUtil ;
28
+ import org .mskcc .oncotree .model .Version ;
28
29
import org .springframework .beans .factory .annotation .Autowired ;
29
30
import org .springframework .scheduling .annotation .EnableScheduling ;
30
31
import org .springframework .scheduling .annotation .Scheduled ;
@@ -41,6 +42,8 @@ public class MSKConceptCache {
41
42
42
43
private final static Logger logger = Logger .getLogger (MSKConceptCache .class );
43
44
private static HashMap <String , MSKConcept > oncoTreeCodesToMSKConcepts = new HashMap <String , MSKConcept >();
45
+ // use this to store and look up previous oncoTree codes
46
+ private static HashMap <String , HashSet <String >> topBraidURIsToOncotreeCodes = new HashMap <String , HashSet <String >>();
44
47
45
48
@ Autowired
46
49
private OncoTreeRepository oncoTreeRepository ;
@@ -67,20 +70,38 @@ public MSKConcept get(String oncoTreeCode) {
67
70
private void resetCache () {
68
71
logger .info ("resetCache() -- clearing Crosswalk MSKConcept cache and refilling" );
69
72
oncoTreeCodesToMSKConcepts .clear ();
70
- List <OncoTreeNode > oncoTreeNodes = oncoTreeRepository .getOncoTree (VersionUtil .getDefaultVersion ());
71
- for (OncoTreeNode node : oncoTreeNodes ) {
72
- getFromCrosswalkAndSave (node .getCode ());
73
- }
73
+ // versions are ordered in ascending order by release date
74
+ for (Version version : VersionUtil .getVersions ()) {
75
+ List <OncoTreeNode > oncoTreeNodes = oncoTreeRepository .getOncoTree (version );
76
+ for (OncoTreeNode node : oncoTreeNodes ) {
77
+ MSKConcept mskConcept = getFromCrosswalkAndSave (node .getCode ());
78
+ // get all codes defined so far for this topbraid uri and save in history
79
+ if (topBraidURIsToOncotreeCodes .containsKey (node .getURI ())) {
80
+ // do not add this code to the history, but add any others
81
+ HashSet <String > allButThisNode = new HashSet <String >(topBraidURIsToOncotreeCodes .get (node .getURI ()));
82
+ allButThisNode .remove (node .getCode ());
83
+ mskConcept .addHistory (allButThisNode );
84
+ } else {
85
+ topBraidURIsToOncotreeCodes .put (node .getURI (), new HashSet <String >());
86
+ }
87
+ // now save this as onoctree code history for this topbraid uri
88
+ topBraidURIsToOncotreeCodes .get (node .getURI ()).add (node .getCode ());
89
+ }
90
+ }
74
91
}
75
92
76
93
private MSKConcept getFromCrosswalkAndSave (String oncoTreeCode ) {
77
- MSKConcept concept = null ;
94
+ // only save if we have not seen before (UMLS/NCI info will not be different)
95
+ if (oncoTreeCodesToMSKConcepts .containsKey (oncoTreeCode )) {
96
+ return oncoTreeCodesToMSKConcepts .get (oncoTreeCode );
97
+ }
98
+ MSKConcept concept = new MSKConcept ();
78
99
try {
79
100
concept = crosswalkRepository .getByOncotreeCode (oncoTreeCode );
80
101
} catch (CrosswalkException e ) {
81
102
// do nothing
82
103
}
83
- // save even if null
104
+ // save even if has no information in it
84
105
oncoTreeCodesToMSKConcepts .put (oncoTreeCode , concept );
85
106
return concept ;
86
107
}
0 commit comments