]> Softwares of Agnibho - medscript.git/blob - prescription.py
Added display without rendering
[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=None):
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 set_data_from_json(self, data):
28 try:
29 self.name = data["name"]
30 self.qualification = data["qualification"]
31 self.registration = data["registration"]
32 self.address = data["address"]
33 self.contact = data["contact"]
34 self.extra = data["extra"]
35 if("properties" in data):
36 self.properties = data["properties"]
37 else:
38 self.properties = None
39 except Exception as e:
40 logging.warning(e)
41
42 def read_from(self, file):
43 try:
44 with open(file, "r") as f:
45 self.set_data_from_json(json.loads(f.read()))
46 except Exception as e:
47 self.name = ""
48 self.qualification = ""
49 self.registration = ""
50 self.address = ""
51 self.contact = ""
52 self.extra = ""
53 self.properties = ""
54
55 class Prescription:
56
57 file=""
58
59 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=None, prescriber=None):
60 self.set_data(date, name, dob, age, sex, address, contact, extra, mode, daw, diagnosis, note, report, advice, investigation, medication, additional, certificate, custom, properties)
61 if prescriber is None:
62 self.prescriber = Prescriber()
63 else:
64 self.prescriber = prescriber
65
66 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=None):
67 self.date = date
68 self.id = id
69 self.pid = pid
70 self.name = name
71 if(age):
72 self.dob = ""
73 self.age = age
74 else:
75 self.dob = dob
76 self.age = ""
77 self.sex = sex
78 self.address = address
79 self.contact = contact
80 self.extra = extra
81 self.mode = mode
82 self.daw = daw
83 self.diagnosis = diagnosis
84 self.note = note
85 self.report = report
86 self.advice = advice
87 self.investigation = investigation
88 self.medication = medication
89 self.additional = additional
90 self.certificate = certificate
91 self.custom = custom
92 self.properties = properties
93
94 def set_data_from_json(self, data):
95 try:
96 self.prescriber.set_data_from_json(data.get("prescriber"))
97 self.date = data.get("date")
98 self.id = data.get("id")
99 self.id = data.get("pid")
100 self.name = data.get("name")
101 self.dob = data.get("dob")
102 self.age = data.get("age")
103 self.sex = data.get("sex")
104 self.address = data.get("address")
105 self.contact = data.get("contact")
106 self.extra = data.get("extra")
107 self.mode = data.get("mode")
108 self.daw = data.get("daw")
109 self.diagnosis = data.get("diagnosis")
110 self.note = data.get("note")
111 self.report = data.get("report")
112 self.advice = data.get("advice")
113 self.investigation = data.get("investigation")
114 self.medication = data.get("medication")
115 self.additional = data.get("additional")
116 self.certificate = data.get("certificate")
117 self.custom = data.get("custom")
118 if("properties" in data):
119 self.properties = data["properties"]
120 else:
121 self.properties = None
122 except Exception as e:
123 logging.warning(e)
124
125 def get_json(self):
126 return(json.dumps(self, default=lambda o: o.__dict__, indent=4))
127
128 def write_to(self, file):
129 with open(file, "w") as f:
130 try:
131 del self.file
132 except AttributeError as e:
133 pass
134 except Exception as e:
135 logging.warning(e)
136 f.write(self.get_json())
137 self.file=file
138
139 def read_from(self, file):
140 with open(file, "r") as f:
141 self.set_data_from_json(json.loads(f.read()))
142 self.file=file
143
144 def reload_prescriber(self, file=None):
145 self.prescriber=Prescriber(file)