def getTimeRangeOffice(self, date, personId): atcAmbulance = 'amb' etcTimeTable = '0' timeRange = ('--:--', '--:--') office = u'' times = [] queue = [] db = QtGui.qApp.db eventTypeId = getEventType(etcTimeTable).eventTypeId eventTable = db.table('Event') cond = [ eventTable['deleted'].eq(0), eventTable['eventType_id'].eq(eventTypeId), eventTable['execDate'].eq(date), eventTable['execPerson_id'].eq(personId) ] event = db.getRecordEx(eventTable, '*', cond) if event: eventId = forceRef(event.value('id')) action = CAction.getAction(eventId, atcAmbulance) begTime = action['begTime'] endTime = action['endTime'] office = action['office'] times = action['times'] queue = action['queue'] if begTime and endTime: timeRange = begTime.toString( 'H:mm') + ' - ' + endTime.toString('H:mm') return timeRange, office, times, queue
def loadData(self, clientId=None): etcQueue = 'queue' atcQueue = 'queue' if clientId: self.clientId = clientId currentDate = forceDateTime(QtCore.QDate.currentDate()) db = QtGui.qApp.db tableAction = db.table('Action') tableEvent = db.table('Event') tableActionProperty = db.table('ActionProperty') tableActionProperty_Action = db.table('ActionProperty_Action') tableActionProperty_rbReason = db.table( 'ActionProperty_rbReasonOfAbsence') tableReason = db.table('rbReasonOfAbsence') cols = [ tableAction['id'], tableAction['setPerson_id'], tableAction['person_id'], tableAction['status'], tableAction['office'], tableAction['directionDate'], tableAction['note'], tableActionProperty_Action['id'].alias('APAction_id'), tableAction['event_id'], tableReason['name'].alias('reason') ] actionType = CActionTypeCache.getByCode(atcQueue) actionTypeId = actionType.id eventType = getEventType(etcQueue) eventTypeId = eventType.eventTypeId cond = [ tableEvent['client_id'].eq(self.clientId), tableEvent['setDate'].ge(currentDate), tableEvent['deleted'].eq(0), tableAction['deleted'].eq(0), tableEvent['eventType_id'].eq(eventTypeId), tableAction['actionType_id'].eq(actionTypeId) ] tableQuery = tableAction tableQuery = tableQuery.innerJoin( tableEvent, tableEvent['id'].eq(tableAction['event_id'])) tableQuery = tableQuery.leftJoin( tableActionProperty, tableActionProperty['action_id'].eq(tableAction['id'])) tableQuery = tableQuery.innerJoin( tableActionProperty_Action, tableActionProperty_Action['value'].eq(tableAction['id'])) tableQuery = tableQuery.leftJoin( tableActionProperty_rbReason, tableActionProperty_rbReason['id'].eq( tableActionProperty['id'])) tableQuery = tableQuery.leftJoin( tableReason, tableReason['id'].eq(tableActionProperty_rbReason['value'])) records = db.getRecordList(tableQuery, cols, cond, 'Action.directionDate') self.setItems(records) else: self.clearItems()
def loadDefaults(self): db = QtGui.qApp.db tablePerson = db.table('Person') prefs = getPref(QtGui.qApp.preferences.appPrefs, 'PreCreateEvent', {}) infisCode = getPref(prefs, 'infisCode', '') eventTypeCode = getPref(prefs, 'eventTypeCode', '01') personCode = getPref(prefs, 'personCode', '') personId = forceRef(getPref(prefs, 'personId', None)) assistantCode = getPref(prefs, 'assistantCode', '') curatorCode = getPref(prefs, 'curatorCode', '') addVisits = bool(getPref(prefs, 'addVisits', False)) includeRedDays = bool(getPref(prefs, 'includeRedDays', False)) tissueTypeCode = getPref(prefs, 'tissueTypeCode', '1') referralType = getPref(prefs, 'referralType', '') selectPreviousActions = bool( getPref(prefs, 'selectPreviousActions', False)) if infisCode: CPreCreateEventDialog._orgId = forceRef( db.translate('Organisation', 'infisCode', infisCode, 'id')) if not CPreCreateEventDialog._orgId: CPreCreateEventDialog._orgId = QtGui.qApp.currentOrgId() if not eventTypeCode: eventTypeCode = '01' CPreCreateEventDialog._eventTypeId = getEventType( eventTypeCode).eventTypeId if QtGui.qApp.userSpecialityId: CPreCreateEventDialog._personId = QtGui.qApp.userId elif personId and db.getRecordEx(tablePerson, 'id', [ tablePerson['id'].eq(personId), tablePerson['code'].eq(personCode) ]) is not None: CPreCreateEventDialog._personId = personId elif personCode: CPreCreateEventDialog._personId = forceRef( db.translate('Person', 'code', personCode, 'id')) if personCode else None CPreCreateEventDialog._assistantId = forceRef( db.translate('Person', 'code', assistantCode, 'id')) if assistantCode else None CPreCreateEventDialog._curatorId = forceRef( db.translate('Person', 'code', curatorCode, 'id')) if curatorCode else None CPreCreateEventDialog._includeRedDays = includeRedDays CPreCreateEventDialog._tissueTypeId = forceRef( db.translate('rbTissueType', 'code', tissueTypeCode, 'id')) if tissueTypeCode else None CPreCreateEventDialog._selectPreviousActions = selectPreviousActions CPreCreateEventDialog._referralType = referralType
def getTimeRange(actionTypeCode, date, personId): timeRange = ('--:--', '--:--') db = QtGui.qApp.db eventTypeId = getEventType(etcTimeTable).eventTypeId eventTable = db.table('Event') cond = [ eventTable['deleted'].eq(0), eventTable['eventType_id'].eq(eventTypeId), eventTable['execDate'].eq(date), eventTable['execPerson_id'].eq(personId) ] event = db.getRecordEx(eventTable, '*', cond) if event: eventId = forceRef(event.value('id')) action = CAction.getAction(eventId, actionTypeCode) begTime = action['begTime'] endTime = action['endTime'] if begTime and endTime: timeRange = begTime.toString( 'H:mm') + ' - ' + endTime.toString('H:mm') return timeRange
def loadData(self, clientId=None): if clientId: currentDateTime = forceDateTime(QtCore.QDateTime.currentDateTime()) etcQueue = 'queue' atcQueue = 'queue' db = QtGui.qApp.db tableEvent = db.table('Event') tableAction = db.table('Action') tableVisit = db.table('Visit') tablePersonWithSpeciality = db.table('vrbPersonWithSpeciality') tableActionProperty_Action = db.table('ActionProperty_Action') tableOrgStructure = db.table('OrgStructure') cols = [ tableAction['event_id'], tableAction['id'], tableAction['directionDate'], tableAction['setPerson_id'], tableAction['person_id'], tableAction['office'], tableAction['note'], tablePersonWithSpeciality['speciality_id'] ] actionType = CActionTypeCache.getByCode(atcQueue) actionTypeId = actionType.id eventType = getEventType(etcQueue) eventTypeId = eventType.eventTypeId tableQuery = tableAction tableQuery = tableQuery.innerJoin( tableEvent, tableEvent['id'].eq(tableAction['event_id'])) tableQuery = tableQuery.innerJoin( tableActionProperty_Action, tableActionProperty_Action['value'].eq(tableAction['id'])) tableQuery = tableQuery.innerJoin( tablePersonWithSpeciality, tablePersonWithSpeciality['id'].eq(tableAction['person_id'])) cond = [ tableEvent['client_id'].eq(clientId), tableAction['directionDate'].lt(currentDateTime), tableEvent['deleted'].eq(0), tableAction['deleted'].eq(0), tableEvent['eventType_id'].eq(eventTypeId), tableAction['actionType_id'].eq(actionTypeId) ] recordBufferAction = db.getRecordList(tableQuery, cols, cond, 'Action.directionDate') listDirectionDateAction = [] specialityIdList = [] personIdList = [] for recordDirectionDateAction in recordBufferAction: directionDate = forceDate( recordDirectionDateAction.value('directionDate')) if directionDate and directionDate not in listDirectionDateAction: listDirectionDateAction.append(directionDate) specialityId = forceRef( recordDirectionDateAction.value('speciality_id')) if specialityId and specialityId not in specialityIdList: specialityIdList.append(specialityId) personId = forceRef( recordDirectionDateAction.value('person_id')) if personId and personId not in personIdList: personIdList.append(personId) if listDirectionDateAction: cols = [ tableVisit['date'], tableVisit['person_id'], tableVisit['event_id'].alias('eventId'), tablePersonWithSpeciality['speciality_id'], tablePersonWithSpeciality['name'].alias('personName') ] condVisit = [ tableVisit['date'].inlist(listDirectionDateAction), tableEvent['client_id'].eq(clientId), tableEvent['deleted'].eq(0), tableVisit['deleted'].eq(0) ] condVisit.append( db.joinOr([ tablePersonWithSpeciality['speciality_id'].inlist( specialityIdList), tableVisit['person_id'].inlist(personIdList) ])) tableQueryVisit = tableVisit tableQueryVisit = tableQueryVisit.innerJoin( tableEvent, tableEvent['id'].eq(tableVisit['event_id'])) tableQueryVisit = tableQueryVisit.innerJoin( tablePersonWithSpeciality, tablePersonWithSpeciality['id'].eq( tableVisit['person_id'])) recordVisit = db.getRecordList(tableQueryVisit, cols, condVisit, 'Visit.date') for record in recordBufferAction: directionDate = forceDate(record.value('directionDate')) personId = forceRef(record.value('person_id')) specialityId = forceRef(record.value('speciality_id')) visitEventId = self.getVisit(directionDate, personId, specialityId, recordVisit) record.setValue('event_id', toVariant(visitEventId)) self.setItems(recordBufferAction) else: self.clearItems()
def __init__(self, parent, eventTypeFilterHospitalization=None, dateTime=None, personId=None, orgStructureId=None, externalId='', clientId=None, begDate=None, endDate=None, referralId=None): CDialogBase.__init__(self, parent) self.dateTime = dateTime self._clientId = clientId self.setupUi(self) self.edtPlannedDate.setDate(QtCore.QDate()) self.edtDate.setDate(QtCore.QDate()) if not CPreCreateEventDialog._orgId: self.loadDefaults() db = QtGui.qApp.db cond = [ getWorkEventTypeFilter(), getOrgStructureEventTypeFilter( orgStructureId if orgStructureId else QtGui.qApp. currentOrgStructureId()), eventTypeFilterHospitalization if eventTypeFilterHospitalization else '1', 'deleted = 0', 'EventType.filterPosts = 0 OR ' ' EXISTS(SELECT etp.id ' ' FROM EventType_Post etp ' ' WHERE etp.post_id = %s AND ' ' etp.eventType_id = EventType.id)' % (QtGui.qApp.userPostId or '-1'), 'EventType.filterSpecialities = 0 OR ' ' EXISTS(SELECT etp.id ' ' FROM EventType_Speciality etp ' ' WHERE etp.speciality_id = %s AND ' ' etp.eventType_id = EventType.id)' % (QtGui.qApp.userSpecialityId or '-1') ] if db.getRecordEx( 'Client_PaymentScheme c INNER JOIN PaymentScheme p ON p.id = c.paymentScheme_id', 'c.id', 'c.client_id = %s AND p.type = 0 AND c.deleted = 0' % self._clientId) is not None: CPreCreateEventDialog._eventTypeId = getEventType( 'protocol').eventTypeId else: cond.append('code != \'protocol\'') self.cmbEventType.setTable('EventType', False, db.joinAnd(cond), group='id') self.cmbTissueType.setTable('rbTissueType') self.cmbOrg.setValue(CPreCreateEventDialog._orgId) self.cmbRelegateOrg.setValue(CPreCreateEventDialog._relegateOrgId) if CPreCreateEventDialog._eventTypeId is None: self.cmbEventType.setCurrentIndex(0) CPreCreateEventDialog._eventTypeId = self.cmbEventType.value() else: self.cmbEventType.setValue(CPreCreateEventDialog._eventTypeId) if QtGui.qApp.currentOrgStructureId(): self.cmbPerson.setOrgStructureId( QtGui.qApp.currentOrgStructureId()) if orgStructureId: self.cmbPerson.setOrgStructureId(orgStructureId) self.cmbOrgStructure.setOrgId(CPreCreateEventDialog._orgId) self.cmbPerson.setValue( personId if personId else CPreCreateEventDialog._personId) eventType = self.cmbEventType.value() if hasEventAssistant(eventType): self.cmbAssistantId.setValue(CPreCreateEventDialog._assistantId) if hasEventCurator(eventType): self.cmbCuratorId.setValue(CPreCreateEventDialog._curatorId) self.chkAddVisits.setChecked(CPreCreateEventDialog._addVisits) self.chkIncludeRedDays.setChecked( CPreCreateEventDialog._includeRedDays) self.cmbTissueType.setValue(CPreCreateEventDialog._tissueTypeId) self.chkSelectPreviousActions.setChecked( CPreCreateEventDialog._selectPreviousActions) self.cmbReferralType.setTable('rbReferralType') if forceInt(CPreCreateEventDialog._referralType): self.cmbReferralType.setValue(CPreCreateEventDialog._referralType) self.prefix = '' self.on_cmbEventType_currentIndexChanged(0) self.edtExternalId.setText(externalId if externalId else '') self.edtPlannedDate.setMinimumDate(QtCore.QDate.currentDate()) self.edtDate.setMinimumDate(QtCore.QDate.currentDate().addMonths(-6)) self.edtDate.setMaximumDate(QtCore.QDate.currentDate()) self.setupReferral() self.useArmyRef = False self.btnAppointment.setVisible( forceBool(getVal(QtGui.qApp.preferences.appPrefs, 'EGISZ', False))) if not CPreCreateEventDialog._connected: QtGui.qApp.connect(QtGui.qApp, QtCore.SIGNAL('dbConnectionChanged(bool)'), CPreCreateEventDialog.onConnectionChanged) CPreCreateEventDialog._connected = True self._isNosologyInit = False if not QtGui.qApp.isSupportCreateNosologyEvent(): self.tabWidget.setTabEnabled(1, False) if begDate: self.edtEventSetDate.setDate(begDate.date()) self.edtEventSetTime.setTime(begDate.time()) #FIXME:skkachaev: Предпологается, что у эвента, который мы пересоздаём, setDate есть всегда self.isRecreated = True if endDate: self.edtEventDate.setDate(endDate.date()) self.edtEventTime.setTime(endDate.time()) self.edtPlannedDate.setDate(QtCore.QDate.currentDate()) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setDefault(True) if QtGui.qApp.changeFocusInPreCreateEvent(): self.cmbEventType.setFocus(QtCore.Qt.OtherFocusReason) self._invisibleObjectsNameList = self.reduceNames(QtGui.qApp.userInfo.hiddenObjectsNameList([self.moduleName()])) \ if QtGui.qApp.userInfo else [] self.updateVisibleState(self, self._invisibleObjectsNameList) if referralId: # showDefaultHint(u'Найдено направление', u'Данные заполнены автоматически') tblReferral = db.table('Referral') recReferral = db.getRecordEx(tblReferral, '*', tblReferral['id'].eq(referralId)) # self.grpReferral.setChecked(True) self.cmbReferralType.setValue(forceInt(recReferral.value('type'))) self.edtNumber.setText(forceString(recReferral.value('number'))) self.cmbRelegateOrg.setValue( forceInt(recReferral.value('relegateOrg_id'))) self.edtDate.setDate(forceDate(recReferral.value('date'))) self.edtPlannedDate.setDate( forceDate(recReferral.value('hospDate'))) self.cmbSpeciality.setValue( forceInt(recReferral.value('medProfile_id'))) self.cmbMKB.setText(forceString(recReferral.value('MKB'))) self.edtPerson.setText(forceString(recReferral.value('person')))