Archive studies to NAS share

Hi, Orthanc Team!

Looking for a best way to archive studies to archive NAS from Orthanc

Need to be archived:



<“PatientID1” - “PatientName1”>.zip
<“PatientID2” - “PatientName2”>.zip

I can studies for a day by
curl -X POST http://localhost:8042/tools/find -d ‘{“Level”:“Study”,“Expand”:false,“Query”:{“StudyDate”:“20211215-20211215”}}’

PatientID and PatinentName can found by
curl http://localhost:8042/studies/f5009020-4969c539-2098a2f8-7c5cfb3a-55d84da8

and can get study archive by
curl http://localhost:8042/studies/f5009020-4969c539-2098a2f8-7c5cfb3a-55d84da8/archive > archive.zip

BUT I need automate this process.

Any suggestions?

Best regards!

Hello,

You might be interested in the following sample Python script that is part of the Orthanc source distribution:

https://hg.orthanc-server.com/orthanc/file/tip/OrthancServer/Resources/Samples/Python/ArchiveStudiesInTimeRange.py

You could also have a look at the WebDAV support:
https://book.orthanc-server.com/users/webdav.html

Sébastien-

Hello!

Thanks for Python script.

Trying it at Debian 11
1.
:~$ /usr/bin/python3 /home/dicom/ArchiveStudiesInTimeRange.py
File “/home/dicom/ArchiveStudiesInTimeRange.py”, line 39
print ‘“%s” is not a valid date!\n’ % date
^
SyntaxError: Missing parentheses in call to ‘print’. Did you mean print(‘“%s” is not a valid date!\n’ % date)?

modified to print(‘“%s” is not a valid date!\n’ % date)
then run and got error 2
2.

:~$ /usr/bin/python3 /home/dicom/ArchiveStudiesInTimeRange.py http://10.21.25.250:8042/ 20211215 /srv/irpen-synology/
Traceback (most recent call last):
File “/home/dicom/ArchiveStudiesInTimeRange.py”, line 27, in
import RestToolbox
ModuleNotFoundError: No module named ‘RestToolbox’

Downloaded https://hg.orthanc-server.com/orthanc/file/tip/OrthancServer/Resources/Samples/Python/RestToolbox.py
put it same folder as ArchiveStudiesInTimeRange.py
run again and got error 3:

  1. TypeError: a bytes-like object is required, not ‘str’

:~$ /usr/bin/python3 /home/dicom/ArchiveStudiesInTimeRange.py http://10.21.25.250:8042/ 20211214 20211215 /srv/irpen-synology/
Traceback (most recent call last):
File “/home/dicom/ArchiveStudiesInTimeRange.py”, line 87, in
filename = filename.encode(‘ascii’, errors = ‘replace’).translate(None, r"'/:*?"<>|!=").strip()
TypeError: a bytes-like object is required, not ‘str’

:frowning:

Done it!

it need to be install python2 and all works fine!

Thanks to all!

Hello,

FYI, I have just fixed compatibility of this sample script against Python3 with the following changeset:
https://hg.orthanc-server.com/orthanc/rev/ffc03a1d60c3

Sébastien-

Hello again.
Seems strange things

At Orthanc i can see 91 study, buy script archives 89

Без названия.png

Any ideas why?

You’ve imported 89 folders and you get 91 studies. One folder may contain data from more than one study.

HTH,

Alain.

Без названия.png

Hi all. Have a question: how correct send username and password to this python script?
https://hg.orthanc-server.com/orthanc/file/tip/OrthancServer/Resources/Samples/Python/ArchiveStudiesInTimeRange.py

got next exeption without credentials
Traceback (most recent call last):
File “/home/urik/OrthancTools/scripts/ArchiveStudiesInTimeRange.py”, line 61, in
for studyId in RestToolbox.DoGet(‘%s/studies’ % URL):
File “/home/urik/OrthancTools/scripts/RestToolbox.py”, line 65, in DoGet
raise Exception(resp.status)
Exception: 401

Hello,

You should be able to do so by adding a call to “RestToolbox.SetCredentials()”, that is defined in the following file:
https://hg.orthanc-server.com/orthanc/file/Orthanc-1.11.3/OrthancServer/Resources/Samples/Python/RestToolbox.py

HTH,
Sébastien-

in these scripts
https://hg.orthanc-server.com/orthanc/file/Orthanc-1.11.3/OrthancServer/Resources/Samples/ImportDicomFiles
i can find autorization but i can’t compile something working for archiving script.
=(
I’m not so strong in programming

Anyone who knows python able to help?