From 1dfbb63f4f726a26bc7ae7ee8511ea1f6f3c8314 Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Fri, 10 Nov 2023 00:53:12 +0530 Subject: [PATCH] Option to replace when original/current prescribers differ --- prescription.py | 3 +++ window.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/prescription.py b/prescription.py index 893a303..e730690 100644 --- a/prescription.py +++ b/prescription.py @@ -24,6 +24,9 @@ class Prescriber: self.extra = extra self.properties = properties + def get_json(self): + return(json.dumps(self, default=lambda o: o.__dict__, indent=4)) + def set_data_from_json(self, data): try: self.name = data["name"] diff --git a/window.py b/window.py index c281b5e..56e8b49 100644 --- a/window.py +++ b/window.py @@ -5,7 +5,7 @@ # 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 . -import logging, os, sys, datetime, dateutil.parser, shutil, json, threading +import logging, os, sys, datetime, dateutil.parser, shutil, json, copy, threading from PyQt6.QtCore import Qt, QDateTime, QDate, QSize, pyqtSignal from PyQt6.QtWidgets import QWidget, QMainWindow, QMessageBox, QLabel, QPushButton, QLineEdit, QTextEdit, QDateTimeEdit, QDateEdit, QCalendarWidget, QListWidget, QComboBox, QCheckBox, QRadioButton, QButtonGroup, QVBoxLayout, QHBoxLayout, QFormLayout, QToolBar, QTabWidget, QStatusBar, QFileDialog, QInputDialog, QCompleter, QSizePolicy from PyQt6.QtGui import QAction, QIcon @@ -97,6 +97,9 @@ class MainWindow(QMainWindow): self.current_file.set_file(filename) for i in range(self.input_attachment.count()): self.current_file.copy(self.input_attachment.item(i).text()) + if(self.prescription.prescriber.get_json()!=self.prescriber.get_json()): + if(QMessageBox.StandardButton.Yes==QMessageBox.question(self,"Change Prescriber", "Original Prescriber: "+self.prescription.prescriber.name+"\nCurrent Prescriber: "+self.prescriber.name+"\nReplace original with current?")): + self.prescription.prescriber=copy.deepcopy(self.prescriber) self.prescription.write_to(os.path.join(self.current_file.directory.name, "prescription.json")) if change_template: config["template"]=os.path.join(config["template_directory"], template) -- 2.39.5