Add DICOM upload and case retrieval endpoints: implement upload_dicom_case and get_cases_available functions

This commit is contained in:
Ross
2026-02-23 10:45:34 +00:00
parent 65db1220d8
commit 83d1b48213
+28
View File
@@ -22,6 +22,7 @@ from ninja.files import UploadedFile
from generic.models import Examination, Modality
from .models import Case, DuplicateDicom, Series, SeriesImage, UncategorisedDicom
from atlas.helpers import get_cases_available_to_user
from loguru import logger
@@ -227,6 +228,26 @@ def import_dicoms_case(request, case_id: int):
return import_dicoms_helper(request, case_id=case_id)
@router.post("/upload_dicom_case/{case_id}", auth=django_auth, response=List[Tuple[SeriesSchema, str]])
def upload_dicom_case(request, case_id: int, files: List[UploadedFile] = File(...)):
"""Upload DICOM files and immediately import them into the given case.
This saves each uploaded file as an `UncategorisedDicom` owned by the user,
then calls the existing import helper which will create Series/SeriesImage
objects and attach them to the specified case.
"""
for file in files:
try:
ud = UncategorisedDicom(image=file, user=request.user)
ud.save()
except DuplicateDicom:
# skip duplicates
continue
# Now reuse import helper which will consume UncategorisedDicom for this user
return import_dicoms_helper(request, case_id=case_id)
@router.get("/orphan_series", auth=django_auth, response=List[SeriesSchema])
def orphan_series(request):
return request.user.series.filter(case=None)
@@ -254,6 +275,13 @@ def get_cases_user(request):
return Case.objects.filter(author=request.user)
@router.get("/get_cases_available", auth=django_auth, response=List[CaseSchema])
def get_cases_available(request):
"""Return cases available to the authenticated user (via get_cases_available_to_user)."""
qs = get_cases_available_to_user(request.user)
return qs.order_by('-created_date')[:200]
@router.get("/check_image_hash/{hash}", auth=django_auth)
def check_image_hash(request, hash: str):
try: