def buildTable(table, masterRecord): i = 1 for org in masterRecord.orgs: numRows = reduce(lambda res, x: (res + x), map(lambda x: len(x.services), org.performers), 0) + len(org.performers) row = perfStartRow = orgStartRow = table.addRow() for performer in org.performers: numRowsPerf = len(performer.services) for service in performer.services: table.setText(row, 3, service.name) table.setText(row, 4, service.amount) table.setText(row, 5, service.price) table.setText(row, 6, service.sum) row = table.addRow() table.setText(row, 3, u'Итого') table.setText(row, 4, performer.amount) table.setText(row, 6, performer.sum) table.mergeCells(perfStartRow, 2, numRowsPerf + 1, 1) table.setText(perfStartRow, 2, performer.name) row = perfStartRow = table.addRow() table.setText(row, 2, u'Итого') table.setText(row, 4, org.amount) table.setText(row, 6, org.sum) table.mergeCells(orgStartRow, 0, numRows + 1, 1) table.mergeCells(orgStartRow, 1, numRows + 1, 1) table.setText(orgStartRow, 1, getOrgStructureName(org.id)) table.setText(orgStartRow, 0, i) i += 1 row = table.addRow() table.mergeCells(row, 0, 1, 4) table.setText(row, 0, u'ИТОГО') table.setText(row, 4, masterRecord.amount) table.setText(row, 6, masterRecord.sum)
def getDescription(self, params): db = QtGui.qApp.db begDate = params.get('begDate', None) endDate = params.get('endDate', None) eventTypeIdList = params.get('eventTypeIdList', []) orgStructureId = params.get('orgStructureId', None) ageFrom = params.get('ageFrom', None) ageTo = params.get('ageTo', 150) sex = params.get('sex', 0) rows = [] if begDate and endDate: rows.append(u'за период с {0} по {1}'.format( forceString(begDate), forceString(endDate))) if eventTypeIdList: rows.append(u'типы обращений: {0}'.format(u', '.join([ forceString(db.translate('EventType', 'id', id, 'code')) for id in eventTypeIdList ]))) if orgStructureId: rows.append(u'подразделение: {0}'.format( getOrgStructureName(orgStructureId))) if (not ageFrom is None) and (not ageTo is None): rows.append(u'возраст: с {0} по {1}'.format( ageFrom, formatNum(ageTo, [u'год', u'года', u'лет']))) if sex: rows.append(u'пол: {0}'.format(formatSex(sex))) return rows
def getDescription(self, params): byPeriod = params.get('byPeriod', False) leavedDate = params.get('leavedDate', QtCore.QDate()) byReceivedDate = params.get('byReceivedDate', False) receivedBegDate = params.get('receivedBegDate', QtCore.QDate()) receivedEndDate = params.get('receivedEndDate', QtCore.QDate()) byLeavedDate = params.get('byLeavedDate', True) leavedBegDate = params.get('leavedBegDate', QtCore.QDate()) leavedEndDate = params.get('leavedEndDate', QtCore.QDate()) orgStructureId = params.get('orgStructureId', None) rows = [] if byPeriod: if byReceivedDate: rows.append( u'Период поступления: с {begDate} по {endDate}'.format( begDate=receivedBegDate.toString('dd/MM/yyyy'), endDate=receivedEndDate.toString('dd/MM/yyyy'))) if byLeavedDate: rows.append(u'Период выписки: с {begDate} по {endDate}'.format( begDate=leavedBegDate.toString('dd/MM/yyyy'), endDate=leavedEndDate.toString('dd/MM/yyyy'))) else: rows.append(u'Дата выписки: {date}'.format( date=leavedDate.toString('dd/MM/yyyy'))) if not orgStructureId is None: rows.append(u'Отделение: {orgStructure}'.format( orgStructure=getOrgStructureName(orgStructureId))) return rows
def dumpParams(self, cursor, params, charFormat = QtGui.QTextCharFormat()): description = self.getDescription(params) description.append(u'Тип финансирования: ДМС') description.append(u'Отделение: ' + getOrgStructureName(params.get('orgStructId', u'Все'))) description.append(u'За период: ' + forceDateTime(params.get('begDateTime')).toString('dd.MM.yyyy hh:mm') + u' по ' + forceDateTime(params.get('endDateTime')).toString('dd.MM.yyyy hh:mm')) columns = [ ('100%', [], CReportBase.AlignLeft) ] table = createTable(cursor, columns, headerRowCount=len(description), border=0, cellPadding=2, cellSpacing=0) for i, row in enumerate(description): table.setText(i, 0, row, charFormat = charFormat) cursor.movePosition(QtGui.QTextCursor.End) cursor.insertBlock()
def setJobInfo(self, jobId): db = QtGui.qApp.db record = db.getRecord('Job', '*', jobId) orgStructureId = forceRef(record.value('orgStructure_id')) jobTypeId = forceRef(record.value('jobType_id')) self.lblOrgStructureValue.setText(getOrgStructureName(orgStructureId)) jobTypeRec = db.getRecord('rbJobType', '*', jobTypeId) if jobTypeRec: self.lblJobTypeValue.setText(forceString(jobTypeRec.value('name'))) self.actionStatusChanger = forceInt(jobTypeRec.value('actionStatusChanger')) self.actionPersonChanger = forceInt(jobTypeRec.value('actionPersonChanger')) self.actionDateChanger = forceInt(jobTypeRec.value('actionDateChanger')) self.jobStatusModifier = forceInt(jobTypeRec.value('jobStatusModifier'))
def dumpParams(self, cursor, params, charFormat=QtGui.QTextCharFormat()): description = self.getDescription(params) description.append(u'Тип финансирования: ДМС') description.append( u'Плательщик: ' + getOrganisationShortName(params.get('organisationId', u'Все'))) description.append( u'Подразделение пребывания пациента: ' + getOrgStructureName(params.get('orgStructId', u'Все'))) columns = [('100%', [], CReportBase.AlignLeft)] table = createTable(cursor, columns, headerRowCount=len(description), border=0, cellPadding=2, cellSpacing=0) for i, row in enumerate(description): table.setText(i, 0, row, charFormat=charFormat) cursor.movePosition(QtGui.QTextCursor.End) cursor.insertBlock()
def getDescription(self, params): begDate = params.get('begDate', None) endDate = params.get('endDate', None) policyType = params.get('policyType', 0) policyTypeText = params.get('policyTypeText', '') attacheTypeTemporary = params.get('attacheTypeTemporary', 0) attacheTypeTemporaryText = params.get('attacheTypeTemporaryText', '') orgStructureId = params.get('orgStructureId', None) rows = [] if begDate: rows.append(u'Начальная дата периода: %s' % forceString(begDate)) if endDate: rows.append(u'Конечная дата периода: %s' % forceString(endDate)) if policyType: rows.append(u'Тип полиса: %s' % policyTypeText) if attacheTypeTemporary: rows.append(u'Тип прикрепления: %s' % attacheTypeTemporaryText) if orgStructureId: rows.append(u'Подразделение: %s' % getOrgStructureName(orgStructureId)) return rows
def build(self, params): query = selectData(params) self.setQueryText(forceString(query.lastQuery())) doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [('30%', [u'Код услуги'], CReportBase.AlignLeft), ('30%', [u'Наименование услуги'], CReportBase.AlignLeft), ('10%', [u'Кол-во'], CReportBase.AlignLeft), ('10%', [u'Цена за ед.'], CReportBase.AlignLeft), ('20%', [u'Сумма'], CReportBase.AlignLeft)] table = createTable(cursor, tableColumns) masterRecord = MasterRecord() while query.next(): record = query.record() doctorName = forceString( record.value('doctorName')) + ', ' + getOrgStructureName( record.value('orgStructureId')) service = ServiceRecord(forceString(record.value('serviceCode')), forceString(record.value('serviceName')), forceInt(record.value('amount')), forceInt(record.value('price')), forceInt(record.value('sum'))) masterRecord.addElement(doctorName, service) buildTable(table, masterRecord) return doc
def buildTable(table, masterRecord, type): for org in masterRecord.orgs: numRows = len(org.services) row = startRow = table.addRow() for service in org.services: table.setText(row, 1, service.name) table.setText(row, 2, service.amount) if type == 0: table.setText(row, 3, service.price) table.setText(row, 4, service.sum) row = table.addRow() table.setText(row, 1, u'Итого') table.setText(row, 2, org.amount) if type == 0: table.setText(row, 4, org.sum) table.mergeCells(startRow, 0, numRows + 1, 1) table.setText(startRow, 0, getOrgStructureName(org.id)) row = table.addRow() table.mergeCells(row, 0, 1, 2) table.setText(row, 0, u'ИТОГО') table.setText(row, 2, masterRecord.amount) if type == 0: table.setText(row, 4, masterRecord.sum)
def build(self, params): outputColumns = params.get('outputColumns') groupOrgStructure = params.get('chkGroupOrgStructure') clientDetail = params.get('clientDetail') totalCountBefore = 0 totalSumBefore = 0 totalCountAfter = 0 totalSumAfter = 0 row = 0 rowNumber = 0 orgStructureId = 0 curOrgStructureId = 0 orgStructureRow = 0 countBefore = 0 sumBefore = 0 countAfter = 0 sumAfter = 0 query = selectData(params) self.setQueryText(forceString(query.lastQuery())) doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) if groupOrgStructure: cursor.insertText(u'Группировка: по отделениям') if clientDetail: cursor.insertText(u'\nДетализация по пациентам') cursor.insertBlock() tableColumns = [('2%', [u'№'], CReportBase.AlignLeft)] queryFeild = [] for key in outputColumns.keys(): if outputColumns[key]: tableColumns.append( ('10%', [columns[key]], CReportBase.AlignLeft)) queryFeild.append(key) colDaysAfter = -1 colDaysBefore = -1 colOrgStructure = -1 widthOrgStructure = 0 for index, feild in enumerate(queryFeild): if feild == 'DaysAfter': colDaysAfter = index elif feild == 'DaysBefore': colDaysBefore = index if feild == 'ExternalId' or feild == 'ClientId' or feild == 'FullName': widthOrgStructure += 1 if colOrgStructure == -1: colOrgStructure = 1 table = createTable(cursor, tableColumns) if len(queryFeild): while query.next(): record = query.record() row = table.addRow() if groupOrgStructure: curOrgStructureId = forceRef( record.value('orgStructureId')) if orgStructureId != curOrgStructureId: if orgStructureRow: if colDaysAfter != -1: table.setText( orgStructureRow, colDaysAfter + 1, u'%.2f' % (float(sumAfter) / float(countAfter))) if colDaysBefore != -1: table.setText( orgStructureRow, colDaysBefore + 1, u'%.2f' % (float(sumBefore) / float(countBefore))) sumAfter = 0 countAfter = 0 sumBefore = 0 countBefore = 0 orgStructureRow = row if colOrgStructure != -1: table.setText( row, 1, getOrgStructureName(curOrgStructureId)) table.mergeCells(row, 1, 1, widthOrgStructure) row = table.addRow() orgStructureId = curOrgStructureId rowNumber += 1 for index, feild in enumerate(queryFeild): if feild == 'DaysAfter': days = forceInt(record.value('daysAfter')) if forceInt( record.value( 'lastMovingOrgHasDayStationary')) in ( 0, 1): days += forceInt( record.value( 'lastMovingOrgHasDayStationary')) elif forceInt( record.value( 'leavedOrgHasDayStationary')) in (0, 1): days += forceInt( record.value('leavedOrgHasDayStationary')) table.setText(row, index + 1, forceString(days)) countAfter += 1 sumAfter += days totalCountAfter += 1 totalSumAfter += days elif feild == 'DaysBefore': days = forceInt(record.value('DaysBefore')) table.setText(row, index + 1, forceString(days)) countBefore += 1 sumBefore += days totalCountBefore += 1 totalSumBefore += days elif feild: table.setText(row, index + 1, forceString(record.value(feild))) table.setText(row, 0, forceString(rowNumber)) if orgStructureRow: if colDaysAfter != -1: table.setText( orgStructureRow, colDaysAfter + 1, u'%.2f' % (float(sumAfter) / float(countAfter))) if colDaysBefore != -1: table.setText( orgStructureRow, colDaysBefore + 1, u'%.2f' % (float(sumBefore) / float(countBefore))) sumAfter = 0 countAfter = 0 sumBefore = 0 countBefore = 0 else: cursor.insertBlock() tableColumns = [('2%', [u'№'], CReportBase.AlignLeft), ('50%', [u'Отделение'], CReportBase.AlignLeft), ('20%', [u'Ср. кол-во дней до операции'], CReportBase.AlignLeft), ('20%', [u'Ср. кол-во дней после операции'], CReportBase.AlignLeft)] if groupOrgStructure: table = createTable(cursor, tableColumns) while query.next(): record = query.record() if groupOrgStructure: curOrgStructureId = forceRef( record.value('orgStructureId')) if orgStructureId != curOrgStructureId: row = table.addRow() if orgStructureRow: fields = ( orgStructureRow, forceString(getOrgStructureName(orgStructureId)), forceString( u'%.2f' % (float(sumBefore) / float(countBefore))), forceString(u'%.2f' % (float(sumAfter) / float(countAfter))), ) for col, val in enumerate(fields): table.setText(orgStructureRow, col, val) sumAfter = 0 countAfter = 0 sumBefore = 0 countBefore = 0 orgStructureRow = row orgStructureId = curOrgStructureId days = forceInt(record.value('daysAfter')) if forceInt( record.value('lastMovingOrgHasDayStationary')) in (0, 1): days += forceInt( record.value('lastMovingOrgHasDayStationary')) elif forceInt( record.value('leavedOrgHasDayStationary')) in (0, 1): days += forceInt(record.value('leavedOrgHasDayStationary')) countAfter += 1 sumAfter += days totalCountAfter += 1 totalSumAfter += days days = forceInt(record.value('DaysBefore')) countBefore += 1 sumBefore += days totalCountBefore += 1 totalSumBefore += days if orgStructureRow: fields = ( orgStructureRow, forceString(getOrgStructureName(orgStructureId)), forceString(u'%.2f' % (float(sumBefore) / float(countBefore))), forceString(u'%.2f' % (float(sumAfter) / float(countAfter))), ) for col, val in enumerate(fields): table.setText(orgStructureRow, col, val) cursor.movePosition(QtGui.QTextCursor.PreviousBlock) avgDaysBeforeOperation = '%.2f' % (float(totalSumBefore) / float( totalCountBefore)) if totalCountBefore > 0 else u'не доступно' avgDaysAfterOperation = '%.2f' % ( float(totalSumAfter) / float(totalCountAfter)) if totalCountAfter > 0 else u'не доступно' cursor.insertText(u'Среднее количество дней до операции: %s \n' % avgDaysBeforeOperation) cursor.insertText(u'Среднее количество дней после операции: %s' % avgDaysAfterOperation) return doc
def dumpParams(self, cursor, params, charFormat=QtGui.QTextCharFormat()): rows = [] if params.get('begDate'): rows.append(u'за период с %s по %s' % (forceString( params.get('begDate')), forceString(params.get('endDate')))) rows.append(u'ЗНО:') if params.get('ZNOFirst') == 1: rows.append(u'ЗНО установлен впервые') if params.get('ZNOFirst') == 2: rows.append(u'ЗНО установлен впервые не выставлено') if params.get('ZNOMorph') == 1: rows.append(u'ЗНО подтверждён морфологически') if params.get('ZNOMorph') == 2: rows.append(u'ЗНО подтверждён морфологически не выставлено') if params.get('chkAge'): rows.append(u'возраст: с %s по %s' % (forceString( params.get('ageFrom')), forceString(params.get('ageTo')))) if params.get('chkSex'): rows.append(u'пол: %s' % { 0: u'не указано', 1: u'М', 2: u'Ж' }[params.get('sex')]) if params.get('chkEmployment'): rows.append(u'трудоспособность: %s' % { 0: u'да', 1: u'нет' }[params.get('employment')]) if params.get('chkMKB'): rows.append(u'Коды диагноов по МКБ: с %s по %s' % (params.get('MKBFrom'), params.get('MKBTo'))) if params.get('chkEventType'): eventTypeNames = [ getEventTypeName(eventTypeId) for eventTypeId in params.get('eventTypeIdMulti') ] rows.append(u'тип обращения: %s' % u', '.join(eventTypeNames)) elif params.get('eventTypeId'): rows.append(u'тип обращения: %s' % getEventTypeName(params.get('eventTypeId'))) if params.get('chkOrgStructure'): orgStructureNames = [ getOrgStructureName(orgStructureId) for orgStructureId in params.get('orgStructureIdMulti') ] rows.append(u'подразделения: %s' % u', '.join(orgStructureNames)) elif params.get('orgStructureId'): rows.append(u'подразделение: %s' % getOrgStructureName(params.get('orgStructureId'))) if params.get('groupOrgStructure'): rows.append(u'группировка: по отделениям') if params.get('chkDistrict'): districtNames = [ getDistrictName(districtId) for districtId in params.get('districtIdMulti') ] rows.append(u'район: %s' % u', '.join(districtNames)) elif params.get('districtId'): rows.append(u'район: %s' % getDistrictName(params.get('districtId'))) if params.get('chkFinanceType'): financeTypeNames = [ getFinanceTypeName(financeTypeId) for financeTypeId in params.get('financeTypeIdMulti') ] rows.append(u'тип финансирования: %s' % u', '.join(financeTypeNames)) elif params.get('financeTypeId'): rows.append(u'тип финансирования: %s' % getFinanceTypeName(params.get('financeTypeId'))) rows.append((u'отчёт составлен: ' + forceString(QtCore.QDateTime.currentDateTime()))) columns = [('100%', [], CReportBase.AlignLeft)] table = createTable(cursor, columns, headerRowCount=len(rows), border=0, cellPadding=2, cellSpacing=0) for i, row in enumerate(rows): table.setText(i, 0, row, charFormat=charFormat) cursor.movePosition(QtGui.QTextCursor.End) cursor.insertBlock()
def saveData(self): result = True result = result and self.checkPersonAttach( self.cmbOrgStructure.value(), self.cmbPerson.value(), self.edtEventSetDate.date()) if QtGui.qApp.defaultNeedPreCreateEventPerson(): result = bool(self.cmbPerson.value()) or self.checkInputMessage( u'ответственного врача', False, self.cmbPerson) if self.grpReferral.isChecked(): # if self.edtPlannedDate.date().isNull(): # result = result and bool(self.checkInputMessage(u'дату планируемой госпитализации', False, self.edtPlannedDate)) if not self.edtNumber.text(): result = result and bool( self.checkInputMessage(u'номер направления', False, self.edtNumber)) if not self.cmbReferralType.value(): result = result and bool( self.checkInputMessage(u'тип направления', False, self.cmbReferralType)) if self.edtDate.date().isNull(): result = result and bool( self.checkInputMessage(u'дату выдачи направления', False, self.edtDate)) if not self.cmbRelegateOrg.value() and not self.edtFreeInput.text( ): result = result and bool( self.checkInputMessage(u'направителя', False, self.cmbRelegateOrg)) if self.edtPlannedDate.date().isNull(): result = result and bool( self.checkInputMessage( u'корректную дату плановой госпитализации', False, self.edtPlannedDate)) if not self.edtPlannedDate.date().isNull( ) and self.edtPlannedDate.date() < self.edtDate.date(): result = result and bool( self.checkInputMessage( u'корректную дату плановой госпитализации', False, self.edtPlannedDate)) if not self.edtPlannedDate.date().isNull( ) and self.edtPlannedDate.date() > self.edtDate.date().addMonths( 6): result = result and bool( self.checkInputMessage( u'корректную дату плановой госпитализации', False, self.edtPlannedDate)) # if not self.edtPerson.text(): # result = result and bool(self.checkInputMessage(u'врача', False, self.edtPerson)) if not self.cmbMKB.text(): result = result and bool( self.checkInputMessage(u'код МКБ', False, self.cmbMKB)) else: db = QtGui.qApp.db tableMKB = db.table('MKB') if not db.getRecordEx( tableMKB, tableMKB['id'], tableMKB['DiagID'].eq( forceString(self.cmbMKB.text()))): result = result and bool( self.checkInputMessage(u'верный код МКБ', False, self.cmbMKB)) result = result and ( not self.cmbPerson.value() or self.cmbOrgStructure.value() or self.checkInputMessage(u'подразделение работы врача', skipable=getPersonOrgId( self.cmbPerson.value()) is not None, widget=self.cmbOrgStructure)) if result: clientOrgStructureId = getClientAttachOrgStructure(self._clientId) personOrgStructureId = self.cmbOrgStructure.value() if clientOrgStructureId and personOrgStructureId and clientOrgStructureId != personOrgStructureId: result = result and self.checkValueMessage( u'Пациент относится к другому участку: <b>{0}</b>'.format( getOrgStructureName(clientOrgStructureId)), True, self.cmbOrgStructure) if result and self.checkOrGenerateUniqueEventExternalId(): self.saveDefaults() CPreCreateEventDialog._eventSetDate = self.edtEventSetDate.date() CPreCreateEventDialog._eventDate = self.edtEventDate.date() return True return result