Commit 8f014f81 by arjun.b

topic updated

parent 3650e464
import configparser import configparser
from scripts.logging.logging import logger
try: try:
config = configparser.ConfigParser() config = configparser.ConfigParser()
...@@ -14,4 +13,4 @@ try: ...@@ -14,4 +13,4 @@ try:
redis_port = config.get("redis_connect", "port") redis_port = config.get("redis_connect", "port")
file_name = config.get("logging", "file_name") file_name = config.get("logging", "file_name")
except configparser.NoOptionError: except configparser.NoOptionError:
logger.error("could not find conf file") print("could not ")
...@@ -3,11 +3,12 @@ import logging ...@@ -3,11 +3,12 @@ import logging
import redis import redis
from scripts.config.application_config import redis_host, redis_port from scripts.config.application_config import redis_host, redis_port
from scripts.logging.logging import logger
try: try:
# Connect to Redis # Connect to Redis
r = redis.Redis(host=redis_host, port=int(redis_port), db=1) r = redis.Redis(host=redis_host, port=int(redis_port), db=1)
except Exception as e: except Exception as e:
logging.error(f'cant connect to redis {e}') logger.error(f'cant connect to redis {e}')
print(str(e)) print(str(e))
...@@ -7,7 +7,7 @@ from scripts.logging.logging import logger ...@@ -7,7 +7,7 @@ from scripts.logging.logging import logger
broker = hostname broker = hostname
port = int(port_num) port = int(port_num)
topic = topic_name # topic = topic_name
client = mqtt_client.Client() client = mqtt_client.Client()
client.connect(broker, port, 60) client.connect(broker, port, 60)
...@@ -30,6 +30,7 @@ def assign_patient(patient, doctors): ...@@ -30,6 +30,7 @@ def assign_patient(patient, doctors):
# Assign the patient to the next doctor # Assign the patient to the next doctor
patient.update({"doctor": next_doctor}) patient.update({"doctor": next_doctor})
r.hset(patient['patient_id'], 'doctor', next_doctor) r.hset(patient['patient_id'], 'doctor', next_doctor)
topic=f"hospital/{next_doctor}"
client.publish(topic, json.dumps(patient)) client.publish(topic, json.dumps(patient))
except Exception as e: except Exception as e:
logger.error(f"could not assign patient: {e}") logger.error(f"could not assign patient: {e}")
import logging import logging
from scripts.config.redis_connection import r from scripts.config.redis_connection import r
from scripts.logging.logging import logger
def get_next_doctor(doctors): def get_next_doctor(doctors):
...@@ -13,4 +14,4 @@ def get_next_doctor(doctors): ...@@ -13,4 +14,4 @@ def get_next_doctor(doctors):
# Return the next doctor # Return the next doctor
return doctors[current_doctor] return doctors[current_doctor]
except Exception as e: except Exception as e:
logging.error(f'cant find next doctor:{e}') logger.error(f'cant find next doctor:{e}')
import logging
from fastapi import FastAPI from fastapi import FastAPI
from scripts.core.handlers.publisher_handler import PublishHandler from scripts.core.handlers.publisher_handler import PublishHandler
from scripts.logging.logging import logger
from scripts.model.patients import patients from scripts.model.patients import patients
from scripts.constants.end_points import EndPoints from scripts.constants.end_points import EndPoints
app = FastAPI() app = FastAPI()
...@@ -16,5 +16,5 @@ def publish_data(details: patients): ...@@ -16,5 +16,5 @@ def publish_data(details: patients):
try: try:
PublishHandler.main_handler(details) PublishHandler.main_handler(details)
except Exception as e: except Exception as e:
logging.error(f'assign a doctor and publishing the details failed: {e}') logger.error(f'assign a doctor and publishing the details failed: {e}')
return {"data": "data published"} return {"data": "data published"}
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