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
rakesh.pv
mqtt_redis
Commits
69ccaa75
Commit
69ccaa75
authored
Feb 03, 2023
by
rakesh.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
almost done
parent
e0e841e8
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
19 deletions
+57
-19
scripts/config/mqtt_connection.py
+1
-1
scripts/core/handlers/assign_doctor_to_patient.py
+31
-0
scripts/core/handlers/check_patient_visited.py
+10
-6
scripts/core/handlers/create_new_patient_data.py
+4
-1
scripts/core/handlers/store_patient_details_in_redis.py
+7
-9
scripts/core/services/app.py
+4
-2
No files found.
scripts/config/mqtt_connection.py
View file @
69ccaa75
MQTT_HOST
=
'192.168.0.220'
MQTT_HOST
=
'192.168.0.220'
MQTT_PORT
=
1883
MQTT_PORT
=
1883
TOPIC
=
'doctor
/#
'
TOPIC
=
'doctor'
scripts/core/handlers/assign_doctor_to_patient.py
0 → 100644
View file @
69ccaa75
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
,
"
\"
"
)
scripts/core/handlers/check_patient_visited.py
View file @
69ccaa75
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
,
"
\"
"
)
scripts/core/handlers/create_new_patient_data.py
View file @
69ccaa75
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
,
"
\n
patient description
\n\n
"
,
print
(
" data that will be published to broker is :
\n\n
"
,
"patiend id :
\n
"
,
patient_id
,
"
\n
patient 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
))
scripts/core/handlers/store_patient_details_in_redis.py
View file @
69ccaa75
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
)
scripts/core/services/app.py
View file @
69ccaa75
...
@@ -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
()
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