From: Agnibho Mondal Date: Tue, 14 Nov 2023 12:32:52 +0000 (+0530) Subject: Plugins get prescription as copy X-Git-Tag: v0.5~3 X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=3400feed98bfda7725bf0814223da73c707e312c;p=medscript.git Plugins get prescription as copy --- diff --git a/README b/README index 51b6b74..ccc9019 100644 --- a/README +++ b/README @@ -324,7 +324,7 @@ structure of the Prescription object is as follows: |-- additional (string: any additional advice/instructions) |-- certificate (string: content of a medical certificate) |-- custom (list: contents of custom input forms) - |-- properties (object: unused, included for future/plugin use) + |-- properties (dictionary: plugin data, each plugin in separate key) |-- prescriber (Prescriber object) | |-- name (string: the name of the prescriber) | |-- qualification (string: the qualification of the prescriber) @@ -332,7 +332,10 @@ structure of the Prescription object is as follows: | |-- address (string: the address of the prescriber) | |-- contact (string: contact number / email of the prescriber) | |-- extra (string: any extra data about the prescriber) - | |-- properties (object: unused, included for future/plugin use) + | |-- properties (dictionary: plugin data, each plugin in separate key) + +Best practice for assigning plugin data to properties is to use a separate +key for each plugin and store the data as the value associated with that key. Plugin ------ @@ -529,6 +532,7 @@ The following names are not allowed as component names: 7. certificate 8. default 9. medcert +10. Website diff --git a/plugin.py b/plugin.py index 0238cf8..b127b0f 100644 --- a/plugin.py +++ b/plugin.py @@ -58,7 +58,9 @@ class Plugin(QObject): if(hasattr(i, "new") and callable(i.new)): if(hasattr(i, "input") and callable(i.input)): i.input(self.input()) - message=i.new(prescription) + prescription_copy=copy.deepcopy(prescription) + message=i.new(prescription_copy) + prescription.set_data_from_copy(prescription_copy) if(message): self.showMessage(message) except Exception as e: @@ -70,7 +72,9 @@ class Plugin(QObject): if(hasattr(i, "open") and callable(i.open)): if(hasattr(i, "input") and callable(i.input)): i.input(self.input()) - message=i.open(prescription) + prescription_copy=copy.deepcopy(prescription) + message=i.open(prescription_copy) + prescription.set_data_from_copy(prescription_copy) if(message): self.showMessage(message) except Exception as e: @@ -82,7 +86,9 @@ class Plugin(QObject): if(hasattr(i, "save") and callable(i.save)): if(hasattr(i, "input") and callable(i.input)): i.input(self.input()) - message=i.save(prescription) + prescription_copy=copy.deepcopy(prescription) + message=i.save(prescription_copy) + prescription.set_data_from_copy(prescription_copy) if(message): self.showMessage(message) except Exception as e: @@ -94,7 +100,9 @@ class Plugin(QObject): if(hasattr(i, "refresh") and callable(i.refresh)): if(hasattr(i, "input") and callable(i.input)): i.input(self.input()) - message=i.refresh(prescription) + prescription_copy=copy.deepcopy(prescription) + message=i.refresh(prescription_copy) + prescription.set_data_from_copy(prescription_copy) if(message): self.showMessage(message) except Exception as e: @@ -105,7 +113,9 @@ class Plugin(QObject): if(hasattr(module, "web") and callable(module.web)): self.webapp=WebApp() self.webapp.done.connect(lambda: self.update.emit()) - url, data=module.web(prescription) + prescription_copy=copy.deepcopy(prescription) + url, data=module.web(prescription_copy) + prescription.set_data_from_copy(prescription_copy) self.webapp.load(module, QUrl(url), prescription, data) self.webapp.show() elif(hasattr(module, "run") and callable(module.run)): @@ -126,7 +136,9 @@ class Plugin(QObject): self.workers[index].pluginComplete.connect(self.showMessage) self.workers[index].start() else: - message=module.run(prescription) + prescription_copy=copy.deepcopy(prescription) + message=module.run(prescription_copy) + prescription.set_data_from_copy(prescription_copy) if(message): self.showMessage(message) except Exception as e: @@ -183,7 +195,9 @@ class JS(QObject): @pyqtSlot(str) def run(self, result): try: - message=self.module.run(self.prescription, result) + prescription_copy=copy.deepcopy(self.prescription) + message=self.module.run(prescription_copy, result) + self.prescription.set_data_from_copy(prescription_copy) if(message): QMessageBox.information(None, "Information", message) self.done.emit() diff --git a/prescription.py b/prescription.py index e730690..4425e63 100644 --- a/prescription.py +++ b/prescription.py @@ -15,7 +15,7 @@ class Prescriber: else: self.read_from(file) - def set_data(self, name="", qualification="", registration="", address="", contact="", extra="", properties=None): + def set_data(self, name="", qualification="", registration="", address="", contact="", extra="", properties={}): self.name = name self.qualification = qualification self.registration = registration @@ -35,10 +35,10 @@ class Prescriber: self.address = data["address"] self.contact = data["contact"] self.extra = data["extra"] - if("properties" in data): + if("properties" in data and type(properties) is dict): self.properties = data["properties"] else: - self.properties = None + self.properties = {} except Exception as e: logging.exception(e) @@ -53,20 +53,20 @@ class Prescriber: self.address = "" self.contact = "" self.extra = "" - self.properties = "" + self.properties = {} class Prescription: file="" - 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): + 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): self.set_data(date, name, dob, age, sex, address, contact, extra, mode, daw, diagnosis, note, report, advice, investigation, medication, additional, certificate, custom, properties) if prescriber is None: self.prescriber = Prescriber() else: self.prescriber = prescriber - 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): + 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={}): self.date = date self.id = id self.pid = pid @@ -99,7 +99,7 @@ class Prescription: self.prescriber.set_data_from_json(data.get("prescriber")) self.date = data.get("date") self.id = data.get("id") - self.id = data.get("pid") + self.pid = data.get("pid") self.name = data.get("name") self.dob = data.get("dob") self.age = data.get("age") @@ -121,10 +121,42 @@ class Prescription: if("properties" in data): self.properties = data["properties"] else: - self.properties = None + self.properties = {} except Exception as e: logging.exception(e) + def set_data_from_copy(self, prescription_copy): + try: + self.date = prescription_copy.date + self.id = prescription_copy.id + self.pid = prescription_copy.pid + self.name = prescription_copy.name + self.dob = prescription_copy.dob + self.age = prescription_copy.age + self.sex = prescription_copy.sex + self.address = prescription_copy.address + self.contact = prescription_copy.contact + self.extra = prescription_copy.extra + self.mode = prescription_copy.mode + self.daw = prescription_copy.daw + self.diagnosis = prescription_copy.diagnosis + self.note = prescription_copy.note + self.report = prescription_copy.report + self.advice = prescription_copy.advice + self.investigation = prescription_copy.investigation + self.medication = prescription_copy.medication + self.additional = prescription_copy.additional + self.certificate = prescription_copy.certificate + self.custom = prescription_copy.custom + if(type(prescription_copy.properties) is dict): + self.properties = prescription_copy.properties + else: + self.properties = {} + self.prescriber = prescription_copy.prescriber + except Exception as e: + logging.exception(e) + + def get_json(self): return(json.dumps(self, default=lambda o: o.__dict__, indent=4))