From: Agnibho Mondal Date: Wed, 11 Oct 2023 20:07:18 +0000 (+0530) Subject: Added data index X-Git-Tag: v0.4~26 X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=f0937d5eed23cdb7497f0a31746514feedd999ac;p=medscript.git Added data index --- diff --git a/index.py b/index.py new file mode 100644 index 0000000..59a284b --- /dev/null +++ b/index.py @@ -0,0 +1,114 @@ +# MedScript +# Copyright (C) 2023 Dr. Agnibho Mondal +# This file is part of MedScript. +# MedScript is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# You should have received a copy of the GNU General Public License along with MedScript. If not, see . + +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 glob import glob +from zipfile import ZipFile +from config import config, config_file, sign_available +import os, json + +class Index(QMainWindow): + + signal_open=pyqtSignal(str) + signal_copy=pyqtSignal(dict) + index=[] + proxymodel=QSortFilterProxyModel() + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.setWindowTitle("MedScript") + self.setGeometry(200, 200, 600, 400) + + widget=QWidget(self) + layout=QVBoxLayout(widget) + self.table=QTableView() + self.table.setSortingEnabled(True) + self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) + self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) + layout2=QFormLayout() + 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 ID:", self.input_id) + layout2.addRow("Filter by Name:", self.input_name) + layout3=QHBoxLayout() + button_open=QPushButton("Open Original") + button_open.clicked.connect(self.cmd_open) + button_copy=QPushButton("New Prescription") + button_copy.clicked.connect(self.cmd_copy) + layout3.addWidget(button_open) + layout3.addWidget(button_copy) + layout.addLayout(layout2) + layout.addLayout(layout3) + layout.addWidget(self.table) + + self.setCentralWidget(widget) + self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico"))) + + self.refresh() + + def refresh(self): + self.build() + self.load() + + def cmd_filter_id(self): + self.input_name.setText("") + self.proxymodel.setFilterKeyColumn(0) + self.proxymodel.setFilterFixedString(self.input_id.text()) + + def cmd_filter_name(self): + self.input_id.setText("") + self.proxymodel.setFilterKeyColumn(1) + self.proxymodel.setFilterFixedString(self.input_name.text()) + + def cmd_open(self): + try: + self.signal_open.emit(self.getSelectedFile()) + self.hide() + except Exception as e: + print(e) + + def cmd_copy(self): + try: + with ZipFile(self.getSelectedFile()) as zf: + with zf.open("prescription.json") as pf: + pres=json.loads(pf.read()) + self.signal_copy.emit(pres) + self.hide() + except Exception as e: + print(e) + + + def getSelectedFile(self): + selection=self.table.selectedIndexes() + file=selection[-1].data() + return file + + 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"], file]) + + def load(self): + model=QStandardItemModel() + model.setHorizontalHeaderLabels(["ID", "Name", "Age", "Sex", "File"]) + for item in self.index: + row=[] + for i in item: + row.append(QStandardItem(i)) + model.appendRow(row) + self.proxymodel.setSourceModel(model) + self.table.setModel(self.proxymodel) + self.table.resizeColumnsToContents() diff --git a/tabular.py b/tabular.py index 81a8682..0dd6aa7 100644 --- a/tabular.py +++ b/tabular.py @@ -8,9 +8,7 @@ from config import config from glob import glob from zipfile import ZipFile -import os -import json -import csv +import os, json, csv class Tabular(): diff --git a/window.py b/window.py index e5f82e7..0b7abad 100644 --- a/window.py +++ b/window.py @@ -21,6 +21,7 @@ from setting import EditConfiguration, EditPrescriber from viewbox import ViewBox from preset import Preset from tabular import Tabular +from index import Index try: from M2Crypto.EVP import EVPError from M2Crypto.BIO import BIOError @@ -61,6 +62,15 @@ class MainWindow(QMainWindow): QMessageBox.warning(self,"Open failed", "Failed to open file.") print(e) + 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.load_interface_from_instance() + def cmd_save(self, save_as=False): self.update_instance() suggest=self.prescription.id if(self.prescription.id) else self.prescription.name @@ -174,7 +184,8 @@ class MainWindow(QMainWindow): QMessageBox.critical(self, "Export failed", "Failed to export the data.") def cmd_index(self): - pass + self.index.refresh() + self.index.show() def cmd_configuration(self): self.edit_configuration.show() @@ -743,6 +754,9 @@ class MainWindow(QMainWindow): self.edit_prescriber=EditPrescriber() self.edit_prescriber.signal_save.connect(self.cmd_prescriber_reload) self.viewbox=ViewBox() + self.index=Index() + self.index.signal_open.connect(self.cmd_open) + self.index.signal_copy.connect(self.cmd_copy) self.new_doc() if(config["filename"]):