comparison OrthancServer/ServerContext.cpp @ 998:4136fab6a639 lua-scripting

callback on stored instance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Jul 2014 18:30:23 +0200
parents 1b1d51e9f1a2
children f3929718ea7e
comparison
equal deleted inserted replaced
997:1b1d51e9f1a2 998:4136fab6a639
91 { 91 {
92 storage_.Remove(fileUuid); 92 storage_.Remove(fileUuid);
93 } 93 }
94 94
95 95
96 bool ServerContext::ApplyReceivedInstanceFilter(const Json::Value& dicomJson, 96 bool ServerContext::ApplyReceivedInstanceFilter(const Json::Value& simplified,
97 const std::string& remoteAet) 97 const std::string& remoteAet)
98 { 98 {
99 LuaContextLocker locker(*this); 99 LuaContextLocker locker(*this);
100 100
101 if (locker.GetLua().IsExistingFunction(RECEIVED_INSTANCE_FILTER)) 101 if (locker.GetLua().IsExistingFunction(RECEIVED_INSTANCE_FILTER))
102 { 102 {
103 Json::Value simplified;
104 SimplifyTags(simplified, dicomJson);
105
106 LuaFunctionCall call(locker.GetLua(), RECEIVED_INSTANCE_FILTER); 103 LuaFunctionCall call(locker.GetLua(), RECEIVED_INSTANCE_FILTER);
107 call.PushJson(simplified); 104 call.PushJson(simplified);
108 call.PushString(remoteAet); 105 call.PushString(remoteAet);
109 106
110 if (!call.ExecutePredicate()) 107 if (!call.ExecutePredicate())
112 return false; 109 return false;
113 } 110 }
114 } 111 }
115 112
116 return true; 113 return true;
114 }
115
116
117 void ServerContext::ApplyOnStoredInstance(const Json::Value& simplified,
118 const std::string& instanceId)
119 {
120 LuaContextLocker locker(*this);
121
122 if (locker.GetLua().IsExistingFunction(ON_STORED_INSTANCE))
123 {
124 LuaFunctionCall call(locker.GetLua(), ON_STORED_INSTANCE);
125 call.PushJson(simplified);
126 call.PushString(instanceId);
127
128 Json::Value result;
129 call.ExecuteToJson(result);
130
131 printf("TODO\n");
132 std::cout << result;
133 }
117 } 134 }
118 135
119 136
120 StoreStatus ServerContext::Store(const char* dicomInstance, 137 StoreStatus ServerContext::Store(const char* dicomInstance,
121 size_t dicomSize, 138 size_t dicomSize,
122 const DicomMap& dicomSummary, 139 const DicomMap& dicomSummary,
123 const Json::Value& dicomJson, 140 const Json::Value& dicomJson,
124 const std::string& remoteAet) 141 const std::string& remoteAet)
125 { 142 {
143 Json::Value simplified;
144 SimplifyTags(simplified, dicomJson);
145
126 // Test if the instance must be filtered out 146 // Test if the instance must be filtered out
127 if (!ApplyReceivedInstanceFilter(dicomJson, remoteAet)) 147 if (!ApplyReceivedInstanceFilter(simplified, remoteAet))
128 { 148 {
129 LOG(INFO) << "An incoming instance has been discarded by the filter"; 149 LOG(INFO) << "An incoming instance has been discarded by the filter";
130 return StoreStatus_FilteredOut; 150 return StoreStatus_FilteredOut;
131 } 151 }
132 152
169 break; 189 break;
170 190
171 default: 191 default:
172 // This should never happen 192 // This should never happen
173 break; 193 break;
194 }
195
196 if (status == StoreStatus_Success ||
197 status == StoreStatus_AlreadyStored)
198 {
199 DicomInstanceHasher hasher(dicomSummary);
200 ApplyOnStoredInstance(simplified, hasher.HashInstance());
174 } 201 }
175 202
176 return status; 203 return status;
177 } 204 }
178 205