7.3 KiB
Simplified PX Sources Implementation Summary
Overview
Successfully simplified the PX Sources model to only 4 fields as requested:
name_en- Source name in Englishname_ar- Source name in Arabicdescription- Detailed descriptionis_active- Active status
Changes Made
1. Simplified PXSource Model
File: apps/px_sources/models.py
Removed Fields:
code- Unique identifier (no longer needed)description_en,description_ar- Replaced with singledescriptionfieldsource_type- Complaint/inquiry type filter (no longer needed)order- Display order (no longer needed)metadata- JSON metadata (no longer needed)icon_class- CSS icon class (already removed)color_code- Color code (already removed)
Kept Fields:
name_en- Source name in Englishname_ar- Source name in Arabic (blank=True)description- Single description field (blank=True)is_active- Boolean status field
Updated Methods:
__str__()- Now returnsname_eninstead ofcodeget_localized_name()- Simplified to handle only name fieldsget_localized_description()- Simplified to return single descriptionget_active_sources()- Removed source_type filteringget_by_code()- Removed this classmethod entirely
Meta Updates:
- Changed ordering from
['order', 'name_en']to['name_en'] - Updated indexes to only include
['is_active', 'name_en'] - Removed unique constraints on code
2. Updated UI Views
File: apps/px_sources/ui_views.py
Removed References:
- All references to
code,source_type,order - All references to
description_en,description_ar - Removed
SourceTypeimport
Updated Functions:
source_list()- Removed source_type filter, updated search to include descriptionsource_create()- Simplified to only handle 4 fieldssource_edit()- Simplified to only handle 4 fieldsajax_search_sources()- Updated search fields and resultsajax_source_choices()- Removed source_type parameter and fields
3. Updated Serializers
File: apps/px_sources/serializers.py
Removed References:
- All references to
code,source_type,order,metadata - All references to
description_en,description_ar
Updated Serializers:
PXSourceSerializer- Fields:id,name_en,name_ar,description,is_active, timestampsPXSourceListSerializer- Fields:id,name_en,name_ar,is_activePXSourceDetailSerializer- Same as PXSourceSerializer plus usage_countPXSourceChoiceSerializer- Simplified to onlyidandname
4. Updated Admin
File: apps/px_sources/admin.py
Removed Fieldsets:
- Display Options section
- Configuration section (source_type, order)
- Metadata section
Updated Fieldsets:
- Basic Information:
name_en,name_ar - Description:
description - Status:
is_active - Metadata:
created_at,updated_at(collapsed)
Updated List Display:
- Shows
name_en,name_ar,is_active_badge,created_at - Removed
code,source_type_badge,order
Updated Filters:
- Only filters by
is_activeandcreated_at - Removed
source_typefilter
5. Updated REST API Views
File: apps/px_sources/views.py
Removed References:
SourceTypeimportget_by_code()method usagesource_typefilterset_fieldcodein search_fields and ordering_fields
Updated ViewSet:
filterset_fields:['is_active']search_fields:['name_en', 'name_ar', 'description']ordering_fields:['name_en', 'created_at']ordering:['name_en']
Removed Actions:
types()- No longer needed since source_type removed
Updated Actions:
choices()- Removed source_type parameteractivate()/deactivate()- Updated log messagesusage()- Kept for statistics (uses SourceUsage model)
6. Updated Call Center Views
File: apps/callcenter/ui_views.py
Changes:
create_complaint()- Changed fromPXSource.get_by_code('CALL_CENTER')toPXSource.objects.filter(is_active=True).first()complaint_list()- Removed filter by call_center_source, now shows all complaints
7. Migration
File: apps/px_sources/migrations/0004_simplify_pxsource_model.py
Changes:
- Removed fields:
code,description_ar,description_en,metadata,order,source_type - Added field:
description - Removed indexes:
code,is_active,source_type,order - Added index:
is_active,name_en
Data Migration
Important: The existing PXSource records from migration 0003 will be updated:
description_envalues will be copied todescriptiondescription_arvalues will be lost (consolidated into single description)code,source_type,order,metadatawill be dropped
Benefits of Simplification
1. Cleaner Code
- Fewer fields to manage
- Simpler model structure
- Easier to understand and maintain
2. Flexible Usage
- Sources can be used for any purpose (complaints, inquiries, feedback, etc.)
- No type restrictions
- Simpler filtering (just by active status)
3. Reduced Complexity
- No need for code field management
- No source_type categorization
- Simpler ordering (alphabetical by name)
4. User-Friendly
- Easier to create new sources (only 4 fields)
- Simpler forms
- Faster data entry
Usage Examples
Creating a Source:
from apps.px_sources.models import PXSource
source = PXSource.objects.create(
name_en="Patient Portal",
name_ar="بوابة المرضى",
description="Feedback submitted through the patient portal",
is_active=True
)
Getting Active Sources:
from apps.px_sources.models import PXSource
# Get all active sources
sources = PXSource.get_active_sources()
# Or use queryset
sources = PXSource.objects.filter(is_active=True)
Filtering Complaints:
# Simplified - no longer filter by specific source
complaints = Complaint.objects.filter(
source__is_active=True
)
Call Center Usage:
from apps.px_sources.models import PXSource
# Get first active source for call center
call_center_source = PXSource.objects.filter(is_active=True).first()
Files Modified
apps/px_sources/models.py- Simplified model structureapps/px_sources/ui_views.py- Updated views for simplified modelapps/px_sources/serializers.py- Updated serializersapps/px_sources/admin.py- Updated admin interfaceapps/px_sources/views.py- Updated REST API viewsapps/callcenter/ui_views.py- Updated call center viewsapps/px_sources/migrations/0004_simplify_pxsource_model.py- New migration
Testing Performed
✅ Migration created successfully ✅ Migration applied successfully ✅ No syntax errors in updated files ✅ All import errors resolved
Recommendations
- Review Existing Data: Check if any existing PXSource records have important data in removed fields
- Update Templates: Review templates that display source information
- Update Forms: Review forms that create/edit PXSource records
- Test Call Center: Test call center complaint creation with new simplified model
- Update Documentation: Update API docs and user guides
Rollback Plan
If needed, you can rollback to the previous version:
python manage.py migrate px_sources 0003
Then revert the code changes to restore the full model with all fields.