Skip to content

Commit 160a60e

Browse files
committed
[Improvement] Cleaned data persistence among page reloads
1 parent d82a275 commit 160a60e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

python/main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,29 @@ def authenticate(credentials: HTTPBasicCredentials = Depends(security)) -> bool:
202202
return True
203203

204204

205+
@app.get("/check_existence_of_clean")
206+
async def check_existence_of_clean() -> UploadFilesResponse:
207+
208+
session_fp = "./tmp/session-data/clean/de-identified-files/session.json"
209+
proper_dicom_paths = sorted(glob.glob("./tmp/session-data/clean/de-identified-files/**/*.dcm", recursive = True))
210+
total_uploaded_file_bytes = 0
211+
skip_deidentification = True
212+
if os.path.exists(session_fp) and len(proper_dicom_paths) != 0:
213+
for dcm_fp in proper_dicom_paths:
214+
total_uploaded_file_bytes += sys.getsizeof(dcm_fp)
215+
total_uploaded_file_megabytes = "%.1f" % (
216+
total_uploaded_file_bytes / (10**3) ** 2
217+
)
218+
else:
219+
total_uploaded_file_megabytes = 0
220+
221+
return UploadFilesResponse(
222+
n_uploaded_files=len(proper_dicom_paths),
223+
total_size=total_uploaded_file_megabytes,
224+
skip_deidentification=skip_deidentification,
225+
)
226+
227+
205228
@app.get("/", response_class=HTMLResponse, dependencies=[Depends(authenticate)])
206229
async def get_root(request: Request) -> HTMLResponse:
207230
return templates.TemplateResponse("index.html", {"request": request})

python/static/script.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,27 @@ nextSlice.addEventListener("click", function () {
400400
DICOMSlider.dispatchEvent(new Event("input"));
401401
});
402402

403+
document.addEventListener("DOMContentLoaded", function() {
404+
check_existence_of_clean();
405+
});
406+
407+
async function check_existence_of_clean()
408+
{
409+
const dcm_files_response = await fetch
410+
(
411+
'/check_existence_of_clean',
412+
{
413+
method: 'GET'
414+
}
415+
);
416+
const dcm_files = await dcm_files_response.json();
417+
if (dcm_files_response.ok && dcm_files.n_uploaded_files > 0)
418+
{
419+
skip_deidentification = dcm_files.skip_deidentification
420+
await submit_dicom_processing_request();
421+
}
422+
}
423+
403424
function base64torgba(encodedData) {
404425
const binaryString = window.atob(encodedData);
405426
const len = binaryString.length;
@@ -611,7 +632,14 @@ async function submit_dicom_processing_request()
611632
}
612633
}
613634
document.body.style.cursor = 'default';
614-
showNotification("success", "DICOM files are now de-identified", 3000);
635+
if (skip_deidentification)
636+
{
637+
showNotification("success", "Loaded de-identified DICOM files", 3000);
638+
}
639+
else
640+
{
641+
showNotification("success", "DICOM files are now de-identified", 3000);
642+
}
615643
}
616644

617645
async function get_mask_from_file() {

0 commit comments

Comments
 (0)