Mercurial > hg > orthanc
changeset 562:f64e3838d6e1 find-move-scp
refactoring enumerations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Sep 2013 16:49:48 +0200 |
parents | e0cfb413c86b |
children | c931ac02db82 |
files | Core/DicomFormat/DicomMap.cpp Core/DicomFormat/DicomMap.h Core/Enumerations.cpp Core/Enumerations.h OrthancServer/ServerEnumerations.cpp OrthancServer/ServerEnumerations.h UnitTests/ServerIndex.cpp |
diffstat | 7 files changed, 128 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- 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)); + } }
--- 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 <map> #include <json/json.h> @@ -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); }; }
--- 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); + } + } }
--- 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); }
--- 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); - } - } }
--- 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 <string> +#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); }
--- 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)); +}