Skip to content

Commit

Permalink
it works, but still have tiny issues
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Dec 28, 2023
1 parent 7ee4e05 commit d537d1f
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 118 deletions.
2 changes: 1 addition & 1 deletion DicomGrep/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</Grid.ColumnDefinitions>
<ComboBox IsEditable="True" ItemsSource="{Binding DicomTagHistory}" Text="{Binding Tag}">
</ComboBox>
<Button Content="..." MinWidth="20" Grid.Column="1" Command="{Binding DicomTagLookupCommand}"></Button>
<Button Content="..." MinWidth="20" Grid.Column="1" Command="{Binding DicomDictionaryLookupCommand}"></Button>
</Grid>
<Label Content="Dicom Tag Value"></Label>
<ComboBox IsEditable="True" ItemsSource="{Binding SearchTextHistory}" Text="{Binding SearchText}">
Expand Down
31 changes: 31 additions & 0 deletions DicomGrep/Services/DicomDictionaryLookupService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using DicomGrep.ViewModels;
using DicomGrep.Views;
using FellowOakDicom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DicomGrep.Services
{
public class DicomDictionaryLookupService
{
public bool SelectDicomDictionaryEntry(ref string dicomTagString)
{
DicomDictionaryLookupView window = new DicomDictionaryLookupView();
DicomDictionaryLookupViewModel vm = window.DataContext as DicomDictionaryLookupViewModel;
if (!string.IsNullOrWhiteSpace(dicomTagString))
{
//build pass
//vm.SelectedEntry = DicomTag.Parse(dicomTagString);
}
if (window.ShowDialog() == true)
{
dicomTagString = vm.SelectedEntry?.ToString();
return true;
}
return false;
}
}
}
30 changes: 0 additions & 30 deletions DicomGrep/Services/DicomTagLookupService.cs

This file was deleted.

66 changes: 66 additions & 0 deletions DicomGrep/ViewModels/DicomDictionaryLookupViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using FellowOakDicom;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DicomGrep.ViewModels
{
public class DicomDictionaryLookupViewModel : ViewModelBase
{
public ObservableCollection<DicomDictionaryEntry> DicomDictionaryEntries { get; private set; }

private DicomDictionaryEntry _selectedEntry;
public DicomDictionaryEntry SelectedEntry
{
get { return _selectedEntry; }
set { SetProperty(ref _selectedEntry, value); }
}

public DicomDictionaryLookupViewModel() : base()
{
if (DicomDictionaryEntries == null || DicomDictionaryEntries.Count == 0)
{
DicomDictionaryEntries = new ObservableCollection<DicomDictionaryEntry>(
GetAllDicomTagDefs().OrderBy(entry=>entry.Tag.Group).ThenBy(entry=>entry.Tag.Element)
.Concat(GetAllPrivateTagDefs()).OrderBy(entry=>entry.Tag.PrivateCreator).ThenBy(entry => entry.Tag.Group).ThenBy(entry => entry.Tag.Element)
);
}
}

/// <summary>
/// Get all public DICOM tag definitions. Private tags are not included.
/// </summary>
/// <returns></returns>
private IEnumerable<DicomDictionaryEntry> GetAllDicomTagDefs()
{
return DicomDictionary.Default;
}

/// <summary>
/// Get all private DICOM tag definitions.
/// </summary>
/// <returns></returns>
private IEnumerable<DicomDictionaryEntry> GetAllPrivateTagDefs()
{
ConcurrentDictionary<string, DicomDictionary> _private = typeof(DicomDictionary)
.GetField("_private", BindingFlags.NonPublic | BindingFlags.Instance)?
.GetValue(DicomDictionary.Default)
as ConcurrentDictionary<string, DicomDictionary>;

// each vendor (private tag creator) can own multiple entries (tags)
IEnumerable<DicomDictionary> vendorsDictionary = _private.Select(item => item.Value);
foreach (var dictionary in vendorsDictionary)
{
foreach( var entry in dictionary)
{
yield return entry;
}
}
}
}
}
62 changes: 0 additions & 62 deletions DicomGrep/ViewModels/DicomTagLookupViewModel.cs

This file was deleted.

12 changes: 6 additions & 6 deletions DicomGrep/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MainViewModel : ViewModelBase
private readonly ConfigurationService configurationService = new ConfigurationService();
private readonly FileOperationService fileOperationService = new FileOperationService();
private readonly SopClassLookupService sopClassLookupService = new SopClassLookupService();
private readonly DicomTagLookupService dicomTagLookupService = new DicomTagLookupService();
private readonly DicomDictionaryLookupService dicomDictionaryLookupService = new DicomDictionaryLookupService();
private readonly DialogService dialogService = new DialogService();
private readonly ExportService exportService = new ExportService();
private readonly TagValueDetailService tagValueDetailService = new TagValueDetailService();
Expand Down Expand Up @@ -226,12 +226,12 @@ public ICommand SopClassLookupCommand
}
}

private ICommand _dicomtagLookupCommand;
public ICommand DicomTagLookupCommand
private ICommand _dicomDictionaryLookupCommand;
public ICommand DicomDictionaryLookupCommand
{
get
{
return _dicomtagLookupCommand ?? (_dicomtagLookupCommand = new RelayCommand<object>(_=> DoDicomTagLookup()));
return _dicomDictionaryLookupCommand ?? (_dicomDictionaryLookupCommand = new RelayCommand<object>(_=> DoDicomDictionaryLookup()));
}
}

Expand Down Expand Up @@ -447,10 +447,10 @@ private void DoSopClassLookup()
}
}

