Ejemplo n.º 1
0
        private aim_dotnet.ImageStudy AimStudyFromAnnotation(aim_dotnet.Annotation annotation)
        {
            aim_dotnet.ImageAnnotation imageAnnotation = annotation as aim_dotnet.ImageAnnotation;

            if (imageAnnotation == null || imageAnnotation.ImageReferenceCollection.Count == 0)
            {
                return(null);
            }

            aim_dotnet.DICOMImageReference dicomImageReference = imageAnnotation.ImageReferenceCollection[0] as aim_dotnet.DICOMImageReference;
            if (dicomImageReference == null)
            {
                return(null);
            }

            if (dicomImageReference.Study == null || dicomImageReference.Study.Series == null ||
                dicomImageReference.Study.Series.ImageCollection == null || dicomImageReference.Study.Series.ImageCollection.Count == 0)
            {
                return(null);
            }

            return(dicomImageReference.Study);
        }
        private static bool AddDicomImageReference(aim_dotnet.ImageAnnotation imageAnnotation, IImageSopProvider image)
        {
            Platform.CheckForNullReference(imageAnnotation, "ImageAnnotation");
            if (imageAnnotation.ImageReferenceCollection == null)
                imageAnnotation.ImageReferenceCollection = new List<aim_dotnet.ImageReference>();
            var imageReferences = imageAnnotation.ImageReferenceCollection;
            aim_dotnet.ImageStudy aimImageStudy = null;
            foreach (var imgRef in imageReferences)
            {
                var dicomImgRef = imgRef as aim_dotnet.DICOMImageReference;
                if (dicomImgRef != null)
                {
                    if (dicomImgRef.Study.InstanceUID == image.ImageSop.StudyInstanceUid &&
                        dicomImgRef.Study.Series.InstanceUID == image.ImageSop.SeriesInstanceUid)
                        aimImageStudy = dicomImgRef.Study;
                }
            }
            if (aimImageStudy == null)
            {
                aimImageStudy = CreateStudy(image);
                aimImageStudy.Series = CreateSeries(image);
                aimImageStudy.Series.ImageCollection = new List<aim_dotnet.Image>();
                var dicomImgRef = new aim_dotnet.DICOMImageReference();
                dicomImgRef.Study = aimImageStudy;
                imageReferences.Add(dicomImgRef);
            }
            foreach (var existingImage in aimImageStudy.Series.ImageCollection)
            {
                if (existingImage.SopInstanceUID == image.ImageSop.SopInstanceUid)
                    return false;
            }
            var aimImage = CreateImage(image);
            aimImageStudy.Series.ImageCollection.Add(aimImage);

            return true;
        }
            public override void Execute()
            {
                List <AIMSearchResult>       results     = new List <AIMSearchResult>();
                List <aim_dotnet.Annotation> annotations = null;

                try
                {
                    if (_aimQueryParameters.AnnotationType == AnnotationType.ImageAnnotation)
                    {
                        AIMTCGAImageAnnotation aimService = new AIMTCGAImageAnnotation();
                        annotations = aimService.getImageAnnotationInfoList(_aimQueryParameters);
                    }
                    else if (_aimQueryParameters.AnnotationType == AnnotationType.AnnotationOfAnnotation)
                    {
                        AIMTCGAAnnotationOfAnnotation aimService = new AIMTCGAAnnotationOfAnnotation();
                        annotations = aimService.getAnnotationOfAnnotationInfoList(_aimQueryParameters);
                    }
                }
                catch (GridServicerException ex)
                {
                    SetError(string.Format("{0}. Contact your system administrator", ex.Message));
                }
                if (annotations != null)
                {
                    foreach (aim_dotnet.Annotation annotation in annotations)
                    {
                        AIMSearchResult result = new AIMSearchResult();
                        result.RetrievedAnnotation = annotation;
                        if (annotation.AnatomyEntityCollection != null)
                        {
                            foreach (aim_dotnet.AnatomicEntity anatomicEntity in annotation.AnatomyEntityCollection)
                            {
                                AnatomicEntity ae = new AnatomicEntity();
                                ae.CodeValue              = anatomicEntity.CodeValue;
                                ae.CodeMeaning            = anatomicEntity.CodeMeaning;
                                ae.CodingSchemeDesignator = anatomicEntity.CodingSchemeDesignator;
                                result.AnatomicEntities.Add(ae);

                                if (anatomicEntity.AnatomicEntityCharacteristicCollection != null)
                                {
                                    foreach (aim_dotnet.AnatomicEntityCharacteristic characteristic in anatomicEntity.AnatomicEntityCharacteristicCollection)
                                    {
                                        AnatomicEntityCharacteristic aec = new AnatomicEntityCharacteristic();
                                        aec.CodeValue              = characteristic.CodeValue;
                                        aec.CodeMeaning            = characteristic.CodeMeaning;
                                        aec.CodingSchemeDesignator = characteristic.CodingSchemeDesignator;
                                        result.AnatomicEntityCharacteristics.Add(aec);
                                    }
                                }
                            }
                        }
                        if (annotation.ImagingObservationCollection != null)
                        {
                            foreach (aim_dotnet.ImagingObservation imagingObservation in annotation.ImagingObservationCollection)
                            {
                                ImagingObservation io = new ImagingObservation();
                                io.CodeValue              = imagingObservation.CodeValue;
                                io.CodeMeaning            = imagingObservation.CodeMeaning;
                                io.CodingSchemeDesignator = imagingObservation.CodingSchemeDesignator;
                                result.ImagingObservations.Add(io);

                                if (imagingObservation.ImagingObservationCharacteristicCollection != null)
                                {
                                    foreach (aim_dotnet.ImagingObservationCharacteristic characteristic in imagingObservation.ImagingObservationCharacteristicCollection)
                                    {
                                        ImagingObservationCharacteristic ioc = new ImagingObservationCharacteristic();
                                        ioc.CodeValue              = characteristic.CodeValue;
                                        ioc.CodeMeaning            = characteristic.CodeMeaning;
                                        ioc.CodingSchemeDesignator = characteristic.CodingSchemeDesignator;
                                        ioc.Comment = characteristic.Comment;
                                        result.ImagingObservationCharacteristics.Add(ioc);
                                    }
                                }
                            }
                        }
                        if (annotation.User != null)
                        {
                            User user = new User();
                            user.Name        = annotation.User.Name;
                            user.LoginName   = annotation.User.LoginName;
                            user.RoleInTrial = annotation.User.RoleInTrial;
                            user.NumberWithinRoleInClinicalTrial = annotation.User.NumberWithinRoleOfClinicalTrial;
                            result.User = user;
                        }
                        if (annotation is aim_dotnet.ImageAnnotation)
                        {
                            aim_dotnet.ImageAnnotation imageAnnotation = (aim_dotnet.ImageAnnotation)annotation;

                            // Study Instance UID
                            if (imageAnnotation.ImageReferenceCollection != null && imageAnnotation.ImageReferenceCollection.Count > 0)
                            {
                                aim_dotnet.DICOMImageReference dicomImageReference =
                                    imageAnnotation.ImageReferenceCollection[0] as aim_dotnet.DICOMImageReference;
                                if (dicomImageReference != null)
                                {
                                    result.Study.StudyInstanceUid = dicomImageReference.Study.InstanceUID;
                                }
                            }

                            if (imageAnnotation.Patient != null)
                            {
                                result.Patient.PatientId        = imageAnnotation.Patient.Id.ToString();
                                result.Patient.PatientsName     = imageAnnotation.Patient.Name;
                                result.Patient.PatientsSex      = imageAnnotation.Patient.Sex;
                                result.Patient.PatientBirthDate = imageAnnotation.Patient.BirthDate;
                            }

                            foreach (aim_dotnet.ImageReference imageReference in imageAnnotation.ImageReferenceCollection)
                            {
                                if (imageReference is aim_dotnet.DICOMImageReference)
                                {
                                    aim_dotnet.DICOMImageReference dicomImageReference = (aim_dotnet.DICOMImageReference)imageReference;
                                    result.Series.SeriesInstanceUid = ((dicomImageReference.Study ?? new aim_dotnet.ImageStudy()).Series ?? new aim_dotnet.ImageSeries()).InstanceUID;
                                }
                            }
                        }

                        results.Add(result);
                    }
                }

                AddResultsToTable(results);

                OnCommandExecuted();
            }