]> Softwares of Agnibho - medscript.git/blob - prescription.py
Added shortcuts
[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 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=""):
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
26 def set_data_from_json(self, data):
27 self.name = data["name"]
28 self.qualification = data["qualification"]
29 self.registration = data["registration"]
30 self.address = data["address"]
31 self.contact = data["contact"]
32 self.extra = data["extra"]
33
34 def read_from(self, file):
35 with open(file, "r") as f:
36 self.set_data_from_json(json.loads(f.read()))
37
38 class Prescription:
39
40 file=""
41
42 def __init__(self, date="", id="", name="", age="", sex="", address="", contact="", extra="", mode="", daw="", diagnosis="", note="", report="", advice="", investigation="", medication="", additional="", prescriber=None):
43 self.set_data(date, name, age, sex, address, contact, extra, mode, daw, diagnosis, note, report, advice, investigation, medication, additional)
44 if prescriber is None:
45 self.prescriber = Prescriber()
46 else:
47 self.prescriber = prescriber
48
49 def set_data(self, date="", id="", name="", age="", sex="", address="", contact="", extra="", mode="", daw="", diagnosis="", note="", report="", advice="", investigation="", medication="", additional=""):
50 self.date = date
51 self.id = id
52 self.name = name
53 self.age = age
54 self.sex = sex
55 self.address = address
56 self.contact = contact
57 self.extra = extra
58 self.mode = mode
59 self.daw = daw
60 self.diagnosis = diagnosis
61 self.note = note
62 self.report = report
63 self.advice = advice
64 self.investigation = investigation
65 self.medication = medication
66 self.additional = additional
67
68 def set_data_from_json(self, data):
69 self.prescriber.set_data_from_json(data.get("prescriber"))
70 self.date = data.get("date")
71 self.id = data.get("id")
72 self.name = data.get("name")
73 self.age = data.get("age")
74 self.sex = data.get("sex")
75 self.address = data.get("address")
76 self.contact = data.get("contact")
77 self.extra = data.get("extra")
78 self.mode = data.get("mode")
79 self.daw = data.get("daw")
80 self.diagnosis = data.get("diagnosis")
81 self.note = data.get("note")
82 self.report = data.get("report")
83 self.advice = data.get("advice")
84 self.investigation = data.get("investigation")
85 self.medication = data.get("medication")
86 self.additional = data.get("additional")
87
88 def get_json(self):
89 return(json.dumps(self, default=lambda o: o.__dict__, indent=4))
90
91 def write_to(self, file):
92 with open(file, "w") as f:
93 try:
94 del self.file
95 except Exception as e:
96 print(e)
97 f.write(self.get_json())
98 self.file=file
99
100 def read_from(self, file):
101 with open(file, "r") as f:
102 self.set_data_from_json(json.loads(f.read()))
103 self.file=file
104
105 def reload_prescriber(self, file=None):
106 self.prescriber=Prescriber(file)