Commit bb069f5f by arun.uday

v3

parent 0fde07ab
# assigning the doctors to new patients
import time
def assign_new_doctor(conn_queue, conn_patient, client, dict_data, next_doc):
avi_doc = conn_queue.get(f'doctor{next_doc}')
# check if the doctor queue is empty
if avi_doc != b'':
print("Wait for the doctor to be free...")
time.sleep(3)
conn_queue.set(f'doctor{next_doc}', '')
# updating the patient details with doctor id
dict_data.update({"doctor": f'doctor{next_doc}'})
# update the db with new data
conn_patient.hmset(dict_data['patient_id'], dict_data)
# set the patient to the doctors queue
conn_queue.set(f'doctor{next_doc}', dict_data['patient_id'])
patient_id = dict_data['patient_id']
# publish the doctor
client.publish(f'doctor{next_doc}', dict_data['patient_id'])
client.publish(f'doctor{next_doc}', patient_id)
# assigning existing patients to the doctors
import time
def assign_doc_exist(conn_queue, conn_patient, client, dict_data):
# getting the doctor id from the patient db
doctor = conn_patient.hmget(dict_data['patient_id'], 'doctor')
# updating the doctors queue
conn_queue.set(doctor[0].decode(), dict_data['patient_id'])
avi_doc = conn_queue.get(doctor[0].decode())
# check if the doctor queue is empty
if avi_doc != b'':
print("Wait for the doctor to be free...")
time.sleep(3)
conn_queue.set(doctor[0].decode(), '')
patient_id = dict_data['patient_id']
# publishing the doctor
client.publish(doctor[0].decode(), dict_data['patient_id'])
client.publish(doctor[0].decode(), patient_id)
......@@ -6,12 +6,10 @@ def set_patient_queue(conn_queue, conn_patient, client, dict_data, next_doc, doc
# check if the next doctor is not the last index
if int(next_doc) != doctors_counter:
avi_doc = conn_queue.get(f'doctor{next_doc}')
# assign the doctor
assign_new_doctor(conn_queue, conn_patient, client, dict_data, next_doc)
conn_queue.set('next_doc', next_doc + 1)
# check if the doctor queue is empty
if avi_doc == b'':
assign_new_doctor(conn_queue, conn_patient, client, dict_data, next_doc)
conn_queue.set('next_doc', next_doc + 1)
else:
conn_queue.set('next_doc', 0)
......
......@@ -74,11 +74,6 @@ def patient_data(body: Patient):
# creating the paho client to listen to the port
client.connect(mqtt_host, int(port))
def on_connect(client_id, userdata, flags, rc):
print("Connected with result code " + str(rc), client_id, userdata, flags)
client.on_connect = on_connect
# generating the patients
dict_data = generate_patients(patient_data_val)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment