Пример #1
0
    def findQueueableEntry(self, routing):
        queueables = []
        retval = None      # default: nothing to queue on this routing slip

        if not self.isWaiting(routing):
            for x in routing:
                entry = GetRoutingSlipEntry(self._host, self._port, self._token, x)
                ret = entry.send(timeout=30)
                if ret[0] == 200:
                    state = ret[1]["state"] 

                    if state == "New" :
                        queueables.append(ret[1])

        if len(queueables):

            # found something to schedule, find highest priority with smallest queue size

            if len(queueables) == 1:
                retval = queueables[0]          # last station for this patient, choose it
            else:       
                # sort the queueables into stations in order of highest priority to lowest.

                tmp = self.sortQueueablesByPriority(queueables)

                retval = self.getSmallestLengthQueue(tmp) 
                
        return retval
Пример #2
0
    def findQueueableEntry(self, routing):
        queueables = []
        retval = None  # default: nothing to queue on this routing slip

        if not self.isScheduledOrCheckedIn(routing):
            for x in routing:
                if self.hasReturnToClinicNotCheckedOut(x):
                    continue
                entry = GetRoutingSlipEntry(self._host, self._port,
                                            self._token)
                entry.setId(x)
                ret = entry.send(timeout=30)
                if ret[0] == 200:
                    state = ret[1]["state"]
                    if state == "New":
                        queueables.append(ret[1])
                else:
                    self.showError(
                        "findQueueableEntry failure in GetRoutingSlipEntry".
                        format(ret[0]))
        if len(queueables):

            # found something to schedule, find highest priority with smallest queue size

            if len(queueables) == 1:
                retval = queueables[
                    0]  # last station for this patient, choose it
            else:
                # sort the queueables into stations in order of highest priority to lowest.

                tmp = self.sortQueueablesByPriority(queueables)

                retval = self.getSmallestLengthQueue(tmp)

        return retval
Пример #3
0
    def findQueueableEntry(self, routing):
        queueables = []
        retval = None      # default: nothing to queue on this routing slip

        if not self.isScheduledOrCheckedIn(routing):
            for x in routing:
                if self.hasReturnToClinicNotCheckedOut(x):
                    continue
                entry = GetRoutingSlipEntry(self._host, self._port, self._token)
	    	entry.setId(x)
                ret = entry.send(timeout=30)
                if ret[0] == 200:
                    state = ret[1]["state"] 
                    if state == "New" :
                        queueables.append(ret[1])
                else:
                    print("findQueueableEntry failure in GetRoutingSlipEntry".format(ret[0]))
        if len(queueables):

            # found something to schedule, find highest priority with smallest queue size

            if len(queueables) == 1:
                retval = queueables[0]          # last station for this patient, choose it
            else:       
                # sort the queueables into stations in order of highest priority to lowest.

                tmp = self.sortQueueablesByPriority(queueables)

                retval = self.getSmallestLengthQueue(tmp) 
                
        return retval
Пример #4
0
    def findCreatedReturnToClinicStationQueueables(self, clinicid):
        queueables = []

        x = GetReturnToClinicStation(self._host, self._port, self._token)
        x.setClinic(clinicid)
        x.setState("created")
        ret = x.send(timeout=30)
        if ret[0] == 200:
            createdList = ret[1]
        else:
            createdList = []

        for x in createdList:

            # get the routing slip for the patient

            y = GetReturnToClinicStation(self._host, self._port, self._token)
            y.setId(x["id"])
            ret = y.send(timeout=30)
            if not (ret[0] == 200):
                self.showWarning(
                    "findCreatedReturnToClinicStation warning: unable to get returntoclinicstation id {}: return {}"
                    .format(x["id"], ret[0]))
                continue
            y = GetRoutingSlip(self._host, self._port, self._token)
            y.setClinic(clinicid)
            patientid = ret[1]["patient"]
            stationid = ret[1]["station"]
            y.setPatient(patientid)
            ret = y.send(timeout=30)
            if not (ret[0] == 200):
                self.showWarning(
                    "findCreateReturnToClinicStation warning: unable to get routing slip for clinic {} and patient {}: return {}"
                    .format(x["clinic"], x["patient"], ret[0]))
                continue

            # create a routing slip entry for the patient

            routingslipid = ret[1]["id"]
            y = CreateRoutingSlipEntry(self._host, self._port, self._token)
            y.setRoutingSlip(routingslipid)
            y.setStation(stationid)
            y.setReturnToClinicStation(x["id"])
            ret = y.send(timeout=30)
            if not (ret[0] == 200):
                self.showWarning(
                    "findCreateReturnToClinicStation warning: unable to create a routing slip entry for clinic {} patient {} station {} routingslip {} returntoclinicstation {}: return {}"
                    .format(clinicid, patientid, stationid, routingslipid,
                            x["id"], ret[0]))
                continue
            entry = GetRoutingSlipEntry(self._host, self._port, self._token)
            entry.setId(ret[1]["id"])
            ret = entry.send(timeout=30)
            if ret[0] == 200:
                queueables.append((ret[1], patientid, x["id"]))
        return queueables
