Exemple #1
0
    def __init__(self, parent):
        QtGui.QFrame.__init__(self, parent, Qt.Popup)
        self.setupUi(self)
        self._parent = parent
        self._model = parent._model
        self._selectionModel = CRBSelectionModel(self._model)
        self.tblService.setModel(self._model)
        self._addNone = True
        self._staticFilter = None
        self._order = ''
        self.id = None
        self._filter = ''
        self.tblService.setSelectionModel(self._selectionModel)

        self.cmbSection.setTable('rbServiceSection')
        self.cmbSection.setFilter(order='id')
        self.cmbType.setTable('rbServiceType')
        self.cmbClass.setTable('rbServiceClass')
        self.table = QtGui.qApp.db.table('rbService')
        self.edtBegDate.canBeEmpty(True)
        self.edtEndDate.canBeEmpty(True)
        self.edtCode.setFocus(Qt.ShortcutFocusReason)
        self.resetEdits()
        self.cmbSection.installEventFilter(self)
        self.cmbType.installEventFilter(self)
        self.cmbClass.installEventFilter(self)
        self.edtCode.installEventFilter(self)
        self.edtName.installEventFilter(self)
        self.edtBegDate.installEventFilter(self)
        self.edtEndDate.installEventFilter(self)
        self.tblServiceSettings()
        self.updateTypesClasses()
        self.chkIsFilterServiceByCurrentCode.setVisible(
            False
        )  # Логика проверки кода изменена, данный чекбокс более не применим. Если не будет отката - удалить совсем после середины 2015 года.
Exemple #2
0
    def __init__(self, parent=None):
        QtGui.QFrame.__init__(self, parent, QtCore.Qt.Popup)
        self.setupUi(self)
        self._parent = parent
        self._model = parent._model
        self._selectionModel = CRBSelectionModel(self._model)
        self.tblMorphology.setModel(self._model)

        self.tableModel = CTableModel(self, [
            CTextCol(u'Код', ['code'], 6),
            CTextCol(u'Наименование', ['name'], 40)
        ], 'MKB_Morphology')
        self.tableSelectionModel = QtGui.QItemSelectionModel(
            self.tableModel, self)
        self.tableSelectionModel.setObjectName('tableSelectionModel')
        self._addNone = True
        self._tableName = 'MKB_Morphology'
        self._filier = ''
        self._order = ''
        self.id = None
        self._searchString = ''
        self.tblMorphology.setSelectionModel(self._selectionModel)
        self.tblSearch.setModel(self.tableModel)
        self.tblSearch.setSelectionModel(self.tableSelectionModel)
        self._model.setTable(self._tableName, self._addNone, self._filier,
                             self._order)
        self.tblMorphology.hideColumn(2)
        self.lastMKBValue = ''
        self.edtSearch.installEventFilter(self)
        self.btnSearch.installEventFilter(self)
        self.tblSearch.installEventFilter(self)
Exemple #3
0
 def __init__(self, parent):
     CQuotaTypeComboBox.__init__(self, parent)
     self._model = CRBModel(self)
     self._searchString = ''
     self._selectionModel = CRBSelectionModel(self._model)
     self.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength)
     self.prefferedWidth = None
     self.popupView = CQuotaTypeComboBoxPopup(self, 'QuotaType')
     self.setModel(self._model)
     self._clientId = None
     self.connect(self.popupView, QtCore.SIGNAL('quotaTypeSelected(int)'),
                  self.setValueByRow)
