-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf.py
More file actions
98 lines (94 loc) · 2.8 KB
/
pdf.py
File metadata and controls
98 lines (94 loc) · 2.8 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import re
import time
def read_liver_pdf(path, filename):
dirs = "gs -sDEVICE=txtwrite -o "+"output.txt "+os.getcwd()+"/"+filename
p = os.popen(dirs)
time.sleep(2)
txt=""
with open ('output.txt','r') as handle:
txt+= handle.read()
newtxt = repr(txt)
lis = txt.split('\n')
calc = lis[17:31]
age = lis[6]
l = ' '.join(calc)
calcs = re.findall(r'([\d.]+) (?:\*H|\*L)? ', l, re.M)
ages = re.findall(r'([\d.]+) Year.+\/(\w+)', age, re.M)
data = {
'age': ages[0][0],
'gender': 1 if ages[0][1] == "Male" else 0,
'tb': calcs[0],
'db': calcs[1],
'alkphos': calcs[5],
'sgpt': calcs[4],
'sgot': calcs[3],
'tp': calcs[7],
'albumin': calcs[3],
'a/g': calcs[10]
}
ldata = [data['age'],data['gender'],data['tb'],data['db'],data['alkphos'],data['sgpt'],data['sgot'], data['tp'],data['albumin'],data['a/g']]
os.remove('output.txt')
data = {k: float(v) for k, v in data.items()}
return ldata,data
def read_kidney_pdf(path, filename):
dirs = "gs -sDEVICE=txtwrite -o "+"output.txt "+os.getcwd()+"/"+filename
p = os.popen(dirs)
time.sleep(2)
txt=""
with open ('output.txt','r') as handle:
txt+= handle.read()
newtxt = repr(txt)
lis = txt.split('\n')
calc = lis[17:24]
age = lis[6]
l = ' '.join(calc)
calcs = re.findall(r'([\d.]+) (?:\*H|\*L)? ', l, re.M)
ages = re.findall(r'([\d.]+) Year.+\/(\w+)', age, re.M)
data = {
'age': ages[0][0],
'gender': 1 if ages[0][1] == "Male" else 0,
'urea': calcs[0],
'sc': calcs[1],
'uric_acid': calcs[2],
'sodium': calcs[3],
'potassium': calcs[4],
'chloride': calcs[5],
'bicarbonate': calcs[6]
}
os.remove('output.txt')
data = {k: float(v) for k, v in data.items()}
return data
def read_blood_pdf(path, filename):
dirs = "gs -sDEVICE=txtwrite -o "+"output.txt "+os.getcwd()+"/"+filename
p = os.popen(dirs)
time.sleep(2)
txt=""
with open ('output.txt','r') as handle:
txt+= handle.read()
newtxt = repr(txt)
lis = txt.split('\n')
for i,n in enumerate(lis):
print i,n
calc = lis[17:26]
print calc
age = lis[6]
l = ' '.join(calc)
calcs = re.findall(r'([\d.]+) (?:\*H|\*L)? ', l, re.M)
print calcs
ages = re.findall(r'([\d.]+) Year.+\/(\w+)', age, re.M)
data = {
'age': ages[0][0],
'gender': 1 if ages[0][1] == "Male" else 0,
'haemoglobin': calcs[0],
'pcv': calcs[1],
'tlc': calcs[2],
'plates': calcs[3],
'neutrop': calcs[4],
'lymph': calcs[5],
'mono':calcs[6],
'eosion':calcs[7]
}
os.remove('output.txt')
data = {k: float(v) for k, v in data.items()}
return data