imaging_api.services.upload =========================== .. py:module:: imaging_api.services.upload Attributes ---------- .. autoapisummary:: imaging_api.services.upload.XNAT_URL imaging_api.services.upload.BASE_IMAGES_DOWNLOAD_DIR imaging_api.services.upload.router Functions --------- .. autoapisummary:: imaging_api.services.upload.upload_data_to_xnat imaging_api.services.upload.create_xnat_scan imaging_api.services.upload.create_xnat_resource imaging_api.services.upload.check_file_exists_in_xnat imaging_api.services.upload.upload_file_to_xnat Module Contents --------------- .. py:data:: XNAT_URL .. py:data:: BASE_IMAGES_DOWNLOAD_DIR .. py:data:: router .. py:function:: upload_data_to_xnat(central_hub_project_id: str, accession_id: str, net_id: str, scan_id: str, resource_id: str, files_relative_paths_to_upload: list[str], exist_ok: bool, headers: dict[str, str]) -> list[str] :async: Uploads image files to XNAT under a specific project, experiment, and scan. :param central_hub_project_id: The central hub project ID in which the experiment belongs to. Corresponds to :type central_hub_project_id: str :param XNAT secondary ID.: :param accession_id: The unique value for a study stored in PACS. Corresponds to XNAT experiment label. :type accession_id: str :param net_id: The ID of the FL net that will run the training. :type net_id: str :param scan_id: The ID of the scan in XNAT. Will be created if it does not exist. :type scan_id: str :param resource_id: XNAT resource type e.g DICOM/NIFTI. Custom value is allowed. Will be created if it does not :type resource_id: str :param exist.: :param files_relative_paths_to_upload: List of relative file paths to be uploaded. :type files_relative_paths_to_upload: list[str] :param exist_ok: Whether to overwrite the file if it already exists. :type exist_ok: bool :param headers: XNAT authentication headers. :type headers: dict[str, str] :returns: List of URLs of the uploaded files. :rtype: list[str] :raises FileNotFoundError: If any of the files to be uploaded are not found. :raises ValueError: If the net ID or any file path attempts path traversal outside the upload directory. .. py:function:: create_xnat_scan(project_id: str, subject_id: str, experiment_id_or_label: str, scan_id: str, headers: dict[str, str]) -> None Creates a scan in XNAT if it does not exist. Normally when we upload a file to XNAT, the scan will already exist. TODO reassess if this function is necessary -- could require the scan to exist In order to create a scan, you must specify the xsiType of the scan. See https://wiki.xnat.org/xnat-api/image-session-scans-api#ImageSessionScansAPI-AddScanToAnImageSession TODO Note this is hardcoded to MR scans below (xsiType=xnat:mrScanData), but it is not really used for anything. Note this function will not complain if the scan already exists. :param project_id: The ID of the XNAT project. :type project_id: str :param subject_id: The ID of the subject in XNAT. :type subject_id: str :param experiment_id_or_label: The ID or label of the experiment in XNAT. :type experiment_id_or_label: str :param scan_id: The ID of the scan in XNAT. :type scan_id: str :param headers: XNAT authentication headers. :type headers: dict[str, str] :returns: None :raises Exception: If there is an error during the creation of the scan. .. py:function:: create_xnat_resource(project_id: str, subject_id: str, experiment_id_or_label: str, scan_id: str, resource_id: str, headers: dict[str, str]) -> None Creates a resource folder under a scan in XNAT if it does not exist. A resource can have any name, but it is typically "DICOM" or "NIFTI". :param project_id: The ID of the XNAT project. :type project_id: str :param subject_id: The ID of the subject in XNAT. :type subject_id: str :param experiment_id_or_label: The ID or label of the experiment in XNAT. :type experiment_id_or_label: str :param scan_id: The ID of the scan in XNAT. :type scan_id: str :param resource_id: The ID of the resource in XNAT. :type resource_id: str :param headers: XNAT authentication headers. :type headers: dict[str, str] :returns: None :raises AlreadyExistsError: If the resource already exists in XNAT. :raises Exception: If there is an error during the creation of the resource. .. py:function:: check_file_exists_in_xnat(check_url: str, headers: dict[str, str]) -> bool Checks if a file already exists in XNAT. :param check_url: The URL to check for the file. :type check_url: str :param headers: XNAT authentication headers. :type headers: dict[str, str] :returns: True if the file exists, False otherwise. :rtype: bool .. py:function:: upload_file_to_xnat(project_id: str, subject_id: str, experiment_id_or_label: str, scan_id: str, resource_id: str, file_path: str, exist_ok: bool, headers: dict[str, str]) -> str Uploads a file to the specified resource in XNAT. :param project_id: The ID of the XNAT project. :type project_id: str :param subject_id: The ID of the subject in XNAT. :type subject_id: str :param experiment_id_or_label: The ID or label of the experiment in XNAT. :type experiment_id_or_label: str :param scan_id: The ID of the scan in XNAT. :type scan_id: str :param resource_id: The ID of the resource in XNAT, for example "DICOM" or "NIFTI". :type resource_id: str :param file_path: The path to the file to be uploaded. :type file_path: str :param exist_ok: Whether to overwrite the file if it already exists. :type exist_ok: bool :param headers: XNAT authentication headers. :type headers: dict[str, str] :returns: The URL of the uploaded file. :rtype: str :raises AlreadyExistsError: If exist_ok is False and a file with the same name already exists in the specified XNAT :raises resource.: :raises Exception: If there is an error during the upload process.