Пример #1
0
    def updateClientPolicy(self, record):
        if record is None:
            self.cmbClientPolicy.updatePolicy()
            return

        execDate = forceDate(record.value('execDate'))
        eventIsClosed = not execDate.isNull()
        eventIsPayed = getRealPayed(forceInt(record.value('payStatus')))

        if eventIsPayed or (
                eventIsClosed and
                not QtGui.qApp.userHasRight(urEditClientPolicyInClosedEvent)):
            self.cmbClientPolicy.setEnabled(False)
        else:
            self.cmbClientPolicy.setEventIsClosed(eventIsClosed)
            self.cmbClientPolicy.setDate(
                execDate if eventIsClosed else QtCore.QDate.currentDate())

            if getEventFinanceCode(forceRef(
                    record.value('eventType_id'))) == 3:  # ДМС
                franchisPolicyTypeId = forceRef(
                    QtGui.qApp.db.translate('rbPolicyType', 'code', 'franchis',
                                            'id'))
                if franchisPolicyTypeId:
                    self.cmbClientPolicy.setPolicyTypeId(franchisPolicyTypeId)
                    self.cmbClientPolicy.updatePolicy()
                    if not self.cmbClientPolicy.value():
                        self.cmbClientPolicy.setPolicyTypeId(
                            forceRef(
                                QtGui.qApp.db.translate(
                                    'rbPolicyType', 'code', '3', 'id')))
                        self.cmbClientPolicy.updatePolicy()
            else:
                self.cmbClientPolicy.updatePolicy()
Пример #2
0
    def getPolicy(self, eventRec):
        clientId = forceRef(eventRec.value('client_id'))
        littleStranger = isLittleStranger(
            clientId, forceDate(eventRec.value('setDate')),
            forceDate(eventRec.value('execDate')))
        eventTypeId = forceRef(eventRec.value('eventType_id'))
        execDate = forceDate(eventRec.value('execDate'))
        eventIsClosed = not execDate.isNull()
        atDate = self.curDate if eventIsClosed else execDate

        if getEventFinanceCode(eventTypeId) == CFinanceType.VMI:
            idList = (getEventAcceptablePolicyList(
                clientId, policyTypeId=self.franchisPolicyTypeId, date=atDate)
                      or getEventAcceptablePolicyList(
                          clientId,
                          policyTypeId=self.voluntaryPolicyTypeId,
                          date=atDate))
            newPolicy = idList[-1] if idList else None
        elif littleStranger:
            newPolicy = getClientRepresentativePolicyList(clientId,
                                                          date=atDate)
        else:
            idList = getEventAcceptablePolicyList(clientId,
                                                  date=atDate,
                                                  eventIsClosed=eventIsClosed)
            newPolicy = idList[-1] if idList else None

        return newPolicy
Пример #3
0
def checkClientPolicyAttendace(eventTypeId, clientId, date=None):
    financeCode = getEventFinanceCode(eventTypeId)
    if financeCode == CFinanceType.CMI:
        return bool(getClientCompulsoryPolicy(clientId, date))
    elif financeCode == CFinanceType.VMI:
        return bool(getClientVoluntaryPolicy(clientId, date))
    else:
        return True
Пример #4
0
    def prepareActions(self, eventTypeId, specialityId, flagHospitalization,
                       addActionTypeId, recommendationList):
        wholeEventForCash = getEventFinanceCode(eventTypeId) == 4
        db = QtGui.qApp.db
        table = db.table('EventType_Action')
        tableActionType = db.table('ActionType')
        self.disabledActionTypeIdList = []
        self.notDeletedActionTypes = {}
        join = table.leftJoin(tableActionType,
                              tableActionType['id'].eq(table['actionType_id']))
        cond = [
            table['eventType_id'].eq(eventTypeId),
            tableActionType['deleted'].eq(0)
        ]
        if specialityId:
            cond.append(
                db.joinOr([
                    table['speciality_id'].eq(specialityId),
                    table['speciality_id'].isNull()
                ]))
        records = QtGui.qApp.db.getRecordList(
            join,
            'EventType_Action.*, CONCAT_WS(\'|\', ActionType.code, ActionType.name) AS actionTypeName',
            cond, 'ActionType.class, idx, id')
        for record in records:
            actionTypeId = forceRef(record.value('actionType_id'))
            if actionTypeId and self.recordAcceptable(record):
                selectionGroup = forceInt(record.value('selectionGroup'))
                notDeleted = forceInt(record.value('isCompulsory'))
                if selectionGroup == -99:
                    self.disabledActionTypeIdList.append(actionTypeId)
                elif selectionGroup == 1 or flagHospitalization and addActionTypeId == actionTypeId:
                    payable = forceInt(record.value('payable'))
                    orgId = forceRef(record.value('defaultOrg_id'))
                    self.unconditionalActionList.append(
                        (actionTypeId, 1.0, payable
                         or wholeEventForCash, orgId))
                    if notDeleted == 1:
                        self.notDeletedActionTypes[actionTypeId] = forceString(
                            record.value('actionTypeName'))

        actionTypeIdRecMap = {}
        for rec in recommendationList:
            actionTypeIdRecMap[forceInt(rec.value('actionType_id'))] = rec
        records = db.getRecordList(
            tableActionType,
            where=tableActionType['id'].inlist(actionTypeIdRecMap))
        for record in records:
            actionTypeId = forceInt(record.value('id'))
            orgId = forceRef(record.value('defaultOrg_id'))
            amount = forceInt(actionTypeIdRecMap[actionTypeId].value('amount'))
            self.unconditionalActionList.append(
                (actionTypeId, amount, False, orgId))
