Mercurial > hg > orthanc
comparison Plugins/Samples/Basic/Plugin.c @ 913:3e43de893d88 plugins
POST, DELETE, PUT from Orthanc plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 20 Jun 2014 15:42:14 +0200 |
parents | dcb2469f00f4 |
children | 5a5a4890ffca |
comparison
equal
deleted
inserted
replaced
912:dcb2469f00f4 | 913:3e43de893d88 |
---|---|
127 } | 127 } |
128 | 128 |
129 | 129 |
130 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | 130 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) |
131 { | 131 { |
132 const char* pathLocator = "\"Path\" : \""; | |
132 OrthancPluginMemoryBuffer tmp; | 133 OrthancPluginMemoryBuffer tmp; |
133 char info[1024]; | 134 char info[1024]; |
135 char *id, *eos; | |
134 | 136 |
135 context = c; | 137 context = c; |
136 OrthancPluginLogWarning(context, "Sample plugin is initializing"); | 138 OrthancPluginLogWarning(context, "Sample plugin is initializing"); |
137 | 139 |
138 sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion); | 140 sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion); |
142 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2); | 144 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2); |
143 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3); | 145 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3); |
144 | 146 |
145 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4); | 147 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4); |
146 | 148 |
147 | 149 /* Make REST requests to the built-in Orthanc API */ |
148 printf(">> %d\n", OrthancPluginRestApiGet(context, &tmp, "/instances")); | 150 OrthancPluginRestApiGet(context, &tmp, "/changes"); |
149 printf(">> [%s]\n", (const char*) tmp.data); | |
150 OrthancPluginFreeMemoryBuffer(context, &tmp); | 151 OrthancPluginFreeMemoryBuffer(context, &tmp); |
152 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1"); | |
153 OrthancPluginFreeMemoryBuffer(context, &tmp); | |
154 | |
155 /* Make POST request to create a new DICOM instance */ | |
156 sprintf(info, "{\"PatientName\":\"Test\"}"); | |
157 OrthancPluginRestApiPost(context, &tmp, "/tools/create-dicom", info, strlen(info)); | |
158 | |
159 /** | |
160 * Recover he ID of the created instance is constructed by a | |
161 * quick-and-dirty parsing of a JSON string. | |
162 **/ | |
163 id = strstr((char*) tmp.data, pathLocator) + strlen(pathLocator); | |
164 eos = strchr(id, '\"'); | |
165 eos[0] = '\0'; | |
166 | |
167 /* Delete the newly created DICOM instance. */ | |
168 OrthancPluginRestApiDelete(context, id); | |
169 OrthancPluginFreeMemoryBuffer(context, &tmp); | |
170 | |
171 /* Play with PUT by defining a new target modality. */ | |
172 sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]"); | |
173 OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info)); | |
151 | 174 |
152 return 0; | 175 return 0; |
153 } | 176 } |
154 | 177 |
155 | 178 |