Mercurial > hg > orthanc-stone
annotate UnitTestsSources/SortedFramesCreateTest.py @ 1835:6c252e51008d
no more need of "-DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES" to dynamically link against system-wide orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 12 Jun 2021 09:01:40 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1477 | 1 #!/usr/bin/env python |
2 | |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
3 # Stone of Orthanc |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
7 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
9 # modify it under the terms of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
10 # as published by the Free Software Foundation, either version 3 of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
11 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
12 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
16 # Affero General Public License for more details. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
17 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
20 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
21 |
1477 | 22 import pprint |
23 import requests | |
24 import sys | |
25 | |
26 if len(sys.argv) != 2: | |
27 print('Usage: %s [Orthanc series ID]' % sys.argv[0]) | |
28 print('Example: %s 4d04593b-953ced51-87e93f11-ae4cf03c-25defdcd | xclip -selection c -t text/plain' % sys.argv[0]) | |
29 exit(-1) | |
30 | |
31 SERIES = sys.argv[1] | |
32 | |
33 r = requests.get('http://localhost:8042/series/%s/study' % SERIES) | |
34 r.raise_for_status() | |
35 print(' // From patient %s' % r.json() ['PatientMainDicomTags']['PatientName']) | |
36 | |
37 r = requests.get('http://localhost:8042/series/%s' % SERIES) | |
38 r.raise_for_status() | |
39 | |
40 first = True | |
41 | |
42 for instance in r.json() ['Instances']: | |
43 tags = requests.get('http://localhost:8042/instances/%s/tags?short' % instance) | |
44 tags.raise_for_status() | |
45 | |
46 if first: | |
47 print(''' | |
48 Orthanc::DicomMap tags; | |
49 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "%s", false); | |
50 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "%s", false); | |
51 OrthancStone::SortedFrames f; | |
52 ''' % (tags.json() ['0020,000d'], tags.json() ['0020,000e'])) | |
53 first = False | |
54 | |
55 print(' tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "%s", false);' % instance) | |
56 | |
57 if '0020,0032' in tags.json(): | |
58 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "%s", false);' % | |
59 tags.json() ['0020,0032'].replace('\\', '\\\\')) | |
60 | |
61 if '0020,0037' in tags.json(): | |
62 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "%s", false);' % | |
63 tags.json() ['0020,0037'].replace('\\', '\\\\')) | |
64 | |
65 if '0020,0013' in tags.json(): | |
66 print(' tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "%s", false);' % | |
67 tags.json() ['0020,0013'].replace('\\', '\\\\')) | |
68 | |
69 if '0054,1330' in tags.json(): | |
70 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_INDEX, "%s", false);' % | |
71 tags.json() ['0054,1330'].replace('\\', '\\\\')) | |
72 | |
73 print(' f.AddInstance(tags);') | |
74 | |
75 print(' f.Sort();') | |
76 | |
77 r = requests.get('http://localhost:8042/series/%s/ordered-slices' % SERIES) | |
78 r.raise_for_status() | |
79 slices = r.json() ['SlicesShort'] | |
80 | |
81 print(' ASSERT_EQ(%du, f.GetFramesCount());' % len(slices)) | |
82 | |
83 for i in range(len(slices)): | |
1644
4796fb60999e
removing methods from SortedFrames to simplify api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
84 print(' ASSERT_EQ(f.GetInstanceOfFrame(%d).GetSopInstanceUid(), "%s");' % (i, slices[i][0])) |
1477 | 85 |