Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maximemulder committed Nov 13, 2024
1 parent b7e5fee commit cb4e2f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
5 changes: 3 additions & 2 deletions python/lib/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -58,6 +58,7 @@ def post(
data=data,
json=json,
files=files,
allow_redirects=False,
)

response.raise_for_status()
Expand Down
8 changes: 5 additions & 3 deletions python/lib/api/endpoints/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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}')
Expand Down
33 changes: 19 additions & 14 deletions python/lib/api/models/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')

0 comments on commit cb4e2f9

Please sign in to comment.