private void DoDicomTagLookup()
private void DoDicomDictionaryLookup()
{
string tag = Tag;
if (dicomTagLookupService.SelectDicomTag(ref tag))
if (dicomDictionaryLookupService.SelectDicomDictionaryEntry(ref tag))
{
Tag = tag;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Window x:Class="DicomGrep.Views.DicomTagLookupView"
<Window x:Class="DicomGrep.Views.DicomDictionaryLookupView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DicomGrep.Views"
xmlns:vm="clr-namespace:DicomGrep.ViewModels"
mc:Ignorable="d"
Title="Looking for DICOM Tag" Height="450" Width="800">
Title="Looking for DICOM Tag Dictionary" Height="450" Width="800">
<Window.DataContext>
<vm:DicomTagLookupViewModel/>
<vm:DicomDictionaryLookupViewModel/>
</Window.DataContext>
<Window.Resources>
<local:TagValueConverter x:Key="TagValueConverter"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="20"/>
Expand All @@ -26,21 +29,22 @@
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="Selected:" Grid.Row="0" Grid.Column="0"/>
<TextBox Name="selected" Text="{Binding SelectedTag, Mode=OneWay}" Grid.Row="0" Grid.Column="1"/>
<TextBox Name="selected" Text="{Binding Path=SelectedEntry, Mode=OneWay, Converter={StaticResource TagValueConverter}, ConverterParameter='X'}" Grid.Row="0" Grid.Column="1"/>
<Label Content="Filter:" Grid.Row="1" Grid.Column="0"/>
<TextBox Name="filter" TextChanged="Filter_TextChanged" Grid.Row="1" Grid.Column="1"/>
<Button Name="pick" Content="Pick" Grid.Column="2" Grid.RowSpan="2" IsDefault="True" Click="pick_Click" Margin="8"/>
</Grid>
<DataGrid Name="dataGridUid" ItemsSource="{Binding DicomTags, Mode=OneWay}" AutoGenerateColumns="False"
SelectedItem="{Binding SelectedTag, Mode=OneWayToSource}" SelectionMode="Single"
<DataGrid Name="dataGridUid" ItemsSource="{Binding DicomDictionaryEntries, Mode=OneWay}" AutoGenerateColumns="False"
SelectedItem="{Binding SelectedEntry, Mode=OneWayToSource}" SelectionMode="Single"
Grid.Row="1" MouseDoubleClick="dataGridUid_MouseDoubleClick">
<DataGrid.Columns>
<DataGridTextColumn Header="Tag" Binding="{Binding .,Mode=OneWay}"/>
<DataGridTextColumn Header="Name" Binding="{Binding DictionaryEntry.Name,Mode=OneWay}"/>
<DataGridTextColumn Header="Group" Binding="{Binding Group,Mode=OneWay}"/>
<DataGridTextColumn Header="Element" Binding="{Binding Element,Mode=OneWay}"/>
<DataGridCheckBoxColumn Header="IsPrivate" Binding="{Binding IsPrivate,Mode=OneWay}"/>
<DataGridTextColumn Header="Private Creator" Binding="{Binding PrivateCreator, Mode=OneWay}"/>
<DataGridTextColumn Header="Tag" Binding="{Binding Tag,Mode=OneWay, Converter={StaticResource TagValueConverter}, ConverterParameter='C'}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Name,Mode=OneWay}"/>
<DataGridTextColumn Header="Group" Binding="{Binding Tag.Group,Mode=OneWay}"/>
<DataGridTextColumn Header="Element" Binding="{Binding Tag.Element,Mode=OneWay}"/>
<DataGridCheckBoxColumn Header="IsRetired" Binding="{Binding IsRetired,Mode=OneWay}"/>
<DataGridCheckBoxColumn Header="IsPrivate" Binding="{Binding Tag.IsPrivate,Mode=OneWay}"/>
<DataGridTextColumn Header="Private Creator" Binding="{Binding Tag.PrivateCreator, Mode=OneWay}"/>
</DataGrid.Columns>
</DataGrid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
namespace DicomGrep.Views
{
/// <summary>
/// Interaction logic for DicomTagLookupView.xaml
/// Interaction logic for DicomDictionaryLookupView.xaml
/// </summary>
public partial class DicomTagLookupView : Window
public partial class DicomDictionaryLookupView : Window
{
public DicomTagLookupView()
public DicomDictionaryLookupView()
{
InitializeComponent();
}
Expand All @@ -36,10 +36,10 @@ private void Filter_TextChanged(object sender, TextChangedEventArgs e)
{
cv.Filter = obj =>
{
DicomTag tag = obj as DicomTag;
return tag.ToString().Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase) ||
tag.DictionaryEntry.Keyword.Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase) ||
tag.DictionaryEntry.Name.Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase);
DicomDictionaryEntry dictionary = obj as DicomDictionaryEntry;
return dictionary.ToString().Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase) ||
dictionary.Keyword.Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase) ||
dictionary.Name.Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase);

};
}
Expand Down
49 changes: 49 additions & 0 deletions DicomGrep/Views/TagValueConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using FellowOakDicom;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace DicomGrep.Views
{
[ValueConversion(typeof(DicomTag), typeof(string))]
public class TagValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is DicomTag dicomTag)
{
string para = "X";
if (parameter is string _p && !string.IsNullOrWhiteSpace(_p))
{
para = (string)parameter;
}

if (para == "C")
{
if (dicomTag.PrivateCreator == null)
{
return $"({dicomTag.Group:x4},{dicomTag.Element:x4})";
}
return $"({dicomTag.Group:x4},xx{dicomTag.Element & 0xFF:x2})";
}
else
{
return dicomTag.ToString(para, null);
}
}
else
{
return value;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

0 comments on commit d537d1f

Please sign in to comment.