Customizing a LEADTOOLS MWL Database

In this tutorial you will customize a database by adding two new columns to tables in an existing database. Then create an Leadtools.Medical.Worklist.DataAccessLayer.IWorklistDataAccessAgent object to query and update the new columns. Finally you will map the new columns to the appropriate DICOM elements for the client query responses.

For a complete working demo program and source code that incorporates the following steps refer to the CustomizingWorklistDAL demo in <InstallationDirectory>\Bin\Dotnet4\Win32 and the source code in <__49_nstallation44_irectory>\Examples\Dotnet\.

Note: These tasks and code snippets assume that you have created and configured the base Modality Worklist database and a valid connection exists. LEADTOOLS provides Microsoft SQL Server Compact Edition database files for you to use if necessary. The files are named LeadDicomWorklist32.sdf and LeadDicomWorklist64.sdf. They are a 32-bit and 64-bit respectively and are located in C:\Users\Public\Documents. Choose the database that is appropriate for your application and environment

  1. The two new columns to create are a "SmokingStatus" column in the "Patient" table and a "CommentsOnTheScheduledProcedureStep" in the "ScheduledProcedureStep" table. The two new columns will be mapped to the following DICOM elements:

    • Smoking Status(0010,21A0)
    • Procedure Step Comments on the Scheduled(0040,0400)

    You can use a visual tool like SQL Enterprise Manager to add the new columns to the appropriate tables in the database. Alternatively, you can use the following SQL commands:

alter table [Patient] add [SmokingStatus]nvarchar(10) 
alter table [ScheduledProcedureStep] add [CommentOnTheSchedulerProcedureStep] nvarchar(400) 

  1. Select a valid data type for the database columns that represents the actual DICOM VR of the elements you are mapping them to.

  2. Use the Leadtools.Medical.Worklist.DataAccessLayer.IWorklistDataAccessAgent object to query and insert a new value into the new fields in the "SmokingStatus" and "CommentsOnTheScheduleProcedureStep" colums. The following code accomplished these tasks. This code assumes that you have successfully created and configured the base Modality Worklist database and that there is a valid database connection.

private void QueryWorklistItems () 
   IWorklistDataAccessAgent agent = GetDataAccessAgent() ; 
   MWLDataset queryResults = agent.QueryModalityWorklists(new MatchingParameterCollection(), new StringCollection()); 
   if (queryResults.Patient.Rows.Count > 0) 
      queryResults.Patient[0] ["SmokingStatus"] = "UNKNOWN"; 
   if (queryResults.ScheduledProcedureStep.Rows.Count > 0) 
      queryResults.ScheduledProcedureStep[0] ["CommentsOnTheScheduledProcedureStep"] = "Some comments on the procedure 
private IWorklistDataAccessAgent GetDataAccessAgent() 
      WorklistDataAccessConfigurationView view = new WorklistDataAccessConfigurationView(); 
      IWorklistDataAccessAgent agent; 
      string connectionString = view.GetConnectionStringSettings().ConnectionString; 
      string provider         = view.GetConnectionStringSettings().ProviderName; 
      if (provider == DataAccessMapping.DefaultSqlProviderName) 
         agent    = new WorklistSqlDbDataAccessAgent (connectionString); 
      else if (provider == DataAccessMapping.DefaultSqlCe3_5ProviderName) 
         agent    = new WorklistSqlCeDataAccessAgent(connectionString); 
         throw new NotImplementedException(); 
      return agent; 

  1. Now that the Leadtools.Medical.Worklist.DataAccessLayer.IWorklistDataAccessAgent object is able to query and update the new columns you created, you need to support these columns in the DICOM C-Find responses. The ModalityWorklistAddIn uses the Leadtools.Dicom.Scp.Command.MWLCFindCommand to map these two columns to the correct DICOM element in the response to a client query.

    The Leadtools.Dicom.Scp.Command.MWLCFindCommand has a static property, Leadtools.Dicom.Scp.Command.MWLCFindCommand.DefualtMWLIOD, which returns a stream. The stream is an XML file containing the DICOM Modality Worklist IOD elements and tells the Leadtools.Dicom.Scp.Command.MWLCFindCommand how each element is mapped in the returned QueryModalityWorklists.

  2. Write the MWL IOD stream to the disk using the following code:

using (Stream iodStream = MWLCFindCommand.DefualtMWLIOD) 
    using (FileStream customIODStream = new FileStream(_iodPath, FileMode.Create)) 
       int readCount; 
       var buffer = new byte[8192]; 
       while((readCount = iodStream.Read(buffer, 0, buffer.Length)) != 0) 
       customIODStream.Write(buffer, 0, readCount); 

  1. Open the new xml file in any text editor and find the SmokingStatus and the ScheduledProcedureStep elements. Update the tableName and columnsName attributes with the new values:

    <element tag="(0010,21a0)" tagName="SmokingStatus" vr="CS" minVM="1" maxVM="1" vmDivider="1" returnType="Type3" matchingType="NotApplicable" returning="true" tableName="Patient" matchingEntity="" columnsName="SmokingStatus" /> 
        <element tag="(0040,0400)" tagName="CommentsOnTheScheduledProcedureStep" vr="LT" minVM="1" maxVM="1" vmDivider="1" returnType="Type3" matchingType="NotApplicable" returning="true" tableName="ScheduledProcedureStep" matchingEntity="" columnsName="CommentsOnTheScheduledProcedureStep" /> 

  2. You should validate your new XML file according to the schema. Use the following code to validate the new XML file:

private static void ValidateDocument(string iodPath) 
   XmlSchema         mwlSchema; 
   XmlReaderSettings settings; 
   mwlSchema = MWLCFindCommand.IODSchema; 
   settings = new XmlReaderSettings(); 
   settings.ValidationType = ValidationType.Schema; 
   settings.ValidationEventHandler += new ValidationEventHandler(schemaValidationHandler); 
   using (XmlReader reader = XmlTextReader.Create(iodPath, settings)) 
      while (reader.Read()); 
private static void schemaValidationHandler(object sender, ValidationEventArgs args)  
   throw args.Exception; 

  1. Use this new file for the Leadtools.Dicom.Scp.Command.MWLCFindCommand. Use the following code in the ModalityWorklistAddIn add-in:

MWLCFindCommand command = new MWLCFindCommand(clientSession, requestDS, GetDataAccessAgent()); 
AutoResetEvent resetEvent = new AutoResetEvent(false); 
command.MWLConfiguration.ModalityWorklistIODPath = _iodPath; 

The following are notes and descriptions of the attributes in the MWL IOD file:

The following is an explanation of the <element> and <sequence> XML tags:

<element  tag="" tagName="" vr="" minVM="" maxVM="" vmDivider="" returnType="" matchingType="" returning="" tableName="" matchingEntity="" columnsName="" /> 
<sequence tag="" tagName="" vr="SQ" minVM="" maxVM="" vmDivider="" returnType="" returning="" tableName=""> 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document