Exemple #1
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    
Exemple #2
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)
Exemple #3
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)
Exemple #4
0
    def run(self):

        while True:
            pickle.dump(self, open(picklepath, "wb"))
            clinic = self.getClinic()
            if not clinic:
                continue

            self.updateClinicStations()

            # get all the routing slips for the clinic

            x = GetRoutingSlip(self._host, self._port, self._token)
            x.setClinic(clinic["id"])
            ret = x.send(timeout=30)
            if ret[0] == 200:
                results = ret[1]

                # process each of the routing slips

                for i in results:
                    routing = i["routing"]
                    entry = self.findQueueableEntry(routing)
                    if entry:
                        # append the entry to the corresponding
                        # clinicstation queue
                        if self.addToQueue(entry, i["patient"]) == True:
                            # update the routingslip entry state to "Scheduled"
                            self.markScheduled(entry)
                            break
                        else:
                            print("Unable to add item to queue")

            else:
                print("GetRoutingSlip failed")
            for k, v in self._queues.iteritems():
                for y in v:
                    ret = y["qent"].update()
                    if not ret:
                        v.remove(y)

            self.dumpQueues()
            self.fillAnEmptyQueue()
            self.updateQueueAvgServiceTime()
            time.sleep(5)
Exemple #5
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
Exemple #6
0
    def run(self):

        while True:
            clinic = self.getClinic()
            if not clinic:
                continue

            self.updateClinicStations()
            self.dumpQueues()

            # get all the routing slips for the clinic

            x = GetRoutingSlip(self._host, self._port, self._token)
            x.setClinic(clinic["id"])
            ret = x.send(timeout=30)
            if ret[0] == 200:
                results = ret[1]

                # process each of the routing slips

                for i in results:
                    routing = i["routing"]
                    entry = self.findQueueableEntry(routing)
                    if entry:
                        # update the routingslip entry state to "Scheduled"
                        self.markScheduled(entry)
                        # append the entry to the corresponding
                        # clinicstation queue
                        self.addToQueue(entry, i["patient"])
                        break

            for k, v in self._queues.iteritems():
                for y in v:
                    ret = y["qent"].update()
                    if not ret:
                        v.remove(y)

            time.sleep(5)
Exemple #7
0
    def run(self):

        while True:
            pickle.dump(self, open(picklepath, "wb"))
            clinic = self.getClinic()
            if not clinic:
                continue

            self.updateClinicStations()

            # process any newly created returntoclinicstation resources

            found = False

            rtcQueueables = self.findCreatedReturnToClinicStationQueueables(
                clinic["id"])

            for rtc in rtcQueueables:
                # append the entry to the corresponding
                # clinicstation queue
                entry = rtc[0]
                patient = rtc[1]
                rtcresource = rtc[2]

                if self.addToQueue(entry, patient) == True:
                    # update the routingslip entry state to "Scheduled"
                    self.markScheduled(entry["id"])
                    # update the returntoclinicstation entry state to "scheduled_dest"
                    self.setRtcState(rtcresource, "scheduled_dest")
                    found = True
                else:
                    self.showError(
                        "Unable to add created return to clinic station item to queue"
                    )

            # process any returntoclinicstation resources that need to be
            # sent back to the requesting clinic station.

            if found == False:
                rtcCheckedOut = self.findCheckedOutDestReturnToClinicStationQueueables(
                    clinic["id"])

                for rtc in rtcCheckedOut:
                    entry = rtc[0]
                    patient = rtc[1]
                    rtcresource = rtc[2]
                    requestingclinicstation = rtc[3]

                    if self.insertFrontOfClinicStationQueue(
                            entry, patient, requestingclinicstation) == True:
                        # update the routingslip entry state to "Scheduled"
                        self.markScheduled(entry["id"])
                        self.setRtcState(rtcresource, "scheduled_return")
                        found = True
                    else:
                        self.showError(
                            "Unable to add checkedout return to clinic station item to queue"
                        )

            if found == False:

                # get all the routing slips for the clinic

                x = GetRoutingSlip(self._host, self._port, self._token)
                x.setClinic(clinic["id"])
                ret = x.send(timeout=30)
                if ret[0] == 200:
                    results = ret[1]

                    # process each of the routing slips

                    for i in results:
                        routing = i["routing"]

                        # search for any routingslip entries that are in
                        # removed state and make sure that routingslip
                        # entries that are in a queue are removed from that
                        # queue

                        for slip in routing:
                            entries = self.findRemovedRoutingSlipEntries(slip)
                            if entries and len(entries) > 0:
                                for rseId in entries:
                                    for k, v in self._queues.iteritems():
                                        dbQueue = self._dbQueues[k]
                                        for item in v:
                                            qent = item["qent"]
                                            ret = self.deleteDbQueueEntry(
                                                dbQueue.id,
                                                qent.getPatientId(), rseId)
                                            if ret == True:
                                                self.showInfo(
                                                    "deleted DbQueueEntry id {} patient {} rseId {} removing item from queue"
                                                    .format(
                                                        dbQueue.id,
                                                        qent.getPatientId(),
                                                        rseId))
                                                try:
                                                    self._queues[k].remove(
                                                        item)
                                                except:
                                                    self.showError(
                                                        "exception: {} failed to remove entry corresponding to DbQueueEntry id {} patient {} rseId {}"
                                                        .format(
                                                            sys.exc_info()[0],
                                                            dbQueue.id,
                                                            qent.getPatientId(
                                                            ), rseId))
                                            else:
                                                self.showError(
                                                    "failed to delete DbQueueEntry id {} patient {} rseId {}"
                                                    .format(
                                                        dbQueue.id,
                                                        qent.getPatientId(),
                                                        rseId))
                                    self.markDeleted(rseId)
                        entry = self.findQueueableEntry(routing)
                        if entry:
                            # append the entry to the corresponding
                            # clinicstation queue
                            if self.addToQueue(entry, i["patient"]) == True:
                                # update the routingslip entry state to "Scheduled"
                                self.markScheduled(entry["id"])
                                break
                            else:
                                self.showError("Unable to add item to queue")

                else:
                    self.showError("GetRoutingSlip failed")

            # process queues

            for k, v in self._queues.iteritems():
                for y in v:
                    ret = y["qent"].update(self)
                    if not ret:
                        v.remove(y)

            self.dumpQueues()
            #self.fillAnEmptyQueue()
            self.updateQueueAvgServiceTime()
            time.sleep(5)
