Example #1
0
    def build(self, params):
        query = selectData(params)
        self.setQueryText(forceString(query.lastQuery()))
        doc = QtGui.QTextDocument()
        cursor = QtGui.QTextCursor(doc)
        cursor.setCharFormat(CReportBase.ReportTitle)

        org_id = QtGui.qApp.currentOrgId()
        org_info = getOrganisationInfo(org_id)

        cursor.insertBlock(CReportBase.AlignCenter)
        cursor.insertText(org_info.get('fullName'))
        cursor.insertBlock(CReportBase.AlignCenter)
        cursor.insertText(self.title())

        cursor.insertBlock()
        self.dumpParams(cursor, params)
        cursor.insertBlock()

        tableColumns = [('20%', [u'Отделение'], CReportBase.AlignCenter)]

        valueDomain = QtGui.qApp.db.translate('ActionPropertyType', 'name',
                                              u'Cостояние пациента',
                                              'valueDomain')
        state_list = CStrComboBox.parse(forceString(valueDomain))[0]
        state_list.insert(0, u'')
        for header in state_list:
            tableColumns.append(('12%', [header], CReportBase.AlignCenter))

        tableColumns.append(('8%', [u'Всего'], CReportBase.AlignCenter))
        table = createTable(cursor, tableColumns)
        struct = OrderedDict()
        while query.next():
            record = query.record()
            org_struct = forceString(record.value('org_struct'))
            org_struct = org_struct if org_struct else u'без уточнения'
            patient_state = forceString(record.value('patient_state'))
            d = struct.setdefault(org_struct,
                                  OrderedDict.fromkeys(state_list, 0))
            d[patient_state] += 1

        total_col = OrderedDict.fromkeys(state_list, 0)
        total_col['total'] = 0
        for org_struct, d in struct.items():
            i = table.addRow()
            table.setText(i, 0, org_struct)
            total_row = 0
            for col, (state, num) in enumerate(d.items()):
                table.setText(i, col + 1, num)
                total_row += num
                total_col[state] += num
            table.setText(i, len(d) + 1, total_row)
            total_col['total'] += total_row
        i = table.addRow()
        table.setText(i, 0, u'Всего', CReportBase.TableTotal)
        for col, N in enumerate(total_col.values()):
            table.setText(i, col + 1, N, CReportBase.TableTotal)

        return doc
    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 = [('28%', [u'Отделение', u''], CReportBase.AlignLeft),
                        ('5%', [u'Госпитализировано',
                                u'Всего'], CReportBase.AlignRight),
                        ('8%', [u'', u'Плановых'], CReportBase.AlignRight),
                        ('8%', [u'', u'Экстренных'], CReportBase.AlignRight),
                        ('10%', [u'', u'в т.ч. ОМС'], CReportBase.AlignRight),
                        ('5%', [u'Не госпитализировано',
                                u'Всего'], CReportBase.AlignRight),
                        ('10%', [u'', u'Амбулатор.'], CReportBase.AlignRight),
                        ('10%', [u'', u'Отказн.'], CReportBase.AlignRight),
                        ('8%', [u'в т.ч. умерло',
                                u''], CReportBase.AlignRight),
                        ('8%', [u'Всего', u''], CReportBase.AlignRight)]

        table = createTable(cursor, tableColumns)
        table.mergeCells(0, 0, 2, 1)
        table.mergeCells(0, 1, 1, 4)
        table.mergeCells(0, 5, 1, 3)
        table.mergeCells(0, 8, 2, 1)
        table.mergeCells(0, 9, 2, 1)

        report = OrderedDict()

        while query.next():
            record = query.record()
            departmnt = forceString(record.value('departmnt'))
            depType = forceInt(record.value('depType'))
            evOrder = forceInt(record.value('evOrder'))
            rbFinance = forceString(record.value('rbFinance'))
            reasonDeny = forceString(record.value('reasonDeny'))
            actionResult = forceString(record.value('actionResult'))
            eventResult = forceString(record.value('eventResult'))
            """
            алгоритм:

            если есть св-во "Причина отказа от госпитализации":
                # это ветка Не госпитализировано
                если OrgStructure.type == 4:
                    -- это ветка Отказн --
                иначе:
                    -- это ветка Амбулатор --
            иначе:
                # это ветка Госпитализировано
                если Event.order == 1:
                    -- это ветка Плановых --
                если Event.order == 2:
                    -- это ветка Экстрен --
                если Event.order in (1,2) AND rbFinance == 'ОМС':
                    -- это ветка в т.ч. ОМС --

            если actionResult == 'умер' or eventResult.find('умер') > -1 or eventResult.find('смерть') > -1:
                -- это ветка в т.ч. умерло --
            """

            repRow = report.setdefault(departmnt, {
                'plan': 0,
                'extren': 0,
                'OMS': 0,
                'amb': 0,
                'deny': 0,
                'died': 0
            })

            if reasonDeny:
                if depType == 4:
                    repRow['deny'] += 1
                else:
                    repRow['amb'] += 1
            else:
                if evOrder == 1:
                    repRow['plan'] += 1
                if evOrder == 2:
                    repRow['extren'] += 1
                if evOrder in (1, 2) and rbFinance.upper() == u'ОМС':
                    repRow['OMS'] += 1
            eventResult = eventResult.lower()
            if actionResult.lower() == u'умер' or eventResult.find(
                    u'умер') > -1 or eventResult.find(u'смерть') > -1:
                repRow['died'] += 1

        total = {
            'plan': 0,
            'extren': 0,
            'OMS': 0,
            'amb': 0,
            'deny': 0,
            'died': 0
        }
        for department, depStat in report.items():
            i = table.addRow()

            plan = depStat.get('plan')
            extren = depStat.get('extren')
            OMS = depStat.get('OMS')
            deny = depStat.get('deny')
            amb = depStat.get('amb')
            died = depStat.get('died')

            table.setText(i, 0,
                          department if department else u'<без уточнения>')
            table.setText(i, 1, plan + extren)
            table.setText(i, 2, plan)
            table.setText(i, 3, extren)
            table.setText(i, 4, OMS)
            table.setText(i, 5, amb + deny)
            table.setText(i, 6, amb)
            table.setText(i, 7, deny)
            table.setText(i, 8, died)
            table.setText(i, 9, plan + extren + amb + deny)

            total['plan'] += plan
            total['extren'] += extren
            total['OMS'] += OMS
            total['deny'] += deny
            total['amb'] += amb
            total['died'] += died

        i = table.addRow()
        table.setText(i, 0, u'Итого:', CReportBase.TableTotal)
        table.setText(i, 1, total['plan'] + total['extren'],
                      CReportBase.TableTotal)
        table.setText(i, 2, total['plan'], CReportBase.TableTotal)
        table.setText(i, 3, total['extren'], CReportBase.TableTotal)
        table.setText(i, 4, total['OMS'], CReportBase.TableTotal)
        table.setText(i, 5, total['amb'] + total['deny'],
                      CReportBase.TableTotal)
        table.setText(i, 6, total['amb'], CReportBase.TableTotal)
        table.setText(i, 7, total['deny'], CReportBase.TableTotal)
        table.setText(i, 8, total['died'], CReportBase.TableTotal)
        table.setText(
            i, 9,
            total['plan'] + total['extren'] + total['amb'] + total['deny'],
            CReportBase.TableTotal)

        return doc
