예제 #1
0
def setProbeResultToActionProperties(tissueJournalId, testId, result):
    db = QtGui.qApp.db

    tableAction = db.table('Action')
    tableActionPropertyType = db.table('ActionPropertyType')

    queryTable = tableAction.innerJoin(
        tableActionPropertyType, tableActionPropertyType['actionType_id'].eq(
            tableAction['actionType_id']))

    cond = [
        tableAction['takenTissueJournal_id'].eq(tissueJournalId),
        tableActionPropertyType['test_id'].eq(testId)
    ]

    actionRecordList = db.getRecordList(queryTable, 'Action.*', cond)

    for actionRecord in actionRecordList:

        needSave = False

        action = CAction(record=actionRecord)

        actionType = action.getType()
        propertyTypeItemsList = actionType.getPropertiesById().items()
        for propertyTypeId, propertyType in propertyTypeItemsList:
            if propertyType.testId == testId:
                property = action.getPropertyById(propertyTypeId)
                if not propertyType.isVector:
                    property.setValue(
                        propertyType.convertQVariantToPyValue(result))
                    needSave = True

        if needSave:
            action.save(idx=forceInt(actionRecord.value('idx')))
예제 #2
0
    def addEventAction(self, eventId, actionTypeId, jobTicketId, date, idx, amount):
        def checkActionTypeIdByTissueType(actionTypeId):
            tissueTypeId = forceRef(self.takenTissueRecord.value('tissueType_id'))
            table = QtGui.qApp.db.table('ActionType_TissueType')
            cond = [table['master_id'].eq(actionTypeId),
                    table['tissueType_id'].eq(tissueTypeId)]
            return bool(QtGui.qApp.db.getRecordEx(table, 'id', cond))

        def setTicketIdToAction(action, jobTicketId):
            propertyTypeList = action.getType().getPropertiesById().values() if action else []
            for propertyType in propertyTypeList:
                if type(propertyType.valueType) == CJobTicketActionPropertyValueType:
                    property = action.getPropertyById(propertyType.id)
                    property.setValue(jobTicketId)
                    return True
            return False

        db = QtGui.qApp.db
        record = db.table('Action').newRecord()
        fillActionRecord(self, record, actionTypeId)
        action = CAction(record=record)
        if setTicketIdToAction(action, jobTicketId):
            #            record.setValue('directionDate', QVariant(date))
            record.setValue('setPerson_id', QtCore.QVariant(QtGui.qApp.userId))
            if not amount is None:
                record.setValue('amount', QtCore.QVariant(amount))
            if self.takenTissueRecord and checkActionTypeIdByTissueType(actionTypeId):
                record.setValue('takenTissueJournal_id', self.takenTissueRecord.value('id'))
            actionId = action.save(eventId, idx)
            self.actionIdListCanDeleted.append(actionId)

            self.mapActionIdToAction[actionId] = action
            return action
        return None