Пример #5
0
    def hasReturnToClinicNotCheckedOut(self, routingslipid):
        '''
        call this function from findQueueableEntry. If returns True, skip this patient.
        otherwise, the patient may be returned to a clinicstation that is not the
        specified requestingclinicstation for the active returntoclinicstation record.

        this keeps the scheduler for overriding the returntoclinicstation logic and
        sending the patient to the next unscheduled item in the routingslip, instead
        of back to the requesting station (which is where a patient must go after being
        seen by a "returntoclinicstation" station). Example, if dentist sends to xray,
        patient must go back to that dentist, not to some other station (like hygiene).
        '''
        '''
        pseudocode

        select routingslipentry where routingslip == routingslip and returntoclinic != null and state != o

        if result not empty
            skip
        '''
        x = GetRoutingSlipEntry(self._host, self._port, self._token)
        x.setRoutingSlip(routingslipid)
        x.setNullrcs(False)
        x.setStates("Checked In, New, Scheduled, Removed, Return")
        ret = x.send(timeout=30)
        if ret[0] == 404:
            return False
        else:
            return True
Пример #6
0
    def fillAnEmptyQueue(self):
        empty = self.getEmptyQueues()
        for x in empty:
            station = self._clinicStationToStationMap[str(x)]
            for k, v in self._queues.iteritems():
                active = self._clinicStationActiveMap[str(k)]
                finished = self._clinicStationFinishedMap[str(k)]
                away = self._clinicStationAwayMap[str(k)]
                if k == x:
                    if len(v):
                        break  # queue is no longer empty, go to next queue
                    else:
                        continue  # queue is one we are trying to fill, skip
                if len(
                        v
                ) == 1 and finished == False and active == False and away == False:
                    continue  # patient is probably being retrieved, don't move from this queue
                '''
                iterate the queue, looking for a patient that has the 
                station of the empty queue in his or her routing slip. 
                If found, move that patient to the queue that is empty.
                '''
                count = 0
                for item in v:
                    if active == False:
                        count = count + 1  # if not active, skip first in list
                        continue
                    qent = item["qent"]
                    r = GetRoutingSlip(self._host, self._port, self._token)
                    r.setId(qent.getRoutingSlip())
                    ret = r.send(timeout=30)
                    if ret[0] == 200:
                        routing = ret[1]["routing"]
                        patient = ret[1]["patient"]
                        for y in routing:
                            entry = GetRoutingSlipEntry(
                                self._host, self._port, self._token)
                            entry.setId(y)
                            ret = entry.send(timeout=30)
                            if ret[0] == 200:
                                rse = ret[1]
                                state = ret[1]["state"]
                                if str(ret[1]["station"]) == station and (
                                        state == "Scheduled"):
                                    self.showInfo(
                                        "************ moving a queue item ******************* item {} patient {}"
                                        .format(y, patient))

                                    dbQueue = self._dbQueues[k]
                                    ret = self.deleteDbQueueEntry(
                                        dbQueue.id, qent.getPatientId(),
                                        rse["id"])
                                    if ret == True:
                                        self.markNew(rse["id"])
                                        self._queues[k].remove(item)
