public static void SaveStreamAsPdf( object sender, Leadtools.Printer.EmfEventArgs e ) { try { ConsoleMethods.Info( "EMF Event: SaveStreamAsPdf" ); // Write the EMF as file to disk. const string format = "pdf"; string path = Path.Combine( GetOutputRootPath(), format + @"\", GetRandomFileName( format ) ); Directory.CreateDirectory( Path.GetDirectoryName( path ) ); // Create an instance of the LEADTOOLS DocumentWriter var docWriter = new DocumentWriter(); docWriter.BeginDocument( path, DocumentFormat.Pdf ); var page = new DocumentEmfPage() { EmfHandle = new Metafile( new MemoryStream( e.Stream.ToArray() ) ) .GetHenhmetafile() }; docWriter.AddPage( page ); docWriter.EndDocument(); ConsoleMethods.Success( "SaveStreamAsPdf: Complete" ); ConsoleMethods.Verbose( path ); } catch ( Exception ex ) { ConsoleMethods.Error( ex.Message, 4000 ); } }
public static void FillSection_Png( object sender, Leadtools.Printer.EmfEventArgs e ) { ConsoleMethods.Info( "EMF Event: FillSection_Png" ); const string format = "png"; string path = Path.Combine( GetOutputRootPath(), format + @"\", GetRandomFileName( format ) ); Directory.CreateDirectory( Path.GetDirectoryName( path ) ); // Get the EMF in memory and save as PNG. Metafile metaFile = null; try { metaFile = new Metafile( e.Stream ); IntPtr hEmf = metaFile.GetHenhmetafile(); using ( RasterImage image = RasterImageConverter.FromEmf( hEmf, 0, 0, RasterColor.White ) ) { using ( RasterRegion region = new RasterRegion( new LeadRect( 20, 30, 100, 200 ) ) ) { image.SetRegion( null, region, RasterRegionCombineMode.Set ); new FillCommand( RasterColor.FromKnownColor( RasterKnownColor.Black ) ).Run( image ); } using ( RasterCodecs codecs = new RasterCodecs() ) { codecs.Options.Png.Save.QualityFactor = 9; codecs.Save( image, path, RasterImageFormat.Png, 32 ); } } ConsoleMethods.Success( "FillSection_Png: PNG saved. " ); ConsoleMethods.Verbose( path ); } catch ( Exception ex ) { ConsoleMethods.Error( ex.Message, 4000 ); } }
private void cstore_Status(object sender, Leadtools.Commands.DicomDemos.StatusEventArgs e) { try { string message = ""; bool done = false; if (e.Type == StatusType.Error) { message = "DICOM error. The process will be terminated! -- Error code is: " + e.Error.ToString(); } else { switch (e.Type) { case StatusType.ConnectFailed: message = "Connect operation failed."; done = true; break; case StatusType.ConnectSucceeded: message = "Connected successfully.\n"; message += "\tPeer Address:\t" + e.PeerIP.ToString() + "\n"; message += "\tPeer Port:\t\t" + e.PeerPort.ToString(); break; case StatusType.SendAssociateRequest: message = "Sending association request..."; break; case StatusType.ReceiveAssociateAccept: message = "Received Associate Accept.\n"; message += "\tCalling AE:\t" + e.CallingAE + "\n"; message += "\tCalled AE:\t" + e.CalledAE; break; case StatusType.ReceiveAssociateReject: message = "Received Associate Reject!"; message += "\tResult: " + e.Result.ToString(); message += "\tReason: " + e.Reason.ToString(); message += "\tSource: " + e.Source.ToString(); break; case StatusType.AbstractSyntaxNotSupported: message = "Abstract Syntax NOT supported!"; break; case StatusType.SendCStoreRequest: message = "Sending C-STORE Request..."; break; case StatusType.ReceiveCStoreResponse: if (e.Error == DicomExceptionCode.Success) { message = "**** Storage completed successfully ****"; } else { message = "**** Storage failed with status: " + e.Status.ToString(); } break; case StatusType.ConnectionClosed: message = "Network Connection closed!"; done = true; break; case StatusType.ProcessTerminated: message = "Process has been terminated!"; done = true; break; case StatusType.SendReleaseRequest: message = "Sending release request..."; break; case StatusType.ReceiveReleaseResponse: message = "Receiving release response"; done = true; break; case StatusType.Timeout: message = "Communication timeout. Process will be terminated."; done = true; break; } } // LogText(message); if (done) { AppLogger.LogAction.AddLog2List(lstFPD560, message); CStore cstore = sender as CStore; if (cstore.IsConnected()) cstore.Close(); } } catch { } }
private void cfind_Status(object sender, Leadtools.Commands.DicomDemos.StatusEventArgs e) { }
private void AddResultItem(Leadtools.Dicom.Common.DataTypes.Modality.ModalityWorklistResult result) { try { string tagValue; DataTable _DataFromWLServer = m_dtWLDataSource.Clone(); if (InvokeRequired) { Invoke(new AddResultItemDelegate(AddResultItem), result); } else { string PID = result.PatientId.Trim(); string pName = result.PatientName.ToString().Trim(); // AppLogger.LogAction.LogActions("Get from WorkListServer:" + pName); string tempName=""; string tempAge=""; string tempSex=""; try2SplitPName_Age_Sex(pName, ref tempName, ref tempAge, ref tempSex); pName = Bodau(tempName).Replace(" ", ""); if (!new PatientController().Exists(PID.ToUpper().Trim(), pName) && m_dtWLDataSource.Select("PATIENT_CODE='" + result.PatientId.Trim() + "'").Length <= 0) //if (m_dtWLDataSource.Select("PATIENT_CODE='" + result.PatientId.Trim() + "'").Length <= 0) { string StudyInstanceUID = ClearCanvas.Dicom.DicomUid.GenerateUid().UID; AppLogger.LogAction.LogActions(WLLogFile, "Nhận dữ liệu từ Dicom WorklistServer với Bệnh nhân:" + PID + "-" + pName); if (!arrRadCode.Contains(result.PatientId)) arrRadCode.Add(result.PatientId, GetCodeValue(result)); DataRow newRow = m_dtWLDataSource.NewRow(); newRow["Patient_ID"] = -1; newRow["PATIENT_CODE"] = result.PatientId; newRow["Patient_Name"] = tempName;// result.PatientName; newRow["PATIENT_NAME_UNSIGNED"] = Bodau(newRow["Patient_Name"].ToString()); newRow["PATIENT_NAME_NOSPACE"] = newRow["PATIENT_NAME_UNSIGNED"].ToString().Replace(" ", ""); //------------------------------------------------------------------------------ newRow["CREATED_BY"] = "WORKLIST"; newRow["Age"] = tempAge; newRow["REG_NUMBER"] = result.AccessionNumber; tagValue = Leadtools.DicomDemos.Utils.GetStringValue((DicomDataSet)result.Tag, DicomTag.StudyDate); newRow["sCREATED_DATE"] = GetDateStringFromDicomTagValue(tagValue); newRow["CREATED_DATE"] = GetDateTimeFromDicomTagValue(tagValue); tagValue = Leadtools.DicomDemos.Utils.GetStringValue((DicomDataSet)result.Tag, DicomTag.PatientBirthDate); DateTime? PBD; bool NoPatientBirthDate = false; if (result.PatientBirthDate != null) { PBD = GetDateTimeFromDicomTagValue(result.PatientBirthDate.Value.Day, result.PatientBirthDate.Value.Month, result.PatientBirthDate.Value.Year); if (File.Exists(Application.StartupPath + @"\log.wl")) AppLogger.LogAction.LogActions("NoPatientBirthDate=" + NoPatientBirthDate.ToString() + " result.PatientBirthDate=" + result.PatientBirthDate.Value.ToString("dd/MM/yyyy") + " PBD=" + PBD.Value.ToString("dd/MM/yyyy")); } else { NoPatientBirthDate = true; PBD = DateTime.Now; } if (NoPatientBirthDate) { newRow["Birth_Date"] = PBD.Value.AddYears(-1 * Convert.ToInt32(tempAge)); newRow["sBirth_Date"] = PBD.Value.AddYears(-1 * Convert.ToInt32(tempAge)).ToString("dd/MM/yyyy"); } else { newRow["Birth_Date"] = PBD.Value; newRow["sBirth_Date"] = PBD.Value.ToString("dd/MM/yyyy"); } if (File.Exists(Application.StartupPath + @"\log.wl")) AppLogger.LogAction.LogActions("NoPatientBirthDate=" + NoPatientBirthDate.ToString() + " PBD=" + newRow["sBirth_Date"].ToString()); newRow["Sex"] = (tempSex.Trim() != "" ? tempSex : result.PatientSex).Trim() == "M" ? 0 : ((tempSex.Trim() != "" ? tempSex : result.PatientSex).Trim() == "F" ? 1 : 2);// rdoMale.Checked ? 0 : (rdoFemale.Checked ? 1 : 2); newRow["EMERGENCY"] = 0; newRow["REG_ID"] = -1; newRow["StudyInstanceUID"] = StudyInstanceUID; newRow["PROCEDURELIST"] = "";// Utility.GetValue(txtProcedure.Text, false); newRow["PHYSICIAN"] = "";// cboPhysician.SelectedValue.ToString(); newRow["Doctor_Name"] = "";// cboPhysician.Text; newRow["REGSTATUS"] = 0; newRow["SEX_NAME"] = tempSex.Trim() != "" ? tempSex : result.PatientSex; newRow["CanDel"] = 1; newRow["HasProcessed"] = 0; newRow["NoneProcessed"] = 1; newRow["TotalProc"] = 1; newRow["COMPANY_NAME"] = "VIETBA DROC"; //Thêm mới một dòng vào Datasource để cập nhật lại dữ liệu trên DataGridView if (newRow != null)//99.99% là sẽ !=null { m_dtWLDataSource.Rows.Add(newRow); m_dtWLDataSource.AcceptChanges(); Utility.GotoNewRow(grdWorkList, "colPATIENT_CODE", result.PatientId); } //phải đảm bảo Datasource và RoomEntity có cấu trúc giống nhau mới dùng hàm này if (lblSaveAfterSearching.IsChecked==false) { } else//Lưu vào CSDL ngay sau khi tìm kiếm { CurrStudyInstanceUID = StudyInstanceUID; ExecuteSavingAction(newRow, null); } } } } catch(Exception ex) { AppLogger.LogAction.AddLog2List(lstFPD560,"Lỗi khi search từ worklist" + ex.Message); } }
private string GetCodeValue(Leadtools.Dicom.Common.DataTypes.Modality.ModalityWorklistResult result) { try { string _CodeValues = ""; AppLogger.LogAction.LogActions(WLLogFile, "Bắt đầu đọc RadCode"); foreach (Leadtools.Dicom.Common.DataTypes.ScheduledProcedureStep _ScheduledProcedureStep in result.ScheduledProcedureStepSequence) { foreach (Leadtools.Dicom.Common.DataTypes.CodeSequence _CodeSequence in _ScheduledProcedureStep.ScheduledProtocolCodeSequence) { AppLogger.LogAction.LogActions(WLLogFile, "RadCode=" + _CodeSequence.CodeValue); _CodeValues += _CodeSequence.CodeValue + ";"; } } AppLogger.LogAction.LogActions(WLLogFile, "Kết thúc đọc RadCode"); return _CodeValues; } catch { return ""; } }
void _MWLCom__AddResultItemEvent(Leadtools.Dicom.Common.DataTypes.Modality.ModalityWorklistResult result) { try { AddResultItem(result); } catch { } }
public static void SaveStreamDirectly( object sender, Leadtools.Printer.EmfEventArgs e ) { ConsoleMethods.Info( "EMF Event: SaveStreamDirectly" ); // Write the EMF as file to disk. const string format = "emf"; string path = Path.Combine( GetOutputRootPath(), format + @"\", GetRandomFileName( format ) ); Directory.CreateDirectory( Path.GetDirectoryName( path ) ); File.WriteAllBytes( path, e.Stream.ToArray() ); ConsoleMethods.Success( "SaveStreamDirectly: EMF saved. " ); ConsoleMethods.Verbose( path ); }