/// <summary>
        /// For some tag with local language, e.g PatientName
        /// ISO_IR 192: use UTF8 encoding local string
        /// ISO_IR 100: use GB2312 encoding local string
        /// </summary>
        /// <param name="strValue"></param>
        /// <param name="elmlist"></param>
        /// <param name="tag"></param>
        private string GetLocalStringTagValue(MElementList elmlist, tag_t tag)
        {
            var strValue = string.Empty;

            try
            {
                String str_speccharacter = "";
                using (MElementRef intereref = elmlist.get_Element(tag_t.kSpecificCharacterSet))
                {
                    if (intereref != null && intereref.value_count != 0 && intereref.value_count != -1)
                    {
                        str_speccharacter = intereref.get_string(0);
                    }
                    else
                    {
                        str_speccharacter = "";
                    }
                }
                using (MElementRef eref = elmlist.get_Element(tag))
                {
                    Byte[] byte_patName = null;
                    if (str_speccharacter.Trim() == "ISO_IR 192")
                    {
                        if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                        {
                            byte_patName = eref.get_blob(0);
                        }
                        strValue = Encoding.UTF8.GetString(byte_patName);
                    }
                    else if (str_speccharacter.Trim() == "ISO_IR 100")
                    {
                        if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                        {
                            byte_patName = eref.get_blob(0);
                        }
                        strValue = Encoding.GetEncoding("GB2312").GetString(byte_patName);
                    }
                    else
                    {
                        if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                        {
                            strValue = eref.get_string(0);
                        }
                        else
                        {
                            strValue = " ";
                        }
                    }
                    return(strValue);
                }
            }
            catch (Exception e)
            {
                _logger.Error("DCMHeader.GetStringTagValue(): " + "get string for tag " + tag.ToString() + " pop up an exception--" + e.Message + ".");
                return(strValue);
            }
        }
Beispiel #2
0
        private static void SetTSN(MElementList elmlist)
        {
            string str_tsn = "";

            using (MElementRef element = elmlist.get_Element(tag_t.kTransferSyntaxUID))
            {
                if (element != null && element.value_count > 0)
                {
                    str_tsn = element.get_string(0);
                    if (str_tsn == "")
                    {
                        str_tsn = "1.2.840.10008.1.2";
                        kdt_managed.UID tsn = new kdt_managed.UID(str_tsn);
                        element.set_uid(0, tsn);
                    }
                }
            }

            if (str_tsn == "")
            {
                MElement        tsnUid = new MElement(tag_t.kTransferSyntaxUID, vr_t.UI);
                kdt_managed.UID tsn    = new kdt_managed.UID("1.2.840.10008.1.2");
                tsnUid.set_uid(0, tsn);
                elmlist.addElement(tsnUid);
            }
        }
Beispiel #3
0
        private static void AddPrefixForAccNo(String strAccPrefix, MElementList elmlist, String accNoOrg)
        {
            using (MElementRef element = elmlist.get_Element(tag_t.kAccessionNumber))
            {
                string accNoNew = strAccPrefix + accNoOrg;

                //delete special char
                string          accNoNew_temp = "";
                Regex           re            = new Regex(@"[a-zA-Z0-9-_]+", RegexOptions.None);
                MatchCollection collection    = re.Matches(accNoNew);
                foreach (Match ma in collection)
                {
                    accNoNew_temp += ma.ToString();
                }
                accNoNew = accNoNew_temp;

                if (element == null || (element != null && element.value_count <= 0))
                {
                    MElement ele = new MElement(tag_t.kAccessionNumber, vr_t.LO);
                    ele.set_string(0, accNoNew);
                    elmlist.addElement(ele);
                }
                else
                {
                    element.set_string(0, accNoNew);
                }
            }
        }