Example #3
0
    def build_R2(self, cursor, query):
        tableColumns = [('35%', [u'Источник информации'],
                         CReportBase.AlignLeft),
                        ('10%', [u'Код пациента'], CReportBase.AlignRight),
                        ('35%', [u'ФИО'], CReportBase.AlignLeft),
                        ('20%', [u'Примечание'], CReportBase.AlignLeft)]
        table = createTable(cursor, tableColumns)
        from library.vm_collections import OrderedDict
        virtTable = OrderedDict()
        #virtTable structure:
        #{ sourceID : {
        #    'sourceName' : sourceName,
        #    'cnt' : cnt,
        #    'clients' : [
        #        {'Id': id, 'FIO': lastName + firstName + patrName},
        #        {}, ...
        #     ]
        # }, sourceID : {}, ... }
        total_cnt = 0
        while query.next():
            record = query.record()
            sourceID = forceRef(record.value('sourceID'))
            sourceName = forceString(record.value('sourceName'))
            Id = forceString(record.value('id'))
            lastName = forceString(record.value('lastName'))
            firstName = forceString(record.value('firstName'))
            patrName = forceString(record.value('patrName'))
            total_cnt += 1
            sourceName = sourceName if sourceID else u'<не указан источник информации>'
            sourceDict = virtTable.setdefault(sourceID, {
                'sourceName': sourceName,
                'cnt': 0,
                'clients': []
            })
            sourceDict.get('clients').append({
                'Id':
                Id,
                'FIO':
                formatName(lastName, firstName, patrName)
            })
            cnt = sourceDict.get('cnt')
            cnt += 1
            sourceDict['cnt'] = cnt

        charFormat = QtGui.QTextCharFormat()
        charFormat.setFontItalic(True)
        for sourceID, sourceDict in virtTable.items():
            i = table.addRow()
            sourceName = sourceDict.get('sourceName')
            clients = sourceDict.get('clients')
            cl = clients.pop(0)
            table.setText(i, 0, sourceName)
            table.setText(i, 1, cl.get('Id'))
            table.setText(i, 2, cl.get('FIO'))
            for cl in clients:
                j = table.addRow()
                table.setText(j, 1, cl.get('Id'))
                table.setText(j, 2, cl.get('FIO'))
            cnt = sourceDict.get('cnt')
            rate = float(cnt) / float(total_cnt) * 100.0
            table.mergeCells(i, 0, cnt, 1)
            i = table.addRow()
            table.setText(i, 0, u'Итого: ' + '%i (%.2f %%)' % (cnt, rate),
                          charFormat)
            table.mergeCells(i, 0, 1, 4)
        i = table.addRow()
        charFormat.setFontWeight(QtGui.QFont.Bold)
        table.setText(i, 0, u'Итоговое итого: ' + str(total_cnt), charFormat)
        table.mergeCells(i, 0, 1, 4)
