Skip to content

Commit

Permalink
Implemented expansion of patient monitor view
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Scholtyssek committed Feb 15, 2020
1 parent 438e11c commit fd308a4
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 54 deletions.
4 changes: 2 additions & 2 deletions CentralMonitorGUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
6 changes: 2 additions & 4 deletions CentralMonitorGUI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace CentralMonitorGUI.ViewModels
{
public class MainViewModel : ViewModelBase
{
private readonly TimeSpan timeToShow = TimeSpan.FromSeconds(10);
private readonly UpdateTrigger updateTrigger;
private readonly FileManager fileManager;
private readonly DataExplorerWindowViewModelFactory dataExplorerWindowViewModelFactory;
Expand Down Expand Up @@ -42,8 +41,7 @@ private void Network_NewMonitorDiscovered(object sender, PatientMonitor newMonit
{
var viewModel = new PatientMonitorViewModel(
newMonitor,
updateTrigger,
timeToShow,
updateTrigger,
dataExplorerWindowViewModelFactory);
Monitors.Add(viewModel);
}
Expand All @@ -54,7 +52,7 @@ private void Network_MonitorDisappeared(object sender, PatientMonitor disappeare
monitor => monitor.Monitor.Equals(disappearedMonitor));
if(viewModelToBeRemoved == null)
return;
Application.Current.Dispatcher.BeginInvoke(new Action(() => Monitors.Remove(viewModelToBeRemoved)));
Application.Current.Dispatcher?.BeginInvoke(new Action(() => Monitors.Remove(viewModelToBeRemoved)));
}

public ObservableCollection<PatientMonitorViewModel> Monitors { get; } = new ObservableCollection<PatientMonitorViewModel>();
Expand Down
45 changes: 34 additions & 11 deletions CentralMonitorGUI/ViewModels/PatientMonitorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Media;
using System.Windows.Threading;
using CentralMonitorGUI.Views;
using Commons.Extensions;
using NetworkCommunication;
using NetworkCommunication.DataStorage;
using NetworkCommunication.Objects;
Expand All @@ -21,7 +22,6 @@ public class PatientMonitorViewModel : ViewModelBase
private bool spO2Enabled = true;
private EcgLead selectedEcgLead = EcgLead.II;
private readonly UpdateTrigger updateTrigger;
private readonly TimeSpan timeToShow;
private readonly DataExplorerWindowViewModelFactory dataExplorerWindowViewModelFactory;
private readonly Dictionary<SensorType, WaveformViewModel> waveformViewModels = new Dictionary<SensorType, WaveformViewModel>();
private VitalSignViewModel vitalSignValues;
Expand All @@ -39,20 +39,19 @@ public class PatientMonitorViewModel : ViewModelBase

public PatientMonitorViewModel(
PatientMonitor monitor,
UpdateTrigger updateTrigger,
TimeSpan timeToShow,
UpdateTrigger updateTrigger,
DataExplorerWindowViewModelFactory dataExplorerWindowViewModelFactory)
{
Monitor = monitor;
this.updateTrigger = updateTrigger;
this.timeToShow = timeToShow;
this.dataExplorerWindowViewModelFactory = dataExplorerWindowViewModelFactory;

TimeToShow = TimeSpan.FromSeconds(10);
VitalSignValues = new VitalSignViewModel(monitor);
OpenDataExplorerWindowCommand = new RelayCommand(OpenDataExplorerWindow);
EcgWaveform = new WaveformViewModel(SensorType.EcgLeadII, new WaveformBuffer(SensorType.EcgLeadII, 0), updateTrigger, timeToShow);
RespirationWaveform = new WaveformViewModel(SensorType.Respiration, new WaveformBuffer(SensorType.Respiration, 0), updateTrigger, timeToShow);
SpO2Waveform = new WaveformViewModel(SensorType.SpO2, new WaveformBuffer(SensorType.SpO2, 0), updateTrigger, timeToShow);
EcgWaveform = new WaveformViewModel(SensorType.EcgLeadII, new WaveformBuffer(SensorType.EcgLeadII, 0), updateTrigger, TimeToShow);
RespirationWaveform = new WaveformViewModel(SensorType.Respiration, new WaveformBuffer(SensorType.Respiration, 0), updateTrigger, TimeToShow);
SpO2Waveform = new WaveformViewModel(SensorType.SpO2, new WaveformBuffer(SensorType.SpO2, 0), updateTrigger, TimeToShow);
alarmTimeoutTimer.Elapsed += AlarmTimeoutTimer_Elapsed;
monitor.NewWaveformSensorConnected += Monitor_NewWaveformSensorConnected;
monitor.NewAlarm += Monitor_NewAlarm;
Expand All @@ -64,10 +63,12 @@ public PatientMonitorViewModel(
sensorType,
waveformSource,
updateTrigger,
timeToShow);
TimeToShow);
waveformViewModels.Add(sensorType, waveformViewModel);
SetWaveformViewModel(sensorType, waveformViewModel);
}

ExpandCommand = new RelayCommand<bool>(newState => IsExpanded = newState);
}

