Finding a patient’s imaging studies is often the first step in a DICOM workflow. With a DICOMweb QIDO-RS query, your application can search study metadata and identify relevant studies before downloading any image instances.

In this tutorial, you’ll use Aspose.Medical for .NET to search DICOM studies by patient name in C#. You’ll set up the SDK, create a DICOMweb client, configure a search pattern and result limit, and read the matching studies. The complete console example displays each study’s Patient Name and Study Instance UID.

To follow along, you’ll need an accessible QIDO-RS endpoint containing studies to query.

Install Aspose.Medical for .NET

This example targets .NET 10 and uses Aspose.Medical 26.10.0. Install the .NET 10 SDK, then create a console project and add the pinned package:

dotnet new console -n DicomStudySearch -f net10.0
cd DicomStudySearch
dotnet add package Aspose.Medical --version 26.10.0

Your project file should contain the following settings. Implicit usings provide the standard namespaces used by the example, while nullable reference types support its optional environment-variable values.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Aspose.Medical" Version="26.10.0" />
  </ItemGroup>
</Project>

If you use Visual Studio’s Package Manager Console, install the same version with:

Install-Package Aspose.Medical -Version 26.10.0

The example uses the Aspose.Medical.Dicom, Aspose.Medical.Dicom.Tags, and Aspose.Medical.Dicom.Web namespaces. Their using directives are included in the complete program below.

Configure the license and endpoint access

The program checks ASPOSE_MEDICAL_LICENSE for a license file path and loads that file when the variable is set. If you need a license for evaluation, you can request a temporary license.

For a service that accepts bearer authentication, set DICOMWEB_TOKEN to your access token. Leave it unset if your endpoint does not require a bearer token. Services using another authentication method need corresponding changes to the HTTP client configuration.

For example, in PowerShell:

$env:ASPOSE_MEDICAL_LICENSE = "C:\Licenses\Aspose.Medical.lic"
$env:DICOMWEB_TOKEN = "your-access-token"

Replace these placeholders with your own values and set only the variables you need.

Search DICOM Studies by Patient Name in C#

Replace Program.cs with the following code. The program accepts the DICOMweb base URI as its first argument and an optional patient-name pattern as its second argument. If you omit the pattern, it uses Doe*.

using System.Net.Http.Headers;
using Aspose.Medical.Dicom;
using Aspose.Medical.Dicom.Tags;
using Aspose.Medical.Dicom.Web;

if (args.Length < 1)
{
    Console.Error.WriteLine("Usage: dotnet run -- <dicomweb-base-uri> [patient-name-pattern]");
    Environment.ExitCode = 1;
    return;
}

try
{
    string? licensePath = Environment.GetEnvironmentVariable("ASPOSE_MEDICAL_LICENSE");
    if (!string.IsNullOrWhiteSpace(licensePath))
        new Aspose.Medical.License().SetLicense(licensePath);

    using var httpClient = new HttpClient();
    string? token = Environment.GetEnvironmentVariable("DICOMWEB_TOKEN");
    if (!string.IsNullOrWhiteSpace(token))
        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

    var client = new DicomWebClient(httpClient, new DicomWebClientOptions
    {
        BaseUri = new Uri(args[0], UriKind.Absolute)
    });
    string pattern = args.Length > 1 ? args[1] : "Doe*";
    var searchOptions = new DicomWebSearchOptions
    {
        MatchingParameters = [new DicomWebQueryParameter("PatientName", pattern)],
        FuzzyMatching = false,
        Limit = 10,
        Offset = 0
    };

    using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30));
    await using DicomWebClientStream<Dataset> results =
        await client.Studies.SearchAsync(searchOptions, timeout.Token);
    int count = 0;
    await foreach (Dataset study in results.WithCancellation(timeout.Token))
    {
        string name = study.GetValueOrDefault<string>(Tag.PatientName, 0, "(not returned)");
        string uid = study.GetValueOrDefault<string>(Tag.StudyInstanceUID, 0, "(not returned)");
        Console.WriteLine($"Patient: {name}, Study UID: {uid}");
        count++;
    }
    Console.WriteLine($"Studies returned: {count}");
}
catch (Exception ex)
{
    Console.Error.WriteLine($"{ex.GetType().Name}: {ex.Message}");
    Environment.ExitCode = 1;
}

