コード例 #1
0
 def setItemsByRecords(self, records):
     specItem = None
     for record in records:
         specName = forceString(record.value('name'))
         personId = forceRef(record.value('id'))
         personName = formatShortName(record.value('lastName'),
                                      record.value('firstName'),
                                      record.value('patrName'))
         self._items.append(
             CPersonnelTreeItem(specItem, personName, personId))
コード例 #2
0
    def produceReportDataDivided(self, query, reportRowSize, detailChildren,
                                 sceneIndexes, params):
        columnShift = 0 if detailChildren else 1
        reportData = {}
        personInfoList = []
        while query.next():
            record = query.record()
            personId = forceRef(record.value('person_id'))
            cnt = forceInt(record.value('cnt'))
            sceneId = forceInt(record.value('scene_id'))
            illness = forceBool(record.value('illness'))
            ageGroup = forceInt(record.value('ageGroup'))
            isWeekend = forceInt(record.value('weekend'))
            reportRow = reportData.get(personId, [])
            if not reportRow:
                reportRow = [0] * reportRowSize
                reportData[personId] = reportRow
                groupingRows = params.get('groupingRows', 0)
                specName = forceString(record.value('specName')) if groupingRows != 2 \
                    else getOrgStructureFullName(forceRef(record.value('whereId')))
                lastName = forceString(record.value('lastName'))
                firstName = forceString(record.value('firstName'))
                patrName = forceString(record.value('patrName'))
                personName = formatShortName(lastName, firstName, patrName)
                personInfoList.append((personId, specName, personName))
            if isWeekend:
                reportRow[1] += cnt
                if illness:
                    reportRow[3] += cnt
                    if not detailChildren:
                        if ageGroup in [0, 1]:
                            ageGroup = 0
                        else:
                            ageGroup = 1
                    reportRow[5 + ageGroup * 2] += cnt
                sceneIndex = sceneIndexes.get(sceneId, 0)
                reportRow[11 + sceneIndex * 4 - columnShift * 2] += cnt
                if illness:
                    reportRow[13 + sceneIndex * 4 - columnShift * 2] += cnt
            else:
                reportRow[0] += cnt
                if illness:
                    reportRow[2] += cnt
                    if not detailChildren:
                        if ageGroup in [0, 1]:
                            ageGroup = 0
                        else:
                            ageGroup = 1
                    reportRow[4 + ageGroup * 2] += cnt
                sceneIndex = sceneIndexes.get(sceneId, 0)
                reportRow[10 + sceneIndex * 4 - columnShift * 2] += cnt
                if illness:
                    reportRow[12 + sceneIndex * 4 - columnShift * 2] += cnt

        return reportData, personInfoList
