-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathDICOMQueryStudyRoot.m
executable file
·262 lines (219 loc) · 10.7 KB
/
DICOMQueryStudyRoot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - GPL
See http://homepage.mac.com/rossetantoine/osirix/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
#import "DICOMQueryStudyRoot.h"
#import "PMStudyRootQueryInformationModel.h"
//#import "PMAttributeList.h"
//#import "PMPersonNameAttribute.h"
//#import "PMSpecificCharacterSet.h"
//#import "PMAttributeTag.h"
//#import "PMQueryTreeModel.h"
//#import "DICOMPersonNameAttribute.h"
//#import "PMDirectoryRecord.h"
#import "MutableArrayCategory.h"
#import "AppController.h"
//#import "dicomFile.h"
extern NSString *QUERYCHARACTERSET;
@implementation DICOMQueryStudyRoot
- (id)initWithCallingAET:(NSString *)myAET calledAET:(NSString *)theirAET hostName:(NSString *)host port:(NSString *)tcpPort{
if (self = [super initWithCallingAET:myAET calledAET:theirAET hostName:host port:tcpPort]){
//Class StudyRoot = NSClassFromString(@"com.pixelmed.query.StudyRootQueryInformationModel");
Class StudyRoot = NSClassFromString(@"DICOMQueryManager");
queryModel = [StudyRoot newWithSignature:@"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)", hostname, port, calledAET, callingAET,0];
//NSLog(@"class %@", NSStringFromClass(StudyRoot));
//NSLog(@"model %@",NSStringFromClass([queryModel class]));
}
return self;
}
- (void)dealloc{
[filterList release];
[queryList release];
}
- (void)addFilter:(NSString *)filter forTag:(NSString *)tag{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"dicomDictionary" ofType:@"plist"];
if( path == 0L) NSLog(@"Cannot find dicomDictionary");
NSDictionary *dd = [[[NSDictionary alloc] initWithContentsOfFile:path] retain];
[self addFilter:filter forDescription:[[dd objectForKey:tag] objectForKey:@"Description"]];
}
- (void)addFilter:(NSString *)filter forDescription:(NSString *)description{
//NSLog (@"Filter %@ description %@", filter, description);
[filters setObject:filter forKey:description];
}
- (BOOL)performQuery{
/*
Possible Attributes for Query
Patient Level: PatientName, PatientID, PatientBirthDate, PatientSex, PatientAge
Study Level: StudyID, StudyDescription, Modalities in Study, Modality, StudyDate, StudyTime, StudyInstanceUID
Series Level:SeriesDescription, SeriesNumber, SeriesDate, SeriesTime, SeriesInstanceUID
Instance Level: InstanceNumber, ContentDate, ContentTime, ImageType, NUmberOfRame SOPInstanceUID
other: SpecificCharacterSet, SOPClassUID
*/
//NSLog(@"tags count %d", [tags count]);
NSMutableDictionary *javaNameDictionary = [NSMutableDictionary dictionaryWithObjects:javaNames forKeys:keys];
NSMutableDictionary *tagDictionary = [NSMutableDictionary dictionaryWithObjects:tags forKeys:keys];
NSArray *descriptions = [filters allKeys];
filterList = [[NSClassFromString(@"com.pixelmed.dicom.AttributeList") alloc] init];
//NSLog(@"filterList");
//PMSpecificCharacterSet *specificCharacterSet = [[[NSClassFromString(SpecificCharacterSet) alloc] init] autorelease];
//NSLog(@"character set %@", NSStringFromClass([specificCharacterSet class]));
NSEnumerator *enumerator = [tagDictionary keyEnumerator];
NSString *key;
/*
PMAttributeTag *aTag = [tagDictionary objectForKey:@"SpecificCharacterSet"];
PMAttribute *scsAttr = [NSClassFromString([javaNameDictionary objectForKey:@"SpecificCharacterSet"]) newWithSignature:@"(Lcom/pixelmed/dicom/AttributeTag;)",aTag];
[scsAttr addStringValue:(NSString *)QUERYCHARACTERSET];
[filterList put:aTag :scsAttr];
id specificCharacterSet = [NSClassFromString(@"com.pixelmed.dicom.SpecificCharacterSetExtension") newWithSignature:@"([Lcom/pixelmed/dicom/Attribute;", scsAttr];
*/
while (key = [enumerator nextObject]) {
//NSLog(@"key %@", key);
//PMAttributeTag *tag;
//PMAttribute *attr;
tag = [tagDictionary objectForKey:key];
/*
if ([key isEqualToString:@"PatientsName"]){
//Class SpecificCharacterSet = NSClassFromString(@"com.pixelmed.dicom.SpecificCharacterSet");
id specificCharacterSet = [NSClassFromString(@"com.pixelmed.dicom.SpecificCharacterSet") newWithSignature:@"([Ljava/lang/String;", [scsAttr getStringValues]];
NSLog(@"character set %@", NSStringFromClass([specificCharacterSet class]));
attr = [NSClassFromString([javaNameDictionary objectForKey:key]) newWithSignature:@"(Lcom/pixelmed/dicom/AttributeTag;Lcom/pixelmed/dicom/SpecificCharacterSet;)",tag, specificCharacterSet];
}
else
*/
attr = [NSClassFromString([javaNameDictionary objectForKey:key]) newWithSignature:@"(Lcom/pixelmed/dicom/AttributeTag;)",tag];
//NSLog(@"class %@", NSStringFromClass([attr class]));
[filterList put:tag :attr];
if ([descriptions containsString:key]) {
[attr addStringValue:(NSString *)[filters objectForKey:key]];
}
//[filterList put:aTag :scsAttr];
}
NS_DURING
tree = [[queryModel performHierarchicalQuery:filterList] retain];
[self createQueryList];
NS_HANDLER
return NO;
NS_ENDHANDLER
return YES;
}
- (BOOL)performRetrieveWithValue:(NSString *)value forTag:(NSString *)tag{
//NSLog(@"performRetrieveforTag %@", value);
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"dicomDictionary" ofType:@"plist"];
if( path == 0L) NSLog(@"Cannot find dicomDictionary");
NSDictionary *dd = [[[NSDictionary alloc] initWithContentsOfFile:path] retain];
[self performRetrieveWithValue:value forDescription:[[dd objectForKey:tag] objectForKey:@"Description"]];
}
- (BOOL)performRetrieveWithAttributeList:(id)attrList atLevel:(NSString*)description{
/*
com.pixelmed.network.MoveSOPClassSCU.MoveSOPClassSCU
(
String hostname,
String port,
String calledAETitle,
String callingAETitle,
String moveDestination,
String affectedSOPClass,
AttributeList identifier,
int debugLevel
)
throws DicomNetworkException, DicomException, IOException
SOPClass.StudyRootQueryRetrieveInformationModelMove
*/
NSString *studyRootQRInformationModelMove = @"1.2.840.10008.5.1.4.1.2.2.2";
//PMAttributeTag *tag = [NSClassFromString(AttributeTag) newWithSignature:@"(II)", QueryRetrieveLevelTag];
//PMAttribute *attr = [NSClassFromString(@"DICOMCodeStringAttribute") newWithSignature:@"(Lcom/pixelmed/dicom/AttributeTag;)",tag];
if ([description isEqualToString:@"StudyInstanceUID"])
[attr addStringValue:@"STUDY"];
else if ([description isEqualToString:@"SeriesInstanceUID"])
[attr addStringValue:@"SERIES"];
else
[attr addStringValue:@"IMAGE"];
//[attrList put:tag :attr];
//Class MoveSCU = NSClassFromString(@"com.pixelmed.network.MoveSOPClassSCU");
//Class MoveSCU = NSClassFromString(@"com.pixelmed.network.DICOMMoveSCU");
//NSLog(@"list: %@", [attrList toString]);
NS_DURING
id moveSCU = [MoveSCU newWithSignature:@"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/pixelmed/dicom/AttributeList;I)", hostname,port, calledAET, callingAET,callingAET,studyRootQRInformationModelMove,attrList,0];
//NSLog(@"class %@", NSStringFromClass(MoveSCU));
//NSLog(@"model %@", NSStringFromClass([moveSCU class]));
NS_HANDLER
NSLog(@"MoveSCU failed");
return NO;
NS_ENDHANDLER
return YES;
}
- (id)queryRoot{
return [tree getRoot];
}
-(NSArray *)queryList{
return queryList;
}
- (void)createQueryList{
//NSLog(@"Create Query");
PMDirectoryRecord *root = [tree getRoot];
id children = [root children];
PMDirectoryRecord *child;
if (queryList)
[queryList release];
queryList = [[NSMutableArray array] retain];
//NSLog(@"root %@ children %@", NSStringFromClass([root class]), NSStringFromClass([children class]));
while ([children hasMoreElements]) {
//NSLog(@"list count %d" ,[queryList count]);
child = [children nextElement];
[queryList addObject:[self createRecord:child]];
}
//NSLog(@"query count %d" ,[queryList count]);
}
- (void) sortQueryList:(NSArray *)sortDescriptors{
[queryList sortUsingDescriptors:sortDescriptors];
}
// create Records for StudyList from Java Directory Records
- (NSDictionary *)createRecord:(PMDirectoryRecord *)directoryRecord{
NSMutableDictionary *record = [NSMutableDictionary dictionary];
PMAttributeList *attrList = [directoryRecord getAllAttributesReturnedInIdentifier];
//NSLog(@"attrList %@", [attrList toString]);
PMAttribute *patient = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", PatientNameTag]];
PMAttribute *patientID = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", PatientIDTag]];
PMAttribute *modality = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", ModalityTag]];
PMAttribute *modalitiesInStudy = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", ModalitiesInStudyTag]];
PMAttribute *description = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", StudyDescriptionTag]];
PMAttribute *attr = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", StudyDateTag]];
PMAttribute *attrTime = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", StudyTimeTag]];
PMAttribute *specificCharacterSet = [attrList get:[NSClassFromString(AttributeTag) newWithSignature:@"(II)", SpecificCharacterSetTag]];
//NSLog(@"Attr");
NSCalendarDate *date = [NSCalendarDate
dateWithString:[attr getSingleStringValueOrEmptyString]
calendarFormat:@"%Y%m%d"];
NSCalendarDate *time = [NSCalendarDate
dateWithString:[attrTime getSingleStringValueOrEmptyString]
calendarFormat:@"%H%M%S"];
//NSLog(@"date time");
//add objects individually in case one is nil
if ([patient getSingleStringValueOrEmptyString] );
[record setObject:[patient getSingleStringValueOrEmptyString] forKey:@"Patient"];
if ([patientID getSingleStringValueOrEmptyString])
[record setObject:[patientID getSingleStringValueOrEmptyString] forKey:@"Patient ID"];
//sometimes Modlaity is used sometime Modalities in study. Try both
if ([modality getSingleStringValueOrEmptyString])
[record setObject:[modality getSingleStringValueOrEmptyString] forKey:@"Modality"];
else if ([modalitiesInStudy getSingleStringValueOrEmptyString])
[record setObject:[modalitiesInStudy getSingleStringValueOrEmptyString] forKey:@"Modality"];
if ([description getSingleStringValueOrEmptyString])
[record setObject:[description getSingleStringValueOrEmptyString] forKey:@"Description"];
if (date)
[record setObject:date forKey:@"Study Date"];
if (time)
[record setObject:time forKey:@"Study Time"];
[record setObject:directoryRecord forKey:@"Directory Record"];
//NSLog(@"End create REcord");
return record;
}
@end