{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Checking if all the patients were scanned in a supine position\n### If any patient isn't suppine I would need to add some code to change the position of that patient","metadata":{}},{"cell_type":"code","source":"import os\nimport pydicom as dicom\nimport pandas as pd\nimport sys\nfrom tqdm.notebook import tqdm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-24T15:15:47.743172Z","iopub.execute_input":"2023-08-24T15:15:47.743794Z","iopub.status.idle":"2023-08-24T15:15:47.923579Z","shell.execute_reply.started":"2023-08-24T15:15:47.74374Z","shell.execute_reply":"2023-08-24T15:15:47.92229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = \"../input/rsna-2023-abdominal-trauma-detection\"\n        \nTASK = 'test'\n\nCSV_METADATA = f'{TASK}_series_meta.csv'\nFOLDER_IMG = f'{TASK}_images'","metadata":{"execution":{"iopub.status.busy":"2023-08-24T15:17:27.82033Z","iopub.execute_input":"2023-08-24T15:17:27.820817Z","iopub.status.idle":"2023-08-24T15:17:27.82746Z","shell.execute_reply.started":"2023-08-24T15:17:27.820781Z","shell.execute_reply":"2023-08-24T15:17:27.825677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_info(folder): \n    try:\n        filenames = os.listdir(folder)\n    except FileNotFoundError as e:\n        print(f\"Error: {e}\\nFolder: {folder}\")\n        return\n    \n    filenames = [str(filenames[0].split('.')[0])]\n    filename = [str(filenames[0]) + '.dcm']\n    fd = os.path.join(folder, filename[0])   # first dicom\n    \n    try:\n        ds = dicom.dcmread(fd)\n    except Exception as e:\n        print(f\"Error: {e}\\nFile: {fd}\")\n        return\n        \n    if 'FFS' == ds.PatientPosition:\n        return\n    elif 'HFS' == ds.PatientPosition:\n        return\n    else:\n        sys.exit(1)\n        \n# Read the file with the metadata\nmeta_df = pd.read_csv(f\"{BASE_PATH}/{CSV_METADATA}\")\npatients = meta_df[\"patient_id\"].unique()\n\n# Dataframe with only the patients list\ndf_patients = pd.DataFrame(patients, columns=['patient_id'])\n\n# Get the images for a patient at time\nfor pidx, patient in enumerate(tqdm(patients)):\n    files, images = [], []\n    \n    series = meta_df[meta_df['patient_id'] == patient]['series_id']\n    paths = BASE_PATH + '/' + FOLDER_IMG + '/' + patient.astype(str) + '/' + series.astype(str)\n    series_paths = paths.tolist()\n\n    for serie in series_paths:\n        get_info(serie)\n        \n\"\"\" Copy the sample submission, just to check if the notebook finish \"\"\" \n!cp ../input/rsna-2023-abdominal-trauma-detection/sample_submission.csv submission.csv","metadata":{"execution":{"iopub.status.busy":"2023-08-24T15:21:25.046642Z","iopub.execute_input":"2023-08-24T15:21:25.047989Z","iopub.status.idle":"2023-08-24T15:21:26.225237Z","shell.execute_reply.started":"2023-08-24T15:21:25.047934Z","shell.execute_reply":"2023-08-24T15:21:26.223774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}