diff --git a/apps/accounts/serializers.py b/apps/accounts/serializers.py index ad7f50c..d35a939 100644 --- a/apps/accounts/serializers.py +++ b/apps/accounts/serializers.py @@ -117,6 +117,8 @@ class ProvisionalUserSerializer(serializers.ModelSerializer): roles = serializers.ListField( child=serializers.CharField(), write_only=True, + required=False, + default=list, help_text="List of role names to assign" ) diff --git a/apps/accounts/services.py b/apps/accounts/services.py index 2f24816..ad2e80b 100644 --- a/apps/accounts/services.py +++ b/apps/accounts/services.py @@ -9,6 +9,8 @@ from django.core.mail import send_mail from django.template.loader import render_to_string from django.utils import timezone +from django.db import models as db_models + from .models import ( AcknowledgementChecklistItem, AcknowledgementContent, @@ -111,14 +113,26 @@ class OnboardingService: Returns: QuerySet of AcknowledgementContent """ - # Get user's role + # Get user's role - convert group name to role code role = None if user.groups.exists(): - role = user.groups.first().name + group_name = user.groups.first().name + # Map group names to role codes + role_mapping = { + 'PX Admin': 'px_admin', + 'Hospital Admin': 'hospital_admin', + 'Department Manager': 'department_manager', + 'PX Coordinator': 'px_coordinator', + 'Physician': 'physician', + 'Nurse': 'nurse', + 'Staff': 'staff', + 'Viewer': 'viewer', + } + role = role_mapping.get(group_name, group_name.lower().replace(' ', '_')) # Get content for user's role or all roles content = AcknowledgementContent.objects.filter(is_active=True).filter( - models.Q(role=role) | models.Q(role__isnull=True) + db_models.Q(role=role) | db_models.Q(role__isnull=True) ).order_by('order') return content @@ -134,16 +148,26 @@ class OnboardingService: Returns: QuerySet of AcknowledgementChecklistItem """ - from django.db import models - - # Get user's role + # Get user's role - convert group name to role code role = None if user.groups.exists(): - role = user.groups.first().name + group_name = user.groups.first().name + # Map group names to role codes + role_mapping = { + 'PX Admin': 'px_admin', + 'Hospital Admin': 'hospital_admin', + 'Department Manager': 'department_manager', + 'PX Coordinator': 'px_coordinator', + 'Physician': 'physician', + 'Nurse': 'nurse', + 'Staff': 'staff', + 'Viewer': 'viewer', + } + role = role_mapping.get(group_name, group_name.lower().replace(' ', '_')) # Get items for user's role or all roles items = AcknowledgementChecklistItem.objects.filter(is_active=True).filter( - models.Q(role=role) | models.Q(role__isnull=True) + db_models.Q(role=role) | db_models.Q(role__isnull=True) ).order_by('order') return items @@ -452,7 +476,7 @@ class EmailService: Boolean indicating success """ base_url = getattr(settings, 'BASE_URL', 'http://localhost:8000') - user_detail_url = f"{base_url}/accounts/management/progress/{user.id}/" + user_detail_url = f"{base_url}/accounts/onboarding/provisional/{user.id}/progress/" # Render email content context = { diff --git a/templates/accounts/onboarding/complete.html b/templates/accounts/onboarding/complete.html index e9b03a7..aae18ac 100644 --- a/templates/accounts/onboarding/complete.html +++ b/templates/accounts/onboarding/complete.html @@ -75,9 +75,9 @@
- + - {% trans "Log In to PX360" %} + {% trans "Go to Dashboard" %}
diff --git a/templates/accounts/onboarding/completion_email.html b/templates/accounts/onboarding/completion_email.html new file mode 100644 index 0000000..b5fab2a --- /dev/null +++ b/templates/accounts/onboarding/completion_email.html @@ -0,0 +1,163 @@ + + + + + + User Onboarding Completed + + + +
+
+ +

Patient Experience Platform

+
+ +
+ +

User Onboarding Completed

+ +
+

A new user has successfully completed the onboarding process and is now active in the PX360 system.

+ + + + +
+ +

+ This notification was sent on {{ "now"|date:"F j, Y, g:i a" }} +

+ + +
+ + diff --git a/templates/accounts/onboarding/completion_email.txt b/templates/accounts/onboarding/completion_email.txt new file mode 100644 index 0000000..eac4dbf --- /dev/null +++ b/templates/accounts/onboarding/completion_email.txt @@ -0,0 +1,22 @@ +User Onboarding Completed +========================== + +A new user has successfully completed the onboarding process and is now active in the PX360 system. + +USER DETAILS +------------ +Name: {{ user.get_full_name|default:"Not provided" }} +Email: {{ user.email }} +Username: {{ user.username }} +Employee ID: {{ user.employee_id|default:"Not provided" }} +Hospital: {{ user.hospital.name|default:"Not assigned" }} +Department: {{ user.department.name|default:"Not assigned" }} +Completed At: {{ user.acknowledgement_completed_at|date:"F j, Y, g:i a" }} + +View user details: {{ user_detail_url }} + +--- + +This is an automated notification from PX360. + +© PX360 - Patient Experience Platform diff --git a/templates/accounts/onboarding/completion_subject.txt b/templates/accounts/onboarding/completion_subject.txt new file mode 100644 index 0000000..0c0a405 --- /dev/null +++ b/templates/accounts/onboarding/completion_subject.txt @@ -0,0 +1 @@ +PX360: {{ user.get_full_name|default:user.email }} has completed onboarding diff --git a/templates/accounts/onboarding/invitation_email.html b/templates/accounts/onboarding/invitation_email.html new file mode 100644 index 0000000..aa6b084 --- /dev/null +++ b/templates/accounts/onboarding/invitation_email.html @@ -0,0 +1,138 @@ + + + + + + Welcome to PX360 + + + +
+
+ +

Patient Experience Platform

+
+ +

Welcome to PX360!

+ +

Hello {{ user.first_name|default:user.email }},

+ +
+

You have been invited to join PX360, our comprehensive Patient Experience management platform. To complete your account setup, please click the button below:

+ + + +

During the onboarding process, you will:

+ +
+ +
+ ⏰ Important: This invitation link will expire on {{ expires_at|date:"F j, Y, g:i a" }}. Please complete your registration before this date. +
+ + + + +
+ + diff --git a/templates/accounts/onboarding/invitation_email.txt b/templates/accounts/onboarding/invitation_email.txt new file mode 100644 index 0000000..1c12f6b --- /dev/null +++ b/templates/accounts/onboarding/invitation_email.txt @@ -0,0 +1,26 @@ +Welcome to PX360! +================== + +Hello {{ user.first_name|default:user.email }}, + +You have been invited to join PX360, our comprehensive Patient Experience management platform. + +To complete your account setup, please visit the following link: + +{{ activation_url }} + +During the onboarding process, you will: +- Learn about PX360 features and your role responsibilities +- Review and acknowledge important policies and guidelines +- Set up your username and password +- Complete your profile information + +IMPORTANT: This invitation link will expire on {{ expires_at|date:"F j, Y, g:i a" }}. +Please complete your registration before this date. + +--- + +This is an automated message from PX360. Please do not reply to this email. +If you did not expect this invitation or have questions, please contact your system administrator. + +© PX360 - Patient Experience Platform diff --git a/templates/accounts/onboarding/invitation_subject.txt b/templates/accounts/onboarding/invitation_subject.txt new file mode 100644 index 0000000..cb66489 --- /dev/null +++ b/templates/accounts/onboarding/invitation_subject.txt @@ -0,0 +1 @@ +Welcome to PX360 - Complete Your Account Setup diff --git a/templates/accounts/onboarding/provisional_list.html b/templates/accounts/onboarding/provisional_list.html index 83e72ba..656b3d8 100644 --- a/templates/accounts/onboarding/provisional_list.html +++ b/templates/accounts/onboarding/provisional_list.html @@ -155,7 +155,7 @@ diff --git a/templates/accounts/onboarding/reminder_email.html b/templates/accounts/onboarding/reminder_email.html new file mode 100644 index 0000000..14f7b2b --- /dev/null +++ b/templates/accounts/onboarding/reminder_email.html @@ -0,0 +1,134 @@ + + + + + + Reminder: Complete Your PX360 Account Setup + + + +
+
+ +

Patient Experience Platform

+
+ +
+ +

Reminder: Complete Your Account Setup

+ +

Hello {{ user.first_name|default:user.email }},

+ +
+

We noticed that you haven't completed your PX360 account setup yet. Your invitation is still active, and we'd love to have you on board!

+ +

Click the button below to continue where you left off:

+ + +
+ +
+ ⚠️ Time Sensitive: Your invitation link will expire on {{ expires_at|date:"F j, Y, g:i a" }}. Please complete your registration before this date to avoid requesting a new invitation. +
+ + + + +
+ + diff --git a/templates/accounts/onboarding/reminder_email.txt b/templates/accounts/onboarding/reminder_email.txt new file mode 100644 index 0000000..5cc85c6 --- /dev/null +++ b/templates/accounts/onboarding/reminder_email.txt @@ -0,0 +1,21 @@ +Reminder: Complete Your PX360 Account Setup +============================================ + +Hello {{ user.first_name|default:user.email }}, + +We noticed that you haven't completed your PX360 account setup yet. Your invitation is still active, and we'd love to have you on board! + +To continue where you left off, please visit the following link: + +{{ activation_url }} + +TIME SENSITIVE: Your invitation link will expire on {{ expires_at|date:"F j, Y, g:i a" }}. +Please complete your registration before this date to avoid requesting a new invitation. + +--- + +This is an automated reminder from PX360. Please do not reply to this email. +If you have already completed your registration, please disregard this message. +If you have questions, please contact your system administrator. + +© PX360 - Patient Experience Platform diff --git a/templates/accounts/onboarding/reminder_subject.txt b/templates/accounts/onboarding/reminder_subject.txt new file mode 100644 index 0000000..7aa1b58 --- /dev/null +++ b/templates/accounts/onboarding/reminder_subject.txt @@ -0,0 +1 @@ +Reminder: Complete Your PX360 Account Setup diff --git a/templates/accounts/onboarding/step_activation.html b/templates/accounts/onboarding/step_activation.html index d42afc6..a365040 100644 --- a/templates/accounts/onboarding/step_activation.html +++ b/templates/accounts/onboarding/step_activation.html @@ -21,6 +21,7 @@
+ {% csrf_token %}