]>
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 Qt
, pyqtSignal
, QSortFilterProxyModel
12 from zipfile
import ZipFile
13 from config
import config
14 import logging
, os
, json
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_pid
= QLineEdit ()
38 self
. input_pid
. returnPressed
. connect ( self
. cmd_filter_pid
)
39 self
. input_id
= QLineEdit ()
40 self
. input_id
. returnPressed
. connect ( self
. cmd_filter_id
)
41 self
. input_name
= QLineEdit ()
42 self
. input_name
. returnPressed
. connect ( self
. cmd_filter_name
)
43 layout2
. addRow ( "Filter by PID:" , self
. input_pid
)
44 layout2
. addRow ( "Filter by ID:" , self
. input_id
)
45 layout2
. addRow ( "Filter by Name:" , self
. input_name
)
47 button_open
= QPushButton ( "Open Original" )
48 button_open
. clicked
. connect ( self
. cmd_open
)
49 button_copy
= QPushButton ( "New Prescription" )
50 button_copy
. clicked
. connect ( self
. cmd_copy
)
51 layout3
. addWidget ( button_open
)
52 layout3
. addWidget ( button_copy
)
53 layout
. addLayout ( layout2
)
54 layout
. addLayout ( layout3
)
55 layout
. addWidget ( self
. table
)
57 self
. setCentralWidget ( widget
)
58 self
. setWindowIcon ( QIcon ( os
. path
. join ( "resource" , "icon_medscript.ico" )))
66 def cmd_filter_pid ( self
):
67 self
. input_id
. setText ( "" )
68 self
. input_name
. setText ( "" )
69 self
. proxymodel
. setFilterKeyColumn ( 0 )
70 self
. proxymodel
. setFilterFixedString ( self
. input_pid
. text ())
72 def cmd_filter_id ( self
):
73 self
. input_pid
. setText ( "" )
74 self
. input_name
. setText ( "" )
75 self
. proxymodel
. setFilterKeyColumn ( 1 )
76 self
. proxymodel
. setFilterFixedString ( self
. input_id
. text ())
78 def cmd_filter_name ( self
):
79 self
. input_pid
. setText ( "" )
80 self
. input_id
. setText ( "" )
81 self
. proxymodel
. setFilterKeyColumn ( 2 )
82 self
. proxymodel
. setFilterFixedString ( self
. input_name
. text ())
86 self
. signal_open
. emit ( self
. getSelectedFile ())
88 except Exception as e
:
93 with
ZipFile ( self
. getSelectedFile ()) as zf
:
94 with zf
. open ( "prescription.json" ) as pf
:
95 pres
= json
. loads ( pf
. read ())
96 self
. signal_copy
. emit ( pres
)
98 except Exception as e
:
102 def getSelectedFile ( self
):
103 selection
= self
. table
. selectedIndexes ()
104 file = selection
[- 1 ]. data ()
108 files
= glob ( os
. path
. join ( config
[ "document_directory" ], "**" , "*.mpaz" ), recursive
= True )
111 with
ZipFile ( file ) as zf
:
113 with zf
. open ( "prescription.json" ) as pf
:
114 pres
= json
. loads ( pf
. read ())
115 self
. index
. append ([ pres
[ "pid" ], pres
[ "id" ], pres
[ "name" ], pres
[ "dob" ], pres
[ "age" ], pres
[ "sex" ], pres
[ "date" ], pres
[ "diagnosis" ], file ])
116 except Exception as e
:
118 except Exception as e
:
122 model
= QStandardItemModel ()
123 model
. setHorizontalHeaderLabels ([ "Patient ID" , "Prescription ID" , "Name" , "Date of Birth" , "Age" , "Sex" , "Date" , "Diagnosis" , "File" ])
124 for item
in self
. index
:
127 row
. append ( QStandardItem ( i
))
129 self
. proxymodel
. setSourceModel ( model
)
130 self
. proxymodel
. setFilterCaseSensitivity ( Qt
. CaseSensitivity
. CaseInsensitive
)
131 self
. table
. setModel ( self
. proxymodel
)
132 self
. table
. resizeColumnsToContents ()