예제 #1
0
    def decodeValue(cls, value, valueTypeInfo, isHumanReadable=False):
        isList = value.type() == QtCore.QVariant.List
        valueList = value.toList() if isList else [value]
        resultList = []
        for value in valueList:
            typeName = valueTypeInfo.get('name', 'str')
            valueType = cls.valueTypeByName(typeName)

            value = value.toString()
            if value.startsWith(valueTypeInfo['leftFrameMark']):
                value.remove(0, len(valueTypeInfo['leftFrameMark']))
            if value.startsWith(valueTypeInfo['rightFrameMark']):
                value.chop(len(valueTypeInfo['leftFrameMark']))

            if valueType == QtCore.QVariant.Date:
                value = QtCore.QDate.fromString(value, QtCore.Qt.ISODate)
            elif QtCore.QVariant.DateTime:
                value = QtCore.QDateTime.fromString(value, QtCore.Qt.ISODate)
            elif value.canConvert(valueType):
                value = value.convert(valueType)
            elif isHumanReadable and valueType == cls.RefBook and valueTypeInfo.has_key(
                    'tableName'):
                tableName = valueTypeInfo['tableName']
                cond = [
                    valueTypeInfo.get('condition', u''),
                    "name like '%%%s%%'" % forceString(value)
                ]
                cache = CRBModelDataCache.getData(tableName, filter=cond)
                valueIndex = cache.getIndexByName(forceString(value),
                                                  isStrinct=False)
                value = cache.getId(valueIndex)
            resultList.append(value.prepend().append(
                valueTypeInfo['rightFrameMark']))

        return QtCore.QVariant(resultList if isList else resultList[0])
예제 #2
0
 def toStatusTip(self, val, record):
     cache = CRBModelDataCache.getData(self.tableName, True)
     text = cache.getStringById(forceRef(val), CRBComboBox.showName)
     specifiedName = forceString(record.value('specifiedName'))
     if specifiedName:
         text = text + ' ' + specifiedName
     return toVariant(text)
예제 #3
0
    def encodeValue(cls, value, valueTypeInfo, isHumanReadable=False):
        isList = value.type() == QtCore.QVariant.List
        valueList = value.toList() if isList else [value]
        resultList = []
        for value in valueList:
            if value.type() in (QtCore.QVariant.Date,
                                QtCore.QVariant.DateTime):
                value = value.toString(QtCore.Qt.ISODate)
            else:
                value = value.toString()
            typeName = valueTypeInfo.get('name', 'str')
            if isHumanReadable and cls.valueTypeByName(
                    typeName) == cls.RefBook and valueTypeInfo.has_key(
                        'tableName'):
                tableName = valueTypeInfo['tableName']
                cond = [
                    valueTypeInfo.get('condition', u''),
                    'id = %s' % forceRef(value)
                ]
                cache = CRBModelDataCache.getData(tableName, filter=cond)
                value = cache.getStringById(forceRef(value),
                                            CRBComboBox.showName)
            resultList.append(
                value.prepend(valueTypeInfo['leftFrameMark']).append(
                    valueTypeInfo['rightFrameMark']))

        return QtCore.QVariant(resultList if isList else resultList[0])
예제 #4
0
    def toString(self, val, record):
        takeDoses = forceString(record.value('takeDose'))
        takeTime = forceString(record.value('takeTime'))
        takeDate = forceString(record.value('takeDate'))

        begDate = forceDate(record.value('takeDateBegin'))
        endDate = forceDate(record.value('takeDateEnd'))
        interval = forceInt(record.value('interval'))

        cache = CRBModelDataCache.getData('rbUnit', True)
        unit = cache.getStringById(
            forceInt(record.value('drugMeasureUnit_id')), CRBComboBox.showName)

        times = takeTime.split(',')
        doses = takeDoses.split(',')

        result = u''
        i = 0
        date = begDate
        while date <= endDate:
            for time in times:
                if result:
                    result += ';'
                dose = doses[i]
                result += '(' + date.toString(
                    'dd.MM.yyyy'
                ) + ' ' + time + ') ' + dose + ' (' + unit + ')'
                i += 1
            date = date.addDays(interval + 1)
        return QtCore.QVariant(result)
예제 #5
0
    def exportTariffs(self, dbf, tariffs):
        lpuCode = forceString(self.edtLpuCode.text())
        expenses = self.getExpenses([forceRef(t.value('id')) for t in tariffs])

        serviceCache = CRBModelDataCache.getData('rbService',
                                                 True,
                                                 codeFieldName='code')

        self.progressBar.setFormat('%p%')
        self.progressBar.setValue(0)
        self.progressBar.setMaximum(len(tariffs))

        for tariff in tariffs:
            self.progressBar.step(1)
            QtGui.qApp.processEvents()
            tariffExpenses = expenses.get(forceRef(tariff.value('id')), {})
            record = dbf.newRecord()
            record['CODE_MO'] = lpuCode
            record['KUSL'] = serviceCache.getCodeById(
                forceRef(tariff.value('service_id')))
            record['DATN'] = forceDate(tariff.value('begDate')).toPyDate()
            record['DATO'] = forceDate(
                tariff.value('endDate')).toPyDate() if forceString(
                    tariff.value('endDate')) else u''
            price = forceDouble(tariff.value('price'))
            # amount = forceDouble(tariff.value('amount'))
            # priceKD = price/amount if amount else price
            record['TARIF'] = price
            # record['TARIF_B'] = tariffExpenses.get('1', 0.0)
            # record['TARIF_DM'] = tariffExpenses.get('2', 0.0)
            # record['TARIF_D'] = tariffExpenses.get('3', 0.0)
            # record['TARIF_UC'] = tariffExpenses.get('4', 0.0)
            # record['CENA_KD'] = 0 if forceDate(tariff.value('begDate')) >= QtCore.QDate(2015, 01, 01) else priceKD
            # record['LEVEL'] = self.cmbMedicalAidLevel.code()
            record.store()