The following sections explain how the client configuration, search options, and result processing work together.

Create a DICOMweb Client

The program creates an HttpClient and, when a token is provided, adds a bearer authorization header. It then passes that HTTP client to DicomWebClient along with DicomWebClientOptions.

Set BaseUri to your service’s DICOMweb base URL. The code reads it from args[0] and requires an absolute URI. Use the base URL supplied by your server administrator rather than assuming that every service uses the same path.

Configure the Patient Name Query

DicomWebSearchOptions contains the study-search criteria. In this example, MatchingParameters pairs PatientName with the pattern supplied on the command line.

The other settings control matching and the requested result page:

SettingExample valuePurpose
FuzzyMatchingfalseDoes not request fuzzy matching.
Limit10Requests at most ten studies.
Offset0Requests results starting at the initial offset.

The Doe* wildcard pattern is separate from the fuzzy-matching option. Check your endpoint’s supported patient-name matching behavior before relying on a particular result. Enabling fuzzy matching does not itself guarantee case-insensitive or wildcard behavior.

The program reads one result page. It does not automatically request subsequent pages.

Execute the Search and Read Study Metadata

client.Studies.SearchAsync executes the query and returns a DicomWebClientStream<Dataset>. The program uses await foreach to read the returned datasets and await using to dispose of the stream when processing finishes.

For each study, GetValueOrDefault<string> reads the first value of Tag.PatientName and Tag.StudyInstanceUID. If a value is absent, the program displays (not returned) instead.

A 30-second cancellation token is passed to both the search call and the result iteration. The program counts the datasets it reads and prints the count after the loop. If an exception occurs, it writes the exception type and message to standard error and sets the process exit code to 1.

Run the Example and Check the Results

From the project directory, run:

dotnet run -- "https://dicom.example.com/dicomweb" "Doe*"

Replace the example URL with your accessible DICOMweb service URL. Use a patient-name pattern that matches studies stored on that service.

The following output is illustrative; the names, UIDs, and count depend on your endpoint’s data and matching rules:

Patient: Doe^Jane, Study UID: 1.2.826.0.1.3680043.10.543.1001
Patient: Doe^John, Study UID: 1.2.826.0.1.3680043.10.543.1002
Studies returned: 2

If the query completes without matches, the program prints:

Studies returned: 0

A zero count means no datasets were returned for that query. An exception message and exit code 1 indicate that the operation did not complete successfully. This example retrieves study metadata; it does not download DICOM image instances.

Conclusion

Run the example against your QIDO-RS endpoint with a known patient name, then adjust the search pattern and result limit for your application. If you need more than one page of studies, extend the example to request subsequent pages using the pagination behavior supported by your server.

For related APIs and configuration guidance, see the Aspose.Medical for .NET documentation and API reference.

Frequently Asked Questions

  1. What is QIDO-RS?

QIDO-RS is the DICOMweb service used to search for DICOM resources through HTTP queries. This example uses it to find studies by patient name and read their metadata.

  1. Which package provides the DICOMweb client?

The supplied example uses the Aspose.Medical NuGet package, version 26.10.0, and imports its Aspose.Medical.Dicom.Web namespace for the client and search options.

  1. Does searching studies download DICOM images?

No. This example reads the metadata returned by a study search. Downloading image instances requires a separate retrieval operation.

  1. Can I limit the number of returned studies?

Yes. Set Limit on DicomWebSearchOptions. The example uses Limit = 10 and Offset = 0 to request the first page of up to ten studies.

  1. What does the FuzzyMatching option do?

It requests fuzzy matching from the server. The example sets it to false. Wildcard patterns such as Doe* are supplied separately in MatchingParameters, and the endpoint determines the supported matching behavior.

  1. How do I read the patient name and Study Instance UID?

Use GetValueOrDefault<string> with Tag.PatientName and Tag.StudyInstanceUID on each returned dataset. The example supplies (not returned) as a fallback for an absent value.

Read More