예제 #3
0
class CF025DentalModel(QtCore.QAbstractTableModel):
    def __init__(self, isCalf, parent = None):
        super(CF025DentalModel, self).__init__(parent)
        self._isCalf = isCalf
        self._dentalNotationAction = None


    #--- re-implement
    def rowCount(self, parentIndex = QtCore.QModelIndex()):
        return 4

    def columnCount(self, parentIndex = QtCore.QModelIndex()):
        return 10 if self._isCalf else 16


    def flags(self, index):
        flags = QtCore.Qt.NoItemFlags

        if self._dentalNotationAction and index.isValid():
            row = index.row()
            column = index.column()
            if column in xrange(self.columnCount()):
                if row in [0, 3]:
                    flags = QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
                    propertyName = self.getPropertyName(row, column)
                    prop = self._dentalNotationAction.getProperty(propertyName)
                    if prop.type().isAssignable:
                        flags += QtCore.Qt.ItemIsUserCheckable
                elif row in [1, 2]:
                    flags = QtCore.Qt.ItemIsEnabled
        return flags


    def data(self, index, role = QtCore.Qt.DisplayRole):
        if self._dentalNotationAction and index.isValid():
            row = index.row()
            column = index.column()
            if column in xrange(self.columnCount()):
                if row in [0, 3]:
                    propertyName = self.getPropertyName(row, column)
                    prop = self._dentalNotationAction.getProperty(propertyName)
                    if role == QtCore.Qt.DisplayRole:
                        return QtCore.QVariant(prop.getText())
                    elif role == QtCore.Qt.CheckStateRole:
                        if prop.type().isAssignable:
                            QtCore.QVariant(QtCore.Qt.Checked if prop.isAssigned() else QtCore.Qt.Unchecked)
                    elif role == QtCore.Qt.EditRole:
                        return QtCore.QVariant(prop.getValue())
                    elif role == QtCore.Qt.DecorationRole:
                        return QtCore.QVariant(prop.getImage())
                    elif role == QtCore.Qt.ForegroundRole:
                        if prop.getEvaluation():
                            return QtCore.QVariant(QtGui.QBrush(QtGui.QColor(255, 0, 0)))
                    elif role == QtCore.Qt.FontRole:
                        evaluation = prop.getEvaluation()
                        if evaluation and abs(evaluation) == 2:
                            font = QtGui.QFont()
                            font.setBold(True)
                            return QtCore.QVariant(font)
                elif row in [1, 2]:
                    if role == QtCore.Qt.DisplayRole:
                        return QtCore.QVariant(self.getPropertyName(0 if row == 1 else 3, column))
                    elif role == QtCore.Qt.FontRole:
                        font = QtGui.QFont()
                        font.setBold(True)
                        return QtCore.QVariant(font)
                    elif role == QtCore.Qt.TextAlignmentRole:
                        return QtCore.QVariant(QtCore.Qt.AlignCenter)



        return QtCore.QVariant()


    def setData(self, index, value, role = QtCore.Qt.EditRole):
        if self._dentalNotationAction and index.isValid():
            row = index.row()
            column = index.column()
            if column in xrange(self.columnCount()):
                if row in [0, 3]:
                    propertyName = self.getPropertyName(row, column)
                    prop = self._dentalNotationAction.getProperty(propertyName)
                    if role == QtCore.Qt.EditRole:
                        prop.setValue(prop.type().convertQVariantToPyValue(value))
                        self.dataChanged.emit(index, index)
                        return True
                    elif role == QtCore.Qt.CheckStateRole:
                        prop.setAssigned(value == QtCore.Qt.Checked)
                        self.dataChanged.emit(index, index)
                        return True
            return False

    #--- working
    def getPropertyName(self, row, column):
        if row not in (0, self.rowCount() - 1):
            return None

        if (column * 2) < self.columnCount():
            quadrant = 1 if row == 0 else 4
            number = (self.columnCount() / 2) - column
        else:
            quadrant = 2 if row == 0 else 3
            number = column  - (self.columnCount() / 2) + 1

        if self._isCalf:
            quadrant += 4

        return u'%s%s' % (quadrant, number)


    def loadData(self, eventId):
        record = None
        db = QtGui.qApp.db
        tableAction = db.table('Action')

        propertyDefList = []
        for row in xrange(self.rowCount()):
            for column in xrange(self.columnCount()):
                propertyName = self.getPropertyName(row, column)
                if propertyName is not None:
                    propertyDefList.append({'name' : propertyName,
                                         'descr' : None,
                                         'unit' : None,
                                         'typeName' : 'String',
                                         'valueDomain' : None,
                                         'isVector' : False,
                                         'norm' : None,
                                         'sex' : None,
                                         'age' : None
                                         })

        actionTypeFlatCode = u'calfTeeth' if self._isCalf else u'permanentTeeth'
        ensureActionTypePresence(actionTypeFlatCode, propTypeList = propertyDefList, isUseFlatCode=True)
        actionType = CActionTypeCache.getByFlatCode(actionTypeFlatCode)
        if eventId:
            cond  = [tableAction['deleted'].eq(0),
                     tableAction['event_id'].eq(eventId),
                     tableAction['actionType_id'].eq(actionType.id)]

            record = db.getRecordEx(tableAction,
                                    '*',
                                    cond,
                                    order = 'idx')
        self._dentalNotationAction = CAction(record = record if record else None,
                                             actionType = actionType)


    def saveData(self, eventId):
        if self._dentalNotationAction:
            self._dentalNotationAction.save(eventId = eventId)