예제 #6
0
    def __init__(self, parent, equipmentId):
        CDialogBase.__init__(self, parent)
        self._equipmentId = equipmentId
        self._tripod = forceInt(QtGui.qApp.db.translate('rbEquipment', 'id', equipmentId, 'tripod'))
        self._parent = parent
        self._probeData = CRBModelDataCache.getData('rbTest', addNone=False)
        self.setupUi()

        self.addModels('LoadingProbe', CLoadingProbeModel(self, equipmentId, self._tripod))
        self.setModels(self.tblLoadingProbe, self.modelLoadingProbe, self.selectionModelLoadingProbe)

        equipmentName = forceString(QtGui.qApp.db.translate('rbEquipment', 'id', equipmentId, 'name'))
        self.setWindowTitle(u'Загрузка проб в штатив оборудования \'%s\''%equipmentName)
예제 #7
0
    def __init__(self, parent, visibilityFilter=0):
        QtCore.QAbstractTableModel.__init__(self, parent)
        self.action = None
        self.clientId = None
        self._rowDataList = []
        self.unitData = CRBModelDataCache.getData('rbUnit', True)
        self.visibilityFilter = visibilityFilter
        self.readOnly = False
        self.actionStatusTip = None

        self._spanInfo = []

        self.propertyValueChanged.connect(self.notifyProperties)
def getChildrenIdList(idList):
    data = CRBModelDataCache.getData('QuotaType', False)
    db = QtGui.qApp.db
    table = db.table('QuotaType')
    result = idList
    while bool(idList):
        tmpResult = []
        for id in idList:
            code = data.getCodeById(id)
            #            code = forceString(db.translate(table, 'id', id, 'code'))
            cond = [table['group_code'].eq(code)]
            tmpResult.extend(db.getIdList(table, 'id', cond))
        result.extend(tmpResult)
        idList = tmpResult
    return result
예제 #9
0
def loadProfileAndRights(userId):
    from library.crbcombobox import CRBModelDataCache
    profileList = []
    rightList = []
    db = QtGui.qApp.db
    if userId:
        tablePUP = db.table('Person_UserProfile')
        tableUPR = db.table('rbUserProfile_Right')
        tableUR = db.table('rbUserRight')

        table = tablePUP.innerJoin(
            tableUPR, tableUPR['master_id'].eq(tablePUP['userProfile_id']))
        table = table.innerJoin(tableUR,
                                tableUR['id'].eq(tableUPR['userRight_id']))

        cols = [
            tablePUP['userProfile_id'].alias('profileId'),
            tableUR['code'].alias('rightCode')
        ]

        for record in db.iterRecordList(table, cols,
                                        tablePUP['person_id'].eq(userId)):
            profileId = forceRef(record.value('profileId'))
            rightCode = forceString(record.value('rightCode')).lower()
            if profileId not in profileList:
                profileList.append(profileId)
            if rightCode not in rightList:
                rightList.append(rightCode)

    # Находим все права, которые забыли добавить в БД с помощью апдейтов. Считаем, что если право не добавили в БД
    # и его нельзя выбрать в интерфейсе, то оно есть у пользователя.
    allRights = []
    for var in dir(Rights):
        if var.startswith('ur'):
            allRights.append(forceString(Rights.__getattribute__(var)))
    rightsCache = CRBModelDataCache.getData('rbUserRight', False)
    if rightsCache._notLoaded:
        rightsCache.load()
    extraRights = set(allRights).symmetric_difference(
        rightsCache.getAllCodes())
    # Убираем права, которые по умолчанию считаются отсутствующими (редко, но требуется)
    extraRights = extraRights - set(Rights.DefaultDisabledRights)

    extraRights = set([r.lower() for r in extraRights])

    rightList = set(rightList)
    rightList.update(extraRights)
    return rightList, profileList
예제 #10
0
 def __init__(self, title, defaultWidth, showFields=CRBComboBox.showName, alignment='l'):
     CCol.__init__(self, title, ('actionType_id', 'specifiedName'), defaultWidth, alignment)
     self.data = CRBModelDataCache.getData('ActionType', True, '')
     self.showFields = showFields
예제 #11
0
 def toStatusTip(self, val, record):
     cache = CRBModelDataCache.getData('rbJobType', True)
     text = cache.getStringById(forceRef(val), CRBComboBox.showCodeAndName)
     return toVariant(text)