Пример #1
0
    def fuzzySearchWorker(self, data):
        """根据关键字,模糊查询医生信息。"""

        keyword = data.get("keyword", None)
        if keyword is None:
            raise Exception("keyword required")

        workerInterface = WorkerInterface()
        result = workerInterface.fuzzySearchWorker(data)

        return result
Пример #2
0
 def setWorkerStatus(self,inputData):
     stationID = inputData["stationID"]
     id = inputData["id"]
     status = inputData["status"]
     worker = { "id":id, "stationID":stationID, "status":status }
     WorkerInterface().editWorker(worker)
     return
Пример #3
0
    def getCallerPublish(self,inputData):
        retlistInfo = {}
        retWorker = {}
        retQueue =  {}
        ret = {}
        stationID = inputData["stationID"]
        callerID = inputData["callerID"]
        selCaller = CallerInterface().getInfo({"stationID":stationID ,"id" :callerID})
        workerOnlineID = selCaller["workerOnline"]
        if workerOnlineID:
            workerOnline = WorkerInterface().getInfo({"stationID":stationID, "id" :workerOnlineID})
            #显示呼叫记录表单中的项目,有效时间内
            validDataTime = "timestamp\'" + self.getValidDateTime() + "\'"
            callRecordList = DB.DBLocal.where("callingRecord",stationID = stationID, callerID = callerID)
            if len(callRecordList) > 0:
                record = callRecordList[0]
                # 从窗口的最后一次呼叫 得到队列信息
                queueID = record["queueID"]
                queueList = StationMainController().getQueueList({"stationID":stationID, "queueID" :queueID})
                queueInfo = QueueInfoInterface().getInfo({"stationID":stationID, "id" :queueID})
                doingList = queueList["doingList"]
                waitingList = queueList["waitingList"]
                retQueue["listNum"] = len(waitingList)
                retQueue["department"] = workerOnline["department"]
                retQueue["pos"] = selCaller["pos"]
                #获得Seeing数据 从记录中的ID中得到呼叫的患者信息 呼叫显示次数递减
                seeing = StationMainController().getVisitorInfo({"stationID":stationID,"id":record["currentVisitorID"]})
                retlistInfo["seeing"] = {}
                retlistInfo["seeing"]["name"] = seeing["name"]
                retlistInfo["seeing"]["id"] = seeing["snumber"]
                if record["showCnt"] > 0:
                    retlistInfo["seeing"]["show"] = 1
                    record["showCnt"] -= 1
                    callRecordInterface().edit(record)
                else:
                    retlistInfo["seeing"]["show"] = 0

                #获得waiting数据
                retlistInfo["waiting"] = []
                for item in waitingList:
                    waitItem = {}
                    waitItem["name"] = item["name"]
                    waitItem["id"] = item["snumber"]
                    retlistInfo["waiting"].append(waitItem)

            # 获得医生数据
            retWorker["name"] = workerOnline["name"]
            retWorker["id"] = workerOnline["id"]
            retWorker["department"] = workerOnline["department"]
            retWorker["title"] = workerOnline["title"]
            retWorker["headpic"] = workerOnline["headPic"]

            ret["workerInfo"] = retWorker
            ret["queueInfo"] = retQueue
            ret["listInfo"] = retlistInfo
        return ret
