-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmapping_context.py
More file actions
56 lines (44 loc) · 1.6 KB
/
mapping_context.py
File metadata and controls
56 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
Created on Oct 29, 2011
@author: jherskovic
'''
from myshelf import shelve
class MappingContextError(Exception): pass
class MappingContext(object):
"""Packages the information needed to map medications to each other and the
UMLS."""
def __init__(self, rxnorm, treatment, drug_problem=None, concept_name_index=None):
self._rxnorm = rxnorm
self._treatment = treatment
self._drug_problem = drug_problem
concept_names = {}
if concept_name_index is not None:
self._concept_names = shelve.open(concept_name_index, flag='r')
return
for c in rxnorm.concepts:
cn = rxnorm.concepts[c]._name.lower()
cn = cn.split('@')[0].strip() # Just use stuff to the left of a @ for a concept name
if cn in concept_names:
concept_names[cn].add(c)
else:
concept_names[cn] = set([c])
# Use a shelf for
self._concept_names = concept_names
@property
def rxnorm(self):
return self._rxnorm
@property
def treatment(self):
return self._treatment
@property
def concept_names(self):
return self._concept_names
@property
def drug_problem(self):
return self._drug_problem
def __repr__(self):
rxcount = len(self._rxnorm.concepts)
tscount = len(self._treatment)
dpcount = len(self._drug_problem._drug_problem_dict) if self._drug_problem is not None else 0
return "<MappingContext RXNORM: %d; treats: %d; drug/problem: %d; 0x%x>" % (
rxcount, tscount, dpcount, id(self),)