From 4e7d22fcbd6b8c9bdf7ef2422d7f148acdcb23fc Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Wed, 8 Nov 2023 20:55:18 +0530 Subject: [PATCH] Added new fields in index and tabular --- index.py | 34 ++++++++++++++++++++++++++-------- tabular.py | 15 +++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/index.py b/index.py index f855c9c..4e71ca4 100644 --- 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() diff --git a/tabular.py b/tabular.py index 0dd6aa7..b351a9a 100644 --- a/tabular.py +++ b/tabular.py @@ -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) -- 2.39.5