def __init__(self, parent=None): super(FindPatientDialog, self).__init__(parent) self.setWindowTitle(_("Patient Finder")) label = QtGui.QLabel(_('Fill in a few of the following fields to get a list of matching patients')) label.setWordWrap(True) label.setAlignment(QtCore.Qt.AlignCenter) self.set_accept_button_text(_("Search Now")) self.sname_le = SoundexLineEdit(self) self.fname_le = SoundexLineEdit(self) self.dob_edit = QtGui.QDateEdit(self) self.dob_edit.setCalendarPopup(True) self.dob_edit.setDate(QtCore.QDate(1900,1,1)) self.address_le = QtGui.QLineEdit(self) self.pcde_le = QtGui.QLineEdit(self) self.telephone_le = QtGui.QLineEdit(self) widget = QtGui.QWidget() form = QtGui.QFormLayout(widget) form.addRow(_("SNO or Surname"), self.sname_le) form.addRow(_("First Name"), self.fname_le) form.addRow(_("Date of Birth"), self.dob_edit) form.addRow(_("Address includes"), self.address_le) form.addRow(_("Post Code"), self.pcde_le) form.addRow(_("Telephone"), self.telephone_le) icon = QtGui.QIcon(":/icons/agt_reload.png") self.repeat_button = QtGui.QPushButton(icon, _("Load Last Search Values"), self) self.insertWidget(label) self.insertWidget(widget) #advanced options self.add_advanced_widget(self.repeat_button) self.enable_soundex_checkbox = QtGui.QCheckBox( _("enable 'sounds like' options")) self.add_advanced_widget(self.enable_soundex_checkbox) self._has_completers = False self._connect_signals() self.search_values = {}
class FindPatientDialog(ExtendableDialog): def __init__(self, parent=None): super(FindPatientDialog, self).__init__(parent) self.setWindowTitle(_("Patient Finder")) label = QtGui.QLabel(_('Fill in a few of the following fields to get a list of matching patients')) label.setWordWrap(True) label.setAlignment(QtCore.Qt.AlignCenter) self.set_accept_button_text(_("Search Now")) self.sname_le = SoundexLineEdit(self) self.fname_le = SoundexLineEdit(self) self.dob_edit = QtGui.QDateEdit(self) self.dob_edit.setCalendarPopup(True) self.dob_edit.setDate(QtCore.QDate(1900,1,1)) self.address_le = QtGui.QLineEdit(self) self.pcde_le = QtGui.QLineEdit(self) self.telephone_le = QtGui.QLineEdit(self) widget = QtGui.QWidget() form = QtGui.QFormLayout(widget) form.addRow(_("SNO or Surname"), self.sname_le) form.addRow(_("First Name"), self.fname_le) form.addRow(_("Date of Birth"), self.dob_edit) form.addRow(_("Address includes"), self.address_le) form.addRow(_("Post Code"), self.pcde_le) form.addRow(_("Telephone"), self.telephone_le) icon = QtGui.QIcon(":/icons/agt_reload.png") self.repeat_button = QtGui.QPushButton(icon, _("Load Last Search Values"), self) self.insertWidget(label) self.insertWidget(widget) #advanced options self.add_advanced_widget(self.repeat_button) self.enable_soundex_checkbox = QtGui.QCheckBox( _("enable 'sounds like' options")) self.add_advanced_widget(self.enable_soundex_checkbox) self._has_completers = False self._connect_signals() self.search_values = {} def sizeHint(self): return QtCore.QSize(350,320) def show_soundex(self, visible): self.sname_le.show_soundex(visible) self.fname_le.show_soundex(visible) def _connect_signals(self): self.sname_le.editingFinished.connect(self.fname_completer) self.sname_le.cursorPositionChanged.connect(self._check) self.fname_le.cursorPositionChanged.connect(self._check) self.address_le.cursorPositionChanged.connect(self._check) self.pcde_le.cursorPositionChanged.connect(self._check) self.telephone_le.cursorPositionChanged.connect(self._check) self.dob_edit.dateChanged.connect(self._check) self.repeat_button.clicked.connect(self.load_last_search) self.enable_soundex_checkbox.toggled.connect(self.show_soundex) def Advise(self, *args): if __name__ == "__main__": print args self.emit(QtCore.SIGNAL("Advise"), *args) def reset_completers(self): ''' called if the connection changes ''' print "reseting completers" self._has_completers = False def populate_completers(self): self.sname_le.setCompleter(SETTINGS.psql_conn.sname_completer()) self._has_completers = True self.connect (QtGui.QApplication.instance(), QtCore.SIGNAL("db_connected"), self.reset_completers) def fname_completer(self): sname = self.sname_le.text() if sname == "": self.fname_le.setCompleter(QtGui.QCompleter()) else: self.fname_le.setCompleter( SETTINGS.psql_conn.fname_completer(sname)) def _check(self, *args): enable = (self.sname_le.text() != "" or self.fname_le.text() != "" or self.dob_edit.date() != QtCore.QDate(1900,1,1) or self.address_le.text() != "" or self.pcde_le.text() != "" or self.telephone_le.text() != "") self.enableApply(enable) self.repeat_button.setVisible(self.search_values != {}) def exec_(self): self.clear() if not self._has_completers: self.populate_completers() return BaseDialog.exec_(self) def clear(self): for le in (self.sname_le, self.fname_le, self.address_le, self.pcde_le, self.telephone_le): le.setText("") self.dob_edit.setDate(QtCore.QDate(1900,1,1)) self.sname_le.setChecked(False) self.fname_le.setChecked(False) self.sname_le.setFocus() self._check() def apply(self): self._analyse() def _emit_result(self, val): self.emit(QtCore.SIGNAL("Load Serial Number"), val) def _analyse(self): self.search_values["dob"] = self.dob_edit.date() self.search_values["addr"] = self.address_le.text() self.search_values["tel"] = self.telephone_le.text() sname = self.sname_le.text() self.search_values["sname"] = sname self.search_values["fname"] = self.fname_le.text() self.search_values["pcde"] = self.pcde_le.text() self.search_values["soundex_sname"] = self.sname_le.isChecked() self.search_values["soundex_fname"] = self.fname_le.isChecked() patient_id, result = sname.toInt() if result and patient_id > 0: self._emit_result(patient_id) else: matches = SETTINGS.psql_conn.get_matchlist(self.search_values) if matches == []: self.Advise(_("no match found"), 1) else: if len(matches) > 1: sno = self.final_choice(matches) if sno != None: self._emit_result(sno) else: self._emit_result(matches[0].patient_id) def final_choice(self, matches): dl = FinalSelectionDialog(matches, self.parent()) return dl.chosen_id def load_last_search(self): self.sname_le.setText(self.search_values.get("sname","")) self.fname_le.setText(self.search_values.get("fname","")) self.dob_edit.setDate(self.search_values.get( "dob", QtCore.QDate(1900,1,1))) self.address_le.setText(self.search_values.get("addr","")) self.pcde_le.setText(self.search_values.get("pcde","")) self.telephone_le.setText(self.search_values.get("tel","")) self.sname_le.setChecked(self.search_values.get("soundex_sname", False)) self.fname_le.setChecked(self.search_values.get("soundex_fname", False))