Пример #5
0
 def prepare(self,
             clientId,
             eventTypeId,
             eventDate,
             personId,
             specialityId,
             tariffCategoryId,
             flagHospitalization=False,
             addActionTypeId=None,
             tissueTypeId=None,
             recommendationList=None,
             useDiagnosticsAndActionsPresets=True):
     if recommendationList is None:
         recommendationList = []
     self.showPrice = getEventCanHavePayableActions(eventTypeId)
     self.wholeEventForCash = getEventFinanceCode(eventTypeId) == 4
     self.personId = personId
     self.setClientInfo(clientId, eventDate)
     self.tissueTypeId = tissueTypeId
     if self.showPrice:
         self.modelDiagnostics.addPriceAndSumColumn()
         self.modelActions.addPriceAndSumColumn()
         self.setDefaultCash()
         self.grpContract.setVisible(True)
         self.tariffCategoryId = tariffCategoryId
         self.setEventTypeId(eventTypeId, specialityId, flagHospitalization,
                             addActionTypeId, recommendationList)
         orgId = QtGui.qApp.currentOrgId()
         self.cmbContract.setOrgId(orgId)
         self.cmbContract.setClientInfo(clientId, self.clientSex,
                                        self.clientAge, None, None)
         self.cmbContract.setFinanceId(CFinanceType.getId(
             CFinanceType.cash))
         self.cmbContract.setBegDate(eventDate)
         self.cmbContract.setEndDate(eventDate)
     else:
         self.grpContract.setVisible(False)
         self.setEventTypeId(
             eventTypeId,
             specialityId,
             flagHospitalization,
             addActionTypeId,
             recommendationList,
             useDiagnosticsAndActionsPresets=useDiagnosticsAndActionsPresets
         )
Пример #6
0
    def check(self):
        db = QtGui.qApp.db
        Client = db.table('Client')
        Event = db.table('Event')

        dateFrom = self.edtDateFrom.date()
        dateTo = self.edtDateTo.date()
        eventTypeIdList = self.tblEventType.values()

        cond = [
            Event['setDate'].dateGe(dateFrom), Event['setDate'].dateLe(dateTo),
            Event['client_id'].isNotNull(), Event['org_id'].eq(self.orgId),
            Event['deleted'].eq(0)
        ]
        if eventTypeIdList:
            cond.append(Event['eventType_id'].inlist(eventTypeIdList))

        QtGui.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
        try:
            self.lblInfo.setText(u'Выполнение запроса к БД ...')
            events = db.getRecordList(Event, where=cond)
        finally:
            QtGui.qApp.restoreOverrideCursor()

        policyCount = 0
        contractCount = 0
        noPolicyCount = 0
        noContractCount = 0
        noChangesCount = 0
        self.progressBar.setMaximum(len(events))

        for i, eventRec in enumerate(events):
            QtGui.qApp.processEvents()
            if self.abort:
                break

            clientId = forceRef(eventRec.value('client_id'))
            littleStranger = isLittleStranger(
                clientId,
                begDate=forceDate(eventRec.value('setDate')),
                endDate=forceDate(eventRec.value('execDate')))

            eventId = forceRef(eventRec.value('id'))
            eventTypeId = forceRef(eventRec.value('eventType_id'))
            self.eventTypeMap[eventId] = eventTypeId
            execDate = forceDate(eventRec.value('execDate'))
            eventIsClosed = not execDate.isNull()
            atDate = self.curDate if eventIsClosed else execDate

            self.itemId = eventId
            self.item_bad = False
            self.err_str = u'Обращение {0}: '.format(eventId)
            updateRecord = False

            oldPolicy = forceRef(eventRec.value('clientPolicy_id'))
            if getEventFinanceCode(eventTypeId) == CFinanceType.VMI:
                newPolicy = self.getClientPolicy(clientId, atDate, self._franchisPolicyTypeId, eventIsClosed) or \
                            self.getClientPolicy(clientId, atDate, self._voluntaryPolicyTypeId, eventIsClosed)
            elif littleStranger:
                newPolicy = self.getClientRepresentativePolicy(
                    clientId, atDate)
            else:
                newPolicy = self.getClientPolicy(clientId,
                                                 atDate,
                                                 eventIsClosed=eventIsClosed)

            if newPolicy and newPolicy != oldPolicy:
                policyCount += 1
                self.err2log(u'переподвязан полис' if oldPolicy else (
                    u'не был выбран полис, подвязан' +
                    (u' полис представителя' if littleStranger else '')))
                eventRec.setValue('clientPolicy_id', newPolicy)
                updateRecord = True
            elif not oldPolicy and not newPolicy:
                noPolicyCount += 1
                self.err2log(u'не удалось подвязать полис')

            clientRecord = db.getRecord(Client, 'birthDate', clientId)
            oldContract = forceRef(eventRec.value('contract_id'))
            newContract = self.getContract(eventRec, clientRecord)
            if newContract and newContract != oldContract:
                contractCount += 1
                self.err2log(u'переподвязан договор' if oldContract else
                             u'не был выбран договор, подвязан')
                eventRec.setValue('contract_id', newContract)
                updateRecord = True
            elif not oldContract and not newContract:
                noContractCount += 1
                self.err2log(u'не удалось подвязать договор')

            if updateRecord:
                db.updateRecord(Event, eventRec)
            else:
                noChangesCount += 1

            self.progressBar.setValue(i + 1)
            self.updateInfoLabel(i + 1, policyCount, noPolicyCount,
                                 contractCount, noContractCount,
                                 noChangesCount)

        if not events:
            self.progressBar.setMaximum(1)
            self.progressBar.setValue(1)
            self.lblInfo.setText(u'Нет подходящих обращений')

        self.finishedEventTypes |= set(eventTypeIdList)