def checkOrGenerateUniqueEventExternalId(self, eventId, eventTypeId): uniqueExternalIdRequired = getUniqueExternalIdRequired(eventTypeId) counterType = getCounterType(eventTypeId) externalId = forceStringEx(self.edtEventExternalIdValue.text()) if counterType == 0 and not externalId and getEventIsExternal( eventTypeId) == 2: return -2 if self._externalIdIsChanged: return not uniqueExternalIdRequired or self.checkUniqueEventExternalId( eventId) elif not forceString(self.edtEventExternalIdValue.text() ) and counterType == 2 and not eventId: return self.generateExternalIdByEventType(eventTypeId) elif counterType == 3 and self._eventResultId and self._eventResultId != self._originalEventResultId: return self.generateExternalIdByEventResult( eventTypeId, self._eventResultId)
def setupExternal(self): eventTypeId = self.cmbEventType.value() isExternal = getEventIsExternal(eventTypeId) self.edtExternalId.setEnabled(isExternal and not getEventCounterId(eventTypeId)) if self.edtExternalId.isEnabled(): prefix = getEventPrefix(eventTypeId) if prefix: self.prefix = prefix re = QtCore.QRegExp('%s.*' % prefix) val = QtGui.QRegExpValidator(re, self) self.edtExternalId.setText(prefix) self.edtExternalId.setValidator(val) return self.prefix = '' self.edtExternalId.setText('') self.edtExternalId.setValidator(None)
def getNotes(self, record, eventTypeId): db = QtGui.qApp.db tbl = db.table('Referral') record.setValue('relegateOrg_id', toVariant(self.cmbRelegateOrg.value())) getTextEditValue(self.edtEventNote, record, 'note') if getEventIsExternal(eventTypeId): getLineEditValue(self.edtEventExternalIdValue, record, 'externalId') if hasEventAssistant(eventTypeId): getRBComboBoxValue(self.cmbEventAssistant, record, 'assistant_id') if hasEventCurator(eventTypeId): getRBComboBoxValue(self.cmbEventCurator, record, 'curator_id') getRBComboBoxValue(self.cmbPatientModel, record, 'patientModel_id') getRBComboBoxValue(self.cmbCureType, record, 'cureType_id') getRBComboBoxValue(self.cmbCureMethod, record, 'cureMethod_id') getRBComboBoxValue(self.cmbClientPolicy, record, 'clientPolicy_id') if QtGui.qApp.isEventLockEnabled(): getCheckBoxValue(self.chkLock, record, 'locked') refId = db.translate('Event', 'id', forceInt(record.value('id')), 'referral_id') if not refId: refId = db.translate('Referral', 'event_id', forceInt(record.value('id')), 'id') if QtGui.qApp.isReferralRequired() and not self.dontSaveReferral: if self.chkLPUReferral.isChecked() and not forceInt(refId): if not forceString(self.edtNumber.text()): QtGui.QMessageBox.warning(self, u'Ошибка', u'Заполните номер направления') return ref_record = db.getRecordEx(tbl, '*', [ tbl['type'].eq(forceInt(self.cmbReferralType.value())), tbl['number'].eq(forceString(self.edtNumber.text())), tbl['client_id'].eq( forceInt(self._clientId if self._clientId else QtGui. qApp.currentClientId())), tbl['date'].eq( self.edtDate.date()), tbl['isCancelled'].eq(0), tbl['deleted'].eq(0) ]) if not ref_record: ref_record = tbl.newRecord() ref_record.setValue('number', QtCore.QVariant(self.edtNumber.text())) ref_record.setValue( 'event_id', QtCore.QVariant( forceInt(record.value('id') ) if forceInt(record.value('id')) else self. lblEventIdValue.text())) ref_record.setValue( 'relegateOrg_id', QtCore.QVariant(self.cmbRelegateOrg.value())) ref_record.setValue( 'client_id', QtCore.QVariant(self._clientId if self._clientId else QtGui .qApp.currentClientId())) ref_record.setValue('MKB', QtCore.QVariant(self.cmbMKB.text())) ref_record.setValue( 'speciality_id', QtCore.QVariant(self.cmbSpeciality.value())) ref_record.setValue( 'type', QtCore.QVariant(self.cmbReferralType.value())) getDateEditValue(self.edtDate, ref_record, 'date') getDateEditValue(self.edtPlannedDate, ref_record, 'hospDate') getLineEditValue(self.edtPerson, ref_record, 'person') if self.chkFreeInput.isChecked(): getLineEditValue(self.edtFreeInput, ref_record, 'freeInput') referralId = db.insertOrUpdate(db.table('Referral'), ref_record) record.setValue('referral_id', toVariant(referralId)) elif forceInt(refId): if not forceString(self.edtNumber.text()): QtGui.QMessageBox.warning(self, u'Ошибка', u'Заполните номер направления') return record.setValue('referral_id', toVariant(refId)) ref_record = db.getRecordEx( tbl, '*', [tbl['id'].eq(refId), tbl['isSend'].eq(0)]) if ref_record and not forceInt(ref_record.value('isSend')): if self.chkLPUReferral.isChecked(): if ref_record: ref_record.setValue( 'number', QtCore.QVariant(self.edtNumber.text())) ref_record.setValue( 'event_id', QtCore.QVariant( forceInt(record.value('id')) if forceInt( record.value('id')) else self. lblEventIdValue.text())) ref_record.setValue( 'relegateOrg_id', QtCore.QVariant(self.cmbRelegateOrg.value())) ref_record.setValue( 'client_id', QtCore.QVariant(self._clientId if self. _clientId else QtGui.qApp. currentClientId())) ref_record.setValue( 'MKB', QtCore.QVariant(self.cmbMKB.text())) ref_record.setValue( 'speciality_id', QtCore.QVariant(self.cmbSpeciality.value())) ref_record.setValue( 'type', QtCore.QVariant(self.cmbReferralType.value())) ref_record.setValue( 'date', QtCore.QVariant(self.edtDate.date())) ref_record.setValue( 'hospDate', QtCore.QVariant(self.edtPlannedDate.date())) ref_record.setValue( 'person', QtCore.QVariant(self.edtPerson.text())) db.updateRecord(tbl, ref_record) else: record.setValue('referral_id', QtCore.QVariant()) else: record.setValue('referral_id', QtCore.QVariant()) if self.chkArmyReferral.isChecked(): armyCond = [ tbl['number'].eq(self.cmbArmyNumber.text()), tbl['id'].eq(self.cmbArmyNumber.value()) ] army_ref_record = db.getRecordEx(tbl, '*', where=armyCond) if not army_ref_record: army_ref_record = tbl.newRecord() new = True else: new = False army_ref_record.setValue( 'number', QtCore.QVariant(self.cmbArmyNumber.lineEdit().text())) army_ref_record.setValue( 'client_id', QtCore.QVariant(self._clientId if self._clientId else QtGui .qApp.currentClientId())) army_ref_record.setValue('type', QtCore.QVariant(1)) army_ref_record.setValue( 'relegateOrg_id', QtCore.QVariant(self.cmbArmyOrg.value())) getDateEditValue(self.edtArmyDate, army_ref_record, 'date') if self.chkArmyFreeInput.isChecked(): getLineEditValue(self.edtArmyFreeInput, army_ref_record, 'freeInput') if new: referralId = db.insertRecord(db.table('Referral'), army_ref_record) else: referralId = db.updateRecord(db.table('Referral'), army_ref_record) record.setValue('armyReferral_id', toVariant(referralId)) self.cmbArmyNumber.forceUpdate() else: record.setValue('armyReferral_id', QtCore.QVariant())
def enableEditors(self, eventTypeId): self.edtEventExternalIdValue.setEnabled( bool(getEventIsExternal(eventTypeId))) self.cmbEventAssistant.setEnabled(hasEventAssistant(eventTypeId)) self.cmbEventCurator.setEnabled(hasEventCurator(eventTypeId))
def externalId(self): eventTypeId = self.cmbEventType.value() return forceStringEx(self.edtExternalId.text()) if getEventIsExternal( eventTypeId) else ''