.
This commit is contained in:
@@ -362,4 +362,3 @@ function keyDownHandler(e) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+46
-2
@@ -90,6 +90,9 @@ class LongSeriesForm(ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class LongForm(ModelForm):
|
class LongForm(ModelForm):
|
||||||
|
|
||||||
|
exams = ModelMultipleChoiceField(required=False, queryset=Exam.objects.all(),widget=FilteredSelectMultiple(verbose_name="Exams", is_stacked=False))
|
||||||
|
|
||||||
class Media:
|
class Media:
|
||||||
# Django also includes a few javascript files necessary
|
# Django also includes a few javascript files necessary
|
||||||
# for the operation of this form element. You need to
|
# for the operation of this form element. You need to
|
||||||
@@ -110,6 +113,16 @@ class LongForm(ModelForm):
|
|||||||
# widget=FilteredSelectMultiple(verbose_name="Examination", is_stacked=False),
|
# widget=FilteredSelectMultiple(verbose_name="Examination", is_stacked=False),
|
||||||
#)
|
#)
|
||||||
|
|
||||||
|
if kwargs.get("instance"):
|
||||||
|
# We get the 'initial' keyword argument or initialize it
|
||||||
|
# as a dict if it didn't exist.
|
||||||
|
initial = kwargs.setdefault("initial", {})
|
||||||
|
# The widget for a ModelMultipleChoiceField expects
|
||||||
|
# a list of primary key for the selected data.
|
||||||
|
initial["exams"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||||
|
|
||||||
|
ModelForm.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Long
|
model = Long
|
||||||
# fields = ['due_back']
|
# fields = ['due_back']
|
||||||
@@ -117,7 +130,16 @@ class LongForm(ModelForm):
|
|||||||
fields = [
|
fields = [
|
||||||
#"examination",
|
#"examination",
|
||||||
#"site",
|
#"site",
|
||||||
|
"history",
|
||||||
"feedback",
|
"feedback",
|
||||||
|
"condition",
|
||||||
|
"sign",
|
||||||
|
"model_observations",
|
||||||
|
"model_interpretation",
|
||||||
|
"model_principle_diagnosis",
|
||||||
|
"model_differential_diagnosis",
|
||||||
|
"model_management",
|
||||||
|
"open_access",
|
||||||
]
|
]
|
||||||
# fields = ['question', 'feedback', 'subspecialty', 'references']
|
# fields = ['question', 'feedback', 'subspecialty', 'references']
|
||||||
widgets = {
|
widgets = {
|
||||||
@@ -126,13 +148,35 @@ class LongForm(ModelForm):
|
|||||||
# (False, 'No')])
|
# (False, 'No')])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
# Get the unsaved Long instance
|
||||||
|
instance = ModelForm.save(self, False)
|
||||||
|
|
||||||
|
# Prepare a 'save_m2m' method for the form,
|
||||||
|
old_save_m2m = self.save_m2m
|
||||||
|
|
||||||
|
def save_m2m():
|
||||||
|
old_save_m2m()
|
||||||
|
instance.exams.clear()
|
||||||
|
for exam in self.cleaned_data["exams"]:
|
||||||
|
# We need the id here
|
||||||
|
instance.exams.add(exam.pk)
|
||||||
|
|
||||||
|
self.save_m2m = save_m2m
|
||||||
|
|
||||||
|
# Do we need to save all changes now?
|
||||||
|
# if commit:
|
||||||
|
instance.save()
|
||||||
|
self.save_m2m()
|
||||||
|
|
||||||
|
return instance
|
||||||
|
|
||||||
SeriesFormSet = inlineformset_factory(
|
SeriesFormSet = inlineformset_factory(
|
||||||
Long,
|
Long,
|
||||||
LongSeries,
|
LongSeries,
|
||||||
exclude=[],
|
exclude=[],
|
||||||
can_delete=True,
|
can_delete=True,
|
||||||
extra=4,
|
extra=1,
|
||||||
max_num=10,
|
max_num=10,
|
||||||
field_classes="testing",
|
field_classes="testing",
|
||||||
)
|
)
|
||||||
@@ -143,7 +187,7 @@ LongSeriesImageFormSet = inlineformset_factory(
|
|||||||
LongSeriesImage,
|
LongSeriesImage,
|
||||||
exclude=[],
|
exclude=[],
|
||||||
can_delete=True,
|
can_delete=True,
|
||||||
extra=4,
|
extra=1,
|
||||||
max_num=2000,
|
max_num=2000,
|
||||||
field_classes="testing",
|
field_classes="testing",
|
||||||
)
|
)
|
||||||
|
|||||||
+23
-3
@@ -102,6 +102,11 @@ class Long(models.Model):
|
|||||||
authors = ", ".join([i.username for i in self.author.all()])
|
authors = ", ".join([i.username for i in self.author.all()])
|
||||||
return authors
|
return authors
|
||||||
|
|
||||||
|
def get_author_objects(self):
|
||||||
|
"""Returns a comma seperated text list of authors"""
|
||||||
|
authors = [i for i in self.author.all()]
|
||||||
|
return authors
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
examinations = [series.get_examination() for series in self.series.all()]
|
examinations = [series.get_examination() for series in self.series.all()]
|
||||||
return "{} : {}".format(self.history, ", ".join(examinations))
|
return "{} : {}".format(self.history, ", ".join(examinations))
|
||||||
@@ -143,6 +148,15 @@ class LongSeries(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} : {} [{}]".format(self.get_examination(), self.description, self.long.pk)
|
return "{} : {} [{}]".format(self.get_examination(), self.description, self.long.pk)
|
||||||
|
|
||||||
|
def get_author_objects(self):
|
||||||
|
"""Returns a comma seperated text list of authors"""
|
||||||
|
if self.long:
|
||||||
|
authors = [i for i in self.long.author.all()]
|
||||||
|
else:
|
||||||
|
authors = []
|
||||||
|
|
||||||
|
return authors
|
||||||
|
|
||||||
def get_examination(self):
|
def get_examination(self):
|
||||||
"""Returns a comma seperated text list of regions"""
|
"""Returns a comma seperated text list of regions"""
|
||||||
return str(self.examination)
|
return str(self.examination)
|
||||||
@@ -156,16 +170,22 @@ class LongSeries(models.Model):
|
|||||||
return ",".join(images)
|
return ",".join(images)
|
||||||
|
|
||||||
def get_thumbnail(self):
|
def get_thumbnail(self):
|
||||||
img = findMiddle(self.images.all()).image
|
images = self.images.all()
|
||||||
|
|
||||||
|
if len(images) < 1:
|
||||||
|
return 'No images', 0
|
||||||
|
|
||||||
|
img = findMiddle(images).image
|
||||||
thumbnailer = get_thumbnailer(img)
|
thumbnailer = get_thumbnailer(img)
|
||||||
thumbnail = thumbnailer["exam-list"]
|
thumbnail = thumbnailer["exam-list"]
|
||||||
return thumbnail
|
return '<img src="/media/{}" />'.format(thumbnail), len(images)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_block(self):
|
def get_block(self):
|
||||||
examination = self.get_examination()
|
examination = self.get_examination()
|
||||||
return format_html('<div>{}<br/><img src="/media/{}" /></div>', examination, self.get_thumbnail() )
|
thumb, image_number = self.get_thumbnail()
|
||||||
|
return format_html('<div>{}<br/>{}<br/>Images: {}</div>', examination, thumb, image_number )
|
||||||
|
|
||||||
#class LongImage(models.Model):
|
#class LongImage(models.Model):
|
||||||
# long = models.ForeignKey(Long,
|
# long = models.ForeignKey(Long,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
{{ question.created_date }}
|
{{ question.created_date }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="pre-whitespace"><b>Long:</b> {{ question }}</p>
|
|
||||||
<p class="pre-whitespace"><b>History:</b> {{ question.history }}</p>
|
<p class="pre-whitespace"><b>History:</b> {{ question.history }}</p>
|
||||||
|
|
||||||
<p class="pre-whitespace"><b>Abnormality:</b> {{ question.get_abnormalities }}</p>
|
<p class="pre-whitespace"><b>Abnormality:</b> {{ question.get_abnormalities }}</p>
|
||||||
@@ -15,10 +14,11 @@
|
|||||||
{{series.get_block}}
|
{{series.get_block}}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="test.html" onclick="return popitup('/longs/series/{{series.pk}}', 'Series')"
|
<a href="#" onclick="return popitup('/longs/series/{{series.pk}}', 'Series')"
|
||||||
>Test</a>
|
>Popup</a>
|
||||||
</span>
|
</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<a href="{% url 'longs:long_series_id_create' pk=question.pk %}">Add series</a>
|
||||||
</div>
|
</div>
|
||||||
<p class="pre-whitespace"><b>Feedback:</b> {{ question.feedback }}</p>
|
<p class="pre-whitespace"><b>Feedback:</b> {{ question.feedback }}</p>
|
||||||
<p><b>Author(s):</b> {% for author in question.author.all %} <a
|
<p><b>Author(s):</b> {% for author in question.author.all %} <a
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
<p class="pre-whitespace"><b>Differential Diagnosis:</b> {{ question.model_differential_diagnosis }}</p>
|
<p class="pre-whitespace"><b>Differential Diagnosis:</b> {{ question.model_differential_diagnosis }}</p>
|
||||||
<p class="pre-whitespace"><b>Managment:</b> {{ question.model_management }}</p>
|
<p class="pre-whitespace"><b>Managment:</b> {{ question.model_management }}</p>
|
||||||
</p>
|
</p>
|
||||||
|
<p><b>Exam(s):</b> {{question.GetExams}}</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Notes:
|
Notes:
|
||||||
|
|||||||
Executable
+59
@@ -0,0 +1,59 @@
|
|||||||
|
{% extends "longs/base.html" %}
|
||||||
|
{% load static from static %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<!--<script type="text/javascript" src="/admin/jsi18n/"></script>-->
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function showEditPopup(url) {
|
||||||
|
var win = window.open(url, "Edit",
|
||||||
|
'height=500,width=800,resizable=yes,scrollbars=yes');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function showAddPopup(triggeringLink) {
|
||||||
|
var name = triggeringLink.id.replace(/^add_/, '');
|
||||||
|
href = triggeringLink.href;
|
||||||
|
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
|
||||||
|
win.focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function closePopup(win, newID, newRepr, id) {
|
||||||
|
console.log(id)
|
||||||
|
$(id + "_to").append('<option value=' + newID + ' title=' + newRepr + ' >' + newRepr + '</option>')
|
||||||
|
win.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{{ form.media }}
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h2>Submit Long Case</h2>
|
||||||
|
Use this form to create a long case. Once the case has been created it can be associated with image sets (series)
|
||||||
|
<form action="" method="post" enctype="multipart/form-data" id="long-form">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
</table>
|
||||||
|
<h3>Series:</h3>
|
||||||
|
<input type="button" value="Add More Series" id="add_more">
|
||||||
|
<div id="form_set">
|
||||||
|
{% for form in series_formset %}
|
||||||
|
<ul class="no-error series-formset">
|
||||||
|
{{form.non_field_errors}}
|
||||||
|
{{form.errors}}
|
||||||
|
{{ form.as_ul }}
|
||||||
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{{ series_formset.management_form }}
|
||||||
|
<input type="submit" class="submit-button" value="Submit" name="submit">
|
||||||
|
</form>
|
||||||
|
<div id="empty_form" style="display:none">
|
||||||
|
<ul class='no_error series-formset'>
|
||||||
|
{{ series_formset.empty_form.as_ul }}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -2,5 +2,10 @@
|
|||||||
{% extends "longs/base.html" %}
|
{% extends "longs/base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<a href="{% url 'longs:long_series_update' pk=series.pk %}" title="Edit the Long">Edit</a>
|
||||||
|
{% if request.user.is_superuser %}
|
||||||
|
<a href="{% url 'admin:longs_longseries_change' series.id %}" title="Edit the Long using the admin interface">Admin Edit</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% include 'longs/long_series_viewer.html' %}
|
{% include 'longs/long_series_viewer.html' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,292 +0,0 @@
|
|||||||
{% extends "longs/base.html" %}
|
|
||||||
{% load static from static %}
|
|
||||||
|
|
||||||
{% block js %}
|
|
||||||
<!--<script type="text/javascript" src="/admin/jsi18n/"></script>-->
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
function showEditPopup(url) {
|
|
||||||
var win = window.open(url, "Edit",
|
|
||||||
'height=500,width=800,resizable=yes,scrollbars=yes');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
function showAddPopup(triggeringLink) {
|
|
||||||
var name = triggeringLink.id.replace(/^add_/, '');
|
|
||||||
href = triggeringLink.href;
|
|
||||||
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
|
|
||||||
win.focus();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
function closePopup(win, newID, newRepr, id) {
|
|
||||||
console.log(id)
|
|
||||||
$(id + "_to").append('<option value=' + newID + ' title=' + newRepr + ' >' + newRepr + '</option>')
|
|
||||||
win.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('drop', function (e) { e.preventDefault(); }, false);
|
|
||||||
|
|
||||||
function add_input_form() {
|
|
||||||
var form_idx = $('#id_images-TOTAL_FORMS').val();
|
|
||||||
$('#image_form_set').append($('#empty_form').html().replace(/__prefix__/g, form_idx));
|
|
||||||
$('#id_images-TOTAL_FORMS').val(parseInt(form_idx) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_answers_input_form() {
|
|
||||||
var form_idx = $('#id_answers-TOTAL_FORMS').val();
|
|
||||||
$('#answer_form_set').append($('#answer_empty_form').html().replace(/__prefix__/g, form_idx));
|
|
||||||
$('#id_answers-TOTAL_FORMS').val(parseInt(form_idx) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
|
||||||
$("#add_abnormality").appendTo($("label[for='id_abnormality']"));
|
|
||||||
$("#add_examination").appendTo($("label[for='id_examination']"));
|
|
||||||
$("#add_region").appendTo($("label[for='id_region']"));
|
|
||||||
|
|
||||||
dropContainer = document.getElementById("drop-container");
|
|
||||||
|
|
||||||
dropContainer.ondragover = function (evt) {
|
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
};
|
|
||||||
|
|
||||||
dropContainer.ondragenter = function (evt) {
|
|
||||||
console.log("ENTER")
|
|
||||||
console.log(evt)
|
|
||||||
$(evt.target).addClass("drop-target-active")
|
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
};
|
|
||||||
|
|
||||||
dropContainer.ondragleave = function (evt) {
|
|
||||||
console.log("ENTER")
|
|
||||||
console.log(evt)
|
|
||||||
$(evt.target).removeClass("drop-target-active")
|
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
};
|
|
||||||
|
|
||||||
dropContainer.ondrop = function (evt) {
|
|
||||||
console.log("SHIT", evt);
|
|
||||||
$(evt.target).removeClass("drop-target-active");
|
|
||||||
|
|
||||||
// Get all input elements
|
|
||||||
inputs = $("#long-form input[type=file][id^=id_images-]");
|
|
||||||
//fileInput = document.getElementById("id_images-0-image");
|
|
||||||
|
|
||||||
// Make sure we have enough input targets
|
|
||||||
input_diff = (evt.dataTransfer.files.length - inputs.length)
|
|
||||||
console.log("diff", input_diff)
|
|
||||||
|
|
||||||
if(input_diff > 0) {
|
|
||||||
for(let j = 0; j < input_diff; j++) {
|
|
||||||
add_input_form()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Need to make sure we include the new ones...
|
|
||||||
inputs = $("#long-form input[type=file][id^=id_images-]");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through each dropped file and try to assign to an
|
|
||||||
// input element
|
|
||||||
[...evt.dataTransfer.files].forEach((f) => {
|
|
||||||
let dT = new DataTransfer();
|
|
||||||
dT.clearData();
|
|
||||||
dT.items.add(f);
|
|
||||||
for(let i = 0; i < inputs.length; i++) {
|
|
||||||
el = inputs.get(i)
|
|
||||||
|
|
||||||
if(el.files.length == 0) {
|
|
||||||
el.files = dT.files;
|
|
||||||
ocr(el)
|
|
||||||
|
|
||||||
if(evt.target.id == "feedback-drop-target") {
|
|
||||||
arr = el.name.split("-");
|
|
||||||
arr.splice(2, 1, "feedback_image");
|
|
||||||
feedback_el_name = arr.join("-");
|
|
||||||
|
|
||||||
$(`[name=${feedback_el_name}]`).prop("checked", true);
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// // If you want to use some of the dropped files
|
|
||||||
// const dT = new DataTransfer();
|
|
||||||
// dT.items.add(evt.dataTransfer.files[0]);
|
|
||||||
// dT.items.add(evt.dataTransfer.files[3]);
|
|
||||||
// fileInput.files = dT.files;
|
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
updateFileList();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
$('#add_more_images').click(() => { add_input_form() });
|
|
||||||
$('#add_more_answers').click(() => { add_answers_input_form() });
|
|
||||||
|
|
||||||
function updateFileList() {
|
|
||||||
$("#drop-filenames").empty()
|
|
||||||
$("#image_form_set input[type=file]").each((n, el) => {
|
|
||||||
console.log(el);
|
|
||||||
if(el.files.length > 0) {
|
|
||||||
extra_class = " image-ident-loading";
|
|
||||||
if($(el).hasClass("image-ident-warning")) {
|
|
||||||
extra_class = " image-ident-warning"
|
|
||||||
} else if($(el).hasClass("image-ident-ok")) {
|
|
||||||
extra_class = " image-ident-ok"
|
|
||||||
}
|
|
||||||
$("#drop-filenames").append(
|
|
||||||
`<span>${n}: ${el.files[0].name}</span><img class='uploading${extra_class}' data-input-id='${el.id}' src=${URL.createObjectURL(el.files[0])}>`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$("input[type=file]").on('change', function () {
|
|
||||||
$(this).removeClass("image-ident-warning");
|
|
||||||
$(this).removeClass("image-ident-ok");
|
|
||||||
updateFileList();
|
|
||||||
console.log("input change1");
|
|
||||||
console.log("input change", this);
|
|
||||||
ocr(this);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ifNormal(){
|
|
||||||
if (document.getElementById("id_normal").checked){
|
|
||||||
$("#answer_form_set textarea").attr("required", false)
|
|
||||||
} else {
|
|
||||||
$("#answer_form_set textarea").attr("required", true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#id_normal").change(() => ifNormal());
|
|
||||||
|
|
||||||
ifNormal();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
function ocr(input) {
|
|
||||||
// Tesseract.recognize(f, "eng",{ logger: m => console.log(m) }
|
|
||||||
// ).then(({ data: { text } }) => {
|
|
||||||
// console.log(text);
|
|
||||||
// l = text.toLowerCase();
|
|
||||||
// if (l.includes("accesion") || l.includes("number") || l.search(/(REF|RK9|RH8|RA9)\d+/g)) {
|
|
||||||
// console.log("SHIT", this);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
console.log('{% static "worker.min.js" %}');
|
|
||||||
console.log('{{ STATIC_URL }}/tesseract-core.wasm.js %}');
|
|
||||||
|
|
||||||
const worker = Tesseract.createWorker({
|
|
||||||
workerPath: '{% static "worker.min.js" %}',
|
|
||||||
langPath: '{% static "" %}',
|
|
||||||
//langPath: '{{ STATIC_URL }}',
|
|
||||||
corePath: '{% static "tesseract-core.wasm.js" %}',
|
|
||||||
});
|
|
||||||
|
|
||||||
const url = URL.createObjectURL(input.files[0]);
|
|
||||||
let img = new Image;
|
|
||||||
img.src = url;
|
|
||||||
|
|
||||||
img.onload = function () {
|
|
||||||
|
|
||||||
|
|
||||||
width = img.width;
|
|
||||||
|
|
||||||
// const rectangle = { left: 0, top: 0, width: width, height: 10 }
|
|
||||||
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
await worker.load();
|
|
||||||
await worker.loadLanguage('eng');
|
|
||||||
await worker.initialize('eng');
|
|
||||||
// const { data: { text } } = await worker.recognize(input.files[0], { rectangle });
|
|
||||||
const { data: { text } } = await worker.recognize(input.files[0]);
|
|
||||||
//console.log(text);
|
|
||||||
l = text.toLowerCase();
|
|
||||||
$(`img[data-input-id='${input.id}'`).removeClass("image-ident-loading");
|
|
||||||
console.log(l);
|
|
||||||
if(l.includes("accesion") || l.includes("number") || l.search(/(ref|rk9|rh8|ra9|rbz)\d+/g) > -1) {
|
|
||||||
console.log("SHIT", input);
|
|
||||||
$(input).addClass("image-ident-warning");
|
|
||||||
$(`img[data-input-id='${input.id}'`).addClass("image-ident-warning");
|
|
||||||
} else {
|
|
||||||
$(input).addClass("image-ident-ok");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
await worker.terminate();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{{ form.media }}
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}
|
|
||||||
<h2>Submit Long</h2>
|
|
||||||
<a href="{% url 'longs:long_create_defaults' %}">Edit defaults</a>
|
|
||||||
<form action="" method="post" enctype="multipart/form-data" id="long-form">
|
|
||||||
{% csrf_token %}
|
|
||||||
<a href="/longs/abnormality/create" id="add_abnormality" class="add-popup"
|
|
||||||
onclick="return showAddPopup(this);"><img src="{% static '/img/icon-addlink.svg' %}"></a>
|
|
||||||
<a href="/longs/examination/create" id="add_examination" class="add-popup"
|
|
||||||
onclick="return showAddPopup(this);"><img src="{% static '/img/icon-addlink.svg' %}"></a>
|
|
||||||
<a href="/longs/region/create" id="add_region" class="add-popup" onclick="return showAddPopup(this);"><img
|
|
||||||
src="{% static '/img/icon-addlink.svg' %}"></a>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
{{ form.as_table }}
|
|
||||||
</table>
|
|
||||||
<h3>Answers:</h3>
|
|
||||||
<input type="button" value="Add More Answers" id="add_more_answers">
|
|
||||||
<div id="answer_form_set">
|
|
||||||
{% for form in answer_formset %}
|
|
||||||
<ul class="no-error answer-formset">
|
|
||||||
{{form.non_field_errors}}
|
|
||||||
{{form.errors}}
|
|
||||||
{{ form.as_ul }}
|
|
||||||
</ul>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{{ answer_formset.management_form }}
|
|
||||||
<h3>Images:</h3>
|
|
||||||
<input type="button" value="Add More Images" id="add_more_images">
|
|
||||||
<div id="drop-container" class="drop-target">Drop images here (or use the buttons below)<div
|
|
||||||
id="feedback-drop-target">Feedback image?<br />drop those here</div>
|
|
||||||
<div id="drop-filenames"></div>
|
|
||||||
</div>
|
|
||||||
<div id="image_form_set">
|
|
||||||
{% for form in image_formset %}
|
|
||||||
<ul class="no-error image-formset">
|
|
||||||
{{form.non_field_errors}}
|
|
||||||
{{form.errors}}
|
|
||||||
{{ form.as_ul }}
|
|
||||||
</ul>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{{ image_formset.management_form }}
|
|
||||||
<input type="submit" class="submit-button" value="Submit" name="submit">
|
|
||||||
<input type="submit" class="submit-button" value="Submit and Clone" name="submit-clone">
|
|
||||||
</form>
|
|
||||||
<div id="empty_form" style="display:none">
|
|
||||||
<ul class='no_error image-formset'>
|
|
||||||
{{ image_formset.empty_form.as_ul }}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div id="answer_empty_form" style="display:none">
|
|
||||||
<ul class='no_error answer-formset'>
|
|
||||||
{{ answer_formset.empty_form.as_ul }}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -37,6 +37,7 @@ urlpatterns = [
|
|||||||
path("exam/json/<int:pk>/recreate", views.exam_json_recreate, name="exam_json_recreate"),
|
path("exam/json/<int:pk>/recreate", views.exam_json_recreate, name="exam_json_recreate"),
|
||||||
path("create/", views.LongCreate.as_view(), name="long_create"),
|
path("create/", views.LongCreate.as_view(), name="long_create"),
|
||||||
path("create/series", views.LongSeriesCreate.as_view(), name="long_series_create"),
|
path("create/series", views.LongSeriesCreate.as_view(), name="long_series_create"),
|
||||||
|
path("create/series/<int:pk>", views.LongSeriesCreate.as_view(), name="long_series_id_create"),
|
||||||
path("create/defaults",
|
path("create/defaults",
|
||||||
views.LongCreationDefaultView.as_view(),
|
views.LongCreationDefaultView.as_view(),
|
||||||
name="long_create_defaults"),
|
name="long_create_defaults"),
|
||||||
@@ -61,5 +62,6 @@ urlpatterns = [
|
|||||||
views.LongUpdate.as_view(),
|
views.LongUpdate.as_view(),
|
||||||
name="long_update",
|
name="long_update",
|
||||||
),
|
),
|
||||||
|
path("series/<int:pk>/update", views.LongSeriesUpdate.as_view(), name="long_series_update"),
|
||||||
path("<int:pk>/add_note", views.AddNote.as_view(), name="long_add_note"),
|
path("<int:pk>/add_note", views.AddNote.as_view(), name="long_add_note"),
|
||||||
]
|
]
|
||||||
|
|||||||
+70
-1
@@ -64,7 +64,7 @@ class AuthorOrCheckerRequiredMixin(object):
|
|||||||
obj = super(UpdateView, self).get_object(*args, **kwargs)
|
obj = super(UpdateView, self).get_object(*args, **kwargs)
|
||||||
if self.request.user.groups.filter(name="long_checker").exists():
|
if self.request.user.groups.filter(name="long_checker").exists():
|
||||||
return obj
|
return obj
|
||||||
if self.request.user not in obj.author.all():
|
if self.request.user not in obj.get_author_objects():
|
||||||
raise PermissionDenied() # or Http404
|
raise PermissionDenied() # or Http404
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@@ -100,6 +100,11 @@ def long_detail(request, pk):
|
|||||||
def long_series_detail(request, pk):
|
def long_series_detail(request, pk):
|
||||||
series = get_object_or_404(LongSeries, pk=pk)
|
series = get_object_or_404(LongSeries, pk=pk)
|
||||||
|
|
||||||
|
# if request.user not in long.author.all():
|
||||||
|
# raise PermissionDenied
|
||||||
|
|
||||||
|
# logging.debug(long.long_notes.first())
|
||||||
|
# logging.debug(long.subspecialty.first().name.all())
|
||||||
return render(request, "longs/long_series.html", {"series": series})
|
return render(request, "longs/long_series.html", {"series": series})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -262,8 +267,19 @@ class LongSeriesCreate(LoginRequiredMixin, CreateView):
|
|||||||
model = LongSeries
|
model = LongSeries
|
||||||
form_class = LongSeriesForm
|
form_class = LongSeriesForm
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
# print(self.request)
|
||||||
|
if "pk" in self.kwargs:
|
||||||
|
initial = super().get_initial()
|
||||||
|
long = get_object_or_404(Long, pk=self.kwargs["pk"])
|
||||||
|
|
||||||
|
initial['long'] = long.id
|
||||||
|
|
||||||
|
return initial
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(LongSeriesCreate, self).get_context_data(**kwargs)
|
context = super(LongSeriesCreate, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
if self.request.POST:
|
if self.request.POST:
|
||||||
context["image_formset"] = LongSeriesImageFormSet(
|
context["image_formset"] = LongSeriesImageFormSet(
|
||||||
self.request.POST, self.request.FILES
|
self.request.POST, self.request.FILES
|
||||||
@@ -291,6 +307,46 @@ class LongSeriesCreate(LoginRequiredMixin, CreateView):
|
|||||||
else:
|
else:
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
|
|
||||||
|
class LongSeriesUpdate(LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView):
|
||||||
|
model = LongSeries
|
||||||
|
form_class = LongSeriesForm
|
||||||
|
|
||||||
|
# fields = '__all__'
|
||||||
|
# #fields = [ 'condition' ]
|
||||||
|
# #initial = {'date_of_death': '05/01/2018'}
|
||||||
|
# exclude = [ 'created_date', 'published_date' ]
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(LongSeriesUpdate, self).get_context_data(**kwargs)
|
||||||
|
if self.request.POST:
|
||||||
|
context["image_formset"] = LongSeriesImageFormSet(
|
||||||
|
self.request.POST, self.request.FILES, instance=self.object
|
||||||
|
)
|
||||||
|
context["image_formset"].full_clean()
|
||||||
|
else:
|
||||||
|
context["image_formset"] = LongSeriesImageFormSet(instance=self.object)
|
||||||
|
return context
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
|
||||||
|
self.object = form.save(commit=False)
|
||||||
|
self.object.save()
|
||||||
|
|
||||||
|
# Do this in the form.save()
|
||||||
|
#new_exams = list(form.cleaned_data['exams'].values_list("pk", flat=True))
|
||||||
|
#self.object.exams.clear()
|
||||||
|
#self.object.exams.add(*new_exams)
|
||||||
|
|
||||||
|
context = self.get_context_data(form=form)
|
||||||
|
image_formset = context["image_formset"]
|
||||||
|
# logger.debug(formset.is_valid())
|
||||||
|
if image_formset.is_valid():
|
||||||
|
response = super().form_valid(form)
|
||||||
|
image_formset.instance = self.object
|
||||||
|
image_formset.save()
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return super().form_invalid(form)
|
||||||
|
|
||||||
class LongCreateBase(LoginRequiredMixin, CreateView):
|
class LongCreateBase(LoginRequiredMixin, CreateView):
|
||||||
model = Long
|
model = Long
|
||||||
form_class = LongForm
|
form_class = LongForm
|
||||||
@@ -309,8 +365,16 @@ class LongCreateBase(LoginRequiredMixin, CreateView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|
||||||
self.object = form.save(commit=False)
|
self.object = form.save(commit=False)
|
||||||
|
|
||||||
|
# Add exam objects
|
||||||
|
|
||||||
self.object.save()
|
self.object.save()
|
||||||
|
|
||||||
|
# Do this in the form.save()
|
||||||
|
#new_exams = list(form.cleaned_data['exams'].values_list("pk", flat=True))
|
||||||
|
#self.object.exams.clear()
|
||||||
|
#self.object.exams.add(*new_exams)
|
||||||
|
|
||||||
form.instance.author.add(self.request.user.id)
|
form.instance.author.add(self.request.user.id)
|
||||||
|
|
||||||
context = self.get_context_data(form=form)
|
context = self.get_context_data(form=form)
|
||||||
@@ -377,6 +441,11 @@ class LongUpdate(LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView):
|
|||||||
self.object = form.save(commit=False)
|
self.object = form.save(commit=False)
|
||||||
self.object.save()
|
self.object.save()
|
||||||
|
|
||||||
|
# Do this in the form.save()
|
||||||
|
#new_exams = list(form.cleaned_data['exams'].values_list("pk", flat=True))
|
||||||
|
#self.object.exams.clear()
|
||||||
|
#self.object.exams.add(*new_exams)
|
||||||
|
|
||||||
form.instance.author.add(self.request.user.id)
|
form.instance.author.add(self.request.user.id)
|
||||||
|
|
||||||
context = self.get_context_data(form=form)
|
context = self.get_context_data(form=form)
|
||||||
|
|||||||
Reference in New Issue
Block a user