Commit a5ad958b by rakesh.pv

completed redis

parent b2e45239
MQTT_HOST = '192.168.0.220'
MQTT_PORT = 1883
TOPIC = 'doctor'
MQTT_TOPIC = 'doctor'
from paho import mqtt
import paho.mqtt.client as mqtt
from scripts.config.mqtt_connection import MQTT_HOST, MQTT_PORT
......@@ -7,12 +6,13 @@ 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 ]"))
no_of_doctor = int(input(" enter the number of doctor [ mqtt topic ]"))
c = 0
def assign_doctor(patient_id):
def assign_doctor_to_patient(patient_id):
try:
c = 0
global c
c = (c + 1)
doctor_topic = "doctor" + str(c)
......@@ -22,11 +22,3 @@ def assign_doctor(patient_id):
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, "\"")
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
def insert_new_data():
# from scripts.core.handlers.assign_doctor_to_patient import send_patient_details
def insert_new_data():
patient_name = input("enter patient name")
patient_id = int(input("enter patient id"))
patient_description = input("enter patient description")
patiend_age = int(input("enter patient age"))
entire_data = {
"patient_description": patient_description,
"patient_name": patient_name,
"patient_id": patient_id,
"age ": patiend_age,
}
data_to_be_sent = {
"patient_description": patient_description,
......@@ -24,4 +31,5 @@ def insert_new_data():
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))
send_patient_details(json.dumps(data_to_be_sent))
Mqtt_msg = json.dumps(entire_data)
return Mqtt_msg
from scripts.config.redis_connection import r
from scripts.core.handlers.assign_doctor_to_patient import assign_doctor, send_patient_details
from scripts.core.handlers.assign_doctor_to_patient import assign_doctor_to_patient
def check_patient_id(patient_id):
......@@ -15,7 +14,7 @@ def check_patient_id(patient_id):
else:
print()
assign_doctor(patient_id)
assign_doctor_to_patient(patient_id)
except Exception as e:
......@@ -26,5 +25,3 @@ def insert_data_redis(patient_id, x):
# -> scripts.core.handlers.check_patient_visited
check_patient_id(patient_id)
import paho.mqtt.client as mqtt
from fastapi import FastAPI
from scripts.config.mqtt_connection import MQTT_HOST, MQTT_PORT, MQTT_TOPIC
from scripts.core.handlers.create_new_patient_data import insert_new_data
app = FastAPI()
......@@ -13,5 +15,24 @@ def index():
# ->scripts.core.handlers.create_new_patient_data
@app.get("/consulation/")
def consult_doctor():
x = insert_new_data()
insert_new_data()
def on_publish(client, userdata, mid):
print("Message Published...")
def on_connect(client, userdata, flags, rc):
client.subscribe(MQTT_TOPIC)
client.publish(MQTT_TOPIC, x)
def on_message(client, userdata, msg):
print(msg.topic)
print(msg.payload)
client.disconnect()
mqttc = mqtt.Client()
mqttc.on_publish = on_publish
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.connect(MQTT_HOST, MQTT_PORT)
mqttc.loop_forever()
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