Ejemplo n.º 1
0
    def _set_memcached_value(self, key, data):
        """将需要缓存的分诊台信息写入memcached

        Args:
            key: 键
            **data: 需要写入的数据
        """
        queue = CachedGetValue(json.dumps(key))
        if not queue:
            queue = deque([])
        queue.extend(data)
        CahedSetValue(json.dumps(key), queue, timeout=300)
Ejemplo n.º 2
0
 def wrapper(*args, **kw):
     value = CachedGetValue(json.dumps(key))
     if value:
         return value
     result = func(*args, **kw)
     CahedSetValue(json.dumps(key), result, timeout)
     return result
Ejemplo n.º 3
0
    def getInfo(self,inputData):
        # TODO: 如果队列的orderAllow属性以后要放在策略配置中,那此处的查询语句要修改
        # TODO: 如果手动在数据库中删除策略,也应该要能获取到队列信息(sceneID在scene表中不存在如何处理)
        stationID = inputData["stationID"]
        id = inputData["id"]

        # 获取缓存
        key = {"type": "queueInfo", "queueID": id, "stationID": stationID}
        value = CachedGetValue(json.dumps(key))
        if value != False:
            return value

        sql = "SELECT q.id, q.name, q.stationID, q.descText, q.filter, " \
              "q.workerOnline, q.workerLimit, q.department, q.isExpert, " \
              "q.orderAllow, s.id as sceneID, s.name as scene, s.activeLocal " \
              "FROM queueInfo AS q LEFT JOIN scene " \
              "AS s ON q.sceneID = s.id WHERE q.id=%s" % id
        # ret = DB.DBLocal.where('queueInfo', stationID=inputData["stationID"],id = inputData["id"])
        ret = DB.DBLocal.query(sql).first()
        if not ret:
            raise Exception("[ERR]: queue not exists.")

        # 缓存 value
        CahedSetValue(json.dumps(key), ret, 3)

        return ret
Ejemplo n.º 4
0
    def getPatientsInfo(self, startDate=None, endDate=None):
        """查询所有队列所有排队的患者信息。

        Returns: 所有队列所有患者的排队信息。

        """
        key = "_getPatientsInfo_ext"
        value = CachedGetValue(key)
        if value != False:
            return value

        if startDate and endDate:
            where = "registDate BETWEEN \'{0}\' AND \'{1}\'".format(
                startDate, endDate)
        else:
            where = "registDate = \'{0}\'".format(
                datetime.datetime.now().strftime("%Y-%m-%d"))
        what = "id, name, age, snumber, cardID AS userPid, registDate, " \
               "queueID, department, localStatus, " \
               "prior, locked, localVip, VIP, orderType"
        order = "stationID, queueID, finalScore, originScore"
        patients = self.db.select("visitor_view_data", what=what,
                                  order=order).list()

        queue_id_list = []
        counter = 0
        queue_counter = defaultdict(int)

        # 获得每个队列的排队人数
        for p in patients:
            queueID = p.queueID
            if queueID not in queue_id_list:
                queue_id_list.append(queueID)
            if p.localStatus not in ('finish', 'doing', 'pass'):
                queue_counter[p.queueID] += 1

        # 获取所有队列名称信息
        queue_info = {}
        if queue_id_list:
            what = "id, name"
            where = "id IN {0}".format(web.sqlquote(queue_id_list))
            queues = self.db.select("queueInfo", where=where, what=what).list()
            for q in queues:
                queue_info[q.id] = q.name
            queue_id_list = []

        # 更新返回值
        for p in patients:
            queueID = p.pop("queueID")
            if queueID not in queue_id_list:
                counter = 0
                queue_id_list.append(queueID)

            localStatus = p.localStatus
            if localStatus in ('finish', 'doing', 'pass'):
                pass
            else:
                counter += 1

            if localStatus in ('finish', 'doing'):
                waitNum = 0
            elif localStatus == 'pass':
                waitNum = queue_counter[queueID]
            else:
                waitNum = counter

            kw = {
                "prior": p.pop("prior"),
                "locked": p.pop("locked"),
                "localVip": p.pop("localVip"),
                "orderType": p.pop("orderType"),
                "VIP": p.pop("VIP")
            }
            status = PublishTVInterface().getVisitorStatus(**kw)

            if localStatus == 'finish':
                localStatus = '已完成'
            elif localStatus == 'doing':
                localStatus = '正在就诊'
            elif localStatus == 'waiting':
                localStatus = '正在排队'
            elif localStatus == 'pass':
                localStatus = '已过号'
            elif localStatus == 'unactive':
                localStatus = '未激活'
            elif localStatus == 'unactivewaiting':
                localStatus = '激活等待中'

            if status == 'locked':
                status = '锁定'
            elif status == 'review':
                status = '复诊'
            elif status == 'pass':
                status = '过号'
            elif status == 'delay':
                status = '延后'
            elif status == 'VIP':
                status = 'VIP'
            elif status == 'order':
                status = '预约'
            else:
                status = '普通'
            print "queueID :", queueID
            print "queue_info :", queue_info
            if queueID in queue_info:
                p.update({
                    "waitingNum": waitNum,
                    "waitingTime": waitNum * 15,
                    "queueName": queue_info[queueID],
                    "localStatus": localStatus,
                    "status": status
                })

        CahedSetValue(key, patients, 10)

        return patients