60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Quick script to create a test survey instance
|
|
"""
|
|
import os
|
|
import django
|
|
import secrets
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev')
|
|
django.setup()
|
|
|
|
from apps.surveys.models import SurveyTemplate, SurveyInstance
|
|
from apps.organizations.models import Hospital, Patient
|
|
|
|
# Get or create a hospital
|
|
hospital = Hospital.objects.first()
|
|
if not hospital:
|
|
hospital = Hospital.objects.create(
|
|
name='Test Hospital',
|
|
name_ar='مستشفى تجريبي',
|
|
code='TEST'
|
|
)
|
|
|
|
# Get or create a patient
|
|
patient = Patient.objects.filter(first_name='Test').first()
|
|
if not patient:
|
|
patient = Patient.objects.create(
|
|
first_name='Test',
|
|
last_name='Patient',
|
|
mrn='TEST001',
|
|
hospital=hospital
|
|
)
|
|
|
|
# Get or create a survey template
|
|
st = SurveyTemplate.objects.filter(name='Patient Satisfaction Survey').first()
|
|
if not st:
|
|
st = SurveyTemplate.objects.create(
|
|
name='Patient Satisfaction Survey',
|
|
name_ar='استبيان رضا المرضى',
|
|
hospital=hospital,
|
|
survey_type='general',
|
|
is_active=True
|
|
)
|
|
|
|
# Create a survey instance with a real token
|
|
survey = SurveyInstance.objects.create(
|
|
survey_template=st,
|
|
patient=patient,
|
|
hospital=hospital,
|
|
status='in_progress'
|
|
)
|
|
|
|
print(f'\nCreated survey instance:')
|
|
print(f' Access Token: {survey.access_token}')
|
|
print(f' Survey ID: {survey.id}')
|
|
print(f' Status: {survey.status}')
|
|
print(f' URL: http://localhost:8000/surveys/s/{survey.access_token}/')
|
|
print(f'\nTest this URL in your browser!\n')
|