comparison OrthancServer/FromDcmtkBridge.cpp @ 2129:0c09d1af22f3

"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Nov 2016 17:44:10 +0100
parents 03b065778fc3
children bb199bccdc45
comparison
equal deleted inserted replaced
2128:9329ba17a069 2129:0c09d1af22f3
421 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding); 421 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding);
422 422
423 if (maxStringLength != 0 && 423 if (maxStringLength != 0 &&
424 utf8.size() > maxStringLength) 424 utf8.size() > maxStringLength)
425 { 425 {
426 return new DicomValue; // Create a NULL value 426 return new DicomValue; // Too long, create a NULL value
427 } 427 }
428 else 428 else
429 { 429 {
430 return new DicomValue(utf8, false); 430 return new DicomValue(utf8, false);
431 } 431 }
432 } 432 }
433 } 433 }
434
435
436 if (element.getVR() == EVR_UN)
437 {
438 // Unknown value representation: Lookup in the dictionary. This
439 // is notably the case for private tags registered with the
440 // "Dictionary" configuration option.
441 DictionaryLocker locker;
442
443 const DcmDictEntry* entry = locker->findEntry(element.getTag().getXTag(),
444 element.getTag().getPrivateCreator());
445 if (entry != NULL &&
446 entry->getVR().isaString())
447 {
448 Uint8* data = NULL;
449
450 // At (*), we do not try and convert to UTF-8, as nothing says
451 // the encoding of the private tag is the same as that of the
452 // remaining of the DICOM dataset. Only go for ASCII strings.
453
454 if (element.getUint8Array(data) == EC_Normal &&
455 Toolbox::IsAsciiString(data, element.getLength())) // (*)
456 {
457 if (data == NULL)
458 {
459 return new DicomValue("", false); // Empty string
460 }
461 else if (maxStringLength != 0 &&
462 element.getLength() > maxStringLength)
463 {
464 return new DicomValue; // Too long, create a NULL value
465 }
466 else
467 {
468 std::string s(reinterpret_cast<const char*>(data), element.getLength());
469 return new DicomValue(s, false);
470 }
471 }
472 }
473 }
474
434 475
435 try 476 try
436 { 477 {
437 // http://support.dcmtk.org/docs/dcvr_8h-source.html 478 // http://support.dcmtk.org/docs/dcvr_8h-source.html
438 switch (element.getVR()) 479 switch (element.getVR())
756 assert(parent.type() == Json::objectValue); 797 assert(parent.type() == Json::objectValue);
757 Json::Value& target = PrepareNode(parent, element, format); 798 Json::Value& target = PrepareNode(parent, element, format);
758 799
759 if (element.isLeaf()) 800 if (element.isLeaf())
760 { 801 {
761 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, flags, maxStringLength, encoding)); 802 // The "0" below lets "LeafValueToJson()" take care of "TooLong" values
803 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, flags, 0, encoding));
762 LeafValueToJson(target, *v, format, flags, maxStringLength); 804 LeafValueToJson(target, *v, format, flags, maxStringLength);
763 } 805 }
764 else 806 else
765 { 807 {
766 assert(target.type() == Json::nullValue); 808 assert(target.type() == Json::nullValue);