Exemple #4
0
    def __init__(self, parent, tableName=''):
        QtGui.QFrame.__init__(self, parent, QtCore.Qt.Popup)
        self._mapClassName2Class = {}
        self._clientId = None
        self.clientBegDate = None
        self.clientEegDate = None
        self._addNone = True
        self._tableName = tableName
        self._filier = ''
        self._order = ''
        self.id = None
        self.table = QtGui.qApp.db.table('QuotaType')

        self.setupUi(self)

        self._applyQuotaTypeClassCombobox()
        self._model = parent._model
        self._selectionModel = CRBSelectionModel(self._model)
        self.tblQuotaType.setModel(self._model)
        self.tblQuotaType.setSelectionModel(self._selectionModel)
        self.edtDate.setDate(QtCore.QDate().currentDate())
        self.buttonBox.button(QtGui.QDialogButtonBox.Apply).setShortcut(
            QtCore.Qt.Key_Return)
Exemple #5
0
 def __init__(self,
              parent,
              filterByHospitalBedsProfile=False,
              additionalIdList=None):
     if not additionalIdList:
         additionalIdList = []
     QtGui.QComboBox.__init__(self, parent)
     self._model = CRBServiceComboBoxModel(self,
                                           filterByHospitalBedsProfile,
                                           additionalIdList)
     self._searchString = ''
     self._staticFilter = None
     self._selectionModel = CRBSelectionModel(self._model)
     self.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength)
     self.prefferedWidth = None
     self.popupView = CRBServiceComboBoxPopup(self)
     self.setModel(self._model)
     self.connect(self.popupView, SIGNAL('serviceSelected(int)'),
                  self.setValueByRow)
     self.setModelColumn(0)
Exemple #6
0
 def __init__(self, parent):
     QtGui.QComboBox.__init__(self, parent)
     self._searchString = ''
     self.showFields = CRBComboBox.showName
     self._model = CMealComboBoxModel(self)
     self._selectionModel = CRBSelectionModel(self._model)
     self._tableName = ''
     self._addNone = True
     self._needCache = True
     self._filter = ''
     self._order = ''
     self._specialValues = None
     self.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength)
     self.prefferedWidth = None
     self.popupView = CRBPopupView(self)
     self.setShowFields(self.showFields)
     self.setView(self.popupView)
     self.setModel(self._model)
     self.popupView.setSelectionModel(self._selectionModel)
     self.popupView.setFrameShape(QtGui.QFrame.NoFrame)
     self._isRTF = False
