{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Deidentify DICOM files\n\nUse this script to deidentify DICOM files in external storage.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from pathlib import Path\nfrom typing import List\n\nfrom encord import EncordUserClient\n\n\ndef deidentify(\n integration_title: str,\n dicom_urls: List[str],\n) -> List[str]:\n # Authentication: adapt the following line to your private key path\n private_key_path = Path.home() / \".ssh\" / \"id_ed25519\"\n\n with private_key_path.open() as f:\n private_key = f.read()\n\n user_client = EncordUserClient.create_with_ssh_private_key(private_key)\n\n integration_hash = None\n\n # Find integration_hash for requested integration_title\n for integration in user_client.get_cloud_integrations():\n if integration.title == integration_title:\n integration_hash = integration.id\n\n if not integration_hash:\n raise Exception(\n f\"Intgration with integration_title={integration_title} not found\"\n )\n\n deidentified_dicom_urls = []\n\n for dicom_url in dicom_urls:\n # requesting deidentification with batch == 1\n deidentified_dicom_url = user_client.deidentify_dicom_files(\n dicom_urls=[dicom_url],\n integration_hash=integration_hash,\n )[0]\n print(f\"Deidentified url: {deidentified_dicom_url}\")\n deidentified_dicom_urls.append(deidentified_dicom_url)\n\n return deidentified_dicom_urls\n\n\n_integration_title = \"deid-demo-0dae9c7b-integration\"\n_dicom_urls = [\n \"s3://deid-demo-0dae9c7b/dicom_0.dcm\",\n \"s3://deid-demo-0dae9c7b/dicom_1.dcm\",\n]\n_deidentified_dicom_urls = deidentify(_integration_title, _dicom_urls)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.17" } }, "nbformat": 4, "nbformat_minor": 0 }