#region License // Copyright (c) 2010, Jasper Yeh. // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither the name of ClearCanvas Inc. nor the names of its contributors // may be used to endorse or promote products derived from this software without // specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY // OF SUCH DAMAGE. #endregion using System.Collections.Generic; using ClearCanvas.Common; using ClearCanvas.Dicom.Utilities; using ClearCanvas.ImageViewer.Annotations; using ClearCanvas.ImageViewer.Annotations.Dicom; using ClearCanvas.ImageViewer.StudyManagement; using DicomTags=Nullstack.ClearCanvasEx.ViewerEx.AnnotationProviders.Backports.DicomTags; using SopClass=Nullstack.ClearCanvasEx.ViewerEx.AnnotationProviders.Backports.SopClass; namespace Nullstack.ClearCanvasEx.ViewerEx.AnnotationProviders { [ExtensionOf(typeof (AnnotationItemProviderExtensionPoint))] public class PTImageAnnotationItemProvider : AnnotationItemProvider { private readonly List _annotationItems; public PTImageAnnotationItemProvider() : base("AnnotationItemProviders.Dicom.PTImage", new AnnotationResourceResolver(typeof (PTImageAnnotationItemProvider).Assembly)) { _annotationItems = new List(); AnnotationResourceResolver resolver = new AnnotationResourceResolver(this); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.DecayCorrectedString", resolver, frame => GetCorrection(frame, "DECY", DicomTags.DecayCorrected, "DECY", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.DecayCorrected", resolver, frame => GetCorrectionValue(frame, "DECY", DicomTags.DecayCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.AttenuationCorrectedString", resolver, frame => GetCorrection(frame, "ATTN", DicomTags.AttenuationCorrected, "ATTN", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.AttenuationCorrected", resolver, frame => GetCorrectionValue(frame, "ATTN", DicomTags.AttenuationCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.ScatterCorrectedString", resolver, frame => GetCorrection(frame, "SCAT", DicomTags.ScatterCorrected, "SCAT", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.ScatterCorrected", resolver, frame => GetCorrectionValue(frame, "SCAT", DicomTags.ScatterCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.DeadTimeCorrectedString", resolver, frame => GetCorrection(frame, "DTIM", DicomTags.DeadTimeCorrected, "DTIM", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.DeadTimeCorrected", resolver, frame => GetCorrectionValue(frame, "DTIM", DicomTags.DeadTimeCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.GantryMotionCorrectedString", resolver, frame => GetCorrection(frame, "MOTN", DicomTags.GantryMotionCorrected, "MOTN", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.GantryMotionCorrected", resolver, frame => GetCorrectionValue(frame, "MOTN", DicomTags.GantryMotionCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.PatientMotionCorrectedString", resolver, frame => GetCorrection(frame, "PMOT", DicomTags.PatientMotionCorrected, "PMOT", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.PatientMotionCorrected", resolver, frame => GetCorrectionValue(frame, "PMOT", DicomTags.PatientMotionCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.CountLossNormalizationString", resolver, frame => GetCorrection(frame, "CLN", DicomTags.CountLossNormalizationCorrected, "CLN", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.CountLossNormalizationString", resolver, frame => GetCorrectionValue(frame, "CLN", DicomTags.CountLossNormalizationCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.RandomsCorrectedString", resolver, frame => GetCorrection(frame, "RAN", DicomTags.RandomsCorrected, "RAN", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.RandomsCorrectedString", resolver, frame => GetCorrectionValue(frame, "RAN", DicomTags.RandomsCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.NonUniformRadialSamplingCorrectedString", resolver, frame => GetCorrection(frame, "RADL", DicomTags.NonUniformRadialSamplingCorrected, "RADL", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.NonUniformRadialSamplingCorrectedString", resolver, frame => GetCorrectionValue(frame, "RADL", DicomTags.NonUniformRadialSamplingCorrected), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.SensitivityCalibratedUsingDoseCalibratorString", resolver, frame => GetCorrection(frame, "DCAL", DicomTags.SensitivityCalibrated, "DCAL", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.SensitivityCalibratedUsingDoseCalibratorString", resolver, frame => GetCorrectionValue(frame, "DCAL", DicomTags.SensitivityCalibrated), FormatBoolean ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.DetectorNormalizationString", resolver, frame => GetCorrection(frame, "NORM", DicomTags.DetectorNormalizationCorrection, "NORM", string.Empty), DicomDataFormatHelper.RawStringFormat ) ); _annotationItems.Add ( new DicomAnnotationItem ( "Dicom.PTImage.DetectorNormalizationString", resolver, frame => GetCorrectionValue(frame, "NORM", DicomTags.DetectorNormalizationCorrection), FormatBoolean ) ); } public override IEnumerable GetAnnotationItems() { return _annotationItems; } private static string FormatBoolean(bool value) { return DicomDataFormatHelper.BooleanFormatter(value ? "\u0001" : "\0"); } private static string GetCorrection(Frame frame, string correctedImageTerm, uint? specificCorrectionTag, string displayCorrected, string displayNotCorrected) { bool corrected = GetCorrectionValue(frame, correctedImageTerm, specificCorrectionTag); return corrected ? displayCorrected : displayNotCorrected; } private static bool GetCorrectionValue(Frame frame, string correctedImageTerm, uint? specificCorrectionTag) { bool corrected = false; if (frame.ParentImageSop.SopClassUid == SopClass.EnhancedPetImageStorageUid && specificCorrectionTag.HasValue) { string value = frame.ParentImageSop[specificCorrectionTag.Value].ToString(); if (!string.IsNullOrEmpty(value) && value.ToUpperInvariant() == "YES") corrected |= true; } string correctedImageValue = frame.ParentImageSop[DicomTags.CorrectedImage].ToString(); if (!string.IsNullOrEmpty(correctedImageValue)) { List corrections = new List(DicomStringHelper.GetStringArray(correctedImageValue.ToUpperInvariant())); if (corrections.Contains(correctedImageTerm)) corrected |= true; } return corrected; } } }