Commit 3650e464 by arjun.b

logging file added

parent 9607ff16
import configparser import configparser
from scripts.logging.logging import logger
try: try:
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(r'E:\MQTT-redis\conf\application.conf') config.read(r'E:\MQTT-redis\conf\application.conf')
...@@ -12,4 +14,4 @@ try: ...@@ -12,4 +14,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:
print("could not find conf file") logger.error("could not find conf file")
...@@ -3,6 +3,7 @@ from paho.mqtt import client as mqtt_client ...@@ -3,6 +3,7 @@ from paho.mqtt import client as mqtt_client
from scripts.config.application_config import hostname, port_num, topic_name from scripts.config.application_config import hostname, port_num, topic_name
from scripts.config.redis_connection import r from scripts.config.redis_connection import r
from scripts.core.handlers.get_next_doctor import get_next_doctor from scripts.core.handlers.get_next_doctor import get_next_doctor
from scripts.logging.logging import logger
broker = hostname broker = hostname
port = int(port_num) port = int(port_num)
...@@ -12,20 +13,23 @@ client.connect(broker, port, 60) ...@@ -12,20 +13,23 @@ client.connect(broker, port, 60)
def assign_patient(patient, doctors): def assign_patient(patient, doctors):
# Get the next doctor for the patient try:
next_doctor = get_next_doctor(doctors) # Get the next doctor for the patient
next_doctor = get_next_doctor(doctors)
# Check if the patient has an assigned doctor # Check if the patient has an assigned doctor
if r.hexists(patient['patient_id'], 'doctor'): if r.hexists(patient['patient_id'], 'doctor'):
# Get the assigned doctor for the patient # Get the assigned doctor for the patient
assigned_doctor = r.hget(patient['patient_id'], 'doctor').decode('utf-8') assigned_doctor = r.hget(patient['patient_id'], 'doctor').decode('utf-8')
# Check if the assigned doctor is still on duty # Check if the assigned doctor is still on duty
if assigned_doctor in doctors: if assigned_doctor in doctors:
# Assign the patient to the same doctor # Assign the patient to the same doctor
next_doctor = assigned_doctor next_doctor = assigned_doctor
# 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)
client.publish(topic, json.dumps(patient)) client.publish(topic, json.dumps(patient))
except Exception as e:
logger.error(f"could not assign patient: {e}")
from scripts.core.handlers.assign_patient import assign_patient from scripts.core.handlers.assign_patient import assign_patient
from scripts.logging.logging import logger
class PublishHandler: class PublishHandler:
@staticmethod @staticmethod
def main_handler(details): def main_handler(details):
doctors = ['Dr. Smith', 'Dr. Johnson', 'Dr. Brown', "Dr. Arjun B"] try:
patient_details = { doctors = ['Dr. Smith', 'Dr. Johnson', 'Dr. Brown', "Dr. Arjun B"]
"patient_id": details.id, patient_details = {
"description": details.description, "patient_id": details.id,
"age": details.age, "description": details.description,
"name": details.name "age": details.age,
} "name": details.name
assign_patient(patient_details, doctors) }
assign_patient(patient_details, doctors)
except Exception as e:
logger.error(f"cant get patients details :{e}")
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