Commit 69ccaa75 by rakesh.pv

almost done

parent e0e841e8
MQTT_HOST = '192.168.0.220' MQTT_HOST = '192.168.0.220'
MQTT_PORT = 1883 MQTT_PORT = 1883
TOPIC = 'doctor/#' TOPIC = 'doctor'
from paho import mqtt
import paho.mqtt.client as mqtt
from scripts.config.mqtt_connection import MQTT_HOST, MQTT_PORT
from scripts.config.redis_connection import r
mqtt_client = mqtt.Client()
mqtt_client.connect(MQTT_HOST, MQTT_PORT)
#
no_of_doctor = int(input(" enter the number of docotr [ mqtt topic ]"))
def assign_doctor(patient_id):
try:
c = 0
c = (c + 1)
doctor_topic = "doctor" + str(c)
r.set(patient_id, doctor_topic)
print(patient_id, " assigned to ", doctor_topic)
except Exception as e:
print("Exception occurred due to \"", e, "\"")
def send_patient_details(patient_details):
try:
# Publish the patient information to the doctor's topic
mqtt_client.publish( patient_details)
except Exception as e:
print("Exception occurred due to \"", e, "\"")
from scripts.config.redis_connection import r from scripts.config.redis_connection import r
from scripts.core.handlers.assign_doctor_to_patient import assign_doctor
def check_patient_id(patient_id): def check_patient_id(patient_id):
try: try:
# Check if the patient has visited before
all_patient_id = r.keys()
if r.exists(patient_id): if r.exists(patient_id):
doctor_topic = r.get(patient_id) doctor_topic = r.get(patient_id)
print("patient id already presnt in redis databse") print(patient_id, " consulted ", doctor_topic.decode(), " before.")
print("patient id already present in redis database")
else: else:
# If the patient is new, assign a doctor using round-robin print()
print("done succesfull")
assign_doctor(patient_id)
except Exception as e: except Exception as e:
print("Exception occurred due to \"", e, "\"") print("Exception occurred due to \"", e, "\"")
import json import json
from scripts.core.handlers.assign_doctor_to_patient import send_patient_details
from scripts.core.handlers.store_patient_details_in_redis import insert_data_redis from scripts.core.handlers.store_patient_details_in_redis import insert_data_redis
...@@ -18,5 +20,6 @@ def insert_new_data(): ...@@ -18,5 +20,6 @@ def insert_new_data():
print(" data that will be published to broker is :\n\n", "patiend id :\n", patient_id, "\npatient description \n\n", print(" data that will be published to broker is :\n\n", "patiend id :\n", patient_id, "\npatient description \n\n",
json.dumps(data_to_be_sent)) json.dumps(data_to_be_sent))
# -> scripts.core.handlers.store_patient_details_in_redis
insert_data_redis(patient_id, json.dumps(data_to_be_sent)) insert_data_redis(patient_id, json.dumps(data_to_be_sent))
send_patient_details(json.dumps(data_to_be_sent))
from scripts.config.redis_connection import r from scripts.config.redis_connection import r
from scripts.core.handlers.check_patient_visited import check_patient_id from scripts.core.handlers.check_patient_visited import check_patient_id
from scripts.core.handlers.assign_doctor_to_patient import assign_doctor, send_patient_details
def insert_data_redis(patient_id,x):
r.set(patient_id,x)
check_patient_id(patient_id)
def insert_data_redis(patient_id, x):
# -> scripts.core.handlers.check_patient_visited
send_patient_details(x)
check_patient_id(patient_id)
r.set(patient_id, x)
assign_doctor(patient_id)
...@@ -10,6 +10,8 @@ def index(): ...@@ -10,6 +10,8 @@ def index():
return {"message :", " FAST API IS CONNECTED"} return {"message :", " FAST API IS CONNECTED"}
insert_new_data() # ->scripts.core.handlers.create_new_patient_data
@app.get("/consulation/")
def consult_doctor():
insert_new_data()
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