def build3000(self, cursor, begDate, endDate, eventTypeId, onlyPermanentAttach, onlyPayedEvents, begPayDate, endPayDate): mapRows = createMapCodeToRowIdx([row[2] for row in Rows]) reportRowSize = 1 reportData = [[0] * reportRowSize for row in Rows] query = selectDiagnostics(begDate, endDate, eventTypeId, onlyPermanentAttach, onlyPayedEvents, begPayDate, endPayDate) while query.next(): record = query.record() clientId = forceInt(record.value('client_id')) mkb = normalizeMKB(forceString(record.value('mkb'))) diagRows = mapRows.get(mkb, []) for row in diagRows: reportData[row][0] += 1 # now text cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText( u'Результаты дополнительной диспансеризации работающих граждан') cursor.insertBlock() cursor.insertText(u'(3000)') cursor.insertBlock() tableColumns = [ ('50%', [ u'Заболевания и отклонения от нормы, выявленные при клинических и лабораторных исследованиях', '1' ], CReportBase.AlignLeft), ('5%', [u'№ строки', u'2'], CReportBase.AlignCenter), ('5%', [u'Код по МКБ-10', u'3'], CReportBase.AlignCenter), ('30%', [ u'Число заболеваний, впервые выявленных у граждан во время дополнительной диспансеризации', u'4' ], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) result = {} for iRow, row in enumerate(Rows): i = table.addRow() for j in xrange(3): table.setText(i, j, row[j]) for j in xrange(reportRowSize): table.setText(i, 3 + j, reportData[iRow][j]) result[row[2]] = reportData[iRow][0] return result
def buildInt(self, params, cursor): global Columns global Rows begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventTypeId = params.get('eventTypeId', None) onlyPermanentAttach = params.get('onlyPermanentAttach', False) onlyPayedEvents = params.get('onlyPayedEvents', False) begPayDate = params.get('begPayDate', QtCore.QDate()) endPayDate = params.get('endPayDate', QtCore.QDate()) mapColumns = createMapCodeToRowIdx( [column[0] for column in Columns] ) reportRowSize = len(Columns) reportData = [ [0] * reportRowSize for row in xrange(5) ] query = selectData(begDate, endDate, eventTypeId, onlyPermanentAttach, onlyPayedEvents, begPayDate, endPayDate) prevClientId = None clientData = None while query.next() : record = query.record() clientId = forceInt(record.value('client_id')) mkb = normalizeMKB(forceString(record.value('mkb'))) r2 = forceBool(record.value('R2b')) final = forceBool(record.value('final')) r3 = final and r2 and forceBool(record.value('R3c')) r4 = final and r2 and forceBool(record.value('R4c')) r5 = final and r2 and forceBool(record.value('R5c')) r6 = r5 and forceBool(record.value('R6c')) if prevClientId != clientId: addClientData(reportData, clientData) clientData = [ [False] * reportRowSize for row in xrange(5) ] prevClientId = clientId diagColumns = mapColumns.get(mkb, []) if not r2 and diagColumns: pass if r2: setSigns(clientData, 0, diagColumns) if r3: setSigns(clientData, 1, diagColumns) if r4: setSigns(clientData, 2, diagColumns) if r5: setSigns(clientData, 3, diagColumns) if r6: setSigns(clientData, 4, diagColumns) addClientData(reportData, clientData) # now text cursor.insertText(u'(3000)') cursor.insertBlock() tableColumns = [ ('15%', [u'Наименование заболевания', u'', u'1', u'Код по МКБ-10'], CReportBase.AlignLeft), ('5%', [u'№ строки', u'', u'2', '01'], CReportBase.AlignCenter), ('5%', [Columns[0][1], u'', u'3', Columns[0][0]], CReportBase.AlignRight), ] tableColumns.extend([('5%', [u'', Columns[i][1], str(i+3), Columns[i][0]], CReportBase.AlignRight) for i in xrange(1, len(Columns))]) table = createTable(cursor, tableColumns, headerRowCount=1, border=3, cellPadding=2, cellSpacing=0) table.mergeCells(0, 0, 2, 1) table.mergeCells(0, 1, 2, 1) table.mergeCells(0, 2, 2, 1) table.mergeCells(0, 3, 1, len(Columns)-1) for iRow, row in enumerate(Rows): i = table.addRow() for j in xrange(2): table.setText(i, j, row[j], CReportBase.TableHeader) for j in xrange(reportRowSize): table.setText(i, 2+j, reportData[iRow][j]) return dict(zip([c[0] for c in Columns], reportData[0]))
def build(self, params): begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) byPeriod = params.get('byPeriod', False) doctype = params.get('doctype', 0) tempInvalidReason = params.get('tempInvalidReason', None) onlyClosed = params.get('onlyClosed', True) orgStructureId = params.get('orgStructureId', None) personId = params.get('personId', None) insuranceOfficeMark = params.get('insuranceOfficeMark', 0) oldForm = params.get('oldForm', 0) tableRows = MainRows if oldForm else newMainRows mapMainRows = createMapCodeToRowIdx( [row[1] for row in tableRows if row[1]]) db = QtGui.qApp.db rowSize = 12 reportMainData = [[0] * rowSize for row in xrange(len(tableRows) * 2)] pregnancyRowIndex = len(tableRows) - 1 totalRowIndex = pregnancyRowIndex - 1 quarantineRowIndex = totalRowIndex - 1 sanatoriumRowIndex = quarantineRowIndex - 1 careRowIndex = sanatoriumRowIndex - 1 query = selectData(begDate, endDate, byPeriod, doctype, tempInvalidReason, onlyClosed, orgStructureId, personId, insuranceOfficeMark) self.setQueryText(forceString(query.lastQuery())) while query.next(): record = query.record() reasonGroup = forceInt(record.value('reasonGroup')) reasonCode = forceString(record.value('reasonCode')) duration = forceInt(record.value('duration')) if reasonGroup == 1: ## уход # sex = forceInt(record.value('sex')) # age = calcAgeInYears(forceDate(record.value('birthDate')), forceDate(record.value('begDate'))) sex = forceInt(record.value('tsex')) age = forceInt(record.value('tage')) else: sex = forceInt(record.value('sex')) age = calcAgeInYears(forceDate(record.value('birthDate')), forceDate(record.value('caseBegDate'))) rows = [] if reasonGroup == 0: ## заболевание MKB = forceString(record.value('MKB')) if MKB[:2] == 'N7': pass rows.extend(mapMainRows.get(normalizeMKB(MKB), [])) if rows or MKB[:1] == 'Z': rows.append(totalRowIndex) elif reasonGroup == 1: ## уход if reasonCode in (u'09', u'12', u'13', u'15'): # уход за больным rows = [careRowIndex, totalRowIndex] elif reasonCode == u'03': # карантин rows = [quarantineRowIndex, totalRowIndex] elif reasonCode == u'14': # поствакцинальное осложнение rows = [quarantineRowIndex, totalRowIndex] elif reasonCode == u'08': # санкурлечение rows = [sanatoriumRowIndex, totalRowIndex] elif reasonGroup == 2: rows = [pregnancyRowIndex] # if age <15: # continue if sex not in [1, 2]: continue ageCol = min(max(age, 15), 60) / 5 - 1 for row in rows: reportLine = reportMainData[row * 2 + (1 if sex == 1 else 0)] reportLine[0] += duration reportLine[1] += 1 reportLine[ageCol] += 1 # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.name) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('15%', [u'Причина нетрудоспособности', u'', u'1'], CReportBase.AlignLeft), ('10%', [u'Код по МКБ X', u'', u'2'], CReportBase.AlignLeft), ('5%', [u'Пол', u'', u'3'], CReportBase.AlignCenter), ('5%', [u'№ строки', u'', u'4'], CReportBase.AlignRight), ('10%', [u'число дней', u'', u'5'], CReportBase.AlignRight), ('5%', [u'число случаев', u'', u'6'], CReportBase.AlignRight), ('5%', [u'в т.ч. по возрастам', u'15-19', u'7'], CReportBase.AlignRight), ('5%', [u'', u'20-24', u'8'], CReportBase.AlignRight), ('5%', [u'', u'25-29', u'9'], CReportBase.AlignRight), ('5%', [u'', u'30-34', u'10'], CReportBase.AlignRight), ('5%', [u'', u'35-39', u'11'], CReportBase.AlignRight), ('5%', [u'', u'40-44', u'12'], CReportBase.AlignRight), ('5%', [u'', u'45-49', u'13'], CReportBase.AlignRight), ('5%', [u'', u'50-54', u'14'], CReportBase.AlignRight), ('5%', [u'', u'55-59', u'15'], CReportBase.AlignRight), ('5%', [u'', u'60 и старше', u'16'], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 2, 1) # п.н. table.mergeCells(0, 1, 2, 1) # мкб table.mergeCells(0, 2, 2, 1) # пол table.mergeCells(0, 3, 2, 1) # N table.mergeCells(0, 4, 2, 1) # дней table.mergeCells(0, 5, 2, 1) # случаев table.mergeCells(0, 6, 1, 10) # по возрастам for row, rowDescr in enumerate(tableRows): i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 1, rowDescr[1]) rowSep = rowDescr[2] if rowSep[0] > 0 and rowSep[1] > 0: i1 = table.addRow() table.mergeCells(i, 0, 2, 1) # п.н. table.mergeCells(i, 1, 2, 1) # мкб mTableRow = i wTableRow = i1 elif rowSep[0] > 0: mTableRow = -1 wTableRow = i else: mTableRow = i wTableRow = -1 if wTableRow >= 0: table.setText(wTableRow, 2, u'ж') table.setText(wTableRow, 3, rowSep[0]) reportLine = reportMainData[row * 2] for col in xrange(rowSize): table.setText(wTableRow, 4 + col, reportLine[col]) if mTableRow >= 0: table.setText(mTableRow, 2, u'м') table.setText(mTableRow, 3, rowSep[1]) reportLine = reportMainData[row * 2 + 1] for col in xrange(rowSize): table.setText(mTableRow, 4 + col, reportLine[col]) return doc
def build(self, params): registeredInPeriod = params.get('registeredInPeriod', False) begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventPurposeIdList = params.get('eventPurposeIdList', []) eventTypeId = params.get('eventTypeId', None) orgStructureId = params.get('orgStructureId', None) personId = params.get('personId', None) sex = params.get('sex', 0) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) socStatusClassId = params.get('socStatusClassId', None) socStatusTypeId = params.get('socStatusTypeId', None) areaIdEnabled = params.get('areaIdEnabled', None) areaId = params.get('areaId', None) locality = params.get('locality', 0) query = selectData(registeredInPeriod, begDate, endDate, eventPurposeIdList, eventTypeId, orgStructureId, personId, sex, ageFrom, ageTo, socStatusClassId, socStatusTypeId, areaIdEnabled, areaId, locality) mapRows = createMapCodeToRowIdx([row[1] for row in Rows]) rowSize = 3 reportData = [ [0]*rowSize for row in xrange(len(Rows)) ] while query.next(): record = query.record() MKB = normalizeMKB(forceString(record.value('MKB'))) sickCount = forceInt(record.value('sickCount')) firstInPeriod = forceBool(record.value('firstInPeriod')) observed = forceBool(record.value('observed')) cols = [0] if firstInPeriod: cols.append(1) if observed: cols.append(2) for row in mapRows.get(MKB, []): reportLine = reportData[row] for col in cols: reportLine[col] += sickCount # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('10%', [u'№ строки', ], CReportBase.AlignLeft), ('45%', [u'Наименование', ], CReportBase.AlignLeft), ('10%', [u'код МКБ', ], CReportBase.AlignLeft), ('10%', [u'Всего', ], CReportBase.AlignRight), ('10%', [u'В т.ч. впервые' ], CReportBase.AlignRight), ('10%', [u'Состоит на д.н. на конец периода'], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) for row, rowDescr in enumerate(Rows): reportLine = reportData[row] i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 2, rowDescr[1]) table.setText(i, 1, rowDescr[2]) for col in xrange(rowSize): table.setText(i, 3+col, reportLine[col]) return doc
def build(self, params): mapMainRows = createMapCodeToRowIdx( [row[2] for row in MainRows] ) registeredInPeriod = params.get('registeredInPeriod', False) begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventPurposeIdList = params.get('eventPurposeIdlist', []) eventTypeId = params.get('eventTypeId', None) orgStructureId = params.get('orgStructureId', None) personId = params.get('personId', None) sex = params.get('sex', 0) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) socStatusClassId = params.get('socStatusClassId', None) socStatusTypeId = params.get('socStatusTypeId', None) areaIdEnabled = params.get('areaIdEnabled', None) areaId = params.get('areaId', None) locality = params.get('locality', 0) reportData = [] reportLine = None prevDoctorId = None query = selectData(registeredInPeriod, begDate, endDate, eventPurposeIdList, eventTypeId, orgStructureId, personId, sex, ageFrom, ageTo, socStatusClassId, socStatusTypeId, areaIdEnabled, areaId, locality) rowSize = 15 report1000Data = [ [0]*rowSize for row in xrange(len(MainRows)) ] report2000Data = [ [0]*rowSize for row in xrange(len(MainRows)) ] while query.next() : record = query.record() age = forceInt(record.value('clientAge')) MKB = normalizeMKB(forceString(record.value('MKB'))) firstInLife = forceBool(record.value('firstInLife')) sickCount = forceInt(record.value('sickCount')) ageCol = min(max(age, 0), 60)/5 + (1 if age >= 18 else 0) + 1 for row in mapMainRows.get(MKB, []): reportLine = report1000Data[row] reportLine[0] += sickCount reportLine[ageCol] += sickCount if firstInLife: reportLine = report2000Data[row] reportLine[0] += sickCount reportLine[ageCol] += sickCount # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('15%', [u'Наименование болезни', u'', u'1' ], CReportBase.AlignLeft), ( '5%', [u'№ строки', u'', u'2' ], CReportBase.AlignRight), ( '5%', [u'Код по МКБ X', u'', u'3' ], CReportBase.AlignLeft), ( '5%', [u'Всего', u'', u'4' ], CReportBase.AlignRight), ( '5%', [u'в т.ч. у больных в возрасте (лет)', u'0-4', u'5' ], CReportBase.AlignRight), ( '5%', [u'', u'5-9', u'6' ], CReportBase.AlignRight), ( '5%', [u'', u'10-14', u'7' ], CReportBase.AlignRight), ( '5%', [u'', u'15-17', u'8' ], CReportBase.AlignRight), ( '5%', [u'', u'18-19', u'9' ], CReportBase.AlignRight), ( '5%', [u'', u'20-24', u'10'], CReportBase.AlignRight), ( '5%', [u'', u'25-29', u'11'], CReportBase.AlignRight), ( '5%', [u'', u'30-34', u'12'], CReportBase.AlignRight), ( '5%', [u'', u'35-39', u'13'], CReportBase.AlignRight), ( '5%', [u'', u'40-44', u'14'], CReportBase.AlignRight), ( '5%', [u'', u'45-49', u'15'], CReportBase.AlignRight), ( '5%', [u'', u'50-54', u'16'], CReportBase.AlignRight), ( '5%', [u'', u'55-59', u'17'], CReportBase.AlignRight), ( '5%', [u'', u'60 и старше', u'18'], CReportBase.AlignRight), ] cursor.insertText(u'(1000) Зарегистрировано заболеваний') cursor.insertBlock() self.addTable(cursor, tableColumns, report1000Data) cursor.movePosition(QtGui.QTextCursor.End) cursor.insertBlock() cursor.insertBlock() cursor.insertText(u'(2000) Зарегистрировано заболеваний c впервые в жизни установленным диагнозом') cursor.insertBlock() self.addTable(cursor, tableColumns, report2000Data) return doc
def build(self, params): begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) byPeriod = params.get('byPeriod', False) doctype = params.get('doctype', 0) tempInvalidReason = params.get('tempInvalidReason', None) onlyClosed = params.get('onlyClosed', True) orgStructureId = params.get('orgStructureId', None) personId = params.get('personId', None) durationFrom = params.get('durationFrom', 0) durationTo = params.get('durationTo', 0) sex = params.get('sex', 0) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) socStatusClassId = params.get('socStatusClassId', None) socStatusTypeId = params.get('socStatusTypeId', None) MKBFilter = params.get('MKBFilter', 0) MKBFrom = params.get('MKBFrom', '') MKBTo = params.get('MKBTo', '') insuranceOfficeMark = params.get('insuranceOfficeMark', 0) localRows = self.getRows() mapMainRows = createMapCodeToRowIdx([row[1] for row in localRows]) reportMainData = [{} for x in xrange(len(localRows))] outrangeRowIndex = len(localRows) - 1 zRowIndex = outrangeRowIndex - 1 pregnancyRowIndex = zRowIndex - 1 totalRowIndex = pregnancyRowIndex - 1 quarantineRowIndex = totalRowIndex - 1 sanatoriumRowIndex = quarantineRowIndex - 1 careRowIndex = sanatoriumRowIndex - 1 diseaseRowIndex = careRowIndex - 2 skipDetails = set([ totalRowIndex, quarantineRowIndex, sanatoriumRowIndex, careRowIndex, diseaseRowIndex ]) query = selectData(begDate, endDate, byPeriod, doctype, tempInvalidReason, onlyClosed, orgStructureId, personId, durationFrom, durationTo, sex, ageFrom, ageTo, socStatusClassId, socStatusTypeId, MKBFilter, MKBFrom, MKBTo, insuranceOfficeMark) totalCnt = 0 totalDays = 0 self.setQueryText(forceString(query.lastQuery())) while query.next(): record = query.record() reasonGroup = forceInt(record.value('reasonGroup')) reasonCode = forceString(record.value('reasonCode')) cnt = forceInt(record.value('cnt')) duration = forceInt(record.value('duration')) MKB = forceString(record.value('MKB')) rows = [] if reasonGroup == 0: ## заболевание # if MKB[:2] == 'N7': # pass rows.extend(mapMainRows.get(normalizeMKB(MKB), [])) if rows or MKB[:1] == 'Z': rows.append(totalRowIndex) elif reasonGroup == 1: ## уход if reasonCode in (u'09', u'12', u'13', u'15'): # уход за больным rows = [careRowIndex, totalRowIndex] elif reasonCode == u'03': # карантин rows = [quarantineRowIndex, totalRowIndex] elif reasonCode == u'14': # поствакцинальное осложнение rows = [quarantineRowIndex, totalRowIndex] elif reasonCode == u'08': # санкурлечение rows = [sanatoriumRowIndex, totalRowIndex] elif reasonGroup == 2: rows = [pregnancyRowIndex] if not rows: rows = [outrangeRowIndex] for row in rows: reportLineGroup = reportMainData[row] if row in skipDetails: diagData = reportLineGroup.setdefault('', [0, 0]) else: diagData = reportLineGroup.setdefault(MKB, [0, 0]) diagData[0] += cnt diagData[1] += duration totalCnt += cnt totalDays += duration # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.name) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('25%', [u'Причина нетрудоспособности', u'1'], CReportBase.AlignLeft), ('10%', [u'Группировка по коду МКБ', u'2'], CReportBase.AlignLeft), ('10%', [u'код МКБ', u'3'], CReportBase.AlignLeft), ('15%', [u'число случаев', u'4'], CReportBase.AlignRight), ('15%', [u'число дней', u'5'], CReportBase.AlignRight), ('15%', [u'средняя длительность', u'6'], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) for row, rowDescr in enumerate(localRows): i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 1, rowDescr[1]) reportLineGroup = reportMainData[row] if reportLineGroup: diags = reportLineGroup.keys() diags.sort() diagTotalCnt = 0 diagTotalDays = 0 for diagRow, MKB in enumerate(diags): if diagRow != 0: j = table.addRow() else: j = i diagInfo = reportLineGroup[MKB] table.setText(j, 2, MKB) table.setText(j, 3, diagInfo[0]) table.setText(j, 4, diagInfo[1]) if diagInfo[0]: table.setText(j, 5, '%1.2f' % (diagInfo[1] / diagInfo[0])) diagTotalCnt += diagInfo[0] diagTotalDays += diagInfo[1] if len(diags) > 1: j = table.addRow() table.setText(j, 2, u'всего', CReportBase.TableTotal) table.setText(j, 3, diagTotalCnt, CReportBase.TableTotal) table.setText(j, 4, diagTotalDays, CReportBase.TableTotal) if diagTotalCnt: table.setText( j, 5, '%1.2f' % (float(diagTotalDays) / diagTotalCnt), CReportBase.TableTotal) table.mergeCells(i, 0, len(diags) + 1, 1) # п.н. table.mergeCells(i, 1, len(diags) + 1, 1) # мкб i = table.addRow() table.setText(i, 0, u'ВСЕГО', CReportBase.TableTotal) table.mergeCells(i, 0, 1, 3) table.setText(i, 3, totalCnt, CReportBase.TableTotal) table.setText(i, 4, totalDays, CReportBase.TableTotal) if totalDays: table.setText(i, 5, '%1.2f' % (float(totalDays) / totalCnt), CReportBase.TableTotal) return doc
def build(self, params): def addOnes(rows, column): for row in rows: reportLine = reportData[row] reportLine[column] += 1 begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventTypeId = params.get('eventTypeId', None) onlyPermanentAttach = params.get('onlyPermanentAttach', False) onlyPayedEvents = params.get('onlyPayedEvents', False) begPayDate = params.get('begPayDate', QtCore.QDate()) endPayDate = params.get('endPayDate', QtCore.QDate()) workType = params.get('workType', 0) ownership = params.get('ownership', 0) db = QtGui.qApp.db mapRows = createMapCodeToRowIdx([row[2] for row in Rows]) reportRowSize = 7 reportData = [[0] * reportRowSize for row in Rows] query = selectDiagnostics(begDate, endDate, eventTypeId, onlyPermanentAttach, onlyPayedEvents, begPayDate, endPayDate) prevClientId = None prevMKB = None clientRowsP8 = set([]) clientRowsP9 = set([]) # clientRowsP10 = set([]) clientRowsP11 = set([]) while query.next(): record = query.record() if ownership > 0 and ownership != forceInt( record.value('ownership')): continue if workType > 0: okved = forceString(record.value('OKVED')) if workType not in OKVEDList.dispatch(okved): continue clientId = forceInt(record.value('client_id')) isPrimary = forceInt(record.value('isPrimary')) == 1 mkb = normalizeMKB(forceString(record.value('mkb'))) p4 = forceBool(record.value('P4')) p5 = forceBool(record.value('P5')) p6 = forceBool(record.value('P6')) p8 = forceBool(record.value('P8')) p9 = forceBool(record.value('P9')) p10 = forceBool(record.value('P10')) p11 = forceBool(record.value('P11')) diagRows = mapRows.get(mkb, []) if prevClientId != clientId or prevMKB != mkb: if not isPrimary: addOnes(diagRows, 6) if p4: addOnes(diagRows, 0) if p5: addOnes(diagRows, 1) if p6: addOnes(diagRows, 2) prevMKB = mkb if prevClientId != clientId: addOnes(clientRowsP8, 3) addOnes(clientRowsP9, 4) addOnes(clientRowsP11, 5) clientRowsP8 = set([]) clientRowsP9 = set([]) clientRowsP11 = set([]) prevClientId = clientId if p8: clientRowsP8.update(diagRows) if p9: clientRowsP9.update(diagRows) if p11: clientRowsP11.update(diagRows) addOnes(clientRowsP8, 4) addOnes(clientRowsP9, 4) addOnes(clientRowsP11, 5) # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) tableColumns = [ ('18%', [ u'Наименование заболевания (по классам и отдельным нозологиям)', u'', u'1' ], CReportBase.AlignLeft), ('6%', [u'№ строки', u'', u'2'], CReportBase.AlignCenter), ('10%', [u'Код по МКБ-10', u'', u'3'], CReportBase.AlignCenter), ('8%', [u'Заболевания', u'ранее изве-\nстное хрони-\nческое', u'4'], CReportBase.AlignRight), ('8%', [u'', u'выявле-\nнное во время доп. дисп.', u'5'], CReportBase.AlignRight), ('8%', [u'', u'в том числе на поздней стадии (из гр.5)', u'6'], CReportBase.AlignRight), ('8%', [ u'Госпитализировано больных (из числа выявленных - графа 5)', u'в стационар (в том числе субъе-\nкта РФ)', u'8' ], CReportBase.AlignRight), ('8%', [u'', u'в фед. спец. мед. уч. (для оказания ВМП)', u'9'], CReportBase.AlignRight), ('8%', [ u'Из числа граждан, прошедших доп. дисп. взято под дисп. набл.', u'', u'10' ], CReportBase.AlignRight), ('8%', [ u'Выявлено забо-\nлеваний в течение 6 месяцев после прохождения доп. дисп.', u'', u'11' ], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 2, 1) table.mergeCells(0, 1, 2, 1) table.mergeCells(0, 2, 2, 1) table.mergeCells(0, 3, 1, 3) table.mergeCells(0, 6, 1, 2) table.mergeCells(0, 8, 2, 1) table.mergeCells(0, 9, 2, 1) for iRow, row in enumerate(Rows): i = table.addRow() for j in xrange(3): table.setText(i, j, row[j]) for j in xrange(reportRowSize): table.setText(i, 3 + j, reportData[iRow][j]) return doc
def build(self, params): def addOnes(rows, column): for row in rows: reportData[row][column] += 1 global ColumnGroups begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventTypeId = params.get('eventTypeId', None) stageId = params.get('stageId', None) onlyPermanentAttach = params.get('onlyPermanentAttach', False) onlyPayedEvents = params.get('onlyPayedEvents', False) begPayDate = params.get('begPayDate', QtCore.QDate()) endPayDate = params.get('endPayDate', QtCore.QDate()) db = QtGui.qApp.db mapColumnGroups = createMapCodeToRowIdx( [columnGroup[0] for columnGroup in ColumnGroups] ) reportRowSize = 3 reportData = [ [0] * reportRowSize for columnGroup in ColumnGroups ] query = selectData(begDate, endDate, eventTypeId, stageId, onlyPermanentAttach, onlyPayedEvents, begPayDate, endPayDate) prevClientId = None prevMKB = None while query.next() : record = query.record() clientId = forceInt(record.value('client_id')) mkb = normalizeMKB(forceString(record.value('mkb'))) if prevClientId != clientId or prevMKB != mkb: prevClientId = clientId prevMKB = mkb diagColumnGroups = mapColumnGroups.get(mkb, []) addOnes(diagColumnGroups, 0) if forceBool(record.value('P1')): addOnes(diagColumnGroups, 1) if forceBool(record.value('P2')): addOnes(diagColumnGroups, 2) # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(u'Итоги дополнительной диспансеризации граждан') cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertText(u'(7000)') cursor.insertBlock() tableColumns = [ ('5%', [ u'Выявлено больных с социально-значимыми заболеваниями (код по МКБ-10)' if i == 0 else u'', ColumnGroups[i/3][1] if i%3 ==0 else u'', [u'всего', u'в том числе впер-\nвые выяв-\nлено', u'из них на заданных ста-\nдиях забо-\nлева\nния'][i%3], str(i+1) ], CReportBase.AlignRight ) for i in xrange(3*len(ColumnGroups)) ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 1, 3*len(ColumnGroups)) for i in xrange(len(ColumnGroups)): table.mergeCells(1, i*3, 1, 3) i = table.addRow() for j in xrange(3*len(ColumnGroups)): table.setText(i, j, reportData[j/3][j%3]) return doc
def build(self, params): begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventTypeId = params.get('eventTypeId', None) onlyPermanentAttach = params.get('onlyPermanentAttach', False) onlyPayedEvents = params.get('onlyPayedEvents', False) begPayDate = params.get('begPayDate', QtCore.QDate()) endPayDate = params.get('endPayDate', QtCore.QDate()) diagnosisType = params.get('diagnosisType', False) orgStructureAttachTypeId = params.get('orgStructureAttachTypeId', None) db = QtGui.qApp.db mapRows = createMapCodeToRowIdx( [row[2] for row in Rows] ) reportRowSize = 4 reportData = [ [0] * reportRowSize for row in Rows ] query = selectDiagnostics(begDate, endDate, eventTypeId, onlyPermanentAttach, onlyPayedEvents, begPayDate, endPayDate, diagnosisType, orgStructureAttachTypeId) self.setQueryText(forceString(query.lastQuery())) eventClosed = 0 eventClosedTeenager = 0 eventClosedPayed = 0 eventClosedPayedTeenager = 0 eventIdList = [] while query.next(): record = query.record() eventId = forceRef(record.value('eventId')) clientId = forceRef(record.value('client_id')) isPrimary = forceInt(record.value('isPrimary')) MKBRec = normalizeMKB(forceString(record.value('MKB'))) ageTeenager = forceInt(record.value('ageTeenager')) sex = forceInt(record.value('sex')) payedEvent = forceInt(record.value('payedEvent')) eventClosedPayedRec = forceInt(record.value('eventClosedPayed')) for row in mapRows.get(MKBRec, []): reportLine = reportData[row] reportLine[0] += 1 if sex == 1: reportLine[1] += 1 if isPrimary: reportLine[3] += 1 reportLine[2] += isPrimary if eventId and eventId not in eventIdList: eventIdList.append(eventId) eventClosed += 1 eventClosedTeenager += ageTeenager if eventClosedPayedRec: eventClosedPayed += 1 eventClosedPayedTeenager += ageTeenager doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertText(u'подразделение: ' + getOrgStructureFullName(orgStructureAttachTypeId)) cursor.insertBlock() cursor.insertBlock() cursor.insertText(u'''1. Число детей подлежащих диспансеризации: %s (человек), из них: 14-ти летних: %s (человек),'''%(str(eventClosed), str(eventClosedTeenager))) cursor.insertBlock() cursor.insertBlock() cursor.insertText(u'''2. Число детей прошедших диспансеризацию: %s (человек), из них: 14-ти летних: %s (человек)'''%(str(eventClosedPayed), str(eventClosedPayedTeenager))) cursor.insertBlock() cursor.insertBlock() cursor.insertText(u'''3. Структура выявленной патологии у подростков:''') cursor.insertBlock() tableColumns = [ ('18%', [u'Наименование заболевания (по классам и отдельным нозологиям)', u'1'], CReportBase.AlignLeft), ('2%', [u'№ строки', u'2'], CReportBase.AlignCenter), ('16%', [u'Код по МКБ-10', u'3'], CReportBase.AlignCenter), ('16%', [u'Всего зарегистрировано заболеваний', u'4'], CReportBase.AlignRight), ('16%', [u'в том числе у юношей (из графы 4)', u'5'], CReportBase.AlignRight), ('16%', [u'Из числа зарегистрированных заболеваний выявлено впервые (из графы 4)', u'6'], CReportBase.AlignRight), ('16%', [u'в том числе у юношей (из графы 6)', u'7'], CReportBase.AlignRight) ] table = createTable(cursor, tableColumns) for iRow, row in enumerate(Rows): i = table.addRow() for j in xrange(3): table.setText(i, j, row[j]) for j in xrange(reportRowSize): table.setText(i, 3+j, reportData[iRow][j]) return doc
def build(self, params): mapMainRows = createMapCodeToRowIdx( [row[1] for row in MainRows if row[1]]) registeredInPeriod = params.get('registeredInPeriod', False) begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventPurposeIdList = params.get('eventPurposeIdList', []) eventTypeId = params.get('eventTypeId', None) specialityId = params.get('specialityId', None) hurtType = params.get('hurtType', None) orgStructureId = params.get('orgStructureId', None) personId = params.get('personId', None) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) socStatusClassId = params.get('socStatusClassId', None) socStatusTypeId = params.get('socStatusTypeId', None) onlyFirstTime = params.get('onlyFirstTime', False) notNullTraumaType = params.get('notNullTraumaType', False) accountAccomp = params.get('accountAccomp', False) locality = params.get('locality', 0) onlyChilds = params.get('onlyChilds', False) isPrimary = params.get('isPrimary', 0) cutAdultColumnsCount = 12 if onlyChilds else 0 rowSize = 24 reportMainData = [[0] * rowSize for row in xrange(len(MainRows) * 2)] query = selectData(registeredInPeriod, begDate, endDate, eventPurposeIdList, eventTypeId, specialityId, hurtType, orgStructureId, personId, ageFrom, ageTo, socStatusClassId, socStatusTypeId, onlyFirstTime, notNullTraumaType, accountAccomp, locality, isPrimary) while query.next(): record = query.record() sickCount = forceInt(record.value('sickCount')) MKB = normalizeMKB(forceString(record.value('MKB'))) sex = forceInt(record.value('sex')) adult = forceBool(record.value('adult')) traumaType = forceString(record.value('traumaType')) mapTraumaTypeToColumns = mapAdultTraumaTypeToColumns if adult else mapChildTraumaTypeToColumns columns = mapTraumaTypeToColumns.get(traumaType, None) if not columns: columns = mapTraumaTypeToColumns[''] mapTraumaTypeToColumns[traumaType] = columns baseIndex = (0 if sex == 1 else 1) rows = mapMainRows.get(MKB, []) for row in rows: reportLine = reportMainData[baseIndex + row * 2] for column in columns: reportLine[column] += sickCount # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) # cursor.setCharFormat(CReportBase.ReportTitle) # cursor.insertText(u'Сведения о травмах, отравлениях и некоторых других последствиях воздействия внешних причин (Ф57)') # cursor.insertBlock() # cursor.setCharFormat(CReportBase.ReportBody) # cursor.insertText(u'за период с %s по %s' % (forceString(begDate), forceString(endDate))) # cursor.insertBlock() cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('15%', [ u'Травмы, отравления и некоторые другие последствия воздействия внешних причин', u'', u'', u'', u'1' ], CReportBase.AlignLeft), ('15%', [u'Код по МКБ X', u'', u'', u'', u'2'], CReportBase.AlignLeft), ('3%', [u'Пол', u'', u'', u'', u'3'], CReportBase.AlignCenter), ('3%', [u'№ стр.', u'', u'', u'', u'4'], CReportBase.AlignRight), ] if not onlyChilds: tableColumns.extend([ ('3%', [ u'У взрослых (18 лет и старше)', u'связанные с производством', u'пром', u'', u'5' ], CReportBase.AlignRight), ('3%', [u'', u'', u'с/х', u'', u'6'], CReportBase.AlignRight), ('3%', [u'', u'', u'трансп.', u'вс', u'7'], CReportBase.AlignRight), ('3%', [u'', u'', u'', u'авт', u'8'], CReportBase.AlignRight), ('3%', [u'', u'', u'пр', u'', u'9'], CReportBase.AlignRight), ('3%', [u'', u'быт', u'', u'', u'10'], CReportBase.AlignRight), ('3%', [u'', u'не связанные с производством', u'ул', u'', u'11'], CReportBase.AlignRight), ('3%', [u'', u'', u'трансп.', u'вс', u'12'], CReportBase.AlignRight), ('3%', [u'', u'', u'', u'авт', u'13'], CReportBase.AlignRight), ('3%', [u'', u'', u'спорт', u'', u'14'], CReportBase.AlignRight), ('3%', [u'', u'', u'пр', u'', u'15'], CReportBase.AlignRight), ('3%', [u'', u'ИТОГО', u'', u'', u'16'], CReportBase.AlignRight), ]) tableColumns.extend([ ('3%', [ u'У детей (0 - 17 лет включительно)', u'быт', u'', u'', '%d' % (17 - cutAdultColumnsCount) ], CReportBase.AlignRight), ('3%', [u'', u'ул', u'', u'', '%d' % (18 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'', u'трансп.', u'вс', u'', '%d' % (19 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'', u'', u'авт', u'', '%d' % (20 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'', u'шк', u'', u'', '%d' % (21 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'', u'спорт', u'', u'', '%d' % (22 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'', u'пр', u'', u'', '%d' % (23 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'', u'ИТОГО', u'', u'', '%d' % (24 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [u'ВСЕГО', u'', u'', u'', '%d' % (25 - cutAdultColumnsCount)], CReportBase.AlignRight), ('3%', [ u'Из гр.25', u'в рез. терр. дей-\nствий', u'', u'', '%d' % (26 - cutAdultColumnsCount) ], CReportBase.AlignRight), ('3%', [ u'Из гр.26', u'у взро-\nслых', u'', u'', '%d' % (27 - cutAdultColumnsCount) ], CReportBase.AlignRight), ('3%', [u'', u'у детей', u'', u'', '%d' % (28 - cutAdultColumnsCount)], CReportBase.AlignRight), ]) table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 4, 1) # п.н. table.mergeCells(0, 1, 4, 1) # мкб table.mergeCells(0, 2, 4, 1) # пол table.mergeCells(0, 3, 4, 1) # N if not onlyChilds: table.mergeCells(0, 4, 1, 12) # взрослые table.mergeCells(1, 4, 1, 5) # произв. table.mergeCells(2, 4, 2, 1) # пром table.mergeCells(2, 5, 2, 1) # сх table.mergeCells(2, 6, 1, 2) # тр table.mergeCells(2, 8, 2, 1) # проч table.mergeCells(1, 9, 3, 1) # быт table.mergeCells(1, 10, 1, 5) # непроизв. table.mergeCells(2, 10, 2, 1) # ул table.mergeCells(2, 11, 1, 2) # тр table.mergeCells(2, 13, 2, 1) # сп table.mergeCells(2, 14, 2, 1) # пр table.mergeCells(1, 15, 3, 1) # итого table.mergeCells(0, 16 - cutAdultColumnsCount, 1, 8) # дети table.mergeCells(1, 16 - cutAdultColumnsCount, 3, 1) # быт table.mergeCells(1, 17 - cutAdultColumnsCount, 3, 1) # ул table.mergeCells(1, 18 - cutAdultColumnsCount, 1, 2) # трансп table.mergeCells(2, 18 - cutAdultColumnsCount, 2, 1) # всего table.mergeCells(2, 19 - cutAdultColumnsCount, 2, 1) # авт table.mergeCells(1, 20 - cutAdultColumnsCount, 3, 1) # шк table.mergeCells(1, 21 - cutAdultColumnsCount, 3, 1) # сп table.mergeCells(1, 22 - cutAdultColumnsCount, 3, 1) # пр table.mergeCells(1, 23 - cutAdultColumnsCount, 3, 1) # итого table.mergeCells(0, 24 - cutAdultColumnsCount, 4, 1) # ВСЕГО table.mergeCells(1, 25 - cutAdultColumnsCount, 3, 1) # т.а. table.mergeCells(0, 26 - cutAdultColumnsCount, 1, 2) # т.а. - по возр. table.mergeCells(1, 26 - cutAdultColumnsCount, 3, 1) # т.а. - взрослые table.mergeCells(1, 27 - cutAdultColumnsCount, 3, 1) # т.а. - дети for row, rowDescr in enumerate(MainRows): man = table.addRow() woman = table.addRow() table.setText(man, 0, rowDescr[0]) table.setText(man, 1, rowDescr[1]) table.mergeCells(man, 0, 2, 1) # п.н. table.mergeCells(man, 1, 2, 1) # мкб table.setText(man, 2, u'М') table.setText(man, 3, row * 2 + 1) reportLine = reportMainData[row * 2] for column in xrange(rowSize): if onlyChilds and (0 <= column <= 11): continue table.setText(man, 4 + column - cutAdultColumnsCount, reportLine[column]) table.setText(woman, 2, u'Ж') table.setText(woman, 3, row * 2 + 2) reportLine = reportMainData[row * 2 + 1] for column in xrange(rowSize): if onlyChilds and (0 <= column <= 11): continue table.setText(woman, 4 + column - cutAdultColumnsCount, reportLine[column]) return doc
def build(self, params): begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) eventPurposeId = params.get('eventPurposeId', None) eventTypeId = params.get('eventTypeId', None) orgStructureId = params.get('orgStructureId', None) specialityId = params.get('specialityId', None) personId = params.get('personId', None) contractIdList = params.get('contractIdList', None) insurerId = params.get('insurerId', None) sex = params.get('sex', 0) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) mapRows = createMapCodeToRowIdx( [row[2] for row in Rows] ) rowSize = 1 + 8*2 reportData = [ [0]*rowSize for row in xrange(len(Rows)) ] query = selectData(begDate, endDate, eventPurposeId, eventTypeId, orgStructureId, specialityId, personId, contractIdList, insurerId, sex, ageFrom, ageTo) prevClientId = False clientRows = set([]) self.setQueryText(forceString(query.lastQuery())) while query.next(): record = query.record() clientId = forceRef(record.value('client_id')) MKB = normalizeMKB(forceString(record.value('MKB'))) medicalAidTypeCode = forceInt(record.value('medicalAidTypeCode')) sum = forceDouble(record.value('sum')) if prevClientId != clientId: for row in clientRows: reportData[row][0] += 1 prevClientId = clientId clientRows = set([]) if 1<=medicalAidTypeCode<=8: if medicalAidTypeCode in [2, 3]: cols = [1, medicalAidTypeCode] else: cols = [medicalAidTypeCode] for row in mapRows.get(MKB, []): clientRows.add(row) reportLine = reportData[row] for col in cols: reportLine[1+(col-1)*2] += 1 reportLine[1+(col-1)*2+1] += sum for row in clientRows: reportData[row][0] += 1 # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.name) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() cursor.insertText(u'Таблица 3. Стоимость нозологий по стандарту за законченный случай лечения') cursor.insertBlock() qnt = u'кол-во единиц учёта' sum = u'сумма (тыс.руб)' prc = u'стоимость случая (руб)' tableColumns = [ ('8%',[u'Наименование классов по МКБ (в т.ч. заболевания)', '', '', '', '1'], CReportBase.AlignLeft), ('3%', [u'код МКБ', '', '', '', '2'], CReportBase.AlignLeft), ('3%', [u'№ строки', '', '', '', '3'], CReportBase.AlignRight), ('3%', [u'численность пролеченных граждан, человек', '', '', '', '4'], CReportBase.AlignRight), ('3%', [u'Виды медицинской помощи', u'стационарная помощь',u'', qnt, '5'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '6'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '7'], CReportBase.AlignRight), ('3%', [u'', u'в том числе', u'высокотехнологичная помощь', qnt, '8'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '9'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc,'10'], CReportBase.AlignRight), ('3%', [u'', u'', u'специализированная стационарная помощь', qnt, '11'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '12'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '13'], CReportBase.AlignRight), ('3%', [u'', u'скорая помощь', u'', qnt, '14'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '15'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '16'], CReportBase.AlignRight), ('3%', [u'', u'скорая специализированная помощь', u'', qnt, '17'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '18'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '19'], CReportBase.AlignRight), ('3%', [u'', u'амбулаторная помощь', u'', qnt, '20'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '21'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '22'], CReportBase.AlignRight), ('3%', [u'', u'дневной стационар', u'', qnt, '23'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '24'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '25'], CReportBase.AlignRight), ('3%', [u'', u'санаторно-курортное лечение', u'', qnt, '26'], CReportBase.AlignRight), ('3%', [u'', u'', u'', sum, '27'], CReportBase.AlignRight), ('3%', [u'', u'', u'', prc, '28'], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 4, 1) # Наименование table.mergeCells(0, 1, 4, 1) # Код МКБ table.mergeCells(0, 2, 4, 1) # № стр. table.mergeCells(0, 3, 4, 1) # Человеки table.mergeCells(0, 4, 1, 3*8) # виды table.mergeCells(1, 4, 2, 3) # стац table.mergeCells(1, 7, 1, 6) # в т.ч. table.mergeCells(2, 7, 1, 3) # ВТМП table.mergeCells(2,10, 1, 3) # СпСтП table.mergeCells(1,13, 2, 3) # СкП table.mergeCells(1,16, 2, 3) # СпСкП table.mergeCells(1,19, 2, 3) # АП table.mergeCells(1,22, 2, 3) # ДнС table.mergeCells(1,25, 2, 3) # СКП for row, rowDescr in enumerate(Rows): reportLine = reportData[row] i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 1, rowDescr[2]) table.setText(i, 2, rowDescr[1]) table.setText(i, 3, reportLine[0]) for col in xrange(8): qnt = reportLine[1+col*2] sum = reportLine[1+col*2+1] prc = ('%.2f' % (sum/qnt)) if qnt else '' table.setText(i, 4+3*col, qnt) table.setText(i, 4+3*col+1, '%.2f'%(sum/1000)) table.setText(i, 4+3*col+2, prc) return doc
def build(self, params): mapMainRows = createMapCodeToRowIdx( [row[2] for row in MainRows] ) begDate = params.get('begDate', None) endDate = params.get('endDate', None) workOrgId = params.get('workOrgId', None) sex = params.get('sex', 0) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) areaIdEnabled = params.get('areaIdEnabled', False) areaId = params.get('areaId', None) MKBFilter = params.get('MKBFilter', 0) MKBFrom = params.get('MKBFrom', 'A00') MKBTo = params.get('MKBTo', 'Z99.9') MKBExFilter = params.get('MKBExFilter', 0) MKBExFrom = params.get('MKBExFrom', 'A00') MKBExTo = params.get('MKBExTo', 'Z99.9') socStatusType = params.get('socStatusType', None) socStatusClass = params.get('socStatusClass', None) orgStructureAttachTypeId = params.get('orgStructureAttachTypeId', None) personId = params.get('personId', None) endDate1 = forceString(endDate) endDate1 = endDate1.split('.') rowSize = 10 reportMainData = [ [0]*rowSize for row in xrange(len(MainRows)) ] query = QtGui.qApp.db.query(selectData(begDate, endDate, workOrgId, sex, ageFrom, ageTo, areaIdEnabled, areaId, MKBFilter, MKBFrom, MKBTo, MKBExFilter, MKBExFrom, MKBExTo, socStatusType, socStatusClass, self.forTeenager, orgStructureAttachTypeId, personId)) self.setQueryText(forceString(query.lastQuery())) while query.next() : record = query.record() MKB = normalizeMKB(forceString(record.value('MKB'))) endDispanserDate = forceDate(record.value('endDate')) dispanserId = forceInt(record.value('dispanser_id')) countSetInYear = forceInt(record.value('countSetInYear')) countExecInYear = forceInt(record.value('countExecInYear')) countSetFirstInYear = forceInt(record.value('countSetFirstInYear')) countInLastYear = forceInt(record.value('countInLastYear')) countInThisYear = forceInt(record.value('countInThisYear')) for row in mapMainRows.get(MKB, []): reportLine = reportMainData[row] reportLine[0] += countInLastYear reportLine[2] += countSetInYear reportLine[4] += countSetFirstInYear reportLine[6] += countExecInYear reportLine[8] += countInThisYear query = QtGui.qApp.db.query(selectDataHurt(begDate, endDate, workOrgId, sex, ageFrom, ageTo, areaIdEnabled, areaId, MKBFilter, MKBFrom, MKBTo, MKBExFilter, MKBExFrom, MKBExTo, socStatusType, socStatusClass, self.forTeenager, orgStructureAttachTypeId)) while query.next() : record = query.record() MKB = normalizeMKB(forceString(record.value('MKB'))) endDispanserDate = forceDate(record.value('endDate')) dispanserId = forceInt(record.value('dispanser_id')) countHurtSetInYear = forceInt(record.value('countHurtSetInYear')) countHurtExecInYear = forceInt(record.value('countHurtExecInYear')) countHurtSetFirstInYear = forceInt(record.value('countHurtSetFirstInYear')) countHurtInLastYear = forceInt(record.value('countHurtInLastYear')) countHurtInThisYear = forceInt(record.value('countHurtInThisYear')) for row in mapMainRows.get(MKB, []): reportLine = reportMainData[row] reportLine[1] += countHurtInLastYear reportLine[3] += countHurtSetInYear reportLine[5] += countHurtSetFirstInYear reportLine[7] += countHurtExecInYear reportLine[9] += countHurtInThisYear doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() if self.forTeenager: column = u'из нах мальчиков 15-17 лет' else: column = u'Из них с проф. вредностью' tableColumns = [ ('10%', [u'Нозологическая группа', u'', u''], CReportBase.AlignLeft), ('10%', [u'Код МКБ', u'', u''], CReportBase.AlignLeft), ('10%', [u'Состояло на начало %s года' %endDate1[2], u'Всего', u''], CReportBase.AlignLeft), ('10%', [u'', column, u''], CReportBase.AlignLeft), ('5%', [u'Взято на Д учёт в %s году' %endDate1[2], u'Всего', u''], CReportBase.AlignLeft), ('5%', [u'', column, u''], CReportBase.AlignLeft), ('5%', [u'', u'Из них с впервые установленным диагнозом в отчётном году (+)', u'Всего'], CReportBase.AlignLeft), ('5%', [u'', u'', column], CReportBase.AlignLeft), ('10%', [u'Снято с Д учёта в %s году' %endDate1[2], u'Всего', u''], CReportBase.AlignLeft), ('10%', [u'', column, u''], CReportBase.AlignLeft), ('10%', [u'Состоит на Д учёте на конец %s года' %endDate1[2], u'Всего', u''], CReportBase.AlignLeft), ('10%', [u'', column, u''], CReportBase.AlignLeft) ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 3, 1) # Наименование table.mergeCells(0, 1, 3, 1) # Код МКБ table.mergeCells(0, 2, 1, 2) # Состояло table.mergeCells(1, 2, 2, 1) table.mergeCells(1, 3, 2, 1) table.mergeCells(0, 4, 1, 4) # Взято на учёт table.mergeCells(1, 4, 2, 1) table.mergeCells(1, 5, 2, 1) table.mergeCells(1, 6, 1, 2) table.mergeCells(2, 6, 1, 1) table.mergeCells(2, 7, 1, 1) table.mergeCells(0, 8, 1, 2) #Снято с учёта table.mergeCells(1, 8, 2, 1) table.mergeCells(1, 9, 2, 1) table.mergeCells(0, 10, 1, 2) #Состоит на учёте table.mergeCells(1, 10, 2, 1) table.mergeCells(1, 11, 2, 1) for row, rowDescr in enumerate(MainRows): reportLine = reportMainData[row] i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 1, rowDescr[2]) table.setText(i, 2, reportLine[0]) table.setText(i, 3, reportLine[1]) table.setText(i, 4, reportLine[2]) table.setText(i, 5, reportLine[3]) table.setText(i, 6, reportLine[4]) table.setText(i, 7, reportLine[5]) table.setText(i, 8, reportLine[6]) table.setText(i, 9, reportLine[7]) table.setText(i, 10, reportLine[8]) table.setText(i, 11, reportLine[9]) cursor.movePosition(QtGui.QTextCursor.End) return doc
def build(self, params): # rowSize = 8 rowSize = 9 reportMainData = [[0] * rowSize for row in xrange(len(MainRows) * 2)] mapMainRows = createMapCodeToRowIdx( [row[1] for row in MainRows if row[1]]) totalRowIndex = len(MainRows) - 1 unknownDiagRowIndex = totalRowIndex - 1 otherDiagRowIndex = unknownDiagRowIndex # QtGui.qApp.beep() query = selectData(params) self.setQueryText(forceString(query.lastQuery())) while query.next(): record = query.record() cnt = forceInt(record.value('cnt')) age = forceInt(record.value('clientAge')) sex = forceInt(record.value('clientSex')) MKB = normalizeMKB(forceString(record.value('MKB'))) rows = [] if MKB: rows.extend(mapMainRows.get(MKB, [])) if not rows: rows.append(otherDiagRowIndex) else: rows.append(unknownDiagRowIndex) rows.append(totalRowIndex) ageCol = (min(max(age, 20), 71) - 11) / 10 if ageCol == 4: if age > 55: ageCol += 1 elif ageCol > 4: ageCol += 1 for row in rows: reportLine = reportMainData[row * 2 + (1 if sex == 1 else 0)] reportLine[ageCol] += cnt # reportLine[7] += cnt reportLine[rowSize - 1] += cnt doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('40%', [u'Нозология', u''], CReportBase.AlignLeft), ('10%', [u'Код по МКБ X', u''], CReportBase.AlignLeft), ('5%', [u'Пол', u''], CReportBase.AlignCenter), ('5%', [u'Возраст, лет', u'до 21'], CReportBase.AlignRight), ('5%', [u'', u'21-30'], CReportBase.AlignRight), ('5%', [u'', u'31-40'], CReportBase.AlignRight), ('5%', [u'', u'41-50'], CReportBase.AlignRight), # ( '5%', [u'', u'51-60'], CReportBase.AlignRight), ('5%', [u'', u'51-55'], CReportBase.AlignRight), ('5%', [u'', u'56-60'], CReportBase.AlignRight), ('5%', [u'', u'61-70'], CReportBase.AlignRight), ('5%', [u'', u'от 71'], CReportBase.AlignRight), ('5%', [u'Всего', u''], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 2, 1) # н. table.mergeCells(0, 1, 2, 1) # мкб table.mergeCells(0, 2, 2, 1) # пол # table.mergeCells(0, 3, 1, 7) # по возрастам table.mergeCells(0, 3, 1, 8) table.mergeCells(0, 11, 2, 1) for row, rowDescr in enumerate(MainRows): i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 1, rowDescr[1]) table.addRow() table.addRow() table.mergeCells(i, 0, 3, 1) table.mergeCells(i, 1, 3, 1) table.setText(i, 2, u'ж') table.setText(i + 1, 2, u'м') table.setText(i + 2, 2, u'всего') reportLine0 = reportMainData[row * 2] reportLine1 = reportMainData[row * 2 + 1] for col in xrange(rowSize): table.setText(i, 3 + col, reportLine0[col]) table.setText(i + 1, 3 + col, reportLine1[col]) table.setText(i + 2, 3 + col, reportLine0[col] + reportLine1[col]) return doc
def build(self, params): mapMainRows = createMapCodeToRowIdx([row[2] for row in MainRows]) begDate = params.get('begDate', QtCore.QDate()) endDate = params.get('endDate', QtCore.QDate()) workOrgId = params.get('workOrgId', None) sex = params.get('sex', 0) ageFrom = params.get('ageFrom', 0) ageTo = params.get('ageTo', 150) areaIdEnabled = params.get('areaIdEnabled', False) areaId = params.get('areaId', None) MKBFilter = params.get('MKBFilter', 0) MKBFrom = params.get('MKBFrom', 'A00') MKBTo = params.get('MKBTo', 'Z99.9') MKBExFilter = params.get('MKBExFilter', 0) MKBExFrom = params.get('MKBExFrom', 'A00') MKBExTo = params.get('MKBExTo', 'Z99.9') personId = params.get('personId', None) orgStructureAttachTypeId = params.get('orgStructureAttachTypeId', None) rowSize = 4 totalClient = 0 reportMainData = [[0] * rowSize for row in xrange(len(MainRows))] query = selectData(begDate, endDate, workOrgId, sex, ageFrom, ageTo, areaIdEnabled, areaId, MKBFilter, MKBFrom, MKBTo, MKBExFilter, MKBExFrom, MKBExTo, personId, self.forChildren, orgStructureAttachTypeId) self.setQueryText(forceString(query.lastQuery())) while query.next(): record = query.record() count = forceInt(record.value('count')) MKB = normalizeMKB(forceString(record.value('MKB'))) inCurrentYear = forceBool(record.value('inCurrentYear')) diseaseCharacter = forceString(record.value('diseaseCharacter')) firstInPeriod = forceBool(record.value('firstInPeriod')) countClient = forceInt(record.value('countClient')) for row in mapMainRows.get(MKB, []): reportLine = reportMainData[row] reportLine[0] += count if inCurrentYear: reportLine[1] += count if diseaseCharacter != '1' and not self.forChildren: if firstInPeriod: reportLine[2] += count else: reportLine[3] += count else: if firstInPeriod: reportLine[2] += count else: reportLine[3] += count if self.forChildren: totalClient += countClient # now text doc = QtGui.QTextDocument() cursor = QtGui.QTextCursor(doc) cursor.setCharFormat(CReportBase.ReportTitle) cursor.insertText(self.title()) cursor.insertBlock() self.dumpParams(cursor, params) cursor.insertBlock() tableColumns = [ ('40%', [u'Нозологическая группа', u''], CReportBase.AlignLeft), ('10%', [u'№ строки', u''], CReportBase.AlignLeft), ('10%', [u'код МКБ', u''], CReportBase.AlignLeft), ('10%', [u'Состоит', u''], CReportBase.AlignRight), ('10%', [u'В т.ч. в тек.году', u'всего'], CReportBase.AlignRight), ('10%', [u'', u'впервые установленые'], CReportBase.AlignRight), ('10%', [u'', u'ранее известные'], CReportBase.AlignRight), ] table = createTable(cursor, tableColumns) table.mergeCells(0, 0, 2, 1) # Наименование table.mergeCells(0, 1, 2, 1) # № стр. table.mergeCells(0, 2, 2, 1) # Код МКБ table.mergeCells(0, 3, 2, 1) # Состоит table.mergeCells(0, 4, 1, 3) # Всего table.mergeCells(0, 5, 1, 2) # в т.ч. впервые table.mergeCells(0, 6, 1, 2) # в т.ч. ранее известны. for row, rowDescr in enumerate(MainRows): reportLine = reportMainData[row] i = table.addRow() table.setText(i, 0, rowDescr[0]) table.setText(i, 1, rowDescr[1]) table.setText(i, 2, rowDescr[2]) table.setText(i, 3, reportLine[0]) table.setText(i, 4, reportLine[1]) table.setText(i, 5, reportLine[2]) table.setText(i, 6, reportLine[3]) if self.forChildren: i = table.addRow() table.mergeCells(i, 1, 1, 6) table.setText(i, 0, u'Всего человек: ') table.setText(i, 1, totalClient) cursor.movePosition(QtGui.QTextCursor.End) return doc