Navigation:  I Want To... > Automation >

Find a study to open in the viewer

Previous pageReturn to chapter overviewNext page

Use Case

You want to programmatically find a study to open in the viewer.

Sample Code

using System;

using System.Collections.Generic;

using System.ServiceModel;

using ClearCanvas.Dicom.ServiceModel.Query;

using ClearCanvas.ImageViewer.Services.Automation;

 

internal static class AutomationHelper

{

   public static IList<StudyRootStudyIdentifier> FindStudyByPatientId(string patientId)

   {

      BasicHttpBinding binding = new BasicHttpBinding();

      EndpointAddress endpoint = new EndpointAddress("http://127.0.0.1:51124/ClearCanvas/ImageViewer/StudyLocator?wsdl");

 

      StudyRootQueryServiceClient client = new StudyRootQueryServiceClient(binding, endpoint);

      try

      {

         client.Open();

         StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier();

         identifier.PatientId = patientId;

         IList<StudyRootStudyIdentifier> results = client.StudyQuery(identifier);

         client.Close();

 

         return results;

      }

      catch(Exception)

      {

         client.Abort();

         throw;

      }

   }

}

Remarks

Now that you can open a study in the viewer, it may have already occurred to you that your application doesn't directly have access to Study Instance Uids.  In fact, many RIS/Worklist applications don't have access to such Uids, and it is generally these types of applications that will automate the viewer.

For this reason, the viewer exposes another service called the Study Locator.  The study locator service will search the viewer's local database and any default servers with streaming capabilities (e.g. those the user has checked in Tools > Options > Default Servers).

For now, let's take the steps necessary to determine whether or not a study is available for viewing.  First, you will need to follow the same steps you took in the Communicate with the automation service section, but this time for the study locator service.  For either Option 1 or Option 2, the default URL of the service is http://127.0.0.1:51124/ClearCanvas/ImageViewer/StudyLocator?wsdl.  If you choose Option 3, the name of the provided proxy class is ClearCanvas.Dicom.ServiceModel.Query.StudyRootQueryServiceClient.

The study locator service uses a concept in Dicom called the Study Root Query/Retrieve Information Model, or Study Root Query for short.  Essentially, what it does is allows clients to send a query "Identifier", that contains Dicom attributes to query on, to a Dicom server (or SCP).  The server will examine the values in the Identifier and compile and return the results in the form of a list of Identifiers.  The study locator service models the Study Root Query as a web service.  The sample code above is a very simple example of how you can find all the studies for a patient with a given Patient Id (or MRN).

The following table gives some sample values (for properties of ClearCanvas.Dicom.ServiceModel.Query.StudyRootStudyIdentifier) that can be used to perform a Study Root Query.  For more information on how to structure these query values, please consult Dicom Part 4 - Service Class Specifications, specifically Annex C.2.

Property

Value

Description

PatientId

123

Finds all studies for patient with Id = 123

PatientsName

Doe*

Finds all patients whose last name starts with Doe

AccessionNumber

456

Finds a study (or studies) with Accession# = 456

StudyDate

20080101

Finds all studies acquired on January 1, 2008

20080101-

Finds all studies acquired on or after January 1, 2008

-20080101

Finds all studies acquired on or before January 1, 2008

20080101-20080103

Finds all studies acquired between January 1-3, 2008 inclusive

When multiple values are used together in a single query, the implied logical operator is AND.

 

Now that we know how to find the studies we're looking for, we can pass them to the automation service in order to open them in the viewer.

Examples in Code Base

ClearCanvas.ImageViewer.DesktopServices.Automation.TestClient.csproj (C# project)