]> Softwares of Agnibho - medscript.git/commitdiff
Plugins get prescription as copy
authorAgnibho Mondal <mondal@agnibho.com>
Tue, 14 Nov 2023 12:32:52 +0000 (18:02 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Tue, 14 Nov 2023 12:32:52 +0000 (18:02 +0530)
README
plugin.py
prescription.py

diff --git a/README b/README
index 51b6b744f8e8d2d20be5906db3a74e986728c459..ccc901926fa3fdef052a7c32409a547ba54a063f 100644 (file)
--- 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. <unchanged>
 
 
 Website
index 0238cf8147113e5c1b969d886ff8d3511e3e4e0b..b127b0fe40bf2627ac784c200cf62b11efebb18b 100644 (file)
--- 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()
index e7306906ab9a14a9a6beb116225d8bd464c119a6..4425e63635114d7f574997f100da25a7b7c67d55 100644 (file)
@@ -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))