comparison Plugins/Samples/Basic/Plugin.c @ 1211:88511c737760

integration db-changes->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Nov 2014 13:57:11 +0100
parents 1e1390665639
children f1c01451a8ee
comparison
equal deleted inserted replaced
1208:6502517fd4af 1211:88511c737760
213 const char* instanceId) 213 const char* instanceId)
214 { 214 {
215 char buffer[256]; 215 char buffer[256];
216 FILE* fp; 216 FILE* fp;
217 char* json; 217 char* json;
218 static int first = 1;
218 219
219 sprintf(buffer, "Just received a DICOM instance of size %d and ID %s from AET %s", 220 sprintf(buffer, "Just received a DICOM instance of size %d and ID %s from AET %s",
220 (int) OrthancPluginGetInstanceSize(context, instance), instanceId, 221 (int) OrthancPluginGetInstanceSize(context, instance), instanceId,
221 OrthancPluginGetInstanceRemoteAet(context, instance)); 222 OrthancPluginGetInstanceRemoteAet(context, instance));
222 223
226 fwrite(OrthancPluginGetInstanceData(context, instance), 227 fwrite(OrthancPluginGetInstanceData(context, instance),
227 OrthancPluginGetInstanceSize(context, instance), 1, fp); 228 OrthancPluginGetInstanceSize(context, instance), 1, fp);
228 fclose(fp); 229 fclose(fp);
229 230
230 json = OrthancPluginGetInstanceSimplifiedJson(context, instance); 231 json = OrthancPluginGetInstanceSimplifiedJson(context, instance);
231 printf("[%s]\n", json); 232 if (first)
233 {
234 /* Only print the first DICOM instance */
235 printf("[%s]\n", json);
236 first = 0;
237 }
232 OrthancPluginFreeString(context, json); 238 OrthancPluginFreeString(context, json);
233 239
234 if (OrthancPluginHasInstanceMetadata(context, instance, "ReceptionDate")) 240 if (OrthancPluginHasInstanceMetadata(context, instance, "ReceptionDate"))
235 { 241 {
236 printf("Received on [%s]\n", OrthancPluginGetInstanceMetadata(context, instance, "ReceptionDate")); 242 printf("Received on [%s]\n", OrthancPluginGetInstanceMetadata(context, instance, "ReceptionDate"));
241 } 247 }
242 248
243 return 0; 249 return 0;
244 } 250 }
245 251
252
253 ORTHANC_PLUGINS_API int32_t OnChangeCallback(OrthancPluginChangeType changeType,
254 OrthancPluginResourceType resourceType,
255 const char* resourceId)
256 {
257 char info[1024];
258 OrthancPluginMemoryBuffer tmp;
259
260 sprintf(info, "Change %d on resource %s of type %d", changeType, resourceId, resourceType);
261 OrthancPluginLogWarning(context, info);
262
263 if (changeType == OrthancPluginChangeType_NewInstance)
264 {
265 sprintf(info, "/instances/%s/metadata/AnonymizedFrom", resourceId);
266 if (OrthancPluginRestApiGet(context, &tmp, info) == 0)
267 {
268 sprintf(info, " Instance %s comes from the anonymization of instance", resourceId);
269 strncat(info, (const char*) tmp.data, tmp.size);
270 OrthancPluginLogWarning(context, info);
271 OrthancPluginFreeMemoryBuffer(context, &tmp);
272 }
273 }
274
275 return 0;
276 }
246 277
247 278
248 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) 279 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
249 { 280 {
250 OrthancPluginMemoryBuffer tmp; 281 OrthancPluginMemoryBuffer tmp;
290 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3); 321 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3);
291 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4); 322 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4);
292 OrthancPluginRegisterRestCallback(context, "/plugin/create", CallbackCreateDicom); 323 OrthancPluginRegisterRestCallback(context, "/plugin/create", CallbackCreateDicom);
293 324
294 OrthancPluginRegisterOnStoredInstanceCallback(context, OnStoredCallback); 325 OrthancPluginRegisterOnStoredInstanceCallback(context, OnStoredCallback);
326
327 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
295 328
296 /* Make REST requests to the built-in Orthanc API */ 329 /* Make REST requests to the built-in Orthanc API */
297 OrthancPluginRestApiGet(context, &tmp, "/changes"); 330 OrthancPluginRestApiGet(context, &tmp, "/changes");
298 OrthancPluginFreeMemoryBuffer(context, &tmp); 331 OrthancPluginFreeMemoryBuffer(context, &tmp);
299 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1"); 332 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1");