Skip to content

Commit

Permalink
added getStudies and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjermiah committed Feb 3, 2024
1 parent e4df33e commit 6e9138a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/nbiatoolkit/nbia.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ def getBodyPartCounts(
)
return bodyparts

def getStudies(self, Collection : str, PatientID : str = "", StudyInstanceUID : str = ""
) -> Union[list[dict[str, str]], None]:
PARAMS = self.parsePARAMS(locals())

response = self.query_api(endpoint=NBIA_ENDPOINTS.GET_STUDIES, params=PARAMS)

if not isinstance(response, list):
self.log.error("Expected list, but received: %s", type(response))
return None

return response

def getSeries(
self,
Collection: str = "",
Expand Down Expand Up @@ -359,8 +371,9 @@ def parsePARAMS(self, params: dict) -> dict:

client = NBIAClient(log_level="info")

all = client.getCollections()
pprint(all)
print(client.getStudies(Collection="TCGA-GBM"))
# all = client.getCollections()
# pprint(all)

sub = client.getCollections(prefix="aCrin")
pprint(sub)
# sub = client.getCollections(prefix="aCrin")
# pprint(sub)
2 changes: 2 additions & 0 deletions src/nbiatoolkit/utils/nbia_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class NBIA_ENDPOINTS(Enum):
GET_BODY_PART_PATIENT_COUNT = "getBodyPartValuesAndCounts"
GET_NEW_PATIENTS_IN_COLLECTION = "NewPatientsInCollection"

GET_STUDIES = "v2/getPatientStudy"

GET_SERIES = "v2/getSeries"
DOWNLOAD_SERIES = "v2/getImageWithMD5Hash"

Expand Down
7 changes: 7 additions & 0 deletions tests/test_nbia.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def test_getPatientsByCollectionAndModality(nbia_patientsByCollectionAndModality
assert isinstance(nbia_patientsByCollectionAndModality[0], str)
assert len(nbia_patientsByCollectionAndModality[0]) > 0

def test_getStudies(nbia_client, nbia_collections):
studies = nbia_client.getStudies(Collection=nbia_collections[0])
assert studies is not None
assert isinstance(studies, list)
assert len(studies) > 0
assert isinstance(studies[0], dict)

def test_getSeries(nbia_client, nbia_collections, nbia_patients):
seriesList = nbia_client.getSeries(
Collection=nbia_collections[0],
Expand Down

0 comments on commit 6e9138a

Please sign in to comment.