from glob import glob
from zipfile import ZipFile
from config import config
+from renderbox import UnrenderBox
import logging, os, json
class Index(QMainWindow):
self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
+ self.table.doubleClicked.connect(self.cmd_view)
layout2=QFormLayout()
self.input_pid=QLineEdit()
self.input_pid.returnPressed.connect(self.cmd_filter_pid)
layout2.addRow("Filter by ID:", self.input_id)
layout2.addRow("Filter by Name:", self.input_name)
layout3=QHBoxLayout()
+ button_view=QPushButton("View Prescription")
+ button_view.clicked.connect(self.cmd_view)
button_open=QPushButton("Open Original")
button_open.clicked.connect(self.cmd_open)
- button_copy=QPushButton("New Prescription")
+ button_copy=QPushButton("Create Copy")
button_copy.clicked.connect(self.cmd_copy)
+ layout3.addWidget(button_view)
layout3.addWidget(button_open)
layout3.addWidget(button_copy)
layout.addLayout(layout2)
layout.addLayout(layout3)
layout.addWidget(self.table)
+ self.unrenderbox=UnrenderBox()
+
self.setCentralWidget(widget)
self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico")))
self.proxymodel.setFilterKeyColumn(2)
self.proxymodel.setFilterFixedString(self.input_name.text())
+ def cmd_view(self):
+ try:
+ with ZipFile(self.getSelectedFile()) as zf:
+ with zf.open("prescription.json") as pf:
+ prescription=json.loads(pf.read())
+ self.unrenderbox.show(prescription).exec()
+ except Exception as e:
+ logging.warning(e)
+
def cmd_open(self):
try:
self.signal_open.emit(self.getSelectedFile())
self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico")))
def show(self, prescription):
+ if(type(prescription) is not dict):
+ prescription=prescription.__dict__
+ prescription["prescriber"]=prescription["prescriber"].__dict__
+ self.load(prescription)
+ return(self)
+
+ def load(self, prescription):
text=""
- for attr, value in prescription.prescriber.__dict__.items():
+ for attr, value in prescription["prescriber"].items():
if(attr not in ["properties"] and len(value)>0):
text=text+"<strong>"+value.upper()+"</strong><br>"
text=text+"<hr>"
- for attr, value in prescription.__dict__.items():
+ for attr, value in prescription.items():
if(attr not in ["prescriber", "custom", "properties", "file"] and len(str(value))>0):
text=text+"<strong>"+attr.upper()+"</strong><br>"
text=text+str(value)+"<br>"
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.prescription.set_data_from_json(data)
+ self.prescription.id=""
+ self.prescription.date=None
self.load_interface_from_instance()
+ self.refresh()
def cmd_save(self, save_as=False):
self.update_instance()
self.cmd_save(save_as=True)
def cmd_refresh(self):
- self.update_instance()
- self.plugin.refresh(self.prescription)
- self.load_interface_from_instance()
self.refresh()
def cmd_quit(self):
sys.exit()
def cmd_unrender(self):
- self.unrenderbox.show(self.prescription)
- self.unrenderbox.exec()
+ self.unrenderbox.show(self.prescription).exec()
def cmd_render(self):
self.refresh()
def refresh(self):
self.update_instance()
+ self.plugin.refresh(self.prescription)
self.load_interface_from_instance()
def add_attachment(self):
action_tabular.triggered.connect(self.cmd_tabular)
action_index=QAction("Show Index", self)
action_index.triggered.connect(self.cmd_index)
+ action_index.setShortcut("Ctrl+I")
action_update=QAction("Check Update", self)
action_update.triggered.connect(self.cmd_update)
action_about=QAction("About MedScript", self)