comparison OrthancServer/FromDcmtkBridge.cpp @ 305:86bb79522f19

name of the private tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Dec 2012 13:01:46 +0100
parents 4eea080e6e7a
children 326d5a4a5af3
comparison
equal deleted inserted replaced
304:4eea080e6e7a 305:86bb79522f19
569 throw OrthancException(ErrorCode_InternalError); 569 throw OrthancException(ErrorCode_InternalError);
570 } 570 }
571 } 571 }
572 572
573 573
574 void ParsedDicomFile::ReplaceInternal(const DicomTag& tag, 574 void ParsedDicomFile::Replace(const DicomTag& tag,
575 const std::string& value, 575 const std::string& value,
576 bool insertOnAbsent) 576 DicomReplaceMode mode)
577 { 577 {
578 DcmTagKey key(tag.GetGroup(), tag.GetElement()); 578 DcmTagKey key(tag.GetGroup(), tag.GetElement());
579 DcmElement* element = NULL; 579 DcmElement* element = NULL;
580 580
581 if (!file_->getDataset()->findAndGetElement(key, element).good() || 581 if (!file_->getDataset()->findAndGetElement(key, element).good() ||
582 element == NULL) 582 element == NULL)
583 { 583 {
584 if (insertOnAbsent) 584 // This field does not exist, act wrt. the specified "mode"
585 { 585 switch (mode)
586 // This field does not exist, use "Insert()" instead 586 {
587 Insert(tag, value); 587 case DicomReplaceMode_InsertIfAbsent:
588 } 588 Insert(tag, value);
589 else 589 break;
590 { 590
591 throw OrthancException(ErrorCode_InternalError); 591 case DicomReplaceMode_ThrowIfAbsent:
592 throw OrthancException(ErrorCode_InexistentItem);
593
594 case DicomReplaceMode_IgnoreIfAbsent:
595 return;
592 } 596 }
593 } 597 }
594 else 598 else
595 { 599 {
596 FillElementWithString(*element, tag, value); 600 FillElementWithString(*element, tag, value);
604 * UID' and 'SOP Instance UID') via insert or modify mode 608 * UID' and 'SOP Instance UID') via insert or modify mode
605 * options. You can disable this behaviour by using the -nmu 609 * options. You can disable this behaviour by using the -nmu
606 * option. 610 * option.
607 **/ 611 **/
608 if (tag == DICOM_TAG_SOP_CLASS_UID) 612 if (tag == DICOM_TAG_SOP_CLASS_UID)
609 ReplaceInternal(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, true); 613 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent);
610 614
611 if (tag == DICOM_TAG_SOP_INSTANCE_UID) 615 if (tag == DICOM_TAG_SOP_INSTANCE_UID)
612 ReplaceInternal(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, true); 616 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent);
613 } 617 }
614 618
615 619
616 void ParsedDicomFile::Replace(const DicomTag& tag,
617 const std::string& value)
618 {
619 return ReplaceInternal(tag, value, false);
620 }
621
622 void ParsedDicomFile::InsertOrReplace(const DicomTag& tag,
623 const std::string& value)
624 {
625 return ReplaceInternal(tag, value, true);
626 }
627
628
629
630 void ParsedDicomFile::Answer(RestApiOutput& output) 620 void ParsedDicomFile::Answer(RestApiOutput& output)
631 { 621 {
632 std::string serialized; 622 std::string serialized;
633 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, file_->getDataset())) 623 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, file_->getDataset()))
634 { 624 {
877 unsigned int maxStringLength) 867 unsigned int maxStringLength)
878 { 868 {
879 assert(target.type() == Json::objectValue); 869 assert(target.type() == Json::objectValue);
880 870
881 DicomTag tag(FromDcmtkBridge::GetTag(element)); 871 DicomTag tag(FromDcmtkBridge::GetTag(element));
872 const std::string formattedTag = tag.Format();
873
874 #if 0
882 const std::string tagName = FromDcmtkBridge::GetName(tag); 875 const std::string tagName = FromDcmtkBridge::GetName(tag);
883 const std::string formattedTag = tag.Format(); 876 #else
877 // This version of the code gives access to the name of the private tags
878 DcmTag tagbis(element.getTag());
879 const std::string tagName(tagbis.getTagName());
880 #endif
884 881
885 if (element.isLeaf()) 882 if (element.isLeaf())
886 { 883 {
887 Json::Value value(Json::objectValue); 884 Json::Value value(Json::objectValue);
888 value["Name"] = tagName; 885 value["Name"] = tagName;
1120 { 1117 {
1121 return n; 1118 return n;
1122 } 1119 }
1123 // End of patches 1120 // End of patches
1124 1121
1122 #if 0
1125 DcmTagKey tag(t.GetGroup(), t.GetElement()); 1123 DcmTagKey tag(t.GetGroup(), t.GetElement());
1126 const DcmDataDictionary& dict = dcmDataDict.rdlock(); 1124 const DcmDataDictionary& dict = dcmDataDict.rdlock();
1127 const DcmDictEntry* entry = dict.findEntry(tag, NULL); 1125 const DcmDictEntry* entry = dict.findEntry(tag, NULL);
1128 1126
1129 std::string s("Unknown"); 1127 std::string s("Unknown");
1132 s = std::string(entry->getTagName()); 1130 s = std::string(entry->getTagName());
1133 } 1131 }
1134 1132
1135 dcmDataDict.unlock(); 1133 dcmDataDict.unlock();
1136 return s; 1134 return s;
1135 #else
1136 DcmTag tag(t.GetGroup(), t.GetElement());
1137 const char* name = tag.getTagName();
1138 if (name == NULL)
1139 {
1140 return "Unknown";
1141 }
1142 else
1143 {
1144 return std::string(name);
1145 }
1146 #endif
1137 } 1147 }
1138 1148
1139 1149
1140 DicomTag FromDcmtkBridge::ParseTag(const char* name) 1150 DicomTag FromDcmtkBridge::ParseTag(const char* name)
1141 { 1151 {
1153 uint16_t group = GetTagValue(name); 1163 uint16_t group = GetTagValue(name);
1154 uint16_t element = GetTagValue(name + 5); 1164 uint16_t element = GetTagValue(name + 5);
1155 return DicomTag(group, element); 1165 return DicomTag(group, element);
1156 } 1166 }
1157 1167
1168 #if 0
1158 const DcmDataDictionary& dict = dcmDataDict.rdlock(); 1169 const DcmDataDictionary& dict = dcmDataDict.rdlock();
1159 const DcmDictEntry* entry = dict.findEntry(name); 1170 const DcmDictEntry* entry = dict.findEntry(name);
1160 1171
1161 if (entry == NULL) 1172 if (entry == NULL)
1162 { 1173 {
1168 DcmTagKey key = entry->getKey(); 1179 DcmTagKey key = entry->getKey();
1169 DicomTag tag(key.getGroup(), key.getElement()); 1180 DicomTag tag(key.getGroup(), key.getElement());
1170 dcmDataDict.unlock(); 1181 dcmDataDict.unlock();
1171 return tag; 1182 return tag;
1172 } 1183 }
1184 #else
1185 DcmTag tag;
1186 if (DcmTag::findTagFromName(name, tag).good())
1187 {
1188 return DicomTag(tag.getGTag(), tag.getETag());
1189 }
1190 else
1191 {
1192 throw OrthancException("Unknown DICOM tag");
1193 }
1194 #endif
1173 } 1195 }
1174 1196
1175 1197
1176 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) 1198 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m)
1177 { 1199 {