.
This commit is contained in:
+29
-4
@@ -1,13 +1,38 @@
|
||||
from time import sleep
|
||||
from django.core.mail import send_mail
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from celery import shared_task
|
||||
from atlas.models import Case
|
||||
from generic.models import CimarCase
|
||||
from rad.settings import REMOTE_URL, CIMAR_USERNAME, CIMAR_PASSWORD
|
||||
from helpers.cimar import CimarAPI
|
||||
from pydicom.uid import generate_uid
|
||||
|
||||
@shared_task()
|
||||
def long():
|
||||
def push_case_to_cimar_task(case_id):
|
||||
"""Sends an email when the feedback form has been submitted."""
|
||||
for i in range(20):
|
||||
sleep(1) # Simulate expensive operation(s) that freeze Django
|
||||
print(i)
|
||||
case = get_object_or_404(Case, pk=case_id)
|
||||
|
||||
api = CimarAPI()
|
||||
api.login(username=CIMAR_USERNAME, password=CIMAR_PASSWORD)
|
||||
|
||||
# We use the same study_uid for all images in a case
|
||||
study_uid = generate_uid()
|
||||
|
||||
for series in case.get_series():
|
||||
for image in series.images.all():
|
||||
data = api.upload_dicom(image.image.path, study_uid=study_uid)
|
||||
|
||||
|
||||
cimar_uuid = api.get_study_by_study_uid(data["study_uid"])["uuid"]
|
||||
|
||||
case.cimar_uuid = cimar_uuid
|
||||
|
||||
case.save()
|
||||
|
||||
cimar_case, created = CimarCase.objects.get_or_create(uuid=cimar_uuid)
|
||||
|
||||
cimar_case.refresh_study()
|
||||
|
||||
return 10
|
||||
+3
-3
@@ -117,7 +117,7 @@ from .filters import (
|
||||
SubspecialtyFilter,
|
||||
)
|
||||
|
||||
from .tasks import long
|
||||
from .tasks import push_case_to_cimar_task
|
||||
|
||||
from django_tables2 import SingleTableView, SingleTableMixin
|
||||
from django_filters.views import FilterView
|
||||
@@ -2985,9 +2985,9 @@ def collection_reset_answers(request, exam_id: int):
|
||||
|
||||
def push_case_to_cimar(request, case_id):
|
||||
|
||||
long.delay()
|
||||
push_case_to_cimar_task.delay(case_id=case_id)
|
||||
|
||||
return HttpResponse("Success")
|
||||
return HttpResponse("Push started")
|
||||
case = get_object_or_404(Case, pk=case_id)
|
||||
|
||||
api = CimarAPI()
|
||||
|
||||
Reference in New Issue
Block a user