Dicom.Data.DcmDataset.AddElementWithValue C# (CSharp) Method

AddElementWithValue() public method

public AddElementWithValue ( Dicom.Data.DicomTag tag, System.DateTime value ) : bool
tag Dicom.Data.DicomTag
value System.DateTime
return bool
        public bool AddElementWithValue(DicomTag tag, DateTime value)
        {
            DicomVR vr = tag.Entry.DefaultVR;
            if (vr != DicomVR.DA && vr != DicomVR.DT && vr != DicomVR.TM)
                throw new DicomDataException("Tried to create element with incorrect VR");
            if (AddElement(tag, vr)) {
                if (vr == DicomVR.DA)
                    GetDA(tag).SetDateTime(value);
                else if (vr == DicomVR.DT)
                    GetDT(tag).SetDateTime(value);
                else if (vr == DicomVR.TM)
                    GetTM(tag).SetDateTime(value);
                return true;
            }
            return false;
        }

Same methods

DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, Dicom.Data.DicomTag value ) : bool
DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, DicomUID value ) : bool
DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, decimal value ) : bool
DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, double value ) : bool
DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, int value ) : bool
DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, string value ) : bool
DcmDataset::AddElementWithValue ( Dicom.Data.DicomTag tag, ushort value ) : bool

Usage Example