Exemple #8
0
    def run(self):

        while True:
            pickle.dump(self, open( picklepath, "wb" ))
            clinic = self.getClinic()
            if not clinic:
                continue

            self.updateClinicStations()

            # process any newly created returntoclinicstation resources

            found = False

            rtcQueueables = self.findCreatedReturnToClinicStationQueueables(clinic["id"])
    
            for rtc in rtcQueueables:
                # append the entry to the corresponding
                # clinicstation queue
                entry = rtc[0]
                patient = rtc[1]
                rtcresource = rtc[2]

                if self.addToQueue(entry, patient) == True:
                    # update the routingslip entry state to "Scheduled"
                    self.markScheduled(entry["id"])
                    # update the returntoclinicstation entry state to "scheduled_dest"
                    self.setRtcState(rtcresource, "scheduled_dest")
                    found = True
                else:
                    print("Unable to add created return to clinic station item to queue");

            # process any returntoclinicstation resources that need to be
            # sent back to the requesting clinic station. 

            if found == False:
                rtcCheckedOut = self.findCheckedOutDestReturnToClinicStationQueueables(clinic["id"])

                for rtc in rtcCheckedOut:
                    entry = rtc[0]
                    patient = rtc[1]
                    rtcresource = rtc[2]
                    requestingclinicstation = rtc[3]

                    if self.insertFrontOfClinicStationQueue(entry, patient, requestingclinicstation) == True:
                        # update the routingslip entry state to "Scheduled"
                        self.markScheduled(entry["id"])
                        self.setRtcState(rtcresource, "scheduled_return")
                        found = True
                    else:
                        print("Unable to add checkedout return to clinic station item to queue");

            if found == False:

                # get all the routing slips for the clinic

                x = GetRoutingSlip(self._host, self._port, self._token)
                x.setClinic(clinic["id"])
                ret = x.send(timeout=30)
                if ret[0] == 200:
                    results = ret[1]

                    # process each of the routing slips

                    for i in results:
                        routing = i["routing"]
            
                        # search for any routingslip entries that are in 
                        # removed state and make sure that routingslip 
                        # entries that are in a queue are removed from that 
                        # queue

                        for slip in routing:
                            entries = self.findRemovedRoutingSlipEntries(slip)
                            if entries and len(entries) > 0:
                                for rseId in entries:
                                    for k, v in self._queues.iteritems():
                                        dbQueue = self._dbQueues[k]
                                        for item in v:
                                            qent = item["qent"] 
                                            ret = self.deleteDbQueueEntry(dbQueue.id, qent.getPatientId(), rseId)
                                            if ret == True:
                                                print("deleted DbQueueEntry id {} patient {} rseId {} removing item from queue".format(dbQueue.id, qent.getPatientId(), rseId))
                                                try:
                                                    self._queues[k].remove(item)
                                                except:
                                                    print("failed to remove entry corresponding to DbQueueEntry id {} patient {} rseId {}".format(dbQueue.id, qent.getPatientId(), rseId))
                                            else:
                                                print("failed to delete DbQueueEntry id {} patient {} rseId {}".format(dbQueue.id, qent.getPatientId(), rseId))
                                    self.markDeleted(rseId)
                        entry = self.findQueueableEntry(routing)
                        if entry:
                            # append the entry to the corresponding
                            # clinicstation queue
                            if self.addToQueue(entry, i["patient"]) == True:
                                # update the routingslip entry state to "Scheduled"
                                self.markScheduled(entry["id"])
                                break
                            else:
                                print("Unable to add item to queue");

                else:
                    print("GetRoutingSlip failed"); 

            # process queues

            for k, v in self._queues.iteritems():
                for y in v:
                    ret = y["qent"].update()
                    if not ret:
                        v.remove(y)

            self.dumpQueues()
            #self.fillAnEmptyQueue()
            self.updateQueueAvgServiceTime()
            time.sleep(5)
Exemple #9
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