Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        public static void ModifyQCMappingList_DateTime <TC>(XCollection <TC> qcList, bool withBracket)
            where TC : QueryCriteriaItem, IDicomMappingItem, new()
        {
            if (qcList == null)
            {
                return;
            }
            bool found = true;

            while (found)
            {
                found = false;
                int count = qcList.Count;
                for (int index = 0; index < count; index++)
                {
                    TC item = qcList[index];

                    IDicomMappingItem dcmItem = item as IDicomMappingItem;
                    if (dcmItem == null)
                    {
                        continue;
                    }

                    if (dcmItem.DPath != null &&
                        dcmItem.DPath.Range == DRangeType.None &&
                        DHelper.IsDateTime(dcmItem.DPath.VR))
                    {
                        qcList.Remove(item);

                        QueryCriteriaItem itemB = dcmItem.Clone() as QueryCriteriaItem;
                        ((IDicomMappingItem)itemB).DPath.Range = DRangeType.Begin;
                        itemB.Operator    = QueryCriteriaOperator.EqualLargerThan;
                        itemB.SourceField = itemB.SourceField + "_BEGIN";

                        QueryCriteriaItem itemE = dcmItem.Clone() as QueryCriteriaItem;
                        ((IDicomMappingItem)itemE).DPath.Range = DRangeType.End;
                        itemE.Operator    = QueryCriteriaOperator.EqualSmallerThan;
                        itemE.SourceField = itemE.SourceField + "_END";

                        if (withBracket)    // for GetRule()
                        {
                            qcList.Insert(index, GetRightBracket <TC>());
                            qcList.Insert(index, GetRightBracket <TC>());

                            TC itemEE = GetFreeText <TC>("@" + itemE.SourceField + "=''");
                            itemEE.Type = QueryCriteriaType.And;
                            qcList.Insert(index, itemEE);

                            TC itemBB = GetFreeText <TC>("@" + itemB.SourceField + "=''");
                            itemBB.Type = QueryCriteriaType.None;
                            qcList.Insert(index, itemBB);

                            TC itemOr = GetLeftBracket <TC>();
                            itemOr.Type = QueryCriteriaType.Or;
                            qcList.Insert(index, itemOr);

                            qcList.Insert(index, GetRightBracket <TC>());

                            itemE.Type = QueryCriteriaType.And;
                            qcList.Insert(index, itemE);

                            itemB.Type = QueryCriteriaType.None;
                            qcList.Insert(index, itemB);

                            qcList.Insert(index, GetLeftBracket <TC>());

                            TC itemAnd = GetLeftBracket <TC>();
                            itemAnd.Type = QueryCriteriaType.And;
                            qcList.Insert(index, itemAnd);
                        }
                        else                // for NT Service to create QC DataSet
                        {
                            qcList.Insert(index, itemE);
                            qcList.Insert(index, itemB);
                        }

                        found = true;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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;
            }
            }
        }