コード例 #3
0
ファイル: ReportStationaryF007.py プロジェクト: dio4/vista_1
    def build(self, params):
        date = params.get('date', QtCore.QDate())
        begTime = params.get('begTime', self.DefaultBegTime)
        orgStructureId = params.get('orgStructureId', None)
        bedSchedule = params.get('bedSchedule', 0)
        bedProfile = params.get('bedProfile', None)
        detailOrgStructure = params.get('detailOrgStructure', False)

        fontSizeHeader = 9
        fontSizeBody = 9
        charFormatHeader = QtGui.QTextCharFormat()
        charFormatHeader.setFontPointSize(fontSizeHeader)
        charFormatHeaderBold = QtGui.QTextCharFormat()
        charFormatHeaderBold.setFontPointSize(fontSizeHeader)
        charFormatHeaderBold.setFontWeight(QtGui.QFont.Bold)
        charFormatBody = QtGui.QTextCharFormat()
        charFormatBody.setFontPointSize(fontSizeBody)
        charFormatBodyBold = QtGui.QTextCharFormat()
        charFormatBodyBold.setFontWeight(QtGui.QFont.Bold)
        charFormatBodyBold.setFontPointSize(fontSizeBody)

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

        self.createHeader(cursor, charFormatHeader, orgStructureId)
        mainTable = self.createTable(cursor, charFormatBodyBold)

        query = selectData(date, begTime, orgStructureId, bedSchedule,
                           bedProfile, detailOrgStructure)
        self.setQueryText(forceString(query.lastQuery()))

        receivedEvents = []
        movingIntoEvents = []
        movingFromEvents = []
        toHomeEvents = []
        toOtherOrgEvents = []
        deathEvents = []

        reportData = {}
        codes = {}

        while query.next():
            record = query.record()
            id = forceRef(record.value('id'))
            code = forceString(record.value('code'))
            menBeds = forceInt(record.value('menBeds'))
            womenBeds = forceInt(record.value('womenBeds'))
            permanentBeds = forceInt(record.value('permanentBeds'))
            involuteBeds = forceInt(record.value('involuteBeds'))
            moving = forceInt(record.value('moving'))
            received = forceInt(record.value('received'))
            receivedVillager = forceInt(record.value('receivedVillager'))
            receivedChildren = forceInt(record.value('receivedChildren'))
            receivedElder = forceInt(record.value('receivedElder'))
            movingInto = forceInt(record.value('movingInto'))
            movingFrom = forceInt(record.value('movingFrom'))
            leaved = forceInt(record.value('leaved'))
            leavedDeath = forceInt(record.value('leavedDeath'))
            leavedToOtherOrg = forceInt(record.value('leavedToOtherOrg'))
            men = forceInt(record.value('men'))
            women = forceInt(record.value('women'))

            inHospital = moving + received + movingInto - movingFrom - leaved
            freeBeds = permanentBeds - inHospital
            freeMenBeds = max(menBeds - men, 0)
            freeWomenBeds = max(womenBeds - women, 0)

            codes[id] = code
            reportData[id] = [
                permanentBeds,
                involuteBeds,
                moving,
                received,
                0,  # поступило из дневного стационара
                receivedVillager,
                receivedChildren,
                receivedElder,
                movingInto,
                movingFrom,
                leaved,
                leavedToOtherOrg,
                0,  # выписано в круглосуточный стационар
                0,  # выписано в дневной стационар
                leavedDeath,
                inHospital,
                0,  # состоит матерей при больных детях
                freeMenBeds,
                freeWomenBeds
            ]

            receivedEventsStr = forceString(record.value('receivedEvents'))
            if receivedEventsStr:
                receivedEvents.extend(map(int, receivedEventsStr.split(',')))

            movingIntoEventsStr = forceString(record.value('movingIntoEvents'))
            if movingIntoEventsStr:
                movingIntoEvents.extend(
                    map(int, movingIntoEventsStr.split(',')))

            movingFromEventsStr = forceString(record.value('movingFromEvents'))
            if movingFromEventsStr:
                movingFromEvents.extend(
                    map(int, movingFromEventsStr.split(',')))

            toHomeEventsStr = forceString(record.value('toHomeEvents'))
            if toHomeEventsStr:
                toHomeEvents.extend(map(int, toHomeEventsStr.split(',')))

            toOtherOrgEventsStr = forceString(record.value('toOtherOrgEvents'))
            if toOtherOrgEventsStr:
                toOtherOrgEvents.extend(
                    map(int, toOtherOrgEventsStr.split(',')))

            deathEventsStr = forceString(record.value('deathEvents'))
            if deathEventsStr:
                deathEvents.extend(map(int, deathEventsStr.split(',')))

        movingEvents = list(set(movingIntoEvents + movingFromEvents))

        def printRow(name, row, charFormat=charFormatBody, firstCol=''):
            i = mainTable.addRow()
            mainTable.setText(i, 0, firstCol)
            mainTable.setText(i, 1, name)
            for j, data in enumerate(row):
                mainTable.setText(i, j + 2, data, charFormat=charFormat)

        orgStructureIdList = sorted(reportData.iterkeys(),
                                    key=lambda id: reportData[id][0])
        total = [sum(data) for data in zip(*reportData.itervalues())]
        printRow(u'', total, charFormat=charFormatBodyBold, firstCol=u'Всего')

        i = mainTable.addRow()
        mainTable.setText(i, 0, u'В том числе по койкам')

        for orgStructureId in orgStructureIdList:
            printRow(codes[orgStructureId], reportData[orgStructureId])

        cursor.movePosition(QtGui.QTextCursor.End)
        cursor.insertBlock()
        self.createFooter(cursor, charFormatHeaderBold)

        # PAGE 2

        blockFormat = QtGui.QTextBlockFormat()
        blockFormat.setPageBreakPolicy(
            QtGui.QTextBlockFormat.PageBreak_AlwaysAfter)
        cursor.insertBlock(blockFormat)

        events = list(
            set(receivedEvents + movingEvents + toHomeEvents +
                toOtherOrgEvents + deathEvents))

        clientsMap = {}
        for record in selectClientData(events):
            eventId = forceRef(record.value('id'))
            shortName = formatShortName(forceString(record.value('lastName')),
                                        forceString(record.value('firstName')),
                                        forceString(record.value('patrName')))
            clientsMap[eventId] = shortName

        cursor.insertBlock()
        clientsTable = self.createClientsTable(cursor, charFormatBodyBold)

        i = clientsTable.addRow()
        clientsTable.setText(
            i, 0,
            u'\n'.join(clientsMap[eventId] for eventId in receivedEvents))
        clientsTable.setText(
            i, 2, u'\n'.join(clientsMap[eventId] for eventId in movingEvents))
        clientsTable.setText(
            i, 3, u'\n'.join(clientsMap[eventId] for eventId in toHomeEvents))
        clientsTable.setText(
            i, 4,
            u'\n'.join(clientsMap[eventId] for eventId in toOtherOrgEvents))
        clientsTable.setText(
            i, 5, u'\n'.join(clientsMap[eventId] for eventId in deathEvents))

        return doc
