Example #1
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);
                }
            }
        }
Example #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);
            }
        }
Example #3
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);
        }
Example #4
0
        /// <summary>
        /// Save DICOM file
        /// </summary>
        /// <param name="dataset"></param>
        /// <param name="baseTsn"></param>
        /// <param name="implClassUid"></param>
        /// <param name="versionName"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private bool SaveDICOMFile(MElementList dataset, ts_t baseTsn, string implClassUid, string versionName, string filePath)
        {
            try
            {
                // add the following group 2 element for writing pt10 files
                string str_tsn = "1.2.840.10008.1.2";
                switch (baseTsn)
                {
                case ts_t.ImplicitVRLittleEndian: str_tsn = "1.2.840.10008.1.2"; break;

                case ts_t.ExplicitVRBigEndian: str_tsn = "1.2.840.10008.1.2.2"; break;

                case ts_t.ExplicitVRLittleEndian: str_tsn = "1.2.840.10008.1.2.1"; break;

                case ts_t.JPEGLosslessNonHierarchical_14: str_tsn = "1.2.840.10008.1.2.4.57"; break;

                case ts_t.JPEGLosslessNonHierarchicalFirstOrderPrediction: str_tsn = "1.2.840.10008.1.2.4.70"; break;

                default: str_tsn = "1.2.840.10008.1.2"; break;
                }
                MElement tsnUid = new MElement(tag_t.kTransferSyntaxUID, vr_t.UI);
                UID      tsn    = new UID(str_tsn);
                tsnUid.set_uid(0, tsn);
                dataset.addElement(tsnUid);

                MElement implUid = new MElement(tag_t.kImplementationClassUID, vr_t.UI);
                UID      uid     = new UID(implClassUid);
                implUid.set_uid(0, uid);
                dataset.addElement(implUid);

                MElement implVer = new MElement(tag_t.kImplementationVersionName, vr_t.SH);
                string   version = versionName;
                implVer.set_string(0, version);
                dataset.addElement(implVer);

                // Note: in the current version,saving file will use a large size of memory,this is a limitation
                // of the managed class in KDT,in the later version,if the limitation is resolved,we will use
                // the MDecoder to save files,not the MEncoder.wirte_pt10_file
                if (MEncoder.write_pt10_file
                    (
                        filePath,
                        dataset,
                        true, // item length is explicit
                        false // do not check group 2 items
                    ))
                {
                    _logger.Info("DAPStoreService.SaveFile(): " + "save file:" + filePath + "OK.");
                    return(true);
                }
                else
                {
                    _logger.Info("DAPStoreService.SaveFile(): " + "save file:" + filePath + "failed.");
                    return(false);
                }
            }
            catch (Exception e)
            {
                _logger.Info("DAPStoreService.SaveFile(): " + "error occurred while trying to write part-10 file " + e.Message);
                return(false);
            }
        }