comparison OrthancServer/ParsedDicomFile.cpp @ 2202:9b373b7d6713

Fix handling of encodings in C-FIND requests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Dec 2016 12:45:06 +0100
parents 5a8840920121
children 6dc3bdb4088b
comparison
equal deleted inserted replaced
2201:307365d0991a 2202:9b373b7d6713
870 ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance)); 870 ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
871 } 871 }
872 } 872 }
873 873
874 874
875 ParsedDicomFile::ParsedDicomFile(const DicomMap& map) : pimpl_(new PImpl) 875 void ParsedDicomFile::CreateFromDicomMap(const DicomMap& source,
876 { 876 Encoding defaultEncoding)
877 std::auto_ptr<DcmDataset> dataset(ToDcmtkBridge::Convert(map)); 877 {
878 878 pimpl_->file_.reset(new DcmFileFormat);
879 // NOTE: This implies an unnecessary memory copy of the dataset, but no way to get around 879
880 // http://support.dcmtk.org/redmine/issues/544 880 const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET);
881 std::auto_ptr<DcmFileFormat> fileFormat(new DcmFileFormat(dataset.get())); 881 if (tmp != NULL)
882 882 {
883 pimpl_->file_.reset(fileFormat.release()); 883 Encoding encoding;
884 if (tmp->IsNull() ||
885 tmp->IsBinary() ||
886 !GetDicomEncoding(encoding, tmp->GetContent().c_str()))
887 {
888 throw OrthancException(ErrorCode_ParameterOutOfRange);
889 }
890 else
891 {
892 SetEncoding(encoding);
893 }
894 }
895 else
896 {
897 SetEncoding(defaultEncoding);
898 }
899
900 for (DicomMap::Map::const_iterator
901 it = source.map_.begin(); it != source.map_.end(); ++it)
902 {
903 if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET &&
904 !it->second->IsNull())
905 {
906 ReplacePlainString(it->first, it->second->GetContent());
907 }
908 }
909 }
910
911
912 ParsedDicomFile::ParsedDicomFile(const DicomMap& map,
913 Encoding defaultEncoding) :
914 pimpl_(new PImpl)
915 {
916 CreateFromDicomMap(map, defaultEncoding);
917 }
918
919
920 ParsedDicomFile::ParsedDicomFile(const DicomMap& map) :
921 pimpl_(new PImpl)
922 {
923 CreateFromDicomMap(map, Configuration::GetDefaultEncoding());
884 } 924 }
885 925
886 926
887 ParsedDicomFile::ParsedDicomFile(const void* content, 927 ParsedDicomFile::ParsedDicomFile(const void* content,
888 size_t size) : pimpl_(new PImpl) 928 size_t size) : pimpl_(new PImpl)