]> Softwares of Agnibho - medscript.git/commitdiff
Updated index view, copy
authorAgnibho Mondal <mondal@agnibho.com>
Wed, 8 Nov 2023 16:35:01 +0000 (22:05 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Wed, 8 Nov 2023 16:35:01 +0000 (22:05 +0530)
index.py
renderbox.py
window.py

index 4e71ca497ec0e9d7034eef536a198b108c246195..efa80c0ce76554b27172468dbef2d56cf20b4fce 100644 (file)
--- a/index.py
+++ b/index.py
@@ -11,6 +11,7 @@ from PyQt6.QtCore import Qt, pyqtSignal, QSortFilterProxyModel
 from glob import glob
 from zipfile import ZipFile
 from config import config
+from renderbox import UnrenderBox
 import logging, os, json
 
 class Index(QMainWindow):
@@ -33,6 +34,7 @@ class Index(QMainWindow):
         self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
         self.table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
         self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
+        self.table.doubleClicked.connect(self.cmd_view)
         layout2=QFormLayout()
         self.input_pid=QLineEdit()
         self.input_pid.returnPressed.connect(self.cmd_filter_pid)
@@ -44,16 +46,21 @@ class Index(QMainWindow):
         layout2.addRow("Filter by ID:", self.input_id)
         layout2.addRow("Filter by Name:", self.input_name)
         layout3=QHBoxLayout()
+        button_view=QPushButton("View Prescription")
+        button_view.clicked.connect(self.cmd_view)
         button_open=QPushButton("Open Original")
         button_open.clicked.connect(self.cmd_open)
-        button_copy=QPushButton("New Prescription")
+        button_copy=QPushButton("Create Copy")
         button_copy.clicked.connect(self.cmd_copy)
+        layout3.addWidget(button_view)
         layout3.addWidget(button_open)
         layout3.addWidget(button_copy)
         layout.addLayout(layout2)
         layout.addLayout(layout3)
         layout.addWidget(self.table)
 
+        self.unrenderbox=UnrenderBox()
+
         self.setCentralWidget(widget)
         self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico")))
 
@@ -81,6 +88,15 @@ class Index(QMainWindow):
         self.proxymodel.setFilterKeyColumn(2)
         self.proxymodel.setFilterFixedString(self.input_name.text())
 
+    def cmd_view(self):
+        try:
+            with ZipFile(self.getSelectedFile()) as zf:
+                with zf.open("prescription.json") as pf:
+                    prescription=json.loads(pf.read())
+            self.unrenderbox.show(prescription).exec()
+        except Exception as e:
+            logging.warning(e)
+
     def cmd_open(self):
         try:
             self.signal_open.emit(self.getSelectedFile())
index b5c87f8dd0d104e8bfb3796b56166d20257cda27..dfd1a1cbe8f941c99516aa4729d081ae2dea3990 100644 (file)
@@ -94,12 +94,19 @@ class UnrenderBox(QDialog):
         self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico")))
 
     def show(self, prescription):
+        if(type(prescription) is not dict):
+            prescription=prescription.__dict__
+            prescription["prescriber"]=prescription["prescriber"].__dict__
+        self.load(prescription)
+        return(self)
+
+    def load(self, prescription):
         text=""
-        for attr, value in prescription.prescriber.__dict__.items():
+        for attr, value in prescription["prescriber"].items():
             if(attr not in ["properties"] and len(value)>0):
                 text=text+"<strong>"+value.upper()+"</strong><br>"
         text=text+"<hr>"
-        for attr, value in prescription.__dict__.items():
+        for attr, value in prescription.items():
             if(attr not in ["prescriber", "custom", "properties", "file"] and len(str(value))>0):
                 text=text+"<strong>"+attr.upper()+"</strong><br>"
                 text=text+str(value)+"<br>"
index f721eabe3d017df876a7965d1ede1603149029e7..28186ad56ee4d432a04ae38c9c5860a7a2674852 100644 (file)
--- a/window.py
+++ b/window.py
@@ -69,12 +69,11 @@ class MainWindow(QMainWindow):
 
     def cmd_copy(self, data):
         self.cmd_new()
-        self.prescription.name=data["name"]
-        self.prescription.age=data["age"]
-        self.prescription.sex=data["sex"]
-        self.prescription.address=data["address"]
-        self.prescription.contact=data["contact"]
+        self.prescription.set_data_from_json(data)
+        self.prescription.id=""
+        self.prescription.date=None
         self.load_interface_from_instance()
+        self.refresh()
 
     def cmd_save(self, save_as=False):
         self.update_instance()
@@ -115,9 +114,6 @@ class MainWindow(QMainWindow):
         self.cmd_save(save_as=True)
 
     def cmd_refresh(self):
-        self.update_instance()
-        self.plugin.refresh(self.prescription)
-        self.load_interface_from_instance()
         self.refresh()
 
     def cmd_quit(self):
@@ -125,8 +121,7 @@ class MainWindow(QMainWindow):
             sys.exit()
 
     def cmd_unrender(self):
-        self.unrenderbox.show(self.prescription)
-        self.unrenderbox.exec()
+        self.unrenderbox.show(self.prescription).exec()
 
     def cmd_render(self):
         self.refresh()
@@ -464,6 +459,7 @@ class MainWindow(QMainWindow):
 
     def refresh(self):
         self.update_instance()
+        self.plugin.refresh(self.prescription)
         self.load_interface_from_instance()
 
     def add_attachment(self):
@@ -591,6 +587,7 @@ class MainWindow(QMainWindow):
         action_tabular.triggered.connect(self.cmd_tabular)
         action_index=QAction("Show Index", self)
         action_index.triggered.connect(self.cmd_index)
+        action_index.setShortcut("Ctrl+I")
         action_update=QAction("Check Update", self)
         action_update.triggered.connect(self.cmd_update)
         action_about=QAction("About MedScript", self)