This commit is contained in:
Marwan Alwali 2025-11-06 14:52:40 +03:00
parent 6e50a3f12e
commit 98e13df2f6
10 changed files with 818 additions and 208 deletions

Binary file not shown.

View File

@ -25,26 +25,28 @@ logger = logging.getLogger(__name__)
def generate_mrn(tenant):
"""
Generate unique Medical Record Number (MRN).
Format: YYYY-NNNNNN
Format: NNNNNN (6 digits)
"""
current_year = timezone.now().year
# Get last patient for this tenant in current year
# Get the highest MRN number for this tenant
last_patient = Patient.objects.filter(
tenant=tenant,
created_at__year=current_year
).order_by('-created_at').first()
mrn__isnull=False
).exclude(mrn='').order_by('-mrn').first()
if last_patient and last_patient.mrn:
# Extract number from last MRN
try:
last_number = int(last_patient.mrn[-1])
last_number = int(last_patient.mrn)
new_number = last_number + 1
except (ValueError, IndexError):
except (ValueError, TypeError):
new_number = 1
else:
new_number = 1
# Ensure uniqueness by checking if MRN already exists
while Patient.objects.filter(tenant=tenant, mrn=f"{new_number:06d}").exists():
new_number += 1
return f"{new_number:06d}"

Binary file not shown.

View File

