# HG changeset patch # User Sebastien Jodogne # Date 1593616975 -7200 # Node ID 64e92ffbba0f9cbed7cc5800a9825e7507bad7a0 # Parent 99e2054d1e8d5558ca5f9a1c3b6a420abaf5abf8 moved samples to access dicom datasets through rest api or plugins to the stone project diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/DicomDatasetReader.cpp --- a/OrthancServer/Plugins/Samples/Common/DicomDatasetReader.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "DicomDatasetReader.h" - -#include "OrthancPluginException.h" - -#include - -namespace OrthancPlugins -{ - // This function is copied-pasted from "../../../Core/Toolbox.cpp", - // in order to avoid the dependency of plugins against the Orthanc core - static std::string StripSpaces(const std::string& source) - { - size_t first = 0; - - while (first < source.length() && - isspace(source[first])) - { - first++; - } - - if (first == source.length()) - { - // String containing only spaces - return ""; - } - - size_t last = source.length(); - while (last > first && - isspace(source[last - 1])) - { - last--; - } - - assert(first <= last); - return source.substr(first, last - first); - } - - - DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) : - dataset_(dataset) - { - } - - - std::string DicomDatasetReader::GetStringValue(const DicomPath& path, - const std::string& defaultValue) const - { - std::string s; - if (dataset_.GetStringValue(s, path)) - { - return s; - } - else - { - return defaultValue; - } - } - - - std::string DicomDatasetReader::GetMandatoryStringValue(const DicomPath& path) const - { - std::string s; - if (dataset_.GetStringValue(s, path)) - { - return s; - } - else - { - ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag); - } - } - - - template - static bool GetValueInternal(T& target, - const IDicomDataset& dataset, - const DicomPath& path) - { - try - { - std::string s; - - if (dataset.GetStringValue(s, path)) - { - target = boost::lexical_cast(StripSpaces(s)); - return true; - } - else - { - return false; - } - } - catch (boost::bad_lexical_cast&) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - } - - - bool DicomDatasetReader::GetIntegerValue(int& target, - const DicomPath& path) const - { - return GetValueInternal(target, dataset_, path); - } - - - bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target, - const DicomPath& path) const - { - int value; - - if (!GetIntegerValue(value, path)) - { - return false; - } - else if (value >= 0) - { - target = static_cast(value); - return true; - } - else - { - ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); - } - } - - - bool DicomDatasetReader::GetFloatValue(float& target, - const DicomPath& path) const - { - return GetValueInternal(target, dataset_, path); - } - - - bool DicomDatasetReader::GetDoubleValue(double& target, - const DicomPath& path) const - { - return GetValueInternal(target, dataset_, path); - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/DicomDatasetReader.h --- a/OrthancServer/Plugins/Samples/Common/DicomDatasetReader.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "IDicomDataset.h" - -#include -#include - -namespace OrthancPlugins -{ - class DicomDatasetReader : public boost::noncopyable - { - private: - const IDicomDataset& dataset_; - - public: - DicomDatasetReader(const IDicomDataset& dataset); - - const IDicomDataset& GetDataset() const - { - return dataset_; - } - - std::string GetStringValue(const DicomPath& path, - const std::string& defaultValue) const; - - std::string GetMandatoryStringValue(const DicomPath& path) const; - - bool GetIntegerValue(int& target, - const DicomPath& path) const; - - bool GetUnsignedIntegerValue(unsigned int& target, - const DicomPath& path) const; - - bool GetFloatValue(float& target, - const DicomPath& path) const; - - bool GetDoubleValue(double& target, - const DicomPath& path) const; - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/DicomPath.cpp --- a/OrthancServer/Plugins/Samples/Common/DicomPath.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "DicomPath.h" - -#include "OrthancPluginException.h" - -#include - -namespace OrthancPlugins -{ - const DicomPath::Prefix& DicomPath::GetPrefixItem(size_t depth) const - { - if (depth >= prefix_.size()) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); - } - else - { - return prefix_[depth]; - } - } - - - DicomPath::Prefix& DicomPath::GetPrefixItem(size_t depth) - { - if (depth >= prefix_.size()) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); - } - else - { - return prefix_[depth]; - } - } - - - DicomPath::DicomPath(const DicomTag& sequence, - size_t index, - const DicomTag& tag) : - finalTag_(tag) - { - AddToPrefix(sequence, index); - } - - - DicomPath::DicomPath(const DicomTag& sequence1, - size_t index1, - const DicomTag& sequence2, - size_t index2, - const DicomTag& tag) : - finalTag_(tag) - { - AddToPrefix(sequence1, index1); - AddToPrefix(sequence2, index2); - } - - - DicomPath::DicomPath(const DicomTag& sequence1, - size_t index1, - const DicomTag& sequence2, - size_t index2, - const DicomTag& sequence3, - size_t index3, - const DicomTag& tag) : - finalTag_(tag) - { - AddToPrefix(sequence1, index1); - AddToPrefix(sequence2, index2); - AddToPrefix(sequence3, index3); - } - - - std::string DicomPath::Format() const - { - std::string s; - - for (size_t i = 0; i < GetPrefixLength(); i++) - { - s += (GetPrefixTag(i).FormatHexadecimal() + " / " + - boost::lexical_cast(i) + " / "); - } - - return s + GetFinalTag().FormatHexadecimal(); - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/DicomPath.h --- a/OrthancServer/Plugins/Samples/Common/DicomPath.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "DicomTag.h" - -#include -#include - -namespace OrthancPlugins -{ - class DicomPath - { - private: - typedef std::pair Prefix; - - std::vector prefix_; - DicomTag finalTag_; - - const Prefix& GetPrefixItem(size_t depth) const; - - Prefix& GetPrefixItem(size_t depth); - - public: - DicomPath(const DicomTag& finalTag) : - finalTag_(finalTag) - { - } - - DicomPath(const DicomTag& sequence, - size_t index, - const DicomTag& tag); - - DicomPath(const DicomTag& sequence1, - size_t index1, - const DicomTag& sequence2, - size_t index2, - const DicomTag& tag); - - DicomPath(const DicomTag& sequence1, - size_t index1, - const DicomTag& sequence2, - size_t index2, - const DicomTag& sequence3, - size_t index3, - const DicomTag& tag); - - void AddToPrefix(const DicomTag& tag, - size_t position) - { - prefix_.push_back(std::make_pair(tag, position)); - } - - size_t GetPrefixLength() const - { - return prefix_.size(); - } - - DicomTag GetPrefixTag(size_t depth) const - { - return GetPrefixItem(depth).first; - } - - size_t GetPrefixIndex(size_t depth) const - { - return GetPrefixItem(depth).second; - } - - void SetPrefixIndex(size_t depth, - size_t value) - { - GetPrefixItem(depth).second = value; - } - - const DicomTag& GetFinalTag() const - { - return finalTag_; - } - - void SetFinalTag(const DicomTag& tag) - { - finalTag_ = tag; - } - - std::string Format() const; - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/DicomTag.cpp --- a/OrthancServer/Plugins/Samples/Common/DicomTag.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "DicomTag.h" - -#include "OrthancPluginException.h" - -namespace OrthancPlugins -{ - const char* DicomTag::GetName() const - { - if (*this == DICOM_TAG_BITS_STORED) - { - return "BitsStored"; - } - else if (*this == DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX) - { - return "ColumnPositionInTotalImagePixelMatrix"; - } - else if (*this == DICOM_TAG_COLUMNS) - { - return "Columns"; - } - else if (*this == DICOM_TAG_MODALITY) - { - return "Modality"; - } - else if (*this == DICOM_TAG_NUMBER_OF_FRAMES) - { - return "NumberOfFrames"; - } - else if (*this == DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE) - { - return "PerFrameFunctionalGroupsSequence"; - } - else if (*this == DICOM_TAG_PHOTOMETRIC_INTERPRETATION) - { - return "PhotometricInterpretation"; - } - else if (*this == DICOM_TAG_PIXEL_REPRESENTATION) - { - return "PixelRepresentation"; - } - else if (*this == DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE) - { - return "PlanePositionSlideSequence"; - } - else if (*this == DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX) - { - return "RowPositionInTotalImagePixelMatrix"; - } - else if (*this == DICOM_TAG_ROWS) - { - return "Rows"; - } - else if (*this == DICOM_TAG_SOP_CLASS_UID) - { - return "SOPClassUID"; - } - else if (*this == DICOM_TAG_SAMPLES_PER_PIXEL) - { - return "SamplesPerPixel"; - } - else if (*this == DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS) - { - return "TotalPixelMatrixColumns"; - } - else if (*this == DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS) - { - return "TotalPixelMatrixRows"; - } - else if (*this == DICOM_TAG_TRANSFER_SYNTAX_UID) - { - return "TransferSyntaxUID"; - } - else - { - ORTHANC_PLUGINS_THROW_EXCEPTION(NotImplemented); - } - } - - - std::string DicomTag::FormatHexadecimal() const - { - char buf[16]; - sprintf(buf, "(%04x,%04x)", group_, element_); - return buf; - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/DicomTag.h --- a/OrthancServer/Plugins/Samples/Common/DicomTag.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include -#include - -namespace OrthancPlugins -{ - class DicomTag - { - private: - uint16_t group_; - uint16_t element_; - - DicomTag(); // Forbidden - - public: - DicomTag(uint16_t group, - uint16_t element) : - group_(group), - element_(element) - { - } - - uint16_t GetGroup() const - { - return group_; - } - - uint16_t GetElement() const - { - return element_; - } - - const char* GetName() const; - - bool operator== (const DicomTag& other) const - { - return group_ == other.group_ && element_ == other.element_; - } - - bool operator!= (const DicomTag& other) const - { - return !(*this == other); - } - - std::string FormatHexadecimal() const; - }; - - - static const DicomTag DICOM_TAG_BITS_STORED(0x0028, 0x0101); - static const DicomTag DICOM_TAG_COLUMNS(0x0028, 0x0011); - static const DicomTag DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021e); - static const DicomTag DICOM_TAG_IMAGE_ORIENTATION_PATIENT(0x0020, 0x0037); - static const DicomTag DICOM_TAG_IMAGE_POSITION_PATIENT(0x0020, 0x0032); - static const DicomTag DICOM_TAG_MODALITY(0x0008, 0x0060); - static const DicomTag DICOM_TAG_NUMBER_OF_FRAMES(0x0028, 0x0008); - static const DicomTag DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE(0x5200, 0x9230); - static const DicomTag DICOM_TAG_PHOTOMETRIC_INTERPRETATION(0x0028, 0x0004); - static const DicomTag DICOM_TAG_PIXEL_REPRESENTATION(0x0028, 0x0103); - static const DicomTag DICOM_TAG_PIXEL_SPACING(0x0028, 0x0030); - static const DicomTag DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE(0x0048, 0x021a); - static const DicomTag DICOM_TAG_RESCALE_INTERCEPT(0x0028, 0x1052); - static const DicomTag DICOM_TAG_RESCALE_SLOPE(0x0028, 0x1053); - static const DicomTag DICOM_TAG_ROWS(0x0028, 0x0010); - static const DicomTag DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021f); - static const DicomTag DICOM_TAG_SAMPLES_PER_PIXEL(0x0028, 0x0002); - static const DicomTag DICOM_TAG_SERIES_INSTANCE_UID(0x0020, 0x000e); - static const DicomTag DICOM_TAG_SLICE_THICKNESS(0x0018, 0x0050); - static const DicomTag DICOM_TAG_SOP_CLASS_UID(0x0008, 0x0016); - static const DicomTag DICOM_TAG_SOP_INSTANCE_UID(0x0008, 0x0018); - static const DicomTag DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS(0x0048, 0x0006); - static const DicomTag DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS(0x0048, 0x0007); - static const DicomTag DICOM_TAG_TRANSFER_SYNTAX_UID(0x0002, 0x0010); - static const DicomTag DICOM_TAG_WINDOW_CENTER(0x0028, 0x1050); - static const DicomTag DICOM_TAG_WINDOW_WIDTH(0x0028, 0x1051); -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/FullOrthancDataset.cpp --- a/OrthancServer/Plugins/Samples/Common/FullOrthancDataset.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,215 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "FullOrthancDataset.h" - -#include "OrthancPluginException.h" - -#include -#include - -namespace OrthancPlugins -{ - static const Json::Value* AccessTag(const Json::Value& dataset, - const DicomTag& tag) - { - if (dataset.type() != Json::objectValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - - char name[16]; - sprintf(name, "%04x,%04x", tag.GetGroup(), tag.GetElement()); - - if (!dataset.isMember(name)) - { - return NULL; - } - - const Json::Value& value = dataset[name]; - if (value.type() != Json::objectValue || - !value.isMember("Name") || - !value.isMember("Type") || - !value.isMember("Value") || - value["Name"].type() != Json::stringValue || - value["Type"].type() != Json::stringValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - - return &value; - } - - - static const Json::Value& GetSequenceContent(const Json::Value& sequence) - { - assert(sequence.type() == Json::objectValue); - assert(sequence.isMember("Type")); - assert(sequence.isMember("Value")); - - const Json::Value& value = sequence["Value"]; - - if (sequence["Type"].asString() != "Sequence" || - value.type() != Json::arrayValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - else - { - return value; - } - } - - - static bool GetStringInternal(std::string& result, - const Json::Value& tag) - { - assert(tag.type() == Json::objectValue); - assert(tag.isMember("Type")); - assert(tag.isMember("Value")); - - const Json::Value& value = tag["Value"]; - - if (tag["Type"].asString() != "String" || - value.type() != Json::stringValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - else - { - result = value.asString(); - return true; - } - } - - - const Json::Value* FullOrthancDataset::LookupPath(const DicomPath& path) const - { - const Json::Value* content = &root_; - - for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++) - { - const Json::Value* sequence = AccessTag(*content, path.GetPrefixTag(depth)); - if (sequence == NULL) - { - return NULL; - } - - const Json::Value& nextContent = GetSequenceContent(*sequence); - - size_t index = path.GetPrefixIndex(depth); - if (index >= nextContent.size()) - { - return NULL; - } - else - { - content = &nextContent[static_cast(index)]; - } - } - - return AccessTag(*content, path.GetFinalTag()); - } - - - void FullOrthancDataset::CheckRoot() const - { - if (root_.type() != Json::objectValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - } - - - FullOrthancDataset::FullOrthancDataset(IOrthancConnection& orthanc, - const std::string& uri) - { - IOrthancConnection::RestApiGet(root_, orthanc, uri); - CheckRoot(); - } - - - FullOrthancDataset::FullOrthancDataset(const std::string& content) - { - IOrthancConnection::ParseJson(root_, content); - CheckRoot(); - } - - - FullOrthancDataset::FullOrthancDataset(const void* content, - size_t size) - { - IOrthancConnection::ParseJson(root_, content, size); - CheckRoot(); - } - - - FullOrthancDataset::FullOrthancDataset(const Json::Value& root) : - root_(root) - { - CheckRoot(); - } - - - bool FullOrthancDataset::GetStringValue(std::string& result, - const DicomPath& path) const - { - const Json::Value* value = LookupPath(path); - - if (value == NULL) - { - return false; - } - else - { - return GetStringInternal(result, *value); - } - } - - - bool FullOrthancDataset::GetSequenceSize(size_t& size, - const DicomPath& path) const - { - const Json::Value* sequence = LookupPath(path); - - if (sequence == NULL) - { - return false; - } - else - { - size = GetSequenceContent(*sequence).size(); - return true; - } - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/FullOrthancDataset.h --- a/OrthancServer/Plugins/Samples/Common/FullOrthancDataset.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "IOrthancConnection.h" -#include "IDicomDataset.h" - -#include - -namespace OrthancPlugins -{ - class FullOrthancDataset : public IDicomDataset - { - private: - Json::Value root_; - - const Json::Value* LookupPath(const DicomPath& path) const; - - void CheckRoot() const; - - public: - FullOrthancDataset(IOrthancConnection& orthanc, - const std::string& uri); - - FullOrthancDataset(const std::string& content); - - FullOrthancDataset(const void* content, - size_t size); - - FullOrthancDataset(const Json::Value& root); - - virtual bool GetStringValue(std::string& result, - const DicomPath& path) const; - - virtual bool GetSequenceSize(size_t& size, - const DicomPath& path) const; - - FullOrthancDataset* Clone() const - { - return new FullOrthancDataset(this->root_); - } - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/IDicomDataset.h --- a/OrthancServer/Plugins/Samples/Common/IDicomDataset.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "DicomPath.h" - -#include -#include - -namespace OrthancPlugins -{ - class IDicomDataset : public boost::noncopyable - { - public: - virtual ~IDicomDataset() - { - } - - virtual bool GetStringValue(std::string& result, - const DicomPath& path) const = 0; - - virtual bool GetSequenceSize(size_t& size, - const DicomPath& path) const = 0; - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/IOrthancConnection.cpp --- a/OrthancServer/Plugins/Samples/Common/IOrthancConnection.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "IOrthancConnection.h" - -#include "OrthancPluginException.h" - -#include - -namespace OrthancPlugins -{ - void IOrthancConnection::ParseJson(Json::Value& result, - const std::string& content) - { - Json::Reader reader; - - if (!reader.parse(content, result)) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - } - - - void IOrthancConnection::ParseJson(Json::Value& result, - const void* content, - size_t size) - { - Json::Reader reader; - - if (!reader.parse(reinterpret_cast(content), - reinterpret_cast(content) + size, result)) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - } - - - void IOrthancConnection::RestApiGet(Json::Value& result, - IOrthancConnection& orthanc, - const std::string& uri) - { - std::string content; - orthanc.RestApiGet(content, uri); - ParseJson(result, content); - } - - - void IOrthancConnection::RestApiPost(Json::Value& result, - IOrthancConnection& orthanc, - const std::string& uri, - const std::string& body) - { - std::string content; - orthanc.RestApiPost(content, uri, body); - ParseJson(result, content); - } - - - void IOrthancConnection::RestApiPut(Json::Value& result, - IOrthancConnection& orthanc, - const std::string& uri, - const std::string& body) - { - std::string content; - orthanc.RestApiPut(content, uri, body); - ParseJson(result, content); - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/IOrthancConnection.h --- a/OrthancServer/Plugins/Samples/Common/IOrthancConnection.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "DicomPath.h" - -#include -#include -#include - -namespace OrthancPlugins -{ - class IOrthancConnection : public boost::noncopyable - { - public: - virtual ~IOrthancConnection() - { - } - - virtual void RestApiGet(std::string& result, - const std::string& uri) = 0; - - virtual void RestApiPost(std::string& result, - const std::string& uri, - const std::string& body) = 0; - - virtual void RestApiPut(std::string& result, - const std::string& uri, - const std::string& body) = 0; - - virtual void RestApiDelete(const std::string& uri) = 0; - - static void ParseJson(Json::Value& result, - const std::string& content); - - static void ParseJson(Json::Value& result, - const void* content, - size_t size); - - static void RestApiGet(Json::Value& result, - IOrthancConnection& orthanc, - const std::string& uri); - - static void RestApiPost(Json::Value& result, - IOrthancConnection& orthanc, - const std::string& uri, - const std::string& body); - - static void RestApiPut(Json::Value& result, - IOrthancConnection& orthanc, - const std::string& uri, - const std::string& body); - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/OrthancHttpConnection.cpp --- a/OrthancServer/Plugins/Samples/Common/OrthancHttpConnection.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "OrthancHttpConnection.h" - -namespace OrthancPlugins -{ - void OrthancHttpConnection::Setup() - { - url_ = client_.GetUrl(); - - // Don't follow 3xx HTTP (avoid redirections to "unsupported.png" in Orthanc) - client_.SetRedirectionFollowed(false); - } - - - OrthancHttpConnection::OrthancHttpConnection() : - client_(Orthanc::WebServiceParameters(), "") - { - Setup(); - } - - - OrthancHttpConnection::OrthancHttpConnection(const Orthanc::WebServiceParameters& parameters) : - client_(parameters, "") - { - Setup(); - } - - - void OrthancHttpConnection::RestApiGet(std::string& result, - const std::string& uri) - { - boost::mutex::scoped_lock lock(mutex_); - - client_.SetMethod(Orthanc::HttpMethod_Get); - client_.SetUrl(url_ + uri); - client_.ApplyAndThrowException(result); - } - - - void OrthancHttpConnection::RestApiPost(std::string& result, - const std::string& uri, - const std::string& body) - { - boost::mutex::scoped_lock lock(mutex_); - - client_.SetMethod(Orthanc::HttpMethod_Post); - client_.SetUrl(url_ + uri); - client_.SetBody(body); - client_.ApplyAndThrowException(result); - } - - - void OrthancHttpConnection::RestApiPut(std::string& result, - const std::string& uri, - const std::string& body) - { - boost::mutex::scoped_lock lock(mutex_); - - client_.SetMethod(Orthanc::HttpMethod_Put); - client_.SetUrl(url_ + uri); - client_.SetBody(body); - client_.ApplyAndThrowException(result); - } - - - void OrthancHttpConnection::RestApiDelete(const std::string& uri) - { - boost::mutex::scoped_lock lock(mutex_); - - std::string result; - - client_.SetMethod(Orthanc::HttpMethod_Delete); - client_.SetUrl(url_ + uri); - client_.ApplyAndThrowException(result); - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/OrthancHttpConnection.h --- a/OrthancServer/Plugins/Samples/Common/OrthancHttpConnection.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "IOrthancConnection.h" - -#if HAS_ORTHANC_EXCEPTION != 1 -# error The macro HAS_ORTHANC_EXCEPTION must be set to 1 if using this header -#endif - -#include "../../../Core/HttpClient.h" - -#include - -namespace OrthancPlugins -{ - // This class is thread-safe - class OrthancHttpConnection : public IOrthancConnection - { - private: - boost::mutex mutex_; - Orthanc::HttpClient client_; - std::string url_; - - void Setup(); - - public: - OrthancHttpConnection(); - - OrthancHttpConnection(const Orthanc::WebServiceParameters& parameters); - - virtual void RestApiGet(std::string& result, - const std::string& uri); - - virtual void RestApiPost(std::string& result, - const std::string& uri, - const std::string& body); - - virtual void RestApiPut(std::string& result, - const std::string& uri, - const std::string& body); - - virtual void RestApiDelete(const std::string& uri); - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/OrthancPluginConnection.cpp --- a/OrthancServer/Plugins/Samples/Common/OrthancPluginConnection.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "OrthancPluginConnection.h" - -#include "OrthancPluginCppWrapper.h" - -namespace OrthancPlugins -{ - void OrthancPluginConnection::RestApiGet(std::string& result, - const std::string& uri) - { - OrthancPlugins::MemoryBuffer buffer; - - if (buffer.RestApiGet(uri, false)) - { - buffer.ToString(result); - } - else - { - ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); - } - } - - - void OrthancPluginConnection::RestApiPost(std::string& result, - const std::string& uri, - const std::string& body) - { - OrthancPlugins::MemoryBuffer buffer; - - if (buffer.RestApiPost(uri, body.c_str(), body.size(), false)) - { - buffer.ToString(result); - } - else - { - ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); - } - } - - - void OrthancPluginConnection::RestApiPut(std::string& result, - const std::string& uri, - const std::string& body) - { - OrthancPlugins::MemoryBuffer buffer; - - if (buffer.RestApiPut(uri, body.c_str(), body.size(), false)) - { - buffer.ToString(result); - } - else - { - ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); - } - } - - - void OrthancPluginConnection::RestApiDelete(const std::string& uri) - { - OrthancPlugins::MemoryBuffer buffer; - - if (!::OrthancPlugins::RestApiDelete(uri, false)) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); - } - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/OrthancPluginConnection.h --- a/OrthancServer/Plugins/Samples/Common/OrthancPluginConnection.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "IOrthancConnection.h" - -#include - -namespace OrthancPlugins -{ - // This class is thread-safe - class OrthancPluginConnection : public IOrthancConnection - { - public: - virtual void RestApiGet(std::string& result, - const std::string& uri); - - virtual void RestApiPost(std::string& result, - const std::string& uri, - const std::string& body); - - virtual void RestApiPut(std::string& result, - const std::string& uri, - const std::string& body); - - virtual void RestApiDelete(const std::string& uri); - }; -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/SimplifiedOrthancDataset.cpp --- a/OrthancServer/Plugins/Samples/Common/SimplifiedOrthancDataset.cpp Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#include "SimplifiedOrthancDataset.h" - -#include "OrthancPluginException.h" - -namespace OrthancPlugins -{ - const Json::Value* SimplifiedOrthancDataset::LookupPath(const DicomPath& path) const - { - const Json::Value* content = &root_; - - for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++) - { - const char* name = path.GetPrefixTag(depth).GetName(); - if (content->type() != Json::objectValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - - if (!content->isMember(name)) - { - return NULL; - } - - const Json::Value& sequence = (*content) [name]; - if (sequence.type() != Json::arrayValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - - size_t index = path.GetPrefixIndex(depth); - if (index >= sequence.size()) - { - return NULL; - } - else - { - content = &sequence[static_cast(index)]; - } - } - - const char* name = path.GetFinalTag().GetName(); - - if (content->type() != Json::objectValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - if (!content->isMember(name)) - { - return NULL; - } - else - { - return &((*content) [name]); - } - } - - - void SimplifiedOrthancDataset::CheckRoot() const - { - if (root_.type() != Json::objectValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - } - - - SimplifiedOrthancDataset::SimplifiedOrthancDataset(IOrthancConnection& orthanc, - const std::string& uri) - { - IOrthancConnection::RestApiGet(root_, orthanc, uri); - CheckRoot(); - } - - - SimplifiedOrthancDataset::SimplifiedOrthancDataset(const std::string& content) - { - IOrthancConnection::ParseJson(root_, content); - CheckRoot(); - } - - - bool SimplifiedOrthancDataset::GetStringValue(std::string& result, - const DicomPath& path) const - { - const Json::Value* value = LookupPath(path); - - if (value == NULL) - { - return false; - } - else if (value->type() != Json::stringValue) - { - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - else - { - result = value->asString(); - return true; - } - } - - - bool SimplifiedOrthancDataset::GetSequenceSize(size_t& size, - const DicomPath& path) const - { - const Json::Value* sequence = LookupPath(path); - - if (sequence == NULL) - { - // Inexistent path - return false; - } - else if (sequence->type() != Json::arrayValue) - { - // Not a sequence - ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); - } - else - { - size = sequence->size(); - return true; - } - } -} diff -r 99e2054d1e8d -r 64e92ffbba0f OrthancServer/Plugins/Samples/Common/SimplifiedOrthancDataset.h --- a/OrthancServer/Plugins/Samples/Common/SimplifiedOrthancDataset.h Wed Jul 01 11:15:29 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2020 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "IOrthancConnection.h" -#include "IDicomDataset.h" - -namespace OrthancPlugins -{ - class SimplifiedOrthancDataset : public IDicomDataset - { - private: - Json::Value root_; - - const Json::Value* LookupPath(const DicomPath& path) const; - - void CheckRoot() const; - - public: - SimplifiedOrthancDataset(IOrthancConnection& orthanc, - const std::string& uri); - - SimplifiedOrthancDataset(const std::string& content); - - virtual bool GetStringValue(std::string& result, - const DicomPath& path) const; - - virtual bool GetSequenceSize(size_t& size, - const DicomPath& path) const; - }; -}