Mercurial > hg > orthanc
changeset 807:566a2fb3c1fb
update/delete modalities
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 May 2014 15:54:23 +0200 |
parents | 557575fd93e9 |
children | 2d9a000aa3a6 |
files | NEWS OrthancServer/DicomProtocol/RemoteModalityParameters.cpp OrthancServer/DicomProtocol/RemoteModalityParameters.h OrthancServer/OrthancInitialization.cpp OrthancServer/OrthancInitialization.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp |
diffstat | 6 files changed, 127 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Wed May 07 15:22:28 2014 +0200 +++ b/NEWS Wed May 07 15:54:23 2014 +0200 @@ -4,6 +4,7 @@ * Dynamic negotiation of SOP classes for C-Store SCU * Creation of DICOM instances using the REST API * Embedding of images within DICOM instances +* Adding/removal/modification of remote modalities/peers through REST * Reuse of the previous SCU connection to avoid unecessary handshakes * Fix missing licensing terms about reuse of some code from DCMTK * Various code refactorings
--- a/OrthancServer/DicomProtocol/RemoteModalityParameters.cpp Wed May 07 15:22:28 2014 +0200 +++ b/OrthancServer/DicomProtocol/RemoteModalityParameters.cpp Wed May 07 15:54:23 2014 +0200 @@ -34,6 +34,9 @@ #include "../../Core/OrthancException.h" +#include <boost/lexical_cast.hpp> +#include <stdexcept> + namespace Orthanc { RemoteModalityParameters::RemoteModalityParameters() @@ -54,4 +57,51 @@ port_ = port; } + + void RemoteModalityParameters::FromJson(const Json::Value& modality) + { + if (!modality.isArray() || + (modality.size() != 3 && modality.size() != 4)) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + SetApplicationEntityTitle(modality.get(0u, "").asString()); + SetHost(modality.get(1u, "").asString()); + + const Json::Value& portValue = modality.get(2u, ""); + try + { + SetPort(portValue.asInt()); + } + catch (std::runtime_error /* error inside JsonCpp */) + { + try + { + SetPort(boost::lexical_cast<int>(portValue.asString())); + } + catch (boost::bad_lexical_cast) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + } + + if (modality.size() == 4) + { + SetManufacturer(modality.get(3u, "").asString()); + } + else + { + SetManufacturer(ModalityManufacturer_Generic); + } + } + + void RemoteModalityParameters::ToJson(Json::Value& value) const + { + value = Json::arrayValue; + value.append(GetApplicationEntityTitle()); + value.append(GetHost()); + value.append(GetPort()); + value.append(EnumerationToString(GetManufacturer())); + } }
--- a/OrthancServer/DicomProtocol/RemoteModalityParameters.h Wed May 07 15:22:28 2014 +0200 +++ b/OrthancServer/DicomProtocol/RemoteModalityParameters.h Wed May 07 15:54:23 2014 +0200 @@ -35,6 +35,7 @@ #include "../ServerEnumerations.h" #include <string> +#include <json/json.h> namespace Orthanc { @@ -103,5 +104,9 @@ { manufacturer_ = StringToModalityManufacturer(manufacturer); } + + void FromJson(const Json::Value& modality); + + void ToJson(Json::Value& value) const; }; }
--- a/OrthancServer/OrthancInitialization.cpp Wed May 07 15:22:28 2014 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Wed May 07 15:54:23 2014 +0200 @@ -255,42 +255,14 @@ const Json::Value& modalities = (*configuration_) ["DicomModalities"]; if (modalities.type() != Json::objectValue || - !modalities.isMember(name) || - (modalities[name].size() != 3 && modalities[name].size() != 4)) + !modalities.isMember(name)) { throw OrthancException(ErrorCode_BadFileFormat); } try { - modality.SetApplicationEntityTitle(modalities[name].get(0u, "").asString()); - modality.SetHost(modalities[name].get(1u, "").asString()); - - const Json::Value& portValue = modalities[name].get(2u, ""); - try - { - modality.SetPort(portValue.asInt()); - } - catch (std::runtime_error /* error inside JsonCpp */) - { - try - { - modality.SetPort(boost::lexical_cast<int>(portValue.asString())); - } - catch (boost::bad_lexical_cast) - { - throw OrthancException(ErrorCode_BadFileFormat); - } - } - - if (modalities[name].size() == 4) - { - modality.SetManufacturer(modalities[name].get(3u, "").asString()); - } - else - { - modality.SetManufacturer(ModalityManufacturer_Generic); - } + modality.FromJson(modalities[name]); } catch (OrthancException& e) { @@ -583,4 +555,46 @@ throw OrthancException("Unknown modality for AET: " + aet); } } + + + void UpdateModality(const RemoteModalityParameters& modality) + { + boost::mutex::scoped_lock lock(globalMutex_); + + if (!configuration_->isMember("DicomModalities")) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + Json::Value& modalities = (*configuration_) ["DicomModalities"]; + if (modalities.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + modalities.removeMember(modality.GetName().c_str()); + + Json::Value v; + modality.ToJson(v); + modalities[modality.GetName()] = v; + } + + + void RemoveModality(const std::string& symbolicName) + { + boost::mutex::scoped_lock lock(globalMutex_); + + if (!configuration_->isMember("DicomModalities")) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + Json::Value& modalities = (*configuration_) ["DicomModalities"]; + if (modalities.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + modalities.removeMember(symbolicName.c_str()); + } }
--- a/OrthancServer/OrthancInitialization.h Wed May 07 15:22:28 2014 +0200 +++ b/OrthancServer/OrthancInitialization.h Wed May 07 15:54:23 2014 +0200 @@ -141,4 +141,8 @@ RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name); RemoteModalityParameters GetModalityUsingAet(const std::string& aet); + + void UpdateModality(const RemoteModalityParameters& modality); + + void RemoveModality(const std::string& symbolicName); }
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Wed May 07 15:22:28 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Wed May 07 15:54:23 2014 +0200 @@ -464,10 +464,32 @@ } + static void UpdateModality(RestApi::PutCall& call) + { + Json::Value json; + Json::Reader reader; + if (reader.parse(call.GetPutBody(), json)) + { + RemoteModalityParameters modality; + modality.FromJson(json); + modality.SetName(call.GetUriComponent("id", "")); + UpdateModality(modality); + } + } + + + static void DeleteModality(RestApi::DeleteCall& call) + { + RemoveModality(call.GetUriComponent("id", "")); + } + + void OrthancRestApi::RegisterModalities() { Register("/modalities", ListModalities); Register("/modalities/{id}", ListModalityOperations); + Register("/modalities/{id}", UpdateModality); + Register("/modalities/{id}", DeleteModality); Register("/modalities/{id}/find-patient", DicomFindPatient); Register("/modalities/{id}/find-study", DicomFindStudy); Register("/modalities/{id}/find-series", DicomFindSeries); @@ -478,5 +500,6 @@ Register("/peers", ListPeers); Register("/peers/{id}", ListPeerOperations); Register("/peers/{id}/store", PeerStore); + } }