Mercurial > hg > orthanc
comparison OrthancServer/ParsedDicomFile.cpp @ 1307:f796207e3df1
Fix replacement and insertion of private DICOM tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 10:26:17 +0100 |
parents | 6e7e5ed91c2d |
children | 60cc0ee61edb |
comparison
equal
deleted
inserted
replaced
1306:8cd5784a6d80 | 1307:f796207e3df1 |
---|---|
805 } | 805 } |
806 } | 806 } |
807 | 807 |
808 | 808 |
809 | 809 |
810 | |
810 void ParsedDicomFile::Insert(const DicomTag& tag, | 811 void ParsedDicomFile::Insert(const DicomTag& tag, |
811 const std::string& value) | 812 const std::string& value) |
812 { | 813 { |
813 std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); | 814 OFCondition cond; |
814 FillElementWithString(*element, tag, value); | 815 |
815 | 816 if (FromDcmtkBridge::IsPrivateTag(tag)) |
816 if (!pimpl_->file_->getDataset()->insert(element.release(), false, false).good()) | 817 { |
818 // This is a private tag | |
819 // http://support.dcmtk.org/redmine/projects/dcmtk/wiki/howto_addprivatedata | |
820 | |
821 DcmTag key(tag.GetGroup(), tag.GetElement(), EVR_OB); | |
822 cond = pimpl_->file_->getDataset()->putAndInsertUint8Array | |
823 (key, (const Uint8*) value.c_str(), value.size(), false); | |
824 } | |
825 else | |
826 { | |
827 std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); | |
828 FillElementWithString(*element, tag, value); | |
829 | |
830 cond = pimpl_->file_->getDataset()->insert(element.release(), false, false); | |
831 } | |
832 | |
833 if (!cond.good()) | |
817 { | 834 { |
818 // This field already exists | 835 // This field already exists |
819 throw OrthancException(ErrorCode_InternalError); | 836 throw OrthancException(ErrorCode_InternalError); |
820 } | 837 } |
821 } | 838 } |
845 return; | 862 return; |
846 } | 863 } |
847 } | 864 } |
848 else | 865 else |
849 { | 866 { |
850 FillElementWithString(*element, tag, value); | 867 if (FromDcmtkBridge::IsPrivateTag(tag)) |
868 { | |
869 if (!element->putUint8Array((const Uint8*) value.c_str(), value.size()).good()) | |
870 { | |
871 throw OrthancException(ErrorCode_InternalError); | |
872 } | |
873 } | |
874 else | |
875 { | |
876 FillElementWithString(*element, tag, value); | |
877 } | |
851 } | 878 } |
852 | 879 |
853 | 880 |
854 /** | 881 /** |
855 * dcmodify will automatically correct 'Media Storage SOP Class | 882 * dcmodify will automatically correct 'Media Storage SOP Class |
886 bool ParsedDicomFile::GetTagValue(std::string& value, | 913 bool ParsedDicomFile::GetTagValue(std::string& value, |
887 const DicomTag& tag) | 914 const DicomTag& tag) |
888 { | 915 { |
889 DcmTagKey k(tag.GetGroup(), tag.GetElement()); | 916 DcmTagKey k(tag.GetGroup(), tag.GetElement()); |
890 DcmDataset& dataset = *pimpl_->file_->getDataset(); | 917 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
891 DcmElement* element = NULL; | 918 |
892 if (!dataset.findAndGetElement(k, element).good() || | 919 if (FromDcmtkBridge::IsPrivateTag(tag)) |
893 element == NULL) | 920 { |
894 { | 921 const Uint8* data = NULL; // This is freed in the destructor of the dataset |
895 return false; | 922 long unsigned int count = 0; |
896 } | 923 |
897 | 924 if (dataset.findAndGetUint8Array(k, data, &count).good()) |
898 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); | 925 { |
899 | 926 if (count > 0) |
900 if (v.get() == NULL) | 927 { |
901 { | 928 assert(data != NULL); |
902 value = ""; | 929 value.assign(reinterpret_cast<const char*>(data), count); |
930 } | |
931 else | |
932 { | |
933 value.clear(); | |
934 } | |
935 | |
936 return true; | |
937 } | |
938 else | |
939 { | |
940 return false; | |
941 } | |
903 } | 942 } |
904 else | 943 else |
905 { | 944 { |
906 value = v->AsString(); | 945 DcmElement* element = NULL; |
907 } | 946 if (!dataset.findAndGetElement(k, element).good() || |
908 | 947 element == NULL) |
909 return true; | 948 { |
949 return false; | |
950 } | |
951 | |
952 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); | |
953 | |
954 if (v.get() == NULL) | |
955 { | |
956 value = ""; | |
957 } | |
958 else | |
959 { | |
960 value = v->AsString(); | |
961 } | |
962 | |
963 return true; | |
964 } | |
910 } | 965 } |
911 | 966 |
912 | 967 |
913 DicomInstanceHasher ParsedDicomFile::GetHasher() | 968 DicomInstanceHasher ParsedDicomFile::GetHasher() |
914 { | 969 { |