Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
redis_producer
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
mohammed.shibili
redis_producer
Commits
21ca313a
Commit
21ca313a
authored
Feb 03, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
corrections done
parent
b2ebebca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
57 deletions
+65
-57
script/config/end_points.py
+3
-3
script/core/handlers/mqtt_coo.py
+1
-2
script/core/handlers/patient_info.py
+52
-0
script/service/main.py
+9
-52
No files found.
script/config/end_points.py
View file @
21ca313a
import
configparser
import
configparser
config
=
configparser
.
RawConfigParser
()
config
=
configparser
.
RawConfigParser
()
config
.
read
(
"conf/app.conf"
)
config
.
read
(
"conf/app.conf"
)
get_end
=
config
.
get
(
"end_point"
,
"get"
)
get_end
=
config
.
get
(
"end_points"
,
"get"
)
post_end
=
config
.
get
(
"end_point"
,
"post"
)
post_end
=
config
.
get
(
"end_points"
,
"post"
)
\ No newline at end of file
\ No newline at end of file
script/core/handlers/mqtt_coo.py
View file @
21ca313a
...
@@ -10,4 +10,4 @@ def mqtt_conn():
...
@@ -10,4 +10,4 @@ def mqtt_conn():
print
(
"mqtt connected"
)
print
(
"mqtt connected"
)
return
mqtt_
return
mqtt_
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"mqtt fail"
,
e
)
print
(
"mqtt fail"
,
e
)
\ No newline at end of file
script/core/handlers/patient_info.py
0 → 100644
View file @
21ca313a
import
json
from
script.core.handlers.mqtt_coo
import
mqtt_conn
from
script.core.handlers.redis_connection
import
redis_connection
class
Consultancy
:
doctors_list
=
[]
topic
=
''
mqtt_
=
mqtt_conn
()
connection_redis
=
redis_connection
()
connection_redis
.
set
(
"current_doctor"
,
0
)
@staticmethod
def
doctor_details
(
no_of_doctors
):
Consultancy
()
.
doctors_list
=
[]
if
Consultancy
()
.
connection_redis
.
exists
(
"available_doctors"
):
Consultancy
()
.
connection_redis
.
delete
(
"available_doctors"
)
for
doctors
in
range
(
1
,
no_of_doctors
+
1
):
Consultancy
()
.
doctors_list
.
append
(
f
'KL/doctor{doctors}'
)
# publishing doctors list to redis
Consultancy
()
.
connection_redis
.
rpush
(
"available_doctors"
,
*
Consultancy
()
.
doctors_list
)
return
Consultancy
()
.
doctors_list
@staticmethod
def
patient_details
(
patient_info
):
# collecting keys from redis db
current_doctor
=
int
(
Consultancy
()
.
connection_redis
.
get
(
"current_doctor"
))
keys
=
Consultancy
()
.
connection_redis
.
keys
()
# decoding keys in redis
decoded_keys
=
[
values
.
decode
()
for
values
in
keys
]
topic
=
''
# print(Consultancy().doctors_list)
# print(Consultancy.self.current_doctor)
# checking whether patient is consulted before
for
patient_id
in
decoded_keys
:
# if patient is consulted before assign him to previous doctor
if
patient_id
==
patient_info
[
'patient_id'
]:
topic
=
Consultancy
()
.
connection_redis
.
get
(
patient_id
)
.
decode
()
# else assign new doctor who is free
if
not
topic
:
topic
=
Consultancy
()
.
doctors_list
[
current_doctor
]
# Increment the index for the next doctor
print
(
len
(
Consultancy
()
.
doctors_list
))
Consultancy
()
.
connection_redis
.
set
(
"current_doctor"
,
(
current_doctor
+
1
)
%
len
(
Consultancy
()
.
doctors_list
))
# Publish the patient information to the MQTT topic
Consultancy
()
.
mqtt_
.
publish
(
topic
,
json
.
dumps
(
patient_info
))
# Store the patient information in Redis cache
Consultancy
()
.
connection_redis
.
set
(
patient_info
[
'patient_id'
],
topic
)
return
patient_info
script/service/main.py
View file @
21ca313a
import
json
from
fastapi
import
FastAPI
from
fastapi
import
FastAPI
from
script.config.end_points
import
get_end
,
post_end
from
script.config.end_points
import
get_end
,
post_end
from
script.core.handlers.mqtt_coo
import
mqtt_conn
from
script.core.handlers.patient_info
import
Consultancy
from
script.core.handlers.redis_connection
import
redis_connection
from
script.database.models
import
patient_details
from
script.database.models
import
patient_details
app
=
FastAPI
()
app
=
FastAPI
()
# defining variables needed
doctors_list
=
[]
current_doctor
=
0
topic
=
''
patient_info
=
{}
# api call for generating doctors list
# api call for generating doctors list
@app.get
(
get_end
,
tags
=
[
'REDIS'
])
@app.get
(
get_end
,
tags
=
[
'REDIS'
])
async
def
doctor
(
no_of_doctors
:
int
):
async
def
doctor
(
no_of_doctors
:
int
):
for
doctors
in
range
(
1
,
no_of_doctors
+
1
):
print
(
Consultancy
()
.
doctor_details
(
no_of_doctors
))
doctors_list
.
append
(
f
'/doctor{doctors}'
)
return
"doctors_list generated"
# publishing doctors list to redis
connection_redis
.
lpush
(
"available_doctors"
,
f
'doctor{doctors}'
)
# api call for accepting patient details
@app.post
(
post_end
,
tags
=
[
"REDIS"
])
@app.post
(
post_end
,
tags
=
[
"REDIS"
])
async
def
patients
(
body
:
patient_details
):
async
def
patients
(
body
:
patient_details
):
global
topic
global
current_doctor
global
doctors_list
# accepting patient details using pydantic BaseModel
# accepting patient details using pydantic BaseModel
patient_data
=
patient_details
(
patient_id
=
body
.
patient_id
,
name
=
body
.
name
,
age
=
body
.
age
,
patient_info
=
dict
(
patient_details
(
patient_id
=
body
.
patient_id
,
name
=
body
.
name
,
age
=
body
.
age
,
description
=
body
.
description
)
description
=
body
.
description
))
patient_info
.
update
(
dict
(
patient_data
))
# patient_info.update(dict(patient_data))
# collecting keys from redis db
print
(
Consultancy
()
.
patient_details
(
patient_info
))
keys
=
connection_redis
.
keys
()
return
"patient is send for consulting"
# decoding keys in redis
decoded_keys
=
[
values
.
decode
()
for
values
in
keys
]
# checking whether patient is consulted before
for
patient_id
in
decoded_keys
:
# if patient is consulted before assign him to previous doctor
if
patient_id
==
patient_info
[
'patient_id'
]:
topic
=
connection_redis
.
get
(
patient_id
)
.
decode
()
# else assign new doctor who is free
if
not
topic
:
topic
=
doctors_list
[
current_doctor
]
print
(
topic
)
# Increment the index for the next doctor
current_doctor
=
(
current_doctor
+
1
)
%
len
(
doctors_list
)
# Publish the patient information to the MQTT topic
mqtt_
.
publish
(
topic
,
json
.
dumps
(
patient_info
))
# Store the patient information in Redis cache
def
on_message
(
client
,
userdata
,
msg
):
connection_redis
.
set
(
patient_info
[
'patient_id'
],
topic
)
mqtt_
=
mqtt_conn
()
connection_redis
=
redis_connection
()
# Subscribe to all the MQTT topics for the doctors
for
topic
in
doctors_list
:
mqtt_
.
subscribe
(
topic
)
# Start the MQTT loop to receive messages
mqtt_
.
on_message
=
on_message
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