Пример #4
0
    def publishNew(self,inputData,lastOne,nextOne,parpareOne,ret):
        stationID = inputData["stationID"]
        queueID = inputData["queueID"]
        workerID = inputData["id"]

        # 获得叫号器信息,位置
        caller = self.getCallerInfo(inputData)
        pos = caller["pos"]
        if parpareOne != {} and lastOne != {}:
            LogOut.info("caller next req pos " + pos + " last " + lastOne["name"] + " doing " + nextOne["name"])
            LogOut.info("parpare One : " + parpareOne["name"])

        worker = WorkerInterface().getInfo({"stationID":stationID,"id":workerID})

        #记录到呼叫记录表中
        record = {}
        record["stationID"] = stationID
        record["callerID"] = caller["id"]
        record["workerID"] = workerID
        record["queueID"] = queueID
        record["currentVisitorID"] = nextOne["id"]
        record["currentVisitorName"] = nextOne["name"]
        curDateTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        record["dateTime"] = curDateTime
        record["showCnt"] = 10
        callRecordInterface().record(record)

        key = {"type":"publish","stationID":stationID,"callerID":caller["id"],"action":"getCallerList"}
        common.func.CachedClearValue(json.dumps(key))
        key = {"type": "publish", "stationID": stationID, "callerID": caller["id"], "action": "getStationList"}
        common.func.CachedClearValue(json.dumps(key))

        # 转换呼叫音频
        cid = str(stationID) + "_" + nextOne["id"]

        qInfo = queueInfo.QueueInfoInterface().getInfo({"stationID": stationID, "id": queueID})
        sceneID = qInfo["sceneID"]
        scene = SceneInterface().getSceneInfo({"sceneID": sceneID})
        text = "请%s到%s%s" % (nextOne["name"], pos, scene["outputText"])
        if parpareOne != {}:
            text += ", 请%s准备" % parpareOne["name"]

        publishDev = PublishDevInterface()
        mediaBoxInterface = MediaBoxInterface()
        devList = publishDev.getInfo({"stationID":stationID})
        ret["list"] = []
        ret["id"] = nextOne.get("id","")
        for dev in devList:
            # 增加语音盒在线判断
            mediabox = mediaBoxInterface.mediaBoxStatus(dev)
            if mediabox["status"] == "offline":
                continue
            ret["list"].append({"soundUrl":dev["deviceIP"] , "text" : text, "id": nextOne["id"]})
Пример #5
0
 def __init__(self):
     self.callerInterface = CallerInterface()
     self.workerInterface = WorkerInterface()
     self.stationController = StationMainController()
