コード例 #1
0
ファイル: RegistryQueueModels.py プロジェクト: dio4/vista_1
 def loadData(self, clientId=None):
     etcQueue = 'queue'
     atcQueue = 'queue'
     if clientId:
         self.clientId = clientId
         currentDate = forceDateTime(QtCore.QDate.currentDate())
         db = QtGui.qApp.db
         tableAction = db.table('Action')
         tableEvent = db.table('Event')
         tableActionProperty = db.table('ActionProperty')
         tableActionProperty_Action = db.table('ActionProperty_Action')
         tableActionProperty_rbReason = db.table(
             'ActionProperty_rbReasonOfAbsence')
         tableReason = db.table('rbReasonOfAbsence')
         cols = [
             tableAction['id'], tableAction['setPerson_id'],
             tableAction['person_id'], tableAction['status'],
             tableAction['office'], tableAction['directionDate'],
             tableAction['note'],
             tableActionProperty_Action['id'].alias('APAction_id'),
             tableAction['event_id'], tableReason['name'].alias('reason')
         ]
         actionType = CActionTypeCache.getByCode(atcQueue)
         actionTypeId = actionType.id
         eventType = getEventType(etcQueue)
         eventTypeId = eventType.eventTypeId
         cond = [
             tableEvent['client_id'].eq(self.clientId),
             tableEvent['setDate'].ge(currentDate),
             tableEvent['deleted'].eq(0), tableAction['deleted'].eq(0),
             tableEvent['eventType_id'].eq(eventTypeId),
             tableAction['actionType_id'].eq(actionTypeId)
         ]
         tableQuery = tableAction
         tableQuery = tableQuery.innerJoin(
             tableEvent, tableEvent['id'].eq(tableAction['event_id']))
         tableQuery = tableQuery.leftJoin(
             tableActionProperty,
             tableActionProperty['action_id'].eq(tableAction['id']))
         tableQuery = tableQuery.innerJoin(
             tableActionProperty_Action,
             tableActionProperty_Action['value'].eq(tableAction['id']))
         tableQuery = tableQuery.leftJoin(
             tableActionProperty_rbReason,
             tableActionProperty_rbReason['id'].eq(
                 tableActionProperty['id']))
         tableQuery = tableQuery.leftJoin(
             tableReason,
             tableReason['id'].eq(tableActionProperty_rbReason['value']))
         records = db.getRecordList(tableQuery, cols, cond,
                                    'Action.directionDate')
         self.setItems(records)
     else:
         self.clearItems()
コード例 #2
0
ファイル: RegistryQueueModels.py プロジェクト: dio4/vista_1
    def loadData(self, clientId=None):
        if clientId:
            currentDateTime = forceDateTime(QtCore.QDateTime.currentDateTime())
            etcQueue = 'queue'
            atcQueue = 'queue'
            db = QtGui.qApp.db
            tableEvent = db.table('Event')
            tableAction = db.table('Action')
            tableVisit = db.table('Visit')
            tablePersonWithSpeciality = db.table('vrbPersonWithSpeciality')
            tableActionProperty_Action = db.table('ActionProperty_Action')
            tableOrgStructure = db.table('OrgStructure')
            cols = [
                tableAction['event_id'], tableAction['id'],
                tableAction['directionDate'], tableAction['setPerson_id'],
                tableAction['person_id'], tableAction['office'],
                tableAction['note'], tablePersonWithSpeciality['speciality_id']
            ]
            actionType = CActionTypeCache.getByCode(atcQueue)
            actionTypeId = actionType.id
            eventType = getEventType(etcQueue)
            eventTypeId = eventType.eventTypeId
            tableQuery = tableAction
            tableQuery = tableQuery.innerJoin(
                tableEvent, tableEvent['id'].eq(tableAction['event_id']))
            tableQuery = tableQuery.innerJoin(
                tableActionProperty_Action,
                tableActionProperty_Action['value'].eq(tableAction['id']))
            tableQuery = tableQuery.innerJoin(
                tablePersonWithSpeciality,
                tablePersonWithSpeciality['id'].eq(tableAction['person_id']))
            cond = [
                tableEvent['client_id'].eq(clientId),
                tableAction['directionDate'].lt(currentDateTime),
                tableEvent['deleted'].eq(0), tableAction['deleted'].eq(0),
                tableEvent['eventType_id'].eq(eventTypeId),
                tableAction['actionType_id'].eq(actionTypeId)
            ]
            recordBufferAction = db.getRecordList(tableQuery, cols, cond,
                                                  'Action.directionDate')
            listDirectionDateAction = []
            specialityIdList = []
            personIdList = []
            for recordDirectionDateAction in recordBufferAction:
                directionDate = forceDate(
                    recordDirectionDateAction.value('directionDate'))
                if directionDate and directionDate not in listDirectionDateAction:
                    listDirectionDateAction.append(directionDate)
                specialityId = forceRef(
                    recordDirectionDateAction.value('speciality_id'))
                if specialityId and specialityId not in specialityIdList:
                    specialityIdList.append(specialityId)
                personId = forceRef(
                    recordDirectionDateAction.value('person_id'))
                if personId and personId not in personIdList:
                    personIdList.append(personId)
            if listDirectionDateAction:
                cols = [
                    tableVisit['date'], tableVisit['person_id'],
                    tableVisit['event_id'].alias('eventId'),
                    tablePersonWithSpeciality['speciality_id'],
                    tablePersonWithSpeciality['name'].alias('personName')
                ]
                condVisit = [
                    tableVisit['date'].inlist(listDirectionDateAction),
                    tableEvent['client_id'].eq(clientId),
                    tableEvent['deleted'].eq(0), tableVisit['deleted'].eq(0)
                ]
                condVisit.append(
                    db.joinOr([
                        tablePersonWithSpeciality['speciality_id'].inlist(
                            specialityIdList),
                        tableVisit['person_id'].inlist(personIdList)
                    ]))
                tableQueryVisit = tableVisit
                tableQueryVisit = tableQueryVisit.innerJoin(
                    tableEvent, tableEvent['id'].eq(tableVisit['event_id']))
                tableQueryVisit = tableQueryVisit.innerJoin(
                    tablePersonWithSpeciality,
                    tablePersonWithSpeciality['id'].eq(
                        tableVisit['person_id']))
                recordVisit = db.getRecordList(tableQueryVisit, cols,
                                               condVisit, 'Visit.date')

            for record in recordBufferAction:
                directionDate = forceDate(record.value('directionDate'))
                personId = forceRef(record.value('person_id'))
                specialityId = forceRef(record.value('speciality_id'))
                visitEventId = self.getVisit(directionDate, personId,
                                             specialityId, recordVisit)
                record.setValue('event_id', toVariant(visitEventId))
            self.setItems(recordBufferAction)
        else:
            self.clearItems()
