Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Plugins/Samples/Basic/Plugin.c Mon Nov 03 16:45:35 2014 +0100 +++ b/Plugins/Samples/Basic/Plugin.c Tue Nov 04 13:57:11 2014 +0100 @@ -215,6 +215,7 @@ char buffer[256]; FILE* fp; char* json; + static int first = 1; sprintf(buffer, "Just received a DICOM instance of size %d and ID %s from AET %s", (int) OrthancPluginGetInstanceSize(context, instance), instanceId, @@ -228,7 +229,12 @@ fclose(fp); json = OrthancPluginGetInstanceSimplifiedJson(context, instance); - printf("[%s]\n", json); + if (first) + { + /* Only print the first DICOM instance */ + printf("[%s]\n", json); + first = 0; + } OrthancPluginFreeString(context, json); if (OrthancPluginHasInstanceMetadata(context, instance, "ReceptionDate")) @@ -244,6 +250,31 @@ } +ORTHANC_PLUGINS_API int32_t OnChangeCallback(OrthancPluginChangeType changeType, + OrthancPluginResourceType resourceType, + const char* resourceId) +{ + char info[1024]; + OrthancPluginMemoryBuffer tmp; + + sprintf(info, "Change %d on resource %s of type %d", changeType, resourceId, resourceType); + OrthancPluginLogWarning(context, info); + + if (changeType == OrthancPluginChangeType_NewInstance) + { + sprintf(info, "/instances/%s/metadata/AnonymizedFrom", resourceId); + if (OrthancPluginRestApiGet(context, &tmp, info) == 0) + { + sprintf(info, " Instance %s comes from the anonymization of instance", resourceId); + strncat(info, (const char*) tmp.data, tmp.size); + OrthancPluginLogWarning(context, info); + OrthancPluginFreeMemoryBuffer(context, &tmp); + } + } + + return 0; +} + ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) { @@ -293,6 +324,8 @@ OrthancPluginRegisterOnStoredInstanceCallback(context, OnStoredCallback); + OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); + /* Make REST requests to the built-in Orthanc API */ OrthancPluginRestApiGet(context, &tmp, "/changes"); OrthancPluginFreeMemoryBuffer(context, &tmp);