comparison Plugins/Engine/OrthancPlugins.cpp @ 1861:a7bea843a7bc

"OrthancPluginLookupDictionary()" to get information about some DICOM tag
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Dec 2015 13:00:18 +0100
parents c7d70f659190
children 5cf2bd0abfa2
comparison
equal deleted inserted replaced
1860:c7d70f659190 1861:a7bea843a7bc
42 #include "../../Core/HttpServer/HttpToolbox.h" 42 #include "../../Core/HttpServer/HttpToolbox.h"
43 #include "../../Core/Logging.h" 43 #include "../../Core/Logging.h"
44 #include "../../Core/OrthancException.h" 44 #include "../../Core/OrthancException.h"
45 #include "../../Core/Toolbox.h" 45 #include "../../Core/Toolbox.h"
46 #include "../../OrthancServer/FromDcmtkBridge.h" 46 #include "../../OrthancServer/FromDcmtkBridge.h"
47 #include "../../OrthancServer/ToDcmtkBridge.h"
47 #include "../../OrthancServer/OrthancInitialization.h" 48 #include "../../OrthancServer/OrthancInitialization.h"
48 #include "../../OrthancServer/ServerContext.h" 49 #include "../../OrthancServer/ServerContext.h"
49 #include "../../OrthancServer/ServerToolbox.h" 50 #include "../../OrthancServer/ServerToolbox.h"
50 #include "../../OrthancServer/Search/HierarchicalMatcher.h" 51 #include "../../OrthancServer/Search/HierarchicalMatcher.h"
51 #include "../../OrthancServer/Internals/DicomImageDecoder.h" 52 #include "../../OrthancServer/Internals/DicomImageDecoder.h"
58 #include "../../Core/Images/JpegWriter.h" 59 #include "../../Core/Images/JpegWriter.h"
59 #include "../../Core/Images/ImageProcessing.h" 60 #include "../../Core/Images/ImageProcessing.h"
60 #include "PluginsEnumerations.h" 61 #include "PluginsEnumerations.h"
61 62
62 #include <boost/regex.hpp> 63 #include <boost/regex.hpp>
64 #include <dcmtk/dcmdata/dcdict.h>
65 #include <dcmtk/dcmdata/dcdicent.h>
63 66
64 namespace Orthanc 67 namespace Orthanc
65 { 68 {
66 static void CopyToMemoryBuffer(OrthancPluginMemoryBuffer& target, 69 static void CopyToMemoryBuffer(OrthancPluginMemoryBuffer& target,
67 const void* data, 70 const void* data,
1588 throw OrthancException(ErrorCode_BadRequest); 1591 throw OrthancException(ErrorCode_BadRequest);
1589 } 1592 }
1590 } 1593 }
1591 1594
1592 1595
1596
1597 namespace
1598 {
1599 class DictionaryReadLocker
1600 {
1601 private:
1602 const DcmDataDictionary& dictionary_;
1603
1604 public:
1605 DictionaryReadLocker() : dictionary_(dcmDataDict.rdlock())
1606 {
1607 }
1608
1609 ~DictionaryReadLocker()
1610 {
1611 dcmDataDict.unlock();
1612 }
1613
1614 const DcmDataDictionary* operator->()
1615 {
1616 return &dictionary_;
1617 }
1618 };
1619 }
1620
1621
1622 void OrthancPlugins::ApplyLookupDictionary(const void* parameters)
1623 {
1624 const _OrthancPluginLookupDictionary& p =
1625 *reinterpret_cast<const _OrthancPluginLookupDictionary*>(parameters);
1626
1627 DicomTag tag(FromDcmtkBridge::ParseTag(p.name));
1628 DcmTagKey tag2(tag.GetGroup(), tag.GetElement());
1629
1630 DictionaryReadLocker locker;
1631 const DcmDictEntry* entry = locker->findEntry(tag2, NULL);
1632
1633 if (entry == NULL)
1634 {
1635 throw OrthancException(ErrorCode_UnknownDicomTag);
1636 }
1637 else
1638 {
1639 p.target->group = entry->getKey().getGroup();
1640 p.target->element = entry->getKey().getElement();
1641 p.target->vr = Plugins::Convert(entry->getEVR());
1642 p.target->minMultiplicity = static_cast<uint32_t>(entry->getVMMin());
1643 p.target->maxMultiplicity = (entry->getVMMax() == DcmVariableVM ? 0 : static_cast<uint32_t>(entry->getVMMax()));
1644 }
1645 }
1646
1647
1648
1593 bool OrthancPlugins::InvokeService(SharedLibrary& plugin, 1649 bool OrthancPlugins::InvokeService(SharedLibrary& plugin,
1594 _OrthancPluginService service, 1650 _OrthancPluginService service,
1595 const void* parameters) 1651 const void* parameters)
1596 { 1652 {
1597 VLOG(1) << "Calling service " << service << " from plugin " << plugin.GetPath(); 1653 VLOG(1) << "Calling service " << service << " from plugin " << plugin.GetPath();
2146 case _OrthancPluginService_ComputeMd5: 2202 case _OrthancPluginService_ComputeMd5:
2147 case _OrthancPluginService_ComputeSha1: 2203 case _OrthancPluginService_ComputeSha1:
2148 ComputeHash(service, parameters); 2204 ComputeHash(service, parameters);
2149 return true; 2205 return true;
2150 2206
2207 case _OrthancPluginService_LookupDictionary:
2208 ApplyLookupDictionary(parameters);
2209 return true;
2210
2151 default: 2211 default:
2152 { 2212 {
2153 // This service is unknown to the Orthanc plugin engine 2213 // This service is unknown to the Orthanc plugin engine
2154 return false; 2214 return false;
2155 } 2215 }