Beispiel #1
0
        private void UpdateImageBox(DcmImageBox imageBox, String filename, int index)
        {
            //try
            //{
            var ff = new DicomFileFormat();

            ff.Load(filename, DicomReadOptions.DefaultWithoutDeferredLoading);
            if (ff.Dataset == null)
            {
                return;
            }

            ff.Dataset.ChangeTransferSyntax(DicomTransferSyntax.ImplicitVRLittleEndian, null);

            var pixelData = new DcmPixelData(ff.Dataset);
            var pi        = PhotometricInterpretation.Lookup(pixelData.PhotometricInterpretation);

            // Grayscale only printer?
            if (pi.IsColor && _supportsColorPrinting == false)
            {
                pixelData.Unload();
                return;
            }

            // Color only printer?
            if (pi.IsColor == false && _supportsGrayscalePrinting == false)
            {
                pixelData.Unload();
                return;
            }

            DicomUID        imageBoxSOPClassUID;
            DcmItemSequence seq;
            var             item = new DcmItemSequenceItem();

            pixelData.UpdateDataset(item.Dataset);

            if (pi.IsColor)
            {
                imageBoxSOPClassUID = DicomUID.BasicColorImageBoxSOPClass;
                seq = new DcmItemSequence(DicomTags.BasicColorImageSequence);
            }
            else
            {
                imageBoxSOPClassUID = DicomUID.BasicGrayscaleImageBoxSOPClass;
                seq = new DcmItemSequence(DicomTags.BasicGrayscaleImageSequence);
            }
            seq.AddSequenceItem(item);
            imageBox.Dataset.AddItem(seq);

            pixelData.Unload();

            imageBox.UpdateImageBox(imageBoxSOPClassUID);
            imageBox.ImageBoxPosition = (ushort)index;
            //}
            //catch (Exception)
            //{
            //}
        }
Beispiel #2
0
        protected override void AdditionalMembers(DcmDataset dataset)
        {
            dataset.AddElement(DicomTags.PatientsBirthDate);
            dataset.AddElement(DicomTags.PatientsSex);
            dataset.AddElement(DicomTags.PatientsAge);
            dataset.AddElement(DicomTags.PatientsSize);
            dataset.AddElement(DicomTags.PatientsWeight);
            dataset.AddElement(DicomTags.MedicalAlerts);
            dataset.AddElement(DicomTags.PregnancyStatus);
            dataset.AddElement(DicomTags.Allergies);              //*Contrast allergies??
            dataset.AddElement(DicomTags.PatientComments);
            dataset.AddElement(DicomTags.SpecialNeeds);           //*
            dataset.AddElement(DicomTags.PatientState);           //*
            dataset.AddElement(DicomTags.CurrentPatientLocation); //*
            dataset.AddElement(DicomTags.InstitutionName);
            dataset.AddElement(DicomTags.AdmissionID);
            dataset.AddElement(DicomTags.AccessionNumber);
            dataset.AddElement(DicomTags.ReferringPhysiciansName);
            dataset.AddElement(DicomTags.AdmittingDiagnosesDescription);
            dataset.AddElement(DicomTags.RequestingPhysician);
            dataset.AddElement(DicomTags.StudyInstanceUID);
            dataset.AddElement(DicomTags.RequestedProcedureDescription);
            dataset.AddElement(DicomTags.RequestedProcedureID);
            dataset.AddElement(DicomTags.ReasonForTheRequestedProcedure);
            dataset.AddElement(DicomTags.RequestedProcedurePriority);

            dataset.AddElement(DicomTags.StudyDate);            //*
            dataset.AddElement(DicomTags.StudyTime);            //*

            //DicomTags.RequestedProcedureCodeSequence
            //DicomTags.ScheduledProtocolCodeSequence

            DcmItemSequenceItem sps = new DcmItemSequenceItem();

            sps.Dataset.AddElementWithValue(DicomTags.ScheduledStationAETitle, ScheduledStationAE);
            sps.Dataset.AddElement(DicomTags.ScheduledProcedureStepStartDate);
            sps.Dataset.GetDA(DicomTags.ScheduledProcedureStepStartDate).SetDateTimeRange(ScheduledProcedureStepStartDate);
            sps.Dataset.AddElement(DicomTags.ScheduledProcedureStepStartTime);
            sps.Dataset.GetTM(DicomTags.ScheduledProcedureStepStartTime).SetDateTimeRange(ScheduledProcedureStepStartTime);
            sps.Dataset.AddElementWithValue(DicomTags.Modality, Modality);
            sps.Dataset.AddElement(DicomTags.ScheduledPerformingPhysiciansName);
            sps.Dataset.AddElement(DicomTags.ScheduledProcedureStepDescription);
            sps.Dataset.AddElement(DicomTags.ScheduledProcedureStepLocation);
            sps.Dataset.AddElement(DicomTags.ScheduledProcedureStepID);

            DcmItemSequence sq = new DcmItemSequence(DicomTags.ScheduledProcedureStepSequence);

            sq.AddSequenceItem(sps);
            dataset.AddItem(sq);
        }
