annotate Tests/Tests.py @ 12:15c166240dfb

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Jun 2015 14:33:01 +0200
parents c660a64ce2dd
children 7b69a561f4d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 # Orthanc - A Lightweight, RESTful DICOM Store
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Department, University Hospital of Liege, Belgium
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 #
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # This program is free software: you can redistribute it and/or
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 # modify it under the terms of the GNU General Public License as
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # published by the Free Software Foundation, either version 3 of the
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # License, or (at your option) any later version.
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 #
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful, but
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # General Public License for more details.
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 #
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 import unittest
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
21 from PIL import ImageChops
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 from Toolbox import *
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 _LOCAL = None
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 _REMOTE = None
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 def SetOrthancParameters(local, remote):
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 global _LOCAL, _REMOTE
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 _LOCAL = local
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 _REMOTE = remote
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 class Orthanc(unittest.TestCase):
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 def setUp(self):
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 DropOrthanc(_LOCAL)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 DropOrthanc(_REMOTE)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 def test_system(self):
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 self.assertTrue('Version' in DoGet(_REMOTE, '/system'))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 def test_upload(self):
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 u = UploadInstance(_REMOTE, 'DummyCT.dcm')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 self.assertEqual('Success', u['Status'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 u = UploadInstance(_REMOTE, 'DummyCT.dcm')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 self.assertEqual('AlreadyStored', u['Status'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 self.assertEqual(1, len(DoGet(_REMOTE, '/instances')))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 i = DoGet(_REMOTE, '/instances/%s/simplified-tags' % u['ID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 self.assertEqual('20070101', i['StudyDate'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
5
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
58 def test_upload_2(self):
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID']
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 instance = DoGet(_REMOTE, '/instances/%s' % i)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 self.assertEqual(i, instance['ID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 instance['MainDicomTags']['SOPInstanceUID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 series = DoGet(_REMOTE, '/series/%s' % instance['ParentSeries'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 series['MainDicomTags']['SeriesInstanceUID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 study = DoGet(_REMOTE, '/studies/%s' % series['ParentStudy'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 study['MainDicomTags']['StudyInstanceUID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 patient = DoGet(_REMOTE, '/patients/%s' % study['ParentPatient'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 self.assertEqual('ozp00SjY2xG',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 patient['MainDicomTags']['PatientID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 dicom = DoGet(_REMOTE, '/instances/%s/file' % instance['ID'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 self.assertEqual(2472, len(dicom))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 self.assertEqual('3e29b869978b6db4886355a2b1132124', ComputeMD5(dicom))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i)))
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/simplified-tags' % i)['StationName'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 self.assertEqual('TWINOW', DoGet(_REMOTE, '/instances/%s/tags' % i)['0008,1010']['Value'])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
5
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
85 def test_images(self):
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
86 i = UploadInstance(_REMOTE, 'Phenix/IM-0001-0001.dcm')['ID']
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
87 self.assertEqual(1, len(DoGet(_REMOTE, '/instances/%s/frames' % i)))
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
5
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
89 im = GetImage(_REMOTE, '/instances/%s/preview' % i)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
90 self.assertEqual("L", im.mode)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
91 self.assertEqual(512, im.size[0])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
92 self.assertEqual(358, im.size[1])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
93
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
94 im = GetImage(_REMOTE, '/instances/%s/image-uint8' % i)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
95 self.assertEqual("L", im.mode)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
96 self.assertEqual(512, im.size[0])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
97 self.assertEqual(358, im.size[1])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
98
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
99 im = GetImage(_REMOTE, '/instances/%s/image-uint16' % i)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
100 self.assertEqual(512, im.size[0])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
101 self.assertEqual(358, im.size[1])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
102
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
103 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
104 self.assertEqual("L", im.mode)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
105 self.assertEqual(512, im.size[0])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
106 self.assertEqual(358, im.size[1])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
107
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
108 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint8' % i)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
109 self.assertEqual("L", im.mode)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
110 self.assertEqual(512, im.size[0])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
111 self.assertEqual(358, im.size[1])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
112
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
113 im = GetImage(_REMOTE, '/instances/%s/frames/0/image-uint16' % i)
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
114 self.assertEqual(512, im.size[0])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
115 self.assertEqual(358, im.size[1])
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
116
6
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
117
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
118 def test_hierarchy(self):
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
119 UploadFolder(_REMOTE, 'Brainix/Epi')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
120 UploadFolder(_REMOTE, 'Brainix/Flair')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
121 UploadFolder(_REMOTE, 'Knee/T1')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
122 UploadFolder(_REMOTE, 'Knee/T2')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
123
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
124 p = DoGet(_REMOTE, '/patients')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
125 s = DoGet(_REMOTE, '/studies')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
126 t = DoGet(_REMOTE, '/series')
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
127 self.assertEqual(2, len(p))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
128 self.assertEqual(2, len(s))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
129 self.assertEqual(4, len(t))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
130 self.assertEqual(94, len(DoGet(_REMOTE, '/instances')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
131
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
132 brainixPatient = '16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
133 brainixStudy = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
134 brainixEpi = '2ac1316d-3e432022-62eabff2-c59f5475-9b1ac3f8'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
135 brainixFlair = '1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
136
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
137 kneePatient = 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
138 kneeStudy = '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
139 kneeT1 = '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
140 kneeT2 = 'bbf7a453-0d34251a-03663b55-46bb31b9-ffd74c59'
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
141
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
142 self.assertTrue(brainixPatient in p)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
143 self.assertTrue(kneePatient in p)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
144 self.assertTrue(brainixStudy in s)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
145 self.assertTrue(kneeStudy in s)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
146 self.assertTrue(brainixEpi in t)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
147 self.assertTrue(brainixFlair in t)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
148 self.assertTrue(kneeT1 in t)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
149 self.assertTrue(kneeT2 in t)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
150
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
151 self.assertEqual(44, len(DoGet(_REMOTE, '/patients/%s/instances' % brainixPatient)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
152 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % brainixPatient)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
153 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % brainixPatient)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
154
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
155 self.assertEqual(50, len(DoGet(_REMOTE, '/patients/%s/instances' % kneePatient)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
156 self.assertEqual(2, len(DoGet(_REMOTE, '/patients/%s/series' % kneePatient)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
157 self.assertEqual(1, len(DoGet(_REMOTE, '/patients/%s/studies' % kneePatient)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
158
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
159 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % brainixStudy)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
160 self.assertEqual(44, len(DoGet(_REMOTE, '/studies/%s/instances' % brainixStudy)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
161
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
162 self.assertEqual(2, len(DoGet(_REMOTE, '/studies/%s/series' % kneeStudy)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
163 self.assertEqual(50, len(DoGet(_REMOTE, '/studies/%s/instances' % kneeStudy)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
164
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
165 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixEpi)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
166 self.assertEqual(22, len(DoGet(_REMOTE, '/series/%s/instances' % brainixFlair)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
167 self.assertEqual(24, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT1)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
168 self.assertEqual(26, len(DoGet(_REMOTE, '/series/%s/instances' % kneeT2)))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
169
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
170 for patient in p:
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
171 for study in DoGet(_REMOTE, '/patients/%s/studies' % patient):
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
172 self.assertEqual(patient, study['ParentPatient'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
173 for series in DoGet(_REMOTE, '/studies/%s/series' % study['ID']):
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
174 self.assertEqual(study['ID'], series['ParentStudy'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
175 for instance in DoGet(_REMOTE, '/series/%s/instances' % series['ID']):
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
176 self.assertEqual(series['ID'], instance['ParentSeries'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
177
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
178 self.assertEqual(json.dumps(DoGet(_REMOTE, '/instances/%s/attachments/dicom-as-json/data' % instance['ID'])),
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
179 json.dumps(DoGet(_REMOTE, '/instances/%s/tags' % instance['ID'])))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
180
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
181
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
182 r = DoDelete(_REMOTE, "/studies/%s" % brainixStudy)['RemainingAncestor']
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
183 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
184 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
185 self.assertEqual(2, len(DoGet(_REMOTE, '/series')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
186 self.assertEqual(50, len(DoGet(_REMOTE, '/instances')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
187 self.assertEqual(None, r)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
188
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
189 r = DoDelete(_REMOTE, "/series/%s" % kneeT2)['RemainingAncestor']
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
190 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
191 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
192 self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
193 self.assertEqual(24, len(DoGet(_REMOTE, '/instances')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
194 self.assertEqual('Study', r['Type'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
195 self.assertEqual(kneeStudy, r['ID'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
196
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
197 r = DoDelete(_REMOTE, "/instances/%s" % DoGet(_REMOTE, '/instances')[0])['RemainingAncestor']
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
198 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
199 self.assertEqual(1, len(DoGet(_REMOTE, '/studies')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
200 self.assertEqual(1, len(DoGet(_REMOTE, '/series')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
201 self.assertEqual(23, len(DoGet(_REMOTE, '/instances')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
202 self.assertEqual('Series', r['Type'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
203 self.assertEqual(kneeT1, r['ID'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
204
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
205 r = DoDelete(_REMOTE, "/patients/%s" % kneePatient)['RemainingAncestor']
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
206 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
207 self.assertEqual(0, len(DoGet(_REMOTE, '/studies')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
208 self.assertEqual(0, len(DoGet(_REMOTE, '/series')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
209 self.assertEqual(0, len(DoGet(_REMOTE, '/instances')))
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
210 self.assertEqual(None, r)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
211
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
212 DropOrthanc(_REMOTE)
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
213 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalDiskSize'])
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
214 self.assertEqual('0', DoGet(_REMOTE, '/statistics')['TotalUncompressedSize'])
7
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
215
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
216
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
217 def test_multi_frame(self):
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
218 i = UploadInstance(_REMOTE, 'Multiframe.dcm')['ID']
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
219 self.assertEqual(76, len(DoGet(_REMOTE, '/instances/%s/frames' % i)))
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
220
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
221 im = GetImage(_REMOTE, '/instances/%s/frames/0/preview' % i)
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
222 self.assertEqual("L", im.mode)
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
223 self.assertEqual(512, im.size[0])
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
224 self.assertEqual(512, im.size[1])
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
225
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
226 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint8' % i)
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
227 DoGet(_REMOTE, '/instances/%s/frames/0/image-uint16' % i)
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
228 DoGet(_REMOTE, '/instances/%s/frames/75/preview' % i)
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
229 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/aaa/preview' % i))
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
230 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/76/preview' % i))
302f06f3bba2 test_multi_frame
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
231
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
232
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
233 def test_changes(self):
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
234 # Check emptiness
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
235 c = DoGet(_REMOTE, '/changes')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
236 self.assertEqual(0, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
237 self.assertEqual(0, c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
238 self.assertTrue(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
239 c = DoGet(_REMOTE, '/changes?last')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
240 self.assertEqual(0, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
241 self.assertEqual(0, c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
242 self.assertTrue(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
243
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
244 # Add 1 instance
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
245 i = UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')['ID']
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
246 c = DoGet(_REMOTE, '/changes')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
247 begin = c['Last']
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
248 self.assertEqual(4, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
249 self.assertTrue(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
250 self.assertEqual(c['Changes'][-1]['Seq'], c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
251
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
252 c = DoGet(_REMOTE, '/changes?last')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
253 self.assertEqual(1, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
254 self.assertEqual(begin, c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
255 self.assertTrue(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
256 c = DoGet(_REMOTE, '/changes?limit=1&since=' + str(begin - 1))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
257 self.assertEqual(1, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
258 self.assertEqual(begin, c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
259 self.assertTrue(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
260 c = DoGet(_REMOTE, '/changes?limit=1&since=' + str(begin - 2))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
261 self.assertEqual(1, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
262 self.assertEqual(begin - 1, c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
263 self.assertFalse(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
264 c = DoGet(_REMOTE, '/changes?limit=1&since=' + str(begin - 3))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
265 self.assertEqual(1, len(c['Changes']))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
266 self.assertEqual(begin - 2, c['Last'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
267 self.assertFalse(c['Done'])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
268
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
269 UploadFolder(_REMOTE, 'Knee/T1')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
270 UploadFolder(_REMOTE, 'Knee/T2')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
271 since = begin
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
272 countPatients = 0
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
273 countStudies = 0
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
274 countSeries = 0
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
275 countInstances = 0
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
276 completed = 0
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
277 while True:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
278 c = DoGet(_REMOTE, '/changes', { 'since' : since, 'limit' : 3 })
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
279 since = c['Last']
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
280 for i in c['Changes']:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
281 if i['ResourceType'] == 'Instance':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
282 countInstances += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
283 if i['ResourceType'] == 'Patient':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
284 countPatients += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
285 if i['ResourceType'] == 'Study':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
286 countStudies += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
287 if i['ResourceType'] == 'Series':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
288 countSeries += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
289 if i['ChangeType'] == 'NewInstance':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
290 countInstances += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
291 if i['ChangeType'] == 'NewPatient':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
292 countPatients += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
293 if i['ChangeType'] == 'NewStudy':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
294 countStudies += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
295 if i['ChangeType'] == 'NewSeries':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
296 countSeries += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
297 if i['ChangeType'] == 'CompletedSeries':
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
298 completed += 1
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
299 self.assertTrue('ID' in i)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
300 self.assertTrue('Path' in i)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
301 self.assertTrue('Seq' in i)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
302 if c['Done']:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
303 break
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
304
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
305 self.assertEqual(2 * 50, countInstances)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
306 self.assertEqual(2 * 1, countPatients)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
307 self.assertEqual(2 * 1, countStudies)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
308 self.assertEqual(2 * 2, countSeries)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
309 self.assertEqual(0, completed)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
310
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
311
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
312 def test_archive(self):
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
313 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
314 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
315
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
316 z = GetArchive(_REMOTE, '/patients/%s/archive' % DoGet(_REMOTE, '/patients')[0])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
317 self.assertEqual(2, len(z.namelist()))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
318
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
319 z = GetArchive(_REMOTE, '/studies/%s/archive' % DoGet(_REMOTE, '/studies')[0])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
320 self.assertEqual(2, len(z.namelist()))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
321
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
322 z = GetArchive(_REMOTE, '/series/%s/archive' % DoGet(_REMOTE, '/series')[0])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
323 self.assertEqual(1, len(z.namelist()))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
324
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
325 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
326
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
327 z = GetArchive(_REMOTE, '/patients/%s/archive' % DoGet(_REMOTE, '/patients')[0])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
328 self.assertEqual(2, len(z.namelist()))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
329
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
330
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
331 def test_media_archive(self):
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
332 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
333 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
334
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
335 z = GetArchive(_REMOTE, '/patients/%s/media' % DoGet(_REMOTE, '/patients')[0])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
336 self.assertEqual(3, len(z.namelist()))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
337 self.assertTrue('IMAGES/IM0' in z.namelist())
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
338 self.assertTrue('IMAGES/IM1' in z.namelist())
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
339 self.assertTrue('DICOMDIR' in z.namelist())
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
340
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
341 try:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
342 os.remove('/tmp/DICOMDIR')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
343 except:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
344 # The file does not exist
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
345 pass
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
346
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
347 z.extract('DICOMDIR', '/tmp')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
348 a = subprocess.check_output([ 'dciodvfy', '/tmp/DICOMDIR' ],
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
349 stderr = subprocess.STDOUT).split('\n')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
350 self.assertEqual(3, len(a))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
351 self.assertTrue(a[0].startswith('Warning'))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
352 self.assertEqual('BasicDirectory', a[1])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
353 self.assertEqual('', a[2])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
354
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
355 a = subprocess.check_output([ 'dcentvfy', '/tmp/DICOMDIR' ],
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
356 stderr = subprocess.STDOUT).split('\n')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
357 self.assertEqual(1, len(a))
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
358 self.assertEqual('', a[0])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
359
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
360 a = subprocess.check_output([ 'dcm2xml', '/tmp/DICOMDIR' ])
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
361 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081908590448738', a) != None)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
362 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081909113806560', a) != None)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
363
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 7
diff changeset
364 os.remove('/tmp/DICOMDIR')
10
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
365
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
366
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
367 def test_protection(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
368 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
369 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
370 self.assertEqual(2, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
371 a = DoGet(_REMOTE, '/patients')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
372 b = DoGet(_REMOTE, '/patients')[1]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
373 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
374 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
375 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
376 DoPut(_REMOTE, '/patients/%s/protected' % a, '1', 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
377 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
378 DoPut(_REMOTE, '/patients/%s/protected' % a, '0', 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
379 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
380
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
381
12
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
382 def test_raw_tags(self):
10
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
383 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
384
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
385 dicom = DoGet(_REMOTE, '/instances/%s/file' % i)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
386 self.assertEqual('1a7c56cb02d6e742cc9c856a8ac182e3', ComputeMD5(dicom))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
387
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
388 s = '/instances/%s/content/' % i
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
389
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
390 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, s + '0008-1010').strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
391 self.assertRaises(Exception, lambda: DoGet(_REMOTE, s + '0008-1011'))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
392
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
393 self.assertEqual('Abdomen', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/0/7fe1-1057').strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
394 self.assertEqual('cla_3c', DoGet(_REMOTE, s + '7fe1-1001/0/7fe1-1008/8/7fe1-1057').strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
395
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
396 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
397 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
398 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
399 UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
400
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
401 for i in DoGet(_REMOTE, '/instances'):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
402 aid = DoGet(_REMOTE, '/instances/%s' % i)['MainDicomTags']['SOPInstanceUID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
403 self.assertEqual(aid, DoGet(_REMOTE, '/instances/%s/content/0008-0018' % i).replace(chr(0), ''))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
404
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
405
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
406 def test_raw_tags_mdn(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
407 # Bug reported by Cyril Paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
408 i = UploadInstance(_REMOTE, 'PrivateMDNTags.dcm')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
409 self.assertAlmostEqual(0.000027, DoGet(_REMOTE, '/instances/%s/content/7053-1000' % i))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
410
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
411
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
412 def test_modify_instance(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
413 i = UploadInstance(_REMOTE, 'PrivateTags.dcm')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
414 modified = DoPost(_REMOTE, '/instances/%s/modify' % i,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
415 json.dumps({
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
416 "Replace" : {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
417 "PatientName" : "hello",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
418 #"PatientID" : "world"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
419 },
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
420 "Remove" : [ "StationName" ],
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
421 "RemovePrivateTags" : None
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
422 }),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
423 'application/json')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
424 j = DoPost(_REMOTE, '/instances', modified, 'application/dicom')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
425
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
426 self.assertNotEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
427 #self.assertNotEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % i).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
428 self.assertEqual('LOGIQBOOK', DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
429 DoGet(_REMOTE, '/instances/%s/content/6003-1010' % i) # Some private tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
430
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
431 self.assertEqual('hello', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
432 #self.assertEqual('world', DoGet(_REMOTE, '/instances/%s/content/0010-0020' % j).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
433 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
434 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/6003-1010' % j))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
435
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
436
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
437 def test_modify_series(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
438 # Upload 4 images from the same series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
439 for i in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
440 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
441
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
442 origSeries = DoGet(_REMOTE, '/series')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
443 newSeries = DoPost(_REMOTE, '/series/%s/modify' % origSeries,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
444 '{"Replace":{"PatientName":"Jodogne"}}',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
445 'application/json')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
446
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
447 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['ModifiedFrom'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
448 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
449 self.assertEqual(4, len(instances))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
450 for i in instances:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
451 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
452 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
453 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
454
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
455 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
456 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
457
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
458
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
459 def test_modify_study(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
460 # Upload 4 images from the 2 series of the same study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
461 for i in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
462 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
463 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
464
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
465 origStudy = DoGet(_REMOTE, '/studies')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
466 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
467 '{"Replace":{"PatientName":"Jodogne"}}',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
468 'application/json')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
469
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
470 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['ModifiedFrom'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
471 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
472 self.assertEqual(2, len(series))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
473 for s in series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
474 ss = DoGet(_REMOTE, '/series/%s' % s)['ModifiedFrom']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
475 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
476 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
477
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
478 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
479 for i in instances:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
480 j = DoGet(_REMOTE, '/instances/%s' % i)['ModifiedFrom']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
481 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
482 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
483
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
484 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
485 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
486
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
487
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
488 def test_anonymize_series(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
489 # Upload 4 images from the same series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
490 for i in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
491 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
492
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
493 origSeries = DoGet(_REMOTE, '/series')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
494 newSeries = DoPost(_REMOTE, '/series/%s/anonymize' % origSeries,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
495 '{}',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
496 'application/json')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
497
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
498 self.assertEqual(origSeries, DoGet(_REMOTE, '/series/%s' % newSeries)['AnonymizedFrom'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
499 instances = DoGet(_REMOTE, '/series/%s' % newSeries)['Instances']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
500 self.assertEqual(4, len(instances))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
501 for i in instances:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
502 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
503 self.assertEqual(newSeries, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
504 self.assertEqual(origSeries, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
505
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
506 DoGet(_REMOTE, '/instances/%s/content/0008-1010' % j)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
507 self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/content/0008-1010' % i))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
508
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
509
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
510 def test_anonymize_study(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
511 # Upload 4 images from the 2 series of the same study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
512 for i in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
513 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
514 UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
515
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
516 origStudy = DoGet(_REMOTE, '/studies')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
517 newStudy = DoPost(_REMOTE,'/studies/%s/anonymize' % origStudy,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
518 '{"Replace":{"PatientName":"Jodogne"}}',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
519 'application/json')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
520
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
521 self.assertEqual(origStudy, DoGet(_REMOTE, '/studies/%s' % newStudy)['AnonymizedFrom'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
522 series = DoGet(_REMOTE, '/studies/%s' % newStudy)['Series']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
523 self.assertEqual(2, len(series))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
524 for s in series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
525 ss = DoGet(_REMOTE, '/series/%s' % s)['AnonymizedFrom']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
526 self.assertEqual(newStudy, DoGet(_REMOTE, '/series/%s' % s)['ParentStudy'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
527 self.assertEqual(origStudy, DoGet(_REMOTE, '/series/%s' % ss)['ParentStudy'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
528
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
529 instances = DoGet(_REMOTE, '/series/%s' % s)['Instances']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
530 for i in instances:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
531 j = DoGet(_REMOTE, '/instances/%s' % i)['AnonymizedFrom']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
532 self.assertEqual(s, DoGet(_REMOTE, '/instances/%s' % i)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
533 self.assertEqual(ss, DoGet(_REMOTE, '/instances/%s' % j)['ParentSeries'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
534
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
535 self.assertEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % i).strip())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
536 self.assertNotEqual('Jodogne', DoGet(_REMOTE, '/instances/%s/content/0010-0010' % j).strip())
11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
537
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
538
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
539
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
540 def test_storescu(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
541 # Check emptiness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
542 e = DoGet(_REMOTE, '/exports')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
543 self.assertEqual(0, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
544 self.assertEqual(0, e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
545 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
546 e = DoGet(_REMOTE, '/exports?last')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
547 self.assertEqual(0, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
548 self.assertEqual(0, e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
549 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
550
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
551 # Add 1 instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
552 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
553 self.assertEqual(0, len(DoGet(_LOCAL, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
554
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
555 # Export the instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
556 j = DoPost(_REMOTE, '/modalities/orthanctest/store', str(i), 'text/plain') # instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
557 self.assertEqual(1, len(DoGet(_LOCAL, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
558 self.assertEqual(1, len(DoGet(_LOCAL, '/studies')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
559 self.assertEqual(1, len(DoGet(_LOCAL, '/series')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
560 self.assertEqual(1, len(DoGet(_LOCAL, '/instances')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
561
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
562 e = DoGet(_REMOTE, '/exports')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
563 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
564 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
565 self.assertEqual(e['Exports'][-1]['Seq'], e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
566 e = DoGet(_REMOTE, '/exports?limit=1')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
567 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
568 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
569 self.assertEqual(e['Exports'][-1]['Seq'], e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
570 e = DoGet(_REMOTE, '/exports?last')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
571 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
572 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
573 self.assertEqual(e['Exports'][-1]['Seq'], e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
574 seqInstance = e['Last']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
575
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
576 # Export the series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
577 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
579 e = DoGet(_REMOTE, '/exports')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
580 self.assertEqual(2, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
581 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
582 self.assertEqual(e['Exports'][-1]['Seq'], e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
583 seqSeries = e['Last']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
584 self.assertNotEqual(seqInstance, seqSeries)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
585 e = DoGet(_REMOTE, '/exports?limit=1&since=0')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
586 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
587 self.assertFalse(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
588 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
589 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
590 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
591 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
592 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
593 e = DoGet(_REMOTE, '/exports?last')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
594 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
595 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
596 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
597
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
598 # Export the study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
599 j = DoPost(_REMOTE, '/modalities/orthanctest/store', 'b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
600 seqStudy = DoGet(_REMOTE, '/exports')['Last']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
601
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
602 # Export the patient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
603 j = DoPost(_REMOTE, '/modalities/orthanctest/store', '6816cb19-844d5aee-85245eba-28e841e6-2414fae2', 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
604 self.assertEqual(1, len(DoGet(_LOCAL, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
605 self.assertEqual(1, len(DoGet(_LOCAL, '/studies')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
606 self.assertEqual(1, len(DoGet(_LOCAL, '/series')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
607 self.assertEqual(1, len(DoGet(_LOCAL, '/instances')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
608
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
609 e = DoGet(_REMOTE, '/exports')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
610 self.assertEqual(4, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
611 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
612 self.assertEqual(e['Exports'][-1]['Seq'], e['Last'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
613 seqPatient = e['Last']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
614 self.assertNotEqual(seqInstance, seqSeries)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
615 self.assertNotEqual(seqSeries, seqStudy)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
616 self.assertNotEqual(seqStudy, seqPatient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
617 self.assertTrue(seqInstance < seqSeries)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
618 self.assertTrue(seqSeries < seqStudy)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
619 self.assertTrue(seqStudy < seqPatient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
620 e = DoGet(_REMOTE, '/exports?limit=1&since=0')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
621 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
622 self.assertFalse(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
623 self.assertEqual(e['Exports'][-1]['Seq'], seqInstance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
624 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqInstance))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
625 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
626 self.assertFalse(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
627 self.assertEqual(e['Exports'][-1]['Seq'], seqSeries)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
628 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqSeries))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
629 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
630 self.assertFalse(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
631 self.assertEqual(e['Exports'][-1]['Seq'], seqStudy)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
632 e = DoGet(_REMOTE, '/exports?limit=1&since=' + str(seqStudy))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
633 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
634 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
635 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
636 e = DoGet(_REMOTE, '/exports?last')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
637 self.assertEqual(1, len(e['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
638 self.assertTrue(e['Done'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
639 self.assertEqual(e['Exports'][-1]['Seq'], seqPatient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
640
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
642 # Check the content of the logged information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
643 e = DoGet(_REMOTE, '/exports')['Exports']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
644
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
645 if 'PatientID' in e[0]:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
646 # Since Orthanc 0.8.6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
647 patient = 'PatientID'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
648 study = 'StudyInstanceUID'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
649 series = 'SeriesInstanceUID'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
650 instance = 'SOPInstanceUID'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
651 else:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
652 # Up to Orthanc 0.8.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
653 patient = 'PatientId'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
654 study = 'StudyInstanceUid'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
655 series = 'SeriesInstanceUid'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
656 instance = 'SopInstanceUid'
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
657
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
658 for k in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
659 self.assertTrue('Date' in e[k])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
660 self.assertTrue('Seq' in e[k])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
661 self.assertEqual('orthanctest', e[k]['RemoteModality'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
662
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
663 self.assertEqual(10, len(e[0]))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
664 self.assertEqual('Instance', e[0]['ResourceType'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
665 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['ID'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
666 self.assertEqual('/instances/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', e[0]['Path'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
667 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', e[0][instance])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
668 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[0][series])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
669 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[0][study])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
670 self.assertEqual('ozp00SjY2xG', e[0][patient])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
671
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
672 self.assertEqual(9, len(e[1]))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
673 self.assertEqual('Series', e[1]['ResourceType'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
674 self.assertEqual('f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['ID'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
675 self.assertEqual('/series/f2635388-f01d497a-15f7c06b-ad7dba06-c4c599fe', e[1]['Path'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
676 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394', e[1][series])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
677 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[1][study])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
678 self.assertEqual('ozp00SjY2xG', e[1][patient])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
679
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
680 self.assertEqual(8, len(e[2]))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
681 self.assertEqual('Study', e[2]['ResourceType'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
682 self.assertEqual('b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['ID'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
683 self.assertEqual('/studies/b9c08539-26f93bde-c81ab0d7-bffaf2cb-a4d0bdd0', e[2]['Path'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
684 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390', e[2][study])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
685 self.assertEqual('ozp00SjY2xG', e[2][patient])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
687 self.assertEqual(7, len(e[3]))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
688 self.assertEqual('Patient', e[3]['ResourceType'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
689 self.assertEqual('6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['ID'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
690 self.assertEqual('/patients/6816cb19-844d5aee-85245eba-28e841e6-2414fae2', e[3]['Path'])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
691 self.assertEqual('ozp00SjY2xG', e[3][patient])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
692
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
693 DropOrthanc(_REMOTE)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
694 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
695
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
696
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
697 def test_store_peer(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
698 self.assertEqual(0, len(DoGet(_LOCAL, '/exports')['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
699 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
700
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
701 i = UploadInstance(_REMOTE, 'DummyCT.dcm')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
702 self.assertEqual(0, len(DoGet(_LOCAL, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
703 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
704
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
705 j = DoPost(_REMOTE, '/peers/peer/store', str(i), 'text/plain')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
706 self.assertEqual(1, len(DoGet(_LOCAL, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
707 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
708
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
709 self.assertEqual(1, len(DoGet(_REMOTE, '/exports')['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
711 DropOrthanc(_REMOTE)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
712 self.assertEqual(0, len(DoGet(_REMOTE, '/exports')['Exports']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
713
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
714
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
715 def test_bulk_storescu(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
716 self.assertEqual(0, len(DoGet(_LOCAL, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
717
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
718 a = UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
719 b = UploadInstance(_REMOTE, 'Knee/T2/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
720
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
721 j = DoPost(_REMOTE, '/modalities/orthanctest/store', [ a['ID'], b['ID'] ], 'application/json')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
722 self.assertEqual(2, len(DoGet(_LOCAL, '/instances')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
723
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
724 DropOrthanc(_LOCAL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
725
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
726 # Send using patient's UUID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
727 self.assertEqual(0, len(DoGet(_LOCAL, '/instances')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
728 j = DoPost(_REMOTE, '/modalities/orthanctest/store',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
729 [ 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' ], 'application/json')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
730 self.assertEqual(2, len(DoGet(_LOCAL, '/instances')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
731
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
732
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
733 def test_color(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
734 i = UploadInstance(_REMOTE, 'ColorTestMalaterre.dcm')['ID']
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
735 im = GetImage(_REMOTE, '/instances/%s/preview' % i)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
736 self.assertEqual("RGB", im.mode)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
737 self.assertEqual(41, im.size[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
738 self.assertEqual(41, im.size[1])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
739
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
740 # http://effbot.org/zone/pil-comparing-images.htm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
741 truth = Image.open(os.path.join(os.path.dirname(__file__), '..', 'Database', 'ColorTestMalaterre.png'))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
742 self.assertTrue(ImageChops.difference(im, truth).getbbox() is None)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
743
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
744
12
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
745 def test_faking_ruby_put(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
746 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
747 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
748 self.assertEqual(2, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
749 a = DoGet(_REMOTE, '/patients')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
750 b = DoGet(_REMOTE, '/patients')[1]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
751 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
752 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
753 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
754 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '1')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
755 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
756 DoGet(_REMOTE, '/patients/%s/protected' % a, data = { '_method' : 'PUT' }, body = '0')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
757 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
759
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
760 def test_faking_ruby_delete(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
761 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
762 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
763 self.assertEqual(2, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
764 a = DoGet(_REMOTE, '/patients')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
765 b = DoGet(_REMOTE, '/patients')[1]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
766 DoGet(_REMOTE, '/patients/%s' % a, data = { '_method' : 'DELETE' })
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
767 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
768 DoGet(_REMOTE, '/patients/%s' % b, data = { '_method' : 'DELETE' })
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
769 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
770
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
771
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
772 def test_faking_google_put(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
773 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
774 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
775 self.assertEqual(2, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
776 a = DoGet(_REMOTE, '/patients')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
777 b = DoGet(_REMOTE, '/patients')[1]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
778 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
779 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
780 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
781 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '1')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
782 self.assertEqual(1, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
783 DoPost(_REMOTE, '/patients/%s/protected' % a, headers = { 'X-HTTP-Method-Override' : 'PUT' }, data = '0')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
784 self.assertEqual(0, DoGet(_REMOTE, '/patients/%s/protected' % a))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
785
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
786
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
787 def test_faking_google_delete(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
788 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
789 UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
790 self.assertEqual(2, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
791 a = DoGet(_REMOTE, '/patients')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
792 b = DoGet(_REMOTE, '/patients')[1]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
793 DoPost(_REMOTE, '/patients/%s' % a, headers = { 'X-HTTP-Method-Override' : 'DELETE' })
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
794 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
795 DoPost(_REMOTE, '/patients/%s' % b, headers = { 'X-HTTP-Method-Override' : 'DELETE' })
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
796 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
797
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
798
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
799 def test_lua(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
800 self.assertEqual(42, DoPost(_REMOTE, '/tools/execute-script', 'print(42)'))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
801 self.assertTrue(IsDefinedInLua(_REMOTE, 'PrintRecursive'))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
802 self.assertFalse(IsDefinedInLua(_REMOTE, 'HelloWorld'))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
803
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
804
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
805 def test_metadata(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
806 UploadInstance(_REMOTE, 'Knee/T1/IM-0001-0001.dcm')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
807 p = DoGet(_REMOTE, '/patients')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
808 i = DoGet(_REMOTE, '/instances')[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
809
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
810 m = DoGet(_REMOTE, '/patients/%s/metadata' % p)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
811 self.assertEqual(1, len(m))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
812 self.assertEqual('LastUpdate', m[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
813
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
814 m = DoGet(_REMOTE, '/instances/%s/metadata' % i)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
815 self.assertEqual(3, len(m))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
816 self.assertTrue('IndexInSeries' in m)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
817 self.assertTrue('ReceptionDate' in m)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
818 self.assertTrue('RemoteAET' in m)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
819
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
820 # Play with custom metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
821 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'coucou')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
822 m = DoGet(_REMOTE, '/patients/%s/metadata' % p)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
823 self.assertEqual(2, len(m))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
824 self.assertTrue('LastUpdate' in m)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
825 self.assertTrue('5555' in m)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
826 self.assertEqual('coucou', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
827 DoPut(_REMOTE, '/patients/%s/metadata/5555' % p, 'hello')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
828 self.assertEqual('hello', DoGet(_REMOTE, '/patients/%s/metadata/5555' % p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
829 DoDelete(_REMOTE, '/patients/%s/metadata/5555' % p)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
830 m = DoGet(_REMOTE, '/patients/%s/metadata' % p)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
831 self.assertEqual(1, len(m))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
832 self.assertTrue('LastUpdate' in m)