Beispiel #1
0
        private void SetExamNumber(DataTable dataSrc)
        {
            if (!dataSrc.Columns.Contains(ReportCommon.FIELDNAME_EXAMNUMBER))
            {
                return;
            }

            string strPatientID = ReportUtils.GetStringFromDataTable(dataSrc, ReportCommon.FIELDNAME_PATIENTID);
            string strOrderGuid = ReportUtils.GetStringFromDataTable(dataSrc, ReportCommon.FIELDNAME_ORDERGUID);

            if (string.IsNullOrEmpty(strPatientID) || string.IsNullOrEmpty(strOrderGuid))
            {
                return;
            }

            int examNo = GetPatientExamNo(strPatientID, strOrderGuid);

            if (examNo == 0)
            {
                return;
            }

            foreach (DataRow dr in dataSrc.Rows)
            {
                dr[ReportCommon.FIELDNAME_EXAMNUMBER] = examNo;
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static string LocalizeCurrentAge(string src, IEnumerable <DictionaryDto> dictionaries)
        {
            if (src == null)
            {
                return("");
            }

            try
            {
                string   strTemp = src;
                string[] split   = strTemp.Split(new Char[] { ' ' });
                if (split.Length < 2)
                {
                    throw new Exception("Invalid current age");
                }

                //src = split[0] + GetLanguage(split[1]);
                //src = split[0] + DictionaryManager.Instance.GetText((int)DictionaryTag.AgeUnit, split[1]);
                src = split[0] + ReportUtils.GetDictionaryText(dictionaries, (int)DictionaryTag.AgeUnit, split[1]);;
            }
            catch (Exception ex)
            {
                //  logger.Error((long)ModuleEnum.Register_Client, ModuleInstanceName.Registration, 53, ex.Message, Application.StartupPath.ToString(), (new System.Diagnostics.StackFrame(true)).GetFileName(),

                //   (new System.Diagnostics.StackFrame(true)).GetFileLineNumber());
            }

            return(src);
        }
Beispiel #3
0
        private void readReportImages(DataTable dstDT, DataTable dtReportInfo, string reportID, C1Report c1rpt, string domain)
        {
            List <string> listTmpFile = getFTPFiles(dtReportInfo, reportID, domain);

            int idx = 0;

            foreach (Field fld in c1rpt.Fields)
            {
                if (fld.Picture != null)
                {
                    C1.C1Report.Util.PictureHolder ph = fld.Picture as C1.C1Report.Util.PictureHolder;

                    if (ph != null && ph.IsBound)
                    {
                        if (string.Compare(ph.FieldName, ReportCommon.FIELDNAME_CREATORSIGNIMAGE, true) == 0)
                        {
                            string creater = ReportUtils.GetStringFromDataTable(dtReportInfo, ReportCommon.FIELDNAME_tbReport__Creater);
                            if (!string.IsNullOrEmpty(creater))
                            {
                                User user = _dbContext.Set <User>().Where(u => u.UniqueID == creater).FirstOrDefault();
                                if (user != null)
                                {
                                    dstDT.Rows[0][ph.FieldName] = user.SignImage;
                                }
                            }
                        }
                        else if (string.Compare(ph.FieldName, ReportCommon.FIELDNAME_FIRSTAPPROVERSIGNIMAGE, true) == 0)
                        {
                            string approver = ReportUtils.GetStringFromDataTable(dtReportInfo, ReportCommon.FIELDNAME_tbReport__FirstApprover);
                            if (!string.IsNullOrEmpty(approver))
                            {
                                User user = _dbContext.Set <User>().Where(u => u.UniqueID == approver).FirstOrDefault();
                                if (user != null)
                                {
                                    dstDT.Rows[0][ph.FieldName] = user.SignImage;
                                }
                            }
                        }
                        else if (string.Compare(ph.FieldName, ReportCommon.FIELDNAME_SUBMITTERSIGNIMAGE, true) == 0)
                        {
                            string submitter = ReportUtils.GetStringFromDataTable(dtReportInfo, ReportCommon.FIELDNAME_tbReport__Submitter);
                            if (!string.IsNullOrEmpty(submitter))
                            {
                                User user = _dbContext.Set <User>().Where(u => u.UniqueID == submitter).FirstOrDefault();
                                if (user != null)
                                {
                                    dstDT.Rows[0][ph.FieldName] = user.SignImage;
                                }
                            }
                        }
                        else if (dstDT.Columns.Contains(ph.FieldName) && idx < listTmpFile.Count)
                        {
                            dstDT.Rows[0][ph.FieldName] = File.ReadAllBytes(listTmpFile[idx]);

                            ++idx;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public ShowHtmlDataDto GetReportViewer2(string reportID, string loginDomain, string loginSite, string printTemplateID)
        {
            List <ProcedureDto> procedureDtos = GetProcedureByReportID(reportID).ToList();
            ProcedureDto        procedure     = procedureDtos[0];

            DataTable dt;
            string    templateInfo = "";

            //use store procedure
            Order           order           = _dbContext.Set <Order>().Where(p => p.UniqueID == procedure.OrderID).FirstOrDefault();
            string          accNo           = order.AccNo;
            string          modalityType    = procedure.ModalityType;
            ReportDBService reportDBService = new ReportDBService();
            string          templateID      = "";

            reportDBService.GetReportPrintTemplate(accNo, modalityType, reportID, loginSite, out templateID, out dt);


            //print templateID
            if (!string.IsNullOrEmpty(printTemplateID))
            {
                Report report = _dbContext.Set <Report>().Where(r => r.UniqueID == reportID).FirstOrDefault();
                if (report != null && report.Status < (int)RPStatus.FirstApprove)
                {
                    templateID = printTemplateID;
                }
            }

            if (templateID != "")
            {
                PrintTemplate printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.UniqueID == templateID).FirstOrDefault();
                if (printTemplate != null)
                {
                    templateInfo = generatePrintTemplate(printTemplate);
                }
            }
            else
            {
                return(null);
            }


            string templateGuid = ReportUtils.GetFirstRowValueFromDataSet(dt.DataSet, ReportCommon.FIELDNAME_tbReport__PrintTemplateGuid);

            DataTable newdt = generateDataTable4PrintingForReport(dt.DataSet, ref templateInfo, reportID, loginDomain);

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, newdt);

                return(new ShowHtmlDataDto {
                    Template = templateInfo, data = Convert.ToBase64String(ms.ToArray())
                });
            }
        }
Beispiel #5
0
        public DataTable GetBaseInfoByProcedure(ProcedureDto procedure)
        {
            DataTable dt = ReportUtils.CreateDTReportTemplate();
            DataRow   dr = dt.NewRow();

            if (procedure != null)
            {
                ReportUtils.SetDTDataForProcedure(procedure, ref dr);

                if (!string.IsNullOrEmpty(procedure.ReportID))
                {
                    Report report = _ReportRepository.Get(p => p.UniqueID == procedure.ReportID).FirstOrDefault();
                    if (report != null)
                    {
                        //report
                        ReportUtils.SetDTDataForReport(report, ref dr);
                    }
                }

                if (!string.IsNullOrEmpty(procedure.ProcedureCode))
                {
                    List <Procedurecode> procedurecodes = _dbContext.Set <Procedurecode>().Where(p => procedure.ProcedureCode.Contains(p.ProcedureCode)).ToList();
                    if (procedurecodes != null)
                    {
                        ReportUtils.SetDTDataForProcedurecode(procedurecodes, ref dr);
                    }
                }

                //
                if (!string.IsNullOrEmpty(procedure.OrderID))
                {
                    Order order = _dbContext.Set <Order>().Where(p => p.UniqueID == procedure.OrderID).FirstOrDefault();
                    if (order != null)
                    {
                        ReportUtils.SetDTDataForOrder(order, ref dr);

                        if (!string.IsNullOrEmpty(order.PatientID))
                        {
                            Patient patient = _dbContext.Set <Patient>().Where(p => p.UniqueID == order.PatientID).FirstOrDefault();
                            ReportUtils.SetDTDataForPatient(patient, ref dr);
                        }
                    }
                }
            }

            dt.Rows.Add(dr);

            return(dt);
        }
Beispiel #6
0
        private DataTable GenerateDataTable4Printing(DataTable dtSrc, C1Report c1rpt)
        {
            DataTable dt = new DataTable();

            foreach (Field fld in c1rpt.Fields)
            {
                if (fld.Picture != null)
                {
                    C1.C1Report.Util.PictureHolder ph = fld.Picture as C1.C1Report.Util.PictureHolder;

                    if (ph != null && ph.IsBound && !dt.Columns.Contains(ph.FieldName))
                    {
                        dt.Columns.Add(ph.FieldName, System.Type.GetType("System.Byte[]"));
                    }
                }
                else if (fld.Calculated)
                {
                    if (!dt.Columns.Contains(fld.Text))
                    {
                        dt.Columns.Add(fld.Text);
                    }
                }
            }

            if (dtSrc.Rows.Count > 0)
            {
                DataRow dr = dt.NewRow();

                foreach (DataColumn fld in dt.Columns)
                {
                    if (dtSrc.Columns.Contains(fld.ColumnName))
                    {
                        if (fld.DataType == System.Type.GetType("System.Byte[]"))
                        {
                            dr[fld.ColumnName] = ReportUtils.GetBytesFromBase64(dtSrc, fld.ColumnName);
                        }
                        else
                        {
                            dr[fld.ColumnName] = GetStringForPrinting(dtSrc, fld.ColumnName);
                        }
                    }
                }

                dt.Rows.Add(dr);
            }

            return(dt);
        }
Beispiel #7
0
        private string GetRenderedReportHtml(DataSet dsReportData, string templateInfo)
        {
            if (dsReportData == null || dsReportData.Tables.Count < 1)
            {
                return(string.Empty);
            }

            string content = "";

            string rptGuid = ReportUtils.GetFirstRowValueFromDataSet(dsReportData, "TBREPORT__REPORTGUID");

            string savePath = GenerateTempSaveFolder();
            string saveFile = Path.Combine(savePath, rptGuid + ".htm");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(templateInfo);
            using (C1Report c1rpt = new C1Report())
            {
                c1rpt.Load(xmlDocument, "Template");
                c1rpt.DataSource.Recordset = dsReportData.Tables[0];

                c1rpt.RenderToFile(saveFile, FileFormatEnum.HTML);
            }

            content = File.ReadAllText(saveFile);

            int startIndex = content.IndexOf("src=\"");

            while (startIndex > 0)
            {
                int endIndex = content.IndexOf("\"", startIndex + 6);
                if (endIndex > 0)
                {
                    string imagePath  = content.Substring(startIndex + 5, endIndex - startIndex - 5);
                    byte[] imageArray = System.IO.File.ReadAllBytes(savePath + "\\" + imagePath);
                    string base64ImageRepresentation = Convert.ToBase64String(imageArray);
                    content = content.Substring(0, startIndex + 5) + "data:image/jpeg;base64," + base64ImageRepresentation + content.Substring(endIndex);
                }

                startIndex = content.IndexOf("src=\"", startIndex + 6);
            }

            return(content);
        }
Beispiel #8
0
        private string getPrintTemplateForBaseInfo(string domain, string site)
        {
            PrintTemplateDto criteria = new PrintTemplateDto
            {
                Type         = 0,
                TemplateName = "baseinfo"
            };

            List <PrintTemplateDto> printTemplateDtoList = GetPrintTemplateByCriteria(criteria, domain, site);

            if (printTemplateDtoList == null || printTemplateDtoList.Count == 0)
            {
                return("");
            }
            PrintTemplateDto printTemplateDto = printTemplateDtoList[0];

            string templateInfo = ReportUtils.GetUnicodeStringFromBytes(printTemplateDto.TemplateInfo);

            return(templateInfo);
        }
Beispiel #9
0
        public string GetReportViewer(string reportID, string loginDomain, string loginSite)
        {
            List <ProcedureDto> procedureDtos = GetProcedureByReportID(reportID).ToList();
            ProcedureDto        procedure     = procedureDtos[0];

            DataTable dt;
            string    templateInfo = "";

            //use store procedure
            Order           order           = _dbContext.Set <Order>().Where(p => p.UniqueID == procedure.OrderID).FirstOrDefault();
            string          accNo           = order.AccNo;
            string          modalityType    = procedure.ModalityType;
            ReportDBService reportDBService = new ReportDBService();
            string          templateID      = "";

            reportDBService.GetReportPrintTemplate(accNo, modalityType, reportID, loginSite, out templateID, out dt);
            if (templateID != "")
            {
                PrintTemplate printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.UniqueID == templateID).FirstOrDefault();
                if (printTemplate != null)
                {
                    templateInfo = generatePrintTemplate(printTemplate);
                }
            }
            else
            {
                return(null);
            }


            string templateGuid = ReportUtils.GetFirstRowValueFromDataSet(dt.DataSet, ReportCommon.FIELDNAME_tbReport__PrintTemplateGuid);

            DataTable newdt = generateDataTable4PrintingForReport(dt.DataSet, ref templateInfo, reportID, loginDomain);

            DataSet newds = new DataSet();

            newds.Tables.Add(newdt);
            //get html
            return(GetRenderedReportHtml(newds, templateInfo));
        }
Beispiel #10
0
        private string MakeReportName(string[] rpGuids)
        {
            string newName = "Error Report " + Guid.NewGuid().ToString();

            if (rpGuids == null || rpGuids.Length == 0)
            {
                throw (new Exception("Miss Parameter"));
            }

            string accNo = "";
            string desc  = "";

            GetInfoForReportName(rpGuids, out accNo, out desc);

            if (accNo != "")
            {
                newName  = ReportUtils.StringRight(accNo, 4);
                newName += "_" + desc;
                newName += DateTime.Now.Second.ToString();
                newName  = "_" + newName;
            }

            return(newName);
        }
Beispiel #11
0
        private List <string> getFTPFiles(DataTable dtReportInfo, string reportID, string domain)
        {
            List <string>     listTmpFile    = new List <string>();
            List <ReportFile> reportFileList = _dbContext.Set <ReportFile>().Where(p => p.ReportID == reportID).OrderBy(p => p.ImagePosition).ToList();

            try
            {
                if (reportFileList == null || reportFileList.Count < 1)
                {
                    return(listTmpFile);
                }

                string tmpFolder = GenerateTempSaveFolder();

                string accNo      = ReportUtils.GetStringFromDataTable(dtReportInfo, ReportCommon.FIELDNAME_ACCNO);
                string reportGuid = ReportUtils.GetStringFromDataTable(dtReportInfo, ReportCommon.FIELDNAME_tbReport__ReportGuid);
                string tmpPath    = System.IO.Path.Combine(tmpFolder, "images");

                if (!System.IO.Directory.Exists(tmpPath))
                {
                    System.IO.Directory.CreateDirectory(tmpPath);
                }

                //
                // Start to Ftp
                FtpClient ftpClient = getFTPObject(domain);
                if (ftpClient != null)
                {
                    foreach (ReportFile reportFile in reportFileList)
                    {
                        string fguid         = reportFile.UniqueID;
                        string fname         = reportFile.FileName;
                        string rpath         = reportFile.RelativePath;
                        int    fType         = reportFile.fileType.Value;
                        int    showWidth     = reportFile.ShowWidth.Value;
                        int    showHeight    = reportFile.ShowHeight.Value;
                        int    imageposition = reportFile.ImagePosition.Value;

                        if (1 == fType)
                        {
                            string localFilePath = tmpPath + "\\" + fname;

                            if (!File.Exists(localFilePath))
                            {
                                ftpClient.DownloadFile(rpath + "\\" + fname, localFilePath);
                            }
                            if (System.IO.File.Exists(localFilePath))
                            {
                                listTmpFile.Add(localFilePath);
                            }
                        }
                    }

                    ftpClient.Close();
                }
            }
            catch (Exception ex)
            {
                string msg = "Fail to get the images from FTP server! Message=" + ex.Message;
            }

            return(listTmpFile);
        }
Beispiel #12
0
        private string GetStringForPrinting(DataTable dt, string colName)
        {
            if (dt == null || dt.Rows.Count < 1 || !dt.Columns.Contains(colName) ||
                colName == null || colName.Length < 1)
            {
                System.Diagnostics.Debug.Assert(false);

                return("");
            }

            string key = colName.ToUpper().Trim();
            string ret = "";

            object objValue = dt.Rows[0][key];
            string fldValue = "";

            var dictionaries = _dbContext.Set <Dictionary>().ToList()
                               .Select(d => Mapper.Map <Dictionary, DictionaryDto>(d)).ToList();
            var groupedDVs = _dbContext.Set <DictionaryValue>().ToList()
                             .Select(dv => Mapper.Map <DictionaryValue, DictionaryValueDto>(dv)).GroupBy(d => d.Tag).ToList();

            dictionaries.ForEach(d =>
            {
                var group = groupedDVs.FirstOrDefault(g => g.Key == d.Tag);
                if (group != null)
                {
                    d.Values = group.Select(g => g).ToList();
                }
            });

            if (objValue.GetType() == System.Type.GetType("System.Byte[]"))
            {
                Byte[] buff = objValue as Byte[];

                fldValue = ReportUtils.GetStringFromBytes(buff);
            }
            if (objValue.GetType() == System.Type.GetType("System.DateTime"))
            {
                DateTime dateTime = Convert.ToDateTime(objValue);

                fldValue = dateTime.ToString("yyyy/MM/dd HH:mm:ss");
            }
            else
            {
                fldValue = objValue.ToString();
            }

            if (objValue.GetType() != System.Type.GetType("System.DateTime") &&
                (key.StartsWith("tbProcedureCode") || key.StartsWith("tbProcedureCode")))
            {
                ret = ReportUtils.GetStringFromDataTable(dt, colName);
                if (ReportUtils.isNeedLocalizationAsUserName(colName))
                {
                    UserDto userDto = null;
                    var     user    = _dbContext.Set <User>().Where(p => p.UniqueID == fldValue).FirstOrDefault();
                    if (user != null)
                    {
                        userDto = Mapper.Map <User, UserDto>(user);
                    }
                    if (userDto != null)
                    {
                        ret = userDto.LocalName;
                    }
                    else
                    {
                        ret = fldValue;
                    }
                }
            }
            else if (key.EndsWith("SITE"))
            {
                var siteDto = _dbContext.Set <Site>().Where(p => p.SiteName.Equals(fldValue, StringComparison.OrdinalIgnoreCase))
                              .ToList().Select(d => Mapper.Map <Site, SiteDto>(d)).FirstOrDefault();
                if (siteDto != null)
                {
                    ret = siteDto.Alias;
                }
                else
                {
                    ret = fldValue;
                }
            }
            else if (key.EndsWith("CURRENTAGE"))
            {
                ret = ReportUtils.LocalizeCurrentAge(fldValue, dictionaries);
            }
            else if (ReportUtils.isNeedLocalizationAsUserName(colName))
            {
                UserDto userDto = null;
                var     user    = _dbContext.Set <User>().Where(p => p.UniqueID == fldValue).FirstOrDefault();
                if (user != null)
                {
                    userDto = Mapper.Map <User, UserDto>(user);
                }
                if (userDto != null)
                {
                    ret = userDto.LocalName;
                }
                else
                {
                    ret = fldValue;
                }
            }
            else if (key.EndsWith("BEDSIDE") || key.EndsWith("THREEDREBUILD"))
            {
                ret = ReportUtils.GetDictionaryText(dictionaries, (int)DictionaryTag.YesNo, fldValue);
            }
            else if (key.EndsWith("ISPOSITIVE"))
            {
                ret = ReportUtils.GetDictionaryText(dictionaries, (int)DictionaryTag.Positive, fldValue);
            }
            else
            {
                ret = fldValue;
            }

            return(ret);
        }
Beispiel #13
0
        private DataTable generateDataTable4Printing(DataTable dtSrc, C1Report c1rpt)
        {
            DataTable dt = ReportUtils.CreateDTBaseInfoTemplate();

            foreach (Field fld in c1rpt.Fields)
            {
                if (fld.Picture != null)
                {
                    C1.C1Report.Util.PictureHolder ph = fld.Picture as C1.C1Report.Util.PictureHolder;

                    if (ph != null && ph.IsBound && !dt.Columns.Contains(ph.FieldName))
                    {
                        dt.Columns.Add(ph.FieldName, System.Type.GetType("System.Byte[]"));
                    }
                }
                else if (fld.Calculated)
                {
                    if (!dt.Columns.Contains(fld.Text))
                    {
                        dt.Columns.Add(fld.Text);

                        if (fld.Text.ToLower() == "tbreport__wys")
                        {
                            fld.RTF  = false;
                            fld.Text = "tbReport__WYSTEXT";
                        }
                        else if (fld.Text.ToLower() == "tbreport__wyg")
                        {
                            fld.RTF  = false;
                            fld.Text = "tbReport__WYGTEXT";
                        }
                    }
                }
            }

            //c1rpt.Save(templateFile);

            if (dtSrc.Rows.Count > 0)
            {
                DataRow dr = dt.NewRow();

                foreach (DataColumn fld in dt.Columns)
                {
                    if (dtSrc.Columns.Contains(fld.ColumnName))
                    {
                        if (fld.ColumnName.ToLower().EndsWith("reportname"))
                        {
                            dr[fld.ColumnName] = GetStringForPrinting(dtSrc, "tbRegPatient__LocalName")
                                                 + GetStringForPrinting(dtSrc, fld.ColumnName);
                        }
                        else
                        {
                            dr[fld.ColumnName] = GetStringForPrinting(dtSrc, fld.ColumnName);
                        }
                    }
                }

                dt.Rows.Add(dr);
            }

            SetExamNumber(dt);

            //SetSignImage(dt, dtSrc);

            return(dt);
        }
Beispiel #14
0
        private string generatePrintTemplate(PrintTemplate printTemplate)
        {
            string templateInfo = ReportUtils.GetUnicodeStringFromBytes(printTemplate.TemplateInfo);

            return(templateInfo);
        }
Beispiel #15
0
        public string GetPacsUrlDX(string procedureID, string loginUserID)
        {
            Procedure    procedure    = _dbContext.Set <Procedure>().Where(p => p.UniqueID == procedureID).FirstOrDefault();
            ProcedureDto procedureDto = Mapper.Map <Procedure, ProcedureDto>(procedure);
            DataTable    dt           = _reportPrintService.GetBaseInfoByProcedure(procedureDto);
            string       siteName     = dt.Rows[0]["tbRegOrder__ExamSite"].ToString();

            if (siteName != "")
            {
                Site   site = _dbContext.Set <Site>().Where(p => p.SiteName == siteName).FirstOrDefault();
                string ret  = site.PacsServer;
                ret = ret.ToLower();
                User user = _dbContext.Set <User>().Where(p => p.UniqueID == loginUserID).FirstOrDefault();
                if (ret.Contains("{user_name}"))
                {
                    ret = ret.Replace("{user_name}", user.LoginName);
                }
                if (ret.Contains("{password}"))
                {
                    string password = "";
                    try
                    {
                        var c = new Cryptography("GCRIS2-20061025");
                        var decryptedPassword = c.DeEncrypt(user.Password);
                        if (decryptedPassword != "")
                        {
                            password = decryptedPassword;
                        }
                    }
                    catch
                    {
                    }

                    ret = ret.Replace("{password}", password);
                }

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    ret = ret.Replace("{" + dt.Columns[i].ColumnName.ToLower() + "}", ReportUtils.GetFieldValue(dt, 0, i));
                    if (ret.IndexOf("{") < 0)
                    {
                        break;
                    }
                }

                return(ret);
            }
            return("");
        }