コード例 #4
0
ファイル: ReportLeavedMovedDead.py プロジェクト: dio4/vista_1
    def build(self, params):
        doc = QtGui.QTextDocument()
        cursor = QtGui.QTextCursor(doc)
        cursor.setCharFormat(CReportBase.ReportTitle)
        cursor.insertText(self.title())
        cursor.movePosition(QtGui.QTextCursor.End)

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

        cursor.setCharFormat(QtGui.QTextCharFormat())

        columnNames = [
            'showExternalId', 'showName', 'showBirthDate', 'showSex',
            'showSocStatus', 'showBenefits', 'showRegAddress',
            'showDeliveredBy', 'showDeliveredTime', 'showEventOrder',
            'showBegDate', 'showPrimary', 'showOrgStructure', 'showResult',
            'showStatus', 'showDiagnosis', 'showAutopsyDiagnosis',
            'showTrauma', 'showLeavedDate', 'showBedDays'
        ]
        operationColumn = 'showOperations'

        showColumn = dict([(showColumn, params.get(showColumn, False))
                           for showColumn in columnNames + [operationColumn]])

        baseColumnsDescription = [
            ('5?', [u'№ ИБ'], CReportBase.AlignLeft),
            ('5?', [u'Фамилия И.О.'], CReportBase.AlignLeft),
            ('5?', [u'Дата рождения'], CReportBase.AlignLeft),
            ('5?', [u'Пол'], CReportBase.AlignCenter),
            ('5?', [u'Социальный статус'], CReportBase.AlignLeft),
            ('5?', [u'Категория'], CReportBase.AlignLeft),
            ('5?', [u'Постоянная регистрация'], CReportBase.AlignLeft),
            ('5?', [u'Направлен (канал госпитализации)'],
             CReportBase.AlignLeft), ('5?', [u'Срок'], CReportBase.AlignLeft),
            ('5?', [u'Вид поступления'], CReportBase.AlignLeft),
            ('5?', [u'Дата, время поступления'], CReportBase.AlignLeft),
            ('5?', [u'Повторно'], CReportBase.AlignLeft),
            ('5?', [u'Отделение поступления'], CReportBase.AlignLeft),
            ('5?', [u'Исход'], CReportBase.AlignLeft),
            ('5?', [u'Состояние'], CReportBase.AlignLeft),
            ('5?', [u'Диагноз клинический'], CReportBase.AlignLeft),
            ('5?', [u'Диагноз патологоанатомический'], CReportBase.AlignLeft),
            ('5?', [u'Травма\nОбстоятельства'], CReportBase.AlignLeft),
            ('5?', [u'Дата выписки'], CReportBase.AlignLeft),
            ('5?', [u'Койко-дней'], CReportBase.AlignLeft)
        ]
        operationColumnsDescription = [
            ('5?', [u'Дата операции'], CReportBase.AlignLeft),
            ('5?', [u'Отделение'], CReportBase.AlignLeft),
            ('5?', [u'Операция'], CReportBase.AlignLeft),
            ('5?', [u'Количество'], CReportBase.AlignLeft),
            ('5?', [u'Экстренно'], CReportBase.AlignLeft)
        ]

        tableColumns = [
            baseColumnsDescription[i] for i, colName in enumerate(columnNames)
            if showColumn[colName]
        ]
        if showColumn[operationColumn]:
            tableColumns.extend(operationColumnsDescription)

        table = createTable(cursor, tableColumns)

        columnIndex = {}
        for col in columnNames + [operationColumn]:
            columnIndex[col] = len(columnIndex)

        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)

        # detailByOrgStructure = orgStructureId is None

        eventOrderMap = {
            1: u'плановый',
            2: u'экстренный',
            3: u'самотеком',
            4: u'принудительный',
            5: u'неотложный'
        }

        eventIsPrimaryMap = {
            1: u'первичный',
            2: u'повторный',
            3: u'активное посещение',
            4: u'перевозка'
        }

        query = selectDataByEvents(byPeriod, leavedDate, byReceivedDate,
                                   receivedBegDate, receivedEndDate,
                                   byLeavedDate, leavedBegDate, leavedEndDate,
                                   orgStructureId)
        self.setQueryText(forceString(query.lastQuery()))

        reportData = []

        while query.next():
            record = query.record()
            # orgStructureId = forceRef(record.value('orgStructureId'))
            # leavedActionId = forceRef(record.value('leavedActionId'))

            clientId = forceRef(record.value('clientId'))
            eventId = forceRef(record.value('eventId'))
            eventExternalId = forceString(record.value('eventExternalId'))
            order = forceInt(record.value('eventOrder'))
            isPrimary = forceInt(record.value('eventIsPrimary'))
            # result = forceString(record.value('result'))
            # receivedOrgStructure = forceString(record.value('receivedOrgStructure'))

            begDate = forceDateTime(record.value('begDate'))
            leavedDate = forceDate(record.value('leavedDate'))
            bedDays = forceInt(record.value('bedDays'))

            receivedActionId = forceRef(record.value('receivedActionId'))
            statCardActionId = forceRef(record.value('statCardActionId'))
            firstExaminationActionId = forceRef(
                record.value('firstExaminationActionId'))
            traumatologistActionId = forceRef(
                record.value('traumatologistActionId'))

            epicrisisId = forceRef(record.value('epicrisisActionId'))

            autopsyActionId = forceRef(record.value('autopsyActionId'))

            clientRecord = getClientRecord(clientId)
            lastName = forceString(clientRecord.value('lastName'))
            firstName = forceString(clientRecord.value('firstName'))
            patrName = forceString(clientRecord.value('patrName'))
            birthDate = forceDate(clientRecord.value('birthDate'))
            sex = clientRecord.value('sex')
            regAddress = forceString(clientRecord.value('regAddress'))

            rowData = [
                eventExternalId if showColumn['showExternalId'] else None,
                formatShortName(lastName, firstName, patrName)
                if showColumn['showName'] else None,
                birthDate.toString('dd/MM/yyyy')
                if showColumn['showBirthDate'] else None,
                formatSex(sex) if showColumn['showSex'] else None,
                getActionPropertyString(statCardActionId,
                                        u'Социальный статус:')
                if showColumn['showSocStatus'] else None,
                getActionPropertyString(statCardActionId,
                                        u'Категория льготности:')
                if showColumn['showBenefits'] else None,
                regAddress if showColumn['showRegAddress'] else None,
                getActionPropertyOrganisation(receivedActionId,
                                              u'Кем доставлен')
                if showColumn['showDeliveredBy'] else None,
                getActionPropertyString(receivedActionId, u'Доставлен')
                if showColumn['showDeliveredTime'] else None,
                eventOrderMap.get(order, u'')
                if showColumn['showEventOrder'] else None,
                begDate.toString('dd/MM/yyyy hh:mm')
                if showColumn['showBegDate'] else None,
                eventIsPrimaryMap.get(isPrimary, u'')
                if showColumn['showPrimary'] else None,
                getActionPropertyOrgStructure(receivedActionId,
                                              u'Направлен в отделение')
                if showColumn['showOrgStructure'] else None,
                getActionPropertyString(statCardActionId,
                                        u'Исход госпитализации:')
                if showColumn['showResult'] else None,
                getActionPropertyString(firstExaminationActionId,
                                        u'Status praesens:%Общее состояние:')
                if showColumn['showStatus'] else None,
                getActionPropertyString(epicrisisId, u'Основное заболевание:')
                if showColumn['showDiagnosis'] else None,
                getActionPropertyString(autopsyActionId,
                                        u'Патолого-Анатомический диагноз%')
                if showColumn['showAutopsyDiagnosis'] else None,
                getActionPropertyString(traumatologistActionId, u'Травма:')
                if showColumn['showTrauma'] else None,
                leavedDate.toString('dd/MM/yyyy')
                if showColumn['showLeavedDate'] else None,
                bedDays if showColumn['showBedDays'] else None
            ]

            eventRow = [
                data for colName, data in zip(columnNames, rowData)
                if showColumn[colName]
            ]

            operations = []
            if showColumn[operationColumn]:
                operationsQuery = getOperationsInfo(eventId)
                while operationsQuery.next():
                    operation = operationsQuery.record()
                    operationRow = [
                        forceDate(
                            operation.value('date')).toString('dd/MM/yyyy'),
                        forceString(operation.value('orgStructure')),
                        forceString(operation.value('operationName')),
                        forceInt(operation.value('amount')), u'экстренно'
                        if forceBool(operation.value('isUrgent')) else u''
                    ]
                    operations.append(operationRow)

            reportData.append({'row': eventRow, 'operations': operations})

        for event in reportData:
            eventRow = event['row']
            eventOperations = event['operations']
            row = table.addRow()
            for col, text in enumerate(eventRow):
                table.setText(row, col, text)

            for i, operationRow in enumerate(eventOperations):
                if i != 0:
                    row = table.addRow()
                for col, text in enumerate(operationRow):
                    table.setText(row, len(eventRow) + col, text)

            operationsCount = len(eventOperations)
            for col in xrange(len(eventRow)):
                table.mergeCells(row - operationsCount + 1, col,
                                 operationsCount, 1)

        return doc