Example #4
0
    def build(self, params):
        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)
        personId = params.get('personId', None)

        query = QtGui.qApp.db.query(
            selectData(begDate, endDate, workOrgId, sex, ageFrom, ageTo,
                       areaIdEnabled, areaId, MKBFilter, MKBFrom, MKBTo,
                       MKBExFilter, MKBExFrom, MKBExTo, socStatusType,
                       socStatusClass, personId))
        self.setQueryText(forceString(query.lastQuery()))

        rows = OrderedDict()

        while query.next():
            rec = query.record()
            cid = forceRef(rec.value('cid'))
            dispanser = forceInt(rec.value('dispanser'))
            clientName = forceString(rec.value('clientName'))
            birthDate = forceDate(rec.value('birthDate'))
            clientPolicy = forceString(rec.value('clientPolicy'))
            SNILS = forceString(rec.value('SNILS'))
            socStatus = forceString(rec.value('socStatus'))
            diagName = forceString(rec.value('DiagName'))
            diagId = forceString(rec.value('DiagId'))
            setDate = forceDate(rec.value('setDate'))
            execDate = forceDate(rec.value('execDate'))
            visits = forceInt(rec.value('visits'))
            f20 = forceString(rec.value('f20'))

            d = rows.setdefault((cid, diagId), INITIAL_ROW_DICT.copy())
            if clientName:
                d['clientName'] = clientName
            if birthDate:
                d['birthDate'] = birthDate
            if clientPolicy:
                d['clientPolicy'] = clientPolicy
            if SNILS:
                d['SNILS'] = SNILS
            if socStatus:
                d['socStatus'] = socStatus
            if diagName:
                d['diagName'] = diagName
            if diagId:
                d['diagId'] = diagId
            if setDate and (not d['setDate']
                            or d['setDate'] > setDate) and dispanser in (1, 2):
                d['setDate'] = setDate
            if execDate and (not d['execDate'] or
                             d['execDate'] < execDate) and dispanser in (3, 4,
                                                                         5):
                d['execDate'] = execDate
            if visits:
                d['visits'] += visits
            if f20:
                d['f20'] = f20

        doc = QtGui.QTextDocument()
        cursor = QtGui.QTextCursor(doc)

        cursor.setCharFormat(CReportBase.ReportTitle)
        cursor.insertText(self.title())
        cursor.insertBlock()
        self.dumpParams(cursor, params)
        cursor.insertBlock()

        tableColumns = [
            ('5%', [u'№ п/п', u'', u'', u'', u'1'], CReportBase.AlignLeft),
            ('5%', [
                u'Сведения врача-терапевта участкового, врача-педиатра участкового, врача общей практики '
                u'(семейного врача)', u'Ф.И.О. пациента', u'', u'', u'2'
            ], CReportBase.AlignLeft),
            ('5%', [u'', u'Дата рождения', u'', u'',
                    u'3'], CReportBase.AlignLeft),
            ('5%', [u'', u'Номер полиса ОМС', u'', u'',
                    u'4'], CReportBase.AlignLeft),
            ('5%', [u'', u'СНИЛС', u'', u'', u'5'], CReportBase.AlignLeft),
            ('5%', [u'', u'Код категории льготы', u'', u'',
                    u'6'], CReportBase.AlignLeft),
            ('5%', [u'', u'Наименование заболевания', u'', u'',
                    u'7'], CReportBase.AlignLeft),
            ('5%', [u'', u'Код по МКБ-10', u'', u'',
                    u'8'], CReportBase.AlignLeft),
            ('5%',
             [u'', u'Дата начала диспансерного наблюдения', u'', u'',
              u'9'], CReportBase.AlignLeft),
            ('5%', [
                u'', u'Дата прекращения диспансерного наблюдения', u'', u'',
                u'10'
            ], CReportBase.AlignLeft),
            ('5%', [u'', u'Число посещений', u'', u'',
                    u'11'], CReportBase.AlignLeft),
            ('5%', [
                u'Сведения организационно-методического кабинета',
                u'Лекарственное обеспечение', u'выписано',
                u'наименование лекарственного препарата, дозировка', u'12'
            ], CReportBase.AlignLeft),
            ('5%', [u'', u'', u'', u'№ и серия рецепта',
                    u'13'], CReportBase.AlignLeft),
            ('5%', [
                u'', u'',
                u'фактически получено (наименование лекарственного препарата, дозировка)',
                u'', u'14'
            ], CReportBase.AlignLeft),
            ('5%',
             [u'', u'Стоимость лекарственного обеспечения', u'', u'',
              u'15'], CReportBase.AlignLeft),
            ('5%', [
                u'', u'Санитарно-курортное лечение', u'Выдано:',
                u'справок для получения путевки на санаторно-курортное лечение',
                u'16'
            ], CReportBase.AlignLeft),
            ('5%', [
                u'', u'', u'', u'из них на амбулаторное курортное лечение',
                u'17'
            ], CReportBase.AlignLeft),
            ('5%', [u'', u'', u'', u'санаторно-курортных карт',
                    u'18'], CReportBase.AlignLeft),
            ('5%', [
                u'', u'',
                u'Возвращено обратных талонов санаторно-курортных карт', u'',
                u'19'
            ], CReportBase.AlignLeft),
            ('5%', [
                u'',
                u'Направлено на госпитализацию, медицинскую реабилитацию, обследование, консультацию',
                u'', u'', u'20'
            ], CReportBase.AlignLeft),
        ]

        table = createTable(cursor, tableColumns)
        table.mergeCells(0, 0, 4, 1)
        table.mergeCells(0, 1, 1, 10)
        table.mergeCells(1, 1, 3, 1)
        table.mergeCells(1, 2, 3, 1)
        table.mergeCells(1, 3, 3, 1)
        table.mergeCells(1, 4, 3, 1)
        table.mergeCells(1, 5, 3, 1)
        table.mergeCells(1, 6, 3, 1)
        table.mergeCells(1, 7, 3, 1)
        table.mergeCells(1, 8, 3, 1)
        table.mergeCells(1, 9, 3, 1)
        table.mergeCells(1, 10, 3, 1)
        table.mergeCells(0, 11, 1, 9)
        table.mergeCells(1, 11, 1, 3)
        table.mergeCells(2, 11, 1, 2)
        table.mergeCells(2, 13, 2, 1)
        table.mergeCells(1, 14, 3, 1)
        table.mergeCells(1, 15, 1, 4)
        table.mergeCells(2, 15, 1, 3)
        table.mergeCells(2, 18, 2, 1)
        table.mergeCells(1, 19, 3, 1)

        for i, row in enumerate(rows.values()):
            birthDate = row['birthDate'].toString(
                'dd.MM.yyyy') if row['birthDate'] else '-'
            setDate = row['setDate'].toString(
                'dd.MM.yyyy') if row['setDate'] else '-'
            execDate = row['execDate'].toString(
                'dd.MM.yyyy') if row['execDate'] else '-'
            table.addRowWithContent(str(i + 1), row['clientName'], birthDate,
                                    row['clientPolicy'], row['SNILS'],
                                    row['socStatus'], row['diagName'],
                                    row['diagId'], setDate, execDate,
                                    str(row['visits']), '', '', '', '', '', '',
                                    '', '', row['f20'])

        cursor.movePosition(QtGui.QTextCursor.End)
        return doc