public DicomCompressedPixelData(DicomMessageBase msg, byte[] frameData) : base(msg) { _sq = new DicomFragmentSequence(DicomTags.PixelData); AddFrameFragment(frameData); //ByteBuffer buffer = new ByteBuffer(frameData); //DicomFragment fragment = new DicomFragment(buffer); //_sq.AddFragment(fragment); NumberOfFrames = 1; }
/// <summary> /// Updat ethe pixel data related tags in a DICOM message. /// </summary> /// <param name="message"></param> public abstract void UpdateMessage(DicomMessageBase message);
/// <summary> /// Constructor. /// </summary> /// <param name="message"></param> protected DicomPixelData(DicomMessageBase message) : this(message.DataSet) { _transferSyntax = message.TransferSyntax; }
/// <summary> /// Creates an instance of <see cref="DicomPixelData"/> from specified dicom message /// </summary> /// <param name="message"></param> /// <returns> /// </returns> public static DicomPixelData CreateFrom(DicomMessageBase message) { if (message.TransferSyntax.LosslessCompressed || message.TransferSyntax.LossyCompressed) return new DicomCompressedPixelData(message); return new DicomUncompressedPixelData(message); }
/// <summary> /// Initializes a <see cref="DicomUncompressedPixelData"/> from the attributes in a DICOM file/message. /// </summary> /// <param name="dicomMessage">A DICOM file/message from which to initialize the properties of the <see cref="DicomUncompressedPixelData"/>.</param> public DicomUncompressedPixelData(DicomMessageBase dicomMessage) : base(dicomMessage) { _pd = dicomMessage.DataSet[DicomTags.PixelData]; InitializeFrameData(this, _pd); }
/// <summary> /// Update a <see cref="DicomMessageBase"/> with the pixel data contained /// within this object and also update pixel data related tags. /// </summary> /// <param name="message"></param> public override void UpdateMessage(DicomMessageBase message) { UpdateAttributeCollection(message.DataSet); DicomFile file = message as DicomFile; if (file != null) file.TransferSyntax = TransferSyntax; }
/// <summary> /// Create a Series Directory Record /// </summary> /// <param name="dicomFile">The dicom file.</param> private static DirectoryRecordSequenceItem CreateSeriesItem(DicomMessageBase dicomFile) { IDictionary<uint, object> dicomTags = new Dictionary<uint, object>(); dicomTags.Add(DicomTags.SeriesInstanceUid, null); dicomTags.Add(DicomTags.Modality, null); dicomTags.Add(DicomTags.SeriesDate, null); dicomTags.Add(DicomTags.SeriesTime, null); dicomTags.Add(DicomTags.SeriesNumber, null); dicomTags.Add(DicomTags.SeriesDescription, null); //dicomTags.Add(DicomTags.SeriesDescription, dicomFile.DataSet[DicomTags.SeriesDescription].GetString(0, String.Empty)); return AddSequenceItem(DirectoryRecordType.Series, dicomFile.DataSet, dicomTags); }
/// <summary> /// Create a Study Directory Record /// </summary> /// <param name="dicomFile">The dicom file.</param> private static DirectoryRecordSequenceItem CreateStudyItem(DicomMessageBase dicomFile) { IDictionary<uint, object> dicomTags = new Dictionary<uint, object>(); dicomTags.Add(DicomTags.StudyInstanceUid, null); dicomTags.Add(DicomTags.StudyId, null); dicomTags.Add(DicomTags.StudyDate, null); dicomTags.Add(DicomTags.StudyTime, null); dicomTags.Add(DicomTags.AccessionNumber, null); dicomTags.Add(DicomTags.StudyDescription, null); return AddSequenceItem(DirectoryRecordType.Study, dicomFile.DataSet, dicomTags); }
/// <summary> /// Create a Patient Directory Record /// </summary> /// <param name="dicomFile">The dicom file or message.</param> private static DirectoryRecordSequenceItem CreatePatientItem(DicomMessageBase dicomFile) { if (dicomFile == null) throw new ArgumentNullException("dicomFile"); IDictionary<uint, object> dicomTags = new Dictionary<uint, object>(); dicomTags.Add(DicomTags.PatientsName, null); dicomTags.Add(DicomTags.PatientId, null); dicomTags.Add(DicomTags.PatientsBirthDate, null); dicomTags.Add(DicomTags.PatientsSex, null); return AddSequenceItem(DirectoryRecordType.Patient, dicomFile.DataSet, dicomTags); }
/// <summary> /// Traverse at the Series level to check if a Series exists, or create a Series if it doesn't exist. /// </summary> /// <param name="series"></param> /// <param name="file"></param> /// <returns></returns> private static DirectoryRecordSequenceItem GetExistingOrCreateNewSeries(DirectoryRecordSequenceItem series, DicomMessageBase file) { DirectoryRecordSequenceItem currentSeries = series; while (currentSeries != null) { if (currentSeries[DicomTags.SeriesInstanceUid].Equals(file.DataSet[DicomTags.SeriesInstanceUid])) { return currentSeries; } if (currentSeries.NextDirectoryRecord == null) { currentSeries.NextDirectoryRecord = CreateSeriesItem(file); return currentSeries.NextDirectoryRecord; } currentSeries = currentSeries.NextDirectoryRecord; } return null; }
/// <summary> /// Traverse at the Study level to check if a Study exists or create a Study if it doesn't exist. /// </summary> /// <param name="studies"></param> /// <param name="file"></param> /// <returns></returns> private static DirectoryRecordSequenceItem GetExistingOrCreateNewStudy(DirectoryRecordSequenceItem studies, DicomMessageBase file) { DirectoryRecordSequenceItem currentStudy = studies; while (currentStudy != null) { if (currentStudy[DicomTags.StudyInstanceUid].Equals(file.DataSet[DicomTags.StudyInstanceUid])) { return currentStudy; } if (currentStudy.NextDirectoryRecord == null) { currentStudy.NextDirectoryRecord = CreateStudyItem(file); return currentStudy.NextDirectoryRecord; } currentStudy = currentStudy.NextDirectoryRecord; } return null; }
/// <summary> /// Traverse at the Patient level to check if a Patient exists or create a Patient if it doesn't exist. /// </summary> /// <param name="patients"></param> /// <param name="file"></param> /// <returns></returns> private static DirectoryRecordSequenceItem GetExistingOrCreateNewPatient(DirectoryRecordSequenceItem patients, DicomMessageBase file) { DirectoryRecordSequenceItem currentPatient = patients; while (currentPatient != null) { if (currentPatient[DicomTags.PatientId].Equals(file.DataSet[DicomTags.PatientId]) && currentPatient[DicomTags.PatientsName].Equals(file.DataSet[DicomTags.PatientsName])) { return currentPatient; } if (currentPatient.NextDirectoryRecord == null) { currentPatient.NextDirectoryRecord = CreatePatientItem(file); return currentPatient.NextDirectoryRecord; } currentPatient = currentPatient.NextDirectoryRecord; } return null; }
public void Insert(DicomMessageBase dicomMessage) { if (dicomMessage.DataSet == null) { throw new ArgumentException(); } var patient = new Patient { PatientId = dicomMessage.DataSet[DicomTags.PatientId].GetString(0, string.Empty), PatientName = dicomMessage.DataSet[DicomTags.PatientsName].GetString(0, string.Empty), PatientBirthDate = dicomMessage.DataSet[DicomTags.PatientsBirthDate].GetString(0, string.Empty), Issuer = dicomMessage.DataSet[DicomTags.IssuerOfPatientId].GetString(0, string.Empty), }; var study = new Study() { StudyId = dicomMessage.DataSet[DicomTags.StudyId].GetString(0, string.Empty), StudyUid = dicomMessage.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty), AccessionNumber = dicomMessage.DataSet[DicomTags.AccessionNumber].GetString(0, string.Empty), StudyDate = dicomMessage.DataSet[DicomTags.StudyDate].GetString(0, string.Empty), StudyTime = dicomMessage.DataSet[DicomTags.StudyTime].GetString(0, string.Empty), RefPhysician = dicomMessage.DataSet[DicomTags.ReferringPhysiciansName].GetString(0, string.Empty), StudyDescription = dicomMessage.DataSet[DicomTags.StudyDescription].GetString(0, string.Empty), PatientAge = dicomMessage.DataSet[DicomTags.PatientsAge].GetString(0, string.Empty), PatientSize = dicomMessage.DataSet[DicomTags.PatientsSize].GetString(0, string.Empty), PatientWeight = dicomMessage.DataSet[DicomTags.PatientsWeight].GetString(0, string.Empty), PatientSex = dicomMessage.DataSet[DicomTags.PatientsSex].GetString(0, string.Empty) }; var series = new Series() { SeriesUid = dicomMessage.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty), SeriesNumber = dicomMessage.DataSet[DicomTags.SeriesNumber].GetString(0, string.Empty), Modality = dicomMessage.DataSet[DicomTags.Modality].GetString(0, string.Empty), BodyPart = dicomMessage.DataSet[DicomTags.BodyPartExamined].GetString(0, string.Empty), Institution = dicomMessage.DataSet[DicomTags.InstitutionName].GetString(0, string.Empty), StationName = dicomMessage.DataSet[DicomTags.StationName].GetString(0, string.Empty), Department = dicomMessage.DataSet[DicomTags.InstitutionalDepartmentName].GetString(0, string.Empty), PerfPhysician = dicomMessage.DataSet[DicomTags.PerformingPhysiciansName].GetString(0, string.Empty), SeriesDate = dicomMessage.DataSet[DicomTags.SeriesDate].GetString(0, string.Empty), SeriesTime = dicomMessage.DataSet[DicomTags.SeriesTime].GetString(0, string.Empty), SeriesDescription = dicomMessage.DataSet[DicomTags.SeriesDescription].GetString(0, string.Empty), PerformedProcedureStepStartDate = dicomMessage.DataSet[DicomTags.PerformedProcedureStepStartDate].GetString(0, string.Empty), PerformedProcedureStepStartTime = dicomMessage.DataSet[DicomTags.PerformedProcedureStepStartTime].GetString(0, string.Empty), }; var instance = new Instance() { SopInstanceUid = dicomMessage.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty), SopClassUid = dicomMessage.DataSet[DicomTags.SopClassUid].GetString(0, string.Empty), InstanceNumber = dicomMessage.DataSet[DicomTags.InstanceNumber].GetString(0, string.Empty), ContentDate = dicomMessage.DataSet[DicomTags.ContentDate].GetString(0, string.Empty), ContentTime = dicomMessage.DataSet[DicomTags.ContentTime].GetString(0, string.Empty) }; if ( string.IsNullOrEmpty(study.StudyUid) || string.IsNullOrEmpty(series.SeriesUid) || string.IsNullOrEmpty(instance.SopInstanceUid)) { throw new ArgumentException(); } // Get Patient Db Object }
private void PopuldateInstance(DicomMessageBase request, DicomMessage response, IEnumerable<DicomTag> tagList, Instance row) { DicomAttributeCollection dataSet = response.DataSet; dataSet[DicomTags.RetrieveAeTitle].SetStringValue(base.Partition.AeTitle); dataSet[DicomTags.InstanceAvailability].SetStringValue("ONLINE"); // character set var characterSet = GetPreferredCharacterSet(); if (!string.IsNullOrEmpty(characterSet)) { dataSet[DicomTags.SpecificCharacterSet].SetStringValue(characterSet); dataSet.SpecificCharacterSet = characterSet; } foreach (DicomTag tag in tagList) { try { switch (tag.TagValue) { case DicomTags.PatientId: dataSet[DicomTags.PatientId].SetStringValue(request.DataSet[DicomTags.PatientId].ToString()); break; case DicomTags.StudyInstanceUid: dataSet[DicomTags.StudyInstanceUid].SetStringValue( request.DataSet[DicomTags.StudyInstanceUid].ToString()); break; case DicomTags.SeriesInstanceUid: dataSet[DicomTags.SeriesInstanceUid].SetStringValue( request.DataSet[DicomTags.SeriesInstanceUid].ToString()); break; case DicomTags.QueryRetrieveLevel: dataSet[DicomTags.QueryRetrieveLevel].SetStringValue("IMAGE"); break; case DicomTags.SopInstanceUid: dataSet[DicomTags.SopInstanceUid].SetStringValue(row.SopInstanceUid); break; case DicomTags.SopClassUid: dataSet[DicomTags.SopClassUid].SetStringValue(row.SopClassUid); break; case DicomTags.InstanceNumber: dataSet[DicomTags.InstanceNumber].SetStringValue(row.InstanceNumber); break; // Meta tags that should have not been in the RQ, but we've already set case DicomTags.RetrieveAeTitle: case DicomTags.InstanceAvailability: case DicomTags.SpecificCharacterSet: break; default: //if (sourceDataSet.Contains(tag)) // dataSet[tag] = sourceDataSet[tag].Copy(); //else if (!tag.IsPrivate) // dataSet[tag].SetNullValue(); break; } } catch (Exception e) { Platform.Log(LogLevel.Warn, e, "Unexpected error setting tag {0} in C-FIND-RSP", dataSet[tag].Tag.ToString()); if (!tag.IsPrivate) dataSet[tag].SetNullValue(); } } }
private void PopulateSeries(DicomMessageBase request, DicomMessage response, IEnumerable<DicomTag> tagList, Series row) { DicomAttributeCollection dataSet = response.DataSet; dataSet[DicomTags.RetrieveAeTitle].SetStringValue(base.Partition.AeTitle); dataSet[DicomTags.InstanceAvailability].SetStringValue("ONLINE"); // character set var characterSet = GetPreferredCharacterSet(); if (!string.IsNullOrEmpty(characterSet)) { dataSet[DicomTags.SpecificCharacterSet].SetStringValue(characterSet); dataSet.SpecificCharacterSet = characterSet; } foreach (DicomTag tag in tagList) { try { switch (tag.TagValue) { case DicomTags.PatientId: dataSet[DicomTags.PatientId].SetStringValue(request.DataSet[DicomTags.PatientId].ToString()); break; case DicomTags.StudyInstanceUid: dataSet[DicomTags.StudyInstanceUid].SetStringValue( request.DataSet[DicomTags.StudyInstanceUid].ToString()); break; case DicomTags.SeriesInstanceUid: dataSet[DicomTags.SeriesInstanceUid].SetStringValue(row.SeriesUid); break; case DicomTags.Modality: dataSet[DicomTags.Modality].SetStringValue(row.Modality); break; case DicomTags.SeriesNumber: dataSet[DicomTags.SeriesNumber].SetStringValue(row.SeriesNumber); break; case DicomTags.SeriesDescription: dataSet[DicomTags.SeriesDescription].SetStringValue(row.SeriesDescription); break; case DicomTags.PerformedProcedureStepStartDate: dataSet[DicomTags.PerformedProcedureStepStartDate].SetStringValue( row.PerformedProcedureStepStartDate); break; case DicomTags.PerformedProcedureStepStartTime: dataSet[DicomTags.PerformedProcedureStepStartTime].SetStringValue( row.PerformedProcedureStepStartTime); break; case DicomTags.NumberOfSeriesRelatedInstances: dataSet[DicomTags.NumberOfSeriesRelatedInstances].AppendInt32(row.NumberOfRelatedImage); break; case DicomTags.RequestAttributesSequence: //LoadRequestAttributes(read, response, row); break; case DicomTags.QueryRetrieveLevel: dataSet[DicomTags.QueryRetrieveLevel].SetStringValue("SERIES"); break; // Meta tags that should have not been in the RQ, but we've already set case DicomTags.RetrieveAeTitle: case DicomTags.InstanceAvailability: case DicomTags.SpecificCharacterSet: break; default: if (!tag.IsPrivate) dataSet[tag].SetNullValue(); break; } } catch (Exception e) { Platform.Log(LogLevel.Warn, e, "Unexpected error setting tag {0} in C-FIND-RSP", dataSet[tag].Tag.ToString()); if (!tag.IsPrivate) dataSet[tag].SetNullValue(); } } }
/// <summary> /// Constructor from a <see cref="DicomMessageBase"/> instance. /// </summary> /// <param name="msg">The message to initialize the object from.</param> public DicomCompressedPixelData(DicomMessageBase msg) : base(msg) { _sq = (DicomFragmentSequence) msg.DataSet[DicomTags.PixelData]; }