ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) { context = c; /* Check the version of the Orthanc core */ if (OrthancPluginCheckVersion(c) == 0) { char info[256]; sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", c->orthancVersion, ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); OrthancPluginLogError(context, info); return -1; } /* Register the callbacks */ #if ORTHANC_PLUGIN_STANDALONE == 1 OrthancPluginLogInfo(context, "Serving static resources (standalone build)"); OrthancPluginRegisterRestCallback(context, ORTHANC_PLUGIN_WEB_ROOT "(.*)", ServeStaticResource); #else OrthancPluginLogInfo(context, "Serving resources from folder: " ORTHANC_PLUGIN_RESOURCES_ROOT); OrthancPluginRegisterRestCallback(context, ORTHANC_PLUGIN_WEB_ROOT "(.*)", ServeFolder); #endif OrthancPluginRegisterRestCallback(context, "/", RedirectRoot); return 0; }
OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, const OrthancPluginWorklistQuery* query, const char* remoteAet, const char* calledAet) { Json::Value json; if (!GetQueryDicom(json, query)) { return OrthancPluginErrorCode_InternalError; } { std::string msg = ("Received worklist query from remote modality " + std::string(remoteAet) + ":\n" + json.toStyledString()); OrthancPluginLogInfo(context_, msg.c_str()); } boost::filesystem::path source(folder_); boost::filesystem::directory_iterator end; try { for (boost::filesystem::directory_iterator it(source); it != end; ++it) { if (is_regular_file(it->status())) { std::string extension = boost::filesystem::extension(it->path()); ToLowerCase(extension); if (extension == ".wl") { OrthancPluginErrorCode error = MatchWorklist(answers, query, it->path().string()); if (error) { OrthancPluginLogError(context_, "Error while adding an answer to a worklist request"); return error; } } } } } catch (boost::filesystem::filesystem_error&) { std::string description = std::string("Inexistent folder while scanning for worklists: ") + source.string(); OrthancPluginLogError(context_, description.c_str()); return OrthancPluginErrorCode_DirectoryExpected; } // Uncomment the following line if too many answers are to be returned // OrthancPluginMarkWorklistAnswersIncomplete(context_, answers); return OrthancPluginErrorCode_Success; }
bool InstanceInformationAdapter::Create(std::string& content, const std::string& instanceId) { std::string message = "Creating spatial information for instance: " + instanceId; OrthancPluginLogInfo(context_, message.c_str()); std::string uri = "/instances/" + instanceId; Json::Value instance, tags; if (!GetJsonFromOrthanc(instance, context_, uri) || !GetJsonFromOrthanc(tags, context_, uri + "/tags?simplify") || instance.type() != Json::objectValue || tags.type() != Json::objectValue) { return false; } InstanceInformation info; if (tags.isMember(IMAGE_ORIENTATION_PATIENT) && tags.isMember(IMAGE_POSITION_PATIENT) && tags[IMAGE_ORIENTATION_PATIENT].type() == Json::stringValue && tags[IMAGE_POSITION_PATIENT].type() == Json::stringValue) { std::vector<float> cosines, position; if (TokenizeVector(cosines, tags[IMAGE_ORIENTATION_PATIENT].asString(), 6) && TokenizeVector(position, tags[IMAGE_POSITION_PATIENT].asString(), 3)) { std::vector<float> normal(3); normal[0] = cosines[1] * cosines[5] - cosines[2] * cosines[4]; normal[1] = cosines[2] * cosines[3] - cosines[0] * cosines[5]; normal[2] = cosines[0] * cosines[4] - cosines[1] * cosines[3]; info.SetPosition(normal, position); } } if (instance.isMember(INDEX_IN_SERIES) && instance[INDEX_IN_SERIES].type() == Json::intValue) { info.SetIndexInSeries(instance[INDEX_IN_SERIES].asInt()); } info.Serialize(content); return true; }
void OrthancContext::LogInfo(const std::string& s) { Check(); OrthancPluginLogInfo(context_, s.c_str()); }