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