forked from smart-on-fhir/sample-patients
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.py
63 lines (49 loc) · 1.93 KB
/
document.py
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
57
58
59
60
61
62
63
from testdata import DOCUMENTS_FILE
import argparse
import csv
class Document:
"""Create instances of Document;
also maintains complete documents lists by patient id"""
documents = {} # Dictionary of documents lists, by patient id
@classmethod
def load(cls):
"""Loads patient documents"""
# Loop through documents and build patient documents lists:
probs = csv.reader(file(DOCUMENTS_FILE,'U'),dialect='excel-tab')
header = probs.next()
for prob in probs:
cls(dict(zip(header,prob))) # Create a clinical note instance
def __init__(self,p):
self.id = p['ID']
self.pid = p['PID']
self.date = p['DATE']
self.title = p['TITLE']
self.mime_type = p['MIME_TYPE']
self.file_name = p['FILE_NAME']
self.type = p['TYPE']
# Append document to the patient's documents list:
if self.pid in self.__class__.documents:
self.__class__.documents[self.pid].append(self)
else: self.__class__.documents[self.pid] = [self]
def asTabString(self):
"""Returns a tab-separated string representation of a document"""
dl = [self.pid, self.date, self.title]
s = ""
for v in dl:
s += "%s\t"%v
return s[0:-1] # Throw away the last tab
if __name__== '__main__':
parser = argparse.ArgumentParser(description='Test Data Documents Module')
group = parser.add_mutually_exclusive_group()
group.add_argument('--documents',
action='store_true', help='list all documents')
group.add_argument('--pid',nargs='?', const='v',
help='display documents for a given patient id (default=2169591)')
args = parser.parse_args()
Document.load()
if args.pid:
if not args.pid in Document.documents:
parser.error("No results found for pid = %s"%args.pid)
probs = Document.documents[args.pid]
for prob in probs:
print prob.asTabString()