-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathwlds.cc
More file actions
1346 lines (1234 loc) · 73.3 KB
/
wlds.cc
File metadata and controls
1346 lines (1234 loc) · 73.3 KB
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Copyright (C) 1996-2026, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmwlm
*
* Author: Thomas Wilkens
*
* Purpose: (Partially) abstract class for connecting to an arbitrary data source.
*
*/
// ----------------------------------------------------------------------------
#include "dcmtk/config/osconfig.h" // specific configuration for operating system
#include "dcmtk/dcmnet/dicom.h" // for DIC_NODENAME etc. used in "wltypdef.h"
#include "dcmtk/dcmwlm/wltypdef.h" // for type definitions
#include "dcmtk/ofstd/oftypes.h" // for OFBool
#include "dcmtk/dcmdata/dcdatset.h" // for DcmDataset
#include "dcmtk/dcmdata/dcmatch.h" // for DcmAttributeMatching
#include "dcmtk/dcmdata/dcvrat.h" // for DcmAttributTag
#include "dcmtk/dcmdata/dcvrlo.h" // for DcmLongString
#include "dcmtk/dcmdata/dcvrae.h"
#include "dcmtk/dcmdata/dcvrda.h"
#include "dcmtk/dcmdata/dcvrcs.h"
#include "dcmtk/dcmdata/dcvrpn.h"
#include "dcmtk/dcmdata/dcvrtm.h"
#include "dcmtk/dcmdata/dcvrsh.h"
#include "dcmtk/dcmdata/dcvrui.h"
#include "dcmtk/dcmdata/dcdict.h" // for global variable dcmDataDict
#include "dcmtk/dcmdata/dcdeftag.h" // for DCM_OffendingElement, ...
#include "dcmtk/dcmdata/dcsequen.h" // for DcmSequenceOfItems
#include "dcmtk/dcmdata/dcdicent.h" // needed by MSVC5 with STL
#include "dcmtk/dcmwlm/wlds.h"
OFLogger DCM_dcmwlmLogger = OFLog::getLogger("dcmtk.dcmwlm");
// ----------------------------------------------------------------------------
WlmDataSource::WlmDataSource()
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : Constructor.
// Parameters : none.
// Return Value : none.
: failOnInvalidQuery( OFTrue ), callingApplicationEntityTitle(""), calledApplicationEntityTitle(""),
identifiers( NULL ), errorElements( NULL ), offendingElements( NULL ), errorComment( NULL ),
foundUnsupportedOptionalKey( OFFalse ), readLockSetOnDataSource( OFFalse ),
noSequenceExpansion( OFFalse ), returnedCharacterSet( RETURN_NO_CHARACTER_SET ), matchingDatasets(),
specificCharacterSet( "" ), superiorSequenceArray( NULL ),
numOfSuperiorSequences( 0 )
{
// Make sure data dictionary is loaded.
if( !dcmDataDict.isDictionaryLoaded() )
{
DCMWLM_WARN("No data dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE);
}
// Initialize member variables.
identifiers = new DcmDataset();
offendingElements = new DcmAttributeTag( DCM_OffendingElement);
errorElements = new DcmAttributeTag( DCM_OffendingElement);
errorComment = new DcmLongString( DCM_ErrorComment);
}
// ----------------------------------------------------------------------------
WlmDataSource::~WlmDataSource()
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : Destructor.
// Parameters : none.
// Return Value : none.
{
// free memory
ClearDataset(identifiers);
delete identifiers;
delete offendingElements;
delete errorElements;
delete errorComment;
}
// ----------------------------------------------------------------------------
void WlmDataSource::SetCalledApplicationEntityTitle( const OFString& value )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : Sets the member variable that specifies called application entity title.
// Parameters : value - Value for calledApplicationEntityTitle.
// Return Value : none.
{
calledApplicationEntityTitle = value;
}
// ----------------------------------------------------------------------------
void WlmDataSource::SetFailOnInvalidQuery( OFBool value )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : Set member variable that determines if a call should fail on an invalid query.
// Parameters : value - Value for failOnInvalidQuery.
// Return Value : none.
{
failOnInvalidQuery = value;
}
// ----------------------------------------------------------------------------
void WlmDataSource::SetNoSequenceExpansion( OFBool value )
// Date : May 8, 2002
// Author : Thomas Wilkens
// Task : Set member variable.
// Parameters : value - Value for member variable.
// Return Value : none.
{
noSequenceExpansion = value;
}
// ----------------------------------------------------------------------------
void WlmDataSource::SetReturnedCharacterSet( WlmReturnedCharacterSetType value )
// Date : March 21, 2002
// Author : Thomas Wilkens
// Task : Set member variable.
// Parameters : value - Value for member variable.
// Return Value : none.
{
returnedCharacterSet = value;
}
// ----------------------------------------------------------------------------
OFBool WlmDataSource::CheckSearchMask( DcmDataset *searchMask )
// Date : March 18, 2001
// Author : Thomas Wilkens
// Task : This function checks if the search mask has a correct format. It returns OFTrue if this
// is the case, OFFalse if this is not the case.
// Parameters : searchMask - [in] Contains the search mask.
// Return Value : OFTrue - The search mask has a correct format.
// OFFalse - The search mask does not have a correct format.
{
// Initialize counter that counts invalid elements in the search mask. This
// variable will later be used to determine the return value for this function.
int invalidMatchingKeyAttributeCount = 0;
// remember the number of data elements in the search mask
unsigned long numOfElementsInSearchMask = searchMask->card();
// remember potentially specified specific character set
searchMask->findAndGetOFString( DCM_SpecificCharacterSet, specificCharacterSet );
// dump some information if required
DCMWLM_INFO("Checking the search mask");
// this member variable indicates if we encountered an unsupported
// optional key attribute in the search mask; initialize it with false.
foundUnsupportedOptionalKey = OFFalse;
// start a loop; go through all data elements in the search mask, for each element, do some checking
unsigned long i = 0;
while( i < numOfElementsInSearchMask )
{
// determine current element
DcmElement *element = searchMask->getElement(i);
// Depending on if the current element is a sequence or not, process this element.
if( element->ident() != EVR_SQ )
CheckNonSequenceElementInSearchMask( searchMask, invalidMatchingKeyAttributeCount, element );
else
CheckSequenceElementInSearchMask( searchMask, invalidMatchingKeyAttributeCount, element );
// Depending on if the number of elements in the search mask has changed, the current element was
// deleted in the above called function or not. In case the current element was deleted, we do not
// need to increase counter i, we only need to update numOfElementsInSearchMask. If the current
// element was not deleted, we need to increase i but don't have to update numOfElementsInSearchMask.
unsigned long currentNumOfElementsInSearchMask = searchMask->card();
if( currentNumOfElementsInSearchMask != numOfElementsInSearchMask )
numOfElementsInSearchMask = currentNumOfElementsInSearchMask;
else
i++;
}
// if there was more than 1 error, override the error comment
if( invalidMatchingKeyAttributeCount > 1 )
errorComment->putString("Syntax error in 1 or more matching keys");
// return OFTrue or OFFalse depending on the number of invalid matching attributes
return( invalidMatchingKeyAttributeCount == 0 );
}
// ----------------------------------------------------------------------------
void WlmDataSource::CheckNonSequenceElementInSearchMask( DcmDataset *searchMask, int &invalidMatchingKeyAttributeCount, DcmElement *element, DcmSequenceOfItems *supSequenceElement )
// Date : March 8, 2002
// Author : Thomas Wilkens
// Task : This function checks if a non-sequence element in the search mask has a correct format.
// Note that if the current element is an unsupported element, the entire element will be re-
// moved from the search mask, since unsupported elements shall not be returned to the caller.
// Parameters : searchMask - [in] Pointer to the search mask.
// invalidMatchingKeyAttributeCount - [inout] Counter that counts invalid elements in the search mask.
// element - [in] Pointer to the currently processed element.
// supSequenceElement - [in] Pointer to the superordinate sequence element of which
// the currently processed element is an attribute.
// Return Value : none.
{
DcmElement *elem = NULL;
// determine current element's tag
DcmTag tag( element->getTag() );
// determine if the current element is a supported matching key attribute
if( IsSupportedMatchingKeyAttribute( element, supSequenceElement ) )
{
// if the current element is a supported matching key attribute, check if the current element meets
// certain conditions (at the moment we only check if the element's data type and value go together)
if( !CheckMatchingKey( element ) )
{
// if there is a problem with the current element, increase the corresponding counter and dump an error message.
invalidMatchingKeyAttributeCount++;
DCMWLM_WARN("Matching key attribute (" << tag.getTagName() << ") with invalid value encountered in the search mask");
}
}
// if current element is not a supported matching key attribute, determine
// if the current element is a supported return key attribute.
else if( IsSupportedReturnKeyAttribute( element, supSequenceElement ) )
{
// we need to check if the current element (a supported return key attribute) does not contain a value.
// According to the DICOM standard part 4, section K.2.2.1.2. a return key attribute which is NOT a
// a matching key attribute must not contain a value. If one such attribute does contain a value,
// i.e. if the current element's length does not equal 0, we want to dump a warning message.
if( element->getLength() != 0 )
{
DCMWLM_INFO(" - Non-empty return key attribute (" << tag.getTagName() << ") encountered in the search mask." << OFendl
<< " The specified value will be overridden.");
}
}
// if current element is neither a supported matching key attribute nor a supported return key
// attribute we've found an unsupported optional attribute; we want to delete this element from
// the search mask, dump a warning and remember this attribute's tag in the list of error elements.
else
{
// delete element from the search mask
// in case there is a superordinate sequence element in whose first item this element occurs,
// we need to delete this element from this particular item in the superordinate sequence element
if( supSequenceElement != NULL )
{
elem = supSequenceElement->getItem(0)->remove( element );
delete elem;
}
// in case there is NO superordinate sequence element in whose first item this element occurs,
// we need to delete this element from the search mask itself.
else
{
elem = searchMask->remove( element );
delete elem;
}
// handle special case of "Specific Character Set"
if( tag == DCM_SpecificCharacterSet )
{
DCMWLM_WARN("Attribute " << tag.getTagName() << " found in the search mask, value is neither checked nor used for matching");
}
else
{
// dump a warning
DCMWLM_INFO(" - Unsupported (non-sequence) attribute (" << tag.getTagName() << ") encountered in the search mask." << OFendl
<< " This attribute will not be existent in any result dataset.");
// remember this attribute's tag in the list of error elements
foundUnsupportedOptionalKey = OFTrue;
PutErrorElements( tag );
}
}
}
// ----------------------------------------------------------------------------
void WlmDataSource::CheckSequenceElementInSearchMask( DcmDataset *searchMask, int &invalidMatchingKeyAttributeCount, DcmElement *element, DcmSequenceOfItems *supSequenceElement )
// Date : March 8, 2002
// Author : Thomas Wilkens
// Task : This function checks if a sequence element in the search mask has a correct format.
// Note that if the current element is an unsupported element, the entire element will be re-
// moved from the search mask, since unsupported elements shall not be returned to the caller.
// Moreover, in case the sequence element in the search mask is supported but empty, this
// function will expand the sequence element by inserting all required attributes into that sequence.
// Parameters : searchMask - [in] Pointer to the search mask.
// invalidMatchingKeyAttributeCount - [inout] Counter that counts invalid elements in the search mask.
// element - [in] Pointer to the currently processed element.
// supSequenceElement - [in] Pointer to the superordinate sequence element of which
// the currently processed element is an attribute.
// Return Value : none.
{
// Be aware of the following remark: the DICOM standard specifies in part 4, section C.2.2.2.6
// that if a search mask contains a sequence attribute which contains a single empty item, all
// attributes from that particular sequence are in fact queried and shall be returned by the SCP.
// This implementation accounts for this specification by expanding the search mask correspondingly.
DcmElement *elem = NULL;
// determine current element's tag
DcmTag tag( element->getTag() );
// remember that the current element is a sequence of items
DcmSequenceOfItems *sequenceElement = OFstatic_cast(DcmSequenceOfItems *, element);
// determine if the current sequence element is a supported matching or return key attribute
if( IsSupportedMatchingKeyAttribute( element, supSequenceElement ) || IsSupportedReturnKeyAttribute( element, supSequenceElement ) )
{
// if the sequence attribute is supported, check if the length of the sequence equals 0, or if the sequence
// contains exactly one empty item
if( element->getLength() == 0 || ( sequenceElement->card() == 1 && sequenceElement->getItem(0)->card() == 0 ) )
{
// an empty sequence is not allowed in a C-FIND request
if (element->getLength() == 0)
{
DCMWLM_WARN("Empty sequence (" << tag.getTagName() << ") encountered within the query, "
<< "treating as if an empty item within the sequence has been sent");
}
// if this is the case, we need to check the value of a variable
// which pertains to a certain command line option
if( noSequenceExpansion == OFFalse )
{
// if the user did not explicitly disable the expansion of empty sequences in C-FIND request
// messages go ahead and expand this sequence according to the remark above
ExpandEmptySequenceInSearchMask( element );
}
}
else
{
// if this is not the case we want to check the cardinality of the sequence; note that there should
// always be exactly one item in a sequence within the search mask.
if( sequenceElement->card() != 1 )
{
// if there is not exactly one item in the sequence of items, we want to remember this
// attribute in the list of offending elements, we want to set the error comment correspondingly,
// we want to dump an error message and we want to increase the corresponding counter.
PutOffendingElements(tag);
errorComment->putString("More than 1 item in sequence.");
DCMWLM_ERROR("More than one item in sequence (" << tag.getTagName() << ") within the query encountered, "
<< "discarding all items except for the first one");
invalidMatchingKeyAttributeCount++;
// also, we want to delete all items except the first one
unsigned long numOfItems = sequenceElement->card();
for( unsigned long i=1 ; i<numOfItems ; i++ )
{
delete sequenceElement->remove( i );
}
}
// (now, even though we might have encountered an error, we go on scrutinizing the search mask)
// get the first (and only) item in the sequence of items
DcmItem *item = sequenceElement->getItem(0);
// determine the cardinality of this item
unsigned long numOfElementsInItem = item->card();
unsigned long k = 0;
// go through all elements of this item
while( k < numOfElementsInItem )
{
// determine the current element
DcmElement *elementseq = item->getElement(k);
// Depending on if the current element is a sequence or not, process this element.
if( elementseq->ident() != EVR_SQ )
CheckNonSequenceElementInSearchMask( searchMask, invalidMatchingKeyAttributeCount, elementseq, sequenceElement );
else
CheckSequenceElementInSearchMask( searchMask, invalidMatchingKeyAttributeCount, elementseq, sequenceElement );
// Depending on if the number of elements in the item has changed, the current element was
// deleted in the above called function or not. In case the current element was deleted, we do not
// need to increase counter k, we only need to update numOfElementsInItem. If the current
// element was not deleted, we need to increase k but don't have to update numOfElementsInItem.
unsigned long currentNumOfElementsInItem = item->card();
if( currentNumOfElementsInItem != numOfElementsInItem )
numOfElementsInItem = currentNumOfElementsInItem;
else
k++;
}
}
}
// if current element is neither a supported matching key attribute sequence nor a supported return key
// attribute sequence we've found an unsupported sequence attribute; we want to delete this element from
// the search mask, dump a warning message (only in verbose mode) remember this attribute in the list of
// error elements.
else
{
// delete element from the search mask
// in case there is a superordinate sequence element in whose first item this element occurs,
// we need to delete this element from this particular item in the superordinate sequence element
if( supSequenceElement != NULL )
{
elem = supSequenceElement->getItem(0)->remove( element );
delete elem;
}
// in case there is NO superordinate sequence element in whose first item this element occurs,
// we need to delete this element from the search mask itself.
else
{
elem = searchMask->remove( element );
delete elem;
}
// dump a warning
DCMWLM_INFO(" - Unsupported (sequence) attribute (" << tag.getTagName() << ") encountered in the search mask." << OFendl
<< " This attribute will not be existent in any result dataset.");
// remember this attribute's tag in the list of error elements
foundUnsupportedOptionalKey = OFTrue;
PutErrorElements( tag );
}
}
// ----------------------------------------------------------------------------
void WlmDataSource::ExpandEmptySequenceInSearchMask( DcmElement *&element )
// Date : March 8, 2002
// Author : Thomas Wilkens
// Task : According to the DICOM standard (part 4, section C.2.2.2.6), if a search mask
// contains a sequence attribute which contains no item or a single empty item, all
// attributes from that particular sequence are in fact queried and shall be returned
// by the SCP. This implementation accounts for this specification by inserting a
// corresponding single item with all required attributes into such empty sequences.
// This function performs the insertion of the required item and attributes.
// Parameters : element - [inout] Pointer to the currently processed element.
// Return Value : none.
{
DcmItem *item = NULL;
DcmElement *newElement = NULL;
// remember that the current element is a sequence of items
DcmSequenceOfItems *sequenceElement = OFstatic_cast(DcmSequenceOfItems *, element);
// determine if the length of the sequence equals 0
if( element->getLength() == 0 )
{
// if the length of the sequence attribute equals 0, we have to insert a single item
item = new DcmItem();
if( sequenceElement->insert( item ) != EC_Normal )
{
delete item;
item = NULL;
}
}
else
{
// if the length of the sequence attribute does not equal 0, we have to determine the
// one and only item in the sequence
item = sequenceElement->getItem(0);
}
// check if item does not equal NULL, only if this is the case, we can insert attributes
// into that item. In general, this should always be the case.
if( item != NULL )
{
// at this point, the current element contains exactly one item, which is empty, i.e. does not
// contain any attributes. Now we have to insert the required attributes into this item.
// depending on what kind of supported sequence attribute
// was passed, we have to insert different attributes
const DcmTagKey key(element->getTag());
if( key == DCM_ScheduledProcedureStepSequence )
{
newElement = new DcmApplicationEntity( DcmTag( DCM_ScheduledStationAETitle ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmDate( DcmTag( DCM_ScheduledProcedureStepStartDate ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmTime( DcmTag( DCM_ScheduledProcedureStepStartTime ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmCodeString( DcmTag( DCM_Modality ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmPersonName( DcmTag( DCM_ScheduledPerformingPhysicianName ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmLongString( DcmTag( DCM_ScheduledProcedureStepDescription ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmShortString( DcmTag( DCM_ScheduledStationName ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmShortString( DcmTag( DCM_ScheduledProcedureStepLocation ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmLongString( DcmTag( DCM_PreMedication ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmShortString( DcmTag( DCM_ScheduledProcedureStepID ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmLongString( DcmTag( DCM_RequestedContrastAgent ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmLongString( DcmTag( DCM_CommentsOnTheScheduledProcedureStep ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmCodeString( DcmTag( DCM_ScheduledProcedureStepStatus ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmDate( DcmTag( DCM_ScheduledProcedureStepEndDate ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmTime( DcmTag( DCM_ScheduledProcedureStepEndTime ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmSequenceOfItems( DcmTag( DCM_ScheduledProtocolCodeSequence ) );
if( item->insert( newElement ) != EC_Normal )
delete newElement;
else
{
DcmItem *item2 = new DcmItem();
if( OFstatic_cast(DcmSequenceOfItems*, newElement)->insert( item2 ) != EC_Normal )
{
delete item2;
item2 = NULL;
}
else
{
DcmElement *newElement2 = NULL;
newElement2 = new DcmShortString( DcmTag( DCM_CodeValue ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
newElement2 = new DcmShortString( DcmTag( DCM_CodingSchemeVersion ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
newElement2 = new DcmShortString( DcmTag( DCM_CodingSchemeDesignator ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
newElement2 = new DcmLongString( DcmTag( DCM_CodeMeaning ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
}
}
}
else if( key == DCM_ScheduledProtocolCodeSequence || key == DCM_RequestedProcedureCodeSequence ||
key == DCM_InstitutionCodeSequence || key == DCM_InstitutionalDepartmentTypeCodeSequence ||
key == DCM_PatientSpeciesCodeSequence || key == DCM_PatientBreedCodeSequence ||
key == DCM_BreedRegistryCodeSequence )
{
newElement = new DcmShortString( DcmTag( DCM_CodeValue ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmShortString( DcmTag( DCM_CodingSchemeVersion ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmShortString( DcmTag( DCM_CodingSchemeDesignator ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmLongString( DcmTag( DCM_CodeMeaning ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
}
else if( key == DCM_BreedRegistrationSequence )
{
newElement = new DcmLongString( DcmTag( DCM_BreedRegistrationNumber ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmSequenceOfItems( DcmTag( DCM_BreedRegistryCodeSequence ) );
if( item->insert( newElement ) != EC_Normal )
delete newElement;
else
{
DcmItem *item2 = new DcmItem();
if( OFstatic_cast(DcmSequenceOfItems*, newElement)->insert( item2 ) != EC_Normal )
{
delete item2;
item2 = NULL;
}
else
{
DcmElement *newElement2 = NULL;
newElement2 = new DcmShortString( DcmTag( DCM_CodeValue ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
newElement2 = new DcmShortString( DcmTag( DCM_CodingSchemeVersion ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
newElement2 = new DcmShortString( DcmTag( DCM_CodingSchemeDesignator ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
newElement2 = new DcmLongString( DcmTag( DCM_CodeMeaning ) ); if( item2->insert( newElement2 ) != EC_Normal ) delete newElement2;
}
}
}
else if( key == DCM_ReferencedStudySequence || key == DCM_ReferencedPatientSequence )
{
newElement = new DcmUniqueIdentifier( DcmTag( DCM_ReferencedSOPClassUID ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
newElement = new DcmUniqueIdentifier( DcmTag( DCM_ReferencedSOPInstanceUID ) ); if( item->insert( newElement ) != EC_Normal ) delete newElement;
}
else
{
// this code should never be executed; if it is, there is a logical error
// in the source code and we want to dump a warning message
DCMWLM_ERROR("WlmDataSource::ExpandEmptySequenceInSearchMask: Unsupported sequence attribute encountered");
}
}
else
{
// this code should never be executed. if it is, we want to dump a warning message
DCMWLM_ERROR("WlmDataSource::ExpandEmptySequenceInSearchMask: Unable to find item in sequence");
}
}
// ----------------------------------------------------------------------------
void WlmDataSource::ClearDataset( DcmDataset *idents )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function removes all elements from the given DcmDataset object.
// Parameters : idents - [in] pointer to object which shall be cleared.
// Return Value : none.
{
// If the given pointer is valid and refers to a non-empty structure
if( idents && (idents->card()>0) )
{
// clear structure
idents->clear();
}
}
// ----------------------------------------------------------------------------
void WlmDataSource::PutOffendingElements( const DcmTagKey &tag )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function inserts the tag of an offending element into the
// corresponding member variable, unless this tag is already con-
// tained in this variable.
// Parameters : tag - [in] The tag that shall be inserted.
// Return Value : none.
{
DcmTagKey errortag;
// determine how many offending elements there have been so far
unsigned long d = offendingElements->getVM();
// if this is the first one, insert it at position 0
if( d==0 )
{
offendingElements->putTagVal(tag, 0);
}
// if this is not the first one, insert it at the end
// but only if it is not yet contained.
else
{
OFBool tagFound = OFFalse;
for( unsigned long j=0 ; j<d && !tagFound ; j++ )
{
offendingElements->getTagVal( errortag, j );
if( errortag == tag )
tagFound = OFTrue;
}
if( !tagFound )
offendingElements->putTagVal( tag, d );
}
}
// ----------------------------------------------------------------------------
void WlmDataSource::PutErrorElements( const DcmTagKey &tag )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function inserts the tag of an error element into the
// corresponding member variable, without checking if it is already
// contained in this variable.
// Parameters : tag - [in] The tag that shall be inserted.
// Return Value : none.
{
// insert tag
errorElements->putTagVal( tag, errorElements->getVM() );
}
// ----------------------------------------------------------------------------
OFBool WlmDataSource::CheckMatchingKey( const DcmElement *elem )
// Date : March 18, 2002
// Author : Thomas Wilkens
// Task : This function checks if the passed matching key's value only uses characters
// which are part of its data type's character repertoire. Note that at the moment
// this application supports the following matching key attributes:
// DCM_ScheduledProcedureStepSequence (0040,0100) SQ R 1
// > DCM_ScheduledStationAETitle (0040,0001) AE R 1
// > DCM_ScheduledProcedureStepStartDate (0040,0002) DA R 1
// > DCM_ScheduledProcedureStepStartTime (0040,0003) TM R 1
// > DCM_Modality (0008,0060) CS R 1
// > DCM_ScheduledPerformingPhysicianName (0040,0006) PN R 2
// DCM_PatientName (0010,0010) PN R 1
// DCM_ResponsiblePerson (0010,2297) PN O 3
// DCM_ResponsiblePersonRole (0010,2298) CS O 3
// DCM_ResponsibleOrganization (0010,2299) LO O 3
// DCM_PatientID (0010,0020) LO R 1
// DCM_AccessionNumber (0008,0050) SH O 2
// DCM_RequestedProcedureID (0040,1001) SH O 1
// DCM_ReferringPhysicianName (0008,0090) PN O 2
// DCM_PatientSex (0010,0040) CS O 2
// DCM_PatientSpeciesDescription (0010,2201) LO O 3
// DCM_PatientSexNeutered (0010,2203) CS O 3
// DCM_PatientBreedDescription (0010,2292) LO O 3
// DCM_RequestingPhysician (0032,1032) PN O 2
// DCM_AdmissionID (0038,0010) LO O 2
// DCM_RequestedProcedurePriority (0040,1003) SH O 2
// DCM_PatientBirthDate (0010,0030) DA O 2
// DCM_IssuerOfPatientID (0010,0021) LO O 3
// DCM_StudyDate (0008,0020) DA O 3
// DCM_StudyTime (0008,0030) TM O 3
// As a result, the following data types have to be supported in this function:
// AE, DA, TM, CS, PN, LO and SH. For the correct specification of these datatypes
// 2003 DICOM standard, part 5, section 6.2, table 6.2-1.
// Parameters : elem - [in] Element which shall be checked.
// Return Value : OFTrue - The given element's value only uses characters which are part of
// the element's data type's character repertoire.
// OFFalse - The given element's value does not only use characters which are part of
// the element's data type's character repertoire.
{
OFBool ok = OFTrue;
OFString val;
switch( elem->ident() )
{
case EVR_DA:
case EVR_DT:
case EVR_TM:
{
const char* data;
size_t size;
{
char* c;
Uint32 s;
if( OFconst_cast( DcmElement*, elem )->getString( c, s ).bad() )
break;
data = c;
size = s;
}
OFStandard::trimString( data, size );
if( !size )
break;
switch( elem->ident() )
{
case EVR_DA:
ok = DcmAttributeMatching::isDateQuery( data, size );
break;
case EVR_DT:
ok = DcmAttributeMatching::isDateTimeQuery( data, size );
break;
case EVR_TM:
ok = DcmAttributeMatching::isTimeQuery( data, size );
break;
default:
ok = false;
break;
}
if( !ok )
{
DcmTag tag( elem->getTag() );
PutOffendingElements( tag );
OFString message( "Invalid value for an attribute with VR=" );
message += DcmVR( elem->ident() ).getVRName();
errorComment->putOFStringArray( message );
}
}
break;
case EVR_CS:
// get string value
ok = GetStringValue( elem, val );
// check if value contains only valid characters
if( ok && !ContainsOnlyValidCharacters( val.c_str(), "*?ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 _" ) )
{
DcmTag tag( elem->getTag() );
PutOffendingElements( tag );
errorComment->putString("Invalid Character Repertoire for datatype CS");
ok = OFFalse;
}
else
ok = OFTrue;
break;
case EVR_AE:
// get string value
ok = GetStringValue( elem, val );
// check if value contains only valid characters
if( ok && !ContainsOnlyValidCharacters( val.c_str(), " !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ) )
{
DcmTag tag( elem->getTag() );
PutOffendingElements( tag );
errorComment->putString("Invalid Character Repertoire for datatype AE");
ok = OFFalse;
}
else
ok = OFTrue;
break;
case EVR_PN:
// get string value
ok = GetStringValue( elem, val );
// check if value contains only valid characters (no ESC since only allowed for ISO 2022 encoding)
if( ok && !ContainsOnlyValidCharacters( val.c_str(), "*? !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}" ) && specificCharacterSet == "" )
{
DcmTag tag( elem->getTag() );
PutOffendingElements( tag );
errorComment->putString("Invalid Character Repertoire for datatype PN");
ok = OFFalse;
}
else
ok = OFTrue;
break;
case EVR_LO:
// get string value
ok = GetStringValue( elem, val );
// check if value contains only valid characters (no ESC since only allowed for ISO 2022 encoding)
if( ok && !ContainsOnlyValidCharacters( val.c_str(), "*? !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}" ) && specificCharacterSet == "" )
{
DcmTag tag( elem->getTag() );
PutOffendingElements( tag );
errorComment->putString("Invalid Character Repertoire for datatype LO");
ok = OFFalse;
}
else
ok = OFTrue;
break;
case EVR_SH:
// get string value
ok = GetStringValue( elem, val );
// check if value contains only valid characters (no ESC since only allowed for ISO 2022 encoding)
if( ok && !ContainsOnlyValidCharacters( val.c_str(), "*? !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}" ) && specificCharacterSet == "" )
{
DcmTag tag( elem->getTag() );
PutOffendingElements( tag );
errorComment->putString("Invalid Character Repertoire for datatype SH");
ok = OFFalse;
}
else
ok = OFTrue;
break;
default:
break;
}
return( ok );
}
// ----------------------------------------------------------------------------
OFBool WlmDataSource::ContainsOnlyValidCharacters( const char *s, const char *charset )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function returns OFTrue if all the characters of s can be found
// in the string charset.
// Parameters : s - [in] String which shall be checked.
// charset - [in] Possible character set for s. (valid pointer expected.)
// Return Value : This function returns OFTrue if all the characters of s can be found
// in the string charset. If s equals NULL, OFTrue will be returned.
{
OFBool result = OFTrue;
// check parameter
if( s == NULL )
{
return OFTrue;
}
// return OFTrue if all the characters of s can be found in the string charset.
size_t s_len = strlen( s );
size_t charset_len = strlen( charset );
for( size_t i=0 ; i<s_len && result ; i++ )
{
OFBool isSetMember = OFFalse;
for( size_t j=0 ; !isSetMember && j<charset_len ; j++ )
{
if( s[i] == charset[j] )
isSetMember = OFTrue;
}
if( !isSetMember )
result = OFFalse;
}
return( result );
}
// ----------------------------------------------------------------------------
OFString WlmDataSource::DeleteLeadingAndTrailingBlanks( const OFString& value )
// Date : March 19, 2002
// Author : Thomas Wilkens
// Task : This function makes a copy of value without leading and trailing blanks.
// Parameters : value - [in] The source string.
// Return Value : A copy of the given string without leading and trailing blanks.
{
OFString returnValue = value;
size_t pos = 0;
// delete leading blanks
while ( !returnValue.empty() && (returnValue[pos] == ' ') )
pos++; // count blanks
if (pos > 0)
returnValue.erase(0, pos);
// delete trailing blanks, start from end of string
pos = returnValue.length() - 1;
while ( !returnValue.empty() && (returnValue[pos] == ' ') )
pos--;
if (pos < returnValue.length() -1)
returnValue.erase(pos);
return returnValue;
}
// ----------------------------------------------------------------------------
OFBool WlmDataSource::GetStringValue( const DcmElement *elem,
OFString& resultVal )
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function returns the value of the given DICOM string element (attribute)
// in the parameter resultVal and returns OFTrue if successful.
// If the element does not refer to a string attribute or contains no value,
// OFFalse is returned.
// Parameters : elem - [in] The DICOM element.
// resultVal - [out] The resulting string value
// Return Value : OFTrue if string value could be accessed, OFFalse else
{
DcmElement *elemNonConst = OFconst_cast(DcmElement*, elem);
OFCondition result = elemNonConst->getOFStringArray( resultVal );
if( result.bad() || resultVal.empty() )
return OFFalse;
return OFTrue;
}
// ----------------------------------------------------------------------------
DcmAttributeTag *WlmDataSource::GetOffendingElements()
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function returns offending elements from member variable offendingElements
// if there are any.
// Parameters : none.
// Return Value : Pointer to offending elements or NULL if there are none.
{
if( offendingElements->getLength() == 0 )
return NULL;
else
return offendingElements;
}
// ----------------------------------------------------------------------------
DcmLongString *WlmDataSource::GetErrorComments()
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function returns error comments from member variable errorComment
// if there are any.
// Parameters : none.
// Return Value : Pointer to error comments or NULL if there are none.
{
if( errorComment->getLength() == 0 )
return NULL;
else
return errorComment;
}
// ----------------------------------------------------------------------------
WlmDataSourceStatusType WlmDataSource::CancelFindRequest()
// Date : December 10, 2001
// Author : Thomas Wilkens
// Task : This function handles a C-CANCEL Request during the processing of a C-FIND Request.
// In detail, in case there are still matching datasets captured in member variable
// matchingDatasets, memory for these datasets (and the array itself) is freed and
// all pointers are set to NULL.
// Parameters : none.
// Return Value : WLM_CANCEL.
{
// remove all remaining datasets from result list
while (!matchingDatasets.empty())
{
DcmDataset *dset = matchingDatasets.front();
delete dset; dset = NULL;
matchingDatasets.pop_front();
}
// return WLM_CANCEL
return WLM_CANCEL;
}
// ----------------------------------------------------------------------------
OFBool WlmDataSource::IsSupportedMatchingKeyAttribute( DcmElement *element, DcmSequenceOfItems *supSequenceElement )
// Date : December 12, 2001
// Author : Thomas Wilkens
// Task : This function checks if the given element refers to an attribute which is a supported
// matching key attribute. If this is the case OFTrue is returned, else OFFalse.
// Currently, the following attributes are supported as matching keys:
// DCM_ScheduledProcedureStepSequence (0040,0100) SQ R 1
// > DCM_ScheduledStationAETitle (0040,0001) AE R 1
// > DCM_ScheduledProcedureStepStartDate (0040,0002) DA R 1
// > DCM_ScheduledProcedureStepStartTime (0040,0003) TM R 1
// > DCM_Modality (0008,0060) CS R 1
// > DCM_ScheduledPerformingPhysicianName (0040,0006) PN R 2
// DCM_PatientName (0010,0010) PN R 1
// DCM_ResponsiblePerson (0010,2297) PN O 3
// DCM_ResponsiblePersonRole (0010,2298) CS O 3
// DCM_PatientID (0010,0020) LO R 1
// DCM_AccessionNumber (0008,0050) SH O 2
// DCM_RequestedProcedureID (0040,1001) SH O 1
// DCM_ReferringPhysicianName (0008,0090) PN O 2
// DCM_PatientSex (0010,0040) CS O 2
// DCM_RequestingPhysician (0032,1032) PN O 2
// DCM_AdmissionID (0038,0010) LO O 2
// DCM_RequestedProcedurePriority (0040,1003) SH O 2
// DCM_PatientBirthDate (0010,0030) DA O 2
// DCM_IssuerOfPatientID (0010,0021) LO O 3
// DCM_StudyDate (0008,0020) DA O 3
// DCM_StudyTime (0008,0030) TM O 3
// Parameters : element - [in] Pointer to the element which shall be checked.
// supSequenceElement - [in] Pointer to the superordinate sequence element of which
// the currently processed element is an attribute, or NULL if
// the currently processed element does not belong to any sequence.
// Return Value : OFTrue - The given tag is a supported matching key attribute.
// OFFalse - The given tag is not a supported matching key attribute.
{
DcmTagKey elementKey, supSequenceElementKey;
// determine the current element's tag
elementKey = element->getTag();
// determine the sequence element's tag, if there is one
if( supSequenceElement != NULL )
supSequenceElementKey = supSequenceElement->getTag();
// initialize result variable