]> Softwares of Agnibho - medscript.git/blob - tabular.py
Multiple preset files
[medscript.git] / tabular.py
1 # MedScript
2 # Copyright (C) 2023 Dr. Agnibho Mondal
3 # This file is part of MedScript.
4 # 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.
5 # 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.
6 # You should have received a copy of the GNU General Public License along with MedScript. If not, see <https://www.gnu.org/licenses/>.
7
8 from config import config
9 from glob import glob
10 from zipfile import ZipFile
11 import os, json, csv
12
13 class Tabular():
14
15 def export(filename):
16 files=glob(os.path.join(config["document_directory"], "**", "*.mpaz"), recursive=True)
17 with open(filename, "w", newline="") as ss:
18 writer=csv.writer(ss, delimiter=config["preset_delimiter"], quoting=csv.QUOTE_MINIMAL)
19 writer.writerow(["id", "date", "name", "age", "sex", "address", "contact", "extra", "mode", "daw", "diagnosis", "note", "report", "advice", "investigation", "medication", "additional", "prescriber"])
20 for file in files:
21 with ZipFile(file) as zf:
22 with zf.open("prescription.json") as pf:
23 pres=json.loads(pf.read())
24 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"]])