Example #1
1
        protected override void OnReceiveCFindRequest(byte presentationID, ushort messageID, DcmPriority priority, Dicom.Data.DcmDataset query)
        {
            TryInterpretStringsInDatasetUsingCorrectEncoding(query);

            Trace.WriteLine(String.Format("{0} Receive C-Find from {1} (marked as anonymous:{2})", DateTime.Now, this.Associate.CallingAE, _flagAnonymousAccess));
            Trace.WriteLine(query.Dump());

               using( var database = new MedicalISDataContext() )
            {
                var queryLevel = query.GetString(DicomTags.QueryRetrieveLevel, null);

                if (queryLevel == "PATIENT")
                {
                    IQueryable<Patient> patients = PatientQueries.GetMatchingPatients(database, query, _flagAnonymousAccess);

                    patients = patients.Take(Settings.Default.MaxNumberOfStudiesReturned);

                    foreach (var currentPatient in patients)
                    {
                        foreach (var currentStudy in currentPatient.Studies)
                        {
                            var p = currentPatient;

                            var response = new DcmDataset
                            {
                                SpecificCharacterSetEncoding = query.SpecificCharacterSetEncoding
                            };

                            // Map saved study tags to output

                            response.AddElementWithValue(DicomTags.RetrieveAETitle, "CURAPACS");
                            response.AddElementWithValue(DicomTags.QueryRetrieveLevel, "PATIENT");

                            response.AddElementWithValue(DicomTags.PatientID, p.ExternalPatientID);
                            response.AddElementWithValue(DicomTags.PatientsName, p.LastName + "^" + p.FirstName);
                            response.AddElementWithValue(DicomTags.PatientsBirthDate, p.BirthDateTime.Value);

                            response.AddElementWithValue(DicomTags.StudyInstanceUID, currentStudy.StudyInstanceUid);
                            response.AddElementWithValue(DicomTags.AccessionNumber, currentStudy.AccessionNumber);
                            response.AddElementWithValue(DicomTags.StudyDescription, currentStudy.Description);
                            response.AddElementWithValue(DicomTags.ModalitiesInStudy, currentStudy.ModalityAggregation);

                            if (currentStudy.PerformedDateTime.HasValue)
                            {
                                response.AddElementWithValue(DicomTags.StudyDate, currentStudy.PerformedDateTime.Value);
                                response.AddElementWithValue(DicomTags.StudyTime, currentStudy.PerformedDateTime.Value);
                            }

                            response.AddElementWithValue(DicomTags.NumberOfStudyRelatedSeries, currentStudy.Series.Count);
                            response.AddElementWithValue(DicomTags.NumberOfStudyRelatedInstances, (from s in currentStudy.Series select s.Images.Count).Sum());

                            if (_flagAnonymousAccess)
                                AnonymizeDatasetBasedOnStudyInfo(response);

                            SendCFindResponse(presentationID, messageID, response, DcmStatus.Pending);
                        }
                    }
                }
                else if (queryLevel == "STUDY")
                {
                    IQueryable<Study> studies = StudyQueries.GetMatchingStudies(database, query, _flagAnonymousAccess);

                    studies = studies.Take(Settings.Default.MaxNumberOfStudiesReturned);

                    foreach (var currentStudy in studies)
                    {
                        var p = currentStudy.Patient;

                        var response = new DcmDataset
                                           {
                                               SpecificCharacterSetEncoding = query.SpecificCharacterSetEncoding
                                           };

                        // Map saved study tags to output

                        response.AddElementWithValue(DicomTags.RetrieveAETitle, "CURAPACS");
                        response.AddElementWithValue(DicomTags.QueryRetrieveLevel, "STUDY");

                        response.AddElementWithValue(DicomTags.PatientID, p.ExternalPatientID);
                        response.AddElementWithValue(DicomTags.PatientsName, p.LastName + "^" + p.FirstName);
                        response.AddElementWithValue(DicomTags.PatientsBirthDate, p.BirthDateTime.Value);

                        response.AddElementWithValue(DicomTags.StudyInstanceUID, currentStudy.StudyInstanceUid);
                        response.AddElementWithValue(DicomTags.AccessionNumber, currentStudy.AccessionNumber);
                        response.AddElementWithValue(DicomTags.StudyDescription, currentStudy.Description);
                        response.AddElementWithValue(DicomTags.ModalitiesInStudy, currentStudy.ModalityAggregation);

                        if (currentStudy.PerformedDateTime.HasValue)
                        {
                            response.AddElementWithValue(DicomTags.StudyDate, currentStudy.PerformedDateTime.Value);
                            response.AddElementWithValue(DicomTags.StudyTime, currentStudy.PerformedDateTime.Value);
                        }

                        response.AddElementWithValue(DicomTags.NumberOfStudyRelatedSeries, currentStudy.Series.Count);
                        response.AddElementWithValue(DicomTags.NumberOfStudyRelatedInstances, (from s in currentStudy.Series select s.Images.Count).Sum());

                        if (! String.IsNullOrEmpty(query.GetString(DicomTags.PatientsSex, null)))
                        {
                            response.AddElementWithValue(DicomTags.PatientsSex, Settings.Default.AlwaysRespondWithGender);
                        }

                        if(_flagAnonymousAccess)
                            AnonymizeDatasetBasedOnStudyInfo(response);

                        Trace.WriteLine("response  (STUDY): > ");
                        Trace.WriteLine(response.Dump());

                        SendCFindResponse(presentationID, messageID, response, DcmStatus.Pending);
                    }
                }
                else if (queryLevel == "SERIES")
                {
                    IQueryable<Series> series = SeriesQueries.GetMatchingSeries(database, query);

                    foreach (var currentSeries in series)
                    {
                        var response = new DcmDataset
                        {
                            SpecificCharacterSetEncoding = query.SpecificCharacterSetEncoding
                        };

                        if (currentSeries.PerformedDateTime.HasValue)
                        {
                            response.AddElementWithValue(DicomTags.SeriesDate, currentSeries.PerformedDateTime.Value);
                            response.AddElementWithValue(DicomTags.SeriesTime, currentSeries.PerformedDateTime.Value);
                        }

                        response.AddElementWithValue(DicomTags.QueryRetrieveLevel, "SERIES");

                        response.AddElementWithValue(DicomTags.StudyInstanceUID, currentSeries.StudyInstanceUid);
                        response.AddElementWithValue(DicomTags.SeriesInstanceUID, currentSeries.SeriesInstanceUid);
                        response.AddElementWithValue(DicomTags.SeriesNumber, currentSeries.SeriesNumber);
                        response.AddElementWithValue(DicomTags.SeriesDescription, currentSeries.Description);
                        response.AddElementWithValue(DicomTags.Modality, currentSeries.PerformedModalityType);

                        response.AddElementWithValue(DicomTags.NumberOfSeriesRelatedInstances, currentSeries.Images.Count());
                        response.AddElementWithValue(DicomTags.ReferringPhysiciansName, "");
                        response.AddElementWithValue(DicomTags.StudyCommentsRETIRED, "");

                        SendCFindResponse(presentationID, messageID, response, DcmStatus.Pending);
                    }
                }

                SendCFindResponse(presentationID, messageID, DcmStatus.Success);
            }
        }
All Usage Examples Of Dicom.Data.DcmDataset::AddElementWithValue