@ -84438,3 +84438,556 @@ INFO 2025-11-06 14:26:29,398 basehttp 70224 6205403136 "GET /en/notifications/ap
INFO 2025-11-06 14:26:59,399 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:27:03,970 basehttp 70224 6205403136 "GET /en/patients/create/ HTTP/1.1" 200 38793
INFO 2025-11-06 14:27:04,003 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
ERROR 2025-11-06 14:27:25,794 tasks 76869 8426217792 Appointment b0c611dd-314f-4f02-8011-ac5519bdd525 not found
INFO 2025-11-06 14:27:34,017 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:28:04,019 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:28:12,668 basehttp 70224 6205403136 "GET /en/patients/ HTTP/1.1" 200 83739
WARNING 2025-11-06 14:28:12,687 basehttp 70224 6205403136 "GET /static/plugins/datatables/datatables.min.css HTTP/1.1" 404 2038
WARNING 2025-11-06 14:28:12,687 basehttp 70224 6222229504 "GET /static/plugins/datatables/datatables.min.js HTTP/1.1" 404 2035
INFO 2025-11-06 14:28:12,704 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:28:15,246 basehttp 70224 6205403136 "GET /en/appointments/create/?patient=068590d0-9ac0-4dad-b596-d09b8afb8466 HTTP/1.1" 200 55637
INFO 2025-11-06 14:28:15,257 basehttp 70224 6205403136 "GET /static/plugins/datatables.net-select-bs5/css/select.bootstrap5.min.css HTTP/1.1" 200 2157
INFO 2025-11-06 14:28:15,279 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:28:22,642 basehttp 70224 6205403136 "GET /api/v1/providers/?clinic=1cbc01b4-2506-4408-9c5b-b60293b3bbbb HTTP/1.1" 200 866
INFO 2025-11-06 14:28:34,738 basehttp 70224 6205403136 "GET /en/appointments/api/available-slots/?provider=8a29b3e3-0133-4d19-88fd-3fa35912a7f0&date=2025-11-06&duration=30 HTTP/1.1" 200 457
INFO 2025-11-06 14:28:45,289 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:28:53,318 basehttp 70224 6205403136 "GET /en/patients/create/ HTTP/1.1" 200 38793
INFO 2025-11-06 14:28:53,404 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:29:15,295 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:29:24,254 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:29:26,730 basehttp 70224 6205403136 "GET /en/referrals/ HTTP/1.1" 200 30248
INFO 2025-11-06 14:29:26,751 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:29:31,939 basehttp 70224 6205403136 "GET /en/referrals/create/ HTTP/1.1" 200 44512
INFO 2025-11-06 14:29:31,980 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:29:54,256 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:29:57,644 basehttp 70224 6205403136 "GET /en/referrals/external/ HTTP/1.1" 200 12512
INFO 2025-11-06 14:30:00,013 tasks 76869 8426217792 Radiology results sync started
INFO 2025-11-06 14:30:00,014 tasks 76869 8426217792 Radiology results sync completed: {'status': 'success', 'new_studies': 0, 'new_reports': 0, 'errors': 0, 'timestamp': '2025-11-06 11:30:00.014086+00:00'}
INFO 2025-11-06 14:30:00,018 tasks 76869 8426217792 Lab results sync started
INFO 2025-11-06 14:30:00,018 tasks 76869 8426217792 Lab results sync completed: {'status': 'success', 'new_results': 0, 'updated_results': 0, 'errors': 0, 'timestamp': '2025-11-06 11:30:00.018689+00:00'}
INFO 2025-11-06 14:30:24,254 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:30:54,243 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:31:24,250 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:31:54,240 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:32:24,235 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:32:27,890 basehttp 70224 6205403136 "GET /en/referrals/external/ HTTP/1.1" 200 12947
INFO 2025-11-06 14:33:09,245 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:34:09,250 basehttp 70224 6205403136 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
ERROR 2025-11-06 14:34:22,082 log 70224 6205403136 Internal Server Error: /en/referrals/external/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
return self.form_valid(form)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/referrals/views.py", line 511, in form_valid
from core.services import generate_mrn
ImportError: cannot import name 'generate_mrn' from 'core.services' (/Users/marwanalwali/AgdarCentre/core/services.py)
ERROR 2025-11-06 14:34:22,083 basehttp 70224 6205403136 "POST /en/referrals/external/ HTTP/1.1" 500 90231
INFO 2025-11-06 14:34:57,914 autoreload 70224 8426217792 /Users/marwanalwali/AgdarCentre/referrals/views.py changed, reloading.
INFO 2025-11-06 14:34:58,200 autoreload 74844 8426217792 Watching for file changes with StatReloader
ERROR 2025-11-06 14:35:05,422 log 74844 6197653504 Internal Server Error: /en/referrals/external/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.IntegrityError: UNIQUE constraint failed: core_patient.mrn
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
return self.form_valid(form)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/referrals/views.py", line 513, in form_valid
patient = Patient.objects.create(**patient_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 663, in create
obj.save(force_insert=True, using=self.db)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 902, in save
self.save_base(
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1008, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1169, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1210, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 1868, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
cursor.execute(sql, params)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 122, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: UNIQUE constraint failed: core_patient.mrn
ERROR 2025-11-06 14:35:05,423 basehttp 74844 6197653504 "POST /en/referrals/external/ HTTP/1.1" 500 197798
INFO 2025-11-06 14:35:09,258 basehttp 74844 6197653504 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:36:00,920 autoreload 74844 8426217792 /Users/marwanalwali/AgdarCentre/referrals/views.py changed, reloading.
INFO 2025-11-06 14:36:01,248 autoreload 75418 8426217792 Watching for file changes with StatReloader
INFO 2025-11-06 14:36:09,064 signals 75418 6131232768 Generated MRN: 000001
ERROR 2025-11-06 14:36:09,080 log 75418 6131232768 Internal Server Error: /en/referrals/external/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.IntegrityError: UNIQUE constraint failed: core_patient.mrn
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
return self.form_valid(form)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/referrals/views.py", line 511, in form_valid
patient = Patient.objects.create(**patient_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 663, in create
obj.save(force_insert=True, using=self.db)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 902, in save
self.save_base(
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1008, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1169, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1210, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 1868, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
cursor.execute(sql, params)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 122, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: UNIQUE constraint failed: core_patient.mrn
ERROR 2025-11-06 14:36:09,082 basehttp 75418 6131232768 "POST /en/referrals/external/ HTTP/1.1" 500 197471
INFO 2025-11-06 14:36:09,233 basehttp 75418 6131232768 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:36:11,617 basehttp 75418 6131232768 "GET /en/referrals/external/ HTTP/1.1" 200 12947
INFO 2025-11-06 14:36:21,134 basehttp 75418 6131232768 "GET /en/admin/core/patient/ HTTP/1.1" 200 88242
INFO 2025-11-06 14:36:21,152 basehttp 75418 6131232768 "GET /en/admin/jsi18n/ HTTP/1.1" 200 3342
INFO 2025-11-06 14:36:24,231 basehttp 75418 6131232768 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:36:54,243 basehttp 75418 6131232768 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:37:15,891 signals 75418 6131232768 Generated MRN: 000001
ERROR 2025-11-06 14:37:15,914 log 75418 6131232768 Internal Server Error: /en/referrals/external/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.IntegrityError: UNIQUE constraint failed: core_patient.mrn
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
return self.form_valid(form)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/referrals/views.py", line 511, in form_valid
patient = Patient.objects.create(**patient_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 663, in create
obj.save(force_insert=True, using=self.db)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 902, in save
self.save_base(
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1008, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1169, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1210, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 1868, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
cursor.execute(sql, params)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 122, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: UNIQUE constraint failed: core_patient.mrn
ERROR 2025-11-06 14:37:15,916 basehttp 75418 6131232768 "POST /en/referrals/external/ HTTP/1.1" 500 197550
INFO 2025-11-06 14:37:55,231 basehttp 75418 6131232768 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:38:05,824 autoreload 75418 8426217792 /Users/marwanalwali/AgdarCentre/core/signals.py changed, reloading.
INFO 2025-11-06 14:38:06,203 autoreload 76462 8426217792 Watching for file changes with StatReloader
INFO 2025-11-06 14:38:14,950 signals 76462 6134231040 Generated MRN: 000051
INFO 2025-11-06 14:38:14,953 signals 76462 6134231040 Generated File Number: 000001
INFO 2025-11-06 14:38:14,954 signals 76462 6134231040 File created: 000001 for patient 000051
INFO 2025-11-06 14:38:14,955 signals 76462 6134231040 Created main file for patient: 000051
INFO 2025-11-06 14:38:14,955 signals 76462 6134231040 Patient created: 000051 - Marwan Alwali
ERROR 2025-11-06 14:38:14,962 log 76462 6134231040 Internal Server Error: /en/referrals/external/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
return self.form_valid(form)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/referrals/views.py", line 514, in form_valid
referral = form.instance
^^^^^^^^^^^^^
AttributeError: 'ExternalReferralForm' object has no attribute 'instance'
ERROR 2025-11-06 14:38:14,963 basehttp 76462 6134231040 "POST /en/referrals/external/ HTTP/1.1" 500 90123
ERROR 2025-11-06 14:38:41,200 tasks 76869 8426217792 Appointment 69dcd286-66b4-4619-9870-fda6fe206ff3 not found
INFO 2025-11-06 14:38:51,508 autoreload 76462 8426217792 /Users/marwanalwali/AgdarCentre/referrals/views.py changed, reloading.
INFO 2025-11-06 14:38:51,853 autoreload 76872 8426217792 Watching for file changes with StatReloader
INFO 2025-11-06 14:38:56,235 basehttp 76872 6201716736 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
ERROR 2025-11-06 14:38:59,732 log 76872 6201716736 Internal Server Error: /en/referrals/external/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.IntegrityError: NOT NULL constraint failed: referrals_referral.from_clinic_id
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
return self.form_valid(form)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/referrals/views.py", line 528, in form_valid
referral = Referral.objects.create(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 663, in create
obj.save(force_insert=True, using=self.db)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 902, in save
self.save_base(
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1008, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1169, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1210, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 1868, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
cursor.execute(sql, params)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 122, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 360, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: NOT NULL constraint failed: referrals_referral.from_clinic_id
ERROR 2025-11-06 14:38:59,733 basehttp 76872 6201716736 "POST /en/referrals/external/ HTTP/1.1" 500 200845
INFO 2025-11-06 14:39:53,302 autoreload 76872 8426217792 /Users/marwanalwali/AgdarCentre/referrals/views.py changed, reloading.
INFO 2025-11-06 14:39:53,680 autoreload 77423 8426217792 Watching for file changes with StatReloader
INFO 2025-11-06 14:39:57,233 basehttp 77423 6162378752 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:40:03,497 basehttp 77423 6162378752 "POST /en/referrals/external/ HTTP/1.1" 302 0
ERROR 2025-11-06 14:40:03,513 log 77423 6162378752 Internal Server Error: /en/referrals/external/success/
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/base.py", line 510, in parse
compile_func = self.tags[command]
~~~~~~~~~^^^^^^^^^
KeyError: 'trans'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 220, in _get_response
response = response.render()
^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/response.py", line 114, in render
self.content = self.rendered_content
^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/response.py", line 90, in rendered_content
template = self.resolve_template(self.template_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/response.py", line 72, in resolve_template
return select_template(template, using=self.using)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/loader.py", line 42, in select_template
return engine.get_template(template_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/backends/django.py", line 79, in get_template
return Template(self.engine.get_template(template_name), self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/engine.py", line 177, in get_template
template, origin = self.find_template(template_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/engine.py", line 159, in find_template
template = loader.get_template(name, skip=skip)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/loaders/cached.py", line 57, in get_template
template = super().get_template(template_name, skip)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/loaders/base.py", line 28, in get_template
return Template(
^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/base.py", line 154, in __init__
self.nodelist = self.compile_nodelist()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/base.py", line 196, in compile_nodelist
nodelist = parser.parse()
^^^^^^^^^^^^^^
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/base.py", line 512, in parse
self.invalid_block_tag(token, command, parse_until)
File "/Users/marwanalwali/AgdarCentre/.venv/lib/python3.12/site-packages/django/template/base.py", line 577, in invalid_block_tag
raise self.error(
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 6: 'trans'. Did you forget to register or load this tag?
ERROR 2025-11-06 14:40:03,514 basehttp 77423 6162378752 "GET /en/referrals/external/success/ HTTP/1.1" 500 172170
ERROR 2025-11-06 14:40:47,565 tasks 76869 8426217792 Appointment 36b67a10-fe1e-41a7-8f62-0b0ca127c128 not found
INFO 2025-11-06 14:40:58,242 basehttp 77423 6162378752 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:41:50,770 basehttp 77423 6162378752 "GET /en/referrals/external/success/ HTTP/1.1" 200 5163
INFO 2025-11-06 14:41:59,236 basehttp 77423 6162378752 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:42:20,353 basehttp 77423 6162378752 "GET /en/referrals/external/ HTTP/1.1" 200 13282
INFO 2025-11-06 14:42:28,771 basehttp 77423 6162378752 "GET /en/referrals/ HTTP/1.1" 200 30248
INFO 2025-11-06 14:42:28,823 basehttp 77423 6162378752 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:42:58,839 basehttp 77423 6162378752 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:43:28,829 basehttp 77423 6162378752 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:43:43,541 autoreload 77423 8426217792 /Users/marwanalwali/AgdarCentre/referrals/views.py changed, reloading.
INFO 2025-11-06 14:43:43,839 autoreload 79345 8426217792 Watching for file changes with StatReloader
INFO 2025-11-06 14:43:49,830 basehttp 79345 6165508096 "GET /en/referrals/ HTTP/1.1" 200 30248
INFO 2025-11-06 14:43:49,862 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:44:01,682 basehttp 79345 6165508096 "GET /en/admin/referrals/referral/ HTTP/1.1" 200 66668
INFO 2025-11-06 14:44:01,699 basehttp 79345 6165508096 "GET /en/admin/jsi18n/ HTTP/1.1" 200 3342
INFO 2025-11-06 14:44:07,272 basehttp 79345 6165508096 "GET /en/admin/referrals/referral/0df8ecaa-4174-47cd-9fcf-27969dbfc513/change/ HTTP/1.1" 200 86395
INFO 2025-11-06 14:44:07,289 basehttp 79345 6182334464 "GET /static/admin/img/icon-deletelink.svg HTTP/1.1" 200 392
INFO 2025-11-06 14:44:07,292 basehttp 79345 6165508096 "GET /en/admin/jsi18n/ HTTP/1.1" 200 3342
INFO 2025-11-06 14:44:20,241 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:44:37,773 basehttp 79345 6165508096 "GET /en/admin/core/patient/ HTTP/1.1" 200 88867
INFO 2025-11-06 14:44:37,786 basehttp 79345 6165508096 "GET /en/admin/jsi18n/ HTTP/1.1" 200 3342
INFO 2025-11-06 14:44:50,240 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:44:52,948 basehttp 79345 6165508096 "GET /en/admin/core/patient/b480432c-b0fc-46c2-9b4b-780a36f6bfbc/change/ HTTP/1.1" 200 71368
INFO 2025-11-06 14:44:52,968 basehttp 79345 6165508096 "GET /en/admin/jsi18n/ HTTP/1.1" 200 3342
INFO 2025-11-06 14:45:20,230 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:45:23,638 basehttp 79345 6165508096 "GET /en/admin/core/patient/ HTTP/1.1" 200 88867
INFO 2025-11-06 14:45:49,866 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:46:19,875 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:46:49,866 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:47:19,896 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:47:27,854 basehttp 79345 6165508096 "GET /en/referrals/ HTTP/1.1" 200 30248
INFO 2025-11-06 14:47:27,884 basehttp 79345 6165508096 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
WARNING 2025-11-06 14:47:54,718 log 79345 6165508096 Not Found: /.well-known/appspecific/com.chrome.devtools.json
WARNING 2025-11-06 14:47:54,718 basehttp 79345 6165508096 "GET /.well-known/appspecific/com.chrome.devtools.json HTTP/1.1" 404 3165
WARNING 2025-11-06 14:47:54,732 basehttp 79345 6165508096 "GET /static/plugins/toastr/toastr.js.map HTTP/1.1" 404 2011
INFO 2025-11-06 14:47:57,908 basehttp 79345 6182334464 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:47:59,673 basehttp 79345 6182334464 "GET /en/referrals/ HTTP/1.1" 200 30248
INFO 2025-11-06 14:47:59,682 basehttp 79345 6199160832 "GET /static/css/custom.css HTTP/1.1" 200 580
INFO 2025-11-06 14:47:59,686 basehttp 79345 6215987200 "GET /static/plugins/toastr/toastr.css HTTP/1.1" 200 7860
INFO 2025-11-06 14:47:59,691 basehttp 79345 6165508096 "GET /static/css/vendor.min.css HTTP/1.1" 200 177466
INFO 2025-11-06 14:47:59,693 basehttp 79345 6182334464 "GET /static/css/default/app.min.css HTTP/1.1" 200 1030608
INFO 2025-11-06 14:47:59,696 basehttp 79345 6215987200 "GET /static/js/htmx.min.js HTTP/1.1" 200 51076
INFO 2025-11-06 14:47:59,699 basehttp 79345 6182334464 "GET /static/webfonts/fa-solid-900.woff2 HTTP/1.1" 200 158220
INFO 2025-11-06 14:47:59,700 basehttp 79345 6182334464 "GET /static/plugins/toastr/toastr.min.js HTTP/1.1" 200 5536
INFO 2025-11-06 14:47:59,703 basehttp 79345 6215987200 "GET /static/js/app.min.js HTTP/1.1" 200 110394
INFO 2025-11-06 14:47:59,704 basehttp 79345 6182334464 "GET /static/js/select2-init.js HTTP/1.1" 200 2415
INFO 2025-11-06 14:47:59,704 basehttp 79345 6232813568 "GET /media/tenant_settings/2025/11/04/Agdar-Logo.png HTTP/1.1" 200 12528
WARNING 2025-11-06 14:47:59,705 log 79345 6199160832 Not Found: /.well-known/appspecific/com.chrome.devtools.json
WARNING 2025-11-06 14:47:59,705 basehttp 79345 6199160832 "GET /.well-known/appspecific/com.chrome.devtools.json HTTP/1.1" 404 3165
INFO 2025-11-06 14:47:59,706 basehttp 79345 6165508096 "GET /static/js/vendor.min.js HTTP/1.1" 200 1091361
INFO 2025-11-06 14:47:59,716 basehttp 79345 6249639936 "GET /media/profile_pictures/Father_-d_HcbHEbL.png HTTP/1.1" 200 1997779
WARNING 2025-11-06 14:47:59,902 basehttp 79345 6165508096 "GET /static/plugins/toastr/toastr.js.map HTTP/1.1" 404 2011
INFO 2025-11-06 14:47:59,909 basehttp 79345 6199160832 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:47:59,915 basehttp 79345 6249639936 "GET /static/css/default/app.min.css.map HTTP/1.1" 200 2154602
INFO 2025-11-06 14:48:00,025 basehttp 79345 6249639936 "GET /static/img/logo/favicon.ico HTTP/1.1" 200 15086
INFO 2025-11-06 14:48:00,025 basehttp 79345 6165508096 "GET /static/img/logo/site.webmanifest HTTP/1.1" 200 436
INFO 2025-11-06 14:48:29,922 basehttp 79345 6249639936 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:48:59,923 basehttp 79345 6249639936 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:49:29,916 basehttp 79345 6249639936 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:49:30,511 autoreload 79345 8426217792 /Users/marwanalwali/AgdarCentre/referrals/views.py changed, reloading.
INFO 2025-11-06 14:49:30,983 autoreload 82325 8426217792 Watching for file changes with StatReloader
INFO 2025-11-06 14:49:41,202 basehttp 82325 6198112256 "GET /en/referrals/ HTTP/1.1" 200 60832
WARNING 2025-11-06 14:49:41,222 log 82325 6198112256 Not Found: /.well-known/appspecific/com.chrome.devtools.json
WARNING 2025-11-06 14:49:41,222 basehttp 82325 6198112256 "GET /.well-known/appspecific/com.chrome.devtools.json HTTP/1.1" 404 3165
INFO 2025-11-06 14:49:41,284 basehttp 82325 6198112256 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
WARNING 2025-11-06 14:49:41,289 basehttp 82325 6198112256 "GET /static/plugins/toastr/toastr.js.map HTTP/1.1" 404 2011
INFO 2025-11-06 14:50:11,297 basehttp 82325 6214938624 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
ERROR 2025-11-06 14:50:19,351 tasks 70301 8426217792 Appointment b7386e99-0cbb-420c-9fa8-13a2200e5715 not found
ERROR 2025-11-06 14:50:19,352 tasks 76869 8426217792 Appointment b5a77fcd-5a4b-4e96-9a68-fd3018073de1 not found
INFO 2025-11-06 14:50:41,298 basehttp 82325 6214938624 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:51:11,299 basehttp 82325 6214938624 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:51:41,298 basehttp 82325 6214938624 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
INFO 2025-11-06 14:51:49,370 basehttp 82325 6214938624 "GET /en/referrals/0df8ecaa-4174-47cd-9fcf-27969dbfc513/ HTTP/1.1" 200 32042
WARNING 2025-11-06 14:51:49,389 log 82325 6214938624 Not Found: /.well-known/appspecific/com.chrome.devtools.json
WARNING 2025-11-06 14:51:49,389 basehttp 82325 6214938624 "GET /.well-known/appspecific/com.chrome.devtools.json HTTP/1.1" 404 3165
WARNING 2025-11-06 14:51:49,449 basehttp 82325 6198112256 "GET /static/plugins/toastr/toastr.js.map HTTP/1.1" 404 2011
INFO 2025-11-06 14:51:49,453 basehttp 82325 6214938624 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19
WARNING 2025-11-06 14:52:05,530 basehttp 82325 6198112256 "GET /static/plugins/toastr/toastr.js.map HTTP/1.1" 404 2011
WARNING 2025-11-06 14:52:05,539 log 82325 6214938624 Not Found: /.well-known/appspecific/com.chrome.devtools.json
WARNING 2025-11-06 14:52:05,540 basehttp 82325 6214938624 "GET /.well-known/appspecific/com.chrome.devtools.json HTTP/1.1" 404 3165
WARNING 2025-11-06 14:52:05,553 log 82325 6214938624 Not Found: /.well-known/appspecific/com.chrome.devtools.json
WARNING 2025-11-06 14:52:05,553 basehttp 82325 6214938624 "GET /.well-known/appspecific/com.chrome.devtools.json HTTP/1.1" 404 3165
INFO 2025-11-06 14:52:11,299 basehttp 82325 6214938624 "GET /en/notifications/api/unread-count/ HTTP/1.1" 200 19

View File

@ -1,15 +1,24 @@
{% load i18n %}
{% load i18n static %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:'en' }}" dir="{% if LANGUAGE_CODE == 'ar' %}rtl{% else %}ltr{% endif %}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% trans "External Referral" %} - {% if tenant %}{{ tenant.name }}{% else %}Agdar Centre{% endif %}</title>
{% load static i18n %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Core CSS -->
{% if LANGUAGE_CODE == 'ar' %}
<link href="{% static 'css/default/app-rtl.min.css' %}" rel="stylesheet" />
<link href="{% static 'css/rtl-fixes.css' %}" rel="stylesheet" />
{% else %}
<link href="{% static 'css/default/app.min.css' %}" rel="stylesheet" />
{% endif %}
<link href="{% static 'css/vendor.min.css' %}" rel="stylesheet" />
<link href="{% static 'css/custom.css' %}" rel="stylesheet" />
<style>
body {
background-color: #f8f9fa;
min-height: 100vh;
padding: 20px 0;
}
@ -17,142 +26,114 @@
max-width: 900px;
margin: 0 auto;
}
.referral-card {
.page-header {
background: white;
border-radius: 15px;
box-shadow: 0 10px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.referral-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 30px;
margin-bottom: 20px;
text-align: center;
}
.referral-header h1 {
.page-header h1 {
margin: 0;
font-size: 2rem;
font-weight: 600;
}
.referral-header p {
margin: 10px 0 0 0;
opacity: 0.9;
}
.referral-body {
padding: 40px;
}
.form-section {
margin-bottom: 30px;
padding-bottom: 30px;
border-bottom: 2px solid #f0f0f0;
}
.form-section:last-child {
border-bottom: none;
}
.form-section h3 {
color: #667eea;
font-size: 1.3rem;
margin-bottom: 20px;
font-weight: 600;
}
.form-label {
font-weight: 500;
color: #333;
margin-bottom: 8px;
}
.form-control, .form-select {
border-radius: 8px;
border: 2px solid #e0e0e0;
padding: 12px;
}
.form-control:focus, .form-select:focus {
border-color: #667eea;
box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}
.btn-submit {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
padding: 15px 40px;
font-size: 1.1rem;
font-weight: 600;
border-radius: 8px;
width: 100%;
margin-top: 20px;
}
.btn-submit:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}
.required-field::after {
content: " *";
color: #dc3545;
.page-header p {
margin: 10px 0 0 0;
color: #6c757d;
}
.info-box {
background: #f8f9fa;
border-left: 4px solid #667eea;
background: #e7f3ff;
border-left: 4px solid #0d6efd;
padding: 15px;
margin-bottom: 20px;
border-radius: 5px;
}
.info-box i {
color: #667eea;
color: #0d6efd;
margin-right: 10px;
}
.form-section {
margin-bottom: 20px;
}
.required-field::after {
content: " *";
color: #dc3545;
}
.btn-submit {
padding: 12px 40px;
font-size: 1.1rem;
font-weight: 600;
}
.footer-text {
text-align: center;
margin-top: 30px;
color: #6c757d;
}
</style>
</head>
<body>
<div class="referral-container">
<div class="referral-card">
<div class="referral-header">
<h1><i class="fas fa-hospital-user me-2"></i>{% trans "External Referral Form" %}</h1>
<p>{% if tenant %}{{ tenant.name }}{% else %}{% trans "Agdar Centre" %}{% endif %}</p>
</div>
<div class="referral-body">
<div class="info-box">
<i class="fas fa-info-circle"></i>
<strong>{% trans "Welcome!" %}</strong> {% trans "Please fill out this form to refer a patient to our center. We will review your referral and contact you within 24-48 hours with next steps." %}
<!-- Page Header -->
<div class="page-header">
<h1><i class="fas fa-hospital-user me-2"></i>{% trans "External Referral Form" %}</h1>
<p>{% if tenant %}{{ tenant.name }}{% else %}{% trans "Agdar Centre" %}{% endif %}</p>
</div>
<!-- Info Box -->
<div class="info-box">
<i class="fas fa-info-circle"></i>
<strong>{% trans "Welcome!" %}</strong> {% trans "Please fill out this form to refer a patient to our center. We will review your referral and contact you within 24-48 hours with next steps." %}
</div>
<!-- Messages -->
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
<form method="post" novalidate>
{% csrf_token %}
<!-- Referring Center Information -->
<div class="form-section">
<h3><i class="fas fa-building me-2"></i>{% trans "Referring Center Information" %}</h3>
<div class="row">
<div class="col-12 mb-3">
<label class="form-label required-field">{{ form.referring_center_name.label }}</label>
<form method="post" novalidate>
{% csrf_token %}
<!-- Referring Center Information -->
<div class="form-section">
<div class="card border-0 shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0">
<i class="fas fa-building me-2"></i>{% trans "Referring Center Information" %}
</h5>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-12">
<label for="{{ form.referring_center_name.id_for_label }}" class="form-label required-field">{{ form.referring_center_name.label }}</label>
{{ form.referring_center_name }}
{% if form.referring_center_name.errors %}
<div class="text-danger small mt-1">{{ form.referring_center_name.errors }}</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.referring_doctor_name.label }}</label>
<div class="col-md-6">
<label for="{{ form.referring_doctor_name.id_for_label }}" class="form-label required-field">{{ form.referring_doctor_name.label }}</label>
{{ form.referring_doctor_name }}
{% if form.referring_doctor_name.errors %}
<div class="text-danger small mt-1">{{ form.referring_doctor_name.errors }}</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.referring_contact_phone.label }}</label>
<div class="col-md-6">
<label for="{{ form.referring_contact_phone.id_for_label }}" class="form-label required-field">{{ form.referring_contact_phone.label }}</label>
{{ form.referring_contact_phone }}
{% if form.referring_contact_phone.errors %}
<div class="text-danger small mt-1">{{ form.referring_contact_phone.errors }}</div>
{% endif %}
</div>
<div class="col-12 mb-3">
<label class="form-label required-field">{{ form.referring_contact_email.label }}</label>
<div class="col-12">
<label for="{{ form.referring_contact_email.id_for_label }}" class="form-label required-field">{{ form.referring_contact_email.label }}</label>
{{ form.referring_contact_email }}
{% if form.referring_contact_email.errors %}
<div class="text-danger small mt-1">{{ form.referring_contact_email.errors }}</div>
@ -160,41 +141,49 @@
</div>
</div>
</div>
</div>
</div>
<!-- Patient Information -->
<div class="form-section">
<h3><i class="fas fa-user me-2"></i>{% trans "Patient Information" %}</h3>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.patient_first_name.label }}</label>
<!-- Patient Information -->
<div class="form-section">
<div class="card border-0 shadow-sm">
<div class="card-header bg-info text-white">
<h5 class="mb-0">
<i class="fas fa-user me-2"></i>{% trans "Patient Information" %}
</h5>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-6">
<label for="{{ form.patient_first_name.id_for_label }}" class="form-label required-field">{{ form.patient_first_name.label }}</label>
{{ form.patient_first_name }}
{% if form.patient_first_name.errors %}
<div class="text-danger small mt-1">{{ form.patient_first_name.errors }}</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.patient_last_name.label }}</label>
<div class="col-md-6">
<label for="{{ form.patient_last_name.id_for_label }}" class="form-label required-field">{{ form.patient_last_name.label }}</label>
{{ form.patient_last_name }}
{% if form.patient_last_name.errors %}
<div class="text-danger small mt-1">{{ form.patient_last_name.errors }}</div>
{% endif %}
</div>
<div class="col-md-4 mb-3">
<label class="form-label required-field">{{ form.patient_date_of_birth.label }}</label>
<div class="col-md-4">
<label for="{{ form.patient_date_of_birth.id_for_label }}" class="form-label required-field">{{ form.patient_date_of_birth.label }}</label>
{{ form.patient_date_of_birth }}
{% if form.patient_date_of_birth.errors %}
<div class="text-danger small mt-1">{{ form.patient_date_of_birth.errors }}</div>
{% endif %}
</div>
<div class="col-md-4 mb-3">
<label class="form-label required-field">{{ form.patient_sex.label }}</label>
<div class="col-md-4">
<label for="{{ form.patient_sex.id_for_label }}" class="form-label required-field">{{ form.patient_sex.label }}</label>
{{ form.patient_sex }}
{% if form.patient_sex.errors %}
<div class="text-danger small mt-1">{{ form.patient_sex.errors }}</div>
{% endif %}
</div>
<div class="col-md-4 mb-3">
<label class="form-label">{{ form.patient_national_id.label }}</label>
<div class="col-md-4">
<label for="{{ form.patient_national_id.id_for_label }}" class="form-label">{{ form.patient_national_id.label }}</label>
{{ form.patient_national_id }}
{% if form.patient_national_id.errors %}
<div class="text-danger small mt-1">{{ form.patient_national_id.errors }}</div>
@ -202,27 +191,35 @@
</div>
</div>
</div>
</div>
</div>
<!-- Guardian Information -->
<div class="form-section">
<h3><i class="fas fa-user-friends me-2"></i>{% trans "Parent/Guardian Information" %}</h3>
<div class="row">
<div class="col-12 mb-3">
<label class="form-label required-field">{{ form.caregiver_name.label }}</label>
<!-- Guardian Information -->
<div class="form-section">
<div class="card border-0 shadow-sm">
<div class="card-header bg-success text-white">
<h5 class="mb-0">
<i class="fas fa-user-friends me-2"></i>{% trans "Parent/Guardian Information" %}
</h5>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-12">
<label for="{{ form.caregiver_name.id_for_label }}" class="form-label required-field">{{ form.caregiver_name.label }}</label>
{{ form.caregiver_name }}
{% if form.caregiver_name.errors %}
<div class="text-danger small mt-1">{{ form.caregiver_name.errors }}</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.caregiver_phone.label }}</label>
<div class="col-md-6">
<label for="{{ form.caregiver_phone.id_for_label }}" class="form-label required-field">{{ form.caregiver_phone.label }}</label>
{{ form.caregiver_phone }}
{% if form.caregiver_phone.errors %}
<div class="text-danger small mt-1">{{ form.caregiver_phone.errors }}</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.caregiver_relationship.label }}</label>
<div class="col-md-6">
<label for="{{ form.caregiver_relationship.id_for_label }}" class="form-label required-field">{{ form.caregiver_relationship.label }}</label>
{{ form.caregiver_relationship }}
{% if form.caregiver_relationship.errors %}
<div class="text-danger small mt-1">{{ form.caregiver_relationship.errors }}</div>
@ -230,34 +227,42 @@
</div>
</div>
</div>
</div>
</div>
<!-- Referral Details -->
<div class="form-section">
<h3><i class="fas fa-clipboard-list me-2"></i>{% trans "Referral Details" %}</h3>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.urgency.label }}</label>
<!-- Referral Details -->
<div class="form-section">
<div class="card border-0 shadow-sm">
<div class="card-header bg-warning text-dark">
<h5 class="mb-0">
<i class="fas fa-clipboard-list me-2"></i>{% trans "Referral Details" %}
</h5>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-6">
<label for="{{ form.urgency.id_for_label }}" class="form-label required-field">{{ form.urgency.label }}</label>
{{ form.urgency }}
{% if form.urgency.errors %}
<div class="text-danger small mt-1">{{ form.urgency.errors }}</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label class="form-label required-field">{{ form.requested_specialty.label }}</label>
<div class="col-md-6">
<label for="{{ form.requested_specialty.id_for_label }}" class="form-label required-field">{{ form.requested_specialty.label }}</label>
{{ form.requested_specialty }}
{% if form.requested_specialty.errors %}
<div class="text-danger small mt-1">{{ form.requested_specialty.errors }}</div>
{% endif %}
</div>
<div class="col-12 mb-3">
<label class="form-label required-field">{{ form.reason.label }}</label>
<div class="col-12">
<label for="{{ form.reason.id_for_label }}" class="form-label required-field">{{ form.reason.label }}</label>
{{ form.reason }}
{% if form.reason.errors %}
<div class="text-danger small mt-1">{{ form.reason.errors }}</div>
{% endif %}
</div>
<div class="col-12 mb-3">
<label class="form-label">{{ form.clinical_summary.label }}</label>
<div class="col-12">
<label for="{{ form.clinical_summary.id_for_label }}" class="form-label">{{ form.clinical_summary.label }}</label>
{{ form.clinical_summary }}
<small class="form-text text-muted">{% trans "Include diagnosis, current treatment, medications, etc." %}</small>
{% if form.clinical_summary.errors %}
@ -266,25 +271,32 @@
</div>
</div>
</div>
{% if form.non_field_errors %}
<div class="alert alert-danger">
{{ form.non_field_errors }}
</div>
{% endif %}
<button type="submit" class="btn btn-primary btn-submit">
<i class="fas fa-paper-plane me-2"></i>Submit Referral
</button>
</form>
</div>
</div>
</div>
<div class="text-center mt-4 text-white">
<!-- Non-field errors -->
{% if form.non_field_errors %}
<div class="alert alert-danger">
{{ form.non_field_errors }}
</div>
{% endif %}
<!-- Submit Button -->
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg btn-submit">
<i class="fas fa-paper-plane me-2"></i>{% trans "Submit Referral" %}
</button>
</div>
</form>
<!-- Footer -->
<div class="footer-text">
<p><small>&copy; 2025 {% if tenant %}{{ tenant.name }}{% else %}{% trans "Agdar Centre" %}{% endif %}. {% trans "All rights reserved." %}</small></p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core JS -->
<script src="{% static 'js/vendor.min.js' %}"></script>
<script src="{% static 'js/app.min.js' %}"></script>
</body>
</html>

