]> Softwares of Agnibho - medscript.git/blob - prescription.py
Bugfix: Windows uninstall package permission error
[medscript.git] / prescription.py
1 # MedScript
2 # Copyright (C) 2023 Dr. Agnibho Mondal
3 # This file is part of MedScript.
4 # MedScript is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6 # You should have received a copy of the GNU General Public License along with MedScript. If not, see <https://www.gnu.org/licenses/>.
7
8 import logging, json
9 from config import config
10
11 class Prescriber:
12 def __init__(self, file=None):
13 if file is None:
14 self.read_from(config["prescriber"])
15 else:
16 self.read_from(file)
17
18 def set_data(self, name="", qualification="", registration="", address="", contact="", extra="", properties={}):
19 self.name = name
20 self.qualification = qualification
21 self.registration = registration
22 self.address = address
23 self.contact = contact
24 self.extra = extra
25 self.properties = properties
26
27 def get_json(self):
28 return(json.dumps(self, default=lambda o: o.__dict__, indent=4))
29
30 def set_data_from_json(self, data):
31 try:
32 self.name = data["name"]
33 self.qualification = data["qualification"]
34 self.registration = data["registration"]
35 self.address = data["address"]
36 self.contact = data["contact"]
37 self.extra = data["extra"]
38 if("properties" in data and type(properties) is dict):
39 self.properties = data["properties"]
40 else:
41 self.properties = {}
42 except Exception as e:
43 logging.exception(e)
44
45 def read_from(self, file):
46 try:
47 with open(file, "r") as f:
48 self.set_data_from_json(json.loads(f.read()))
49 except Exception as e:
50 self.name = ""
51 self.qualification = ""
52 self.registration = ""
53 self.address = ""
54 self.contact = ""
55 self.extra = ""
56 self.properties = {}
57
58 class Prescription:
59
60 file=""
61
62 def __init__(self, date="", id="", pid="", name="", dob="", age="", sex="", address="", contact="", extra="", mode="", daw="", diagnosis="", note="", report="", advice="", investigation="", medication="", additional="", certificate="", custom=None, properties={}, prescriber=None):
63 self.set_data(date, name, dob, age, sex, address, contact, extra, mode, daw, diagnosis, note, report, advice, investigation, medication, additional, certificate, custom, properties)
64 if prescriber is None:
65 self.prescriber = Prescriber()
66 else:
67 self.prescriber = prescriber
68
69 def set_data(self, date="", id="", pid="", name="", dob="", age="", sex="", address="", contact="", extra="", mode="", daw="", diagnosis="", note="", report="", advice="", investigation="", medication="", additional="", certificate="", custom=None, properties={}):
70 self.date = date
71 self.id = id
72 self.pid = pid
73 self.name = name
74 if(age):
75 self.dob = ""
76 self.age = age
77 else:
78 self.dob = dob
79 self.age = ""
80 self.sex = sex
81 self.address = address
82 self.contact = contact
83 self.extra = extra
84 self.mode = mode
85 self.daw = daw
86 self.diagnosis = diagnosis
87 self.note = note
88 self.report = report
89 self.advice = advice
90 self.investigation = investigation
91 self.medication = medication
92 self.additional = additional
93 self.certificate = certificate
94 self.custom = custom
95 self.properties = properties
96
97 def set_data_from_json(self, data):
98 try:
99 self.prescriber.set_data_from_json(data.get("prescriber"))
100 self.date = data.get("date")
101 self.id = data.get("id")
102 self.pid = data.get("pid")
103 self.name = data.get("name")
104 self.dob = data.get("dob")
105 self.age = data.get("age")
106 self.sex = data.get("sex")
107 self.address = data.get("address")
108 self.contact = data.get("contact")
109 self.extra = data.get("extra")
110 self.mode = data.get("mode")
111 self.daw = data.get("daw")
112 self.diagnosis = data.get("diagnosis")
113 self.note = data.get("note")
114 self.report = data.get("report")
115 self.advice = data.get("advice")
116 self.investigation = data.get("investigation")
117 self.medication = data.get("medication")
118 self.additional = data.get("additional")
119 self.certificate = data.get("certificate")
120 self.custom = data.get("custom")
121 if("properties" in data):
122 self.properties = data["properties"]
123 else:
124 self.properties = {}
125 except Exception as e:
126 logging.exception(e)
127
128 def set_data_from_copy(self, prescription_copy):
129 try:
130 self.date = prescription_copy.date
131 self.id = prescription_copy.id
132 self.pid = prescription_copy.pid
133 self.name = prescription_copy.name
134 self.dob = prescription_copy.dob
135 self.age = prescription_copy.age
136 self.sex = prescription_copy.sex
137 self.address = prescription_copy.address
138 self.contact = prescription_copy.contact
139 self.extra = prescription_copy.extra
140 self.mode = prescription_copy.mode
141 self.daw = prescription_copy.daw
142 self.diagnosis = prescription_copy.diagnosis
143 self.note = prescription_copy.note
144 self.report = prescription_copy.report
145 self.advice = prescription_copy.advice
146 self.investigation = prescription_copy.investigation
147 self.medication = prescription_copy.medication
148 self.additional = prescription_copy.additional
149 self.certificate = prescription_copy.certificate
150 self.custom = prescription_copy.custom
151 if(type(prescription_copy.properties) is dict):
152 self.properties = prescription_copy.properties
153 else:
154 self.properties = {}
155 self.prescriber = prescription_copy.prescriber
156 except Exception as e:
157 logging.exception(e)
158
159
160 def get_json(self):
161 return(json.dumps(self, default=lambda o: o.__dict__, indent=4))
162
163 def write_to(self, file):
164 with open(file, "w") as f:
165 try:
166 del self.file
167 except AttributeError as e:
168 pass
169 except Exception as e:
170 logging.exception(e)
171 f.write(self.get_json())
172 self.file=file
173
174 def read_from(self, file):
175 with open(file, "r") as f:
176 self.set_data_from_json(json.loads(f.read()))
177 self.file=file
178
179 def reload_prescriber(self, file=None):
180 self.prescriber=Prescriber(file)