]> Softwares of Agnibho - medscript.git/commitdiff
Added new fields in index and tabular
authorAgnibho Mondal <mondal@agnibho.com>
Wed, 8 Nov 2023 15:25:18 +0000 (20:55 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Wed, 8 Nov 2023 15:25:18 +0000 (20:55 +0530)
index.py
tabular.py

index f855c9c0152beb7f386a4f70b9defbb3babac666..4e71ca497ec0e9d7034eef536a198b108c246195 100644 (file)
--- a/index.py
+++ b/index.py
@@ -7,7 +7,7 @@
 
 from PyQt6.QtWidgets import QWidget, QMainWindow, QFormLayout, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit, QTableView, QAbstractItemView
 from PyQt6.QtGui import QIcon, QStandardItemModel, QStandardItem
-from PyQt6.QtCore import pyqtSignal, QSortFilterProxyModel
+from PyQt6.QtCore import Qt, pyqtSignal, QSortFilterProxyModel
 from glob import glob
 from zipfile import ZipFile
 from config import config
@@ -34,10 +34,13 @@ class Index(QMainWindow):
         self.table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
         self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
         layout2=QFormLayout()
+        self.input_pid=QLineEdit()
+        self.input_pid.returnPressed.connect(self.cmd_filter_pid)
         self.input_id=QLineEdit()
         self.input_id.returnPressed.connect(self.cmd_filter_id)
         self.input_name=QLineEdit()
         self.input_name.returnPressed.connect(self.cmd_filter_name)
+        layout2.addRow("Filter by PID:", self.input_pid)
         layout2.addRow("Filter by ID:", self.input_id)
         layout2.addRow("Filter by Name:", self.input_name)
         layout3=QHBoxLayout()
@@ -60,14 +63,22 @@ class Index(QMainWindow):
         self.build()
         self.load()
 
-    def cmd_filter_id(self):
+    def cmd_filter_pid(self):
+        self.input_id.setText("")
         self.input_name.setText("")
         self.proxymodel.setFilterKeyColumn(0)
+        self.proxymodel.setFilterFixedString(self.input_pid.text())
+
+    def cmd_filter_id(self):
+        self.input_pid.setText("")
+        self.input_name.setText("")
+        self.proxymodel.setFilterKeyColumn(1)
         self.proxymodel.setFilterFixedString(self.input_id.text())
 
     def cmd_filter_name(self):
+        self.input_pid.setText("")
         self.input_id.setText("")
-        self.proxymodel.setFilterKeyColumn(1)
+        self.proxymodel.setFilterKeyColumn(2)
         self.proxymodel.setFilterFixedString(self.input_name.text())
 
     def cmd_open(self):
@@ -96,19 +107,26 @@ class Index(QMainWindow):
     def build(self):
         files=glob(os.path.join(config["document_directory"], "**", "*.mpaz"), recursive=True)
         for file in files:
-            with ZipFile(file) as zf:
-                with zf.open("prescription.json") as pf:
-                    pres=json.loads(pf.read())
-                    self.index.append([pres["id"], pres["name"], pres["age"], pres["sex"], pres["date"], file])
+            try:
+                with ZipFile(file) as zf:
+                    try:
+                        with zf.open("prescription.json") as pf:
+                            pres=json.loads(pf.read())
+                            self.index.append([pres["pid"], pres["id"], pres["name"], pres["dob"], pres["age"], pres["sex"], pres["date"], pres["diagnosis"], file])
+                    except Exception as e:
+                        logging.warning(e)
+            except Exception as e:
+                logging.warning(e)
 
     def load(self):
         model=QStandardItemModel()
-        model.setHorizontalHeaderLabels(["ID", "Name", "Age", "Sex", "Date", "File"])
+        model.setHorizontalHeaderLabels(["Patient ID", "Prescription ID", "Name", "Date of Birth", "Age", "Sex", "Date", "Diagnosis", "File"])
         for item in self.index:
             row=[]
             for i in item:
                 row.append(QStandardItem(i))
             model.appendRow(row)
         self.proxymodel.setSourceModel(model)
+        self.proxymodel.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
         self.table.setModel(self.proxymodel)
         self.table.resizeColumnsToContents()
index 0dd6aa7e3687516cfbc5459415077cb3e9044b89..b351a9a8ad03216c072dc252add1f63a4a788608 100644 (file)
@@ -8,7 +8,7 @@
 from config import config
 from glob import glob
 from zipfile import ZipFile
-import os, json, csv
+import logging, os, json, csv
 
 class Tabular():
 
@@ -16,9 +16,12 @@ class Tabular():
         files=glob(os.path.join(config["document_directory"], "**", "*.mpaz"), recursive=True)
         with open(filename, "w", newline="") as ss:
             writer=csv.writer(ss, delimiter=config["preset_delimiter"], quoting=csv.QUOTE_MINIMAL)
-            writer.writerow(["id", "date", "name", "age", "sex", "address", "contact", "extra", "mode", "daw", "diagnosis", "note", "report", "advice", "investigation", "medication", "additional", "prescriber"])
+            writer.writerow(["pid", "id", "date", "name", "dob", "age", "sex", "address", "contact", "extra", "mode", "daw", "diagnosis", "note", "report", "advice", "investigation", "medication", "additional", "certificate", "prescriber"])
             for file in files:
-                with ZipFile(file) as zf:
-                    with zf.open("prescription.json") as pf:
-                        pres=json.loads(pf.read())
-                        writer.writerow([pres["id"], pres["date"], pres["name"], pres["age"], pres["sex"], pres["address"], pres["contact"], pres["extra"], pres["mode"], pres["daw"], pres["diagnosis"], pres["note"], pres["report"], pres["advice"], pres["investigation"], pres["medication"], pres["additional"], pres["prescriber"]["name"]])
+                try:
+                    with ZipFile(file) as zf:
+                        with zf.open("prescription.json") as pf:
+                            pres=json.loads(pf.read())
+                            writer.writerow([pres["pid"], pres["id"], pres["date"], pres["name"], pres["dob"], pres["age"], pres["sex"], pres["address"], pres["contact"], pres["extra"], pres["mode"], pres["daw"], pres["diagnosis"], pres["note"], pres["report"], pres["advice"], pres["investigation"], pres["medication"], pres["additional"], pres["certificate"], pres["prescriber"]["name"]])
+                except Exception as e:
+                    logging.warning(e)