Source code for nlpmed_portal.annotations.admin
# SPDX-FileCopyrightText: Copyright (C) 2026 Omid Jafari <omidjafari.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import nested_admin
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from nlpmed_portal.annotations.models import Adjudication
from nlpmed_portal.annotations.models import ImportJob
from nlpmed_portal.annotations.models import Lab
from nlpmed_portal.annotations.models import LabelCategory
from nlpmed_portal.annotations.models import LabelValue
from nlpmed_portal.annotations.models import NERAnnotation
from nlpmed_portal.annotations.models import Note
from nlpmed_portal.annotations.models import Patient
from nlpmed_portal.annotations.models import PatientAnnotation
from nlpmed_portal.annotations.models import Project
from nlpmed_portal.annotations.models import ProjectMembership
from nlpmed_portal.annotations.models import Section
from nlpmed_portal.annotations.models import Sentence
from nlpmed_portal.annotations.models import Task
from nlpmed_portal.nlp.admin import NLPSettingInline
[docs]
class LabelValueInline(nested_admin.NestedTabularInline):
model = LabelValue
extra = 1
[docs]
class LabelCategoryInline(nested_admin.NestedTabularInline):
model = LabelCategory
extra = 1
inlines = [LabelValueInline]
[docs]
@admin.register(Project)
class ProjectAdmin(nested_admin.NestedModelAdmin):
inlines = [LabelCategoryInline, NLPSettingInline]
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(Patient)
class PatientAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
class SentenceInline(nested_admin.NestedTabularInline):
model = Sentence
extra = 1
[docs]
class SectionInline(nested_admin.NestedTabularInline):
model = Section
extra = 1
inlines = [SentenceInline]
[docs]
@admin.register(Note)
class NoteAdmin(nested_admin.NestedModelAdmin):
inlines = [SectionInline]
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(Lab)
class LabAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(Section)
class SectionAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(PatientAnnotation)
class PatientAnnotationAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(Adjudication)
class AdjudicationAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(ProjectMembership)
class ProjectMembershipAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(Task)
class TaskAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(ImportJob)
class ImportJobAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
[docs]
@admin.register(NERAnnotation)
class NERAnnotationAdmin(SimpleHistoryAdmin):
readonly_fields = ("created_at", "updated_at")
admin.site.register(LabelCategory, SimpleHistoryAdmin)
admin.site.register(LabelValue, SimpleHistoryAdmin)
admin.site.register(Sentence, SimpleHistoryAdmin)