296 lines
10 KiB
Python
296 lines
10 KiB
Python
"""
|
|
Django admin configuration for ot app.
|
|
"""
|
|
|
|
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from .models import (
|
|
OTConsult,
|
|
OTDifficultyArea,
|
|
OTMilestone,
|
|
OTSelfHelpSkill,
|
|
OTInfantBehavior,
|
|
OTCurrentBehavior,
|
|
OTSession,
|
|
OTTargetSkill,
|
|
OTProgressReport,
|
|
OTScoringConfig,
|
|
)
|
|
|
|
|
|
class OTDifficultyAreaInline(admin.TabularInline):
|
|
"""Inline admin for difficulty areas."""
|
|
model = OTDifficultyArea
|
|
extra = 1
|
|
max_num = 3
|
|
|
|
|
|
class OTMilestoneInline(admin.TabularInline):
|
|
"""Inline admin for milestones."""
|
|
model = OTMilestone
|
|
extra = 0
|
|
|
|
|
|
class OTSelfHelpSkillInline(admin.TabularInline):
|
|
"""Inline admin for self-help skills."""
|
|
model = OTSelfHelpSkill
|
|
extra = 0
|
|
|
|
|
|
class OTInfantBehaviorInline(admin.TabularInline):
|
|
"""Inline admin for infant behaviors."""
|
|
model = OTInfantBehavior
|
|
extra = 0
|
|
|
|
|
|
class OTCurrentBehaviorInline(admin.TabularInline):
|
|
"""Inline admin for current behaviors."""
|
|
model = OTCurrentBehavior
|
|
extra = 0
|
|
|
|
|
|
@admin.register(OTConsult)
|
|
class OTConsultAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTConsult model."""
|
|
|
|
list_display = ['patient', 'consultation_date', 'provider', 'referral_reason',
|
|
'total_score', 'score_interpretation', 'signed_by', 'signed_at', 'tenant']
|
|
list_filter = ['consultation_date', 'referral_reason', 'recommendation', 'tenant', 'signed_at']
|
|
search_fields = ['patient__mrn', 'patient__first_name_en', 'patient__last_name_en']
|
|
readonly_fields = ['id', 'self_help_score', 'behavior_score', 'developmental_score',
|
|
'eating_score', 'total_score', 'score_interpretation',
|
|
'created_at', 'updated_at']
|
|
date_hierarchy = 'consultation_date'
|
|
inlines = [OTDifficultyAreaInline, OTMilestoneInline, OTSelfHelpSkillInline,
|
|
OTInfantBehaviorInline, OTCurrentBehaviorInline]
|
|
|
|
fieldsets = (
|
|
(_('Patient & Provider'), {
|
|
'fields': ('patient', 'tenant', 'consultation_date', 'provider', 'appointment')
|
|
}),
|
|
(_('Referral Information'), {
|
|
'fields': ('referral_reason',)
|
|
}),
|
|
(_('Motor Learning & Regression'), {
|
|
'fields': ('motor_learning_difficulty', 'motor_learning_details',
|
|
'motor_skill_regression', 'regression_details')
|
|
}),
|
|
(_('Eating/Feeding'), {
|
|
'fields': ('eats_healthy_variety', 'eats_variety_textures',
|
|
'participates_family_meals', 'eating_comments')
|
|
}),
|
|
(_('Behavior Comments'), {
|
|
'fields': ('infant_behavior_comments', 'current_behavior_comments')
|
|
}),
|
|
(_('Recommendations'), {
|
|
'fields': ('recommendation', 'recommendation_notes')
|
|
}),
|
|
(_('Scoring Results'), {
|
|
'fields': ('self_help_score', 'behavior_score', 'developmental_score',
|
|
'eating_score', 'total_score', 'score_interpretation'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Clinician Signature'), {
|
|
'fields': ('clinician_name', 'clinician_signature', 'signed_by', 'signed_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('id', 'created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
actions = ['calculate_scores_action']
|
|
|
|
def calculate_scores_action(self, request, queryset):
|
|
"""Admin action to recalculate scores for selected consultations."""
|
|
count = 0
|
|
for consult in queryset:
|
|
consult.calculate_scores()
|
|
consult.save()
|
|
count += 1
|
|
self.message_user(request, f'Successfully recalculated scores for {count} consultation(s).')
|
|
calculate_scores_action.short_description = _('Recalculate scores')
|
|
|
|
|
|
@admin.register(OTDifficultyArea)
|
|
class OTDifficultyAreaAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTDifficultyArea model."""
|
|
|
|
list_display = ['consult', 'area', 'details', 'order']
|
|
list_filter = ['area', 'consult__consultation_date']
|
|
search_fields = ['consult__patient__mrn', 'details']
|
|
|
|
|
|
@admin.register(OTMilestone)
|
|
class OTMilestoneAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTMilestone model."""
|
|
|
|
list_display = ['consult', 'milestone', 'age_achieved', 'is_required']
|
|
list_filter = ['milestone', 'is_required', 'consult__consultation_date']
|
|
search_fields = ['consult__patient__mrn', 'age_achieved']
|
|
|
|
|
|
@admin.register(OTSelfHelpSkill)
|
|
class OTSelfHelpSkillAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTSelfHelpSkill model."""
|
|
|
|
list_display = ['consult', 'age_range', 'skill_name', 'response', 'comments']
|
|
list_filter = ['age_range', 'response', 'consult__consultation_date']
|
|
search_fields = ['consult__patient__mrn', 'skill_name', 'comments']
|
|
|
|
|
|
@admin.register(OTInfantBehavior)
|
|
class OTInfantBehaviorAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTInfantBehavior model."""
|
|
|
|
list_display = ['consult', 'behavior', 'response']
|
|
list_filter = ['behavior', 'response', 'consult__consultation_date']
|
|
search_fields = ['consult__patient__mrn']
|
|
|
|
|
|
@admin.register(OTCurrentBehavior)
|
|
class OTCurrentBehaviorAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTCurrentBehavior model."""
|
|
|
|
list_display = ['consult', 'behavior', 'response']
|
|
list_filter = ['behavior', 'response', 'consult__consultation_date']
|
|
search_fields = ['consult__patient__mrn']
|
|
|
|
|
|
@admin.register(OTSession)
|
|
class OTSessionAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTSession model."""
|
|
|
|
list_display = ['patient', 'session_date', 'session_type', 'provider', 'cooperative_level_display',
|
|
'signed_by', 'tenant']
|
|
list_filter = ['session_date', 'session_type', 'tenant', 'signed_at']
|
|
search_fields = ['patient__mrn', 'patient__first_name_en', 'patient__last_name_en']
|
|
readonly_fields = ['id', 'cooperative_level_display', 'distraction_tolerance_display',
|
|
'created_at', 'updated_at']
|
|
date_hierarchy = 'session_date'
|
|
|
|
fieldsets = (
|
|
(_('Patient & Provider'), {
|
|
'fields': ('patient', 'tenant', 'session_date', 'session_type', 'provider', 'appointment')
|
|
}),
|
|
(_('Child Behavior'), {
|
|
'fields': ('cooperative_level', 'cooperative_level_display', 'distraction_tolerance',
|
|
'distraction_tolerance_display')
|
|
}),
|
|
(_('Activities'), {
|
|
'fields': ('activities_checklist', 'activities_performed')
|
|
}),
|
|
(_('Session Notes'), {
|
|
'fields': ('observations', 'recommendations')
|
|
}),
|
|
(_('Signature'), {
|
|
'fields': ('signed_by', 'signed_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('id', 'created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
@admin.register(OTTargetSkill)
|
|
class OTTargetSkillAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTTargetSkill model."""
|
|
|
|
list_display = ['session', 'skill_name', 'score', 'score_percentage', 'achievement_level', 'order']
|
|
list_filter = ['session__patient', 'session__session_date']
|
|
search_fields = ['skill_name', 'session__patient__mrn']
|
|
readonly_fields = ['id', 'score_percentage', 'achievement_level']
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('session', 'skill_name', 'order')
|
|
}),
|
|
(_('Scoring'), {
|
|
'fields': ('score', 'score_percentage', 'achievement_level')
|
|
}),
|
|
(_('Notes'), {
|
|
'fields': ('notes',),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('id',),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
@admin.register(OTProgressReport)
|
|
class OTProgressReportAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTProgressReport model."""
|
|
|
|
list_display = ['patient', 'report_date', 'provider', 'sessions_attended', 'attendance_rate',
|
|
'signed_by', 'tenant']
|
|
list_filter = ['report_date', 'tenant', 'signed_at']
|
|
search_fields = ['patient__mrn', 'patient__first_name_en', 'patient__last_name_en']
|
|
readonly_fields = ['id', 'attendance_rate', 'created_at', 'updated_at']
|
|
date_hierarchy = 'report_date'
|
|
|
|
fieldsets = (
|
|
(_('Patient & Provider'), {
|
|
'fields': ('patient', 'tenant', 'report_date', 'provider')
|
|
}),
|
|
(_('Attendance'), {
|
|
'fields': ('sessions_scheduled', 'sessions_attended', 'attendance_rate')
|
|
}),
|
|
(_('Progress Summary'), {
|
|
'fields': ('goals_progress', 'overall_progress')
|
|
}),
|
|
(_('Recommendations'), {
|
|
'fields': ('recommendations', 'continue_treatment')
|
|
}),
|
|
(_('Signature'), {
|
|
'fields': ('signed_by', 'signed_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('id', 'created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
@admin.register(OTScoringConfig)
|
|
class OTScoringConfigAdmin(admin.ModelAdmin):
|
|
"""Admin interface for OTScoringConfig model."""
|
|
|
|
list_display = ['name', 'is_active', 'total_max_score', 'immediate_attention_threshold',
|
|
'moderate_difficulty_threshold', 'tenant']
|
|
list_filter = ['is_active', 'tenant', 'created_at']
|
|
search_fields = ['name']
|
|
readonly_fields = ['id', 'total_max_score', 'created_at', 'updated_at']
|
|
|
|
fieldsets = (
|
|
(_('Configuration'), {
|
|
'fields': ('tenant', 'name', 'is_active')
|
|
}),
|
|
(_('Maximum Scores'), {
|
|
'fields': ('self_help_max', 'behavior_max', 'developmental_max', 'eating_max',
|
|
'total_max_score')
|
|
}),
|
|
(_('Thresholds'), {
|
|
'fields': ('immediate_attention_threshold', 'moderate_difficulty_threshold')
|
|
}),
|
|
(_('Labels'), {
|
|
'fields': ('immediate_attention_label', 'moderate_difficulty_label',
|
|
'age_appropriate_label')
|
|
}),
|
|
(_('Recommendation Templates'), {
|
|
'fields': ('immediate_attention_recommendation', 'moderate_difficulty_recommendation',
|
|
'age_appropriate_recommendation'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('id', 'created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|