]> Softwares of Agnibho - medscript.git/blob - tabular.py
Export to CSV
[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
12 import json
13 import csv
14
15 class Tabular():
16
17 def export(filename):
18 files=glob(os.path.join(config["document_directory"], "**", "*.mpaz"), recursive=True)
19 with open(filename, "w", newline="") as ss:
20 writer=csv.writer(ss, delimiter=config["preset_delimiter"], quoting=csv.QUOTE_MINIMAL)
21 writer.writerow(["id", "date", "name", "age", "sex", "address", "contact", "extra", "mode", "daw", "diagnosis", "note", "report", "advice", "investigation", "medication", "additional", "prescriber"])
22 for file in files:
23 with ZipFile(file) as zf:
24 with zf.open("prescription.json") as pf:
25 pres=json.loads(pf.read())
26 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"]])