コード例 #3
0
def selectData(params):
    db = QtGui.qApp.db
    tablePerson = db.table('vrbPersonWithSpeciality').alias('ExecPerson')
    tableAction = db.table('Action')

    begDate = params.get('begDate', None)
    endDate = params.get('endDate', None)
    begDateRecord = params.get('begDateBeforeRecord', None)
    endDateRecord = params.get('endDateBeforeRecord', None)
    personId = params.get('personId', None)
    userId = params.get('beforeRecordUserId', None)
    orgStructureId = params.get('orgStructureId', None)
    specialityId = params.get('specialityId', None)
    chkOrgStructure = params.get('chkOrgStructure', None)
    queueType = params.get('queueType', 0)
    chkPeriodRecord = params.get('chkPeriodRecord', None)
    chkPeriodBeforeRecord = params.get('chkPeriodBeforeRecord', None)
    userProfileId = params.get('userProfileId', None)
    showWithoutOverTime = params.get('showWithoutOverTime', None)
    ignoreRehabilitation = params.get('ignoreRehabilitation', None)
    detailExternalIS = params.get('detailExternalIS', None)

    cond = [tableAction['deleted'].eq(0)]
    if chkPeriodRecord:
        if begDate:
            cond.append(tableAction['createDatetime'].dateGe(begDate))
        if endDate:
            cond.append(tableAction['createDatetime'].dateLe(endDate))
    if chkPeriodBeforeRecord:
        if begDateRecord:
            cond.append(tableAction['directionDate'].dateGe(begDateRecord))
        if endDateRecord:
            cond.append(tableAction['directionDate'].dateLe(endDateRecord))

    if queueType == 0:
        ambActionType = CActionTypeCache.getByCode('amb')
        codeAT = 'AT.id = %d' % ambActionType.id
    elif queueType == 1:
        homeActionType = CActionTypeCache.getByCode('home')
        codeAT = 'AT.id = %d' % homeActionType.id
    else:
        ambActionType = CActionTypeCache.getByCode('amb')
        homeActionType = CActionTypeCache.getByCode('home')
        codeAT = '(AT.id = %d OR AT.id = %d)' % (ambActionType.id,
                                                 homeActionType.id)
    if chkOrgStructure:
        if personId:
            cond.append(tableAction['person_id'].eq(personId))
        if orgStructureId:
            cond.append(tablePerson['orgStructure_id'].inlist(
                getOrgStructureDescendants(orgStructureId)))
        else:
            if not personId:
                cond.append(tablePerson['org_id'].eq(
                    QtGui.qApp.currentOrgId()))
        if specialityId:
            cond.append(tablePerson['speciality_id'].eq(specialityId))
    if userId:
        cond.append(tableAction['createPerson_id'].eq(userId))
    if userProfileId:
        cond.append('EXISTS(SELECT PUP.id '
                    '       FROM Person_UserProfile AS PUP '
                    '       WHERE PUP.person_id = PersonUserProfile.id '
                    '               AND PUP.userProfile_id = %s)' %
                    userProfileId)
    if showWithoutOverTime:
        cond.append('APTime.value IS NOT NULL')
    if ignoreRehabilitation:
        cond.append(tablePerson['orgStructure_id'].notInlist(
            db.getIdList('OrgStructure', where=u'name LIKE "%реабилитац%"')))

    queueActionType = CActionTypeCache.getByCode('queue')
    cond.append(tableAction['actionType_id'].eq(queueActionType.id))

    mainCond = []
    if detailExternalIS:
        mainCond.append(u'''Locate('Call-центр', A2.note)
        or Locate('CALLCENTER', A2.note)
        or Locate('оператор колл-центра', setPerson.lastName)
        or Locate('call-центр', setPerson.lastName)
        or Locate('менеджер колл-центра', rbPost.name)
        or Locate('инфомат', A2.note)
        or Locate('E-mail', A2.note)
        or Locate('iVista Web Medical Service', A2.note)
        or Locate('ЗАПИСЬ ОСУЩЕСТВЛЕНА ЧЕРЕЗ СИСТЕМУ "НЕТРИКА"', A2.note)
        or Locate('FROM RIR', A2.note)
        or not (setPerson.lastName
            or setPerson.firstName
            or setPerson.patrName
            or setPerson.post_id
            or setPerson.speciality_id)''')
        mainCond = u'AND ' + db.joinAnd(mainCond)

    if not mainCond:
        mainCond = u''
    stmt = u'''
            SELECT DISTINCTROW
				A2.createPerson_id,
                A2.person_id,
                Client.id,
                Client.lastName,
                Client.firstName,
                Client.patrName,
                Client.birthDate,
                getClientContacts(Client.id) AS clientPhones,
                getClientRegAddress(Client.id) AS clientAddress,
                rbPolicyType.name AS policyType,
                ClientPolicy.serial,
                ClientPolicy.number,
                Insurer.shortName AS insurerName,
                AT.code AS codeAT, A2.note AS actionNote,
                A2.directionDate,
                A2.createDatetime,
                ExecPerson.speciality_id AS personSpecialyty,               
                PersonUser.name AS userName,
                ExecPerson.name AS personName,
                setPerson.lastName  AS setPersonLastName,
                setPerson.firstName  AS setPersonFirstName,
                setPerson.patrName  AS setPersonPatrName,
                setPerson.post_id  AS setPersonPost,
                setPerson.speciality_id AS setPersonSpeciality,
                rbPost.name As postName
            FROM ActionProperty_Action
            INNER JOIN ActionProperty ON ActionProperty.id = ActionProperty_Action.id
            
            INNER JOIN Action AS A ON A.id = ActionProperty.action_id
            INNER JOIN ActionType AS AT ON AT.id = A.actionType_id

            INNER JOIN Action AS A2 ON A2.id = ActionProperty_Action.value
            INNER JOIN Event ON Event.id = A2.event_id
            INNER JOIN Person AS setPerson ON setPerson.id = A2.setPerson_id
            
            INNER JOIN Client ON Client.id = Event.client_id
            INNER JOIN ClientPolicy ON ClientPolicy.client_id = Client.id
            INNER JOIN Organisation AS Insurer ON Insurer.id = ClientPolicy.insurer_id
            INNER JOIN rbPolicyType ON rbPolicyType.id = ClientPolicy.policyType_id
            
			LEFT JOIN rbPost ON rbPost.id = setPerson.post_id
            LEFT JOIN vrbPersonWithSpeciality AS ExecPerson ON ExecPerson.id = A2.person_id
            LEFT JOIN vrbPersonWithSpeciality AS PersonUser ON PersonUser.id = A2.createPerson_id
            WHERE %s
                AND Client.deleted = 0 AND Event.deleted = 0 AND A.deleted = 0 AND A2.deleted = 0   
				AND ClientPolicy.id = (SELECT MAX(CP.id) FROM ClientPolicy AS CP WHERE  CP.client_id = Client.id AND CP.deleted = 0)
                AND ActionProperty_Action.value IN (SELECT DISTINCT Action.id FROM Action WHERE %s)
                %s
            ORDER BY A2.directionDate
    ''' % (codeAT, db.joinAnd(cond), mainCond)
    return db.query(stmt)