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; }
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; }
static int32_t ServeFolder(OrthancPluginRestOutput* output, const char* url, const OrthancPluginHttpRequest* request) { if (request->method != OrthancPluginHttpMethod_Get) { OrthancPluginSendMethodNotAllowed(context, output, "GET"); return 0; } std::string path = ORTHANC_PLUGIN_RESOURCES_ROOT "/" + std::string(request->groups[0]); const char* mime = GetMimeType(path); std::string s; if (ReadFile(s, path)) { const char* resource = s.size() ? s.c_str() : NULL; OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); return 0; } else { std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); OrthancPluginLogError(context, s.c_str()); OrthancPluginSendHttpStatusCode(context, output, 404); return 0; } }
static int32_t ServeStaticResource(OrthancPluginRestOutput* output, const char* url, const OrthancPluginHttpRequest* request) { if (request->method != OrthancPluginHttpMethod_Get) { OrthancPluginSendMethodNotAllowed(context, output, "GET"); return 0; } std::string path = "/" + std::string(request->groups[0]); const char* mime = GetMimeType(path); try { std::string s; Orthanc::EmbeddedResources::GetDirectoryResource (s, Orthanc::EmbeddedResources::STATIC_RESOURCES, path.c_str()); const char* resource = s.size() ? s.c_str() : NULL; OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); return 0; } catch (std::runtime_error&) { std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); OrthancPluginLogError(context, s.c_str()); OrthancPluginSendHttpStatusCode(context, output, 404); return 0; } }
void OrthancContext::LogError(const std::string& s) { Check(); OrthancPluginLogError(context_, s.c_str()); }
ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) { context_ = c; OrthancPluginLogWarning(context_, "Sample worklist plugin is initializing"); OrthancPluginSetDescription(context_, "Serve DICOM modality worklists from a folder with Orthanc."); /* Check the version of the Orthanc core */ if (OrthancPluginCheckVersion(c) == 0) { char info[1024]; sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", context_->orthancVersion, ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); OrthancPluginLogError(context_, info); return -1; } Json::Value configuration; if (!ConvertToJson(configuration, OrthancPluginGetConfiguration(context_))) { OrthancPluginLogError(context_, "Cannot access the configuration of the worklist server"); return -1; } bool enabled = false; if (configuration.isMember("Worklists")) { const Json::Value& config = configuration["Worklists"]; if (!config.isMember("Enable") || config["Enable"].type() != Json::booleanValue) { OrthancPluginLogError(context_, "The configuration option \"Worklists.Enable\" must contain a Boolean"); return -1; } else { enabled = config["Enable"].asBool(); if (enabled) { if (!config.isMember("Database") || config["Database"].type() != Json::stringValue) { OrthancPluginLogError(context_, "The configuration option \"Worklists.Database\" must contain a path"); return -1; } folder_ = config["Database"].asString(); } else { OrthancPluginLogWarning(context_, "Worklists server is disabled by the configuration file"); } } } else { OrthancPluginLogWarning(context_, "Worklists server is disabled, no suitable configuration section was provided"); } if (enabled) { std::string message = "The database of worklists will be read from folder: " + folder_; OrthancPluginLogWarning(context_, message.c_str()); OrthancPluginRegisterWorklistCallback(context_, Callback); } return 0; }