This repository has been archived by the owner on May 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatient.py
95 lines (84 loc) · 3.5 KB
/
Patient.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
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
import os
class Patient:
def __init__(self, SSN: str):
self.file_write = open(SSN + '.txt', 'at')
self.file_read = open(SSN + '.txt')
self.ssn = SSN
self.attributesAndValues = [line for line in self.file_read.read().split(',^')]
self.attributedValues = [line.split(':;') for line in self.attributesAndValues]
print(self.attributedValues)
try:
self.attributeIndex = [i[0] for i in self.attributedValues]
self.valuesIndex = [i[1] for i in self.attributedValues]
except IndexError:
self.attributeIndex = []
self.valuesIndex = []
self.assert_attribute('SSN', SSN)
self.assert_attribute('First Name')
self.assert_attribute('Last Name')
self.assert_attribute('Medical History')
self.assert_attribute('Birth Date')
self.assert_attribute('Current Medicines')
self.assert_attribute('Schedule')
def change_attribute(self, attribute: str, value: str):
if attribute not in self.attributeIndex:
self.attributeIndex.append(attribute)
self.valuesIndex.append(value)
self.file_write.write(',^' + str(attribute) + ':;' + str(value))
else:
file_data = self.file_read.read()
old_attval = attribute + ':;' + self.valuesIndex[self.attributeIndex.index(attribute)]
new_attval = attribute + ':;' + value
self.valuesIndex[self.attributeIndex.index(attribute)] = value
file_data = file_data.replace(old_attval, new_attval)
self.file_write = open(self.ssn + '.txt', 'wt')
self.file_write.write(file_data)
self.file_read = open(self.ssn + '.txt')
def assert_attribute(self, attribute: str, default: str=' '):
if self.get_attribute(attribute) is None:
self.change_attribute(attribute, default)
self.file_read = open(self.ssn + '.txt')
def delete(self):
os.remove(self.ssn + '.txt')
del self
def remove_attribute(self, attribute: str):
file_data = self.file_read.read()
old_val = self.valuesIndex[self.attributeIndex.index(attribute)]
old_attval = attribute + ':;' + old_val
file_data = file_data.replace(',^' + old_attval, '')
self.file_write = open(self.ssn + '.txt')
self.file_write.write(file_data)
self.__init__(self.ssn)
def get_attribute(self, attribute: str):
if attribute in self.attributeIndex:
return self.valuesIndex[self.attributeIndex.index(attribute)]
else:
return None
@property
def name(self):
fn = self.get_attribute('First Name')
mn = self.get_attribute('Middle Name')
ln = self.get_attribute('Last Name')
if mn is not None:
if fn is not None:
if ln is not None:
return fn + ' ' + mn + ' ' + ln
else:
return fn + ' ' + mn
else:
if ln is not None:
return mn + ' ' + ln
else:
return mn
else:
if fn is not None:
if ln is not None:
return fn + ' ' + ln
else:
return fn
else:
if ln is not None:
return ln
else:
return ''
pass