Пример #6
0
class PublishTVInterface:

    def __init__(self):
        self.callerInterface = CallerInterface()
        self.workerInterface = WorkerInterface()
        self.stationController = StationMainController()

    def POST(self,name):

        webData = json.loads(web.data())
        action = webData["action"]

        if action == "getCallerList":
            try:
                ret = self.getCallerList(webData)
                return packOutput(ret)
            except Exception as e:
                return packOutput({}, code="400", errorInfo=str(e))
        elif action == "getStationList":
            try:
                ret = self.getStationList(webData)
                return packOutput(ret)
            except Exception as e:
                return packOutput({}, code="400", errorInfo=str(e))
        elif action == "getWinList":
            try:
                ret = self.getWinList(webData)
                return packOutput(ret)
            except Exception as e:
                return packOutput({},code="400", errorInfo=str(e))

    def getValidDateTime(self):
        now = int(time.time())
        ValidSec = now - int(4*60*60)
        return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ValidSec))

    def getCallerPublish(self,inputData):
        retlistInfo = {}
        retWorker = {}
        retQueue =  {}
        ret = {}
        stationID = inputData["stationID"]
        callerID = inputData["callerID"]
        selCaller = CallerInterface().getInfo({"stationID":stationID ,"id" :callerID})
        workerOnlineID = selCaller["workerOnline"]
        if workerOnlineID:
            workerOnline = WorkerInterface().getInfo({"stationID":stationID, "id" :workerOnlineID})
            #显示呼叫记录表单中的项目,有效时间内
            validDataTime = "timestamp\'" + self.getValidDateTime() + "\'"
            callRecordList = DB.DBLocal.where("callingRecord",stationID = stationID, callerID = callerID)
            if len(callRecordList) > 0:
                record = callRecordList[0]
                # 从窗口的最后一次呼叫 得到队列信息
                queueID = record["queueID"]
                queueList = StationMainController().getQueueList({"stationID":stationID, "queueID" :queueID})
                queueInfo = QueueInfoInterface().getInfo({"stationID":stationID, "id" :queueID})
                doingList = queueList["doingList"]
                waitingList = queueList["waitingList"]
                retQueue["listNum"] = len(waitingList)
                retQueue["department"] = workerOnline["department"]
                retQueue["pos"] = selCaller["pos"]
                #获得Seeing数据 从记录中的ID中得到呼叫的患者信息 呼叫显示次数递减
                seeing = StationMainController().getVisitorInfo({"stationID":stationID,"id":record["currentVisitorID"]})
                retlistInfo["seeing"] = {}
                retlistInfo["seeing"]["name"] = seeing["name"]
                retlistInfo["seeing"]["id"] = seeing["snumber"]
                if record["showCnt"] > 0:
                    retlistInfo["seeing"]["show"] = 1
                    record["showCnt"] -= 1
                    callRecordInterface().edit(record)
                else:
                    retlistInfo["seeing"]["show"] = 0

                #获得waiting数据
                retlistInfo["waiting"] = []
                for item in waitingList:
                    waitItem = {}
                    waitItem["name"] = item["name"]
                    waitItem["id"] = item["snumber"]
                    retlistInfo["waiting"].append(waitItem)

            # 获得医生数据
            retWorker["name"] = workerOnline["name"]
            retWorker["id"] = workerOnline["id"]
            retWorker["department"] = workerOnline["department"]
            retWorker["title"] = workerOnline["title"]
            retWorker["headpic"] = workerOnline["headPic"]

            ret["workerInfo"] = retWorker
            ret["queueInfo"] = retQueue
            ret["listInfo"] = retlistInfo
        return ret

    # 获取药房呼叫队列
    def getCallerListPublish(self,inputData):
        retlistInfo = {}
        ret = {}
        stationID = inputData["stationID"]
        callerID = inputData["callerID"]
        callerList = DB.DBLocal.select("caller", where="id=$id", vars={"id": callerID})
        if len(callerList) == 0:
            raise Exception("[ERR]: caller not exists.")
        validDateTime = datetime.datetime.strptime(self.getValidDateTime(), "%Y-%m-%d %H:%M:%S")
        callRecordList = DB.DBLocal.select("callingRecord",
                                         where="stationID=$stationID AND callerID=$callerID AND dateTime>$dateTime",
                                         vars={"stationID": stationID, "callerID": callerID, "dateTime": validDateTime})
        if len(callRecordList) > 0:
            record = callRecordList[0]
            # 从窗口的最后一次呼叫 得到队列信息
            queueID = record["queueID"]
            queueList = StationMainController().getQueueList({"stationID":stationID, "queueID" :queueID})
            queueInfo = QueueInfoInterface().getInfo({"stationID":stationID, "id" :queueID})
            doingList = queueList["doingList"]
            waitingList = queueList["waitingList"]
            retlistInfo["seeingList"] = []
            for item in doingList:
                seeingItem = {}
                seeingItem["name"] = item["name"]
                seeingItem["id"] = item["snumber"]
                retlistInfo["seeingList"].append(seeingItem)

            retlistInfo["watingList"] = []
            for item in waitingList:
                waitItem = {}
                if item["locked"]:
                    continue
                waitItem["name"] = item["name"]
                waitItem["id"] = item["snumber"]
                retlistInfo["watingList"].append(waitItem)
        callRecordList = DB.DBLocal.where("callingRecord", stationID=stationID, callerID=callerID)
        retlistInfo["calling"] = []
        if len(callRecordList) > 0:
            record = callRecordList[0]
            # 病人ID显示为snumber
            currentVisitor = self.stationController.getVisitorInfo(
                {"stationID": stationID, "id": record["currentVisitorID"]})
            calling = {}
            calling["name"] = record["currentVisitorName"]
            calling["id"] = currentVisitor["snumber"]
            calling["pos"] = callerList[0]["pos"]
            retlistInfo["calling"] = calling
        ret = retlistInfo
        return ret

    # def getCallerList(self,inputData):
    #     retList = {"list":[]}
    #     stationID = inputData["stationID"]
    #     callerList = inputData["callerID"]
    #     for caller in callerList:
    #         ret = self.getCallerPublish({"stationID" : stationID, "callerID" : caller})
    #         retList["list"].append(ret)
    #     return retList
    def getCallerList(self, inputData):
        stationID = inputData.get("stationID", None)
        callerList = inputData.get("callerID", None)
        action = inputData.get("action", None)
        if stationID is None:
            raise Exception("[ERR]: stationID required.")
        station = DB.DBLocal.select("stationSet", where="id=$id", vars={"id": stationID})
        if len(station) == 0:
            raise Exception("[ERR]: station not exists.")
        # if not callerList:
        #     raise Exception("[ERR]: callerID required.")
        if action is None:
            raise Exception("[ERR]: action required.")

        # 获取叫号器下的医生、队列等信息
        publishList = []
        result = {}
        for caller in callerList:
            try:
                out = self.getPublishList({"stationID": stationID, "callerID": caller, "action": action})
            except:
                continue
            else:
                if not out: continue
            publishList.append(out)
        result["list"] = publishList
        if not publishList:
            return result

        # 判断叫号器叫号时,是否显示弹窗信息
        current_time = datetime.datetime.now()
        tmp = []
        for item in publishList:
            listInfo = item["listInfo"]
            seeing = listInfo["seeing"]
            if not isinstance(seeing, dict):
                continue
            dateTime = seeing.pop("dateTime", None)
            if not dateTime:
                continue
            interval = (current_time - dateTime).seconds
            if interval < 10:
                tmp.append((interval, seeing))
        tmp.sort(key=lambda x: x[0], reverse=True)
        # tmp的格式类似于:
        # tmp = [(9, seeing), (5, seeing), (4, seeing), (1, seeing)]
        # 然后根据interval的值确定seeing字典中的show的值
        if len(tmp) == 1:
            tmp[0][1]["show"] = 1
        elif len(tmp) ==2 :
            if tmp[0][0] < 5:
                tmp[0][1]["show"] = 1
            else:
                tmp[1][1]["show"] = 1
        elif len(tmp) > 2:
            if tmp[0][0] < 4:
                tmp[0][1]["show"] = 1
            elif tmp[1][0] < 8:
                tmp[1][1]["show"] = 1
            else:
                tmp[2][1]["show"] = 1
        return result

    def getWinList(self,inputData):
        retList = {"list":[]}
        stationID = inputData["stationID"]
        callerList = inputData["callerID"]
        for caller in callerList:
            ret = self.getCallerListPublish({"stationID" : stationID, "callerID" : caller})
            retList["list"].append(ret)
        return retList

    # def getStationList(self,inputData):
    #     retList = {"list": []}
    #     stationID = inputData["stationID"]
    #     callList = CallerInterface().getList({"stationID": stationID })
    #     for item in callList:
    #         ret = self.getCallerPublish({"stationID": stationID ,"callerID" : item["id"]})
    #         if "listInfo" in ret:
    #             if ret["listInfo"] != {}:
    #                 retList["list"].append(ret)
    #     return retList

    def getStationList(self, inputData):
        action = inputData.get("action", None)
        if action is None:
            raise Exception("[ERR]: action required.")
        stationID = inputData.get("stationID", None)
        if stationID is None:
            raise Exception("[ERR]: stationID required.")
        # 这里还是要判断station是否存在,否则删除掉分诊台后,由于不会删除和分诊台相关的其他信息,所以还是会显示
        station = DB.DBLocal.select("stationSet", where="id=$id", vars={"id": stationID})
        if len(station) == 0:
            raise Exception("[ERR]: station not exists.")

        callerList = self.callerInterface.getList({"stationID": stationID})
        callerID = []
        for item in callerList:
            id = item["id"]
            callerID.append(id)
        result = self.getCallerList({"stationID": stationID, "callerID": callerID, "action": action})
        return result

    def getPublishList(self, inputData):
        stationID = inputData.get("stationID", None)
        if stationID is None:
            raise Exception("[ERR]: stationID required.")
        callerID = inputData.get("callerID", None)
        action = inputData.get("action", None)
        if action is None:
            raise Exception("[ERR]: action required.")

        # if can get from Memcached
        key = "_getPublishList_stationID" + str(stationID) +"_callerID"+ str(callerID) + "_action" + action
        value = common.func.CachedGetValue(json.dumps(key))
        if value != False:
            return value

        # TODO: 试验删掉医生的情况
        # 如果获取叫号器信息时发生异常,在上层函数中处理
        caller = self.callerInterface.getInfo({"stationID": stationID, "id": callerID})
        workerID = caller["workerOnline"]
        try:
            workerOnline = self.workerInterface.getInfo({"stationID": stationID, "id": workerID})
            workerInfo = {
                "id": workerOnline["id"],
                "name": workerOnline["name"],
                "title": workerOnline["title"],
                "descText": workerOnline["descText"],
                "department": workerOnline["department"],
                "headpic": workerOnline["headPic"],
                "status": workerOnline["status"],
                "speciality": workerOnline["speciality"]
            }

            if action == 'getStationList' and workerInfo["status"] == "离开":
                return None
        except:
            workerInfo = {"id": "", "name": "", "title": "", "descText": "", "department": "", "headpic": ""}

        # 获取呼叫队列的信息
        queueInfo = {
            "department": workerInfo["department"],
            "pos": caller["pos"],
            "listNum": 0
        }

        # 获取正在就诊、正在排队的信息
        seeing = {"id": "", "name": "", "show": 0, "status": ""}
        waiting = []
        validDateTime = datetime.datetime.strptime(self.getValidDateTime(), "%Y-%m-%d %H:%M:%S")
        callerRecord = DB.DBLocal.select("callingRecord",
                                         where="stationID=$stationID AND callerID=$callerID AND dateTime>$dateTime",
                                         vars={"stationID": stationID, "callerID": callerID, "dateTime": validDateTime})

        try:
            record = callerRecord[0]
            queueID = record["queueID"]
            queue = QueueInfoInterface().getInfo({"stationID": stationID, "id": queueID})
            sceneID = queue["sceneID"]
            scene = SceneInterface().getSceneInfo({"sceneID": sceneID})
            queueList = self.stationController.getQueueList({"stationID": stationID, "queueID": queueID})
        except:
            if action == 'getStationList':
                result = {}
                return result
        else:
            # 获取呼叫队列中当前看诊的信息
            currentVisitor = self.stationController.getVisitorInfo({"stationID": stationID, "id": record["currentVisitorID"]})
            if currentVisitor["localStatus"] == 'doing':
                seeing["id"] = currentVisitor["snumber"]
                seeing["name"] = currentVisitor["name"]
                seeing["status"] = self.getVisitorStatus(**currentVisitor)
                seeing["outputText"] = scene["outputText"]
                seeing["show"] = 0
            seeing["dateTime"] = record["dateTime"]

            # 获取呼叫队列中当前排队的信息
            waitingList = queueList["waitingList"]
            queueInfo.update({"listNum": len(waitingList), "queueName": queue["name"]})
            for item in waitingList:
                if item["locked"]:
                    continue
                waitingVisitor = {}
                waitingVisitor["id"] = item["snumber"]
                waitingVisitor["name"] = item["name"]
                waitingVisitor["status"] = self.getVisitorStatus(**item)
                waiting.append(waitingVisitor)

        result = {}
        result["workerInfo"] = workerInfo
        result["queueInfo"] = queueInfo
        result["listInfo"] = {"seeing": seeing, "waiting": waiting}

        # 缓存 value
        common.func.CahedSetValue(json.dumps(key), result, 3)

        return result

    def getVisitorStatus(self, **kwargs):
        prior = kwargs.get("prior", None)
        locked = kwargs.get("locked", None)
        VIP = kwargs.get("VIP", None)
        localVip = kwargs.get("localVip", None)
        orderType = kwargs.get("orderType", None)

        if locked:
            result = "locked"
        elif prior == 1:
            result = "review"
        elif prior == 2:
            result = "pass"
        elif prior == 3:
            result = "delay"
        elif VIP or localVip:
            result = "VIP"
        elif orderType:
            result = "order"
        else:
            result = "normal"

        return result