Exemple #7
0
class CRBServiceComboBoxPopup(QtGui.QFrame, Ui_RBServiceComboBoxPopup):
    __pyqtSignals__ = ('serviceSelected(int)', )

    def __init__(self, parent):
        QtGui.QFrame.__init__(self, parent, Qt.Popup)
        self.setupUi(self)
        self._parent = parent
        self._model = parent._model
        self._selectionModel = CRBSelectionModel(self._model)
        self.tblService.setModel(self._model)
        self._addNone = True
        self._staticFilter = None
        self._order = ''
        self.id = None
        self._filter = ''
        self.tblService.setSelectionModel(self._selectionModel)

        self.cmbSection.setTable('rbServiceSection')
        self.cmbSection.setFilter(order='id')
        self.cmbType.setTable('rbServiceType')
        self.cmbClass.setTable('rbServiceClass')
        self.table = QtGui.qApp.db.table('rbService')
        self.edtBegDate.canBeEmpty(True)
        self.edtEndDate.canBeEmpty(True)
        self.edtCode.setFocus(Qt.ShortcutFocusReason)
        self.resetEdits()
        self.cmbSection.installEventFilter(self)
        self.cmbType.installEventFilter(self)
        self.cmbClass.installEventFilter(self)
        self.edtCode.installEventFilter(self)
        self.edtName.installEventFilter(self)
        self.edtBegDate.installEventFilter(self)
        self.edtEndDate.installEventFilter(self)
        self.tblServiceSettings()
        self.updateTypesClasses()
        self.chkIsFilterServiceByCurrentCode.setVisible(
            False
        )  # Логика проверки кода изменена, данный чекбокс более не применим. Если не будет отката - удалить совсем после середины 2015 года.

    def tblServiceSettings(self):
        pass

    def setTableFocus(self):
        self.tblService.setFocus()

    def resetEdits(self):
        self.cmbSection.setValue(0)
        self.cmbType.setValue(0)
        self.cmbClass.setValue(0)
        self.edtCode.setText('')
        self.edtName.setText('')
        self.chkEIS.setCheckState(Qt.PartiallyChecked)
        self.chkNomenclature.setCheckState(Qt.PartiallyChecked)
        self.edtBegDate.setDate(QDate())
        self.edtEndDate.setDate(QDate())

    def hideColumn(self, index):
        self.tblService.hideColumn(index)

    def show(self):
        scrollBar = self.tblService.horizontalScrollBar()
        scrollBar.setValue(0)
        QtGui.QFrame.show(self)

    def rowCount(self, index=None):
        return self._model.rowCount()

    def searchCodeEx(self, searchString):
        return self._model.searchCodeEx(searchString)

    def setCurrentIndex(self, rowIndex):
        index = self._model.index(rowIndex, 0)
        self.tblService.setCurrentIndex(index)

    def currentIndex(self):
        return self.tblService.currentIndex()

    def setSelectionCurrentIndex(self, index, selectionFlags):
        self._selectionModel.setCurrentIndex(index, selectionFlags)

    def model(self):
        return self.tblService.model()

    def setViewFocus(self):
        self.tblService.setFocus()

    def view(self):
        return self.tblService

    def loadData(self, addNone=True, filter='', order=None):
        self._addNone = addNone
        self._filter = filter
        self._order = order
        self._model.loadData(addNone, filter, order)

    def setFilter(self, filter='', order=None):
        self._filter = filter
        self._order = order
        self.loadData(self._addNone, filter, order)

    def reloadData(self):
        self._model.loadData(self._addNone, self._filter, self._order)

    def setModel(self, model):
        self._model = model
        self.tblService.setModel(model)

    def on_buttonBox_apply(self):
        table = self.table
        db = QtGui.qApp.db
        cond = []
        properties = {}
        properties['section'] = forceRef(self.cmbSection.value())
        properties['type'] = forceRef(self.cmbType.value())
        properties['class'] = forceRef(self.cmbClass.value())
        properties['code'] = forceStringEx(self.edtCode.text())
        properties['name'] = forceStringEx(self.edtName.text())
        properties['EIS'] = self.chkEIS.checkState()
        properties['nomenclature'] = self.chkNomenclature.checkState()
        properties['begDate'] = forceDate(self.edtBegDate.date())
        properties['endDate'] = forceDate(self.edtEndDate.date())

        section = properties.get('section', 0)
        if section:
            cond.append("""(select code
                            from rbServiceSection
                            where id = %s)
                            = left(rbService.code, 1)""" % section)

        type = properties.get('type', 0)
        if type:
            cond.append("""(select code
                            from rbServiceType
                            where id = %s)
                            = substr(rbService.code from 2 for 2)""" % type)

        class_ = properties.get('class', 0)
        if class_:
            cond.append("""rbService.code like concat("___.",
            (select code
                            from rbServiceClass
                            where id = %s), "%%")
                            """ % class_)

        code = properties.get('code', '')
        if code:
            cond.append(table['code'].like(addDots(code)))

        name = properties.get('name', '')
        if name:
            cond.append(table['name'].like(addDotsEx(name)))

        flagEIS = properties.get('EIS', Qt.PartiallyChecked)
        if flagEIS != Qt.PartiallyChecked:
            cond.append(table['eisLegacy'].eq( \
                flagEIS != Qt.Unchecked))

        flagNomenclature = properties.get('nomenclature', Qt.PartiallyChecked)
        if flagNomenclature != Qt.PartiallyChecked:
            cond.append(table['nomenclatureLegacy'].eq( \
                flagNomenclature!= Qt.Unchecked))

        begDate = properties.get('begDate', QDate())
        if not begDate.isNull():
            cond.append(table['begDate'].dateGe(begDate))

        endDate = properties.get('endDate', QDate())
        if not endDate.isNull():
            cond.append(table['endDate'].dateLe(endDate))
        f = db.joinAnd(cond)
        self.setFilter(f)
        if self.rowCount():
            self.tabWidget.setCurrentIndex(0)

    def on_buttonBox_reset(self):
        self.resetEdits()
        self.setFilter('')

    def selectItemByIndex(self, index):
        row = index.row()
        self.emit(SIGNAL('serviceSelected(int)'), row)
        self.hide()

    def callWithIdSave(self, func):
        rowIndex = self.currentIndex().row()
        id = self._model.getId(rowIndex)
        func()
        self.id = id
        rowIndex = self._model.searchId(id)
        if rowIndex > -1 and rowIndex < self._model.rowCount():
            self.emit(SIGNAL('serviceSelected(int)'), rowIndex)

    @pyqtSlot(QtGui.QAbstractButton)
    def on_buttonBox_clicked(self, button):
        rowIndex = self.currentIndex().row()
        id = self._model.getId(rowIndex)
        if not self.id:
            self.id = id
        buttonCode = self.buttonBox.standardButton(button)
        if buttonCode == QtGui.QDialogButtonBox.Apply or button == 'enter':
            self.on_buttonBox_apply()
            rowIndex = self._model.searchId(id)
            self.id = id
        elif buttonCode == QtGui.QDialogButtonBox.Reset:
            self.on_buttonBox_reset()
            rowIndex = self._model.searchId(self.id)
        if rowIndex > -1 and rowIndex < self._model.rowCount():
            self.emit(SIGNAL('serviceSelected(int)'), rowIndex)

    @pyqtSlot(QModelIndex)
    def on_tblService_clicked(self, index):
        self.selectItemByIndex(index)

    def updateTypesClasses(self):
        code = self.cmbSection.code()
        if code and code != "0":
            self.edtCode.setText(code)
            self.cmbType.setEnabled(True)
            self.cmbType.setFilter('section="%s"' % code)
            if code in (u'А', u'В'):
                self.cmbClass.setEnabled(True)
                self.cmbClass.setFilter('section="%s"' % code)
            else:
                self.cmbClass.setEnabled(False)
        else:
            self.cmbType.setValue(0)
            self.cmbType.setEnabled(False)
            self.cmbClass.setValue(0)
            self.cmbClass.setEnabled(False)

    @pyqtSlot(int)
    def on_cmbSection_currentIndexChanged(self, val):
        self.updateTypesClasses()

    def eventFilter(self, obj, event):
        if event.type() == QEvent.KeyPress:
            key = event.key()
            if key in [Qt.Key_Return, Qt.Key_Enter, Qt.Key_E, Qt.Key_G]:
                if key == Qt.Key_E:
                    obj.keyPressEvent(event)
                if key in [Qt.Key_Return, Qt.Key_Enter]:
                    return False
                self.keyPressEvent(event)
                return False
            if key == Qt.Key_Tab:
                self.focusNextPrevChild(True)
                return True
        return False

    def keyPressEvent(self, event):
        if event.key() in [Qt.Key_Return, Qt.Key_Enter]:
            if self.tabWidget.currentIndex():
                self.callWithIdSave(self.on_buttonBox_applied)
            else:
                index = self.tblService.selectedIndexes()
                if index:
                    self.selectItemByIndex(index[0])
        if (event.modifiers() == Qt.ControlModifier
                and event.key() == Qt.Key_E):
            self.tabWidget.setCurrentIndex(0)
        if (event.modifiers() == Qt.ControlModifier
                and event.key() == Qt.Key_G):
            self.tabWidget.setCurrentIndex(1)
        QtGui.QFrame.keyPressEvent(self, event)
