Navigation:  I Want To... > Automation >

Open a study in the viewer

Previous pageReturn to chapter overviewNext page

Use Case

You want to use the automation service to open a study (or studies) 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 void OpenStudy(string studyInstanceUid)

   {

      BasicHttpBinding binding = new BasicHttpBinding();

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

 

      ViewerAutomationServiceClient client = new ViewerAutomationServiceClient(binding, endpoint);

 

      try

      {

         client.Open();

         OpenStudiesRequest request = new OpenStudiesRequest();

         request.ActivateIfAlreadyOpen = true;

         List<OpenStudyInfo> studiesToOpen = new List<OpenStudyInfo>();

 

         OpenStudyInfo info = new OpenStudyInfo(studyInstanceUid);

         studiesToOpen.Add(info);

         request.StudiesToOpen = studiesToOpen;

         client.OpenStudies(request);

 

         client.Close();

      }

      catch (Exception e)

      {

         client.Abort();

         MessageBox.Show(e.Message);

      }

   }

}

Remarks

Now comes the fun part, where you can start automating the viewer.  Follow these steps to try it out:

Paste the sample code above into your project.
In the viewer, manually open a study and select an image.  Select Tools > Utilities > Dicom Editor.  Make a note of the Study Instance Uid and close the study.
In your code, call the sample method, passing the Study Instance Uid from the previous step.  The study should open in the viewer.

 

A couple of things to note about the automation service's behaviour:

Because OpenStudiesRequest.ActivateIfAlreadyOpen is true, you can call this method repeatedly, and the study will only ever open once.  If this property were false, it would open in a new window each time OpenStudies was called.
When first displaying the images, the viewer will respect the order of the studies in OpenStudiesRequest.StudiesToOpen; the first one will be displayed first, and will be treated by the viewer as the 'primary' study, or study of interest. This is important to keep in mind when using automation.
The automation service is explicitly study-centric—you can only open studies, by Study Instance Uid.

Examples in Code Base

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