Пример #7
0
    def findCheckedOutDestReturnToClinicStationQueueables(self, clinicid):
        queueables = []

        x = GetReturnToClinicStation(self._host, self._port, self._token)
        x.setClinic(clinicid)
        x.setState("checked_out_dest")
        ret = x.send(timeout=30)
        if ret[0] == 200:
            checkedOutDestList = ret[1]
        else:
            checkedOutDestList = []

        for x in checkedOutDestList:

            returntoclinicstationid = x["id"]
            y = GetReturnToClinicStation(self._host, self._port, self._token)
            y.setId(returntoclinicstationid)
            ret = y.send(timeout=30)
            if not (ret[0] == 200):
                print("findCheckedOutDestReturnToClinicStationQueueables warning: unable to get returntoclinicstation id {}: return {}".format(returntoclinicstationid, ret[0]))
                continue

            # get the routing slip for the patient

            requestingclinicstationid = ret[1]["requestingclinicstation"]
            patientid = ret[1]["patient"]
            stationid = ret[1]["station"]

            y = GetRoutingSlip(self._host, self._port, self._token)
            y.setClinic(clinicid)
            y.setPatient(patientid)
            ret = y.send(timeout=30)
            if not (ret[0] == 200):
                print("findCheckedOutDestReturnToClinicStationQueueables warning: unable to get routing slip for clinic {} and patient {}: return {}".format(x["clinic"], x["patient"], ret[0]))
                continue

            # create a routing slip entry for the patient

            routingslipid = ret[1]["id"]
            y = CreateRoutingSlipEntry(self._host, self._port, self._token)
            y.setRoutingSlip(routingslipid)
            y.setStation(self._clinicStationToStationMap[str(requestingclinicstationid)])
            #y.setStation(stationid)
            y.setReturnToClinicStation(returntoclinicstationid)
            ret = y.send(timeout=30)
            if not (ret[0] == 200):
                print("findCheckedOutDestReturnToClinicStationQueueables warning: unable to create a routing slip entry for clinic {} patient {} station {} routingslip {} returntoclinicstation {}: return {}".format(clinicid, patientid, stationid, routingslipid, returntoclinicstationid, ret[0]))
                continue
            entry = GetRoutingSlipEntry(self._host, self._port, self._token)
	    entry.setId(ret[1]["id"])
            ret = entry.send(timeout=30)
            if ret[0] == 200:
                queueables.append((ret[1], patientid, returntoclinicstationid, requestingclinicstationid))
        return queueables
Пример #8
0
    def isWaiting(self, routing):
        retval = False

        for x in routing:
            entry = GetRoutingSlipEntry(self._host, self._port, self._token, x)
            ret = entry.send(timeout=30)
            if ret[0] == 200:
                state = ret[1]["state"] 

                if state == "Scheduled" or state == "Checked In":
                    retval = True
                    break

        return retval
Пример #9
0
    def hasReturnToClinicNotCheckedOut(self, routingslipid):
        '''
        call this function from findQueueableEntry. If returns True, skip this patient.
        otherwise, the patient may be returned to a clinicstation that is not the
        specified requestingclinicstation for the active returntoclinicstation record.

        this keeps the scheduler for overriding the returntoclinicstation logic and
        sending the patient to the next unscheduled item in the routingslip, instead
        of back to the requesting station (which is where a patient must go after being
        seen by a "returntoclinicstation" station). Example, if dentist sends to xray,
        patient must go back to that dentist, not to some other station (like hygiene).
        '''

        '''
        pseudocode

        select routingslipentry where routingslip == routingslip and returntoclinic != null and state != o

        if result not empty
            skip
        '''
        x = GetRoutingSlipEntry(self._host, self._port, self._token)
        x.setRoutingSlip(routingslipid)
        x.setNullrcs(False)
        x.setStates("Checked In, New, Scheduled, Removed, Return")
        ret = x.send(timeout=30)
        if ret[0] == 404:
            return False
        else:
            return True
