144 lines
5.8 KiB
Python
144 lines
5.8 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Create a demo survey template with different question types
|
|
to demonstrate the survey builder preview functionality.
|
|
"""
|
|
import os
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
django.setup()
|
|
|
|
from apps.surveys.models import SurveyTemplate, SurveyQuestion
|
|
from apps.organizations.models import Hospital
|
|
|
|
def create_demo_survey():
|
|
"""Create a demo survey template with various question types."""
|
|
|
|
# Get or create a hospital
|
|
hospital, _ = Hospital.objects.get_or_create(
|
|
name="Al Hammadi Hospital - Demo",
|
|
defaults={
|
|
'code': 'DEMO',
|
|
'city': 'Riyadh',
|
|
'is_active': True
|
|
}
|
|
)
|
|
|
|
# Create the survey template
|
|
template = SurveyTemplate.objects.create(
|
|
name="Patient Experience Demo Survey",
|
|
name_ar="استبيان تجربة المريض التجريبي",
|
|
hospital=hospital,
|
|
survey_type='post_discharge',
|
|
scoring_method='average',
|
|
negative_threshold=3.0,
|
|
is_active=True
|
|
)
|
|
|
|
print(f"✓ Created template: {template.name}")
|
|
|
|
# Question 1: Text question
|
|
q1 = SurveyQuestion.objects.create(
|
|
template=template,
|
|
text="Please share any additional comments about your stay",
|
|
text_ar="يرجى مشاركة أي تعليقات إضافية حول إقامتك",
|
|
question_type='text',
|
|
order=1,
|
|
is_required=False
|
|
)
|
|
print(f" ✓ Question 1: Text - {q1.text}")
|
|
|
|
# Question 2: Rating question
|
|
q2 = SurveyQuestion.objects.create(
|
|
template=template,
|
|
text="How would you rate the quality of nursing care?",
|
|
text_ar="كيف تقي جودة التمريض؟",
|
|
question_type='rating',
|
|
order=2,
|
|
is_required=True
|
|
)
|
|
print(f" ✓ Question 2: Rating - {q2.text}")
|
|
|
|
# Question 3: Single choice question
|
|
q3 = SurveyQuestion.objects.create(
|
|
template=template,
|
|
text="Which department did you visit?",
|
|
text_ar="ما هو القسم الذي زرته؟",
|
|
question_type='single_choice',
|
|
order=3,
|
|
is_required=True,
|
|
choices_json=[
|
|
{"value": "emergency", "label": "Emergency", "label_ar": "الطوارئ"},
|
|
{"value": "outpatient", "label": "Outpatient", "label_ar": "العيادات الخارجية"},
|
|
{"value": "inpatient", "label": "Inpatient", "label_ar": "الإقامة الداخلية"},
|
|
{"value": "surgery", "label": "Surgery", "label_ar": "الجراحة"},
|
|
{"value": "radiology", "label": "Radiology", "label_ar": "الأشعة"}
|
|
]
|
|
)
|
|
print(f" ✓ Question 3: Single Choice - {q3.text}")
|
|
print(f" Choices: {', '.join([c['label'] for c in q3.choices_json])}")
|
|
|
|
# Question 4: Multiple choice question
|
|
q4 = SurveyQuestion.objects.create(
|
|
template=template,
|
|
text="What aspects of your experience were satisfactory? (Select all that apply)",
|
|
text_ar="ما هي جوانب تجربتك التي كانت مرضية؟ (حدد جميع ما ينطبق)",
|
|
question_type='multiple_choice',
|
|
order=4,
|
|
is_required=False,
|
|
choices_json=[
|
|
{"value": "staff", "label": "Staff friendliness", "label_ar": "لطف الموظفين"},
|
|
{"value": "cleanliness", "label": "Cleanliness", "label_ar": "النظافة"},
|
|
{"value": "communication", "label": "Communication", "label_ar": "التواصل"},
|
|
{"value": "wait_times", "label": "Wait times", "label_ar": "أوقات الانتظار"},
|
|
{"value": "facilities", "label": "Facilities", "label_ar": "المرافق"}
|
|
]
|
|
)
|
|
print(f" ✓ Question 4: Multiple Choice - {q4.text}")
|
|
print(f" Choices: {', '.join([c['label'] for c in q4.choices_json])}")
|
|
|
|
# Question 5: Another rating question
|
|
q5 = SurveyQuestion.objects.create(
|
|
template=template,
|
|
text="How would you rate the hospital facilities?",
|
|
text_ar="كيف تقي مرافق المستشفى؟",
|
|
question_type='rating',
|
|
order=5,
|
|
is_required=True
|
|
)
|
|
print(f" ✓ Question 5: Rating - {q5.text}")
|
|
|
|
print("\n" + "="*70)
|
|
print("DEMO SURVEY TEMPLATE CREATED SUCCESSFULLY!")
|
|
print("="*70)
|
|
print(f"\nTemplate ID: {template.id}")
|
|
print(f"Template Name: {template.name}")
|
|
print(f"Total Questions: {template.questions.count()}")
|
|
print("\nQuestion Types Summary:")
|
|
print(f" - Text questions: {template.questions.filter(question_type='text').count()}")
|
|
print(f" - Rating questions: {template.questions.filter(question_type='rating').count()}")
|
|
print(f" - Single Choice questions: {template.questions.filter(question_type='single_choice').count()}")
|
|
print(f" - Multiple Choice questions: {template.questions.filter(question_type='multiple_choice').count()}")
|
|
|
|
print("\n" + "="*70)
|
|
print("NEXT STEPS:")
|
|
print("="*70)
|
|
print("1. Open your browser and go to: http://localhost:8000/surveys/templates/")
|
|
print(f"2. Find and click on: {template.name}")
|
|
print("3. You'll see the survey builder with all questions")
|
|
print("4. The preview panel will show how each question type appears to patients")
|
|
print("\nPreview Guide:")
|
|
print(" ✓ Text: Shows as a textarea input")
|
|
print(" ✓ Rating: Shows 5 radio buttons (Poor to Excellent)")
|
|
print(" ✓ Single Choice: Shows radio buttons, only one can be selected")
|
|
print(" ✓ Multiple Choice: Shows checkboxes, multiple can be selected")
|
|
print("\nBilingual Support:")
|
|
print(" - All questions have both English and Arabic text")
|
|
print(" - Preview will show Arabic if you switch language")
|
|
print("="*70)
|
|
|
|
if __name__ == '__main__':
|
|
create_demo_survey()
|