public List <SeriesImage> GetAllPatientImages(string patientID) { List <SeriesImage> seriesImages; DataSet instances; seriesImages = new List <SeriesImage>(); instances = QueryCurrentPatient(patientID); foreach (DataRow row in instances.Tables[DataTableHelper.InstanceTableName].Rows) { RasterImage image; string referencedFile = row.Field <string>("ReferencedFile"); using (var dicomDs = new DicomDataSet()) { dicomDs.Load(referencedFile, DicomDataSetLoadFlags.None); double xDpi = 0; double yDpi = 0; AddInsUtils.GetDpi(dicomDs, out xDpi, out yDpi); image = GetImage(dicomDs); if (image != null) { string seriesIntanceUID = dicomDs.GetValue <string>(DicomTag.SeriesInstanceUID, string.Empty); string sopInstanceUID = dicomDs.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty); SeriesImage si = new SeriesImage(seriesIntanceUID, sopInstanceUID, image, xDpi, yDpi); seriesImages.Add(si); } } } return(seriesImages); }
public WorklistResult[] QueryWorklist(string userName, WorklistQueryOptions options) { List <WorklistResult> results = new List <WorklistResult>(); MatchingParameterCollection matchingCollection = new MatchingParameterCollection(); MatchingParameterList matchingList = new MatchingParameterList(); MWLDataset dataset = null; matchingCollection.Add(matchingList); AddInsUtils.FillWorklistMatchingParameters(options, matchingList); dataset = _DataAccessAgent.QueryModalityWorklists(matchingCollection, new StringCollection()); foreach (MWLDataset.ScheduledProcedureStepRow row in dataset.ScheduledProcedureStep.Rows) { WorklistResult result = new WorklistResult(); result.ScheduledProcedureStep = new WorklistScheduledProcedureStep(); result.Patient = new WorklistPatient(); row.CopyTo(result.ScheduledProcedureStep); row.RequestedProcedureRowParent.ImagingServiceRequestRow.PatientRowParent.CopyTo(result.Patient); results.Add(result); result.ImagingServiceRequest = new ImagingServiceRequest(); row.RequestedProcedureRowParent.ImagingServiceRequestRow.CopyTo(result.ImagingServiceRequest); result.RequestedProcedure = new WorklistRequestedProcedure(); row.RequestedProcedureRowParent.CopyTo(result.RequestedProcedure); } return(results.ToArray()); }
public Stream ExportLayout(string userName, string seriesInstanceUID, Layout layout, bool burnAnnotations, CompressionType compression, int width) { Dictionary <string, DicomDataSet> datasets = _Exporter.GetSeriesDatasets(new string[] { seriesInstanceUID }); RasterImage image; // // Check to see if a width was provide. If not we default to 1024; // if (width == 0) { width = 1024; } image = AddInsUtils.LayoutToImage(datasets, layout, burnAnnotations, width, _QueryAddIn, _ObjectRetrieveAddIn, userName); if (image != null) { if (null != WebOperationContext.Current) { WebOperationContext.Current.OutgoingResponse.ContentType = SupportedMimeTypes.JPG; WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Disposition", string.Format("attachment; filename={0}.jpg", seriesInstanceUID)); } return(image.ToStream(RasterImageFormat.Jpeg, GetCompression(compression))); } return(null); }
private ZipFile LoadInstances(List <SeriesImage> seriesImages, string userName, ExportOptions options) { ZipFile zip = null; string extension = string.Empty; bool isLossless = false; RasterImageFormat format = GetFormat(options.FileFormat, out extension, out isLossless); Dictionary <string, Dictionary <string, List <AnnContainer> > > seriesAnnotations = new Dictionary <string, Dictionary <string, List <AnnContainer> > >(); foreach (SeriesImage seriesImage in seriesImages) { string fileName = Path.ChangeExtension(Path.GetRandomFileName(), extension); if (options.BurnAnnotations) { if (!seriesAnnotations.ContainsKey(seriesImage.SeriesInstanceUID)) { seriesAnnotations[seriesImage.SeriesInstanceUID] = AddInsUtils.GetSeriesAnnotations(userName, seriesImage.SeriesInstanceUID, _QueryAddIn, _ObjectRetrieveAddIn); } if (seriesAnnotations[seriesImage.SeriesInstanceUID].ContainsKey(seriesImage.SOPInstanceUID)) { foreach (AnnContainer container in seriesAnnotations[seriesImage.SeriesInstanceUID][seriesImage.SOPInstanceUID]) { seriesImage.Image.Burn(container, seriesImage.XDpi, seriesImage.YDpi); } } } ResetGrayscale(seriesImage.Image, options.ReduceGrayscaleTo8BitsSelected); if (zip == null) { zip = new ZipFile(); } zip.AddEntry(fileName, seriesImage.Image.ToStream(format, (!isLossless && (format == RasterImageFormat.Jpeg || format == RasterImageFormat.Cmp)) ? GetCompression(options.ImageCompression) : 0)); zip.Dispose(); } return(zip); }
public Stream PrintSeries(string userName, string[] seriesInstanceUIDs, PrintOptions options, string annotationData) { DocumentWriter documentWriterInstance = null; try { List <SeriesImage> seriesImages = _Exporter.GetSeriesImages(seriesInstanceUIDs); Dictionary <string, List <AnnContainer> > annotations = AddInsUtils.GetAnnotations(annotationData); documentWriterInstance = OpenDocumentWriterInstance(options.PageWidth, options.PageHeight, 300); string fileName = Path.GetTempFileName(); documentWriterInstance.BeginDocument(fileName, DocumentFormat.Pdf); foreach (SeriesImage si in seriesImages) { ProcessInstance(si, userName, options, annotations); { var page = new Leadtools.Document.Writer.DocumentWriterRasterPage(); page.Image = si.Image; documentWriterInstance.AddPage(page); } } documentWriterInstance.EndDocument(); MemoryStream ms = new MemoryStream(File.ReadAllBytes(fileName)); File.Delete(fileName); ms.Position = 0; return(ms); } finally { if (null != documentWriterInstance) { documentWriterInstance.EndDocument(); } } }
private void ProcessInstance(SeriesImage seriesImage, string userName, PrintOptions options, Dictionary <string, List <AnnContainer> > annotations) { ResetGrayscale(seriesImage.Image, options.ReduceGrayscaleTo8BitsSelected); List <DicomDataSet> ds = _Exporter.GetInstanceDatasets(new string[] { seriesImage.SOPInstanceUID }); double xDpi = 0; double yDpi = 0; if (ds.Count > 0) { AddInsUtils.GetDpi(ds[0], out xDpi, out yDpi); if (options.PatientInfo) { string name = ds[0].GetValue <string>(DicomTag.PatientName, string.Empty); string id = ds[0].GetValue <string>(DicomTag.PatientID, string.Empty); string sex = ds[0].GetValue <string>(DicomTag.PatientSex, string.Empty); string date = ds[0].GetValue <string>(DicomTag.SeriesDate, string.Empty); string icomments = ds[0].GetValue <string>(DicomTag.ImageComments, string.Empty); string fcomments = ds[0].GetValue <string>(DicomTag.FrameComments, string.Empty); string patientDOB = ds[0].GetValue <string>(DicomTag.PatientBirthDate, string.Empty); string seriesDecription = ds[0].GetValue <string>(DicomTag.SeriesDescription, string.Empty); string tag = string.Empty; if (!string.IsNullOrEmpty(name)) { tag += string.Format("Patient: {1}{0}", Environment.NewLine, name.Replace('^', ' ')); } if (!string.IsNullOrEmpty(id)) { tag += string.Format("Patient ID: {1}{0}", Environment.NewLine, id); } if (!string.IsNullOrEmpty(sex)) { tag += string.Format("Sex: {1}{0}", Environment.NewLine, sex); } if (!string.IsNullOrEmpty(date)) { tag += string.Format("Date: {1}{0}", Environment.NewLine, date); } if (!string.IsNullOrEmpty(icomments)) { tag += string.Format("Comments: {1}{0}", Environment.NewLine, icomments); } if (!string.IsNullOrEmpty(fcomments)) { tag += string.Format("Comments: {1}{0}", Environment.NewLine, fcomments); } if (options.LayoutPatientInfo) { tag = string.Empty; if (!string.IsNullOrEmpty(id)) { tag += string.Format("Patient ID: {1}{0}", Environment.NewLine, id); } if (!string.IsNullOrEmpty(name)) { tag += string.Format("Patient: {1}{0}", Environment.NewLine, name.Replace('^', ' ')); } if (!string.IsNullOrEmpty(patientDOB)) { tag += string.Format("Brith Date: {1}{0}", Environment.NewLine, patientDOB); } if (!string.IsNullOrEmpty(sex)) { tag += string.Format("Sex: {1}{0}", Environment.NewLine, sex); } if (!string.IsNullOrEmpty(date)) { tag += string.Format("Date: {1}{0}", Environment.NewLine, date); } if (!string.IsNullOrEmpty(seriesDecription)) { tag += string.Format("Description: {1}{0}", Environment.NewLine, date); } } if (!string.IsNullOrEmpty(tag)) { // adjust the text size based on the size of the output image. var imageTagged = AddTextFooter(seriesImage.Image, tag, options.LayoutPatientInfo ? Math.Max(100, seriesImage.Image.Height / 5) : 100); seriesImage.Image.Dispose(); seriesImage.Image = null; seriesImage.Image = imageTagged; } } } try { if (options.BurnAnnotations) { if (annotations.ContainsKey(seriesImage.SOPInstanceUID)) { foreach (AnnContainer container in annotations[seriesImage.SOPInstanceUID]) { container.IsVisible = true; seriesImage.Image.Burn(container, xDpi, yDpi); } } } } catch { }//ignored }
public Stream PrintLayout(string userName, string seriesInstanceUID, Layout layout, PrintOptions options, string annotationData) { DocumentWriter documentWriterInstance = null; // // Check to see if a width was provide. If not we default to 1024; // if (options.LayoutImageWidth == 0) { options.LayoutImageWidth = 1024; } SeriesImage layoutImageWithInfo = null; using (RasterImage layoutImage = AddInsUtils.CreateLayoutImage(options.LayoutImageWidth, options.WhiteBackground)) { try { options.LayoutPatientInfo = true; Dictionary <string, List <AnnContainer> > annotations = AddInsUtils.GetAnnotations(annotationData); foreach (var box in layout.Boxes) { if (null == box.referencedSOPInstanceUID) { continue; } if (0 == box.referencedSOPInstanceUID.Count) { continue; } //only the first instance List <SeriesImage> seriesImages = _Exporter.GetInstanceImages(new string[] { box.referencedSOPInstanceUID[0] }); if (null == seriesImages) { continue; } if (0 == seriesImages.Count) { continue; } // layout patient info check whether to print the patient information on each image or on the whole layout image. if (!options.LayoutPatientInfo) { //only the first image ProcessInstance(seriesImages[0], userName, options, annotations); } else { // take one of those series image to print them at the bottom of the final resultant image. if (layoutImageWithInfo == null) { layoutImageWithInfo = seriesImages[0]; } } AddInsUtils.LayoutImage(layoutImage, seriesImages[0].Image, box); } documentWriterInstance = OpenDocumentWriterInstance(options.PageWidth, options.PageHeight, 300); string fileName = Path.GetTempFileName(); documentWriterInstance.BeginDocument(fileName, DocumentFormat.Pdf); { var page = new Leadtools.Document.Writer.DocumentWriterRasterPage(); var finalImage = layoutImage; if (options.LayoutPatientInfo) { // add text to the bottom of the resultant image. layoutImageWithInfo.Image = layoutImage; ProcessInstance(layoutImageWithInfo, userName, options, null); finalImage = layoutImageWithInfo.Image; } page.Image = finalImage; documentWriterInstance.AddPage(page); } documentWriterInstance.EndDocument(); MemoryStream ms = new MemoryStream(File.ReadAllBytes(fileName)); File.Delete(fileName); ms.Position = 0; return(ms); } finally { if (null != documentWriterInstance) { documentWriterInstance.EndDocument(); } } } return(null); }