]>
Softwares of Agnibho - medscript.git/blob - index.py
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/>.
8 from PyQt6
. QtWidgets
import QWidget
, QMainWindow
, QFormLayout
, QVBoxLayout
, QHBoxLayout
, QPushButton
, QLineEdit
, QTableView
, QAbstractItemView
9 from PyQt6
. QtGui
import QIcon
, QStandardItemModel
, QStandardItem
10 from PyQt6
. QtCore
import pyqtSignal
, QSortFilterProxyModel
12 from zipfile
import ZipFile
13 from config
import config
16 class Index ( QMainWindow
):
18 signal_open
= pyqtSignal ( str )
19 signal_copy
= pyqtSignal ( dict )
21 proxymodel
= QSortFilterProxyModel ()
23 def __init__ ( self
, * args
, ** kwargs
):
24 super () .__ init
__ (* args
, ** kwargs
)
26 self
. setWindowTitle ( "MedScript" )
27 self
. setGeometry ( 200 , 200 , 600 , 400 )
30 layout
= QVBoxLayout ( widget
)
31 self
. table
= QTableView ()
32 self
. table
. setSortingEnabled ( True )
33 self
. table
. setSelectionBehavior ( QAbstractItemView
. SelectionBehavior
. SelectRows
)
34 self
. table
. setSelectionMode ( QAbstractItemView
. SelectionMode
. SingleSelection
)
35 self
. table
. setEditTriggers ( QAbstractItemView
. EditTrigger
. NoEditTriggers
)
37 self
. input_id
= QLineEdit ()
38 self
. input_id
. returnPressed
. connect ( self
. cmd_filter_id
)
39 self
. input_name
= QLineEdit ()
40 self
. input_name
. returnPressed
. connect ( self
. cmd_filter_name
)
41 layout2
. addRow ( "Filter by ID:" , self
. input_id
)
42 layout2
. addRow ( "Filter by Name:" , self
. input_name
)
44 button_open
= QPushButton ( "Open Original" )
45 button_open
. clicked
. connect ( self
. cmd_open
)
46 button_copy
= QPushButton ( "New Prescription" )
47 button_copy
. clicked
. connect ( self
. cmd_copy
)
48 layout3
. addWidget ( button_open
)
49 layout3
. addWidget ( button_copy
)
50 layout
. addLayout ( layout2
)
51 layout
. addLayout ( layout3
)
52 layout
. addWidget ( self
. table
)
54 self
. setCentralWidget ( widget
)
55 self
. setWindowIcon ( QIcon ( os
. path
. join ( "resource" , "icon_medscript.ico" )))
63 def cmd_filter_id ( self
):
64 self
. input_name
. setText ( "" )
65 self
. proxymodel
. setFilterKeyColumn ( 0 )
66 self
. proxymodel
. setFilterFixedString ( self
. input_id
. text ())
68 def cmd_filter_name ( self
):
69 self
. input_id
. setText ( "" )
70 self
. proxymodel
. setFilterKeyColumn ( 1 )
71 self
. proxymodel
. setFilterFixedString ( self
. input_name
. text ())
75 self
. signal_open
. emit ( self
. getSelectedFile ())
77 except Exception as e
:
82 with
ZipFile ( self
. getSelectedFile ()) as zf
:
83 with zf
. open ( "prescription.json" ) as pf
:
84 pres
= json
. loads ( pf
. read ())
85 self
. signal_copy
. emit ( pres
)
87 except Exception as e
:
91 def getSelectedFile ( self
):
92 selection
= self
. table
. selectedIndexes ()
93 file = selection
[- 1 ]. data ()
97 files
= glob ( os
. path
. join ( config
[ "document_directory" ], "**" , "*.mpaz" ), recursive
= True )
99 with
ZipFile ( file ) as zf
:
100 with zf
. open ( "prescription.json" ) as pf
:
101 pres
= json
. loads ( pf
. read ())
102 self
. index
. append ([ pres
[ "id" ], pres
[ "name" ], pres
[ "age" ], pres
[ "sex" ], pres
[ "date" ], file ])
105 model
= QStandardItemModel ()
106 model
. setHorizontalHeaderLabels ([ "ID" , "Name" , "Age" , "Sex" , "Date" , "File" ])
107 for item
in self
. index
:
110 row
. append ( QStandardItem ( i
))
112 self
. proxymodel
. setSourceModel ( model
)
113 self
. table
. setModel ( self
. proxymodel
)
114 self
. table
. resizeColumnsToContents ()