begin work on creating the zip file within an output directory
# pylint: disable = too-many-lines, redefined-outer-name
""
-import base64
-import io
import pathlib
import shutil
import tempfile
@@ -42,16 +40,24 @@ ANON_DEMOGRAPHIC_FILE = HERE.joinpath("demographic.000000")
patient_directory
+# TODO: Determine output directory
+
+
+if st.button("Copy and Anonymise"):
with tempfile.TemporaryDirectory() as temp_dir:
pl_temp_dir = pathlib.Path(temp_dir)
new_temp_location = pl_temp_dir.joinpath(patient_directory.name)
+ "Copying to temp directory, skipping DICOM files..."
+
shutil.copytree(
patient_directory,
new_temp_location,
ignore=shutil.ignore_patterns("*.DCM", "demographic.*"),
)
+ "Creating anonymised demographic file..."
+
new_demographic_file = new_temp_location.joinpath(f"demographic.{patient_id}")
shutil.copy2(ANON_DEMOGRAPHIC_FILE, new_demographic_file)
@@ -63,6 +69,8 @@ with tempfile.TemporaryDirectory() as temp_dir:
with open(new_demographic_file, "w") as f:
f.writelines(demographic_data)
+ "Creating zip file..."
+
new_temp_zip_file = pl_temp_dir.joinpath(f"{patient_id}.zip")
shutil.make_archive(
@@ -71,14 +79,3 @@ with tempfile.TemporaryDirectory() as temp_dir:
root_dir=str(pl_temp_dir.resolve()),
base_dir=f"{patient_directory.name}",
)
-
- with open(new_temp_zip_file, "rb") as fh:
- buf = io.BytesIO(fh.read())
-
-
-b64 = base64.b64encode(buf.getvalue())
-
-st.markdown(
- f'<a href="data:application/octet-stream;base64,{b64.decode()}" download="{patient_id}.zip">Download Anonymised Data</a>',
- unsafe_allow_html=True,
-)
