PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/DICOM/DicomUID.cs

https://github.com/petnet/fo-dicom
C# | 187 lines | 153 code | 31 blank | 3 comment | 52 complexity | c17c611b51f1fdf0d17e1c0cc15d9ecb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Concurrent;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Dicom {
  7. public enum DicomUidType {
  8. TransferSyntax,
  9. SOPClass,
  10. MetaSOPClass,
  11. ServiceClass,
  12. SOPInstance,
  13. ApplicationContextName,
  14. ApplicationHostingModel,
  15. CodingScheme,
  16. FrameOfReference,
  17. LDAP,
  18. ContextGroupName,
  19. Unknown
  20. }
  21. public enum DicomStorageCategory {
  22. None,
  23. Image,
  24. PresentationState,
  25. StructuredReport,
  26. Waveform,
  27. Document,
  28. Raw,
  29. Other
  30. }
  31. public sealed partial class DicomUID : DicomParseable {
  32. private string _uid;
  33. private string _name;
  34. private DicomUidType _type;
  35. private bool _retired;
  36. public DicomUID(string uid, string name, DicomUidType type, bool retired=false) {
  37. _uid = uid;
  38. _name = name;
  39. _type = type;
  40. _retired = retired;
  41. }
  42. public string UID {
  43. get {
  44. return _uid;
  45. }
  46. }
  47. public string Name {
  48. get {
  49. return _name;
  50. }
  51. }
  52. public DicomUidType Type {
  53. get {
  54. return _type;
  55. }
  56. }
  57. public bool IsRetired {
  58. get {
  59. return _retired;
  60. }
  61. }
  62. public static bool IsValid(string uid) {
  63. if (String.IsNullOrEmpty(uid))
  64. return false;
  65. // only checks that the UID contains valid characters
  66. foreach (char c in uid) {
  67. if (c != '.' && !Char.IsDigit(c))
  68. return false;
  69. }
  70. return true;
  71. }
  72. public static DicomUID Parse(string s) {
  73. string u = s.TrimEnd(' ', '\0');
  74. DicomUID uid = null;
  75. if (_uids.TryGetValue(u, out uid))
  76. return uid;
  77. //if (!IsValid(u))
  78. // throw new DicomDataException("Invalid characters in UID string ['" + u + "']");
  79. return new DicomUID(u, "Unknown", DicomUidType.Unknown);
  80. }
  81. private static IDictionary<string, DicomUID> _uids;
  82. static DicomUID() {
  83. _uids = new ConcurrentDictionary<string, DicomUID>();
  84. LoadInternalUIDs();
  85. }
  86. public static IEnumerable<DicomUID> Enumerate() {
  87. return _uids.Values;
  88. }
  89. public bool IsImageStorage {
  90. get {
  91. return StorageCategory == DicomStorageCategory.Image;
  92. }
  93. }
  94. public DicomStorageCategory StorageCategory {
  95. get {
  96. if (Type != DicomUidType.SOPClass || !Name.Contains("Storage"))
  97. return DicomStorageCategory.None;
  98. if (Name.Contains("Image Storage"))
  99. return DicomStorageCategory.Image;
  100. if (this == DicomUID.BlendingSoftcopyPresentationStateStorageSOPClass ||
  101. this == DicomUID.ColorSoftcopyPresentationStateStorageSOPClass ||
  102. this == DicomUID.GrayscaleSoftcopyPresentationStateStorageSOPClass ||
  103. this == DicomUID.PseudoColorSoftcopyPresentationStateStorageSOPClass)
  104. return DicomStorageCategory.PresentationState;
  105. if (this == DicomUID.AudioSRStorageTrialRETIRED ||
  106. this == DicomUID.BasicTextSRStorage ||
  107. this == DicomUID.ChestCADSRStorage ||
  108. this == DicomUID.ComprehensiveSRStorage ||
  109. this == DicomUID.ComprehensiveSRStorageTrialRETIRED ||
  110. this == DicomUID.DetailSRStorageTrialRETIRED ||
  111. this == DicomUID.EnhancedSRStorage ||
  112. this == DicomUID.MammographyCADSRStorage ||
  113. this == DicomUID.TextSRStorageTrialRETIRED ||
  114. this == DicomUID.XRayRadiationDoseSRStorage)
  115. return DicomStorageCategory.StructuredReport;
  116. if (this == DicomUID.AmbulatoryECGWaveformStorage ||
  117. this == DicomUID.BasicVoiceAudioWaveformStorage ||
  118. this == DicomUID.CardiacElectrophysiologyWaveformStorage ||
  119. this == DicomUID.GeneralECGWaveformStorage ||
  120. this == DicomUID.HemodynamicWaveformStorage ||
  121. this == DicomUID.TwelveLeadECGWaveformStorage ||
  122. this == DicomUID.WaveformStorageTrialRETIRED)
  123. return DicomStorageCategory.Waveform;
  124. if (this == DicomUID.EncapsulatedCDAStorage ||
  125. this == DicomUID.EncapsulatedPDFStorage)
  126. return DicomStorageCategory.Document;
  127. if (this == DicomUID.RawDataStorage)
  128. return DicomStorageCategory.Raw;
  129. return DicomStorageCategory.Other;
  130. }
  131. }
  132. public static bool operator ==(DicomUID a, DicomUID b) {
  133. if (((object)a == null) && ((object)b == null))
  134. return true;
  135. if (((object)a == null) || ((object)b == null))
  136. return false;
  137. return a.UID == b.UID;
  138. }
  139. public static bool operator !=(DicomUID a, DicomUID b) {
  140. return !(a == b);
  141. }
  142. public override bool Equals(object obj) {
  143. if (ReferenceEquals(this, obj))
  144. return true;
  145. if (!(obj is DicomUID))
  146. return false;
  147. return (obj as DicomUID).UID == UID;
  148. }
  149. public override int GetHashCode() {
  150. return UID.GetHashCode();
  151. }
  152. public override string ToString() {
  153. return UID;
  154. }
  155. }
  156. }