comparison OrthancServer/DicomProtocol/RemoteModalityParameters.cpp @ 807:566a2fb3c1fb

update/delete modalities
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 May 2014 15:54:23 +0200
parents 557575fd93e9
children 8a36c947490c
comparison
equal deleted inserted replaced
806:557575fd93e9 807:566a2fb3c1fb
32 32
33 #include "RemoteModalityParameters.h" 33 #include "RemoteModalityParameters.h"
34 34
35 #include "../../Core/OrthancException.h" 35 #include "../../Core/OrthancException.h"
36 36
37 #include <boost/lexical_cast.hpp>
38 #include <stdexcept>
39
37 namespace Orthanc 40 namespace Orthanc
38 { 41 {
39 RemoteModalityParameters::RemoteModalityParameters() 42 RemoteModalityParameters::RemoteModalityParameters()
40 { 43 {
41 name_ = ""; 44 name_ = "";
52 throw OrthancException(ErrorCode_ParameterOutOfRange); 55 throw OrthancException(ErrorCode_ParameterOutOfRange);
53 } 56 }
54 57
55 port_ = port; 58 port_ = port;
56 } 59 }
60
61 void RemoteModalityParameters::FromJson(const Json::Value& modality)
62 {
63 if (!modality.isArray() ||
64 (modality.size() != 3 && modality.size() != 4))
65 {
66 throw OrthancException(ErrorCode_BadFileFormat);
67 }
68
69 SetApplicationEntityTitle(modality.get(0u, "").asString());
70 SetHost(modality.get(1u, "").asString());
71
72 const Json::Value& portValue = modality.get(2u, "");
73 try
74 {
75 SetPort(portValue.asInt());
76 }
77 catch (std::runtime_error /* error inside JsonCpp */)
78 {
79 try
80 {
81 SetPort(boost::lexical_cast<int>(portValue.asString()));
82 }
83 catch (boost::bad_lexical_cast)
84 {
85 throw OrthancException(ErrorCode_BadFileFormat);
86 }
87 }
88
89 if (modality.size() == 4)
90 {
91 SetManufacturer(modality.get(3u, "").asString());
92 }
93 else
94 {
95 SetManufacturer(ModalityManufacturer_Generic);
96 }
97 }
98
99 void RemoteModalityParameters::ToJson(Json::Value& value) const
100 {
101 value = Json::arrayValue;
102 value.append(GetApplicationEntityTitle());
103 value.append(GetHost());
104 value.append(GetPort());
105 value.append(EnumerationToString(GetManufacturer()));
106 }
57 } 107 }