Skip to content

Commit

Permalink
use async client for orthanc
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Jan 16, 2024
1 parent cff1099 commit 9ca98ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
22 changes: 13 additions & 9 deletions orthanc_push/orthanc_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from chrisapp.base import ChrisApp
import os
import glob
from pyorthanc import Orthanc, RemoteModality
# from pyorthanc import Orthanc, RemoteModality
from orthanc_api_client import OrthancApiClient
import logging
import sys
import time
Expand Down Expand Up @@ -258,29 +259,32 @@ def run(self, options):
log_file = os.path.join(options.outputdir, 'terminal.log')
logger.add(log_file)

orthanc = Orthanc(options.orthancUrl,username=options.username,password=options.password)
# orthanc = Orthanc(options.orthancUrl,username=options.username,password=options.password)
orthanc = OrthancApiClient(options.orthancUrl,user=options.username,pwd=options.password)
dcm_str_glob = '%s/%s' % (options.inputdir,options.inputFileFilter)
l_dcm_datapath = glob.glob(dcm_str_glob, recursive=True)

modality = RemoteModality(orthanc,options.pushToRemote)
# modality = RemoteModality(orthanc,options.pushToRemote)

data={}
instances_ids=[]
for dcm_datapath in l_dcm_datapath:
LOG(f"Pushing dicom: {dcm_datapath} to orthanc")
with open(dcm_datapath, 'rb') as file:

try:
data = orthanc.post_instances(file.read())
# data = orthanc.post_instances(file.read())
instances_ids = orthanc.upload(file.read())
except Exception as err:
LOG(f'{err} \n')

if len(options.pushToRemote)>0:
resource_id = data['ID']
LOG(f'Pushing resource {resource_id} to {options.pushToRemote} \n')

# resource_id = data['ID']
LOG(f'Pushing resource {instances_ids} to {options.pushToRemote} \n')
try:
response = modality.store( {'Resources':[resource_id]})
LOG(f'Response : {response}\n')
# response = modality.store( {'Resources':[resource_id]})
response = orthanc.modalities.send(options.pushToRemote,resources_ids=instances_ids)
LOG('Response : {Success}\n')
except Exception as err:
LOG(f'{err} \n')

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
chrisapp~=2.5.3
nose~=1.3.7
pyorthanc
# pyorthanc
orthanc-api-client~=0.14.4
loguru
pftag==1.2.22
pflog==1.2.26
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name = 'orthanc_push',
version = '1.2.2',
version = '1.2.3',
description = 'An app to push/upload dicoms to an orthanc server',
long_description = readme,
author = 'FNNDSC',
Expand Down

0 comments on commit 9ca98ef

Please sign in to comment.