6.5 KiB
6.5 KiB
Organization Model Implementation
Overview
The Organization model has been added to create a hierarchical structure for healthcare facilities. This allows multiple hospitals to be grouped under a parent organization.
Model Structure
Organization (Top-level)
├── Hospital (Branch)
│ ├── Department
│ │ ├── Physician
│ │ └── Employee
│ └── Patient
Organization Model
Fields
name(CharField) - Organization name (English)name_ar(CharField) - Organization name (Arabic)code(CharField) - Unique organization code (indexed)address(TextField) - Organization addresscity(CharField) - Organization cityphone(CharField) - Contact phone numberemail(EmailField) - Contact email addresswebsite(URLField) - Organization website URLstatus(CharField) - Active/Inactive status (from StatusChoices)logo(ImageField) - Organization logo imagelicense_number(CharField) - Organization license numbercreated_at(DateTimeField) - Auto-populated creation timestampupdated_at(DateTimeField) - Auto-populated update timestamp
Relationships
hospitals(One-to-Many) - Related name for Hospital model
Hospital Model Changes
New Field
organization(ForeignKey to Organization) - Parent organization (nullable for backward compatibility)
Backward Compatibility
The organization field is nullable to ensure existing hospitals without an organization continue to work.
Database Migration
Migration File
apps/organizations/migrations/0002_organization_hospital_organization.py
Changes Made
- Created
Organizationmodel table - Added
organizationforeign key toHospitaltable - Migration applied successfully
Admin Interface
OrganizationAdmin
- List display: name, code, city, status, created_at
- Filters: status, city
- Search: name, name_ar, code, license_number
- Ordering: by name
- Fieldsets: Basic info, Contact, Details, Metadata
HospitalAdmin Updates
- Added
organizationfield to form - Added autocomplete for organization selection
- Added
organization_nameto list display (read-only)
Serializers
OrganizationSerializer
- Includes
hospitals_countmethod field - Fields: id, name, name_ar, code, address, city, phone, email, website, status, license_number, logo, hospitals_count, created_at, updated_at
HospitalSerializer Updates
- Added
organizationfield - Added
organization_name(read-only, from organization.name) - Added
departments_countmethod field - Fields: id, organization, organization_name, name, name_ar, code, address, city, phone, email, status, license_number, capacity, departments_count, created_at, updated_at
Data Migration
Management Command
python manage.py create_default_organization
Options
--name- Organization name (default: "Default Healthcare Organization")--code- Organization code (default: "DEFAULT")--force- Force reassignment of all hospitals--dry-run- Preview changes without applying
Example Usage
# Create default organization
python manage.py create_default_organization
# Create with custom name and code
python manage.py create_default_organization --name="My Hospital Group" --code="MHG"
# Preview changes
python manage.py create_default_organization --dry-run
# Force reassign all hospitals
python manage.py create_default_organization --force
Current Data
- Organization: King Faisal Specialist Hospital Group (KFSHG)
- Hospital: Alhammadi Hospital (HH)
- Departments: 10
- Status: All hospitals assigned to organization
Verification
Verification Script
Run python verify_organization.py to check:
- Total organizations
- Hospitals per organization
- Departments per hospital
- Orphaned hospitals (without organization)
Expected Output
============================================================
Organization Verification
============================================================
Total Organizations: 1
Organization: King Faisal Specialist Hospital Group (KFSHG)
Status: active
Hospitals: 1
- Alhammadi Hospital (Code: HH)
Departments: 10
✓ All hospitals have organizations assigned
============================================================
Impact on Other Apps
Complaints App
- Hospital selection in forms now shows organization context
- Complaints can be filtered by organization via hospital relationship
- No breaking changes - existing functionality preserved
Surveys App
- Surveys can be filtered by organization
- Patient relationships work through hospital → organization
Journey Engine
- Journeys can be organized by organization
- Department routing can consider organization context
Call Center
- Agent dashboard can filter by organization
- Call routing can consider organization hierarchy
Analytics App
- Reports can be aggregated at organization level
- Multi-hospital analytics available
Future Enhancements
Recommended Features
-
Organization-Level Permissions
- Role-based access control at organization level
- Organization admins managing their hospitals
-
Organization Settings
- Custom branding per organization
- Organization-specific policies and procedures
- Organization-level notification settings
-
Organization Dashboard
- Overview of all hospitals in organization
- Aggregate metrics and KPIs
- Cross-hospital comparison
-
Multi-Organization Support
- Users can belong to multiple organizations
- Organization switching in UI
- Organization-scoped data views
-
Organization Hierarchy
- Sub-organizations (regional, national)
- Multi-level organization structure
- Parent/child organization relationships
-
Organization Templates
- Standardized hospital templates
- Quick setup of new hospitals
- Consistent policies across organization
Notes
- All models inherit from
UUIDModelandTimeStampedModelfor consistency - Bilingual support (English/Arabic) maintained throughout
- Status management follows existing
StatusChoicespattern - Backward compatible with existing data
- No breaking changes to existing functionality
References
- Model file:
apps/organizations/models.py - Admin file:
apps/organizations/admin.py - Serializer file:
apps/organizations/serializers.py - Migration:
apps/organizations/migrations/0002_organization_hospital_organization.py - Management command:
apps/organizations/management/commands/create_default_organization.py