Mercurial > hg > orthanc-tests
comparison Plugins/Worklists/Run.py @ 635:88539de02bcc
clarifying worklists test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Apr 2024 18:37:40 +0200 |
parents | 575aa420f866 |
children | 685022ee236c |
comparison
equal
deleted
inserted
replaced
634:f6ee256f2404 | 635:88539de02bcc |
---|---|
112 | 112 |
113 a = subprocess.check_output([ 'findscu', '-v', '--call', 'ORTHANC', '-aet', 'ORTHANCTEST', | 113 a = subprocess.check_output([ 'findscu', '-v', '--call', 'ORTHANC', '-aet', 'ORTHANCTEST', |
114 args.server, str(args.dicom), f.name ], | 114 args.server, str(args.dicom), f.name ], |
115 stderr = subprocess.STDOUT).splitlines() | 115 stderr = subprocess.STDOUT).splitlines() |
116 | 116 |
117 if sys.version_info.major == 2: | |
118 if len(list(filter(lambda x: x.startswith('E:'), a))) > 0: | |
119 raise Exception('Error while running findscu') | |
120 else: | |
121 # pprint.pprint(a) | |
122 a = list(map(lambda x: x.decode('utf-8', errors="ignore"), a)) | |
123 # pprint.pprint(a) | |
124 | |
125 if len(list(filter(lambda x: x.startswith('E:'), a))) > 0: | |
126 raise Exception('Error while running findscu') | |
127 | |
128 b = map(lambda x: x[3:], filter(lambda x: (x.startswith('I: ---') or | |
129 x.startswith('W: ---') or | |
130 x.startswith('I: (') or | |
131 x.startswith('W: (')), a)) | |
132 b = map(lambda x: re.sub(r'\s*#.*', '', x), b) | |
133 | |
134 answers = [] | 117 answers = [] |
135 current = [] | 118 current = [] |
136 isQuery = True | 119 isQuery = True |
137 | 120 |
138 for l in b: | 121 for line in a: |
139 l = l.replace('\0', '') | 122 as_ascii = line.decode('ascii', errors='ignore') |
140 | 123 |
141 if l[0] == '-': | 124 if as_ascii.startswith('E:'): |
125 raise Exception('Error while running findscu') | |
126 | |
127 if (as_ascii.startswith('I: ---') or | |
128 as_ascii.startswith('W: ---')): | |
142 if isQuery: | 129 if isQuery: |
143 isQuery = False | 130 isQuery = False |
144 else: | 131 else: |
145 # This is a separator between DICOM datasets | 132 # This is a separator between DICOM datasets |
146 if len(current) > 0: | 133 if len(current) > 0: |
147 answers.append(current) | 134 answers.append(current) |
148 current = [] | 135 current = [] |
149 | 136 |
150 else: | 137 elif (as_ascii.startswith('I: (') or |
138 as_ascii.startswith('W: (')): | |
139 | |
140 # This is a tag | |
151 if not isQuery: | 141 if not isQuery: |
152 tag = l[1:10].lower() | 142 tag = as_ascii[4:13].lower() |
153 if not tag in ignoreTags: | 143 if not tag in ignoreTags: |
154 current.append(l) | 144 line_without_comment = re.sub(b'\s*#.*', b'', line) |
145 line_without_comment = line_without_comment.replace(b'\0', b'') | |
146 current.append(line_without_comment) | |
155 | 147 |
156 if len(current) > 0: | 148 if len(current) > 0: |
157 answers.append(current) | 149 answers.append(current) |
158 | 150 |
159 return answers | 151 return answers |
174 | 166 |
175 | 167 |
176 def ParseTopLevelTags(answer): | 168 def ParseTopLevelTags(answer): |
177 tags = {} | 169 tags = {} |
178 for line in answer: | 170 for line in answer: |
179 m = re.match(r'^\(([0-9a-f]{4},[0-9a-f]{4})\)\s*..\s*\[([^]]*)\]', line) | 171 as_ascii = line.decode('ascii', errors='ignore') |
180 tags[m.group(1)] = m.group(2).strip() | 172 tag = as_ascii[4:13] |
173 start = line.find(b'[') | |
174 end = line.rfind(b']') | |
175 | |
176 tags[tag] = line[start + 1 : end].strip() | |
181 | 177 |
182 return tags | 178 return tags |
183 | 179 |
184 | 180 |
185 ## | 181 ## |