HH/update_inpatient_post_discharge_survey.py

106 lines
2.9 KiB
Python

#!/usr/bin/env python
"""
Update Inpatient Post-Discharge Survey to add satisfaction options.
This converts text questions to multiple choice with satisfaction levels.
"""
import os
import sys
import django
# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
django.setup()
from apps.surveys.models import SurveyTemplate, SurveyQuestion
print("=" * 70)
print("UPDATING INPATIENT POST-DISCHARGE SURVEY")
print("=" * 70)
# Get the survey
survey = SurveyTemplate.objects.get(name='Inpatient Post-Discharge Survey')
print(f"\nSurvey: {survey.name}")
print(f"ID: {survey.id}")
# Define the satisfaction options with bilingual labels
SATISFACTION_CHOICES = [
{
'value': '1',
'label': 'Very Unsatisfied',
'label_ar': 'غير راضٍ جداً'
},
{
'value': '2',
'label': 'Poor',
'label_ar': 'ضعيف'
},
{
'value': '3',
'label': 'Neutral',
'label_ar': 'محايد'
},
{
'value': '4',
'label': 'Good',
'label_ar': 'جيد'
},
{
'value': '5',
'label': 'Very Satisfied',
'label_ar': 'راضٍ جداً'
}
]
# Questions to update (convert from text to multiple_choice)
questions_to_update = {
1: "How satisfied were you with the nursing care?",
2: "How satisfied were you with the doctor's care?",
3: "How clean was your room?",
4: "How satisfied were you with the food quality?",
5: "How well were you informed about your treatment?"
}
updated_count = 0
for order, question_text in questions_to_update.items():
try:
question = SurveyQuestion.objects.get(
survey_template=survey,
order=order
)
print(f"\n--- Question {order} ---")
print(f"Current Type: {question.question_type}")
print(f"Question: {question.text}")
if question.question_type == 'text':
# Update the question
question.question_type = 'multiple_choice'
question.choices_json = SATISFACTION_CHOICES
question.save()
print(f"✓ Updated to multiple_choice with satisfaction options")
updated_count += 1
else:
print(f"⚠️ Already {question.question_type} - skipping")
except SurveyQuestion.DoesNotExist:
print(f"\n⚠️ Question {order} not found")
print("\n" + "=" * 70)
print("UPDATE COMPLETE")
print("=" * 70)
print(f"Updated {updated_count} questions")
print(f"Survey: {survey.name}")
# Show updated questions
print("\n--- Updated Questions ---")
questions = survey.questions.filter(question_type='multiple_choice').order_by('order')
for q in questions:
print(f"\nQ{q.order}: {q.text}")
print(f" Type: {q.question_type}")
print(f" Options: {len(q.choices_json)} satisfaction levels")
print("\n" + "=" * 70)