Mercurial > hg > orthanc-tests
comparison NewTests/ExtraMainDicomTags/test_extra_main_dicom_tags.py @ 486:6144ef431512
new tests for sequences in ExtraMainDicomTags
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 28 Jun 2022 18:38:21 +0200 |
parents | |
children | ed0a51317c0b |
comparison
equal
deleted
inserted
replaced
485:459eb688d3a1 | 486:6144ef431512 |
---|---|
1 import unittest | |
2 import time | |
3 import os | |
4 from helpers import OrthancTestCase, Helpers | |
5 | |
6 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file | |
7 from orthanc_tools import OrthancTestDbPopulator | |
8 | |
9 import pathlib | |
10 import glob | |
11 here = pathlib.Path(__file__).parent.resolve() | |
12 | |
13 | |
14 class TestExtraMainDicomTags(OrthancTestCase): | |
15 | |
16 @classmethod | |
17 def prepare(cls): | |
18 print('-------------- preparing TestExtraMainDicomTags tests') | |
19 | |
20 cls.clear_storage(storage_name="ExtraMainDicomTags") | |
21 | |
22 config = { | |
23 "ExtraMainDicomTags": { | |
24 "Instance" : [ | |
25 "Rows", | |
26 "PerformedProtocolCodeSequence" | |
27 ], | |
28 "Series" : [ | |
29 "RequestAttributesSequence" | |
30 ], | |
31 "Study": [], | |
32 "Patient": [] | |
33 }, | |
34 "OverwriteInstances": True, | |
35 "DicomWeb" : { | |
36 "StudiesMetadata" : "MainDicomTags", | |
37 "SeriesMetadata": "MainDicomTags" | |
38 } | |
39 } | |
40 | |
41 config_path = cls.generate_configuration( | |
42 config_name="extra_main_dicom_tags", | |
43 storage_name="ExtraMainDicomTags", | |
44 config=config, | |
45 plugins=Helpers.plugins | |
46 ) | |
47 | |
48 print('-------------- prepared ExtraMainDicomTags tests') | |
49 if Helpers.break_after_preparation: | |
50 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") | |
51 input("Press Enter to continue") | |
52 else: | |
53 print('-------------- launching ExtraMainDicomTags tests') | |
54 cls.launch_orthanc_under_tests( | |
55 config_path=config_path, | |
56 config_name="extra_main_dicom_tags", | |
57 storage_name="ExtraMainDicomTags", | |
58 plugins=Helpers.plugins | |
59 ) | |
60 | |
61 print('-------------- waiting for orthanc-under-tests to be available') | |
62 cls.o.wait_started() | |
63 | |
64 def test_main_dicom_tags(self): | |
65 | |
66 # upload a study | |
67 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
68 | |
69 instance = self.o.get(endpoint="instances/4dc71dc0-6093b5f8-ca67aa8a-07b18ff5-95dbe3c8").json() | |
70 | |
71 self.assertIn("Rows", instance["MainDicomTags"]) | |
72 self.assertIn("PerformedProtocolCodeSequence", instance["MainDicomTags"]) | |
73 | |
74 def test_main_dicom_tags_full(self): | |
75 | |
76 # upload a study | |
77 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
78 | |
79 instance = self.o.get(endpoint="instances/4dc71dc0-6093b5f8-ca67aa8a-07b18ff5-95dbe3c8?full").json() | |
80 | |
81 self.assertIn("0028,0010", instance["MainDicomTags"]) | |
82 self.assertIn("0040,0260", instance["MainDicomTags"]) | |
83 | |
84 | |
85 def test_main_reconstruct(self): | |
86 | |
87 # upload a study | |
88 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
89 | |
90 instance = self.o.get(endpoint="instances/4dc71dc0-6093b5f8-ca67aa8a-07b18ff5-95dbe3c8").json() | |
91 | |
92 self.assertIn("Rows", instance["MainDicomTags"]) | |
93 self.assertIn("PerformedProtocolCodeSequence", instance["MainDicomTags"]) | |
94 | |
95 # reconstruct instance | |
96 self.o.post(endpoint="/instances/4dc71dc0-6093b5f8-ca67aa8a-07b18ff5-95dbe3c8/reconstruct", json={}) | |
97 instance = self.o.get(endpoint="instances/4dc71dc0-6093b5f8-ca67aa8a-07b18ff5-95dbe3c8").json() | |
98 self.assertIn("Rows", instance["MainDicomTags"]) | |
99 self.assertIn("PerformedProtocolCodeSequence", instance["MainDicomTags"]) | |
100 | |
101 | |
102 def test_tools_find(self): | |
103 | |
104 # upload a study | |
105 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
106 | |
107 # instance level | |
108 r = self.o.post( | |
109 endpoint="/tools/find", | |
110 json={ | |
111 "Level": "Instances", | |
112 "Query": { | |
113 "PatientID": "5Yp0E" | |
114 }, | |
115 "Expand": True, | |
116 "RequestedTags" : ["Rows", "PerformedProtocolCodeSequence", "ReferencedStudySequence"] # "ReferencedStudySequence" is not stored in MainDicomTags ! | |
117 } | |
118 ) | |
119 | |
120 instances = r.json() | |
121 self.assertEqual(1, len(instances)) | |
122 self.assertIn("Rows", instances[0]["RequestedTags"]) | |
123 self.assertIn("PerformedProtocolCodeSequence", instances[0]["RequestedTags"]) | |
124 self.assertIn("ReferencedStudySequence", instances[0]["RequestedTags"]) | |
125 | |
126 | |
127 # series level, request a sequence | |
128 r = self.o.post( | |
129 endpoint="/tools/find", | |
130 json={ | |
131 "Level": "Series", | |
132 "Query": { | |
133 "PatientID": "5Yp0E" | |
134 }, | |
135 "Expand": True, | |
136 "RequestedTags" : ["RequestAttributesSequence"] | |
137 } | |
138 ) | |
139 | |
140 series = r.json() | |
141 self.assertEqual(1, len(series)) | |
142 self.assertIn("RequestAttributesSequence", series[0]["RequestedTags"]) | |
143 | |
144 | |
145 | |
146 def test_dicom_web_metadata(self): | |
147 | |
148 # upload a study | |
149 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
150 | |
151 metadata = self.o.get( | |
152 endpoint="/dicom-web/studies/2.16.840.1.113669.632.20.1211.10000357775/metadata" | |
153 ).json() | |
154 | |
155 self.assertEqual(1, len(metadata)) | |
156 self.assertIn("00280010", metadata[0]) # Rows | |
157 self.assertNotIn("00280011", metadata[0]) # Columns should not be stored ! | |
158 self.assertIn("00400260", metadata[0]) # PerformedProtocolCodeSequence |