Пример #10
0
    def isScheduledOrCheckedIn(self, routing):
        retval = False

        for x in routing:
            entry = GetRoutingSlipEntry(self._host, self._port, self._token)
	    entry.setId(x)
            ret = entry.send(timeout=30)
            if ret[0] == 200:
                state = ret[1]["state"] 

                if state == "Scheduled" or state == "Checked In":
                    retval = True
                    break

        return retval
Пример #11
0
def inRoutingSlip(mockclinic, clinicid, patientid, stationid):
    retval = False
    host = mockclinic._host
    port = mockclinic._port
    token = mockclinic._token

    x = GetRoutingSlip(host, port, token)
    x.setClinic(clinicid)
    x.setPatient(patientid)
    ret = x.send(timeout=30)
    if ret[0] == 200:
        entries = ret[1]["routing"]
        for entry in entries:
            x = GetRoutingSlipEntry(host, port, token)
            x.setId(entry)
            ret = x.send(timeout=30)
            if ret[0] == 200:
                station = ret[1]["station"]
                if station == stationid:
                    retval = True
                    break
            else:
                print(
                    "inRoutingSlip failed to get routing slip entry {} return {}"
                    .format(entry, ret[0]))
    else:
        print(
            "inRoutingSlip failed to get routing slip for clinic {} patient {} return {}"
            .format(clinicid, patientid, ret[0]))
    return retval
Пример #12
0
    def fillAnEmptyQueue(self):
        empty = self.getEmptyQueues()
        for x in empty:
            station = self._clinicStationToStationMap[str(x)]
            for k, v in self._queues.iteritems():
                active = self._clinicStationActiveMap[str(k)]
                finished = self._clinicStationFinishedMap[str(k)]
                away = self._clinicStationAwayMap[str(k)]
                if k == x:
                    if len(v):
                        break    # queue is no longer empty, go to next queue
                    else:
                        continue # queue is one we are trying to fill, skip
                if len(v) == 1 and finished == False and active == False and away == False:
                    continue     # patient is probably being retrieved, don't move from this queue
                '''
                iterate the queue, looking for a patient that has the 
                station of the empty queue in his or her routing slip. 
                If found, move that patient to the queue that is empty.
                ''' 
                count = 0 
                for item in v:
                    if active == False:
                        count = count + 1  # if not active, skip first in list
                        continue
                    qent = item["qent"] 
                    r = GetRoutingSlip(self._host, self._port, self._token)
		    r.setId(qent.getRoutingSlip())
                    ret = r.send(timeout=30)
                    if ret[0] == 200:
                        routing = ret[1]["routing"]
                        patient = ret[1]["patient"]
                        for y in routing:
                            entry = GetRoutingSlipEntry(self._host, self._port, self._token)
			    entry.setId(y)
                            ret = entry.send(timeout=30)
                            if ret[0] == 200:
                                rse = ret[1]
                                state = ret[1]["state"] 
                                if str(ret[1]["station"]) == station and (state == "Scheduled"):
                                    print ("************ moving a queue item ******************* item {} patient {}".format(y, patient))

                                    dbQueue = self._dbQueues[k]
                                    ret = self.deleteDbQueueEntry(dbQueue.id, qent.getPatientId(), rse["id"])
                                    if ret == True:
                                        self.markNew(rse["id"])
                                        self._queues[k].remove(item)
Пример #13
0
 def findRemovedRoutingSlipEntries(self, routing):
     retval = []
     x = GetRoutingSlipEntry(self._host, self._port, self._token)
     x.setRoutingSlip(routing)
     x.setStates("Removed")
     ret = x.send(timeout=30)
     if ret[0] == 200:
         retval = ret[1]
     return retval
Пример #14
0
 def findRemovedRoutingSlipEntries(self, routing):
     retval = []
     x = GetRoutingSlipEntry(self._host, self._port, self._token)
     x.setRoutingSlip(routing)
     x.setStates("Removed")
     ret = x.send(timeout=30)
     if ret[0] == 200:
         retval = ret[1]
     return retval