Last active
August 29, 2015 14:03
-
-
Save Romiko/9b55815eafcf5dcb7b7f to your computer and use it in GitHub Desktop.
DICOM Query Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using DicomObjects; | |
using DicomObjects.Enums; | |
namespace Dicom | |
{ | |
public class DicomQueryManager : IDicomQueryManager | |
{ | |
public string CurrentServer { get; set; } | |
private readonly string workstation; | |
public IServers Servers { get; set; } | |
public bool Found { get; private set; } | |
public int Port { get; private set; } | |
public DicomQuery Query { get; set; } | |
private readonly DicomDataSet dataSet; | |
public DicomDataSetCollection Data { get; set; } | |
public string AccessionNumber { get; private set; } | |
public int ImageCount{ get; set; } | |
readonly Tuple<int, int> studyLevelImageCount = new Tuple<int, int>(0x0020, 0x1208); | |
public DicomQueryManager(string currentServer, IServers servers, string workstation, string port, string accessionNumber) | |
{ | |
AccessionNumber = accessionNumber; | |
CurrentServer = currentServer; | |
this.workstation = workstation; | |
Servers = servers; | |
int thePort; | |
if (!int.TryParse(port, out thePort)) | |
Port = 5000; | |
Port = thePort; | |
Query = GetDicomQuery(); | |
dataSet = Query.QueryDataSet(); | |
dataSet.Add(Keyword.AccessionNumber, accessionNumber); | |
} | |
public IDicomQueryManager BuildPreferred() | |
{ | |
Query.Level = QueryLevel.IMAGE; | |
return this; | |
} | |
public IDicomQueryManager BuildMaster() | |
{ | |
Query.Level = QueryLevel.STUDY; | |
return this; | |
} | |
public void AssignServer(string server) | |
{ | |
Query.Node = server; | |
Query.CalledAE = server; | |
CurrentServer = server; | |
} | |
private DicomQuery GetDicomQuery() | |
{ | |
var query = new DicomQuery | |
{ | |
Node = CurrentServer, | |
Port = Port, | |
CallingAE = workstation, | |
CalledAE = CurrentServer, | |
Level = QueryLevel.IMAGE, | |
Root = QueryRoot.Study, | |
Destination = workstation | |
}; | |
return query; | |
} | |
public bool Find() | |
{ | |
Data = Query.Find(dataSet); | |
if(Query.Level == QueryLevel.IMAGE) | |
ImageCount = Data.ToList().Count; | |
else if (Query.Level == QueryLevel.STUDY) | |
{ | |
if (Data.Count > 0) | |
{ | |
int imageCount; | |
int.TryParse(Data[0][studyLevelImageCount.Item1, studyLevelImageCount.Item2].ToString(), out imageCount); | |
ImageCount = imageCount; | |
} | |
else | |
{ | |
ImageCount = 0; | |
} | |
} | |
else | |
{ | |
throw new NotSupportedException("Only QueryLevel at Image and Study level is supported."); | |
} | |
Found = Data.Count > 0; | |
return Found; | |
} | |
public void Move() | |
{ | |
Query.Move(dataSet); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DicomObjects; | |
namespace Dicom | |
{ | |
public interface IDicomQueryManager | |
{ | |
string AccessionNumber { get; } | |
string CurrentServer { get; set; } | |
IServers Servers { get; set; } | |
int Port { get; } | |
void AssignServer(string server); | |
bool Find(); | |
bool Found { get; } | |
void Move(); | |
DicomQuery Query { get; } | |
DicomDataSetCollection Data { get; set; } | |
IDicomQueryManager BuildPreferred(); | |
IDicomQueryManager BuildMaster(); | |
int ImageCount { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
namespace Dicom | |
{ | |
public interface IServers | |
{ | |
string DefaultPreferred { get; } | |
string DefaultMaster { get; } | |
List<string> OtherPreferredModalityServers { get; } | |
List<string> OtherMasterModalityServers { get; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var preferredQuery = | |
new DicomQueryManager(servers.DefaultPreferred, servers, workstation, port, o.AccessionNumber) | |
.BuildPreferred(); | |
var masterQuery = | |
new DicomQueryManager(servers.DefaultMaster, servers, workstation, port, o.AccessionNumber) | |
.BuildMaster(); | |
if (preferredQuery.Found) | |
{ | |
//Do SOmething | |
var imageCount = preferredQuery.ImageCount; | |
preferredQuery.Move(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment