98 lines
3.7 KiB
C#
98 lines
3.7 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using CommunityToolkit.Mvvm.Messaging.Messages;
|
|
using Livia.Models.Data;
|
|
using Livia.Utility;
|
|
|
|
namespace Livia.ViewModels;
|
|
|
|
public class SearchQueryMessage(SearchQueryCondition value) : ValueChangedMessage<SearchQueryCondition>(value);
|
|
|
|
public class SearchQueryInputControlViewModel : ObservableRecipient, IRecipient<LogoutMessage>
|
|
{
|
|
public string? PatientName { get => _patientName; set => SetProperty(ref _patientName, value); }
|
|
public string? PatientId { get => _patientId; set => SetProperty(ref _patientId, value); }
|
|
public string? PatientSex { get => _patientSex; set => SetProperty(ref _patientSex, value); }
|
|
public string? PatientAgeStart { get => _patientAgeStart; set => SetProperty(ref _patientAgeStart, value); }
|
|
public string? PatientAgeEnd { get => _patientAgeEnd; set => SetProperty(ref _patientAgeEnd, value); }
|
|
public DateTime? ImportTimeStart { get => _importTimeStart; set => SetProperty(ref _importTimeStart, value); }
|
|
public DateTime? ImportTimeEnd { get => _importTimeEnd; set => SetProperty(ref _importTimeEnd, value); }
|
|
public DateTime? StudyDateStart { get => _studyDateStart; set => SetProperty(ref _studyDateStart, value); }
|
|
public DateTime? StudyDateEnd { get => _studyDateEnd; set => SetProperty(ref _studyDateEnd, value); }
|
|
|
|
|
|
private string? _patientName = string.Empty;
|
|
private string? _patientId = string.Empty;
|
|
private string? _patientSex = string.Empty;
|
|
private string? _patientAgeStart;
|
|
private string? _patientAgeEnd;
|
|
private DateTime? _importTimeStart;
|
|
private DateTime? _importTimeEnd;
|
|
private DateTime? _studyDateStart;
|
|
private DateTime? _studyDateEnd;
|
|
|
|
public SearchQueryInputControlViewModel()
|
|
{
|
|
WeakReferenceMessenger.Default.RegisterAll(this);
|
|
}
|
|
|
|
private SearchQueryCondition GenerateCondition()
|
|
{
|
|
return new SearchQueryCondition
|
|
{
|
|
PatientName = string.IsNullOrWhiteSpace(PatientName) ? null : PatientName.Trim(),
|
|
PatientId = string.IsNullOrWhiteSpace(PatientId) ? null : PatientId.Trim(),
|
|
PatientSex = string.IsNullOrWhiteSpace(PatientSex) ? null : PatientSex.Trim(),
|
|
PatientAge = AgeToList(PatientAgeStart, PatientAgeEnd),
|
|
ImportTime = DateTimeToList(ImportTimeStart, ImportTimeEnd),
|
|
StudyDate = DateTimeToList(StudyDateStart, StudyDateEnd)
|
|
};
|
|
}
|
|
private static List<int>? AgeToList(string? start, string? end)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(start) && string.IsNullOrWhiteSpace(end))
|
|
return null;
|
|
|
|
if (!int.TryParse(start ?? "0", out int startInt))
|
|
startInt = 0;
|
|
|
|
if (!int.TryParse(end ?? "999", out int endInt))
|
|
endInt = 999;
|
|
|
|
return new List<int> { startInt, endInt };
|
|
}
|
|
|
|
private static List<string>? DateTimeToList(DateTime? start, DateTime? end)
|
|
{
|
|
if (start == null && end == null)
|
|
return null;
|
|
|
|
start ??= DateTime.UnixEpoch;
|
|
end ??= new DateTime(3000, 1, 1);
|
|
|
|
return new List<string> { start.Value.ToString("yyyy-MM-dd"), end.Value.ToString("yyyy-MM-dd") };
|
|
}
|
|
|
|
public void Search()
|
|
{
|
|
WeakReferenceMessenger.Default.Send(new SearchQueryMessage(GenerateCondition()));
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
PatientName = null;
|
|
PatientId = null;
|
|
PatientSex = null;
|
|
PatientAgeStart = null;
|
|
PatientAgeEnd = null;
|
|
StudyDateStart = null;
|
|
StudyDateEnd = null;
|
|
ImportTimeStart = null;
|
|
ImportTimeEnd = null;
|
|
}
|
|
|
|
public void Receive(LogoutMessage message)
|
|
{
|
|
Clear();
|
|
}
|
|
} |