]> Softwares of Agnibho - medscript.git/commitdiff
Export to CSV
authorAgnibho Mondal <mondal@agnibho.com>
Wed, 11 Oct 2023 14:41:06 +0000 (20:11 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Wed, 11 Oct 2023 14:41:06 +0000 (20:11 +0530)
tabular.py [new file with mode: 0644]
window.py

diff --git a/tabular.py b/tabular.py
new file mode 100644 (file)
index 0000000..81a8682
--- /dev/null
@@ -0,0 +1,26 @@
+# 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 <https://www.gnu.org/licenses/>.
+
+from config import config
+from glob import glob
+from zipfile import ZipFile
+import os
+import json
+import csv
+
+class Tabular():
+
+    def export(filename):
+        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"])
+            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"]])
index 82eca0312357091d9d42975dc519a2e2701edf77..e5f82e793361536dfc974e7f8fbe4049d5d10b44 100644 (file)
--- a/window.py
+++ b/window.py
@@ -20,6 +20,7 @@ from renderbox import RenderBox
 from setting import EditConfiguration, EditPrescriber
 from viewbox import ViewBox
 from preset import Preset
+from tabular import Tabular
 try:
     from M2Crypto.EVP import EVPError
     from M2Crypto.BIO import BIOError
@@ -150,7 +151,7 @@ class MainWindow(QMainWindow):
         try:
             result=self.current_file.verify()
             if result is False:
-               QMessageBox.critical(self, "Verification failed", "Signature is invalid.")
+                QMessageBox.critical(self, "Verification failed", "Signature is invalid.")
             elif result is None:
                 QMessageBox.warning(self, "No Siganture", "No signature was found.")
             else:
@@ -163,6 +164,18 @@ class MainWindow(QMainWindow):
             print(e)
             QMessageBox.warning(self, "Failed", "Failed to verify.")
 
+    def cmd_tabular(self):
+        try:
+            filename=QFileDialog.getSaveFileName(self, "Export CSV File", os.path.join(config["data_directory"], "data.csv"), "CSV (*.csv);; All Files (*)")[0]
+            Tabular.export(filename)
+            QMessageBox.information(self, "Data Exported", "Data exported to."+filename)
+        except Exception as e:
+            print(e)
+            QMessageBox.critical(self, "Export failed", "Failed to export the data.")
+
+    def cmd_index(self):
+        pass
+
     def cmd_configuration(self):
         self.edit_configuration.show()
 
@@ -463,6 +476,10 @@ class MainWindow(QMainWindow):
         action_prescriber.triggered.connect(self.cmd_prescriber)
         action_switch=QAction("Switch", self)
         action_switch.triggered.connect(self.cmd_switch)
+        action_tabular=QAction("Tabular", self)
+        action_tabular.triggered.connect(self.cmd_tabular)
+        action_index=QAction("Index", self)
+        action_index.triggered.connect(self.cmd_index)
         action_about=QAction("About", self)
         action_about.triggered.connect(self.cmd_about)
         action_help=QAction("Help", self)
@@ -487,6 +504,9 @@ class MainWindow(QMainWindow):
         menu_settings.addAction(action_configuration)
         menu_settings.addAction(action_prescriber)
         menu_settings.addAction(action_switch)
+        menu_data=menubar.addMenu("Data")
+        menu_data.addAction(action_tabular)
+        menu_data.addAction(action_index)
         menu_help=menubar.addMenu("Help")
         menu_help.addAction(action_about)
         menu_help.addAction(action_help)