Beispiel #4
0
        private static string AddPrefix(String strAccPrefix, MElementList elmlist, String accNoOrg, String patIDOrg, int PrefixLength)
        {
            AddPrefixForAccNo(strAccPrefix, elmlist, accNoOrg);
            //Modify PatientID
            if (patIDOrg.Length > PrefixLength)
            {
                patIDOrg = patIDOrg.Remove(PrefixLength);
            }
            using (MElementRef element = elmlist.get_Element(tag_t.kPatientID))
            {
                string patIDNew = strAccPrefix + patIDOrg;

                //delete special char
                string          patIDNew_temp = "";
                Regex           re            = new Regex(@"[a-zA-Z0-9-_]+", RegexOptions.None);
                MatchCollection collection    = re.Matches(patIDNew);
                foreach (Match ma in collection)
                {
                    patIDNew_temp += ma.ToString();
                }
                patIDNew = patIDNew_temp;

                if (element == null || (element != null && element.value_count <= 0))
                {
                    MElement ele = new MElement(tag_t.kPatientID, vr_t.LO);
                    ele.set_string(0, patIDNew);
                    elmlist.addElement(ele);
                }
                else
                {
                    element.set_string(0, patIDNew);
                }
            }
            return(patIDOrg);
        }
        private string GetStringTagValue(MElementList elmlist, tag_t tag)
        {
            var strValue = string.Empty;

            try
            {
                using (MElementRef eref = elmlist.get_Element(tag))
                {
                    if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                    {
                        strValue = eref.get_string(0);
                    }
                    else
                    {
                        strValue = "";
                    }
                    return(strValue);
                }
            }
            catch (Exception e)
            {
                _logger.Error("DicomHeader.GetStringTagValue(): " + "get string for tag " + tag.ToString() + " pop up an exception--" + e.Message + ".");
                return(strValue);
            }
        }
        private string GetDateTimeTagValue(MElementList elmlist, tag_t tag)
        {
            var strValue = string.Empty;
            var strRet   = string.Empty;

            try
            {
                using (MElementRef eref = elmlist.get_Element(tag))
                {
                    if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                    {
                        strValue = eref.get_string(0);
                    }
                    if (!string.IsNullOrEmpty((strValue)))
                    {
                        strRet = System.DateTime.ParseExact(strValue, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd");
                    }
                    return(strRet);
                }
            }
            catch (Exception e)
            {
                _logger.Error("DCMHeader.GetDateTimeTagValue(): " + "get datetime for tag " + tag.ToString() + " pop up an exception--" + e.Message + ".");
                strRet = System.DateTime.ParseExact(strValue, "yyyy.MM.dd", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd");
                return(strRet);
            }
        }
Beispiel #7
0
 private static void GetDICOMInfo(MElementList elmlist, ref String accNoOrg, ref String patIDOrg)
 {
     using (MElementRef element = elmlist.get_Element(tag_t.kAccessionNumber))
     {
         if (element != null && element.value_count > 0)
         {
             accNoOrg = element.get_string(0);
         }
     }
     using (MElementRef element = elmlist.get_Element(tag_t.kPatientID))
     {
         if (element != null && element.value_count > 0)
         {
             patIDOrg = element.get_string(0);
         }
     }
 }
        private string GetUIDTagValue(MElementList elmlist, tag_t tag)
        {
            var strUID = string.Empty;

            using (MElementRef eref = elmlist.get_Element(tag))
            {
                if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                {
                    strUID = eref.get_uid(0);
                }
                return(strUID);
            }
        }
Beispiel #9
0
 private void GetUIDTagValue(ref string strUID, MElementList elmlist, tag_t tag)
 {
     using (MElementRef eref = elmlist.get_Element(tag))
     {
         if (eref != null && eref.value_count != 0 && eref.value_count != -1)
         {
             strUID = eref.get_uid(0);
         }
         else
         {
             strUID = "";
         }
     }
 }
        /// <summary>
        /// indicate receiving over of an image
        /// </summary>
        /// <param name="ind">all the information about the received image</param>
        /// <param name="status">status that returned to the SCU</param>
        public override void indication(MElementList ind, MElementList status)
        {
            using (MElementRef eref = ind.get_Element(tag_t.kSOPInstanceUID))
            {
                if (eref != null)
                {
                    m_fileName = eref.get_string(0);
                }
            }

            MElementList pt10file = ind.getDataset();

            // save image and update case information
            if (!SaveFile(pt10file))
            {
                try
                {
                    using (MElementRef statusRef = status.get_Element(tag_t.kStatus))
                    {
                        // notify the client that image processing failed and cancel the whole association
                        statusRef.set_ushort(0, (ushort)MDTService.status_t.PROCESSING_FAILURE);
                        statusRef.set_ushort(1, (ushort)MDTService.status_t.CANCEL);
                    }

                    // file saving failed,the case should not be submitted
                    m_theObserver.m_OK = false;
                }
                catch (Exception e)
                {
                    m_theObserver.m_OK = false;
                    _logger.Info("DAPStoreService.indication(): " + "set response status error " + e.Message);
                }
            }

            // release the memory used by MElementList
            pt10file.Dispose();
            ind.Dispose();

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        private int GetIntTagValue(MElementList elmlist, tag_t tag)
        {
            var nValue = 0;

            try
            {
                using (MElementRef eref = elmlist.get_Element(tag))
                {
                    if (eref != null && eref.value_count != 0 && eref.value_count != -1)
                    {
                        nValue = eref.get_sint(0);
                    }
                    return(nValue);
                }
            }
            catch (Exception e)
            {
                _logger.Error("DCMHeader.GetIntTagValue(): " + "get int for tag " + tag.ToString() + " pop up an exception--" + e.Message + ".");
                return(nValue);
            }
        }
Beispiel #12
0
 private void GetDateTimeTagValue(ref string strValue, MElementList elmlist, tag_t tag)
 {
     try
     {
         using (MElementRef eref = elmlist.get_Element(tag))
         {
             if (eref != null && eref.value_count != 0 && eref.value_count != -1)
             {
                 strValue = eref.get_string(0);
             }
             else
             {
                 strValue = " ";
             }
         }
     }
     catch (Exception e)
     {
         strValue = " ";
         _logger.Error("DCMHeader.GetDateTimeTagValue(): " + "get datetime for tag " + tag.ToString() + " pop up an exception--" + e.Message + ".");
     }
 }