# HG changeset patch # User Sebastien Jodogne # Date 1379515788 -7200 # Node ID f64e3838d6e1484556308ba58f1381d8427dab55 # Parent e0cfb413c86b2d1d5e19f8b1d36c39be0630e35e refactoring enumerations diff -r e0cfb413c86b -r f64e3838d6e1 Core/DicomFormat/DicomMap.cpp --- a/Core/DicomFormat/DicomMap.cpp Wed Sep 18 16:22:21 2013 +0200 +++ b/Core/DicomFormat/DicomMap.cpp Wed Sep 18 16:49:48 2013 +0200 @@ -280,4 +280,55 @@ SetValue(tag, source.GetValue(tag)); } } + + + bool DicomMap::IsMainDicomTag(const DicomTag& tag, ResourceType level) + { + DicomTag *tags = NULL; + size_t size; + + switch (level) + { + case ResourceType_Patient: + tags = patientTags; + size = sizeof(patientTags) / sizeof(DicomTag); + break; + + case ResourceType_Study: + tags = studyTags; + size = sizeof(studyTags) / sizeof(DicomTag); + break; + + case ResourceType_Series: + tags = seriesTags; + size = sizeof(seriesTags) / sizeof(DicomTag); + break; + + case ResourceType_Instance: + tags = instanceTags; + size = sizeof(instanceTags) / sizeof(DicomTag); + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + for (size_t i = 0; i < size; i++) + { + if (tags[i] == tag) + { + return true; + } + } + + return false; + } + + bool DicomMap::IsMainDicomTag(const DicomTag& tag) + { + return (IsMainDicomTag(tag, ResourceType_Patient) || + IsMainDicomTag(tag, ResourceType_Study) || + IsMainDicomTag(tag, ResourceType_Series) || + IsMainDicomTag(tag, ResourceType_Instance)); + } } diff -r e0cfb413c86b -r f64e3838d6e1 Core/DicomFormat/DicomMap.h --- a/Core/DicomFormat/DicomMap.h Wed Sep 18 16:22:21 2013 +0200 +++ b/Core/DicomFormat/DicomMap.h Wed Sep 18 16:49:48 2013 +0200 @@ -35,6 +35,7 @@ #include "DicomTag.h" #include "DicomValue.h" #include "DicomString.h" +#include "../Enumerations.h" #include #include @@ -148,5 +149,9 @@ void CopyTagIfExists(const DicomMap& source, const DicomTag& tag); + + static bool IsMainDicomTag(const DicomTag& tag, ResourceType level); + + static bool IsMainDicomTag(const DicomTag& tag); }; } diff -r e0cfb413c86b -r f64e3838d6e1 Core/Enumerations.cpp --- a/Core/Enumerations.cpp Wed Sep 18 16:22:21 2013 +0200 +++ b/Core/Enumerations.cpp Wed Sep 18 16:49:48 2013 +0200 @@ -33,6 +33,7 @@ #include "Enumerations.h" #include "OrthancException.h" +#include "Toolbox.h" namespace Orthanc { @@ -222,4 +223,54 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } } + + + const char* EnumerationToString(ResourceType type) + { + switch (type) + { + case ResourceType_Patient: + return "Patient"; + + case ResourceType_Study: + return "Study"; + + case ResourceType_Series: + return "Series"; + + case ResourceType_Instance: + return "Instance"; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + + ResourceType StringToResourceType(const char* type) + { + std::string s(type); + Toolbox::ToUpperCase(s); + + if (s == "PATIENT") + { + return ResourceType_Patient; + } + else if (s == "STUDY") + { + return ResourceType_Study; + } + else if (s == "SERIES") + { + return ResourceType_Series; + } + else if (s == "INSTANCE" || s == "IMAGE") + { + return ResourceType_Instance; + } + else + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } } diff -r e0cfb413c86b -r f64e3838d6e1 Core/Enumerations.h --- a/Core/Enumerations.h Wed Sep 18 16:22:21 2013 +0200 +++ b/Core/Enumerations.h Wed Sep 18 16:49:48 2013 +0200 @@ -183,9 +183,20 @@ FileContentType_Json = 2 }; + enum ResourceType + { + ResourceType_Patient = 1, + ResourceType_Study = 2, + ResourceType_Series = 3, + ResourceType_Instance = 4 + }; const char* EnumerationToString(HttpMethod method); const char* EnumerationToString(HttpStatus status); + + const char* EnumerationToString(ResourceType type); + + ResourceType StringToResourceType(const char* type); } diff -r e0cfb413c86b -r f64e3838d6e1 OrthancServer/ServerEnumerations.cpp --- a/OrthancServer/ServerEnumerations.cpp Wed Sep 18 16:22:21 2013 +0200 +++ b/OrthancServer/ServerEnumerations.cpp Wed Sep 18 16:49:48 2013 +0200 @@ -83,27 +83,6 @@ return dictMetadataType_.Translate(str); } - const char* EnumerationToString(ResourceType type) - { - switch (type) - { - case ResourceType_Patient: - return "Patient"; - - case ResourceType_Study: - return "Study"; - - case ResourceType_Series: - return "Series"; - - case ResourceType_Instance: - return "Instance"; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - } - std::string GetBasePath(ResourceType type, const std::string& publicId) { @@ -290,32 +269,4 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } } - - - ResourceType StringToResourceType(const char* type) - { - std::string s(type); - Toolbox::ToUpperCase(s); - - if (s == "PATIENT") - { - return ResourceType_Patient; - } - else if (s == "STUDY") - { - return ResourceType_Study; - } - else if (s == "SERIES") - { - return ResourceType_Series; - } - else if (s == "INSTANCE" || s == "IMAGE") - { - return ResourceType_Instance; - } - else - { - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - } } diff -r e0cfb413c86b -r f64e3838d6e1 OrthancServer/ServerEnumerations.h --- a/OrthancServer/ServerEnumerations.h Wed Sep 18 16:22:21 2013 +0200 +++ b/OrthancServer/ServerEnumerations.h Wed Sep 18 16:49:48 2013 +0200 @@ -33,6 +33,8 @@ #include +#include "../Core/Enumerations.h" + namespace Orthanc { enum SeriesStatus @@ -71,14 +73,6 @@ GlobalProperty_AnonymizationSequence = 3 }; - enum ResourceType - { - ResourceType_Patient = 1, - ResourceType_Study = 2, - ResourceType_Series = 3, - ResourceType_Instance = 4 - }; - enum MetadataType { MetadataType_Instance_IndexInSeries = 1, @@ -122,8 +116,6 @@ MetadataType StringToMetadata(const std::string& str); - const char* EnumerationToString(ResourceType type); - std::string EnumerationToString(MetadataType type); const char* EnumerationToString(SeriesStatus status); @@ -139,6 +131,4 @@ ResourceType GetParentResourceType(ResourceType type); ResourceType GetChildResourceType(ResourceType type); - - ResourceType StringToResourceType(const char* type); } diff -r e0cfb413c86b -r f64e3838d6e1 UnitTests/ServerIndex.cpp --- a/UnitTests/ServerIndex.cpp Wed Sep 18 16:22:21 2013 +0200 +++ b/UnitTests/ServerIndex.cpp Wed Sep 18 16:49:48 2013 +0200 @@ -487,3 +487,11 @@ } + + +TEST(DicomMap, MainTags) +{ + ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID)); + ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient)); + ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study)); +}