private void AlarmTimeoutTimer_Elapsed(object sender, ElapsedEventArgs e)
Expand Down Expand Up @@ -97,7 +98,7 @@ private void Monitor_NewWaveformSensorConnected(object sender, SensorType sensor
sensorType,
waveformSource,
updateTrigger,
timeToShow);
TimeToShow);
waveformViewModels[sensorType] = waveformViewModel;
SetWaveformViewModel(sensorType, waveformViewModel);
}
Expand Down Expand Up @@ -126,7 +127,16 @@ private void SetWaveformViewModel(SensorType sensorType, WaveformViewModel wavef
}

public PatientMonitor Monitor { get; }

private TimeSpan timeToShow;
public TimeSpan TimeToShow
{
get => timeToShow;
private set
{
timeToShow = value;
waveformViewModels.Values.ForEach(waveFormViewModel => waveFormViewModel.TimeToShow = timeToShow);
}
}

public Alarm ActiveAlarm
{
Expand Down Expand Up @@ -273,7 +283,7 @@ public EcgLead SelectedEcgLead
ecgSensorType,
new WaveformBuffer(ecgSensorType, 0),
updateTrigger,
timeToShow);
TimeToShow);
}
OnPropertyChanged();
}
Expand All @@ -288,6 +298,19 @@ public Brush InfoBarBackground
OnPropertyChanged();
}
}
private bool isExpanded;
public bool IsExpanded
{
get => isExpanded;
set
{
isExpanded = value;
TimeToShow = isExpanded ? TimeSpan.FromSeconds(30) : TimeSpan.FromSeconds(10);
OnPropertyChanged();
}
}

public ICommand ExpandCommand { get; }

private void OpenDataExplorerWindow()
{
Expand Down
21 changes: 15 additions & 6 deletions CentralMonitorGUI/ViewModels/WaveformViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
using NetworkCommunication.DataStorage;
using NetworkCommunication.Objects;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

namespace CentralMonitorGUI.ViewModels
{
public class WaveformViewModel : ViewModelBase, IDisposable
{
private readonly IWaveformSource waveformSource;
private readonly TimeSpan timeToShow;
private readonly UpdateTrigger updateTrigger;
private readonly int sampleCountPerUpdate;
private readonly int sampleCount;
private int sampleIdx;

public WaveformViewModel(
Expand All @@ -25,12 +24,10 @@ public WaveformViewModel(
TimeSpan timeToShow)
{
this.waveformSource = waveformSource;
this.timeToShow = timeToShow;
this.updateTrigger = updateTrigger;
SensorType = sensorType;
TimeToShow = timeToShow;
sampleCountPerUpdate = Informations.SensorBatchSizes[sensorType];
var samplesPerSecond = Informations.SensorBatchesPerSecond * Informations.SensorBatchSizes[sensorType];
sampleCount = (int) (timeToShow.TotalSeconds * samplesPerSecond);
SetupPlotModel();
updateTrigger.Trig += UpdateTrigger_Trig;
}
Expand All @@ -56,7 +53,16 @@ private static Color MapSensorTypeToBrush(SensorType sensorType)

private void SetupPlotModel()
{
PlotModel = new PlotModel();
PlotModel = new PlotModel
{
Axes = { new LinearAxis
{
Position = AxisPosition.Bottom,
IsAxisVisible = false,
IsZoomEnabled = false,
IsPanEnabled = false
}}
};

var sensorColor = MapSensorTypeToBrush(SensorType);
PlotModel.Series.Add(new LineSeries
Expand All @@ -72,6 +78,8 @@ private void UpdateTrigger_Trig(object sender, EventArgs e)
{
if(isUpdating)
return;
var samplesPerSecond = Informations.SensorBatchesPerSecond * Informations.SensorBatchSizes[SensorType];
var sampleCount = (int) (TimeToShow.TotalSeconds * samplesPerSecond);
lock (PlotModel.SyncRoot)
{
isUpdating = true;
Expand All @@ -92,6 +100,7 @@ private void UpdateTrigger_Trig(object sender, EventArgs e)
}

public SensorType SensorType { get; }
public TimeSpan TimeToShow { get; set; }
public PlotModel PlotModel { get; private set; }

public void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion CentralMonitorGUI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ItemsControl Grid.Row="1" ItemsSource="{Binding Monitors}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:PatientMonitorView ViewModel="{Binding}" Height="180"/>
<views:PatientMonitorView ViewModel="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down
Loading

0 comments on commit fd308a4

Please sign in to comment.