public static DElementListWrapper[] CreateQRElementList <TR>(XCollection <TR> qrList, DataSet dsQR) where TR : QueryResultItem, IDicomMappingItem { if (dsQR == null || qrList == null) { return(null); } List <DElementListWrapper> dcmResult = new List <DElementListWrapper>(); if (dsQR.Tables.Count > 0) { foreach (DataRow dr in dsQR.Tables[0].Rows) { DicomDataset dcmEleList = new DicomDataset(); int count = qrList.Count; for (int index = 0; index < count; index++) { IDicomMappingItem qr = qrList[index] as IDicomMappingItem; if (!qr.DPath.Enable) { continue; } List <string> tagList = qr.DPath.GetTagGE(0); ushort uGroup = DHelper.HexString2ushort(tagList[0]); ushort uElement = DHelper.HexString2ushort(tagList[1]); DicomTag tag = new DicomTag(uGroup, uElement); FillElement <TR>(dcmEleList, tag, qr.DPath.VR, ref index, 0, qrList, dr); } DElementListWrapper w = new DElementListWrapper(dcmEleList); w.GUIDs.Add(DicomMappingHelper.GetGUID(dr)); dcmResult.Add(w); } } return(dcmResult.ToArray()); }
private static void FillDataSet <TC>(Hashtable dr, ref int index, int depth, XCollection <TC> qcList, DicomDataset eleList) where TC : MappingItem, IDicomMappingItem { int count = qcList.Count; for (; index < count; index++) { TC qc = qcList[index] as TC; if (qc.Translating.Type == TranslatingType.FixValue) { continue; } if (qc.DPath.Type == DPathType.BeginItem) { continue; } if (qc.DPath.Type == DPathType.EndItem && depth > 0) { break; } if (!qc.DPath.Enable) { continue; } //int tag = qc.DPath.GetTag(depth); //DicomItem ele = eleList(tag); List <string> tagList = qc.DPath.GetTagGE(depth); if (tagList == null) { continue; } ushort uGroup = DHelper.HexString2ushort(tagList[0]); ushort uElement = DHelper.HexString2ushort(tagList[1]); DicomItem ele = eleList.Get <DicomItem>(new DicomTag(uGroup, uElement)); if (ele == null || ConvertDicomVRToDVR(ele.ValueRepresentation) != qc.DPath.VR) { if (qc.DPath.VR == DVR.SQ) { continue; } dr[qc.SourceField] = GetSQLString <TC>(qc, (ele == null) ? "" : eleList.Get <string>(new DicomTag(uGroup, uElement))); continue; } if (qc.DPath.VR == DVR.SQ) { int d = depth + 1; DicomDataset sqList = null; DicomSequence dicomSequence = (DicomSequence)ele; if (dicomSequence.Items.Count > 0) //support one sequence item only { sqList = dicomSequence.Items[0]; } index++; if (sqList == null) { sqList = new DicomDataset(); } FillDataSet <TC>(dr, ref index, d, qcList, sqList); break; } else { string value = eleList.Get <string>(new DicomTag(uGroup, uElement)); if (DHelper.IsDateTime(qc.DPath.VR)) { DVR realVR = qc.DPath.VR; // ------ merge TM to DT ------ if (uGroup == DicomTag.ScheduledProcedureStepStartDate.Group && uElement == DicomTag.ScheduledProcedureStepStartDate.Element) { string eleTM = eleList.Get <string>(DicomTag.ScheduledProcedureStepStartTime); if (eleTM != null) { string strTM = eleTM; string[] strTMList = strTM.Split('-'); string[] strDAList = value.Split('-'); if (strTMList.Length > 0 && strDAList.Length > 0) { if (strDAList.Length == 1 && strDAList[0].Length > 0) { if (strTMList.Length == 1 && strTMList[0].Length > 0) { realVR = DVR.DT; if (strTM.Length > 6) { strTM = strTM.Substring(0, 6); } value += strTM; } else if (strTMList.Length == 2) { realVR = DVR.DT; string beginTM = strTMList[0]; string endTM = strTMList[1]; if (beginTM.Length < 1) { beginTM = "000000"; } if (endTM.Length < 1) { endTM = "235959"; } if (beginTM.Length > 6) { beginTM = beginTM.Substring(0, 6); } if (endTM.Length > 6) { endTM = endTM.Substring(0, 6); } value = strDAList[0] + beginTM + "-" + strDAList[0] + endTM; } } else if (strDAList.Length == 2) { if (strTMList.Length == 1 && strTMList[0].Length > 0) { realVR = DVR.DT; if (strTM.Length > 6) { strTM = strTM.Substring(0, 6); } value = strDAList[0] + strTM + "-" + strDAList[1] + strTM; } else if (strTMList.Length == 2) { realVR = DVR.DT; string beginTM = strTMList[0]; string endTM = strTMList[1]; if (beginTM.Length < 1) { beginTM = "000000"; } if (endTM.Length < 1) { endTM = "235959"; } if (beginTM.Length > 6) { beginTM = beginTM.Substring(0, 6); } if (endTM.Length > 6) { endTM = endTM.Substring(0, 6); } value = strDAList[0] + beginTM + "-" + strDAList[1] + endTM; } } } } } // ---------------------------- if (qc.DPath.Range == DRangeType.None) { DDateTime2 singleddt = DDateTime2.FromDateTime(realVR, value); object singledt = (singleddt != null) ? singleddt.GetDateTime() : null; //value = (singledt != null) ? ((DateTime)singledt).ToString(GWDataDB.DateTimeFormat) : ""; value = GetGWDTStartString(singledt, realVR); dr[qc.SourceField] = GetSQLString <TC>(qc, value); continue; } TC qcStart = qc; if (qcStart.DPath.Range != DRangeType.Begin) { continue; } TC qcEnd = qcList[index + 1]; if (qcEnd == null || qcEnd.DPath.Range != DRangeType.End) { continue; } index++; object dtStart = null, dtEnd = null; DDateTime2 ddt = DDateTime2.FromDateTime(realVR, value); if (ddt != null) { switch (ddt.Type) { case DDateTimeType.SINGLE: { dtStart = dtEnd = ddt.GetDateTime(); break; } case DDateTimeType.START_ONLY: { dtStart = ddt.GetStartDateTime(); break; } case DDateTimeType.END_ONLY: { dtEnd = ddt.GetEndDateTime(); break; } case DDateTimeType.RANGE: { dtStart = ddt.GetStartDateTime(); dtEnd = ddt.GetEndDateTime(); break; } } } string strStart = "", strEnd = ""; strStart = GetGWDTStartString(dtStart, realVR); strEnd = GetGWDTEndString(dtEnd, realVR); dr[qcStart.SourceField] = strStart; dr[qcEnd.SourceField] = strEnd; } else if (qc.DPath.VR == DVR.PN) { value = PersonNameRule.Parse(value); dr[qc.SourceField] = GetSQLString <TC>(qc, value); } else { dr[qc.SourceField] = GetSQLString <TC>(qc, value); } break; } } }
private static void FillElement <TR>(DicomDataset ds, DicomTag tagIn, DVR vrIn, ref int index, int depth, XCollection <TR> qrList, DataRow dr) where TR : QueryResultItem, IDicomMappingItem { TR qr = qrList[index] as TR; if (!qr.DPath.Enable) { return; } switch (qr.DPath.VR) { case DVR.Unknown: return; case DVR.SQ: { index++; int count = qrList.Count; DicomDataset eleList = null; for (; index < count; index++) { qr = qrList[index] as TR; switch (qr.DPath.Type) { case DPathType.BeginItem: { eleList = new DicomDataset(); continue; } case DPathType.EndItem: { DicomSequence dicomSequence = new DicomSequence(tagIn); if (eleList != null) { dicomSequence.Items.Add(eleList); } TR qrNext = ((index + 1) < qrList.Count) ? qrList[index + 1] : null; if (qrNext == null || qrNext.DPath.Type != DPathType.BeginItem) { return; } continue; } default: { if (eleList == null) { continue; } if (!qr.DPath.Enable) { continue; } //int tag = qr.DPath.GetTag(depth + 1); List <string> tagList = qr.DPath.GetTagGE(depth + 1); ushort uGroup = DHelper.HexString2ushort(tagList[0]); ushort uElement = DHelper.HexString2ushort(tagList[1]); DicomTag tag = new DicomTag(uGroup, uElement); //DElement ele = new DElement(tag, qr.DPath.VR); FillElement <TR>(eleList, tag, qr.DPath.VR, ref index, depth + 1, qrList, dr); //eleList.Add(ele); break; } } } break; } default: { string value = null; object obj = dr[qr.TargetField]; if (obj != null) { value = obj.ToString(); } if (value == null) { value = ""; } if (DHelper.IsDateTime(qr.DPath.VR)) { try { if (value.Length > 0) { DateTime dt = DateTime.Parse(value); //DDateTime ddt = DDateTime.FromDateTime(qr.DPath.VR, dt); DicomDateTime ddt = new DicomDateTime(tagIn, dt); //rootSQElement.Value = ddt.ToDicomString(); ds.Add(ddt); } else { //rootSQElement.Value = value; ds.Add <string>(tagIn, value); } } catch (Exception err) { //SetError(err); //rootSQElement.Value = value; ds.Add <string>(tagIn, value); } } else { //rootSQElement.Value = value; ds.Add <string>(tagIn, value); } break; } } }
private static void FillElement <TR>(DicomDataset ds, DicomTag tagIn, DVR vrIn, ref int index, int depth, XCollection <TR> qrList, DataRow[] drList) where TR : QueryResultItem, IDicomMappingItem { if (drList.Length < 1) { return; } DataRow dr = drList[0]; TR qr = qrList[index] as TR; if (!qr.DPath.Enable) { return; } if (qr.DPath.VR == DVR.Unknown) { return; } else if (qr.DPath.VR == DVR.SQ) { index++; int count = qrList.Count; List <DicomDataset> eleListSequence = null; bool isProctolCodeSQ = (qr.DPath.GetTag() == Tags.ScheduledProtocolCodeSequence); //0x00400008 // use this to create a temporary patch to Japan according to requirement of sending multiple items in Requested Procedure Sequence, which is not allow in DICOM standard, 20090403 //bool isProctolCodeSQ = (qr.DPath.GetTag() == 0x00321064); for (; index < count; index++) { qr = qrList[index] as TR; switch (qr.DPath.Type) { case DPathType.BeginItem: { eleListSequence = new List <DicomDataset>(); if (isProctolCodeSQ) { foreach (DataRow d in drList) { DicomDataset eleList = new DicomDataset(); eleListSequence.Add(eleList); } //Program.Log.Write("--- Begin Protocol Code Sequence ---" + eleListSequence.Count.ToString()); } else { //Program.Log.Write("--- Begin Sequence ---" + DHelper.GetTagName((uint)rootSQElement.Tag)); DicomDataset eleList = new DicomDataset(); eleListSequence.Add(eleList); } continue; } case DPathType.EndItem: { if (eleListSequence == null) { continue; } DicomSequence dicomSequence = new DicomSequence(tagIn); if (isProctolCodeSQ) { foreach (DicomDataset eleList in eleListSequence) { dicomSequence.Items.Add(eleList); } //Program.Log.Write("--- End Protocol Code Sequence ---" + rootSQElement.Sequence.Count.ToString()); } else { //Program.Log.Write("--- End Sequence ---" + DHelper.GetTagName((uint)rootSQElement.Tag)); if (eleListSequence.Count > 0) { dicomSequence.Items.Add(eleListSequence[0]); } } TR qrNext = qrList[index + 1]; if (qrNext == null || qrNext.DPath.Type != DPathType.BeginItem) { return; } continue; } default: { if (eleListSequence == null) { continue; } if (!qr.DPath.Enable) { continue; } //int tag = qr.DPath.GetTag(depth + 1); List <string> tagList = qr.DPath.GetTagGE(depth); ushort uGroup = DHelper.HexString2ushort(tagList[0]); ushort uElement = DHelper.HexString2ushort(tagList[1]); DicomTag tag = new DicomTag(uGroup, uElement); if (isProctolCodeSQ) { int beginIndex = index; for (int i = 0; i < eleListSequence.Count; i++) { if (i == 0) { FillElement <TR>(eleListSequence[i], tag, qr.DPath.VR, ref index, depth + 1, qrList, new DataRow[] { drList[i] }); } else { FillElement <TR>(eleListSequence[i], tag, qr.DPath.VR, ref beginIndex, depth + 1, qrList, new DataRow[] { drList[i] }); } //Program.Log.Write("--- Add Protocol Code Sequence Item ---" // + i.ToString() + " " // + DHelper.GetTagName((uint)tag)); } } else { //Program.Log.Write("--- Add Sequence Item ---" + DHelper.GetTagName((uint)tag)); if (eleListSequence.Count > 0) { FillElement <TR>(eleListSequence[0], tag, qr.DPath.VR, ref index, depth + 1, qrList, drList); } } break; } } } } else { string value = null; object obj = dr[qr.TargetField]; if (obj != null) { value = obj.ToString(); } if (value == null) { value = ""; } ds.Add(tagIn, value); } }
public static DElementListWrapper[] CreateQRElementList <TR>(XCollection <TR> qrList, DataSet dsQR) where TR : QueryResultItem, IDicomMappingItem { if (qrList == null || dsQR == null || dsQR.Tables.Count < 1) { return(null); } DataTable dt = dsQR.Tables[0]; string pkColumn = Program.ConfigMgt.Config.PrimaryKeyColumnName; if (!dt.Columns.Contains(pkColumn)) { return(null); } Dictionary <string, List <DataRow> > drDict = new Dictionary <string, List <DataRow> >(); foreach (DataRow dr in dt.Rows) { string key = null; string pkValue = dr[pkColumn] as string; //if (pkValue != null || pkValue.Length > 0) if (pkValue != null && pkValue.Length > 0) { key = pkValue; } else { key = "_" + dt.Rows.IndexOf(dr).ToString(); } if (drDict.ContainsKey(key)) { drDict[key].Add(dr); } else { List <DataRow> drList = new List <DataRow>(); drDict.Add(key, drList); drList.Add(dr); } } List <DElementListWrapper> dcmResult = new List <DElementListWrapper>(); foreach (KeyValuePair <string, List <DataRow> > pair in drDict) { int count = qrList.Count; DicomDataset dcmEleList = new DicomDataset(); for (int index = 0; index < count; index++) { IDicomMappingItem qr = qrList[index] as IDicomMappingItem; if (!qr.DPath.Enable) { continue; } //int tag = qr.DPath.GetTag(0); List <string> tagList = qr.DPath.GetTagGE(0); ushort uGroup = DHelper.HexString2ushort(tagList[0]); ushort uElement = DHelper.HexString2ushort(tagList[1]); DicomTag tag = new DicomTag(uGroup, uElement); FillElement <TR>(dcmEleList, tag, qr.DPath.VR, ref index, 0, qrList, pair.Value.ToArray()); //dcmEleList.Add(ele); } DElementListWrapper w = new DElementListWrapper(dcmEleList); foreach (DataRow dr in pair.Value) { w.GUIDs.Add(DicomMappingHelper.GetGUID(dr)); } dcmResult.Add(w); } return(dcmResult.ToArray()); }