Exemple #8
0
class CQuotaTypeComboBoxPopup(QtGui.QFrame, Ui_RBQuotaTypeComboBoxPopup):
    __pyqtSignals__ = ('quotaTypeSelected(int)', )
    quotaTypeClassList = None

    def __init__(self, parent, tableName=''):
        QtGui.QFrame.__init__(self, parent, QtCore.Qt.Popup)
        self._mapClassName2Class = {}
        self._clientId = None
        self.clientBegDate = None
        self.clientEegDate = None
        self._addNone = True
        self._tableName = tableName
        self._filier = ''
        self._order = ''
        self.id = None
        self.table = QtGui.qApp.db.table('QuotaType')

        self.setupUi(self)

        self._applyQuotaTypeClassCombobox()
        self._model = parent._model
        self._selectionModel = CRBSelectionModel(self._model)
        self.tblQuotaType.setModel(self._model)
        self.tblQuotaType.setSelectionModel(self._selectionModel)
        self.edtDate.setDate(QtCore.QDate().currentDate())
        self.buttonBox.button(QtGui.QDialogButtonBox.Apply).setShortcut(
            QtCore.Qt.Key_Return)

    def _applyQuotaTypeClassCombobox(self):
        for name, _class in getQuotaTypeClassItemsByExists():
            self._mapClassName2Class[name] = _class
            self.cmbVTMPClass.addItem(name)

    def setBegDate(self, date):
        self.clientBegDate = date

    def setEndDate(self, date):
        self.clientEndDate = date

    def setClientId(self, clientId):
        self._clientId = clientId
        self.setTable(self._tableName)

    def hideColumn(self, index):
        self.tblQuotaType.hideColumn(index)

    def rowCount(self, index):
        return self._model.rowCount()

    def searchCodeEx(self, searchString):
        return self._model.searchCodeEx(self._searchString)

    def setCurrentIndex(self, rowIndex):
        index = self._model.index(rowIndex, 1)
        self.tblQuotaType.setCurrentIndex(index)

    def currentIndex(self):
        return self.tblQuotaType.currentIndex()

    def setSelectionCurrentIndex(self, index, selectionFlags):
        self._selectionModel.setCurrentIndex(index, selectionFlags)

    def model(self):
        return self.tblQuotaType.model()

    def setViewFocus(self):
        self.tblQuotaType.setFocus()

    def view(self):
        return self.tblQuotaType

    def setTable(self, tableName, addNone=True, filter='', order=None):
        self._tableName = tableName
        self._addNone = addNone
        self._filier = filter
        self._order = order
        cond = [self.table['isObsolete'].eq(0)]
        db = QtGui.qApp.db
        if self._clientId:
            condClient = []
            tableClientQuoting = db.table('Client_Quoting')
            tableQuotaType = db.table('QuotaType')
            queryTable = tableClientQuoting.innerJoin(
                tableQuotaType,
                tableQuotaType['id'].eq(tableClientQuoting['quotaType_id']))
            condClient = [tableClientQuoting['deleted'].eq(0)]
            condClient.append(tableClientQuoting['master_id'].eq(
                self._clientId))
            if self.clientEndDate.isValid():
                condClient.append(
                    tableClientQuoting['dateRegistration'].dateLe(
                        self.clientEndDate))
            if self.clientBegDate.isValid():
                condClient.append(
                    db.joinOr([
                        tableClientQuoting['dateEnd'].dateGe(
                            self.clientBegDate),
                        tableClientQuoting['dateEnd'].dateGe(
                            self.clientBegDate),
                        'DATE(' + tableClientQuoting['dateEnd'].name() + ')=' +
                        'DATE(0000-00-00)'
                    ]))
            idList = db.getIdList(queryTable, 'QuotaType.id', condClient)
            idList += self.getChildrenIdList(idList)
            cond.append(self.table['id'].inlist(idList))
        if self.chkVTMPClass.isChecked():
            className = unicode(self.cmbVTMPClass.currentText())
            if className:
                _class = self._mapClassName2Class[className]
                cond.append(self.table['class'].eq(_class))
        if self.chkLimits.isChecked():
            tableQuoting = db.table('Quoting')
            checkedDate = self.edtDate.date()
            c = [tableQuoting['beginDate'].le(checkedDate)]
            c.append(tableQuoting['endDate'].ge(checkedDate))
            idList = db.getIdList(tableQuoting, 'quotaType_id', c)
            idList += self.getChildrenIdList(idList)
            index = self.cmbLimits.currentIndex()
            if index == 0:
                cond.append(self.table['id'].inlist(idList))
            elif index == 1:
                cond.append(self.table['id'].notInlist(idList))
        filter = db.joinAnd(cond)
        self._model.setTable(tableName, addNone, filter, order)

    def getChildrenIdList(self, idList):
        db = QtGui.qApp.db
        resume = []
        for id in idList:
            code = forceString(db.translate(self.table, 'id', id, 'code'))
            cond = [self.table['group_code'].eq(code)]
            resume += db.getIdList(self.table, 'id', cond)
        if resume:
            resume += self.getChildrenIdList(resume)
        return resume

    def setFilter(self, filter='', order=None):
        self._filier = filter
        self._order = order
        self.setTable(self._tableName, self._addNone, filter, order)

    def reloadData(self):
        self._model.setTable(self._tableName, self._addNone, self._filier,
                             self._order)

    def setModel(self, model):
        self._model = model
        self.tblQuotaType.setModel(model)

    def selectItemByIndex(self, index):
        row = index.row()
        self.emit(QtCore.SIGNAL('quotaTypeSelected(int)'), row)
        self.hide()

    def _resize(self):
        parent = self.parent()
        pos = parent.rect().bottomLeft()
        pos2 = parent.rect().topLeft()
        pos = parent.mapToGlobal(pos)
        pos2 = parent.mapToGlobal(pos2)
        size = self.sizeHint()
        hHeaderSize = 0
        for column in [0, 1]:
            hHeaderSize += self.view().columnWidth(column)
        screen = QtGui.QApplication.desktop().availableGeometry(pos)
        width = max(size.width(), parent.width(), hHeaderSize)
        size.setWidth(width)
        pos.setX(
            max(min(pos.x(),
                    screen.right() - size.width()), screen.left()))
        pos.setY(
            max(min(pos.y(),
                    screen.bottom() - size.height()), screen.top()))
        self.move(pos)
        self.resize(size)
        self.view().resizeColumnToContents(0)
        scrollBar = self.view().horizontalScrollBar()
        scrollBar.setValue(0)

    def on_buttonBox_apply(self):
        self.setTable(self._tableName, self._addNone, self._filier,
                      self._order)
        if self._model.rowCount() > 1:
            self.view().resizeColumnToContents(0)
            self.tabWidget.setCurrentIndex(0)

    def on_buttonBox_reset(self):
        self.chkVTMPClass.setChecked(True)
        self.chkLimits.setChecked(True)
        self.edtDate.setDate(QtCore.QDate().currentDate())
        self.cmbVTMPClass.setCurrentIndex(0)
        self.cmbLimits.setCurrentIndex(0)
        self.cmbVTMPClass.setEnabled(True)
        self.cmbLimits.setEnabled(True)
        self.setTable(self._tableName, self._addNone, self._filier,
                      self._order)

    @QtCore.pyqtSlot(QtGui.QAbstractButton)
    def on_buttonBox_clicked(self, button):
        buttonCode = self.buttonBox.standardButton(button)
        if buttonCode == QtGui.QDialogButtonBox.Apply or button == 'enter':
            self.on_buttonBox_apply()
        elif buttonCode == QtGui.QDialogButtonBox.Reset:
            self.on_buttonBox_reset()

    @QtCore.pyqtSlot(QtCore.QModelIndex)
    def on_tblQuotaType_clicked(self, index):
        self.selectItemByIndex(index)