Beispiel #3
0
 public override void FromDataset(DcmDataset dataset)
 {
     //dataset.Dump();
     _dataset = dataset;
     dataset.LoadDicomFields(this);
     if (dataset.Contains(DicomTags.ScheduledProcedureStepSequence))
     {
         DcmItemSequence sq = dataset.GetSQ(DicomTags.ScheduledProcedureStepSequence);
         if (sq.SequenceItems.Count > 0)
         {
             DcmItemSequenceItem sps = sq.SequenceItems[0];
             Modality = sps.Dataset.GetString(DicomTags.Modality, String.Empty);
             ScheduledStationAETitle           = sps.Dataset.GetString(DicomTags.ScheduledStationAETitle, String.Empty);
             ScheduledProcedureStartDate       = sps.Dataset.GetDateTime(DicomTags.ScheduledProcedureStepStartDate, 0, DateTime.MinValue);
             ScheduledProcedureStartTime       = sps.Dataset.GetDateTime(DicomTags.ScheduledProcedureStepStartTime, 0, DateTime.MinValue);
             ScheduledPerformingPhysicianName  = sps.Dataset.GetString(DicomTags.ScheduledPerformingPhysiciansName, String.Empty);
             ScheduledProcedureStepDescription = sps.Dataset.GetString(DicomTags.ScheduledProcedureStepDescription, String.Empty);
             ScheduledProcedureStepID          = sps.Dataset.GetString(DicomTags.ScheduledProcedureStepID, String.Empty);
             ScheduledProcedureStepLocation    = sps.Dataset.GetString(DicomTags.ScheduledProcedureStepLocation, String.Empty);
         }
     }
 }
Beispiel #4
0
        private DicomReadStatus InsertSequenceItem(DicomReadOptions options)
        {
            if (_tag.Equals(DicomTags.Item))
            {
                if (_len != UndefinedLength && _len > _remain)
                {
                    return(NeedMoreData(_len));
                }

                if (_sds.Count > _sqs.Count)
                {
                    _sds.Pop();
                }

                DcmItemSequenceItem si = new DcmItemSequenceItem(_pos, _len);

                if (_len != UndefinedLength || (_stream.CanSeek && Flags.IsSet(options, DicomReadOptions.AllowSeekingForContext)))
                {
                    if (_len == UndefinedLength)
                    {
                        options |= DicomReadOptions.SequenceItemOnly;
                    }

                    DcmDataset      ds     = null;
                    DicomReadStatus status = ParseSequenceItemDataset(TransferSyntax, _len, out ds, options);

                    if (status != DicomReadStatus.Success)
                    {
                        Dicom.Debug.Log.Warn("Unknown error while attempting to read sequence item.  Trying again with alternate encodings.");

                        DicomTransferSyntax[] syntaxes = null;
                        if (TransferSyntax == DicomTransferSyntax.ExplicitVRBigEndian)
                        {
                            syntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRLittleEndian }
                        }
                        ;
                        else if (TransferSyntax.IsExplicitVR)
                        {
                            syntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRBigEndian }
                        }
                        ;
                        else
                        {
                            syntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ExplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRBigEndian }
                        };

                        foreach (DicomTransferSyntax tx in syntaxes)
                        {
                            status = ParseSequenceItemDataset(tx, _len, out ds, options);
                            if (status == DicomReadStatus.Success)
                            {
                                break;
                            }
                        }
                    }

                    if (status != DicomReadStatus.Success)
                    {
                        return(DicomReadStatus.UnknownError);
                    }

                    si.Dataset = ds;

                    if (_len == UndefinedLength)
                    {
                        if (8 > _remain)
                        {
                            // need more data?
                            _sds.Push(ds);
                        }
                        else
                        {
                            // skip delimitation item
                            _stream.Seek(8, SeekOrigin.Current);
                            _remain -= 8;
                            _bytes  += 8;
                            _read   += 8;
                        }
                    }
                }
                else
                {
                    DcmDataset ds = new DcmDataset(_pos + 8, _len, TransferSyntax);
                    _sds.Push(ds);
                }

                _sqs.Peek().AddSequenceItem(si);
            }
            else if (_tag == DicomTags.ItemDelimitationItem)
            {
                if (_sds.Count == _sqs.Count)
                {
                    _sds.Pop();
                }
            }
            else if (_tag == DicomTags.SequenceDelimitationItem)
            {
                if (_sds.Count == _sqs.Count)
                {
                    _sds.Pop();
                }
                _sqs.Pop();
            }
            return(DicomReadStatus.Success);
        }