]> Softwares of Agnibho - medscript.git/blob - prescription.py
Package installer <unchanged> in protected list
[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 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):
39 self.properties = data["properties"]
40 else:
41 self.properties = None
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=None, 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=None):
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.id = 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 = None
125 except Exception as e:
126 logging.exception(e)
127
128 def get_json(self):
129 return(json.dumps(self, default=lambda o: o.__dict__, indent=4))
130
131 def write_to(self, file):
132 with open(file, "w") as f:
133 try:
134 del self.file
135 except AttributeError as e:
136 pass
137 except Exception as e:
138 logging.exception(e)
139 f.write(self.get_json())
140 self.file=file
141
142 def read_from(self, file):
143 with open(file, "r") as f:
144 self.set_data_from_json(json.loads(f.read()))
145 self.file=file
146
147 def reload_prescriber(self, file=None):
148 self.prescriber=Prescriber(file)