# HG changeset patch # User Sebastien Jodogne # Date 1403793725 -7200 # Node ID 81134ea872ff8326ef47df7a5fe38a1da8ec3876 # Parent b39c4837966e14410ff98cb77dcd6e9de2bff34f retrieve values of modules diff -r b39c4837966e -r 81134ea872ff NEWS --- a/NEWS Thu Jun 26 16:01:57 2014 +0200 +++ b/NEWS Thu Jun 26 16:42:05 2014 +0200 @@ -2,6 +2,7 @@ =============================== * Official support of OS X (Darwin) +* Extraction of patient/study/series/instance DICOM modules * Extraction of the tags shared by all the instances of a patient/study/series * Options to limit the number of results for an incoming C-FIND query * Support of kFreeBSD diff -r b39c4837966e -r 81134ea872ff OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Jun 26 16:01:57 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Jun 26 16:42:05 2014 +0200 @@ -691,6 +691,60 @@ } + template + static void GetModule(RestApi::GetCall& call) + { + ServerContext& context = OrthancRestApi::GetContext(call); + std::string publicId = call.GetUriComponent("id", ""); + + typedef std::set Module; + Module module; + DicomTag::GetTagsForModule(module, resourceType); + + Json::Value tags; + + if (resourceType != ResourceType_Instance) + { + // Retrieve all the instances of this patient/study/series + typedef std::list Instances; + Instances instances; + context.GetIndex().GetChildInstances(instances, publicId); + + if (instances.empty()) + { + return; // Error: No instance (should never happen) + } + + // Select one child instance + publicId = instances.front(); + } + + context.ReadJson(tags, publicId); + + // Filter the tags of the instance according to the module + Json::Value result = Json::objectValue; + for (Module::const_iterator it = module.begin(); it != module.end(); it++) + { + std::string s = it->Format(); + if (tags.isMember(s)) + { + result[s] = tags[s]; + } + } + + if (simplify) + { + Json::Value simplified; + SimplifyTags(simplified, result); + call.GetOutput().AnswerJson(simplified); + } + else + { + call.GetOutput().AnswerJson(result); + } + } + + void OrthancRestApi::RegisterResources() { Register("/instances", ListResources); @@ -719,6 +773,15 @@ Register("/studies/{id}/shared-tags", GetSharedTags); Register("/studies/{id}/simplified-shared-tags", GetSharedTags); + Register("/instances/{id}/module", GetModule); + Register("/patients/{id}/module", GetModule); + Register("/series/{id}/module", GetModule); + Register("/studies/{id}/module", GetModule); + Register("/instances/{id}/simplified-module", GetModule); + Register("/patients/{id}/simplified-module", GetModule); + Register("/series/{id}/simplified-module", GetModule); + Register("/studies/{id}/simplified-module", GetModule); + Register("/instances/{id}/file", GetInstanceFile); Register("/instances/{id}/export", ExportInstanceFile); Register("/instances/{id}/tags", GetInstanceTags); diff -r b39c4837966e -r 81134ea872ff UnitTestsSources/DicomMap.cpp --- a/UnitTestsSources/DicomMap.cpp Thu Jun 26 16:01:57 2014 +0200 +++ b/UnitTestsSources/DicomMap.cpp Thu Jun 26 16:42:05 2014 +0200 @@ -37,6 +37,7 @@ #include "../Core/OrthancException.h" #include "../Core/DicomFormat/DicomMap.h" #include "../Core/DicomFormat/DicomNullValue.h" +#include "../OrthancServer/FromDcmtkBridge.h" #include @@ -128,3 +129,61 @@ DicomMap::SetupFindInstanceTemplate(m); ASSERT_TRUE(m.HasTag(DICOM_TAG_SOP_INSTANCE_UID)); } + + + + +static void TestModule(ResourceType level) +{ + std::set module, main; + DicomTag::GetTagsForModule(module, level); + DicomMap::GetMainDicomTags(main, level); + + // The main dicom tags are a subset of the module + for (std::set::const_iterator it = main.begin(); it != main.end(); it++) + { + bool ok = module.find(*it) != module.end(); + + // Exceptions for the Series level + /*if ((// + *it == DicomTag(0x, 0x) && + level == ResourceType_Series)) + { + ok = true; + }*/ + + // Exceptions for the Instance level + if ((/* Accession number, from Image module */ + *it == DicomTag(0x0020, 0x0012) && + level == ResourceType_Instance) || + (/* Image Index, from PET Image module */ + *it == DicomTag(0x0054, 0x1330) && + level == ResourceType_Instance) || + (/* Temporal Position Identifier, from MR Image module */ + *it == DicomTag(0x0020, 0x0100) && + level == ResourceType_Instance) || + (/* Number of Frames, from Multi-frame module attributes, related to Image IOD */ + *it == DicomTag(0x0028, 0x0008) && + level == ResourceType_Instance )) + { + ok = true; + } + + if (!ok) + { + std::cout << it->Format() << ": " << FromDcmtkBridge::GetName(*it) + << " not expected at level " << EnumerationToString(level) << std::endl; + } + + EXPECT_TRUE(ok); + } +} + + +TEST(DicomMap, Modules) +{ + TestModule(ResourceType_Patient); + TestModule(ResourceType_Study); + //TestModule(ResourceType_Series); // TODO + TestModule(ResourceType_Instance); +}