Package be.uclouvain.orthanc
Class Functions
- java.lang.Object
-
- be.uclouvain.orthanc.Functions
-
public class Functions extends java.lang.Object
Wrapper around the global functions provided by the Orthanc SDK.
-
-
Constructor Summary
Constructors Constructor Description Functions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
autodetectMimeType(java.lang.String path)
Detect the MIME type of a file.static byte[]
bufferCompression(byte[] source, CompressionType compression, byte uncompress)
Compress or decompress a buffer.static int
checkVersion()
Check the compatibility of the plugin wrt.static int
checkVersionAdvanced(int expectedMajor, int expectedMinor, int expectedRevision)
Check that the version of the hosting Orthanc is above a given version.static byte[]
compressJpegImage(PixelFormat format, int width, int height, int pitch, byte[] buffer, byte quality)
Encode a JPEG image.static byte[]
compressPngImage(PixelFormat format, int width, int height, int pitch, byte[] buffer)
Encode a PNG image.static java.lang.String
computeMd5(byte[] buffer)
Compute an MD5 hash.static java.lang.String
computeSha1(byte[] buffer)
Compute a SHA-1 hash.static byte[]
createDicom(java.lang.String json, Image pixelData, CreateDicomFlags flags)
Create a DICOM instance from a JSON string and an image.static byte[]
createDicom2(java.lang.String json, Image pixelData, CreateDicomFlags flags, java.lang.String privateCreator)
Create a DICOM instance from a JSON string and an image, with a private creator.static java.lang.String
dicomBufferToJson(byte[] buffer, DicomToJsonFormat format, DicomToJsonFlags flags, int maxStringLength)
Format a DICOM memory buffer as a JSON string.static java.lang.String
dicomInstanceToJson(java.lang.String instanceId, DicomToJsonFormat format, DicomToJsonFlags flags, int maxStringLength)
Format a DICOM instance as a JSON string.static void
extendOrthancExplorer(java.lang.String javascript)
Extend the JavaScript code of Orthanc Explorer.static java.lang.String
generateRestApiAuthorizationToken()
Generate a token to grant full access to the REST API of Orthanc This function generates a token that can be set in the HTTP header "Authorization" so as to grant full access to the REST API of Orthanc using an external HTTP client.static java.lang.String
generateUuid()
Generate an UUID.static java.lang.String
getCommandLineArgument(int argument)
Get the value of a command-line argument.static int
getCommandLineArgumentsCount()
Get the number of command-line arguments.static java.lang.String
getConfiguration()
Return the content of the configuration file(s).static java.lang.String
getConfigurationPath()
Return the path to the configuration file(s).static byte[]
getDicomForInstance(java.lang.String instanceId)
Retrieve a DICOM instance using its Orthanc identifier.static java.lang.String
getErrorDescription(ErrorCode error)
Get the description of a given error code.static int
getExpectedDatabaseVersion()
Get the expected version of the database schema.static java.lang.String
getFontName(int fontIndex)
Return the name of a font.static int
getFontsCount()
Return the number of available fonts.static int
getFontSize(int fontIndex)
Return the size of a font.static java.lang.String
getGlobalProperty(int property, java.lang.String defaultValue)
Get the value of a global property.static java.lang.String
getOrthancDirectory()
Return the directory containing the Orthanc.static java.lang.String
getOrthancPath()
Return the path to the Orthanc executable.static java.lang.String
getTagName(short group, short element, java.lang.String privateCreator)
Returns the symbolic name of a DICOM tag.static void
httpDelete(java.lang.String url, java.lang.String username, java.lang.String password)
Issue a HTTP DELETE call.static byte[]
httpGet(java.lang.String url, java.lang.String username, java.lang.String password)
Issue a HTTP GET call.static byte[]
httpPost(java.lang.String url, byte[] body, java.lang.String username, java.lang.String password)
Issue a HTTP POST call.static byte[]
httpPut(java.lang.String url, byte[] body, java.lang.String username, java.lang.String password)
Issue a HTTP PUT call.static void
logError(java.lang.String message)
Log an error.static void
logInfo(java.lang.String message)
Log an information.static void
logWarning(java.lang.String message)
Log a warning.static java.lang.String
lookupInstance(java.lang.String sopInstanceUID)
Look for an instance.static java.lang.String
lookupPatient(java.lang.String patientID)
Look for a patient.static java.lang.String
lookupSeries(java.lang.String seriesUID)
Look for a series.static java.lang.String
lookupStudy(java.lang.String studyUID)
Look for a study.static java.lang.String
lookupStudyWithAccessionNumber(java.lang.String accessionNumber)
Look for a study, using the accession number.static byte[]
readFile(java.lang.String path)
Read a file.static void
registerDictionaryTag(short group, short element, ValueRepresentation vr, java.lang.String name, int minMultiplicity, int maxMultiplicity)
Register a new tag into the DICOM dictionary.static void
registerErrorCode(int code, short httpStatus, java.lang.String message)
Declare a custom error code for this plugin.static void
registerPrivateDictionaryTag(short group, short element, ValueRepresentation vr, java.lang.String name, int minMultiplicity, int maxMultiplicity, java.lang.String privateCreator)
Register a new private tag into the DICOM dictionary.static void
restApiDelete(java.lang.String uri)
Make a DELETE call to the built-in Orthanc REST API.static void
restApiDeleteAfterPlugins(java.lang.String uri)
Make a DELETE call to the REST API, as tainted by the plugins.static byte[]
restApiGet(java.lang.String uri)
Make a GET call to the built-in Orthanc REST API.static byte[]
restApiGetAfterPlugins(java.lang.String uri)
Make a GET call to the REST API, as tainted by the plugins.static byte[]
restApiPost(java.lang.String uri, byte[] body)
Make a POST call to the built-in Orthanc REST API.static byte[]
restApiPostAfterPlugins(java.lang.String uri, byte[] body)
Make a POST call to the REST API, as tainted by the plugins.static byte[]
restApiPut(java.lang.String uri, byte[] body)
Make a PUT call to the built-in Orthanc REST API.static byte[]
restApiPutAfterPlugins(java.lang.String uri, byte[] body)
Make a PUT call to the REST API, as tainted by the plugins.static void
setDescription(java.lang.String description)
Set a description for this plugin.static void
setGlobalProperty(int property, java.lang.String value)
Set the value of a global property.static void
setMetricsValue(java.lang.String name, float value, MetricsType type)
Set the value of a metrics.static void
setRootUri(java.lang.String uri)
Set the URI where the plugin provides its Web interface.static void
writeFile(java.lang.String path, byte[] data)
Write a file.
-
-
-
Method Detail
-
checkVersionAdvanced
public static int checkVersionAdvanced(int expectedMajor, int expectedMinor, int expectedRevision)
Check that the version of the hosting Orthanc is above a given version. This function checks whether the version of the Orthanc server running this plugin, is above the given version. Contrarily to OrthancPluginCheckVersion(), it is up to the developer of the plugin to make sure that all the Orthanc SDK services called by the plugin are actually implemented in the given version of Orthanc.- Parameters:
expectedMajor
- Expected major version.expectedMinor
- Expected minor version.expectedRevision
- Expected revision.- Returns:
- 1 if and only if the versions are compatible. If the result is 0, the initialization of the plugin should fail.
-
checkVersion
public static int checkVersion()
Check the compatibility of the plugin wrt. the version of its hosting Orthanc. This function checks whether the version of the Orthanc server running this plugin, is above the version of the current Orthanc SDK header. This guarantees that the plugin is compatible with the hosting Orthanc (i.e. it will not call unavailable services). The result of this function should always be checked in the OrthancPluginInitialize() entry point of the plugin.- Returns:
- 1 if and only if the versions are compatible. If the result is 0, the initialization of the plugin should fail.
-
logError
public static void logError(java.lang.String message)
Log an error. Log an error message using the Orthanc logging system.- Parameters:
message
- The message to be logged.
-
logWarning
public static void logWarning(java.lang.String message)
Log a warning. Log a warning message using the Orthanc logging system.- Parameters:
message
- The message to be logged.
-
logInfo
public static void logInfo(java.lang.String message)
Log an information. Log an information message using the Orthanc logging system.- Parameters:
message
- The message to be logged.
-
getDicomForInstance
public static byte[] getDicomForInstance(java.lang.String instanceId)
Retrieve a DICOM instance using its Orthanc identifier. Retrieve a DICOM instance using its Orthanc identifier. The DICOM file is stored into a newly allocated memory buffer.- Parameters:
instanceId
- The Orthanc identifier of the DICOM instance of interest.- Returns:
- The resulting memory buffer.
-
restApiGet
public static byte[] restApiGet(java.lang.String uri)
Make a GET call to the built-in Orthanc REST API. Make a GET call to the built-in Orthanc REST API. The result to the query is stored into a newly allocated memory buffer. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI in the built-in Orthanc API.- Returns:
- The resulting memory buffer.
-
restApiGetAfterPlugins
public static byte[] restApiGetAfterPlugins(java.lang.String uri)
Make a GET call to the REST API, as tainted by the plugins. Make a GET call to the Orthanc REST API, after all the plugins are applied. In other words, if some plugin overrides or adds the called URI to the built-in Orthanc REST API, this call will return the result provided by this plugin. The result to the query is stored into a newly allocated memory buffer. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI in the built-in Orthanc API.- Returns:
- The resulting memory buffer.
-
restApiPost
public static byte[] restApiPost(java.lang.String uri, byte[] body)
Make a POST call to the built-in Orthanc REST API. Make a POST call to the built-in Orthanc REST API. The result to the query is stored into a newly allocated memory buffer. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI in the built-in Orthanc API.body
- The body of the POST request.- Returns:
- The resulting memory buffer.
-
restApiPostAfterPlugins
public static byte[] restApiPostAfterPlugins(java.lang.String uri, byte[] body)
Make a POST call to the REST API, as tainted by the plugins. Make a POST call to the Orthanc REST API, after all the plugins are applied. In other words, if some plugin overrides or adds the called URI to the built-in Orthanc REST API, this call will return the result provided by this plugin. The result to the query is stored into a newly allocated memory buffer. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI in the built-in Orthanc API.body
- The body of the POST request.- Returns:
- The resulting memory buffer.
-
restApiDelete
public static void restApiDelete(java.lang.String uri)
Make a DELETE call to the built-in Orthanc REST API. Make a DELETE call to the built-in Orthanc REST API. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI to delete in the built-in Orthanc API.
-
restApiDeleteAfterPlugins
public static void restApiDeleteAfterPlugins(java.lang.String uri)
Make a DELETE call to the REST API, as tainted by the plugins. Make a DELETE call to the Orthanc REST API, after all the plugins are applied. In other words, if some plugin overrides or adds the called URI to the built-in Orthanc REST API, this call will return the result provided by this plugin. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI to delete in the built-in Orthanc API.
-
restApiPut
public static byte[] restApiPut(java.lang.String uri, byte[] body)
Make a PUT call to the built-in Orthanc REST API. Make a PUT call to the built-in Orthanc REST API. The result to the query is stored into a newly allocated memory buffer. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI in the built-in Orthanc API.body
- The body of the PUT request.- Returns:
- The resulting memory buffer.
-
restApiPutAfterPlugins
public static byte[] restApiPutAfterPlugins(java.lang.String uri, byte[] body)
Make a PUT call to the REST API, as tainted by the plugins. Make a PUT call to the Orthanc REST API, after all the plugins are applied. In other words, if some plugin overrides or adds the called URI to the built-in Orthanc REST API, this call will return the result provided by this plugin. The result to the query is stored into a newly allocated memory buffer. Remark: If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.- Parameters:
uri
- The URI in the built-in Orthanc API.body
- The body of the PUT request.- Returns:
- The resulting memory buffer.
-
lookupPatient
public static java.lang.String lookupPatient(java.lang.String patientID)
Look for a patient. Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). This function uses the database index to run as fast as possible (it does not loop over all the stored patients).- Parameters:
patientID
- The Patient ID of interest.- Returns:
- The resulting string.
-
lookupStudy
public static java.lang.String lookupStudy(java.lang.String studyUID)
Look for a study. Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). This function uses the database index to run as fast as possible (it does not loop over all the stored studies).- Parameters:
studyUID
- The Study Instance UID of interest.- Returns:
- The resulting string.
-
lookupStudyWithAccessionNumber
public static java.lang.String lookupStudyWithAccessionNumber(java.lang.String accessionNumber)
Look for a study, using the accession number. Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050). This function uses the database index to run as fast as possible (it does not loop over all the stored studies).- Parameters:
accessionNumber
- The Accession Number of interest.- Returns:
- The resulting string.
-
lookupSeries
public static java.lang.String lookupSeries(java.lang.String seriesUID)
Look for a series. Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). This function uses the database index to run as fast as possible (it does not loop over all the stored series).- Parameters:
seriesUID
- The Series Instance UID of interest.- Returns:
- The resulting string.
-
lookupInstance
public static java.lang.String lookupInstance(java.lang.String sopInstanceUID)
Look for an instance. Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). This function uses the database index to run as fast as possible (it does not loop over all the stored instances).- Parameters:
sopInstanceUID
- The SOP Instance UID of interest.- Returns:
- The resulting string.
-
getOrthancPath
public static java.lang.String getOrthancPath()
Return the path to the Orthanc executable. This function returns the path to the Orthanc executable.- Returns:
- The resulting string.
-
getOrthancDirectory
public static java.lang.String getOrthancDirectory()
Return the directory containing the Orthanc. This function returns the path to the directory containing the Orthanc executable.- Returns:
- The resulting string.
-
getConfigurationPath
public static java.lang.String getConfigurationPath()
Return the path to the configuration file(s). This function returns the path to the configuration file(s) that was specified when starting Orthanc. Since version 0.9.1, this path can refer to a folder that stores a set of configuration files. This function is deprecated in favor of OrthancPluginGetConfiguration().- Returns:
- The resulting string.
-
setRootUri
public static void setRootUri(java.lang.String uri)
Set the URI where the plugin provides its Web interface. For plugins that come with a Web interface, this function declares the entry path where to find this interface. This information is notably used in the "Plugins" page of Orthanc Explorer.- Parameters:
uri
- The root URI for this plugin.
-
setDescription
public static void setDescription(java.lang.String description)
Set a description for this plugin. Set a description for this plugin. It is displayed in the "Plugins" page of Orthanc Explorer.- Parameters:
description
- The description.
-
extendOrthancExplorer
public static void extendOrthancExplorer(java.lang.String javascript)
Extend the JavaScript code of Orthanc Explorer. Add JavaScript code to customize the default behavior of Orthanc Explorer. This can for instance be used to add new buttons.- Parameters:
javascript
- The custom JavaScript code.
-
getGlobalProperty
public static java.lang.String getGlobalProperty(int property, java.lang.String defaultValue)
Get the value of a global property. Get the value of a global property that is stored in the Orthanc database. Global properties whose index is below 1024 are reserved by Orthanc.- Parameters:
property
- The global property of interest.defaultValue
- The value to return, if the global property is unset.- Returns:
- The resulting string.
-
setGlobalProperty
public static void setGlobalProperty(int property, java.lang.String value)
Set the value of a global property. Set the value of a global property into the Orthanc database. Setting a global property can be used by plugins to save their internal parameters. Plugins are only allowed to set properties whose index are above or equal to 1024 (properties below 1024 are read-only and reserved by Orthanc).- Parameters:
property
- The global property of interest.value
- The value to be set in the global property.
-
getCommandLineArgumentsCount
public static int getCommandLineArgumentsCount()
Get the number of command-line arguments. Retrieve the number of command-line arguments that were used to launch Orthanc.- Returns:
- The number of arguments.
-
getCommandLineArgument
public static java.lang.String getCommandLineArgument(int argument)
Get the value of a command-line argument. Get the value of one of the command-line arguments that were used to launch Orthanc. The number of available arguments can be retrieved by OrthancPluginGetCommandLineArgumentsCount().- Parameters:
argument
- The index of the argument.- Returns:
- The resulting string.
-
getExpectedDatabaseVersion
public static int getExpectedDatabaseVersion()
Get the expected version of the database schema. Retrieve the expected version of the database schema.- Returns:
- The version.
-
getConfiguration
public static java.lang.String getConfiguration()
Return the content of the configuration file(s). This function returns the content of the configuration that is used by Orthanc, formatted as a JSON string.- Returns:
- The resulting string.
-
bufferCompression
public static byte[] bufferCompression(byte[] source, CompressionType compression, byte uncompress)
Compress or decompress a buffer. This function compresses or decompresses a buffer, using the version of the zlib library that is used by the Orthanc core.- Parameters:
source
- The source buffer.compression
- The compression algorithm.uncompress
- If set to "0", the buffer must be compressed. If set to "1", the buffer must be uncompressed.- Returns:
- The resulting memory buffer.
-
readFile
public static byte[] readFile(java.lang.String path)
Read a file. Read the content of a file on the filesystem, and returns it into a newly allocated memory buffer.- Parameters:
path
- The path of the file to be read.- Returns:
- The resulting memory buffer.
-
writeFile
public static void writeFile(java.lang.String path, byte[] data)
Write a file. Write the content of a memory buffer to the filesystem.- Parameters:
path
- The path of the file to be written.data
- The content of the memory buffer.
-
getErrorDescription
public static java.lang.String getErrorDescription(ErrorCode error)
Get the description of a given error code. This function returns the description of a given error code.- Parameters:
error
- The error code of interest.- Returns:
- The resulting string.
-
compressPngImage
public static byte[] compressPngImage(PixelFormat format, int width, int height, int pitch, byte[] buffer)
Encode a PNG image. This function compresses the given memory buffer containing an image using the PNG specification, and stores the result of the compression into a newly allocated memory buffer.- Parameters:
format
- The memory layout of the uncompressed image.width
- The width of the image.height
- The height of the image.pitch
- The pitch of the image (i.e. the number of bytes between 2 successive lines of the image in the memory buffer).buffer
- The memory buffer containing the uncompressed image.- Returns:
- The resulting memory buffer.
-
compressJpegImage
public static byte[] compressJpegImage(PixelFormat format, int width, int height, int pitch, byte[] buffer, byte quality)
Encode a JPEG image. This function compresses the given memory buffer containing an image using the JPEG specification, and stores the result of the compression into a newly allocated memory buffer.- Parameters:
format
- The memory layout of the uncompressed image.width
- The width of the image.height
- The height of the image.pitch
- The pitch of the image (i.e. the number of bytes between 2 successive lines of the image in the memory buffer).buffer
- The memory buffer containing the uncompressed image.quality
- The quality of the JPEG encoding, between 1 (worst quality, best compression) and 100 (best quality, worst compression).- Returns:
- The resulting memory buffer.
-
httpGet
public static byte[] httpGet(java.lang.String url, java.lang.String username, java.lang.String password)
Issue a HTTP GET call. Make a HTTP GET call to the given URL. The result to the query is stored into a newly allocated memory buffer. Favor OrthancPluginRestApiGet() if calling the built-in REST API of the Orthanc instance that hosts this plugin.- Parameters:
url
- The URL of interest.username
- The username (can be "NULL" if no password protection).password
- The password (can be "NULL" if no password protection).- Returns:
- The resulting memory buffer.
-
httpPost
public static byte[] httpPost(java.lang.String url, byte[] body, java.lang.String username, java.lang.String password)
Issue a HTTP POST call. Make a HTTP POST call to the given URL. The result to the query is stored into a newly allocated memory buffer. Favor OrthancPluginRestApiPost() if calling the built-in REST API of the Orthanc instance that hosts this plugin.- Parameters:
url
- The URL of interest.body
- The content of the body of the request.username
- The username (can be "NULL" if no password protection).password
- The password (can be "NULL" if no password protection).- Returns:
- The resulting memory buffer.
-
httpPut
public static byte[] httpPut(java.lang.String url, byte[] body, java.lang.String username, java.lang.String password)
Issue a HTTP PUT call. Make a HTTP PUT call to the given URL. The result to the query is stored into a newly allocated memory buffer. Favor OrthancPluginRestApiPut() if calling the built-in REST API of the Orthanc instance that hosts this plugin.- Parameters:
url
- The URL of interest.body
- The content of the body of the request.username
- The username (can be "NULL" if no password protection).password
- The password (can be "NULL" if no password protection).- Returns:
- The resulting memory buffer.
-
httpDelete
public static void httpDelete(java.lang.String url, java.lang.String username, java.lang.String password)
Issue a HTTP DELETE call. Make a HTTP DELETE call to the given URL. Favor OrthancPluginRestApiDelete() if calling the built-in REST API of the Orthanc instance that hosts this plugin.- Parameters:
url
- The URL of interest.username
- The username (can be "NULL" if no password protection).password
- The password (can be "NULL" if no password protection).
-
getFontsCount
public static int getFontsCount()
Return the number of available fonts. This function returns the number of fonts that are built in the Orthanc core. These fonts can be used to draw texts on images through OrthancPluginDrawText().- Returns:
- The number of fonts.
-
getFontName
public static java.lang.String getFontName(int fontIndex)
Return the name of a font. This function returns the name of a font that is built in the Orthanc core.- Parameters:
fontIndex
- The index of the font. This value must be less than OrthancPluginGetFontsCount().- Returns:
- The resulting string.
-
getFontSize
public static int getFontSize(int fontIndex)
Return the size of a font. This function returns the size of a font that is built in the Orthanc core.- Parameters:
fontIndex
- The index of the font. This value must be less than OrthancPluginGetFontsCount().- Returns:
- The font size.
-
registerErrorCode
public static void registerErrorCode(int code, short httpStatus, java.lang.String message)
Declare a custom error code for this plugin. This function declares a custom error code that can be generated by this plugin. This declaration is used to enrich the body of the HTTP answer in the case of an error, and to set the proper HTTP status code.- Parameters:
code
- The error code that is internal to this plugin.httpStatus
- The HTTP status corresponding to this error.message
- The description of the error.
-
registerDictionaryTag
public static void registerDictionaryTag(short group, short element, ValueRepresentation vr, java.lang.String name, int minMultiplicity, int maxMultiplicity)
Register a new tag into the DICOM dictionary. This function declares a new public tag in the dictionary of DICOM tags that are known to Orthanc. This function should be used in the OrthancPluginInitialize() callback.- Parameters:
group
- The group of the tag.element
- The element of the tag.vr
- The value representation of the tag.name
- The nickname of the tag.minMultiplicity
- The minimum multiplicity of the tag (must be above 0).maxMultiplicity
- The maximum multiplicity of the tag. A value of 0 means an arbitrary multiplicity (""n"").
-
registerPrivateDictionaryTag
public static void registerPrivateDictionaryTag(short group, short element, ValueRepresentation vr, java.lang.String name, int minMultiplicity, int maxMultiplicity, java.lang.String privateCreator)
Register a new private tag into the DICOM dictionary. This function declares a new private tag in the dictionary of DICOM tags that are known to Orthanc. This function should be used in the OrthancPluginInitialize() callback.- Parameters:
group
- The group of the tag.element
- The element of the tag.vr
- The value representation of the tag.name
- The nickname of the tag.minMultiplicity
- The minimum multiplicity of the tag (must be above 0).maxMultiplicity
- The maximum multiplicity of the tag. A value of 0 means an arbitrary multiplicity (""n"").privateCreator
- The private creator of this private tag.
-
dicomBufferToJson
public static java.lang.String dicomBufferToJson(byte[] buffer, DicomToJsonFormat format, DicomToJsonFlags flags, int maxStringLength)
Format a DICOM memory buffer as a JSON string. This function takes as input a memory buffer containing a DICOM file, and outputs a JSON string representing the tags of this DICOM file.- Parameters:
buffer
- The memory buffer containing the DICOM file.format
- The output format.flags
- Flags governing the output.maxStringLength
- The maximum length of a field. Too long fields will be output as "null". The 0 value means no maximum length.- Returns:
- The resulting string.
-
dicomInstanceToJson
public static java.lang.String dicomInstanceToJson(java.lang.String instanceId, DicomToJsonFormat format, DicomToJsonFlags flags, int maxStringLength)
Format a DICOM instance as a JSON string. This function formats a DICOM instance that is stored in Orthanc, and outputs a JSON string representing the tags of this DICOM instance.- Parameters:
instanceId
- The Orthanc identifier of the instance.format
- The output format.flags
- Flags governing the output.maxStringLength
- The maximum length of a field. Too long fields will be output as "null". The 0 value means no maximum length.- Returns:
- The resulting string.
-
createDicom
public static byte[] createDicom(java.lang.String json, Image pixelData, CreateDicomFlags flags)
Create a DICOM instance from a JSON string and an image. This function takes as input a string containing a JSON file describing the content of a DICOM instance. As an output, it writes the corresponding DICOM instance to a newly allocated memory buffer. Additionally, an image to be encoded within the DICOM instance can also be provided. Private tags will be associated with the private creator whose value is specified in the "DefaultPrivateCreator" configuration option of Orthanc. The function OrthancPluginCreateDicom2() can be used if another private creator must be used to create this instance.- Parameters:
json
- The input JSON file.pixelData
- The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.flags
- Flags governing the output.- Returns:
- The resulting memory buffer.
-
computeMd5
public static java.lang.String computeMd5(byte[] buffer)
Compute an MD5 hash. This functions computes the MD5 cryptographic hash of the given memory buffer.- Parameters:
buffer
- The source memory buffer.- Returns:
- The resulting string.
-
computeSha1
public static java.lang.String computeSha1(byte[] buffer)
Compute a SHA-1 hash. This functions computes the SHA-1 cryptographic hash of the given memory buffer.- Parameters:
buffer
- The source memory buffer.- Returns:
- The resulting string.
-
generateUuid
public static java.lang.String generateUuid()
Generate an UUID. Generate a random GUID/UUID (globally unique identifier).- Returns:
- The resulting string.
-
autodetectMimeType
public static java.lang.String autodetectMimeType(java.lang.String path)
Detect the MIME type of a file. This function returns the MIME type of a file by inspecting its extension.- Parameters:
path
- Path to the file.- Returns:
- The resulting string.
-
setMetricsValue
public static void setMetricsValue(java.lang.String name, float value, MetricsType type)
Set the value of a metrics. This function sets the value of a metrics to monitor the behavior of the plugin through tools such as Prometheus. The values of all the metrics are stored within the Orthanc context.- Parameters:
name
- The name of the metrics to be set.value
- The value of the metrics.type
- The type of the metrics. This parameter is only taken into consideration the first time this metrics is set.
-
getTagName
public static java.lang.String getTagName(short group, short element, java.lang.String privateCreator)
Returns the symbolic name of a DICOM tag. This function makes a lookup to the dictionary of DICOM tags that are known to Orthanc, and returns the symbolic name of a DICOM tag.- Parameters:
group
- The group of the tag.element
- The element of the tag.privateCreator
- For private tags, the name of the private creator (can be NULL).- Returns:
- The resulting string.
-
generateRestApiAuthorizationToken
public static java.lang.String generateRestApiAuthorizationToken()
Generate a token to grant full access to the REST API of Orthanc This function generates a token that can be set in the HTTP header "Authorization" so as to grant full access to the REST API of Orthanc using an external HTTP client. Using this function avoids the need of adding a separate user in the "RegisteredUsers" configuration of Orthanc, which eases deployments. This feature is notably useful in multiprocess scenarios, where a subprocess created by a plugin has no access to the "OrthancPluginContext", and thus cannot call "OrthancPluginRestApi[Get|Post|Put|Delete]()". This situation is frequently encountered in Python plugins, where the "multiprocessing" package can be used to bypass the Global Interpreter Lock (GIL) and thus to improve performance and concurrency.- Returns:
- The resulting string.
-
createDicom2
public static byte[] createDicom2(java.lang.String json, Image pixelData, CreateDicomFlags flags, java.lang.String privateCreator)
Create a DICOM instance from a JSON string and an image, with a private creator. This function takes as input a string containing a JSON file describing the content of a DICOM instance. As an output, it writes the corresponding DICOM instance to a newly allocated memory buffer. Additionally, an image to be encoded within the DICOM instance can also be provided. Contrarily to the function OrthancPluginCreateDicom(), this function can be explicitly provided with a private creator.- Parameters:
json
- The input JSON file.pixelData
- The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.flags
- Flags governing the output.privateCreator
- The private creator to be used for the private DICOM tags. Check out the global configuration option "Dictionary" of Orthanc.- Returns:
- The resulting memory buffer.
-
-