comparison OrthancServer/FromDcmtkBridge.cpp @ 1690:ae09132e4237

FromJson
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 Oct 2015 17:42:42 +0200
parents 26083d84d237
children e447f3cb8b30
comparison
equal deleted inserted replaced
1689:26083d84d237 1690:ae09132e4237
693 DicomToJsonFormat format, 693 DicomToJsonFormat format,
694 unsigned int maxStringLength, 694 unsigned int maxStringLength,
695 Encoding encoding); 695 Encoding encoding);
696 696
697 697
698 static void ElementToJson(Json::Value& parent, 698 void FromDcmtkBridge::ToJson(Json::Value& parent,
699 DcmElement& element, 699 DcmElement& element,
700 DicomToJsonFormat format, 700 DicomToJsonFormat format,
701 unsigned int maxStringLength, 701 unsigned int maxStringLength,
702 Encoding encoding) 702 Encoding encoding)
703 { 703 {
704 parent = Json::objectValue;
704 Json::Value& target = PrepareNode(parent, element, format); 705 Json::Value& target = PrepareNode(parent, element, format);
705 706
706 if (element.isLeaf()) 707 if (element.isLeaf())
707 { 708 {
708 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, encoding)); 709 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, encoding));
737 assert(parent.type() == Json::objectValue); 738 assert(parent.type() == Json::objectValue);
738 739
739 for (unsigned long i = 0; i < item.card(); i++) 740 for (unsigned long i = 0; i < item.card(); i++)
740 { 741 {
741 DcmElement* element = item.getElement(i); 742 DcmElement* element = item.getElement(i);
742 ElementToJson(parent, *element, format, maxStringLength, encoding); 743 FromDcmtkBridge::ToJson(parent, *element, format, maxStringLength, encoding);
743 } 744 }
744 } 745 }
745 746
746 747
747 void FromDcmtkBridge::ToJson(Json::Value& target, 748 void FromDcmtkBridge::ToJson(Json::Value& target,
750 unsigned int maxStringLength) 751 unsigned int maxStringLength)
751 { 752 {
752 target = Json::objectValue; 753 target = Json::objectValue;
753 DatasetToJson(target, dataset, format, maxStringLength, DetectEncoding(dataset)); 754 DatasetToJson(target, dataset, format, maxStringLength, DetectEncoding(dataset));
754 } 755 }
755
756
757
758 void FromDcmtkBridge::ToJson(Json::Value& target,
759 const std::string& path,
760 DicomToJsonFormat format,
761 unsigned int maxStringLength)
762 {
763 DcmFileFormat dicom;
764 if (!dicom.loadFile(path.c_str()).good())
765 {
766 throw OrthancException(ErrorCode_BadFileFormat);
767 }
768 else
769 {
770 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), format, maxStringLength);
771 }
772 }
773
774 756
775 757
776 std::string FromDcmtkBridge::GetName(const DicomTag& t) 758 std::string FromDcmtkBridge::GetName(const DicomTag& t)
777 { 759 {
778 // Some patches for important tags because of different DICOM 760 // Some patches for important tags because of different DICOM
1331 const DicomTag& tag, 1313 const DicomTag& tag,
1332 bool decodeBinaryTags) 1314 bool decodeBinaryTags)
1333 { 1315 {
1334 std::auto_ptr<DcmElement> element; 1316 std::auto_ptr<DcmElement> element;
1335 1317
1336 if (value.type() == Json::stringValue) 1318 switch (value.type())
1337 { 1319 {
1338 element.reset(CreateElementForTag(tag)); 1320 case Json::stringValue:
1339 FillElementWithString(*element, tag, value.asString(), decodeBinaryTags); 1321 element.reset(CreateElementForTag(tag));
1322 FillElementWithString(*element, tag, value.asString(), decodeBinaryTags);
1323 break;
1324
1325 case Json::arrayValue:
1326 {
1327 DcmTag key(tag.GetGroup(), tag.GetElement());
1328 if (key.getEVR() != EVR_SQ)
1329 {
1330 throw OrthancException(ErrorCode_BadParameterType);
1331 }
1332
1333 DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key, value.size());
1334 element.reset(sequence);
1335
1336 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
1337 {
1338 std::auto_ptr<DcmItem> item(new DcmItem);
1339
1340 Json::Value::Members members = value[i].getMemberNames();
1341 for (Json::Value::ArrayIndex j = 0; j < members.size(); j++)
1342 {
1343 item->insert(FromJson(value[i][members[j]], ParseTag(members[j]), decodeBinaryTags));
1344 }
1345
1346 sequence->append(item.release());
1347 }
1348
1349 break;
1350 }
1351
1352 default:
1353 throw OrthancException(ErrorCode_BadParameterType);
1340 } 1354 }
1341 1355
1342 return element.release(); 1356 return element.release();
1343 } 1357 }
1344 } 1358 }