Пример #7
0
    def getDepartment(self, data):
        """查询科室信息"""

        result = WorkerInterface().getDepartment(data)
        return result
Пример #8
0
    def publishNew(self, inputData, lastOne, nextOne, prepareOne, ret):
        stationID = inputData["stationID"]
        queueID = inputData["queueID"]
        workerID = inputData["id"]

        # 获得叫号器信息,位置
        caller = self.getCallerInfo(inputData)
        pos = caller["pos"]
        if prepareOne != {} and lastOne != {}:
            LogOut.info("caller next req pos " + pos + " last " + lastOne["name"] + " doing " + nextOne["name"])
            LogOut.info("parpare One : " + prepareOne["name"])

        worker = WorkerInterface().getInfo({"stationID":stationID,"id":workerID})

        #记录到呼叫记录表中
        record = {}
        record["stationID"] = stationID
        record["callerID"] = caller["id"]
        record["workerID"] = workerID
        record["queueID"] = queueID
        record["currentVisitorID"] = nextOne["id"]
        record["currentVisitorName"] = nextOne["name"]
        curDateTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        record["dateTime"] = curDateTime
        record["showCnt"] = 10
        callRecordInterface().record(record)

        key = {"type":"publish","stationID":stationID,"callerID":caller["id"],"action":"getCallerList"}
        common.func.CachedClearValue(json.dumps(key))
        key = {"type": "publish", "stationID": stationID, "callerID": caller["id"], "action": "getStationList"}
        common.func.CachedClearValue(json.dumps(key))

        #更新nextOne和prepareOne的信息
        if nextOne:
            where = {"id": nextOne["id"]}
            next_visitor = DB.DBLocal.select("visitor_source_data",
                                             where=where).first()
            nextOne.update({"snumber": next_visitor.snumber})
            nextOne.update({"cardID": next_visitor.cardID})
        if prepareOne:
            where = {"id": prepareOne["id"]}
            prepare_visitor = DB.DBLocal.select("visitor_source_data",
                                                where=where).first()
            prepareOne.update({"snumber": prepare_visitor.snumber})
            prepareOne.update(({"cardID": prepare_visitor.cardID}))

        # 转换呼叫音频
        cid = str(stationID) + "_" + nextOne["id"]

        qInfo = queueInfo.QueueInfoInterface().getInfo({"stationID": stationID, "id": queueID})
        sceneID = qInfo["sceneID"]
        scene = SceneInterface().getSceneInfo({"sceneID": sceneID})
        # V1.2.1 增加按照名字、序号、卡号等语音播报方式
        # V1.2.1 将"请***准备"设置为可配置项
        property = scene["property"]
        callMode = property["callMode"]
        if callMode == 'callByName':
            nextOneText = nextOne.get("name")
            prepareOneText = prepareOne.get("name", "")
        elif callMode == 'callBySnumber':
            nextOneText = "%s号" % nextOne.get("snumber")
            prepareOneText = "%s号" % prepareOne.get("snumber", "")
        elif callMode == 'callByCardID':
            nextOneText = nextOne.get("cardID")
            prepareOneText = prepareOne.get("cardID", "")
        else:
            raise Exception("unsupport callMode")
        text = "请%s到%s%s" % (nextOneText, pos, scene["outputText"])
        # TODO: V1.21  scene property add noPrepare
        if not property["noPrepare"]:
            if prepareOne != {}:
                text += ", 请%s准备" % prepareOneText

        publishDev = PublishDevInterface()
        mediaBoxInterface = MediaBoxInterface()
        devList = publishDev.getInfo({"stationID":stationID})
        ret["list"] = []
        for dev in devList:
            # 增加语音盒在线判断
            mediabox = mediaBoxInterface.mediaBoxStatus(dev)
            callerLimit = mediabox["callerLimit"]
            if callerLimit:
                callerLimit = str2List(callerLimit)
                if caller["id"] not in callerLimit:
                    continue
            if mediabox["status"] == "offline":
                continue
            ret["list"].append({"soundUrl":dev["deviceIP"] , "text" : text, "id": nextOne["id"]})