Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
MQTT-Redis
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arjun.b
MQTT-Redis
Commits
3650e464
Commit
3650e464
authored
Feb 06, 2023
by
arjun.b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging file added
parent
9607ff16
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
23 deletions
+33
-23
scripts/config/application_config.py
+3
-1
scripts/core/handlers/assign_patient.py
+18
-14
scripts/core/handlers/publisher_handler.py
+12
-8
No files found.
scripts/config/application_config.py
View file @
3650e464
import
configparser
from
scripts.logging.logging
import
logger
try
:
config
=
configparser
.
ConfigParser
()
config
.
read
(
r'E:\MQTT-redis\conf\application.conf'
)
...
...
@@ -12,4 +14,4 @@ try:
redis_port
=
config
.
get
(
"redis_connect"
,
"port"
)
file_name
=
config
.
get
(
"logging"
,
"file_name"
)
except
configparser
.
NoOptionError
:
print
(
"could not find conf file"
)
logger
.
error
(
"could not find conf file"
)
scripts/core/handlers/assign_patient.py
View file @
3650e464
...
...
@@ -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.redis_connection
import
r
from
scripts.core.handlers.get_next_doctor
import
get_next_doctor
from
scripts.logging.logging
import
logger
broker
=
hostname
port
=
int
(
port_num
)
...
...
@@ -12,20 +13,23 @@ client.connect(broker, port, 60)
def
assign_patient
(
patient
,
doctors
):
# Get the next doctor for the patient
next_doctor
=
get_next_doctor
(
doctors
)
try
:
# Get the next doctor for the patient
next_doctor
=
get_next_doctor
(
doctors
)
# Check if the patient has an assigned doctor
if
r
.
hexists
(
patient
[
'patient_id'
],
'doctor'
):
# Get the assigned doctor for the patient
assigned_doctor
=
r
.
hget
(
patient
[
'patient_id'
],
'doctor'
)
.
decode
(
'utf-8'
)
# Check if the patient has an assigned doctor
if
r
.
hexists
(
patient
[
'patient_id'
],
'doctor'
):
# Get the assigned doctor for the patient
assigned_doctor
=
r
.
hget
(
patient
[
'patient_id'
],
'doctor'
)
.
decode
(
'utf-8'
)
# Check if the assigned doctor is still on duty
if
assigned_doctor
in
doctors
:
# Assign the patient to the same doctor
next_doctor
=
assigned_doctor
# Check if the assigned doctor is still on duty
if
assigned_doctor
in
doctors
:
# Assign the patient to the same doctor
next_doctor
=
assigned_doctor
# Assign the patient to the next doctor
patient
.
update
({
"doctor"
:
next_doctor
})
r
.
hset
(
patient
[
'patient_id'
],
'doctor'
,
next_doctor
)
client
.
publish
(
topic
,
json
.
dumps
(
patient
))
# Assign the patient to the next doctor
patient
.
update
({
"doctor"
:
next_doctor
})
r
.
hset
(
patient
[
'patient_id'
],
'doctor'
,
next_doctor
)
client
.
publish
(
topic
,
json
.
dumps
(
patient
))
except
Exception
as
e
:
logger
.
error
(
f
"could not assign patient: {e}"
)
scripts/core/handlers/publisher_handler.py
View file @
3650e464
from
scripts.core.handlers.assign_patient
import
assign_patient
from
scripts.logging.logging
import
logger
class
PublishHandler
:
@staticmethod
def
main_handler
(
details
):
doctors
=
[
'Dr. Smith'
,
'Dr. Johnson'
,
'Dr. Brown'
,
"Dr. Arjun B"
]
patient_details
=
{
"patient_id"
:
details
.
id
,
"description"
:
details
.
description
,
"age"
:
details
.
age
,
"name"
:
details
.
name
}
assign_patient
(
patient_details
,
doctors
)
try
:
doctors
=
[
'Dr. Smith'
,
'Dr. Johnson'
,
'Dr. Brown'
,
"Dr. Arjun B"
]
patient_details
=
{
"patient_id"
:
details
.
id
,
"description"
:
details
.
description
,
"age"
:
details
.
age
,
"name"
:
details
.
name
}
assign_patient
(
patient_details
,
doctors
)
except
Exception
as
e
:
logger
.
error
(
f
"cant get patients details :{e}"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment