]>
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 from renderbox
import UnrenderBox
15 import logging
, os
, json
17 class Index ( QMainWindow
):
19 signal_open
= pyqtSignal ( str )
20 signal_copy
= pyqtSignal ( dict )
22 proxymodel
= QSortFilterProxyModel ()
24 def __init__ ( self
, * args
, ** kwargs
):
25 super () .__ init
__ (* args
, ** kwargs
)
27 self
. setWindowTitle ( "MedScript" )
28 self
. setGeometry ( 200 , 200 , 600 , 400 )
31 layout
= QVBoxLayout ( widget
)
32 self
. table
= QTableView ()
33 self
. table
. setSortingEnabled ( True )
34 self
. table
. setSelectionBehavior ( QAbstractItemView
. SelectionBehavior
. SelectRows
)
35 self
. table
. setSelectionMode ( QAbstractItemView
. SelectionMode
. SingleSelection
)
36 self
. table
. setEditTriggers ( QAbstractItemView
. EditTrigger
. NoEditTriggers
)
37 self
. table
. doubleClicked
. connect ( self
. cmd_view
)
39 self
. input_pid
= QLineEdit ()
40 self
. input_pid
. returnPressed
. connect ( self
. cmd_filter_pid
)
41 self
. input_id
= QLineEdit ()
42 self
. input_id
. returnPressed
. connect ( self
. cmd_filter_id
)
43 self
. input_name
= QLineEdit ()
44 self
. input_name
. returnPressed
. connect ( self
. cmd_filter_name
)
45 layout2
. addRow ( "Filter by PID:" , self
. input_pid
)
46 layout2
. addRow ( "Filter by ID:" , self
. input_id
)
47 layout2
. addRow ( "Filter by Name:" , self
. input_name
)
49 button_view
= QPushButton ( "View Prescription" )
50 button_view
. clicked
. connect ( self
. cmd_view
)
51 button_open
= QPushButton ( "Open Original" )
52 button_open
. clicked
. connect ( self
. cmd_open
)
53 button_copy
= QPushButton ( "Create Copy" )
54 button_copy
. clicked
. connect ( self
. cmd_copy
)
55 layout3
. addWidget ( button_view
)
56 layout3
. addWidget ( button_open
)
57 layout3
. addWidget ( button_copy
)
58 layout
. addLayout ( layout2
)
59 layout
. addLayout ( layout3
)
60 layout
. addWidget ( self
. table
)
62 self
. unrenderbox
= UnrenderBox ()
64 self
. setCentralWidget ( widget
)
65 self
. setWindowIcon ( QIcon ( os
. path
. join ( "resource" , "icon_medscript.ico" )))
73 def cmd_filter_pid ( self
):
74 self
. input_id
. setText ( "" )
75 self
. input_name
. setText ( "" )
76 self
. proxymodel
. setFilterKeyColumn ( 0 )
77 self
. proxymodel
. setFilterFixedString ( self
. input_pid
. text ())
79 def cmd_filter_id ( self
):
80 self
. input_pid
. setText ( "" )
81 self
. input_name
. setText ( "" )
82 self
. proxymodel
. setFilterKeyColumn ( 1 )
83 self
. proxymodel
. setFilterFixedString ( self
. input_id
. text ())
85 def cmd_filter_name ( self
):
86 self
. input_pid
. setText ( "" )
87 self
. input_id
. setText ( "" )
88 self
. proxymodel
. setFilterKeyColumn ( 2 )
89 self
. proxymodel
. setFilterFixedString ( self
. input_name
. text ())
93 with
ZipFile ( self
. getSelectedFile ()) as zf
:
94 with zf
. open ( "prescription.json" ) as pf
:
95 prescription
= json
. loads ( pf
. read ())
96 self
. unrenderbox
. show ( prescription
). exec ()
97 except Exception as e
:
102 self
. signal_open
. emit ( self
. getSelectedFile ())
104 except Exception as e
:
109 with
ZipFile ( self
. getSelectedFile ()) as zf
:
110 with zf
. open ( "prescription.json" ) as pf
:
111 pres
= json
. loads ( pf
. read ())
112 self
. signal_copy
. emit ( pres
)
114 except Exception as e
:
118 def getSelectedFile ( self
):
119 selection
= self
. table
. selectedIndexes ()
120 file = selection
[- 1 ]. data ()
124 files
= glob ( os
. path
. join ( config
[ "document_directory" ], "**" , "*.mpaz" ), recursive
= True )
128 with
ZipFile ( file ) as zf
:
130 with zf
. open ( "prescription.json" ) as pf
:
131 pres
= json
. loads ( pf
. read ())
132 self
. index
. append ([ pres
[ "pid" ], pres
[ "id" ], pres
[ "name" ], pres
[ "dob" ], pres
[ "age" ], pres
[ "sex" ], pres
[ "date" ], pres
[ "diagnosis" ], file ])
133 except Exception as e
:
135 except Exception as e
:
139 model
= QStandardItemModel ()
140 model
. setHorizontalHeaderLabels ([ "Patient ID" , "Prescription ID" , "Name" , "Date of Birth" , "Age" , "Sex" , "Date" , "Diagnosis" , "File" ])
141 for item
in self
. index
:
144 row
. append ( QStandardItem ( i
))
146 self
. proxymodel
. setSourceModel ( model
)
147 self
. proxymodel
. setFilterCaseSensitivity ( Qt
. CaseSensitivity
. CaseInsensitive
)
148 self
. table
. setModel ( self
. proxymodel
)
149 self
. table
. resizeColumnsToContents ()