Esempio n. 1
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="context">OrthancPluginContext* - The Orthanc plugin context, as received by OrthancPluginInitialize().</param>
        /// <param name="buffer">const void* - The memory buffer containing the DICOM file.</param>
        /// <param name="size">uint32_t - The size of the memory buffer.</param>
        /// <param name="format">OrthancPluginDicomToJsonFormat - The output format.</param>
        /// <param name="flags">OrthancPluginDicomToJsonFlags - Flags governing the output.</param>
        /// <param name="maxStringLength">uint32_t - The maximum length of a field. Too long fields will be output as "null". The 0 value means no maximum length.</param>
        /// <returns>char* - The NULL value if the case of an error, or the JSON string. This string must be freed by OrthancPluginFreeString().</returns>
        public static IntPtr OrthancPluginDicomBufferToJson(ref OrthancPluginContext context, IntPtr buffer, uint size, OrthancPluginDicomToJsonFormat format, OrthancPluginDicomToJsonFlags flags, uint maxStringLength)
        {
            IntPtr ptr = IntPtr.Zero;

            try
            {
                _OrthancPluginDicomToJson pr = new _OrthancPluginDicomToJson();
                pr.buffer          = buffer;
                pr.size            = size;
                pr.format          = format;
                pr.flags           = flags;
                pr.maxStringLength = maxStringLength;

                int ptrSize = Marshal.SizeOf(pr);
                ptr = Marshal.AllocHGlobal(ptrSize);
                Marshal.StructureToPtr(pr, ptr, true);

                if (context.InvokeService(ref context, _OrthancPluginService._OrthancPluginService_DicomBufferToJson, ptr) != OrthancPluginErrorCode.OrthancPluginErrorCode_Success)
                {
                    return(IntPtr.Zero);
                }
                else
                {
                    pr = (_OrthancPluginDicomToJson)Marshal.PtrToStructure(ptr, typeof(_OrthancPluginDicomToJson));
                    return(pr.result);
                }
            }
            catch (Exception ex)
            {
                Log.Message(ex.ToString());
                OrthancPluginLogError(ref context, ex.ToString());
                return(IntPtr.Zero);
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="context">OrthancPluginContext* - The Orthanc plugin context, as received by OrthancPluginInitialize().</param>
        /// <param name="instanceId">const char* - The Orthanc identifier of the instance.</param>
        /// <param name="format">OrthancPluginDicomToJsonFormat - The output format.</param>
        /// <param name="flags">OrthancPluginDicomToJsonFlags - Flags governing the output.</param>
        /// <param name="maxStringLength">uint32_t - The maximum length of a field. Too long fields will be output as "null". The 0 value means no maximum length.</param>
        /// <returns>char* - The NULL value if the case of an error, or the JSON string. This string must be freed by OrthancPluginFreeString().</returns>
        public static IntPtr OrthancPluginDicomInstanceToJson(ref OrthancPluginContext context, IntPtr instanceId, OrthancPluginDicomToJsonFormat format, OrthancPluginDicomToJsonFlags flags, uint maxStringLength)
        {
            IntPtr ptr = IntPtr.Zero;
            try
            {
                _OrthancPluginDicomToJson pr = new _OrthancPluginDicomToJson();
                pr.instanceId = instanceId;
                pr.format = format;
                pr.flags = flags;
                pr.maxStringLength = maxStringLength;

                int size = Marshal.SizeOf(pr);
                ptr = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(pr, ptr, true);

                if (context.InvokeService(ref context, _OrthancPluginService._OrthancPluginService_DicomInstanceToJson, ptr) != OrthancPluginErrorCode.OrthancPluginErrorCode_Success)
                {
                    return IntPtr.Zero;
                }
                else
                {
                    pr = (_OrthancPluginDicomToJson)Marshal.PtrToStructure(ptr, typeof(_OrthancPluginDicomToJson));
                    return pr.result;
                }
            }
            catch (Exception ex)
            {
                Log.Message(ex.ToString());
                OrthancPluginLogError(ref context, ex.ToString());
                return IntPtr.Zero;
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }