From cb4e2f9fa79a21617949dd3e381c2073765eb647 Mon Sep 17 00:00:00 2001 From: Maxime Mulder Date: Wed, 13 Nov 2024 15:22:35 -0500 Subject: [PATCH] misc fixes --- python/lib/api/client.py | 5 +++-- python/lib/api/endpoints/dicom.py | 8 +++++--- python/lib/api/models/dicom.py | 33 ++++++++++++++++++------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/python/lib/api/client.py b/python/lib/api/client.py index 6a7f8b2ad..cda93fbed 100644 --- a/python/lib/api/client.py +++ b/python/lib/api/client.py @@ -23,19 +23,19 @@ def get( 'Authorization': f'Bearer {self.api_token}', } - print(f'https://{self.loris_url}/api/{version}/{route}') - try: response = requests.get( f'https://{self.loris_url}/api/{version}/{route}', headers=headers, json=json, + allow_redirects=False, ) response.raise_for_status() return response except HTTPError as error: # TODO: Better error handling + print(error.response.status_code) print(error.response.text) exit(0) @@ -58,6 +58,7 @@ def post( data=data, json=json, files=files, + allow_redirects=False, ) response.raise_for_status() diff --git a/python/lib/api/endpoints/dicom.py b/python/lib/api/endpoints/dicom.py index 4fb0619ed..92a463d12 100644 --- a/python/lib/api/endpoints/dicom.py +++ b/python/lib/api/endpoints/dicom.py @@ -2,7 +2,7 @@ import os from lib.api.client import ApiClient -from lib.api.models.dicom import GetDicom, GetDicomProcess, GetDicomProcesses +from lib.api.models.dicom import GetDicom, GetDicomProcess, GetDicomProcesses, PostDicomProcesses def get_candidate_dicom(api: ApiClient, cand_id: int, visit_label: str): @@ -34,7 +34,7 @@ def post_candidate_dicom( } response = api.post('v0.0.4-dev', f'candidates/{cand_id}/{visit_label}/dicoms', data=data, files=files) - return response + return response.headers['Location'] def get_candidate_dicom_archive(api: ApiClient, cand_id: int, visit_label: str, tar_name: str): @@ -53,12 +53,14 @@ def post_candidate_dicom_processes(api: ApiClient, cand_id: int, visit_label: st 'MriUploadID': upload_id, } - api.post( + response = api.post( 'v0.0.4-dev', f'/candidates/{cand_id}/{visit_label}/dicoms/{tar_name}/processes', json=json, ) + return PostDicomProcesses.model_validate(response.json()) + def get_candidate_dicom_process(api: ApiClient, cand_id: int, visit_label: str, tar_name: str, process_id: int): response = api.get('v0.0.4-dev', f'candidates/{cand_id}/{visit_label}/dicoms/{tar_name}/processes/{process_id}') diff --git a/python/lib/api/models/dicom.py b/python/lib/api/models/dicom.py index 48b1739d0..bd48f244a 100644 --- a/python/lib/api/models/dicom.py +++ b/python/lib/api/models/dicom.py @@ -3,7 +3,7 @@ from pydantic import BaseModel, Field -class GetDicomArchiveSeries(BaseModel): +class DicomArchiveSeries(BaseModel): series_description : str = Field(alias='SeriesDescription') series_number : int = Field(alias='SeriesNumber') echo_time : Optional[str] = Field(alias='EchoTime') @@ -14,35 +14,40 @@ class GetDicomArchiveSeries(BaseModel): series_uid : str = Field(alias='SeriesUID') -class GetDicomArchive(BaseModel): +class DicomArchive(BaseModel): tar_name : str = Field(alias='Tarname') patient_name : str = Field(alias='Patientname') - series : list[GetDicomArchiveSeries] = Field(alias='SeriesInfo') + series : list[DicomArchiveSeries] = Field(alias='SeriesInfo') -class GetDicomMeta(BaseModel): +class DicomMeta(BaseModel): cand_id : int = Field(alias='CandID') visit_label : str = Field(alias='Visit') class GetDicom(BaseModel): - meta : GetDicomMeta = Field(alias='Meta') - tars : list[GetDicomArchive] = Field(alias='DicomTars') + meta : DicomMeta = Field(alias='Meta') + tars : list[DicomArchive] = Field(alias='DicomTars') class GetDicomProcess(BaseModel): - end_time : str = Field(alias='END_TIME') - exit_code : int = Field(alias='EXIT_CODE') - id : int = Field(alias='ID') - pid : int = Field(alias='PID') - progress : str = Field(alias='PROGRESS') - state : str = Field(alias='STATE') + end_time : Optional[str] = Field(alias='END_TIME') + exit_code : Optional[int] = Field(alias='EXIT_CODE') + id : int = Field(alias='ID') + pid : int = Field(alias='PID') + progress : str = Field(alias='PROGRESS') + state : str = Field(alias='STATE') -class GetDicomUpload(BaseModel): +class DicomUpload(BaseModel): upload_id : int = Field(alias='MriUploadID') processes : list[GetDicomProcess] = Field(alias='Processes') +class PostDicomProcesses(BaseModel): + link : str = Field(alias='Link') + processes : list[GetDicomProcess] = Field(alias='ProcessState') + + class GetDicomProcesses(BaseModel): - uploads : list[GetDicomUpload] = Field(alias='MriUploads') + uploads : list[DicomUpload] = Field(alias='MriUploads')