예제 #4
0
 def on_btnNextAction_clicked(self):
     if self.cmbStatus.currentIndex() == 3:
         currentDateTime = QtCore.QDateTime.currentDateTime()
         db = QtGui.qApp.db
         table = db.table('vrbPersonWithSpeciality')
         personId = QtGui.qApp.userId if (
         QtGui.qApp.userId and QtGui.qApp.userSpecialityId) else self.cmbSetPerson.value()
         record = db.getRecordEx(table, [table['name']], [table['id'].eq(personId)]) if personId else None
         personName = forceString(record.value('name')) if record else ''
         self.edtNote.setText('Отменить: %s %s' % (currentDateTime.toString('dd-MM-yyyy hh:mm'), personName))
     else:
         self.newActionId = None
         prevRecord = self.getRecord()
         if prevRecord:
             actionTypeId = forceRef(prevRecord.value('actionType_id')) if prevRecord else None
             duration = self.edtDuration.value()
             aliquoticity = self.edtAliquoticity.value()
             if duration >= 1 or aliquoticity > 1:
                 recordList = {}
                 periodicity = self.edtPeriodicity.value()
                 if aliquoticity and actionTypeId:
                     db = QtGui.qApp.db
                     tableAction = db.table('Action')
                     eventId = forceRef(prevRecord.value('event_id'))
                     actionId = forceRef(prevRecord.value('id'))
                     directionDate = forceDateTime(prevRecord.value('directionDate'))
                     setPersonId = forceRef(prevRecord.value('setPerson_id'))
                     if eventId:
                         cond = [
                             tableAction['deleted'].eq(0),
                             tableAction['actionType_id'].eq(actionTypeId),
                             tableAction['event_id'].eq(eventId),
                             tableAction['directionDate'].eq(directionDate),
                             tableAction['setPerson_id'].eq(setPersonId)
                         ]
                         for recordOld in db.iterRecordList(
                                 tableAction, tableAction['*'], cond, tableAction['begDate']
                         ):
                             id = forceRef(recordOld.value('id'))
                             begDateOld = forceDateTime(recordOld.value('begDate'))
                             recordList[(id, begDateOld)] = recordOld
                         keysList = recordList.keys()
                         keysList.sort()
                         keyList = keysList[-1]
                         quoticity = 0
                         if aliquoticity > 1:
                             for key in recordList.keys():
                                 if key[1].date() == keyList[1].date():
                                     quoticity += 1
                         if duration >= 1 or (aliquoticity > 1 and aliquoticity > quoticity):
                             lastRecord = recordList.get(keyList, None)
                             newRecordAction = False
                             if lastRecord:
                                 prevActionId = forceRef(lastRecord.value('id'))
                                 if actionId == prevActionId:
                                     begDate = forceDateTime(prevRecord.value('begDate'))
                                     if QtGui.qApp.userId and QtGui.qApp.userSpecialityId:
                                         execPersonId = QtGui.qApp.userId
                                     else:
                                         execPersonId = self.cmbSetPerson.value()
                                     dialog = CExecTimeNextActionDialog(self, begDate, execPersonId)
                                     if dialog.exec_():
                                         execTime = dialog.getExecTime()
                                         execPersonId = dialog.getExecPersonId()
                                         specifiedName = forceString(prevRecord.value('specifiedName'))
                                         prevRecord.setValue('person_id', toVariant(execPersonId))
                                         executionPlan = self.action.getExecutionPlan()
                                         executionPlanKeys = executionPlan.keys()
                                         executionPlanKeys.sort()
                                         executionPlanBegDate = executionPlan.get(pyDate(begDate.date()), {})
                                         if not executionPlanBegDate:
                                             for keyDate in executionPlanKeys:
                                                 executionPlanTimes = executionPlan.get(keyDate, {})
                                                 aliquoticityNew = len(executionPlanTimes)
                                                 if aliquoticityNew:
                                                     executionPlanTimeKeys = executionPlanTimes.keys()
                                                     executionPlanTimeKeys.sort()
                                                     aliquoticity = aliquoticityNew
                                                     begDateDate = begDate.date()
                                                     durationNew = duration - begDateDate.daysTo(
                                                         QtCore.QDate(keyDate))
                                                     duration = durationNew
                                                     begDate = QtCore.QDateTime(QtCore.QDate(keyDate),
                                                                                executionPlanTimeKeys[0])
                                                     break
                                         else:
                                             executionPlanBegDateKeys = executionPlanBegDate.keys()
                                             executionPlanBegDateKeys.sort()
                                             begTime = executionPlanBegDateKeys[0]
                                             executionPlanKeys = executionPlan.keys()
                                             executionPlanKeys.sort()
                                             if QtCore.QDate(executionPlanKeys[0]) == begDate.date():
                                                 aliquoticity = len(executionPlanBegDateKeys)
                                                 newBegDate = begDate.date().addDays(1)
                                                 maxBegDate = executionPlanKeys[len(executionPlanKeys) - 1]
                                                 while newBegDate <= maxBegDate:
                                                     periodicityPlanTimes = executionPlan.get(pyDate(newBegDate), {})
                                                     if len(periodicityPlanTimes):
                                                         periodicity = begDate.date().daysTo(newBegDate) - 1
                                                         break
                                                     else:
                                                         newBegDate = newBegDate.addDays(1)
                                                 if periodicity < 0:
                                                     periodicity = 0
                                             begDate = QtCore.QDateTime(begDate.date(), begTime)
                                         prevRecord.setValue('aliquoticity', toVariant(aliquoticity))
                                         prevRecord.setValue('begDate', toVariant(begDate))
                                         prevRecord.setValue('endDate',
                                                             toVariant(QtCore.QDateTime(begDate.date(), execTime)))
                                         prevRecord.setValue('status', toVariant(2))
                                         prevRecord.setValue('plannedEndDate',
                                                             toVariant(begDate.addDays(duration - 1)))
                                         prevRecord.setValue('duration', toVariant(duration))
                                         endDate = forceDateTime(prevRecord.value('endDate'))
                                         newExecutionPlan = {}
                                         tableActionExecutionPlan = db.table('Action_ExecutionPlan')
                                         for execDate, timeList in executionPlan.items():
                                             timeListDict = {}
                                             for execTime, record in timeList.items():
                                                 if QtCore.QDateTime(QtCore.QDate(execDate), execTime) > begDate:
                                                     newExecPlanRecord = tableActionExecutionPlan.newRecord()
                                                     newExecPlanRecord.setValue('execDate',
                                                                                toVariant(record.value('execDate')))
                                                     newExecPlanRecord.setValue('master_id', toVariant(None))
                                                     newExecPlanRecord.setValue('id', toVariant(None))
                                                     timeListDict[execTime] = newExecPlanRecord
                                             if timeListDict or QtCore.QDate(execDate) > begDate.date():
                                                 newExecutionPlan[execDate] = timeListDict
                                         begDateNew = None
                                         periodicityNew = -1
                                         if newExecutionPlan:
                                             newExecutionPlanKeys = newExecutionPlan.keys()
                                             newExecutionPlanKeys.sort()
                                             newExecTimeList = {}
                                             newExecDate = None
                                             for planKey in newExecutionPlanKeys:
                                                 newExecTimeList = newExecutionPlan.get(planKey, {})
                                                 if newExecTimeList:
                                                     newExecDate = planKey
                                                     break
                                             if newExecTimeList and newExecDate:
                                                 newExecTimeListKeys = newExecTimeList.keys()
                                                 if len(newExecTimeListKeys) > 0:
                                                     newExecTimeListKeys.sort()
                                                     newExecTime = newExecTimeListKeys[0]
                                                     begDateNew = QtCore.QDateTime(QtCore.QDate(newExecDate),
                                                                                   newExecTime)
                                                     aliquoticity = len(newExecTimeListKeys)
                                                     begDateDate = begDate.date()
                                                     periodicity = begDateDate.daysTo(begDateNew.date()) - 1
                                                     if periodicity < 0:
                                                         periodicity = 0
                                                     if begDateDate == begDateNew.date():
                                                         durationNew = duration
                                                     else:
                                                         durationNew = duration - 1 - periodicity
                                                     periodicityNew = 0
                                                     begDateNewDate = begDateNew.date()
                                                     for newExecutionKey in newExecutionPlanKeys:
                                                         newExecutionDate = QtCore.QDate(newExecutionKey)
                                                         if newExecutionDate > begDateNewDate:
                                                             periodicityNew = begDateNewDate.daysTo(
                                                                 newExecutionDate) - 1
                                                             if periodicityNew < 0:
                                                                 periodicityNew = 0
                                                             break
                                         elif aliquoticity > 1 and aliquoticity > quoticity:
                                             begDateNew = QtCore.QDateTime(endDate.date(),
                                                                           execTime if execTime else self.getCurrentTimeAction(
                                                                               endDate))
                                             durationNew = duration
                                         else:
                                             endDateNew = endDate.addDays(periodicity + 1)
                                             begDateNew = QtCore.QDateTime(endDateNew.date(),
                                                                           execTime if execTime else  self.getCurrentTimeAction(
                                                                               endDate))
                                             durationNew = duration - 1 - periodicity
                                         prevRecord.setValue('periodicity', toVariant(periodicity))
                                         if begDateNew and durationNew:
                                             if periodicityNew > -1:
                                                 periodicity = periodicityNew
                                             newRecord = tableAction.newRecord()
                                             newRecord.setValue('event_id', toVariant(prevRecord.value('event_id')))
                                             newRecord.setValue('begDate', toVariant(begDateNew))
                                             newRecord.setValue('status', toVariant(0))
                                             newRecord.setValue('idx', toVariant(9999))
                                             newRecord.setValue('specifiedName', toVariant(specifiedName))
                                             newRecord.setValue('duration', toVariant(durationNew))
                                             newRecord.setValue('periodicity', toVariant(periodicity))
                                             newRecord.setValue('aliquoticity', toVariant(aliquoticity))
                                             newRecord.setValue('plannedEndDate',
                                                                toVariant(begDateNew.addDays(durationNew - 1)))
                                             newRecord.setValue('actionType_id', toVariant(actionTypeId))
                                             newRecord.setValue('directionDate',
                                                                toVariant(prevRecord.value('directionDate')))
                                             newRecord.setValue('setPerson_id',
                                                                toVariant(prevRecord.value('setPerson_id')))
                                             newRecord.setValue('person_id', toVariant(QtGui.qApp.userId if (
                                             QtGui.qApp.userId and QtGui.qApp.userSpecialityId) else self.cmbSetPerson.value()))
                                             newRecord.setValue('org_id', toVariant(prevRecord.value('org_id')))
                                             newRecord.setValue('amount', toVariant(prevRecord.value('amount')))
                                             newAction = CAction(record=newRecord)
                                             if newExecutionPlan:
                                                 newAction.setExecutionPlan(newExecutionPlan)
                                             if newAction:
                                                 for properties in self.action._properties:
                                                     type = properties._type
                                                     name = type.name
                                                     if (type.canChangeOnlyOwner > 0
                                                         or type.inActionsSelectionTable == 1
                                                         or type.isActionNameSpecifier
                                                         ) and name:
                                                         newAction[name] = self.action[name]
                                                 self.newActionId = newAction.save(idx=9999)
                                             newRecordAction = True
                                             self.setRecordByNext(prevRecord)
                                             self.saveData()
                                             self.close()
                             if duration == 1 and not newRecordAction:
                                 begDate = forceDateTime(prevRecord.value('begDate'))
                                 prevRecord.setValue('status', toVariant(2))
                                 endDate = forceDateTime(prevRecord.value('endDate'))
                                 if not endDate:
                                     prevRecord.setValue('endDate', toVariant(begDate))
                                 prevRecord.setValue('person_id', toVariant(QtGui.qApp.userId if (
                                 QtGui.qApp.userId and QtGui.qApp.userSpecialityId) else self.cmbSetPerson.value()))
                                 prevRecord.setValue('plannedEndDate', toVariant(begDate.addDays(duration - 1)))
                                 self.setRecordByNext(prevRecord)
                                 self.saveData()
                                 self.close()
