This commit is contained in:
Ross
2021-11-21 20:39:08 +00:00
parent 8f50dabb5a
commit 2bdc41278c
4 changed files with 44 additions and 0 deletions
+1
View File
@@ -458,6 +458,7 @@ class RapidImage(models.Model):
# Try and read the file as a dicom # Try and read the file as a dicom
try: try:
# and generate a hash from the pixel data # and generate a hash from the pixel data
# TODO: improve?
dataset = pydicom.dcmread(self.image) dataset = pydicom.dcmread(self.image)
print(dataset) print(dataset)
flatten = dataset.pixel_array.flatten() flatten = dataset.pixel_array.flatten()
+27
View File
@@ -446,6 +446,7 @@
ocr2(url, el); ocr2(url, el);
checkHash(hash);
$("#drop-filenames").append( $("#drop-filenames").append(
`<span data-input-id='${el.id}'><span>${n}: ${el.files[0].name}</span><img class='uploading${extra_class}' data-input-id='${el.id}' src=${url}></span>` `<span data-input-id='${el.id}'><span>${n}: ${el.files[0].name}</span><img class='uploading${extra_class}' data-input-id='${el.id}' src=${url}></span>`
@@ -468,6 +469,7 @@
let hash = CryptoJS.MD5(pixel_data).toString(); let hash = CryptoJS.MD5(pixel_data).toString();
console.log(element, "HASH", hash) console.log(element, "HASH", hash)
checkHash(hash);
}); });
@@ -630,6 +632,31 @@
} }
function checkHash(hash) {
$.ajax({
url: "{% url 'rapids:rapid_question_by_hash' %}",
data: {
csrfmiddlewaretoken: csrf,
hash: hash
},
type: "POST",
dataType: "json",
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
if (data.status == "success") {
console.log("success");
console.log(data.id)
toastr.info(f'id {data.id}')
}
})
.always(function () {
console.log('[Done]');
})
}
function extractDicomStudyDescription(byteArray) { function extractDicomStudyDescription(byteArray) {
// We need to setup a try/catch block because parseDicom will throw an exception // We need to setup a try/catch block because parseDicom will throw an exception
// if you attempt to parse a non dicom part 10 file (or one that is corrupted) // if you attempt to parse a non dicom part 10 file (or one that is corrupted)
+1
View File
@@ -12,6 +12,7 @@ urlpatterns = [
path("author/<int:pk>/", views.GenericViews.author_detail, name="author_detail"), path("author/<int:pk>/", views.GenericViews.author_detail, name="author_detail"),
path("author/", views.GenericViews.author_list, name="author_list"), path("author/", views.GenericViews.author_list, name="author_list"),
path("question/", views.RapidView.as_view(), name="rapid_view"), path("question/", views.RapidView.as_view(), name="rapid_view"),
path("question/hash", views.get_question_by_hash, name="rapid_question_by_hash"),
# path("unchecked/", views.unchecked_list, name="unchecked_list"), # path("unchecked/", views.unchecked_list, name="unchecked_list"),
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"), # path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
path( path(
+15
View File
@@ -33,6 +33,7 @@ from .forms import (
from .models import ( from .models import (
Rapid, Rapid,
Abnormality, Abnormality,
RapidImage,
Region, Region,
Examination, Examination,
Exam, Exam,
@@ -1105,3 +1106,17 @@ def question_save_annotation(request, pk):
class ExamClone(ExamCloneMixin, ExamCreate): class ExamClone(ExamCloneMixin, ExamCreate):
"""Clone exam view""" """Clone exam view"""
@login_required
def get_question_by_hash(request, pk):
if request.is_ajax() and request.method == "POST":
hash = json.loads(request.POST.get("hash"))
try:
question = RapidImage.objects.get(image_md5_hash=hash)
data = {"status": "success", "id": question.pk}
return JsonResponse(data, status=200)
except RapidImage.DoesNotExist:
data = {"status": "success", "id": False}
return JsonResponse(data, status=200)