78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify the survey mapping fix works correctly.
|
|
This simulates what the JavaScript will send to the API.
|
|
"""
|
|
|
|
import os
|
|
import django
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
django.setup()
|
|
|
|
from apps.integrations.models import SurveyTemplateMapping
|
|
from apps.organizations.models import Hospital
|
|
from apps.surveys.models import SurveyTemplate
|
|
|
|
print("=== Testing Survey Mapping Fix ===\n")
|
|
|
|
# Get a hospital and survey template
|
|
hospital = Hospital.objects.first()
|
|
survey_template = SurveyTemplate.objects.filter(hospital=hospital).first()
|
|
|
|
if not hospital:
|
|
print("ERROR: No hospitals found in database")
|
|
exit(1)
|
|
|
|
if not survey_template:
|
|
print("ERROR: No survey templates found for hospital")
|
|
exit(1)
|
|
|
|
print(f"Hospital ID: {hospital.id}")
|
|
print(f"Hospital ID type: {type(hospital.id)}")
|
|
print(f"Survey Template ID: {survey_template.id}")
|
|
print(f"Survey Template ID type: {type(survey_template.id)}")
|
|
|
|
# Simulate what the JavaScript will send (without parseInt)
|
|
print("\n=== Simulating JavaScript data (AFTER fix) ===")
|
|
data_correct = {
|
|
'hospital': str(hospital.id),
|
|
'survey_template': str(survey_template.id),
|
|
'patient_type': '2',
|
|
'is_active': True
|
|
}
|
|
print(f"Data to send: {data_correct}")
|
|
|
|
# Simulate what the JavaScript was sending (with parseInt - the bug)
|
|
print("\n=== Simulating JavaScript data (BEFORE fix - with bug) ===")
|
|
# This simulates parseInt(UUID) which returns NaN in real browsers,
|
|
# but in some cases might parse part of the string
|
|
try:
|
|
data_broken = {
|
|
'hospital': int(hospital.id),
|
|
'survey_template': int(survey_template.id),
|
|
'patient_type': '2',
|
|
'is_active': True
|
|
}
|
|
print(f"Data to send: {data_broken}")
|
|
except ValueError as e:
|
|
print(f"ERROR: parseInt(UUID) fails with: {e}")
|
|
print("This is what was causing the validation error!")
|
|
|
|
# Test creating a mapping with correct data
|
|
print("\n=== Testing with correct UUID strings ===")
|
|
try:
|
|
mapping = SurveyTemplateMapping(
|
|
hospital=hospital,
|
|
patient_type='2',
|
|
survey_template=survey_template,
|
|
is_active=True
|
|
)
|
|
mapping.save()
|
|
print(f"✓ SUCCESS: Created mapping with ID: {mapping.id}")
|
|
mapping.delete() # Clean up
|
|
except Exception as e:
|
|
print(f"✗ ERROR: {e}")
|
|
|
|
print("\n=== Fix Verification Complete ===")
|
|
print("The fix removes parseInt() from the JavaScript, allowing UUIDs to be sent as strings.") |