예제 #5
0
class CTemperatureListEditorDialog(QtGui.QDialog, CConstructHelperMixin, Ui_TemperatureListEditor):
    def __init__(self, parent, clientId, eventId, actionTypeIdList, clientSex, clientAge, setDate):
        QtGui.QDialog.__init__(self, parent)
        self.addModels('APActionProperties',   CActionPropertiesTableModel(self))
        self.btnTemperatureList = QPushButton(u'Температурный лист', self)
        self.btnTemperatureList.setObjectName('btnTemperatureList')
        self.setupUi(self)
        try:
            from PyQt4.Qwt5 import Qwt
            self.btnTemperatureList.setEnabled(True)
            self.btnTemperatureList.setToolTip(u'')
        except:
            self.btnTemperatureList.setEnabled(False)
            self.btnTemperatureList.setToolTip(u'Не удалось загрузить модуль Qwt.')
        self.buttonBox.addButton(self.btnTemperatureList, QtGui.QDialogButtonBox.ActionRole)
        self.setModels(self.tblAPProps, self.modelAPActionProperties, self.selectionModelAPActionProperties)
        
        self.clientId = clientId
        self.clientSex = clientSex
        self.clientAge = clientAge
        self.setDate = setDate.date() if setDate else None
        self.eventId = eventId
        self.actionTypeIdList = actionTypeIdList
        self.action = None
        self.timeList = {}
        self.isDirty = False
        currentDateTime = QtCore.QDateTime.currentDateTime()
        self.edtDate.setDate(currentDateTime.date())
        self.edtTime.setTime(currentDateTime.time())
        self.cmbTimeEdit.setCurrentIndex(0)


    @pyqtSlot(QModelIndex, QModelIndex)
    def on_modelAPActionProperties_dataChanged(self, topLeft, bottomRight):
        self.isDirty = True


    def canClose(self):
        if self.isDirty:
            res = QtGui.QMessageBox.warning( self,
                                      u'Внимание!',
                                      u'Данные были изменены.\nСохранить изменения?',
                                      QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
                                      QtGui.QMessageBox.Yes)
            if res == QtGui.QMessageBox.Yes:
                self.isDirty = False
                return True
        return False


    def closeEvent(self, event):
        if self.canClose():
            self.isDirty = False
            self.action.save()
        QtGui.QDialog.closeEvent(self, event)


    def updatePropTable(self, action):
        self.tblAPProps.model().setAction(action, self.clientId, self.clientSex, self.clientAge)
        self.tblAPProps.resizeRowsToContents()


    def createAction(self):
        self.action = None
        if self.clientId:
            db = QtGui.qApp.db
            tableAction = db.table('Action')
            date = self.edtDate.date()
            time = self.edtTime.time()
            execPersonId = self.cmbExecPerson.value()
            if not execPersonId:
                execPersonId = QtGui.qApp.userId
                self.cmbExecPerson.setValue(execPersonId)
            dialogDateTime = QtCore.QDateTime(date, time)
            cond = [tableAction['deleted'].eq(0),
                    tableAction['event_id'].eq(self.eventId),
                    tableAction['actionType_id'].inlist(self.actionTypeIdList)
                    ]
            cond.append(tableAction['endDate'].eq(dialogDateTime))
            record = db.getRecordEx(tableAction, '*', cond)
            if record:
                execPersonId = forceRef(record.value('person_id'))
                if execPersonId:
                    self.cmbExecPerson.setValue(execPersonId)
                else:
                    self.cmbExecPerson.setValue(QtGui.qApp.userId)
                record.setValue('person_id', toVariant(execPersonId))
                self.action = CAction(record=record)
            else:
                actionTypeId = self.actionTypeIdList[0]
                if actionTypeId:
                    record = tableAction.newRecord()
                    record.setValue('event_id', toVariant(self.eventId))
                    record.setValue('actionType_id', toVariant(actionTypeId))
                    record.setValue('begDate', toVariant(dialogDateTime))
                    record.setValue('endDate', toVariant(dialogDateTime))
                    record.setValue('status',  toVariant(2))
                    record.setValue('person_id', toVariant(execPersonId))
                    record.setValue('org_id',  toVariant(QtGui.qApp.currentOrgId()))
                    record.setValue('amount',  toVariant(1))
                    self.action = CAction(record=record)
            if self.action:
                tableEvent = db.table('Event')
                prevSetDate = None
                prevEventId = None
                prevEventRecord = db.getRecordEx(tableEvent, [tableEvent['prevEvent_id'], tableEvent['setDate']], [tableEvent['id'].eq(self.eventId), tableEvent['deleted'].eq(0)])
                if prevEventRecord:
                    prevEventId = forceRef(prevEventRecord.value('prevEvent_id'))
                    prevSetDate = forceRef(prevEventRecord.value('setDate'))
                while prevEventId:
                    prevEventRecord = db.getRecordEx(tableEvent, [tableEvent['prevEvent_id'], tableEvent['setDate']], [tableEvent['id'].eq(prevEventId), tableEvent['deleted'].eq(0)])
                    if prevEventRecord:
                        prevEventId = forceRef(prevEventRecord.value('prevEvent_id'))
                        prevSetDate = forceRef(prevEventRecord.value('setDate'))
                    else:
                        prevEventId = None
                begDate = forceDate(record.value('begDate'))
                if (self.setDate and begDate) or (prevSetDate and begDate):
                    if prevSetDate:
                        self.action[u'День болезни'] = prevSetDate.daysTo(begDate) + 1
                    else:
                        self.action[u'День болезни'] = self.setDate.daysTo(begDate) + 1
                setActionPropertiesColumnVisible(self.action._actionType, self.tblAPProps)
                self.updatePropTable(self.action)
                self.tblAPProps.setEnabled(self.getIsLocked(self.action._record))
        self.isDirty = False
        return self.action


    def getIsLocked(self, record):
        if record:
            status = forceInt(record.value('status'))
            personId = forceRef(record.value('person_id'))
            if status == ActionStatus.Done and personId:
                return ( QtGui.qApp.userId == personId
                                 or QtGui.qApp.userHasRight(urEditOtherPeopleAction)
                                 or QtGui.qApp.userId in getPersonChiefs(personId)
                               )
        return False


    @QtCore.pyqtSlot()
    def on_btnTemperatureList_clicked(self):
        if self.canClose():
            self.isDirty = False
            self.action.save()
        try:
            from ThermalSheet.TemperatureList import CTemperatureListParameters, CTemperatureList
            dialog = CTemperatureListParameters(self, self.eventId)
            if dialog.exec_():
                demo = CTemperatureList(self, dialog.params(), self.clientId, self.eventId)
                demo.getInfo()
                demo.exec_()
        except:
            QtGui.qApp.logCurrentException()


    @pyqtSlot(QTime)
    def on_edtTime_timeChanged(self, time):
        if self.canClose():
            self.isDirty = False
            self.action.save()
        self.createAction()


    @pyqtSlot(QDate)
    def on_edtDate_dateChanged(self, date):
        if self.canClose():
            self.isDirty = False
            self.action.save()
        self.getTimeList()
        self.cmbTimeEdit.setCurrentIndex(0)
        self.createAction()


    @pyqtSlot(int)
    def on_cmbTimeEdit_currentIndexChanged(self, index):
        if index > 0:
            time = self.timeList.get(index, QtCore.QTime())
            self.edtTime.setTime(time)
        else:
            currentDateTime = QtCore.QDateTime.currentDateTime()
            self.edtTime.setTime(currentDateTime.time())
            self.cmbExecPerson.setValue(QtGui.qApp.userId)


    def getTimeList(self):
        self.timeList = {}
        countItems = self.cmbTimeEdit.count()
        countItem = countItems - 1
        while countItem > 0:
            self.cmbTimeEdit.removeItem(countItem)
            countItem -= 1
        if self.eventId and self.actionTypeIdList:
            db = QtGui.qApp.db
            tableAction = db.table('Action')
            date = forceDate(self.edtDate.date())
            cond = [tableAction['deleted'].eq(0),
                    tableAction['event_id'].eq(self.eventId),
                    tableAction['actionType_id'].inlist(self.actionTypeIdList)
                    ]
            cond.append(tableAction['endDate'].dateEq(date))
            records = db.getRecordList(tableAction, [tableAction['id'], tableAction['endDate']], cond, 'Action.endDate')
            idx = 1
            for record in records:
                actionId = forceRef(record.value('id'))
                endDate = forceDateTime(record.value('endDate'))
                endTime = endDate.time()
                self.timeList[idx] = endTime
                self.cmbTimeEdit.insertItem(idx, endTime.toString('hh:mm'))
                idx += 1
        if len(self.timeList) > 0:
            endTime = self.timeList.get(idx-1, None)
            if endTime:
                self.lblLastTime.setText(endTime.toString('hh:mm'))
            else:
                self.lblLastTime.setText(u'')
        else:
            self.lblLastTime.setText(u'нет')