Merge pull request #37 from WDI-Ideas/bobby_dev

refactor(notification):added notification for symptom
This commit is contained in:
BOBBY VISHWAKARMA
2024-05-13 17:02:39 +05:30
committed by GitHub
3 changed files with 57 additions and 4 deletions

Binary file not shown.

View File

@@ -8,9 +8,9 @@ from module_activity.models import MealRecord, Bowel, MealSymptomRecord, Medicat
def notification_for_meal():
notification_message = "You havent filled your meal details yet."
notification_message = "Have you eaten yet? It's been a while since you logged a meal."
current_date = datetime.now()
fifteen_days_ago = current_date - timedelta(days=20)
fifteen_days_ago = current_date - timedelta(days=15)
users = IAmPrincipal.objects.filter(
last_login__gte=fifteen_days_ago,
@@ -60,9 +60,9 @@ def notification_for_meal():
pass
def notification_for_medication():
notification_message = "You havent filled your medication details yet. "
notification_message = "Have you taken your medication today? Remember to log your medication to stay on track with your treatment!"
current_date = datetime.now()
fifteen_days_ago = current_date - timedelta(days=20)
fifteen_days_ago = current_date - timedelta(days=15)
users = IAmPrincipal.objects.filter(
last_login__gte=fifteen_days_ago,
@@ -111,6 +111,58 @@ def notification_for_medication():
print(f"Notification error in medication {str(e)}")
pass
def notification_for_symptom():
notification_message = "How are you feeling? Don't forget to input your symptoms."
current_date = datetime.now()
fifteen_days_ago = current_date - timedelta(days=15)
users = IAmPrincipal.objects.filter(
last_login__gte=fifteen_days_ago,
principal_type=IAmPrincipalType.get_principal_user(),
).values_list("id", flat=True)
symptom_obj = MealSymptomRecord.objects.filter(date=current_date).values_list(
"principal", flat=True
)
# Remove IDs of users who have recorded symptoms for the current day
users_without_medications = set(users) - set(symptom_obj)
print(f"user id {set(users)}")
print(
f"users_without_medication {users_without_medications}"
)
player_ids = list(
IAmPrincipal.objects.filter(
id__in=users_without_medications
).values_list("player_id", flat=True)
)
# removing none from list
player_ids = list(itertools.filterfalse(lambda x: x is None, player_ids))
notifications_to_create = []
if users_without_medications:
for user_id in users_without_medications:
message = notification_message
notifications_to_create.append(
InAppNotification(user_id=user_id, message=message)
)
# Bulk create notifications
if notifications_to_create:
InAppNotification.objects.bulk_create(notifications_to_create)
try:
notification = OneSignalService()
response = notification.send_notification(
headings="Medication",
contents=notification_message,
include_player_ids=player_ids,
)
except Exception as e:
print(f"Notification error in medication {str(e)}")
pass
def testing_cron():
print("cron is working ")

View File

@@ -287,6 +287,7 @@ SIMPLE_JWT = {
CRONJOBS = [
('0 18 * * *', 'module_notification.tasks.notification_for_meal', '>> {}'.format(str(BASE_DIR / 'logs/cron.log'))),
('0 20 * * *', 'module_notification.tasks.notification_for_medication', '>> {}'.format(str(BASE_DIR / 'logs/cron.log'))),
('0 22 * * *', 'module_notification.tasks.notification_for_symptom', '>> {}'.format(str(BASE_DIR / 'logs/cron.log'))),
# ('* * * * *', 'module_notification.tasks.testing_cron', '>> {}'.format(str(BASE_DIR / 'logs/cron.log'))),
]