from django.urls import path, include
from django.views.generic import RedirectView, TemplateView


from atlas.models import CaseCollection, Condition, Finding, Presentation, Structure, Subspecialty, Procedure, Series
from . import views

app_name = "atlas"

urlpatterns = [
    path("", views.index, name="index"),
    path("help/", TemplateView.as_view(template_name="atlas/help.html"), name="help"),
    path("messages", views.user_messages_inbox, name="user_messages_inbox"),
    path(
        "create/",
        RedirectView.as_view(pattern_name="atlas:case_create", permanent=False),
        name="create",
    ),
    path(
        "self_review/<int:user_exam_id>/<int:case_id>/add",
        views.AddSelfReview.as_view(),
        name="add_self_review",
    ),
    path(
        "self_review/<int:user_exam_id>/<int:case_id>/update/<int:pk>",
        views.SelfReviewUpdate.as_view(),
        name="self_review_update",
    ),
    path(
        "self_review/<int:user_exam_id>/<int:case_id>/view/<int:pk>",
        views.SelfReviewDetail.as_view(),
        name="self_review_detail",
    ),
    path(
        "self_review/<int:user_exam_id>/<int:case_id>/delete/<int:pk>",
        views.SelfReviewDelete.as_view(),
        name="self_review_delete",
    ),
    path("author/<int:pk>/", views.author_detail, name="author_detail"),
    path("author/", views.author_list, name="author_list"),
    path("case/", views.CaseView.as_view(), name="case_view"),
    path("case/admin-overview", views.case_admin_overview, name="case_admin_overview"),
    path(
        "case/admin-overview/recent",
        views.case_admin_recent_cases_partial,
        name="case_admin_recent_cases_partial",
    ),
    path(
        "case/admin-overview/largest",
        views.case_admin_largest_cases_partial,
        name="case_admin_largest_cases_partial",
    ),
    path("collection/<int:collection_id>/add_case", views.add_case_to_collection, name="add_case_to_collection"),
    path("collection/case_search", views.case_search, name="case_search"),
    path("collection/", views.CollectionView.as_view(), name="collection_view"),
    path("collection/user", views.user_collections, name="user_collections"),
    path("collection/related", views.user_related_collections, name="user_related_collections"),
    path("uploads", views.user_uploads, name="user_uploads"),
    path("uploads/<int:user_pk>/user", views.other_user_uploads, name="other_user_uploads"),
    path("uploads/all", views.all_uploads, name="all_uploads"),
    path("uploads/hash-search", views.uploads_hash_search, name="uploads_hash_search"),
    path("uploads/new", views.new_uploads, name="new_uploads"),
    path("uploads/import", views.uploads_import_htmx, name="uploads_import_htmx"),
    path("uploads/import/case/<int:case_id>", views.uploads_import_htmx, name="uploads_import_case_htmx"),
    path("uploads/import/case-series", views.uploads_import_case_series_htmx, name="uploads_import_case_series_htmx"),
    path("uploads/case/<int:case_id>", views.user_uploads, name="user_uploads_case"),
    path("uploads/<int:user_pk>/user/case/<int:case_id>", views.other_user_uploads, name="other_user_uploads_case"),
    path("uploads/series_id/<str:series_instance_uid>", views.user_uploads_series, name="user_uploads_series"),
    path("resource/", views.ResourceView.as_view(), name="resource_view"),
    path("resource/<int:pk>/", views.resource_detail, name="resource_detail"),
    path("resource/<int:pk>/view", views.resource_view, name="resource_view"),
    path("resource/<int:pk>/update", views.ResourceUpdate.as_view(), name="resource_update"),
    path("resource/<int:pk>/delete", views.ResourceDelete.as_view(), name="resource_delete"),
        path("resource-search-panel/", views.resource_search_panel, name="resource_search_panel"),
    path("resource-search-widget/", views.resource_search_widget, name="resource_search_widget"),

    path(
        "resource/create",
        views.ResourceCreate.as_view(),
        name="resource_create",
    ),
    path(
        "collection/create",
        views.CaseCollectionCreate.as_view(),
        name="exam_create",
    ),
    path("collection/<int:exam_id>/clone", views.CollectionClone.as_view(), name="exam_clone"),
    path(
        "collection/<int:pk>/delete",
        views.CaseCollectionDelete.as_view(),
        name="exam_deleted",
    ),
    path(
        "collection/<int:pk>/update",
        views.CaseCollectionUpdate.as_view(),
        name="exam_update",
    ),
    path("collection/viewer", TemplateView.as_view(template_name="atlas/viewer.html"), name="collection_viewer"),
    path("collection/viewer_local", TemplateView.as_view(template_name="atlas/viewer_local.html"), name="collection_viewer_local"),
    path("collection/viewer_local_progressive", TemplateView.as_view(template_name="atlas/viewer_local_progressive.html"), name="collection_viewer_local_progressive"),
    path("collection/<int:pk>", views.collection_detail, name="collection_detail"),
    path("collection/<int:pk>/viva", views.collection_viva, name="collection_viva"),
    path("collection/<int:pk>/viva-local", views.collection_viva_local, name="collection_viva_local"),
    path("collection/<int:pk>/viva/<int:case_number>", views.collection_viva_case, name="collection_viva_case"),
    path("collection/<int:pk>/viva/<int:series_id>/series", views.collection_viva_series, name="collection_viva_series"),
    path(
        "collection/<int:pk>/take",
        views.collection_take_start,
        name="collection_take_start",
    ),
    path(
        "collection/<int:pk>/sync_prerequisite_users",
        views.collection_sync_prerequisite_users,
        name="collection_sync_prerequisite_users",
    ),
    path(
        "collection/<int:pk>/apply_question_template",
        views.collection_apply_question_template,
        name="collection_apply_question_template",
    ),
    path("collection/<int:pk>/authors", views.CaseCollectionAuthorUpdate.as_view(), name="collection_authors"),
    path(
        "collection/<int:pk>/toggle_results_published",
        views.GenericExamViews.exam_toggle_results_published_htmx,
        name="exam_toggle_results_published",
    ),
    path(
        "collection/<int:pk>/toggle_active",
        views.GenericExamViews.exam_toggle_active_htmx,
        name="exam_toggle_active",
    ),
    path(
        "collection/<int:exam_id>/cids",
        views.GenericExamViews.exam_cids,
        name="exam_cids",
    ),
    path(
        "collection/<int:exam_id>/cids/cid_list",
        views.GenericExamViews.exam_cids_cid_list,
        name="exam_cids_cid_list",
    ),
    path(
        "collection/<int:exam_id>/cids/user_list",
        views.GenericExamViews.exam_cids_user_list,
        name="exam_cids_user_list",
    ),
    path(
        "collection/<int:exam_id>/cids/submitted_list",
        views.GenericExamViews.exam_cids_submitted_list,
        name="exam_cids_submitted_list",
    ),
    path(
        "collection/<int:exam_id>/history",
        views.collection_history,
        name="collection_history",
    ),
    path(
        "collection/<int:pk>/cases/update",
        views.CollectionCaseUpdate.as_view(),
        name="collection_case_update",
    ),
    path(
        "collection/<int:pk>/case_jump",
        views.collection_case_jump_partial,
        name="collection_case_jump_partial",
    ),
    path(
        "collection/add_cases",
        views.add_cases_to_collection,
        name="add_cases_to_collection",
    ),
    path(
        "collection/remove_cases",
        views.remove_cases_from_collection,
        name="remove_cases_from_collection",
    ),
    path("case/set_open_access", views.set_open_access, name="set_open_access"),
    path("case/remove_open_access", views.remove_open_access, name="remove_open_access"),
    path(
        "collection/options",
        views.collection_options,
        name="collection_options",
    ),
    path(
        "collection/<int:exam_id>/history/<int:user_pk>/user",
        views.collection_history_user,
        name="collection_history_user",
    ),
    path(
        "collection/<int:exam_id>/messages/<int:user_pk>/user",
        views.collection_user_messages,
        name="collection_user_messages",
    ),
    path(
        "collection/<int:exam_id>/history/<int:cid>/ciduser",
        views.collection_history_ciduser,
        name="collection_history_ciduser",
    ),
    path(
        "collection/<int:exam_id>/messages/<int:cid>/ciduser",
        views.collection_cid_messages,
        name="collection_cid_messages",
    ),
    path(
        "collection/<int:exam_id>/attempt/<int:cid_user_exam_id>/case/<int:case_id>/review-thread",
        views.collection_case_review_thread,
        name="collection_case_review_thread",
    ),

    path(
        "collection/<int:pk>/user_status",
        views.GenericExamViews.exam_user_status,
        name="exam_user_status",
    ),
    path(
        "collection/<int:pk>/user_status/<int:cid>/cid",
        views.GenericExamViews.exam_user_status_cid,
        name="exam_user_status_cid",
    ),
    path(
        "collection/<int:pk>/user_status/<int:user_id>/user",
        views.GenericExamViews.exam_user_status_user,
        name="exam_user_status_user",
    ),
    #path("collection/<int:pk>/<int:sk>/test", views.test_form, name="test_form"),
    path(
        "collection/<int:exam_id>/cids/edit",
        views.GenericExamViews.exam_cids_edit,
        name="exam_cids_edit",
    ),
    path(
        "collection/<int:exam_id>/users/edit",
        views.GenericExamViews.exam_users_edit,
        name="exam_users_edit",
    ),
    path(
        "collection/<int:exam_id>/cid_bulk_edit",
        views.GenericExamViews.exam_cid_bulk_edit,
        name="exam_cid_bulk_edit",
    ),
    path(
        "collection/<int:exam_id>/user_bulk_edit",
        views.GenericExamViews.exam_user_bulk_edit,
        name="exam_user_bulk_edit",
    ),
    path("exam/<int:pk>/groups", views.ExamGroupsUpdate.as_view(), name="exam_groups_edit"),
    path(
        "collection/<int:exam_id>/case/<int:case_number>/details",
        views.collection_case_details,
        name="collection_case_details",
    ),

    # HTMX endpoints for attaching/detaching resources to a case
    path("case/<int:pk>/attach-resource/", views.case_attach_resource, name="case_attach_resource"),
    path("case/<int:pk>/detach-resource/", views.case_detach_resource, name="case_detach_resource"),
    path("case/<int:pk>/toggle-resource-pre/", views.case_toggle_resource_pre, name="case_toggle_resource_pre"),
    path("case/<int:pk>/create-resource-inline/", views.case_create_resource_inline, name="case_create_resource_inline"),
    # Backwards-compatible redirect from legacy case_id-style URLs
    path(
        "collection/<int:exam_id>/case/id/<int:case_id>/details",
        views.redirect_collection_case_details_by_id,
        name="collection_case_details_legacy",
    ),
    path(
        "collection/<int:exam_id>/case/<int:case_number>/questions",
        views.collection_case_questions,
        name="collection_case_questions",
    ),
    path(
        "collection/<int:exam_id>/case/id/<int:case_id>/questions",
        views.redirect_collection_case_questions_by_id,
        name="collection_case_questions_legacy",
    ),
    path(
        "collection/<int:exam_id>/case/<int:case_number>/priors",
        views.collection_case_priors,
        name="collection_case_priors",
    ),
    path(
        "collection/<int:exam_id>/case/id/<int:case_id>/priors",
        views.redirect_collection_case_priors_by_id,
        name="collection_case_priors_legacy",
    ),
    path(
        "collection/<int:exam_id>/case/<int:case_number>/dicom_json",
        views.collection_case_dicom_json,
        name="collection_case_dicom_json",
    ),
    path(
        "collection/<int:exam_id>/case/id/<int:case_id>/dicom_json",
        views.redirect_collection_case_dicom_json_by_id,
        name="collection_case_dicom_json_legacy",
    ),
    path(
        "collection/<int:exam_id>/case/<int:case_number>/dicom_json/review",
        views.collection_case_dicom_json_review,
        name="collection_case_dicom_json_review",
    ),
    # Partial endpoint to return a single case field (history/discussion/report) for modal display

    path(
        "collection/<int:exam_id>/case/id/<int:case_id>/dicom_json/review",
        views.redirect_collection_case_dicom_json_review_by_id,
        name="collection_case_dicom_json_review_legacy",
    ),
    path(
        "collection/<int:exam_id>/question_schemas",
        views.collection_question_schemas,
        name="collection_question_schemas",
    ),
    path(
        "collection/<int:exam_id>/reset_answers",
        views.collection_reset_answers,
        name="collection_reset_answers",
    ),
    path(
        "collection/<int:exam_id>/reset_answers_user_list",
        views.collection_reset_answers_user_list,
        name="collection_reset_answers_user_list",
    ),
    path(
        "collection/<int:exam_id>/<int:user_id>/reset_answers",
        views.collection_reset_answers_user,
        name="collection_reset_answers_user",
    ),
    path(
        "collection/<int:exam_id>/cid/<int:cid>/reset_answers",
        views.collection_reset_answers_ciduser,
        name="collection_reset_answers_ciduser",
    ),
    #path(
    #    "question_schemas_preset",
    #    views.question_schemas_preset,
    #    name="question_schemas_preset",
    #),
    path(
        "collection/<int:exam_id>/cids/<int:cid>/delete_answers",
        views.delete_collection_cid_answers,
        name="delete_collection_cid_answers",
    ),
    path(
        "collection/<int:exam_id>/delete_answers",
        views.delete_collection_answers,
        name="delete_collection_answers",
    ),
    path(
        "collection/<int:exam_id>/cids/edit",
        views.GenericExamViews.exam_cids_edit,
        name="exam_cids_edit",
    ),
    path(
        "collection/<int:exam_id>/users/edit",
        views.GenericExamViews.exam_users_edit,
        name="exam_users_edit",
    ),
    path(
        "collection/<int:pk>/mark",
        views.collection_mark_overview,
        name="collection_mark_overview",
    ),
    path(
        "collection/<int:pk>/mark/<int:case_number>",
        views.collection_mark_question,
        name="collection_mark_question",
    ),
    path(
        "collection/<int:pk>/scores",
        views.collection_scores_cid,
        name="collection_scores_cid",
    ),
    path(
        "collection/<int:pk>/take_overview/<int:cid>/<str:passcode>",
        views.collection_take_overview,
        name="collection_take_overview",
    ),
    path(
        "collection/<int:pk>/feedback/<int:cid>/<str:passcode>",
        views.collection_feedback_overview,
        name="collection_feedback_overview",
    ),
    path(
        "collection/<int:pk>/take_overview",
        views.collection_take_overview_user,
        name="collection_take_overview_user",
    ),
    path(
        "collection/<int:pk>/feedback",
        views.collection_feedback_overview_user,
        name="collection_feedback_overview_user",
    ),
    path(
        "collection/<int:pk>/<int:case_number>",
        views.collection_case_view,
        name="collection_case_view",
    ),
    # legacy path that used case PK; redirect to canonical case_number URL
    path(
        "collection/<int:pk>/id/<int:case_id>",
        views.redirect_collection_case_view_by_id,
        name="collection_case_view_legacy",
    ),
    path(
        "collection/<int:collection_id>/<int:case_number>/display_setup",
        views.collection_case_displaysetup,
        name="collection_case_displaysetup",
    ),
    path(
        "collection/<int:collection_id>/id/<int:case_id>/display_setup",
        views.redirect_collection_case_displaysetup_by_id,
        name="collection_case_displaysetup_legacy",
    ),
    path(
        "collection/<int:pk>/<int:case_number>/take/<int:cid>/<str:passcode>",
        views.collection_case_view_take,
        name="collection_case_view_take",
    ),
    path(
        "collection/<int:pk>/id/<int:case_id>/take/<int:cid>/<str:passcode>",
        views.redirect_collection_case_view_take_by_id,
        name="collection_case_view_take_legacy",
    ),
    path(
        "collection/<int:pk>/<int:case_number>/take/",
        views.collection_case_view_take_user,
        name="collection_case_view_take_user",
    ),
    path(
        "collection/<int:pk>/id/<int:case_id>/take/",
        views.redirect_collection_case_view_take_user_by_id,
        name="collection_case_view_take_user_legacy",
    ),
    path(
        "collection/<int:pk>/<int:case_number>/take/answers",
        views.collection_case_view_take_user_answers,
        name="collection_case_view_take_user_answers",
    ),
    path(
        "collection/<int:pk>/id/<int:case_id>/take/answers",
        views.redirect_collection_case_view_take_user_answers_by_id,
        name="collection_case_view_take_user_answers_legacy",
    ),
    path(
        "collection/<int:pk>/<int:case_number>/take/review/<int:user_pk>/",
        views.collection_case_view_take_review_user,
        name="collection_case_view_take_review_user",
    ),
    path(
        "collection/<int:pk>/json_edit",
        views.GenericExamViews.exam_json_edit,
        name="exam_json_edit",
    ),
    path(
        "collection/<int:pk>/cid_bulk_edit",
        views.GenericExamViews.exam_cid_bulk_edit,
        name="exam_cid_bulk_edit",
    ),
    path(
        "collection/<int:pk>/dicom_json",
        views.collection_dicom_json,
        name="collection_dicom_json",
    ),
    path("case/<int:pk>/authors", views.CaseAuthorUpdate.as_view(), name="case_authors"),
    path("case/<int:pk>/display_sets", views.case_displaysets, name="case_displaysets"),
    path("case/<int:pk>/display_sets/add", views.case_displaysets_add, name="case_displaysets_add"),
    path("<int:pk>/display_sets/edit", views.case_displaysets_edit, name="case_displaysets_edit"),
    path("<int:pk>/display_sets/detail", views.case_displaysets_detail, name="case_displaysets_detail"),
    path("<int:pk>/display_sets/modal", views.case_displaysets_modal, name="case_displaysets_modal"),
    path('displayset/<int:pk>/preview/', views.displayset_preview, name='displayset_preview'),
    path("<int:pk>/display_sets/delete", views.case_displaysets_delete, name="case_displaysets_delete"),
    path(
        "case/<int:pk>/dicom_json",
        views.case_dicom_json,
        name="case_dicom_json",
    ),
    path(
        "case/<int:pk>/use_dates_as_descriptions",
        views.use_dates_as_descriptions,
        name="use_dates_as_descriptions",
    ),
    path(
        "case/<int:case_pk>/collection/<int:collection_pk>/remove/",
        views.remove_case_from_collection,
        name="remove_case_from_collection",
    ),
    path(
        "case/<int:case_pk>/series_remove/",
        views.remove_selected_series_from_case,
        name="remove_selected_series_from_case",
    ),
    path(
        "case/<int:case_pk>/series_move/",
        views.move_selected_series_to_case,
        name="move_selected_series_to_case",
    ),
    path('case/<int:case_pk>/reorder_series/', views.reorder_series, name='reorder_series'),
    path(
        "series/<int:pk>/dicom_json",
        views.series_dicom_json,
        name="series_dicom_json",
    ),
    path(
        "series/<str:pk>/tags_partial",
        views.series_tags_partial,
        name="series_tags_partial",
    ),
    path('series/<int:series_pk>/add-to-case/', views.add_series_to_case, name='add_series_to_case'),
    path('series/<int:series_pk>/<int:case_pk>/remove-from-case/', views.remove_series_from_case, name='remove_series_from_case'),
    path('series/bulk-delete/', views.series_bulk_delete, name='series_bulk_delete'),
    path('series_finding/<int:finding_id>/details/', views.series_finding_details, name='series_finding_details'),
    path('series_finding/<int:pk>/preview/', views.series_finding_preview, name='series_finding_preview'),
    path('series_finding/migration-status/', views.seriesfinding_migration_status, name='seriesfinding_migration_status'),
    path("uncategorised_dicoms/", views.uncategorised_dicoms, name="uncategorised_dicoms_view"),
    path("question_schema/", views.QuestionSchemaView.as_view(), name="question_schema_overview"),
    path("question_schema/<int:pk>", views.question_schema_detail, name="question_schema_detail"),
    path("question_schema/<int:pk>/update", views.QuestionSchemaUpdate.as_view(), name="question_schema_update"),
    path("question_schema/<int:pk>/delete", views.QuestionSchemaDelete.as_view(), name="question_schema_delete"),
    path("question_schema/create", views.QuestionSchemaCreate.as_view(), name="question_schema_create"),
    path("question_schema/schemas", views.question_schema_schemas, name="question_schema_schemas"),
    path("condition/", views.ConditionView.as_view(), name="condition_view"),
    path("categories/", views.categories_list, name="categories_list"),
    path("categories/search_partial/", views.categories_search_partial, name="categories_search_partial"),
    path("search/cases/", views.case_search_partial, name="case_search_partial"),
    path("search/findings/", views.finding_search, name="finding_search"),
    path("search/findings/partial/", views.finding_search, name="finding_search_partial"),
    path("search/displaysets/", views.displayset_search, name="displayset_search"),
    path("search/displaysets/partial/", views.displayset_search, name="displayset_search_partial"),
    path("search/cases/page/", views.case_search_page, name="case_search_page"),
    path("normals/", views.NormalCaseList.as_view(), name="normals_list"),
    path("condition/<int:pk>", views.condition_detail, name="condition_detail"),
    path(
        "condition/<int:pk>/delete",
        views.ConditionDelete.as_view(),
        name="condition_delete",
    ),
    path(
        "condition/<int:pk>/update",
        views.ConditionUpdate.as_view(),
        name="condition_update",
    ),
    path(
        "condition/<int:pk_to_merge>/merge/",
        views.condition_merge,
        name="condition_merge",
    ),
    path("subspecialty/", views.SubspecialtyView.as_view(), name="subspecialty_view"),
    path(
        "subspecialty/<int:pk>", views.subspecialty_detail, name="subspecialty_detail"
    ),
    path("subspecialty/create", views.SubspecialtyCreate.as_view(), name="subspecialty_create"),
    path("condition/create", views.ConditionCreate.as_view(), name="condition_create"),
    path("finding/", views.FindingView.as_view(), name="finding_view"),
    path("finding/<int:pk>", views.finding_detail, name="finding_detail"),
    path(
        "finding/<int:pk>/delete", views.FindingDelete.as_view(), name="finding_delete"
    ),
    path(
        "finding/<int:pk>/update", views.FindingUpdate.as_view(), name="finding_update"
    ),
    path("finding/create", views.FindingCreate.as_view(), name="finding_create"),
    path("structure/", views.StructureView.as_view(), name="structure_view"),
    path("structure/<int:pk>", views.structure_detail, name="structure_detail"),
    path(
        "structure/<int:pk>/delete",
        views.StructureDelete.as_view(),
        name="structure_delete",
    ),
    path(
        "structure/<int:pk>/update",
        views.StructureUpdate.as_view(),
        name="structure_update",
    ),
    path("structure/create", views.StructureCreate.as_view(), name="structure_create"),
    path("series/<int:pk>/thumbnail/fail", views.series_thumbnail_fail, name="series_thumbnail_fail"),
    path("series/<int:pk>/thumbnail", views.series_thumbnail, name="series_thumbnail"),
    path("tasks/overview/", views.task_overview, name="task_overview"),
    # TODO: case context series viewing (so that we can view series in the context of a case)
    path("series/<int:pk>", views.series_detail, name="series_detail"),
    path("series/<int:pk>/viewer", views.series_viewer, name="series_viewer"),
        path(
            "series/<int:series_id>/reconstruct/advanced/",
            views.series_reconstruct_advanced,
            name="series_reconstruct_advanced",
        ),
        path(
            "series/<int:series_id>/truncate/<int:start>/<int:end>/",
            views.series_truncate_htmx,
            name="series_truncate",
        ),
        path(
            "series/<int:series_id>/image_size/",
            views.series_image_size_htmx,
            name="series_image_size",
        ),
        path(
            "series/<int:series_id>/optimize/",
            views.series_optimize_htmx,
            name="series_optimize",
        ),
        path(
            "series/<int:series_id>/reconstruct/status/<str:task_id>/",
            views.series_reconstruct_status_htmx,
            name="series_reconstruct_status",
        ),
        path(
            "series/<int:series_id>/downsample/status/<str:task_id>/",
            views.series_downsample_status_htmx,
            name="series_downsample_status",
        ),
    path("series/<int:pk>/images/", views.series_images_partial, name="series_images"),
    path("series/<int:pk>/authors", views.SeriesAuthorUpdate.as_view(), name="series_authors"),
    path("series/<int:series_id>/finding/related", views.series_finding_related, name="series_finding_related"),
    path("series/", views.SeriesView.as_view(), name="series_view"),
    path("series_image/<int:pk>/dicom", views.series_image_dicom, name="series_image_dicom"),
    path(
        "series/<int:pk>/<int:finding_pk>",
        views.series_detail,
        name="series_edit_finding",
    ),
    path(
        "series/<int:pk>/anon",
        views.series_anonymise_dicom,
        name="series_anonymise_dicom",
    ),
    path(
        "case/<int:pk>/order_dicom",
        views.case_order_dicom,
        name="case_order_dicom",
    ),
    path(
        "series/<int:pk>/order_dicom",
        views.series_order_dicom,
        name="series_order_dicom",
    ),
    path(
        "images/diff",
        views.image_diff,
        name="image_diff",
    ),
    path(
        "series/<int:pk>/download",
        views.SeriesImagesZipView.as_view(),
        name="series_download",
    ),
    path(
        "case/<int:pk>/download",
        views.case_download,
        name="case_download",
    ),
    path("api_tokens/", views.api_tokens_page, name="api_tokens"),
    path(
        "series/<int:pk>/order_dicom_instance",
        views.series_order_dicom_instance,
        name="series_order_dicom_instance",
    ),
    path(
        "series/<int:pk>/order_dicom_SeriesInstanceUID",
        views.series_order_dicom_SeriesInstanceUID,
        name="series_order_dicom_SeriesInstanceUID",
    ),
    path(
        "series/<int:pk>/order_upload_filename",
        views.series_order_upload_filename,
        name="series_order_upload_filename",
    ),
    path(
        "series/<int:pk>/split_by_tag",
        views.series_split_by_tag,
        name="series_split_by_tag",
    ),
    path(
        "series/<int:pk>/tag_consistency",
        views.series_tag_consistency,
        name="series_tag_consistency",
    ),
    path(
        "series/<int:pk>/delete",
        views.SeriesDelete.as_view(),
        name="series_delete",
    ),
    # path("unchecked/", views.unchecked_list, name="unchecked_list"),
    # path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
    path("case/<int:pk>/", views.case_detail, name="case_detail"),
    path("case/<int:pk>/inline-field/<str:field_name>/", views.case_inline_field, name="case_inline_field"),
    path("case/<int:pk>/toggle_normal/", views.toggle_case_normal, name="case_toggle_normal"),
    path("case/<int:pk>/normal_form/", views.case_normal_form, name="case_normal_form"),
    path("case/<int:pk>/create_normal/", views.create_case_normal, name="case_create_normal"),
    path("normal/<int:pk>/edit/", views.case_normal_edit, name="case_normal_edit"),
    # path("case/<int:pk>/collection-form", views.AddCollectionToCaseView.as_view(), name="case_collection_form"),
    path(
        "case/<int:case_id>/collection-form",
        views.add_collection_to_case_form,
        name="case_collection_form",
    ),
    path(
        "case/<int:case_id>/collection-inline-search/",
        views.collection_inline_search,
        name="collection_inline_search",
    ),
    path(
        "case/<int:case_id>/add-collection/<int:collection_id>/",
        views.add_collection_to_case_inline,
        name="add_collection_to_case_inline",
    ),
    path("case/<int:pk>/clone", views.AtlasClone.as_view(), name="case_clone"),
    path("case/<int:pk>/clone/next", views.AtlasCloneNext.as_view(), name="case_clone_next"),
    # path("verified/", views.verified, name="verified"),
    # path("all_questions/", views.all_questions, name="all_questions"),
    path("case/<int:pk>/scrap", views.atlas_scrap, name="case_scrap"),
    path("case/<int:pk>/delete", views.CaseDelete.as_view(), name="case_delete"),
    path("case/<int:case_id>/push_to_cimar", views.push_case_to_cimar, name="push_case_to_cimar"),
    path("case/create/", views.AtlasCreate.as_view(), name="case_create"),
    path(
        "case/collection/<int:pk>/create",
        views.AtlasCreate.as_view(),
        name="atlas_create_exam",
    ),
    path("series/create", views.SeriesCreate.as_view(), name="series_create"),
    path(
        "series/<int:pk>/create",
        views.SeriesCreate.as_view(),
        name="series_id_create",
    ),
    path(
        "case/<int:pk>/update",
        views.AtlasUpdate.as_view(),
        name="case_update",
    ),
    path(
        "case/<int:pk>/update/series",
        views.AtlasSeriesUpdate.as_view(),
        name="case_series_update",
    ),
    path(
        "series/<int:pk>/update",
        views.SeriesUpdate.as_view(),
        name="series_update",
    ),
    path(
        "series/add_finding",
        views.create_series_findings,
        name="add_finding",
    ),
    path(
        "series/delete_finding/<int:pk>",
        views.SeriesFindingDelete.as_view(),
        name="delete_finding",
    ),
    path(
        "condition-autocomplete",
        views.ConditionAutocomplete.as_view(model=Condition, create_field="name"),
        name="condition-autocomplete",
    ),
    path(
        "condition-autocomplete-rcr-curriculum",
        views.ConditionAutocompleteRCRCurriculum.as_view(model=Condition),
        name="condition-autocomplete-rcr-curriculum",
    ),

    path(
        "presentation-autocomplete",
        views.PresentationAutocomplete.as_view(model=Presentation, create_field="name"),
        name="presentation-autocomplete",
    ),
    path(
        "finding-autocomplete",
        views.FindingAutocomplete.as_view(model=Finding, create_field="name"),
        name="finding-autocomplete",
    ),
    path(
        "structure-autocomplete",
        views.StructureAutocomplete.as_view(model=Structure, create_field="name", validate_create=True),
        name="structure-autocomplete",
    ),
    path(
        "procedure-autocomplete",
        views.ProcedureAutocomplete.as_view(model=Procedure, create_field="name"),
        name="procedure-autocomplete",
    ),
    path(
        "casecollection-prerequisite-autocomplete",
        views.CaseCollectionPrerequisiteAutocomplete.as_view(model=CaseCollection),
        name="casecollection-prerequisite-autocomplete",
    ),
    path(
        "subspecialty-autocomplete",
        views.SubspecialtyAutocomplete.as_view(model=Subspecialty, create_field="name"),
        name="subspecialty-autocomplete",
    ),
    path(
        "series-autocomplete",
        views.SeriesAutocomplete.as_view(model=Series),
        name="series-autocomplete",
    ),
    path("presentation/", views.PresentationView.as_view(), name="presentation_view"),
    path(
        "presentation/<int:pk>", views.presentation_detail, name="presentation_detail"
    ),
    path("procedure/", views.ProcedureView.as_view(), name="procedure_view"),
    path("procedure/<int:pk>", views.procedure_detail, name="procedure_detail"),
    path("procedure/create", views.ProcedureCreate.as_view(), name="procedure_create"),
    path("procedure/<int:pk>/update", views.ProcedureUpdate.as_view(), name="procedure_update"),
    path("procedure/<int:pk>/delete", views.ProcedureDelete.as_view(), name="procedure_delete"),
    
    path("presentation/create", views.PresentationCreate.as_view(), name="presentation_create"),
    path(
        "process/",
        views.PathologicalProcessView.as_view(),
        name="pathological_process_view",
    ),
    path(
        "process/<int:pk>",
        views.pathological_process_detail,
        name="pathological_process_detail",
    ),
    path("process/create", views.PathologicalProcessCreate.as_view(), name="pathological_process_create"),
    path("combine_series/", views.combine_series, name="combine_series"),
    path(
        "case/<int:case_id>/linked/",
        views.linked_cases_overview,
        name="linked_cases_overview",
    ),
    path("cases/by_size", views.cases_by_size, name="cases_by_size"),
    # Sharing
    path(
        "exam/<int:pk>/sharing",
        views.collection_exam_sharing_panel,
        name="collection_exam_sharing_panel",
    ),
    path(
        "exam/<int:pk>/sharing/user-search",
        views.collection_exam_user_search,
        name="collection_exam_user_search",
    ),
    path(
        "collection/shared-with-me",
        views.collection_shared_with_me,
        name="collection_shared_with_me",
    ),
    path(
        "exam/<int:cid_user_exam_pk>/attempt-overview",
        views.collection_shared_attempt_overview,
        name="collection_shared_attempt_overview",
    ),
    path(
        "supervision/",
        views.collection_supervision,
        name="collection_supervision",
    ),
]
