# HG changeset patch # User Sebastien Jodogne # Date 1580905488 -3600 # Node ID 335611d2b6cd1387b7ad13a692207359da956eb8 # Parent 05df4860aea69d7d936c49d7fb93f5ae66e2d937# Parent 46cb00e4adbb4ca0f33d33c695666c834102168c integration mainline->storage-commitment diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomFormat/DicomArray.cpp --- a/Core/DicomFormat/DicomArray.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomFormat/DicomArray.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -40,10 +40,10 @@ { DicomArray::DicomArray(const DicomMap& map) { - elements_.reserve(map.map_.size()); + elements_.reserve(map.content_.size()); - for (DicomMap::Map::const_iterator it = - map.map_.begin(); it != map.map_.end(); ++it) + for (DicomMap::Content::const_iterator it = + map.content_.begin(); it != map.content_.end(); ++it) { elements_.push_back(new DicomElement(it->first, *it->second)); } diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomFormat/DicomMap.cpp --- a/Core/DicomFormat/DicomMap.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomFormat/DicomMap.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -55,7 +55,7 @@ }; } - static const MainDicomTag PATIENT_MAIN_DICOM_TAGS_2[] = + static const MainDicomTag PATIENT_MAIN_DICOM_TAGS[] = { // { DicomTag(0x0010, 0x1010), "PatientAge" }, // { DicomTag(0x0010, 0x1040), "PatientAddress" }, @@ -66,7 +66,7 @@ { DICOM_TAG_PATIENT_ID, "PatientID" } }; - static const MainDicomTag STUDY_MAIN_DICOM_TAGS_2[] = + static const MainDicomTag STUDY_MAIN_DICOM_TAGS[] = { // { DicomTag(0x0010, 0x1020), "PatientSize" }, // { DicomTag(0x0010, 0x1030), "PatientWeight" }, @@ -84,7 +84,7 @@ { DICOM_TAG_REFERRING_PHYSICIAN_NAME, "ReferringPhysicianName" } }; - static const MainDicomTag SERIES_MAIN_DICOM_TAGS_2[] = + static const MainDicomTag SERIES_MAIN_DICOM_TAGS[] = { // { DicomTag(0x0010, 0x1080), "MilitaryRank" }, { DicomTag(0x0008, 0x0021), "SeriesDate" }, @@ -97,7 +97,7 @@ { DicomTag(0x0018, 0x0024), "SequenceName" }, { DicomTag(0x0018, 0x1030), "ProtocolName" }, { DicomTag(0x0020, 0x0011), "SeriesNumber" }, - { DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES, "CardiacNumberOfImage" }, + { DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES, "CardiacNumberOfImages" }, { DICOM_TAG_IMAGES_IN_ACQUISITION, "ImagesInAcquisition" }, { DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, "NumberOfTemporalPositions" }, { DICOM_TAG_NUMBER_OF_SLICES, "NumberOfSlices" }, @@ -105,15 +105,15 @@ { DICOM_TAG_SERIES_INSTANCE_UID, "SeriesInstanceUID" }, // New in db v6 - { DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "ImageOrientationPatientt" }, // TODO - Should have an unit test that fails + { DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "ImageOrientationPatient" }, { DICOM_TAG_SERIES_TYPE, "SeriesType" }, - { DICOM_TAG_OPERATOR_NAME, "OperatorName" }, + { DICOM_TAG_OPERATOR_NAME, "OperatorsName" }, { DICOM_TAG_PERFORMED_PROCEDURE_STEP_DESCRIPTION, "PerformedProcedureStepDescription" }, { DICOM_TAG_ACQUISITION_DEVICE_PROCESSING_DESCRIPTION, "AcquisitionDeviceProcessingDescription" }, - { DICOM_TAG_CONTRAST_BOLUS_AGENT, "ContrastBolusAgen" } + { DICOM_TAG_CONTRAST_BOLUS_AGENT, "ContrastBolusAgent" } }; - static const MainDicomTag INSTANCE_MAIN_DICOM_TAGS_2[] = + static const MainDicomTag INSTANCE_MAIN_DICOM_TAGS[] = { { DicomTag(0x0008, 0x0012), "InstanceCreationDate" }, { DicomTag(0x0008, 0x0013), "InstanceCreationTime" }, @@ -137,111 +137,32 @@ **/ { DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "ImageOrientationPatient" } // New in Orthanc 1.4.2 }; - - - - static const DicomTag PATIENT_MAIN_DICOM_TAGS[] = - { - //DicomTag(0x0010, 0x1010), // PatientAge - //DicomTag(0x0010, 0x1040) // PatientAddress - DicomTag(0x0010, 0x0010), // PatientName - DicomTag(0x0010, 0x0030), // PatientBirthDate - DicomTag(0x0010, 0x0040), // PatientSex - DicomTag(0x0010, 0x1000), // OtherPatientIDs - DICOM_TAG_PATIENT_ID - }; - - static const DicomTag STUDY_MAIN_DICOM_TAGS[] = - { - //DicomTag(0x0010, 0x1020), // PatientSize - //DicomTag(0x0010, 0x1030) // PatientWeight - DICOM_TAG_STUDY_DATE, - DicomTag(0x0008, 0x0030), // StudyTime - DicomTag(0x0020, 0x0010), // StudyID - DICOM_TAG_STUDY_DESCRIPTION, - DICOM_TAG_ACCESSION_NUMBER, - DICOM_TAG_STUDY_INSTANCE_UID, - DICOM_TAG_REQUESTED_PROCEDURE_DESCRIPTION, // New in db v6 - DICOM_TAG_INSTITUTION_NAME, // New in db v6 - DICOM_TAG_REQUESTING_PHYSICIAN, // New in db v6 - DICOM_TAG_REFERRING_PHYSICIAN_NAME // New in db v6 - }; - - static const DicomTag SERIES_MAIN_DICOM_TAGS[] = - { - //DicomTag(0x0010, 0x1080), // MilitaryRank - DicomTag(0x0008, 0x0021), // SeriesDate - DicomTag(0x0008, 0x0031), // SeriesTime - DICOM_TAG_MODALITY, - DicomTag(0x0008, 0x0070), // Manufacturer - DicomTag(0x0008, 0x1010), // StationName - DICOM_TAG_SERIES_DESCRIPTION, - DicomTag(0x0018, 0x0015), // BodyPartExamined - DicomTag(0x0018, 0x0024), // SequenceName - DicomTag(0x0018, 0x1030), // ProtocolName - DicomTag(0x0020, 0x0011), // SeriesNumber - DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES, - DICOM_TAG_IMAGES_IN_ACQUISITION, - DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, - DICOM_TAG_NUMBER_OF_SLICES, - DICOM_TAG_NUMBER_OF_TIME_SLICES, - DICOM_TAG_SERIES_INSTANCE_UID, - DICOM_TAG_IMAGE_ORIENTATION_PATIENT, // New in db v6 - DICOM_TAG_SERIES_TYPE, // New in db v6 - DICOM_TAG_OPERATOR_NAME, // New in db v6 - DICOM_TAG_PERFORMED_PROCEDURE_STEP_DESCRIPTION, // New in db v6 - DICOM_TAG_ACQUISITION_DEVICE_PROCESSING_DESCRIPTION, // New in db v6 - DICOM_TAG_CONTRAST_BOLUS_AGENT // New in db v6 - }; - - static const DicomTag INSTANCE_MAIN_DICOM_TAGS[] = - { - DicomTag(0x0008, 0x0012), // InstanceCreationDate - DicomTag(0x0008, 0x0013), // InstanceCreationTime - DicomTag(0x0020, 0x0012), // AcquisitionNumber - DICOM_TAG_IMAGE_INDEX, - DICOM_TAG_INSTANCE_NUMBER, - DICOM_TAG_NUMBER_OF_FRAMES, - DICOM_TAG_TEMPORAL_POSITION_IDENTIFIER, - DICOM_TAG_SOP_INSTANCE_UID, - DICOM_TAG_IMAGE_POSITION_PATIENT, // New in db v6 - DICOM_TAG_IMAGE_COMMENTS, // New in db v6 - - /** - * Main DICOM tags that are not part of any release of the - * database schema yet, and that will be part of future db v7. In - * the meantime, the user must call "/tools/reconstruct" once to - * access these tags if the corresponding DICOM files where - * indexed in the database by an older version of Orthanc. - **/ - DICOM_TAG_IMAGE_ORIENTATION_PATIENT // New in Orthanc 1.4.2 - }; - void DicomMap::LoadMainDicomTags(const DicomTag*& tags, - size_t& size, - ResourceType level) + static void LoadMainDicomTags(const MainDicomTag*& tags, + size_t& size, + ResourceType level) { switch (level) { case ResourceType_Patient: tags = PATIENT_MAIN_DICOM_TAGS; - size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag); + size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(MainDicomTag); break; case ResourceType_Study: tags = STUDY_MAIN_DICOM_TAGS; - size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag); + size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(MainDicomTag); break; case ResourceType_Series: tags = SERIES_MAIN_DICOM_TAGS; - size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag); + size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(MainDicomTag); break; case ResourceType_Instance: tags = INSTANCE_MAIN_DICOM_TAGS; - size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag); + size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(MainDicomTag); break; default: @@ -250,55 +171,106 @@ } - void DicomMap::SetValue(uint16_t group, - uint16_t element, - DicomValue* value) + static void LoadMainDicomTags(std::map& target, + ResourceType level) + { + const MainDicomTag* tags = NULL; + size_t size; + LoadMainDicomTags(tags, size, level); + + assert(tags != NULL && + size != 0); + + for (size_t i = 0; i < size; i++) + { + assert(target.find(tags[i].tag_) == target.end()); + + target[tags[i].tag_] = tags[i].name_; + } + } + + + namespace + { + class DicomTag2 : public DicomTag + { + public: + DicomTag2() : + DicomTag(0, 0) // To make std::map<> happy + { + } + + DicomTag2(const DicomTag& tag) : + DicomTag(tag) + { + } + }; + } + + + static void LoadMainDicomTags(std::map& target, + ResourceType level) + { + const MainDicomTag* tags = NULL; + size_t size; + LoadMainDicomTags(tags, size, level); + + assert(tags != NULL && + size != 0); + + for (size_t i = 0; i < size; i++) + { + assert(target.find(tags[i].name_) == target.end()); + + target[tags[i].name_] = tags[i].tag_; + } + } + + + void DicomMap::SetValueInternal(uint16_t group, + uint16_t element, + DicomValue* value) { DicomTag tag(group, element); - Map::iterator it = map_.find(tag); + Content::iterator it = content_.find(tag); - if (it != map_.end()) + if (it != content_.end()) { delete it->second; it->second = value; } else { - map_.insert(std::make_pair(tag, value)); + content_.insert(std::make_pair(tag, value)); } } - void DicomMap::SetValue(DicomTag tag, - DicomValue* value) - { - SetValue(tag.GetGroup(), tag.GetElement(), value); - } - void DicomMap::Clear() { - for (Map::iterator it = map_.begin(); it != map_.end(); ++it) + for (Content::iterator it = content_.begin(); it != content_.end(); ++it) { assert(it->second != NULL); delete it->second; } - map_.clear(); + content_.clear(); } - void DicomMap::ExtractTags(DicomMap& result, - const DicomTag* tags, - size_t count) const + static void ExtractTags(DicomMap& result, + const DicomMap::Content& source, + const MainDicomTag* tags, + size_t count) { result.Clear(); for (unsigned int i = 0; i < count; i++) { - Map::const_iterator it = map_.find(tags[i]); - if (it != map_.end()) + DicomMap::Content::const_iterator it = source.find(tags[i].tag_); + if (it != source.end()) { - result.SetValue(it->first, it->second->Clone()); + result.SetValue(it->first, *it->second /* value will be cloned */); } } } @@ -306,22 +278,22 @@ void DicomMap::ExtractPatientInformation(DicomMap& result) const { - ExtractTags(result, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + ExtractTags(result, content_, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); } void DicomMap::ExtractStudyInformation(DicomMap& result) const { - ExtractTags(result, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + ExtractTags(result, content_, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); } void DicomMap::ExtractSeriesInformation(DicomMap& result) const { - ExtractTags(result, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + ExtractTags(result, content_, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); } void DicomMap::ExtractInstanceInformation(DicomMap& result) const { - ExtractTags(result, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + ExtractTags(result, content_, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); } @@ -330,9 +302,9 @@ { std::auto_ptr result(new DicomMap); - for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it) + for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) { - result->map_.insert(std::make_pair(it->first, it->second->Clone())); + result->content_.insert(std::make_pair(it->first, it->second->Clone())); } return result.release(); @@ -343,9 +315,9 @@ { Clear(); - for (Map::const_iterator it = other.map_.begin(); it != other.map_.end(); ++it) + for (Content::const_iterator it = other.content_.begin(); it != other.content_.end(); ++it) { - map_.insert(std::make_pair(it->first, it->second->Clone())); + content_.insert(std::make_pair(it->first, it->second->Clone())); } } @@ -367,9 +339,9 @@ const DicomValue* DicomMap::TestAndGetValue(const DicomTag& tag) const { - Map::const_iterator it = map_.find(tag); + Content::const_iterator it = content_.find(tag); - if (it == map_.end()) + if (it == content_.end()) { return NULL; } @@ -382,35 +354,35 @@ void DicomMap::Remove(const DicomTag& tag) { - Map::iterator it = map_.find(tag); - if (it != map_.end()) + Content::iterator it = content_.find(tag); + if (it != content_.end()) { delete it->second; - map_.erase(it); + content_.erase(it); } } static void SetupFindTemplate(DicomMap& result, - const DicomTag* tags, + const MainDicomTag* tags, size_t count) { result.Clear(); for (size_t i = 0; i < count; i++) { - result.SetValue(tags[i], "", false); + result.SetValue(tags[i].tag_, "", false); } } void DicomMap::SetupFindPatientTemplate(DicomMap& result) { - SetupFindTemplate(result, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + SetupFindTemplate(result, PATIENT_MAIN_DICOM_TAGS, sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); } void DicomMap::SetupFindStudyTemplate(DicomMap& result) { - SetupFindTemplate(result, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + SetupFindTemplate(result, STUDY_MAIN_DICOM_TAGS, sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "", false); result.SetValue(DICOM_TAG_PATIENT_ID, "", false); @@ -423,7 +395,7 @@ void DicomMap::SetupFindSeriesTemplate(DicomMap& result) { - SetupFindTemplate(result, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + SetupFindTemplate(result, SERIES_MAIN_DICOM_TAGS, sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "", false); result.SetValue(DICOM_TAG_PATIENT_ID, "", false); result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "", false); @@ -445,7 +417,7 @@ void DicomMap::SetupFindInstanceTemplate(DicomMap& result) { - SetupFindTemplate(result, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag)); + SetupFindTemplate(result, INSTANCE_MAIN_DICOM_TAGS, sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(MainDicomTag)); result.SetValue(DICOM_TAG_ACCESSION_NUMBER, "", false); result.SetValue(DICOM_TAG_PATIENT_ID, "", false); result.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "", false); @@ -465,38 +437,13 @@ bool DicomMap::IsMainDicomTag(const DicomTag& tag, ResourceType level) { - const DicomTag *tags = NULL; + const MainDicomTag *tags = NULL; size_t size; - - switch (level) - { - case ResourceType_Patient: - tags = PATIENT_MAIN_DICOM_TAGS; - size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - case ResourceType_Study: - tags = STUDY_MAIN_DICOM_TAGS; - size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - case ResourceType_Series: - tags = SERIES_MAIN_DICOM_TAGS; - size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - case ResourceType_Instance: - tags = INSTANCE_MAIN_DICOM_TAGS; - size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } + LoadMainDicomTags(tags, size, level); for (size_t i = 0; i < size; i++) { - if (tags[i] == tag) + if (tags[i].tag_ == tag) { return true; } @@ -516,38 +463,13 @@ void DicomMap::GetMainDicomTagsInternal(std::set& result, ResourceType level) { - const DicomTag *tags = NULL; + const MainDicomTag *tags = NULL; size_t size; - - switch (level) - { - case ResourceType_Patient: - tags = PATIENT_MAIN_DICOM_TAGS; - size = sizeof(PATIENT_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - case ResourceType_Study: - tags = STUDY_MAIN_DICOM_TAGS; - size = sizeof(STUDY_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - case ResourceType_Series: - tags = SERIES_MAIN_DICOM_TAGS; - size = sizeof(SERIES_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - case ResourceType_Instance: - tags = INSTANCE_MAIN_DICOM_TAGS; - size = sizeof(INSTANCE_MAIN_DICOM_TAGS) / sizeof(DicomTag); - break; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } + LoadMainDicomTags(tags, size, level); for (size_t i = 0; i < size; i++) { - result.insert(tags[i]); + result.insert(tags[i].tag_); } } @@ -573,8 +495,8 @@ { tags.clear(); - for (Map::const_iterator it = map_.begin(); - it != map_.end(); ++it) + for (Content::const_iterator it = content_.begin(); + it != content_.end(); ++it) { tags.insert(it->first); } @@ -1124,14 +1046,14 @@ void DicomMap::Merge(const DicomMap& other) { - for (Map::const_iterator it = other.map_.begin(); - it != other.map_.end(); ++it) + for (Content::const_iterator it = other.content_.begin(); + it != other.content_.end(); ++it) { assert(it->second != NULL); - if (map_.find(it->first) == map_.end()) + if (content_.find(it->first) == content_.end()) { - map_[it->first] = it->second->Clone(); + content_[it->first] = it->second->Clone(); } } } @@ -1140,7 +1062,7 @@ void DicomMap::ExtractMainDicomTagsInternal(const DicomMap& other, ResourceType level) { - const DicomTag* tags = NULL; + const MainDicomTag* tags = NULL; size_t size = 0; LoadMainDicomTags(tags, size, level); @@ -1148,13 +1070,13 @@ for (size_t i = 0; i < size; i++) { - Map::const_iterator found = other.map_.find(tags[i]); + Content::const_iterator found = other.content_.find(tags[i].tag_); - if (found != other.map_.end() && - map_.find(tags[i]) == map_.end()) + if (found != other.content_.end() && + content_.find(tags[i].tag_) == content_.end()) { assert(found->second != NULL); - map_[tags[i]] = found->second->Clone(); + content_[tags[i].tag_] = found->second->Clone(); } } } @@ -1177,7 +1099,7 @@ std::set mainDicomTags; GetMainDicomTags(mainDicomTags); - for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it) + for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) { if (mainDicomTags.find(it->first) == mainDicomTags.end()) { @@ -1193,7 +1115,7 @@ { target = Json::objectValue; - for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it) + for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) { assert(it->second != NULL); @@ -1223,7 +1145,7 @@ DicomTag tag(0, 0); if (!DicomTag::ParseHexadecimal(tag, tags[i].c_str()) || - map_.find(tag) != map_.end()) + content_.find(tag) != content_.end()) { throw OrthancException(ErrorCode_BadFileFormat); } @@ -1231,7 +1153,7 @@ std::auto_ptr value(new DicomValue); value->Unserialize(source[tags[i]]); - map_[tag] = value.release(); + content_[tag] = value.release(); } } @@ -1390,9 +1312,9 @@ void DicomMap::RemoveBinaryTags() { - Map kept; + Content kept; - for (Map::iterator it = map_.begin(); it != map_.end(); ++it) + for (Content::iterator it = content_.begin(); it != content_.end(); ++it) { assert(it->second != NULL); @@ -1407,7 +1329,67 @@ } } - map_ = kept; + content_ = kept; + } + + + void DicomMap::DumpMainDicomTags(Json::Value& target, + ResourceType level) const + { + std::map mainTags; // TODO - Create a singleton to hold this map + LoadMainDicomTags(mainTags, level); + + target = Json::objectValue; + + for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) + { + assert(it->second != NULL); + + if (!it->second->IsBinary() && + !it->second->IsNull()) + { + std::map::const_iterator found = mainTags.find(it->first); + + if (found != mainTags.end()) + { + target[found->second] = it->second->GetContent(); + } + } + } + } + + + void DicomMap::ParseMainDicomTags(const Json::Value& source, + ResourceType level) + { + if (source.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + Clear(); + + std::map mainTags; // TODO - Create a singleton to hold this map + LoadMainDicomTags(mainTags, level); + + Json::Value::Members members = source.getMemberNames(); + for (size_t i = 0; i < members.size(); i++) + { + std::map::const_iterator found = mainTags.find(members[i]); + + if (found != mainTags.end()) + { + const Json::Value& value = source[members[i]]; + if (value.type() != Json::stringValue) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + else + { + SetValue(found->second, value.asString(), false); + } + } + } } diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomFormat/DicomMap.h --- a/Core/DicomFormat/DicomMap.h Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomFormat/DicomMap.h Wed Feb 05 13:24:48 2020 +0100 @@ -45,28 +45,23 @@ { class DicomMap : public boost::noncopyable { + public: + typedef std::map Content; + private: friend class DicomArray; friend class FromDcmtkBridge; friend class ParsedDicomFile; - typedef std::map Map; - - Map map_; + Content content_; // Warning: This takes the ownership of "value" - void SetValue(uint16_t group, - uint16_t element, - DicomValue* value); + void SetValueInternal(uint16_t group, + uint16_t element, + DicomValue* value); - void SetValue(DicomTag tag, - DicomValue* value); - - void ExtractTags(DicomMap& source, - const DicomTag* tags, - size_t count) const; - - static void GetMainDicomTagsInternal(std::set& result, ResourceType level); + static void GetMainDicomTagsInternal(std::set& result, + ResourceType level); void ExtractMainDicomTagsInternal(const DicomMap& other, ResourceType level); @@ -83,7 +78,7 @@ size_t GetSize() const { - return map_.size(); + return content_.size(); } DicomMap* Clone() const; @@ -95,32 +90,32 @@ void SetNullValue(uint16_t group, uint16_t element) { - SetValue(group, element, new DicomValue); + SetValueInternal(group, element, new DicomValue); } void SetNullValue(const DicomTag& tag) { - SetValue(tag, new DicomValue); + SetValueInternal(tag.GetGroup(), tag.GetElement(), new DicomValue); } void SetValue(uint16_t group, uint16_t element, const DicomValue& value) { - SetValue(group, element, value.Clone()); + SetValueInternal(group, element, value.Clone()); } void SetValue(const DicomTag& tag, const DicomValue& value) { - SetValue(tag, value.Clone()); + SetValueInternal(tag.GetGroup(), tag.GetElement(), value.Clone()); } void SetValue(const DicomTag& tag, const std::string& str, bool isBinary) { - SetValue(tag, new DicomValue(str, isBinary)); + SetValueInternal(tag.GetGroup(), tag.GetElement(), new DicomValue(str, isBinary)); } void SetValue(uint16_t group, @@ -128,7 +123,7 @@ const std::string& str, bool isBinary) { - SetValue(group, element, new DicomValue(str, isBinary)); + SetValueInternal(group, element, new DicomValue(str, isBinary)); } bool HasTag(uint16_t group, uint16_t element) const @@ -138,7 +133,7 @@ bool HasTag(const DicomTag& tag) const { - return map_.find(tag) != map_.end(); + return content_.find(tag) != content_.end(); } const DicomValue& GetValue(uint16_t group, uint16_t element) const @@ -188,10 +183,6 @@ void GetTags(std::set& tags) const; - static void LoadMainDicomTags(const DicomTag*& tags, - size_t& size, - ResourceType level); - static bool ParseDicomMetaInformation(DicomMap& result, const char* dicom, size_t size); @@ -240,6 +231,12 @@ void RemoveBinaryTags(); + void DumpMainDicomTags(Json::Value& target, + ResourceType level) const; + + void ParseMainDicomTags(const Json::Value& source, + ResourceType level); + void Print(FILE* fp) const; // For debugging only }; } diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomFormat/DicomTag.cpp --- a/Core/DicomFormat/DicomTag.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomFormat/DicomTag.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -187,6 +187,10 @@ if (*this == DICOM_TAG_IMAGE_ORIENTATION_PATIENT) return "ImageOrientationPatient"; + // New in Orthanc 1.6.0, as tagged as "RETIRED_" since DCMTK 3.6.4 + if (*this == DICOM_TAG_OTHER_PATIENT_IDS) + return "OtherPatientIDs"; + return ""; } diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomFormat/DicomTag.h --- a/Core/DicomFormat/DicomTag.h Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomFormat/DicomTag.h Wed Feb 05 13:24:48 2020 +0100 @@ -191,6 +191,7 @@ static const DicomTag DICOM_TAG_PATIENT_COMMENTS(0x0010, 0x4000); static const DicomTag DICOM_TAG_PATIENT_SPECIES_DESCRIPTION(0x0010, 0x2201); static const DicomTag DICOM_TAG_STUDY_COMMENTS(0x0032, 0x4000); + static const DicomTag DICOM_TAG_OTHER_PATIENT_IDS(0x0010, 0x1000); // Tags used within the Stone of Orthanc static const DicomTag DICOM_TAG_FRAME_INCREMENT_POINTER(0x0028, 0x0009); diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomParsing/FromDcmtkBridge.cpp --- a/Core/DicomParsing/FromDcmtkBridge.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomParsing/FromDcmtkBridge.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -468,10 +468,10 @@ DcmElement* element = dataset.getElement(i); if (element && element->isLeaf()) { - target.SetValue(element->getTag().getGTag(), - element->getTag().getETag(), - ConvertLeafElement(*element, DicomToJsonFlags_Default, - maxStringLength, encoding, hasCodeExtensions, ignoreTagLength)); + target.SetValueInternal(element->getTag().getGTag(), + element->getTag().getETag(), + ConvertLeafElement(*element, DicomToJsonFlags_Default, + maxStringLength, encoding, hasCodeExtensions, ignoreTagLength)); } } } @@ -1117,8 +1117,8 @@ result.clear(); - for (DicomMap::Map::const_iterator - it = values.map_.begin(); it != values.map_.end(); ++it) + for (DicomMap::Content::const_iterator + it = values.content_.begin(); it != values.content_.end(); ++it) { // TODO Inject PrivateCreator if some is available in the DicomMap? const std::string tagName = GetTagName(it->first, ""); diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomParsing/FromDcmtkBridge.h --- a/Core/DicomParsing/FromDcmtkBridge.h Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomParsing/FromDcmtkBridge.h Wed Feb 05 13:24:48 2020 +0100 @@ -192,7 +192,8 @@ const std::string& tagName, DicomValue* value) { - target.SetValue(ParseTag(tagName), value); + const DicomTag tag = ParseTag(tagName); + target.SetValueInternal(tag.GetGroup(), tag.GetElement(), value); } static void ToJson(Json::Value& result, diff -r 05df4860aea6 -r 335611d2b6cd Core/DicomParsing/ParsedDicomFile.cpp --- a/Core/DicomParsing/ParsedDicomFile.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/Core/DicomParsing/ParsedDicomFile.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -1007,8 +1007,8 @@ } } - for (DicomMap::Map::const_iterator - it = source.map_.begin(); it != source.map_.end(); ++it) + for (DicomMap::Content::const_iterator + it = source.content_.begin(); it != source.content_.end(); ++it) { if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET && !it->second->IsNull()) diff -r 05df4860aea6 -r 335611d2b6cd OrthancServer/OrthancRestApi/OrthancRestModalities.cpp diff -r 05df4860aea6 -r 335611d2b6cd OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/OrthancServer/ServerIndex.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -356,34 +356,40 @@ void LoadTags(ResourceType level) { - const DicomTag* tags = NULL; - size_t size; + { + const DicomTag* tags = NULL; + size_t size; - ServerToolbox::LoadIdentifiers(tags, size, level); + ServerToolbox::LoadIdentifiers(tags, size, level); - for (size_t i = 0; i < size; i++) - { - if (registry_.find(tags[i]) == registry_.end()) + for (size_t i = 0; i < size; i++) { - registry_[tags[i]] = TagInfo(level, DicomTagType_Identifier); - } - else - { - // These patient-level tags are copied in the study level - assert(level == ResourceType_Study && - (tags[i] == DICOM_TAG_PATIENT_ID || - tags[i] == DICOM_TAG_PATIENT_NAME || - tags[i] == DICOM_TAG_PATIENT_BIRTH_DATE)); + if (registry_.find(tags[i]) == registry_.end()) + { + registry_[tags[i]] = TagInfo(level, DicomTagType_Identifier); + } + else + { + // These patient-level tags are copied in the study level + assert(level == ResourceType_Study && + (tags[i] == DICOM_TAG_PATIENT_ID || + tags[i] == DICOM_TAG_PATIENT_NAME || + tags[i] == DICOM_TAG_PATIENT_BIRTH_DATE)); + } } } - - DicomMap::LoadMainDicomTags(tags, size, level); - - for (size_t i = 0; i < size; i++) + { - if (registry_.find(tags[i]) == registry_.end()) + std::set tags; + DicomMap::GetMainDicomTags(tags, level); + + for (std::set::const_iterator + tag = tags.begin(); tag != tags.end(); ++tag) { - registry_[tags[i]] = TagInfo(level, DicomTagType_Main); + if (registry_.find(*tag) == registry_.end()) + { + registry_[*tag] = TagInfo(level, DicomTagType_Main); + } } } } diff -r 05df4860aea6 -r 335611d2b6cd UnitTestsSources/DicomMapTests.cpp --- a/UnitTestsSources/DicomMapTests.cpp Tue Feb 04 20:00:48 2020 +0100 +++ b/UnitTestsSources/DicomMapTests.cpp Wed Feb 05 13:24:48 2020 +0100 @@ -991,3 +991,44 @@ ASSERT_TRUE(target.LookupStringValue(s, DICOM_TAG_PIXEL_SPACING, false)); ASSERT_EQ(s, "1.5\\1.3"); } + + +TEST(DicomMap, MainTagNames) +{ + ASSERT_EQ(3, ResourceType_Instance - ResourceType_Patient); + + for (int i = ResourceType_Patient; i <= ResourceType_Instance; i++) + { + ResourceType level = static_cast(i); + + std::set tags; + DicomMap::GetMainDicomTags(tags, level); + + for (std::set::const_iterator it = tags.begin(); it != tags.end(); ++it) + { + DicomMap a; + a.SetValue(*it, "TEST", false); + + Json::Value json; + a.DumpMainDicomTags(json, level); + + ASSERT_EQ(Json::objectValue, json.type()); + ASSERT_EQ(1u, json.getMemberNames().size()); + + std::string name = json.getMemberNames() [0]; + EXPECT_EQ(name, FromDcmtkBridge::GetTagName(*it, "")); + + DicomMap b; + b.ParseMainDicomTags(json, level); + + ASSERT_EQ(1u, b.GetSize()); + ASSERT_EQ("TEST", b.GetStringValue(*it, "", false)); + + std::string main = it->GetMainTagsName(); + if (!main.empty()) + { + ASSERT_EQ(main, name); + } + } + } +}