fo-dicom /DICOM/Generators/DicomUIDGenerator.cs

Language C# Lines 119
MD5 Hash 8c5f2e534d36ece39fcda30f7742d95e
Repository https://github.com/petnet/fo-dicom.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace Dicom.Generators {
	public class DicomUIDGenerator {
		public static string Process(string file) {
			StringBuilder list = new StringBuilder();
			StringBuilder uids = new StringBuilder();

			XDocument doc = XDocument.Load(file);
			XElement xdict = doc.Element("dictionary");
			if (xdict == null)
				throw new DicomDataException("Expected <dictionary> root node in DICOM dictionary.");

			foreach (XElement xuid in xdict.Elements("uid")) {
				string name = xuid.Value;

				if (xuid.Attribute("uid") == null)
					continue;
				string uid = xuid.Attribute("uid").Value;

				if (xuid.Attribute("keyword") == null)
					continue;
				string keyword = xuid.Attribute("keyword").Value;

				bool retired = false;
				XAttribute xretired = xuid.Attribute("retired");
				if (xretired != null && !String.IsNullOrEmpty(xretired.Value) && Boolean.Parse(xretired.Value))
					retired = true;

				if (retired)
					keyword += "RETIRED";

				if (xuid.Attribute("type") == null)
					continue;
				string type = xuid.Attribute("type").Value;

				DicomUidType uidType = DicomUidType.Unknown;
				switch (type) {
				case "Transfer":
				case "Transfer Syntax":
					uidType = DicomUidType.TransferSyntax;
					break;
				case "SOP Class":
				case "Query/Retrieve":
					uidType = DicomUidType.SOPClass;
					break;
				case "Meta SOP Class":
					uidType = DicomUidType.MetaSOPClass;
					break;
				case "Service Class":
					uidType = DicomUidType.ServiceClass;
					break;
				case "Well-known frame of reference":
				case "Synchronization Frame of Reference":
					uidType = DicomUidType.FrameOfReference;
					break;
				case "Well-known SOP Instance":
				case "Well-known Printer SOP Instance":
				case "Well-known Print Queue SOP Instance":
					uidType = DicomUidType.SOPInstance;
					break;
				case "Coding Scheme":
				case "DICOM UIDs as a Coding Scheme":
					uidType = DicomUidType.CodingScheme;
					break;
				case "Application Context Name":
					uidType = DicomUidType.ApplicationContextName;
					break;
				case "LDAP":
				case "LDAP OID":
					uidType = DicomUidType.LDAP;
					break;
				case "Context Group Name":
					uidType = DicomUidType.ContextGroupName;
					break;
				case "Application Hosting Model":
					uidType = DicomUidType.ApplicationHostingModel;
					break;
				case "":
					uidType = DicomUidType.Unknown;
					break;
				default:
					throw new DicomDataException("Unkown UID type: {0}", type);
				}

				list.AppendFormat("\t\t\t_uids.Add(DicomUID.{0}.UID, DicomUID.{0});", keyword).AppendLine();

				uids.AppendLine();
				uids.AppendFormat("\t\t/// <summary>{0}: {1}</summary>", type, name).AppendLine();
				uids.AppendFormat("\t\tpublic readonly static DicomUID {0} = new DicomUID(\"{1}\", \"{2}\", DicomUidType.{3}, {4});", keyword, uid, name, uidType, retired ? "true" : "false").AppendLine();
			}

			string code = @"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dicom {
	public partial class DicomUID {
		private static void LoadInternalUIDs() {
";

			code += list.ToString();
			code += "		}";
			code += uids.ToString();

			code += @"	}
}";
			return code;
		}
	}
}
Back to Top