View File

@ -1,15 +1,24 @@
{% load i18n static %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:'en' }}" dir="{% if LANGUAGE_CODE == 'ar' %}rtl{% else %}ltr{% endif %}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% trans "Referral Submitted Successfully" %} - {% trans "Agdar Centre" %}</title>
{% load static i18n %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<title>{% trans "Referral Submitted Successfully" %} - {% if tenant %}{{ tenant.name }}{% else %}Agdar Centre{% endif %}</title>
<!-- Core CSS -->
{% if LANGUAGE_CODE == 'ar' %}
<link href="{% static 'css/default/app-rtl.min.css' %}" rel="stylesheet" />
<link href="{% static 'css/rtl-fixes.css' %}" rel="stylesheet" />
{% else %}
<link href="{% static 'css/default/app.min.css' %}" rel="stylesheet" />
{% endif %}
<link href="{% static 'css/vendor.min.css' %}" rel="stylesheet" />
<link href="{% static 'css/custom.css' %}" rel="stylesheet" />
<style>
body {
{#background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);#}
background-color: #f8f9fa;
min-height: 100vh;
display: flex;
align-items: center;
@ -31,7 +40,7 @@
.success-icon {
width: 100px;
height: 100px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
border-radius: 50%;
display: flex;
align-items: center;
@ -65,14 +74,14 @@
}
.info-box {
background: #f8f9fa;
border-left: 4px solid #667eea;
border-left: 4px solid #0d6efd;
padding: 20px;
margin: 30px 0;
text-align: left;
border-radius: 5px;
}
.info-box h5 {
color: #667eea;
color: #0d6efd;
font-weight: 600;
margin-bottom: 15px;
}
@ -85,7 +94,7 @@
color: #555;
}
.contact-info {
background: #e8f4f8;
background: #e7f3ff;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
@ -100,10 +109,15 @@
color: #555;
}
.contact-info i {
color: #667eea;
color: #0d6efd;
margin-right: 10px;
width: 20px;
}
.footer-text {
text-align: center;
margin-top: 30px;
color: #6c757d;
}
</style>
</head>
<body>
@ -144,11 +158,13 @@
</div>
</div>
<div class="text-center mt-4 text-white">
<p><small>&copy; 2025 {% trans "Agdar Centre" %}. {% trans "All rights reserved." %}</small></p>
<div class="footer-text">
<p><small>&copy; 2025 {% if tenant %}{{ tenant.name }}{% else %}{% trans "Agdar Centre" %}{% endif %}. {% trans "All rights reserved." %}</small></p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core JS -->
<script src="{% static 'js/vendor.min.js' %}"></script>
<script src="{% static 'js/app.min.js' %}"></script>
</body>
</html>

View File

@ -55,10 +55,13 @@ class ReferralListView(LoginRequiredMixin, TenantFilterMixin, PaginationMixin,
# Role-based filtering
if user.role in [User.Role.DOCTOR, User.Role.NURSE, User.Role.OT,
User.Role.SLP, User.Role.ABA]:
# Clinical staff see referrals from or to them
# Clinical staff see referrals from or to them, plus external referrals to their clinic
queryset = queryset.filter(
Q(from_provider=user) | Q(to_provider=user)
Q(from_provider=user) |
Q(to_provider=user) |
Q(from_discipline=Referral.Discipline.EXTERNAL, to_clinic__isnull=False)
)
# Admins and other roles see all referrals (no additional filtering needed)
# Apply search
search_query = self.request.GET.get('search', '').strip()
@ -123,12 +126,29 @@ class ReferralListView(LoginRequiredMixin, TenantFilterMixin, PaginationMixin,
'date_to': self.request.GET.get('date_to', ''),
}
# Add statistics
# Get all referrals
queryset = self.get_queryset()
# Split into sent and received
user = self.request.user
if user.role == User.Role.ADMIN:
# Admins see all referrals in both tabs
context['sent_referrals'] = queryset.filter(from_provider__isnull=False)
context['received_referrals'] = queryset
else:
# Clinical staff see their sent and received referrals
context['sent_referrals'] = queryset.filter(from_provider=user)
context['received_referrals'] = queryset.filter(
Q(to_provider=user) |
Q(from_discipline=Referral.Discipline.EXTERNAL, to_clinic__isnull=False)
)
# Add statistics
context['stats'] = {
'total_referrals': queryset.count(),
'pending': queryset.filter(status=Referral.Status.PENDING).count(),
'accepted': queryset.filter(status=Referral.Status.ACCEPTED).count(),
'completed': queryset.filter(status=Referral.Status.COMPLETED).count(),
'urgent': queryset.filter(urgency=Referral.Urgency.URGENT).count(),
}
@ -507,53 +527,60 @@ class ExternalReferralCreateView(FormView):
).first()
if not patient:
# Generate MRN for new patient
from core.services import generate_mrn
patient_data['mrn'] = generate_mrn(tenant)
# Create new patient (MRN will be auto-generated by signal)
patient = Patient.objects.create(**patient_data)
# Create referral
referral = form.instance
referral.tenant = tenant
referral.patient = patient
# Set external provider information
referral.external_provider_name = form.cleaned_data['referring_center_name']
referral.external_provider_contact = (
f"Doctor: {form.cleaned_data['referring_doctor_name']}\n"
f"Phone: {form.cleaned_data['referring_contact_phone']}\n"
f"Email: {form.cleaned_data['referring_contact_email']}"
# Get or create an "External" clinic for external referrals
from core.models import Clinic
from_clinic, _ = Clinic.objects.get_or_create(
tenant=tenant,
code='EXT',
defaults={
'name_en': 'External Referrals',
'name_ar': 'الإحالات الخارجية',
'specialty': 'EXTERNAL',
'is_active': True,
}
)
# Set referral details
referral.reason = form.cleaned_data['reason']
referral.urgency = form.cleaned_data['urgency']
referral.clinical_summary = form.cleaned_data.get('clinical_summary', '')
referral.from_discipline = Referral.Discipline.EXTERNAL
referral.status = Referral.Status.PENDING
# Map requested specialty to clinic
# Map requested specialty to target clinic
to_clinic = None
to_discipline = None
requested_specialty = form.cleaned_data.get('requested_specialty')
if requested_specialty:
from core.models import Clinic
to_clinic = Clinic.objects.filter(
tenant=tenant,
specialty=requested_specialty,
is_active=True
).first()
if to_clinic:
referral.to_clinic = to_clinic
referral.to_discipline = requested_specialty
to_discipline = requested_specialty
# Store referring center contact info in notes
referral.notes = (
f"External Referral from: {form.cleaned_data['referring_center_name']}\n"
f"Referring Doctor: {form.cleaned_data['referring_doctor_name']}\n"
f"Contact: {form.cleaned_data['referring_contact_phone']} / {form.cleaned_data['referring_contact_email']}"
# Create referral object
referral = Referral.objects.create(
tenant=tenant,
patient=patient,
from_clinic=from_clinic,
external_provider_name=form.cleaned_data['referring_center_name'],
external_provider_contact=(
f"Doctor: {form.cleaned_data['referring_doctor_name']}\n"
f"Phone: {form.cleaned_data['referring_contact_phone']}\n"
f"Email: {form.cleaned_data['referring_contact_email']}"
),
reason=form.cleaned_data['reason'],
urgency=form.cleaned_data['urgency'],
clinical_summary=form.cleaned_data.get('clinical_summary', ''),
from_discipline=Referral.Discipline.EXTERNAL,
status=Referral.Status.PENDING,
to_clinic=to_clinic,
to_discipline=to_discipline,
notes=(
f"External Referral from: {form.cleaned_data['referring_center_name']}\n"
f"Referring Doctor: {form.cleaned_data['referring_doctor_name']}\n"
f"Contact: {form.cleaned_data['referring_contact_phone']} / {form.cleaned_data['referring_contact_email']}"
)
)
referral.save()
# Send notification to staff (TODO: implement)
self._send_staff_notification(referral, form.cleaned_data)