nbiatoolkit.utils

Submodules

Package Contents

Classes

NBIA_ENDPOINTS

This enum class defines the NBIA endpoints used in the NBIA toolkit.

NBIA_BASE_URLS

This enum class defines the NBIA base URLs used in the NBIA toolkit.

ReturnType

Generic enumeration.

Functions

validateMD5(→ bool)

convertMillis(→ str)

Convert milliseconds to a formatted date string.

clean_html(→ str)

Cleans the given HTML string by removing HTML tags and replacing special characters.

convertDateFormat(→ str)

Converts the input date to the desired format.

parse_response(→ List[dict[Any, Any]])

Response will be either JSON or bytes

conv_response_list(→ List[dict[Any, ...)

Function that takes in a list of dictionaries and returns either a list or a dataframe.

class nbiatoolkit.utils.NBIA_ENDPOINTS[source]

Bases: enum.Enum

This enum class defines the NBIA endpoints used in the NBIA toolkit.

GET_COLLECTIONS = 'v2/getCollectionValues'
GET_COLLECTION_PATIENT_COUNT = 'getCollectionValuesAndCounts'
GET_COLLECTION_DESCRIPTIONS = 'getCollectionDescriptions'
GET_MODALITY_VALUES = 'v2/getModalityValues'
GET_MODALITY_PATIENT_COUNT = 'getModalityValuesAndCounts'
GET_PATIENTS = 'v2/getPatient'
GET_NEW_PATIENTS_IN_COLLECTION = 'v2/NewPatientsInCollection'
GET_PATIENT_BY_COLLECTION_AND_MODALITY = 'v2/getPatientByCollectionAndModality'
GET_BODY_PART_PATIENT_COUNT = 'getBodyPartValuesAndCounts'
GET_STUDIES = 'v2/getPatientStudy'
GET_SERIES = 'v2/getSeries'
GET_UPDATED_SERIES = 'v2/getUpdatedSeries'
GET_SERIES_METADATA = 'v1/getSeriesMetaData'
DOWNLOAD_SERIES = 'v2/getImageWithMD5Hash'
GET_DICOM_TAGS = 'getDicomTags'
__str__()[source]

Return str(self).

_format()[source]
class nbiatoolkit.utils.NBIA_BASE_URLS[source]

Bases: enum.Enum

This enum class defines the NBIA base URLs used in the NBIA toolkit.

NBIA = 'https://services.cancerimagingarchive.net/nbia-api/services/'
NLST = 'https://nlst.cancerimagingarchive.net/nbia-api/services/'
LOGOUT_URL = 'https://services.cancerimagingarchive.net/nbia-api/logout'
__str__()[source]

Return str(self).

_format()[source]
class nbiatoolkit.utils.ReturnType[source]

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

LIST = 'list'
DATAFRAME = 'dataframe'
nbiatoolkit.utils.validateMD5(seriesDir: str) bool[source]
nbiatoolkit.utils.convertMillis(millis: int) str[source]

Convert milliseconds to a formatted date string.

Parameters:

millis (int) – The number of milliseconds to convert.

Returns:

The formatted date string in the format ‘YYYY-MM-DD’.

Return type:

str

Raises:

AssertionError – If the input is not an integer.

nbiatoolkit.utils.clean_html(html_string: str) str[source]

Cleans the given HTML string by removing HTML tags and replacing special characters.

Parameters:

html_string (str) – The input HTML string to be cleaned.

Returns:

The cleaned text content without HTML tags and special characters.

Return type:

str

nbiatoolkit.utils.convertDateFormat(input_date: str | datetime.datetime, format: str = '%Y/%m/%d') str[source]

Converts the input date to the desired format.

Parameters:

input_date (str) – The date to be converted.

Returns:

The converted date in the format “YYYY/MM/DD”.

Return type:

str

Raises:

ValueError – If the input date has an invalid format.

nbiatoolkit.utils.parse_response(response: requests.Response) List[dict[Any, Any]][source]

Response will be either JSON or bytes

nbiatoolkit.utils.conv_response_list(response_json: List[dict[Any, Any]], return_type: nbiatoolkit.utils.nbia_endpoints.ReturnType) List[dict[Any, Any]] | pandas.DataFrame[source]

Function that takes in a list of dictionaries and returns either a list or a dataframe.

Parameters:
  • response_json (List[dict[Any, Any]]) – A response from the API in the form of a list of dictionaries.

  • return_type (ReturnType) – The desired return type for the response.

Returns:

Either a list of dictionaries or a DataFrame.

Return type:

List[dict[Any, Any]] | pd.DataFrame