128 lines
4.2 KiB
Python
128 lines
4.2 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
from .models import DocumentTemplate, ClinicalNote, NoteAddendum, NoteAuditLog
|
|
|
|
|
|
@admin.register(DocumentTemplate)
|
|
class DocumentTemplateAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'category', 'is_active', 'created_by', 'created_at']
|
|
list_filter = ['category', 'is_active', 'created_at']
|
|
search_fields = ['name', 'description', 'content']
|
|
readonly_fields = ['created_at', 'updated_at', 'created_by']
|
|
|
|
fieldsets = (
|
|
(_('Template Information'), {
|
|
'fields': ('name', 'category', 'description', 'is_active')
|
|
}),
|
|
(_('Content'), {
|
|
'fields': ('content',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('created_by', 'created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
if not change: # If creating new object
|
|
obj.created_by = request.user
|
|
super().save_model(request, obj, form, change)
|
|
|
|
|
|
class NoteAddendumInline(admin.TabularInline):
|
|
model = NoteAddendum
|
|
extra = 0
|
|
readonly_fields = ['author', 'created_at']
|
|
fields = ['reason', 'content', 'author', 'created_at']
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
return False
|
|
|
|
|
|
class NoteAuditLogInline(admin.TabularInline):
|
|
model = NoteAuditLog
|
|
extra = 0
|
|
readonly_fields = ['action', 'user', 'timestamp', 'ip_address', 'changes']
|
|
fields = ['action', 'user', 'timestamp', 'ip_address']
|
|
|
|
def has_add_permission(self, request, obj=None):
|
|
return False
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
return False
|
|
|
|
|
|
@admin.register(ClinicalNote)
|
|
class ClinicalNoteAdmin(admin.ModelAdmin):
|
|
list_display = ['title', 'patient', 'status', 'author', 'created_at', 'finalized_at']
|
|
list_filter = ['status', 'created_at', 'finalized_at']
|
|
search_fields = ['title', 'content', 'patient__first_name', 'patient__last_name', 'patient__patient_id']
|
|
readonly_fields = ['author', 'created_at', 'updated_at', 'finalized_at', 'finalized_by', 'version']
|
|
inlines = [NoteAddendumInline, NoteAuditLogInline]
|
|
|
|
fieldsets = (
|
|
(_('Note Information'), {
|
|
'fields': ('patient', 'template', 'title', 'status')
|
|
}),
|
|
(_('Content'), {
|
|
'fields': ('content',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('author', 'created_at', 'updated_at', 'version'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Finalization'), {
|
|
'fields': ('finalized_at', 'finalized_by'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Versioning'), {
|
|
'fields': ('parent_note',),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
if not change: # If creating new object
|
|
obj.author = request.user
|
|
super().save_model(request, obj, form, change)
|
|
|
|
|
|
@admin.register(NoteAddendum)
|
|
class NoteAddendumAdmin(admin.ModelAdmin):
|
|
list_display = ['note', 'reason', 'author', 'created_at']
|
|
list_filter = ['created_at']
|
|
search_fields = ['note__title', 'reason', 'content']
|
|
readonly_fields = ['author', 'created_at']
|
|
|
|
fieldsets = (
|
|
(_('Addendum Information'), {
|
|
'fields': ('note', 'reason')
|
|
}),
|
|
(_('Content'), {
|
|
'fields': ('content',)
|
|
}),
|
|
(_('Metadata'), {
|
|
'fields': ('author', 'created_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
if not change: # If creating new object
|
|
obj.author = request.user
|
|
super().save_model(request, obj, form, change)
|
|
|
|
|
|
@admin.register(NoteAuditLog)
|
|
class NoteAuditLogAdmin(admin.ModelAdmin):
|
|
list_display = ['note', 'action', 'user', 'timestamp', 'ip_address']
|
|
list_filter = ['action', 'timestamp']
|
|
search_fields = ['note__title', 'user__username']
|
|
readonly_fields = ['note', 'action', 'user', 'timestamp', 'ip_address', 'changes']
|
|
|
|
def has_add_permission(self, request):
|
|
return False
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
return False
|