private static void AddReferencedSopSequence(ReferencedSopItemCollection storageCommitItems, uint tag, DvtkData.Dimse.AttributeSet attributeSet, InstanceStateEnum newInstanceState) { ushort group = (ushort)(tag >> 16); ushort element = (ushort)(tag & 0x0000FFFF); DvtkData.Dimse.Tag tagValue = new DvtkData.Dimse.Tag(group, element); DvtkData.Dimse.Attribute referencedSopSequence = attributeSet.GetAttribute(tagValue); if (referencedSopSequence != null) { attributeSet.Remove(referencedSopSequence); } referencedSopSequence = new DvtkData.Dimse.Attribute(tag, DvtkData.Dimse.VR.SQ); SequenceOfItems referencedSopSequenceOfItems = new SequenceOfItems(); referencedSopSequence.DicomValue = referencedSopSequenceOfItems; foreach(ReferencedSopItem referencedSopItem in storageCommitItems) { if (((referencedSopItem.InstanceState == InstanceStateEnum.InstanceStored) && (newInstanceState == InstanceStateEnum.InstanceMppsCompleted)) || ((referencedSopItem.InstanceState == InstanceStateEnum.InstanceMppsCompleted) && (newInstanceState == InstanceStateEnum.InstanceStorageCommitRequested))) { DvtkData.Dimse.SequenceItem referencedSopSequenceItem = new DvtkData.Dimse.SequenceItem(); referencedSopSequenceItem.AddAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID.GroupNumber, DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID.ElementNumber, DvtkData.Dimse.VR.UI, referencedSopItem.SopClassUid); referencedSopSequenceItem.AddAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID.GroupNumber, DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID.ElementNumber, DvtkData.Dimse.VR.UI, referencedSopItem.SopInstanceUid); referencedSopItem.InstanceState = newInstanceState; referencedSopSequenceOfItems.Sequence.Add(referencedSopSequenceItem); } } attributeSet.Add(referencedSopSequence); }
private static void UpdateValue(System.String attributeValue, DvtkData.Dimse.Tag tag, VR vr, DvtkData.Dimse.AttributeSet attributeSet) { // Only update the value if the dataset contains an attribute with the same tag DvtkData.Dimse.Attribute attribute = attributeSet.GetAttribute(tag); if (attribute != null) { // Remove the existing attribute attributeSet.Remove(attribute); // Add the new (updated) value attributeSet.AddAttribute(tag.GroupNumber, tag.ElementNumber, (DvtkData.Dimse.VR)vr, attributeValue); } }
private static void AddDefaultValueEvenIfZeroLength(Dvtk.Dicom.InformationEntity.DefaultValues.DefaultValueManager defaultValueManager, DvtkData.Dimse.Tag tag, VR vr, DvtkData.Dimse.AttributeSet attributeSet) { // Only add a default value if the attribute does not already exist or has a zero length DvtkData.Dimse.Attribute attribute = attributeSet.GetAttribute(tag); if (attribute == null) { // Attribute does not exist so add a default value System.String lValue = defaultValueManager.GetInstantiatedValue(tag); attributeSet.AddAttribute(tag.GroupNumber, tag.ElementNumber, (DvtkData.Dimse.VR)vr, lValue); } else if (attribute.Length == 0) { // Remove the existing attribute attributeSet.Remove(attribute); // Attribute had zero length so add a default value System.String lValue = defaultValueManager.GetInstantiatedValue(tag); attributeSet.AddAttribute(tag.GroupNumber, tag.ElementNumber, (DvtkData.Dimse.VR)vr, lValue); } }
private static void UpdateStartDateTimeValues(Dvtk.Dicom.InformationEntity.DefaultValues.DefaultValueManager defaultValueManager, DvtkData.Dimse.DataSet dataset) { DvtkData.Dimse.Attribute ppsStartDate = dataset.GetAttribute(DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_START_DATE); if (ppsStartDate != null) { dataset.Remove(ppsStartDate); } AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_START_DATE, VR.DA, dataset); DvtkData.Dimse.Attribute ppsStartTime = dataset.GetAttribute(DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_START_TIME); if (ppsStartTime != null) { dataset.Remove(ppsStartTime); } AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_START_TIME, VR.TM, dataset); }
private static void AddStoreInstanceValues(Dvtk.Dicom.InformationEntity.DefaultValues.DefaultValueManager defaultValueManager, DvtkData.Dimse.DataSet dataset, bool generateImageData) { DvtkData.Dimse.SequenceItem requestAttributesSequenceItem = new DvtkData.Dimse.SequenceItem(); // Patient Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PATIENTS_NAME, VR.PN, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PATIENT_ID, VR.LO, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PATIENTS_BIRTH_DATE, VR.DA, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PATIENTS_SEX, VR.CS, dataset); // Study Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.STUDY_DESCRIPTION, VR.LO, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.STUDY_ID, VR.SH, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.STUDY_DATE, VR.DA, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.STUDY_TIME, VR.TM, dataset); // Series Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PROTOCOL_NAME, VR.LO, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SERIES_DESCRIPTION, VR.LO, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMING_PHYSICIANS_NAME, VR.PN, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.OPERATORS_NAME, VR.PN, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SERIES_INSTANCE_UID, VR.UI, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SERIES_NUMBER, VR.IS, dataset); // Instance Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SOP_INSTANCE_UID, VR.UI, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.INSTANCE_NUMBER, VR.IS, dataset); // Image Service Request Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.ACCESSION_NUMBER, VR.SH, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.REFERRING_PHYSICIANS_NAME, VR.PN, dataset); // Requested Procedure Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.REQUESTED_PROCEDURE_ID, VR.SH, requestAttributesSequenceItem); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.STUDY_INSTANCE_UID, VR.UI, dataset); // Scheduled Procedure Step Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.MODALITY, VR.CS, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SCHEDULED_PROCEDURE_STEP_ID, VR.SH, requestAttributesSequenceItem); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SCHEDULED_PROCEDURE_STEP_DESCRIPTION, VR.LO, requestAttributesSequenceItem); // Performed Procedure Step Entity default values AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_ID, VR.SH, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_DESCRIPTION, VR.LO, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_START_DATE, VR.DA, dataset); AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.PERFORMED_PROCEDURE_STEP_START_TIME, VR.TM, dataset); // Check if the Request Attribute Sequence is already present DvtkData.Dimse.Attribute requestAttributesSequence = dataset.GetAttribute(DvtkData.Dimse.Tag.REQUEST_ATTRIBUTES_SEQUENCE); if (requestAttributesSequence != null) { // Remove the existing (old) sequence dataset.Remove(requestAttributesSequence); } // Add the new sequence dataset.AddAttribute(DvtkData.Dimse.Tag.REQUEST_ATTRIBUTES_SEQUENCE.GroupNumber, DvtkData.Dimse.Tag.REQUEST_ATTRIBUTES_SEQUENCE.ElementNumber, DvtkData.Dimse.VR.SQ, requestAttributesSequenceItem); // Check if we need to generate the image data too (including pixel data) if (generateImageData == true) { // Add Secondary Capture image data dataset.AddAttribute(DvtkData.Dimse.Tag.SOP_CLASS_UID.GroupNumber, DvtkData.Dimse.Tag.SOP_CLASS_UID.ElementNumber, DvtkData.Dimse.VR.UI, "1.2.840.10008.5.1.4.1.1.7"); dataset.AddAttribute(DvtkData.Dimse.Tag.CONVERSION_TYPE.GroupNumber, DvtkData.Dimse.Tag.CONVERSION_TYPE.ElementNumber, DvtkData.Dimse.VR.CS, "DV"); dataset.AddAttribute(DvtkData.Dimse.Tag.PATIENT_ORIENTATION.GroupNumber, DvtkData.Dimse.Tag.PATIENT_ORIENTATION.ElementNumber, DvtkData.Dimse.VR.CS); dataset.AddAttribute(DvtkData.Dimse.Tag.SAMPLES_PER_PIXEL.GroupNumber, DvtkData.Dimse.Tag.SAMPLES_PER_PIXEL.ElementNumber, DvtkData.Dimse.VR.US, 1); dataset.AddAttribute(DvtkData.Dimse.Tag.PHOTOMETRIC_INTERPRETATION.GroupNumber, DvtkData.Dimse.Tag.PHOTOMETRIC_INTERPRETATION.ElementNumber, DvtkData.Dimse.VR.CS, "MONOCHROME2"); dataset.AddAttribute(DvtkData.Dimse.Tag.ROWS.GroupNumber, DvtkData.Dimse.Tag.ROWS.ElementNumber, DvtkData.Dimse.VR.US, 512); dataset.AddAttribute(DvtkData.Dimse.Tag.COLUMNS.GroupNumber, DvtkData.Dimse.Tag.COLUMNS.ElementNumber, DvtkData.Dimse.VR.US, 512); dataset.AddAttribute(DvtkData.Dimse.Tag.BITS_ALLOCATED.GroupNumber, DvtkData.Dimse.Tag.BITS_ALLOCATED.ElementNumber, DvtkData.Dimse.VR.US, 8); dataset.AddAttribute(DvtkData.Dimse.Tag.BITS_STORED.GroupNumber, DvtkData.Dimse.Tag.BITS_STORED.ElementNumber, DvtkData.Dimse.VR.US, 8); dataset.AddAttribute(DvtkData.Dimse.Tag.HIGH_BIT.GroupNumber, DvtkData.Dimse.Tag.HIGH_BIT.ElementNumber, DvtkData.Dimse.VR.US, 7); dataset.AddAttribute(DvtkData.Dimse.Tag.PIXEL_REPRESENTATION.GroupNumber, DvtkData.Dimse.Tag.PIXEL_REPRESENTATION.ElementNumber, DvtkData.Dimse.VR.US, 0); dataset.AddAttribute(DvtkData.Dimse.Tag.PIXEL_DATA.GroupNumber, DvtkData.Dimse.Tag.PIXEL_DATA.ElementNumber, DvtkData.Dimse.VR.OB, 512); } }
private static void AddStorageCommitItems(Dvtk.Dicom.InformationEntity.DefaultValues.DefaultValueManager defaultValueManager, ReferencedSopItemCollection storageCommitItems, DvtkData.Dimse.DataSet dataset) { DvtkData.Dimse.SequenceItem performedSeriesSequenceItem = null; // Try to get the Performed Series Sequence DvtkData.Dimse.Attribute performedSeriesSequence = dataset.GetAttribute(DvtkData.Dimse.Tag.PERFORMED_SERIES_SEQUENCE); if (performedSeriesSequence != null) { DvtkData.Dimse.SequenceOfItems sequenceOfItems = (DvtkData.Dimse.SequenceOfItems)performedSeriesSequence.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { performedSeriesSequenceItem = sequenceOfItems.Sequence[0]; } else { dataset.Remove(performedSeriesSequence); performedSeriesSequenceItem = new DvtkData.Dimse.SequenceItem(); dataset.AddAttribute(DvtkData.Dimse.Tag.PERFORMED_SERIES_SEQUENCE.GroupNumber, DvtkData.Dimse.Tag.PERFORMED_SERIES_SEQUENCE.ElementNumber, DvtkData.Dimse.VR.SQ, performedSeriesSequenceItem); } } else { performedSeriesSequenceItem = new DvtkData.Dimse.SequenceItem(); dataset.AddAttribute(DvtkData.Dimse.Tag.PERFORMED_SERIES_SEQUENCE.GroupNumber, DvtkData.Dimse.Tag.PERFORMED_SERIES_SEQUENCE.ElementNumber, DvtkData.Dimse.VR.SQ, performedSeriesSequenceItem); } if (performedSeriesSequenceItem != null) { // Series Entity default values DvtkData.Dimse.Attribute seriesInstanceUid = performedSeriesSequenceItem.GetAttribute(DvtkData.Dimse.Tag.SERIES_INSTANCE_UID); if (seriesInstanceUid != null) { performedSeriesSequenceItem.Remove(seriesInstanceUid); } AddDefaultValue(defaultValueManager, DvtkData.Dimse.Tag.SERIES_INSTANCE_UID, VR.UI, performedSeriesSequenceItem); AddReferencedSopSequence(storageCommitItems, 0x00081140, performedSeriesSequenceItem, InstanceStateEnum.InstanceMppsCompleted); } }
private static void AddTagsToDataset(TagValueCollection tags, DvtkData.Dimse.DataSet dataset) { // iterate over the tags foreach(DicomTagValue tag in tags) { if (tag.ParentSequenceTag != Tag.UNDEFINED) { // try to get the sequence tag in the dataset DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(tag.ParentSequenceTag); if ((sequenceAttribute != null) && (sequenceAttribute.ValueRepresentation == DvtkData.Dimse.VR.SQ)) { SequenceOfItems sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { SequenceItem item = sequenceOfItems.Sequence[0]; if (item != null) { VR vr = VR.UN; // try to get the attribute in the item DvtkData.Dimse.Attribute attribute = item.GetAttribute(tag.Tag); if (attribute != null) { vr = attribute.ValueRepresentation; item.Remove(attribute); } // add the query value item.AddAttribute(tag.Tag.GroupNumber, tag.Tag.ElementNumber, vr, tag.Value); } } } } else { VR vr = VR.UN; // try to get the attribute in the dataset DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(tag.Tag); if (attribute != null) { vr = attribute.ValueRepresentation; dataset.Remove(attribute); } // special check for the SPECIFIC CHARACTER SET attribute if (tag.Tag == Tag.SPECIFIC_CHARACTER_SET) { vr = VR.CS; } // add the query value dataset.AddAttribute(tag.Tag.GroupNumber, tag.Tag.ElementNumber, vr, tag.Value); } } }
private static void AddDicomAttribute(DvtkData.Dimse.AttributeSet dataset, DicomTagPath dicomTagPath, System.String dicomValue) { if (dicomTagPath.Next != null) { // Try to get the sequence identified by this Tag DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(dicomTagPath.Tag); if (sequenceAttribute == null) { // Need to add the sequence DvtkData.Dimse.SequenceItem item = new DvtkData.Dimse.SequenceItem(); dataset.AddAttribute(dicomTagPath.Tag.GroupNumber, dicomTagPath.Tag.ElementNumber, DvtkData.Dimse.VR.SQ, item); // Get the newly added sequence sequenceAttribute = dataset.GetAttribute(dicomTagPath.Tag); } // Get the contained item DvtkData.Dimse.SequenceOfItems sequenceOfItems = (DvtkData.Dimse.SequenceOfItems)sequenceAttribute.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0]; // Call recursively AddDicomAttribute(item, dicomTagPath.Next, dicomValue); } } else { // Try to get the attribute identified by this Tag DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(dicomTagPath.Tag); if (attribute != null) { // If present - remove the attribute - we want to update the value dataset.Remove(attribute); } // Add the new value dataset.AddAttribute(dicomTagPath.Tag.GroupNumber, dicomTagPath.Tag.ElementNumber, DicomTagVrLookup.GetVR(dicomTagPath.Tag), dicomValue); } }