1477
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import pprint
|
|
4 import requests
|
|
5 import sys
|
|
6
|
|
7 if len(sys.argv) != 2:
|
|
8 print('Usage: %s [Orthanc series ID]' % sys.argv[0])
|
|
9 print('Example: %s 4d04593b-953ced51-87e93f11-ae4cf03c-25defdcd | xclip -selection c -t text/plain' % sys.argv[0])
|
|
10 exit(-1)
|
|
11
|
|
12 SERIES = sys.argv[1]
|
|
13
|
|
14 r = requests.get('http://localhost:8042/series/%s/study' % SERIES)
|
|
15 r.raise_for_status()
|
|
16 print(' // From patient %s' % r.json() ['PatientMainDicomTags']['PatientName'])
|
|
17
|
|
18 r = requests.get('http://localhost:8042/series/%s' % SERIES)
|
|
19 r.raise_for_status()
|
|
20
|
|
21 first = True
|
|
22
|
|
23 for instance in r.json() ['Instances']:
|
|
24 tags = requests.get('http://localhost:8042/instances/%s/tags?short' % instance)
|
|
25 tags.raise_for_status()
|
|
26
|
|
27 if first:
|
|
28 print('''
|
|
29 Orthanc::DicomMap tags;
|
|
30 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "%s", false);
|
|
31 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "%s", false);
|
|
32 OrthancStone::SortedFrames f;
|
|
33 ''' % (tags.json() ['0020,000d'], tags.json() ['0020,000e']))
|
|
34 first = False
|
|
35
|
|
36 print(' tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "%s", false);' % instance)
|
|
37
|
|
38 if '0020,0032' in tags.json():
|
|
39 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "%s", false);' %
|
|
40 tags.json() ['0020,0032'].replace('\\', '\\\\'))
|
|
41
|
|
42 if '0020,0037' in tags.json():
|
|
43 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "%s", false);' %
|
|
44 tags.json() ['0020,0037'].replace('\\', '\\\\'))
|
|
45
|
|
46 if '0020,0013' in tags.json():
|
|
47 print(' tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "%s", false);' %
|
|
48 tags.json() ['0020,0013'].replace('\\', '\\\\'))
|
|
49
|
|
50 if '0054,1330' in tags.json():
|
|
51 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_INDEX, "%s", false);' %
|
|
52 tags.json() ['0054,1330'].replace('\\', '\\\\'))
|
|
53
|
|
54 print(' f.AddInstance(tags);')
|
|
55
|
|
56 print(' f.Sort();')
|
|
57
|
|
58 r = requests.get('http://localhost:8042/series/%s/ordered-slices' % SERIES)
|
|
59 r.raise_for_status()
|
|
60 slices = r.json() ['SlicesShort']
|
|
61
|
|
62 print(' ASSERT_EQ(%du, f.GetFramesCount());' % len(slices))
|
|
63
|
|
64 for i in range(len(slices)):
|
|
65 print(' ASSERT_EQ(f.GetFrameSopInstanceUid(%d), "%s");' % (i, slices[i][0]))
|
|
66
|