/// <summary> /// Load the values for the sequence <see cref="DicomTags.RequestAttributesSequence"/> /// into a response message for a specific series. /// </summary> /// <param name="read">The connection to use to read the values.</param> /// <param name="response">The message to add the values into.</param> /// <param name="row">The <see cref="Series"/> entity to load the related <see cref="RequestAttributes"/> entity for.</param> private static void LoadRequestAttributes(IPersistenceContext read, DicomMessageBase response, Series row) { var select = read.GetBroker<IRequestAttributesEntityBroker>(); var criteria = new RequestAttributesSelectCriteria(); criteria.SeriesKey.EqualTo(row.GetKey()); IList<RequestAttributes> list = select.Find(criteria); if (list.Count == 0) { response.DataSet[DicomTags.RequestAttributesSequence].SetNullValue(); return; } foreach (RequestAttributes request in list) { var item = new DicomSequenceItem(); item[DicomTags.ScheduledProcedureStepId].SetStringValue(request.ScheduledProcedureStepId); item[DicomTags.RequestedProcedureId].SetStringValue(request.RequestedProcedureId); response.DataSet[DicomTags.RequestAttributesSequence].AddSequenceItem(item); } }
public void TestDicomTagPathGetAttribute_NoCreate() { var collection = new DicomAttributeCollection(); var path = new DicomTagPath(DicomTags.PatientId); //PatientID IS empty Assert.IsNull(path.GetAttribute(collection)); collection[DicomTags.PatientId].SetNullValue(); //PatientID NOT empty Assert.IsNotNull(path.GetAttribute(collection)); collection[DicomTags.PatientId].SetStringValue("PatientId"); collection[DicomTags.PatientsName].SetStringValue("PatientsName"); //PatientID NOT empty Assert.IsNotNull(path.GetAttribute(collection)); path = new DicomTagPath(DicomTags.PatientsName); //PatientsName NOT empty Assert.IsNotNull(path.GetAttribute(collection)); //ViewCodeSequence IS empty path = new DicomTagPath(DicomTags.ViewCodeSequence); Assert.IsNull(path.GetAttribute(collection)); var sequence1 = new DicomSequenceItem(); collection[DicomTags.ViewCodeSequence].AddSequenceItem(sequence1); //ViewCodeSequence NOT empty Assert.IsNotNull(path.GetAttribute(collection)); path += DicomTags.CodeMeaning; //ViewCodeSequence/CodeMeaning IS empty Assert.IsNull(path.GetAttribute(collection)); sequence1[DicomTags.CodeMeaning].SetNullValue(); //ViewCodeSequence/CodeMeaning NOT empty Assert.IsNotNull(path.GetAttribute(collection)); //ViewCodeSequence/ConceptNameCodeSequence IS empty path = new DicomTagPath(DicomTags.ViewCodeSequence, DicomTags.ConceptNameCodeSequence); Assert.IsNull(path.GetAttribute(collection)); var sequence2 = new DicomSequenceItem(); sequence1[DicomTags.ConceptNameCodeSequence].AddSequenceItem(sequence2); //ViewCodeSequence/ConceptNameCodeSequence NOT empty Assert.IsNotNull(path.GetAttribute(collection)); path += DicomTags.CodeValue; //ViewCodeSequence/ConceptNameCodeSequence/CodeValue IS empty Assert.IsNull(path.GetAttribute(collection)); sequence2[DicomTags.CodeValue].SetStringValue("Code"); //ViewCodeSequence/ConceptNameCodeSequence/CodeValue IS empty Assert.IsNotNull(path.GetAttribute(collection)); }
public void TestFormatNoDescription() { var item0 = new DicomSequenceItem(); item0[DicomTags.CodeValue].SetStringValue("CODEVALUE"); item0[DicomTags.CodeMeaning].SetStringValue("Code Meaning"); item0[DicomTags.CodingSchemeDesignator].SetStringValue("DCM"); var dataset = new DicomAttributeCollection(); dataset[DicomTags.PatientBreedCodeSequence].AddSequenceItem(item0); dataset[DicomTags.PatientBreedDescription].SetNullValue(); Assert.AreEqual("Code Meaning", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "1"); Assert.AreEqual("Code Meaning", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null, false), "2"); Assert.AreEqual("Code Meaning", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "3"); Assert.AreEqual("Code Meaning", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription, false), "4"); item0[DicomTags.CodeMeaning].SetEmptyValue(); Assert.AreEqual("CODEVALUE (DCM)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "5"); Assert.AreEqual("CODEVALUE (DCM)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null, false), "6"); Assert.AreEqual("CODEVALUE (DCM)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "7"); Assert.AreEqual("CODEVALUE (DCM)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription, false), "8"); }
private InstanceXml GetInstanceXml(StudyXmlOutputSettings outputSettings, out DicomFile real) { var xml = new StudyXml(); real = new DicomFile(); SetupMR(real.DataSet); real.MediaStorageSopClassUid = real.DataSet[DicomTags.SopClassUid].ToString(); real.MetaInfo[DicomTags.SopClassUid].SetString(0, real.DataSet[DicomTags.SopClassUid].ToString()); var bytes = new Byte[2048]; real.DataSet[DicomTags.RedPaletteColorLookupTableData].Values = bytes; var privateTag = new DicomTag(0x00111301, "Private Tag", "PrivateTag", DicomVr.CSvr, false, 1, 1, false); real.DataSet[privateTag].SetString(0, "Private"); var sequences = (DicomSequenceItem[])real.DataSet[DicomTags.RequestAttributesSequence].Values; var firstItem = sequences.First(); firstItem[DicomTags.RedPaletteColorLookupTableData].Values = bytes; var attr = real.DataSet[DicomTags.ReferencedStudySequence]; var sequenceItem = new DicomSequenceItem(); attr.AddSequenceItem(sequenceItem); sequenceItem[privateTag].SetString(0, "Private"); xml.AddFile(real); var memento = xml.GetMemento(outputSettings ?? new StudyXmlOutputSettings { IncludeLargeTags = StudyXmlTagInclusion.IncludeTagExclusion, IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag, MaxTagLength = 1024 }); xml = new StudyXml(); xml.SetMemento(memento); return xml.First().First(); }
private void PopulateScheduledProcedureStepSequence(DicomAttributeSQ dicomAttribute, ExamsScheduled row) { DicomSequenceItem item; item = new DicomSequenceItem(); item[DicomTags.ScheduledStationAeTitle].SetStringValue(row.ScheduledAET); item[DicomTags.ScheduledProcedureStepStartDate].SetStringValue(GetDateStringOnly(row.ExamScheduledDateAndTime)); item[DicomTags.ScheduledProcedureStepStartTime].SetStringValue(GetTimeStringOnly(row.ExamScheduledDateAndTime)); item[DicomTags.Modality].SetStringValue(row.Modality); item[DicomTags.PerformedProcedureStepId].SetStringValue(string.Format("{0}",row.ProcedureStepID));//O M K supported item[DicomTags.ScheduledProcedureStepLocation].SetStringValue(row.ExamRoom);//return type 2 -O M K supported item[DicomTags.ScheduledProcedureStepDescription].SetStringValue(row.ExamDescription);//return type 2 -O M K supported dicomAttribute.AddSequenceItem(item); }
/// <summary> /// Initializes a new instance of the <see cref="HL7v2HierarchicDesignatorMacroIod"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public HL7v2HierarchicDesignatorMacroIod(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
public AddOriginalAttributes(DicomSequenceItem value) : this() { this.value = value; }
/// <summary> /// Method for adding a <see cref="DicomSequenceItem"/> to an attributes value. /// </summary> /// <remarks> /// This method is value for <see cref="DicomAttributeSQ"/> attributes only. /// </remarks> /// <param name="item">The <see cref="DicomSequenceItem"/> to add to the attribute.</param> public virtual void AddSequenceItem(DicomSequenceItem item) { throw new DicomException(SR.InvalidType); }
/// <summary> /// Initializes a new instance of the <see cref="VoiLutSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public VoiLutSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) {}
/// <summary> /// Gets the specified sequence item from the attribute, if it exists. /// </summary> /// <remarks> /// For non-sequence attributes, this method always returns false. /// </remarks> public virtual bool TryGetSequenceItem(int i, out DicomSequenceItem item) { item = null; return false; }
public void SetupDataSet(DicomAttributeCollection theSet, string characterSet) { DateTime studyTime = DateTime.Now; theSet[DicomTags.SpecificCharacterSet].SetStringValue(characterSet); theSet[DicomTags.ImageType].SetStringValue("ORIGINAL\\PRIMARY\\OTHER\\"); theSet[DicomTags.InstanceCreationDate].SetStringValue(DateParser.ToDicomString(DateTime.Now)); theSet[DicomTags.InstanceCreationTime].SetStringValue(TimeParser.ToDicomString(DateTime.Now)); theSet[DicomTags.SopClassUid].SetStringValue(SopClass.SecondaryCaptureImageStorageUid); theSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID); theSet[DicomTags.StudyDate].SetStringValue(DateParser.ToDicomString(studyTime)); theSet[DicomTags.StudyTime].SetStringValue(TimeParser.ToDicomString(studyTime)); theSet[DicomTags.SeriesDate].SetStringValue(DateParser.ToDicomString(studyTime)); theSet[DicomTags.SeriesTime].SetStringValue(TimeParser.ToDicomString(studyTime)); theSet[DicomTags.AccessionNumber].SetStringValue("A1234"); theSet[DicomTags.Modality].SetStringValue("MR"); theSet[DicomTags.Manufacturer].SetStringValue("ClearCanvas"); theSet[DicomTags.ManufacturersModelName].SetNullValue(); theSet[DicomTags.InstitutionName].SetStringValue("Toronto General Hospital"); theSet[DicomTags.ReferringPhysiciansName].SetStringValue("Last^First"); theSet[DicomTags.StudyDescription].SetStringValue("TEST"); theSet[DicomTags.SeriesDescription].SetStringValue("TEST"); theSet[DicomTags.PatientsName].SetStringValue("Patient^Test"); theSet[DicomTags.PatientId].SetStringValue("ID123-45-9999"); theSet[DicomTags.PatientsBirthDate].SetStringValue("19600102"); theSet[DicomTags.PatientsSize].SetStringValue("10.000244140625"); theSet[DicomTags.SequenceVariant].SetStringValue("OTHER"); theSet[DicomTags.DeviceSerialNumber].SetStringValue("1234"); theSet[DicomTags.SoftwareVersions].SetStringValue("V1.0"); theSet[DicomTags.PatientPosition].SetStringValue("HFS"); theSet[DicomTags.StudyInstanceUid].SetStringValue(DicomUid.GenerateUid().UID); theSet[DicomTags.SeriesInstanceUid].SetStringValue(DicomUid.GenerateUid().UID); theSet[DicomTags.StudyId].SetStringValue("1933"); theSet[DicomTags.SeriesNumber].SetStringValue("1"); theSet[DicomTags.InstanceNumber].SetStringValue("1"); theSet[DicomTags.ImageComments].SetStringValue("Test SC Image"); theSet[DicomTags.SamplesPerPixel].SetStringValue("1"); theSet[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2"); theSet[DicomTags.Rows].SetStringValue("256"); theSet[DicomTags.Columns].SetStringValue("256"); theSet[DicomTags.BitsAllocated].SetStringValue("16"); theSet[DicomTags.BitsStored].SetStringValue("12"); theSet[DicomTags.HighBit].SetStringValue("11"); theSet[DicomTags.PixelRepresentation].SetStringValue("0"); uint length = 256 * 256 * 2; DicomAttributeOW pixels = new DicomAttributeOW(DicomTags.PixelData); byte[] pixelArray = new byte[length]; for (uint i = 0; i < length; i += 2) pixelArray[i] = (byte)(i % 255); pixels.Values = pixelArray; theSet[DicomTags.PixelData] = pixels; DicomSequenceItem item = new DicomSequenceItem(); theSet[DicomTags.RequestAttributesSequence].AddSequenceItem(item); item[DicomTags.RequestedProcedureId].SetStringValue("MRR1234"); item[DicomTags.ScheduledProcedureStepId].SetStringValue("MRS1234"); item = new DicomSequenceItem(); theSet[DicomTags.RequestAttributesSequence].AddSequenceItem(item); item[DicomTags.RequestedProcedureId].SetStringValue("MR2R1234"); item[DicomTags.ScheduledProcedureStepId].SetStringValue("MR2S1234"); DicomSequenceItem studyItem = new DicomSequenceItem(); item[DicomTags.ReferencedStudySequence].AddSequenceItem(studyItem); studyItem[DicomTags.ReferencedSopClassUid].SetStringValue(SopClass.SecondaryCaptureImageStorageUid); studyItem[DicomTags.ReferencedSopInstanceUid].SetStringValue("1.2.3.4.5.6.7.8.9"); }
/// <summary> /// Initializes a new instance of the <see cref="PrimaryAnatomicStructureSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public PrimaryAnatomicStructureSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
/// <summary> /// Initializes a new instance of the <see cref="ReferencedSeriesSequenceIod"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public ReferencedSeriesSequenceIod(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
/// <summary> /// Initializes a new instance of the <see cref="SegmentedPropertyTypeCodeSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public SegmentedPropertyTypeCodeSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
/// <summary> /// Initializes a new instance of the <see cref="SegmentSequence"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public SegmentSequence(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
public void TestFormatMultipleItems() { var item0 = new DicomSequenceItem(); item0[DicomTags.CodeValue].SetStringValue("CODE1"); item0[DicomTags.CodeMeaning].SetStringValue("Code Meaning 1"); item0[DicomTags.CodingSchemeDesignator].SetStringValue("DCM1"); var item1 = new DicomSequenceItem(); item1[DicomTags.CodeValue].SetStringValue("CODE2"); item1[DicomTags.CodeMeaning].SetStringValue("Code Meaning 2"); item1[DicomTags.CodingSchemeDesignator].SetStringValue("DCM2"); var item2 = new DicomSequenceItem(); item2[DicomTags.CodeValue].SetStringValue("CODE3"); item2[DicomTags.CodeMeaning].SetStringValue("Code Meaning 3"); item2[DicomTags.CodingSchemeDesignator].SetStringValue("DCM3"); var dataset = new DicomAttributeCollection(); dataset[DicomTags.PatientBreedCodeSequence].AddSequenceItem(item0); dataset[DicomTags.PatientBreedCodeSequence].AddSequenceItem(item1); dataset[DicomTags.PatientBreedCodeSequence].AddSequenceItem(item2); dataset[DicomTags.PatientBreedDescription].SetStringValue("Description (CODE1, CODE2, CODE3)"); Assert.AreEqual(@"Code Meaning 1\Code Meaning 2\Code Meaning 3", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "1"); Assert.AreEqual(@"Code Meaning 1\Code Meaning 2\Code Meaning 3", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "2"); item1[DicomTags.CodeMeaning].SetEmptyValue(); Assert.AreEqual(@"Code Meaning 1\CODE2 (DCM2)\Code Meaning 3", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "3"); Assert.AreEqual(@"Code Meaning 1\CODE2 (DCM2)\Code Meaning 3", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "4"); item2[DicomTags.CodeMeaning].SetNullValue(); Assert.AreEqual(@"Code Meaning 1\CODE2 (DCM2)\CODE3 (DCM3)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "5"); Assert.AreEqual(@"Code Meaning 1\CODE2 (DCM2)\CODE3 (DCM3)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "6"); item0[DicomTags.CodeMeaning].SetEmptyValue(); Assert.AreEqual(@"CODE1 (DCM1)\CODE2 (DCM2)\CODE3 (DCM3)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "7"); Assert.AreEqual("Description (CODE1, CODE2, CODE3)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "8"); dataset[DicomTags.PatientBreedDescription].SetNullValue(); Assert.AreEqual(@"CODE1 (DCM1)\CODE2 (DCM2)\CODE3 (DCM3)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, null), "9"); Assert.AreEqual(@"CODE1 (DCM1)\CODE2 (DCM2)\CODE3 (DCM3)", CodeSequenceAnnotationItem.FormatCodeSequence(dataset, DicomTags.PatientBreedCodeSequence, DicomTags.PatientBreedDescription), "10"); }
public override bool TryGetSequenceItem(int i, out DicomSequenceItem item) { item = this[i]; return item != null; }
/// <summary> /// Initializes a new instance of the <see cref="StudiesContainingOtherReferencedInstancesSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public StudiesContainingOtherReferencedInstancesSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
/// <summary> /// Method for adding a <see cref="DicomSequenceItem"/> to an attributes value. /// </summary> /// <param name="item">The <see cref="DicomSequenceItem"/> to add to the attribute.</param> /// <remarks> /// This method is value for <see cref="DicomAttributeSQ"/> attributes only. /// </remarks> public override void AddSequenceItem(DicomSequenceItem item) { if (_values == null) { _values = new DicomSequenceItem[1]; _values[0] = item; } else { DicomSequenceItem[] oldValues = _values; _values = new DicomSequenceItem[oldValues.Length + 1]; oldValues.CopyTo(_values, 0); _values[oldValues.Length] = item; } if (item.SpecificCharacterSet == null) item.SpecificCharacterSet = ParentCollection.SpecificCharacterSet; base.Count = _values.Length; base.StreamLength = (uint)base.Count; }
/// <summary> /// Initializes a new instance of the <see cref="AlternateContentDescriptionSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public AlternateContentDescriptionSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
public static bool Convert2Dicom(byte[] pixelData, string rawFileName, DataRow patientInfo, bool delbeforeSave, string AutoWLPath) { try { const string colPid = "PID"; const string colKVP = "KVP"; const string colMAS = "MAS"; const string colDepartmentName = "Department_Name"; const string colPatientName = "Patient_Name"; const string colPatientSex = "Patient_Sex"; const string colPatientAge = "Patient_Age"; const string colPatientBirthdate = "Patient_Birthdate"; const string colRegDate = "Reg_Date"; const string colRegNum = "Reg_Num"; const string colImgWidth = "IMGWidth"; const string colImgHeight = "IMGHeigh"; const string colModalityCode = "Modality_Code"; const string colAtonomyCode = "Atonomy_Code"; const string colProjectionCode = "Projection_Code"; const string colHostpitalName = "Hostpital_Name"; const string colMonoChrome = "MonoChrome"; const string _colStudyInstanceUID = "StudyInstanceUID"; const string colSeriesInstanceUID = "SeriesInstanceUID"; const string colSOPInstanceUID = "SOPInstanceUID"; const string colAcqDate = "AcqDate"; const string colAppName = "AppName"; const string colBitsStored = "BitsStored"; const string colHightBit = "HightBit"; const string colBitsAllocated = "BitsAllocated"; _bitsStored = TryGetBitsStored(patientInfo, colBitsStored); var _HightBit = TryGetBitsStored(patientInfo, colHightBit); var _BitsAllocated = TryGetBitsStored(patientInfo, colBitsAllocated); var MonoChrome = TryGetString(patientInfo, colMonoChrome, "MONOCHROME2"); var pid = TryGetString(patientInfo, colPid); var _KVP = TryGetString(patientInfo, colKVP); var _MAS = TryGetString(patientInfo, colMAS); var patientName = TryGetString(patientInfo, colPatientName); var patientSex = TryGetString(patientInfo, colPatientSex); var patientAge = TryGetString(patientInfo, colPatientAge); var patientBirthdate = TryGetString(patientInfo, colPatientBirthdate); var regDate = TryGetString(patientInfo, colRegDate); var regNum = TryGetString(patientInfo, colRegNum); var imgWidth = TryGetString(patientInfo, colImgWidth); var imgHeigh = TryGetString(patientInfo, colImgHeight); var modalityCode = TryGetString(patientInfo, colModalityCode); var atonomyCode = TryGetString(patientInfo, colAtonomyCode); var projectionCode = TryGetString(patientInfo, colProjectionCode); var hostpitalName = TryGetString(patientInfo, colHostpitalName, "BACH MAI HOSTPITAL"); var departmentName = TryGetString(patientInfo, colDepartmentName, "Khoa chan doan hinh anh"); string defaultStudyInstanceUID = ClearCanvas.Dicom.DicomUid.GenerateUid().UID; string defaultSeriesInstanceUID = defaultStudyInstanceUID + ".1"; string defaultSOPInstanceUID = defaultSeriesInstanceUID + ".1"; var StudyInstanceUID = TryGetString(patientInfo, _colStudyInstanceUID, defaultStudyInstanceUID); var SeriesInstanceUID = TryGetString(patientInfo, colSeriesInstanceUID, defaultSeriesInstanceUID); var SOPInstanceUID = TryGetString(patientInfo, colSOPInstanceUID, defaultSOPInstanceUID); var AppName = TryGetString(patientInfo, colAppName, "VBIT"); string dicomPath = Path.GetDirectoryName(rawFileName); // Lấy về tên file Dicom từ file raw string dicomFileName = string.Format("{0}{1}{2}.DCM", dicomPath, Path.DirectorySeparatorChar, Path.GetFileNameWithoutExtension(rawFileName)); if (delbeforeSave && File.Exists(dicomFileName)) Try2DelFile(dicomFileName); else try2RenameExistedFile(dicomFileName); //FileStream fs = File.OpenRead(rawFileName); //long length = fs.Length; long dataLength = pixelData.Length; string col = imgWidth.ToString(); string row = imgHeigh.ToString(); // GetSize(dataLength, out col, out row); // Tạo File Dicom để lưu thông tin var dcmFile = new DicomFile(dicomFileName); DicomAttributeCollection dicomDataSet = dcmFile.DataSet; //Set Tag For File DateTime studyTime = DateTime.Now; dicomDataSet[DicomTags.SpecificCharacterSet].SetStringValue("ISO_IR 100"); dicomDataSet[DicomTags.ImageType].SetStringValue("ORIGINAL\\PRIMARY\\OTHER\\M\\FFE"); dicomDataSet[DicomTags.InstanceCreationDate].SetStringValue(DateParser.ToDicomString(studyTime)); dicomDataSet[DicomTags.InstanceCreationTime].SetStringValue(TimeParser.ToDicomString(studyTime)); dicomDataSet[DicomTags.SopClassUid].SetStringValue(SopClass.MrImageStorageUid); dicomDataSet[DicomTags.SopInstanceUid].SetStringValue(SOPInstanceUID); dicomDataSet[DicomTags.StudyDate].SetStringValue(regDate); dicomDataSet[DicomTags.ApplicationName].SetStringValue(AppName); dicomDataSet[DicomTags.StudyTime].SetStringValue(TimeParser.ToDicomString(studyTime)); dicomDataSet[DicomTags.SeriesDate].SetStringValue(regDate); dicomDataSet[DicomTags.SeriesTime].SetStringValue(TimeParser.ToDicomString(studyTime)); dicomDataSet[DicomTags.AccessionNumber].SetStringValue(regNum); dicomDataSet[DicomTags.Modality].SetStringValue(modalityCode); dicomDataSet[DicomTags.Manufacturer].SetStringValue("VBIT"); dicomDataSet[DicomTags.StationName].SetStringValue(AppName); dicomDataSet[DicomTags.ExposureInMas].SetStringValue(_MAS); dicomDataSet[DicomTags.Kvp].SetStringValue(_KVP); dicomDataSet[DicomTags.ManufacturersModelName].SetNullValue(); dicomDataSet[DicomTags.InstitutionName].SetStringValue(hostpitalName); dicomDataSet[DicomTags.InstitutionalDepartmentName].SetStringValue(departmentName); //dicomDataSet[DicomTags.StudyDescription].SetStringValue("HEART"); //dicomDataSet[DicomTags.SeriesDescription].SetStringValue("Heart 2D EPI BH TRA"); //dicomDataSet[DicomTags.PatientsName].SetStringValue("Patient^Test"); dicomDataSet[DicomTags.PatientsName].SetStringValue(patientName); dicomDataSet[DicomTags.PatientId].SetStringValue(pid); dicomDataSet[DicomTags.PatientsBirthDate].SetStringValue(patientBirthdate); dicomDataSet[DicomTags.PatientsSex].SetStringValue(patientSex); dicomDataSet[DicomTags.PatientsAge].SetStringValue(patientAge); dicomDataSet[DicomTags.PatientsWeight].SetStringValue("70"); dicomDataSet[DicomTags.SequenceVariant].SetStringValue("OTHER"); dicomDataSet[DicomTags.ScanOptions].SetStringValue("CG"); dicomDataSet[DicomTags.MrAcquisitionType].SetStringValue("2D"); dicomDataSet[DicomTags.SliceThickness].SetStringValue("2"); dicomDataSet[DicomTags.RepetitionTime].SetStringValue("857.142883"); dicomDataSet[DicomTags.EchoTime].SetStringValue("8.712100"); dicomDataSet[DicomTags.NumberOfAverages].SetStringValue("1"); dicomDataSet[DicomTags.ImagingFrequency].SetStringValue("63.901150"); dicomDataSet[DicomTags.ImagedNucleus].SetStringValue("1H"); dicomDataSet[DicomTags.EchoNumbers].SetStringValue("1"); dicomDataSet[DicomTags.MagneticFieldStrength].SetStringValue("1.500000"); dicomDataSet[DicomTags.SpacingBetweenSlices].SetStringValue("10.00000"); dicomDataSet[DicomTags.NumberOfPhaseEncodingSteps].SetStringValue("81"); dicomDataSet[DicomTags.EchoTrainLength].SetStringValue("0"); dicomDataSet[DicomTags.PercentSampling].SetStringValue("63.281250"); dicomDataSet[DicomTags.PercentPhaseFieldOfView].SetStringValue("68.75000"); dicomDataSet[DicomTags.DeviceSerialNumber].SetStringValue("1234"); dicomDataSet[DicomTags.SoftwareVersions].SetStringValue("V1.0"); dicomDataSet[DicomTags.ProtocolName].SetStringValue("2D EPI BH"); dicomDataSet[DicomTags.TriggerTime].SetStringValue("14.000000"); dicomDataSet[DicomTags.LowRRValue].SetStringValue("948"); dicomDataSet[DicomTags.HighRRValue].SetStringValue("1178"); dicomDataSet[DicomTags.IntervalsAcquired].SetStringValue("102"); dicomDataSet[DicomTags.IntervalsRejected].SetStringValue("0"); dicomDataSet[DicomTags.HeartRate].SetStringValue("56"); dicomDataSet[DicomTags.ReceiveCoilName].SetStringValue("B"); dicomDataSet[DicomTags.TransmitCoilName].SetStringValue("B"); dicomDataSet[DicomTags.InPlanePhaseEncodingDirection].SetStringValue("COL"); dicomDataSet[DicomTags.FlipAngle].SetStringValue("50.000000"); dicomDataSet[DicomTags.PatientPosition].SetStringValue("HFS"); dicomDataSet[DicomTags.StudyInstanceUid].SetStringValue(StudyInstanceUID); dicomDataSet[DicomTags.SeriesInstanceUid].SetStringValue(SeriesInstanceUID); //dicomDataSet[DicomTags.StudyId].SetStringValue(pid); dicomDataSet[DicomTags.SeriesNumber].SetStringValue("1"); dicomDataSet[DicomTags.AcquisitionNumber].SetStringValue("7"); dicomDataSet[DicomTags.InstanceNumber].SetStringValue("1"); dicomDataSet[DicomTags.ImagePositionPatient].SetStringValue("-61.7564\\-212.04848\\-99.6208"); dicomDataSet[DicomTags.ImageOrientationPatient].SetStringValue("0.861\\0.492\\0.126\\-0.2965"); dicomDataSet[DicomTags.FrameOfReferenceUid].SetStringValue(DicomUid.GenerateUid().UID); dicomDataSet[DicomTags.PositionReferenceIndicator].SetStringValue(null); //dicomDataSet[DicomTags.ImageComments].SetStringValue("Test MR Image"); dicomDataSet[DicomTags.SamplesPerPixel].SetStringValue("1"); dicomDataSet[DicomTags.PhotometricInterpretation].SetStringValue(MonoChrome); dicomDataSet[DicomTags.Rows].SetStringValue(row); dicomDataSet[DicomTags.Columns].SetStringValue(col); dicomDataSet[DicomTags.PixelSpacing].SetStringValue("0.168\\0.168"); dicomDataSet[DicomTags.BitsAllocated].SetStringValue(_BitsAllocated.ToString()); dicomDataSet[DicomTags.BitsStored].SetStringValue(_bitsStored.ToString()); dicomDataSet[DicomTags.HighBit].SetStringValue(_HightBit.ToString()); dicomDataSet[DicomTags.PixelRepresentation].SetStringValue("0"); if (File.Exists(AutoWLPath)) { switch (_bitsStored) { case 12: dicomDataSet[DicomTags.WindowCenter].SetStringValue("2048"); dicomDataSet[DicomTags.WindowWidth].SetStringValue("4095"); break; case 14: dicomDataSet[DicomTags.WindowCenter].SetStringValue("8192"); dicomDataSet[DicomTags.WindowWidth].SetStringValue("16383"); break; case 16: dicomDataSet[DicomTags.WindowCenter].SetStringValue("32767"); dicomDataSet[DicomTags.WindowWidth].SetStringValue("65535"); break; default: dicomDataSet[DicomTags.WindowCenter].SetStringValue("32767"); dicomDataSet[DicomTags.WindowWidth].SetStringValue("65535"); break; } } //dicomDataSet[DicomTags.SmallestImagePixelValue].SetStringValue("32772"); //dicomDataSet[DicomTags.LargestImagePixelValue].SetStringValue("47745"); dicomDataSet[DicomTags.RescaleIntercept].SetStringValue("0."); dicomDataSet[DicomTags.RescaleSlope].SetStringValue("1."); dicomDataSet[DicomTags.ViewPosition].SetStringValue(projectionCode); dicomDataSet[DicomTags.BodyPartExamined].SetStringValue(atonomyCode); //Gán Dữ liệu ảnh var pixels = new DicomAttributeOW(DicomTags.PixelData) { Values = pixelData }; dicomDataSet[DicomTags.PixelData] = pixels; var item = new DicomSequenceItem(); dicomDataSet[DicomTags.RequestAttributesSequence].AddSequenceItem(item); item[DicomTags.RequestedProcedureId].SetStringValue("MRR1234"); item[DicomTags.ScheduledProcedureStepId].SetStringValue("MRS1234"); item = new DicomSequenceItem(); dicomDataSet[DicomTags.RequestAttributesSequence].AddSequenceItem(item); item[DicomTags.RequestedProcedureId].SetStringValue("MR2R1234"); item[DicomTags.ScheduledProcedureStepId].SetStringValue("MR2S1234"); var studyItem = new DicomSequenceItem(); item[DicomTags.ReferencedStudySequence].AddSequenceItem(studyItem); studyItem[DicomTags.ReferencedSopClassUid].SetStringValue(SopClass.MrImageStorageUid); studyItem[DicomTags.ReferencedSopInstanceUid].SetStringValue("1.2.3.4.5.6.7.8.9"); //Set Meta Info dicomDataSet[DicomTags.MediaStorageSopClassUid].SetStringValue( dcmFile.DataSet[DicomTags.SopClassUid].GetString(0, "")); dicomDataSet[DicomTags.MediaStorageSopInstanceUid].SetStringValue( dcmFile.DataSet[DicomTags.SopInstanceUid].GetString(0, "")); dcmFile.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian; dicomDataSet[DicomTags.ImplementationClassUid].SetStringValue("1.1.1.1.1.11.1"); dicomDataSet[DicomTags.ImplementationVersionName].SetStringValue("droc 1.0"); // Lưu File dcmFile.Save(); return true; } catch (Exception ex) { return false; } }
/// <summary> /// Initializes a new instance of the <see cref="FrameExtractionSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public FrameExtractionSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }
/// <summary> /// Initializes a new instance of the <see cref="VoiLutMacro"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public VoiLutMacro(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) {}
private void SetSeriesTags() { _theFile.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(DicomUid.GenerateUid().UID); _theFile.DataSet[DicomTags.SeriesDate].SetStringValue(DateParser.ToDicomString(StudyDate)); _theFile.DataSet[DicomTags.SeriesTime].SetStringValue(TimeParser.ToDicomString(DateTime.Now)); _theFile.DataSet[DicomTags.Modality].SetStringValue(Modality); DicomSequenceItem item = new DicomSequenceItem(); _theFile.DataSet[DicomTags.RequestAttributesSequence].AddSequenceItem(item); item[DicomTags.RequestedProcedureId].SetStringValue(ModalityHospital.GetNextRequestedProcedureStepId()); item[DicomTags.ScheduledProcedureStepId].SetStringValue(ModalityHospital.GetNextScheduledProcedureStepId()); _theFile.DataSet[DicomTags.SeriesDescription].SetStringValue(_seriesDescription[Rand.Next(_seriesDescription.Count)]); _seriesNumber++; _theFile.DataSet[DicomTags.SeriesNumber].AppendInt32(_seriesNumber); }
protected static DicomAttribute FindAttribute(DicomAttributeCollection collection, ImageLevelUpdateEntry entry) { if (collection == null) return null; if (entry.TagPath.Parents != null) { foreach (DicomTag tag in entry.TagPath.Parents) { DicomAttribute sq = collection[tag] as DicomAttributeSQ; if (sq == null) { throw new Exception(String.Format("Invalid tag value: {0}({1}) is not a SQ VR", tag, tag.Name)); } if (sq.IsEmpty) { DicomSequenceItem item = new DicomSequenceItem(); sq.AddSequenceItem(item); } DicomSequenceItem[] items = sq.Values as DicomSequenceItem[]; Platform.CheckForNullReference(items, "items"); collection = items[0]; } } return collection[entry.TagPath.Tag]; }
private void AddSourceImageSequence(DicomFile file, string oldSopUid) { DicomAttributeSQ sourceImageSq; if (!file.DataSet.Contains(DicomTags.SourceImageSequence)) { sourceImageSq = new DicomAttributeSQ(DicomTags.SourceImageSequence); file.DataSet[DicomTags.SourceImageSequence] = sourceImageSq; } else sourceImageSq = file.DataSet[DicomTags.SourceImageSequence] as DicomAttributeSQ; DicomSequenceItem item = new DicomSequenceItem(); item[DicomTags.ReferencedSopClassUid].SetStringValue(file.SopClass.Uid); item[DicomTags.ReferencedSopInstanceUid].SetStringValue(oldSopUid); sourceImageSq.AddSequenceItem(item); }
private static void InitializeDerivationImageFunctionalGroup(FunctionalGroupsSequenceItem functionalGroupsSequenceItem, ImageSop imageSop, int frameNumber) { var derivationImageFunctionalGroup = functionalGroupsSequenceItem.GetFunctionalGroup<DerivationImageFunctionalGroup>(); var derivationImageSequenceItem = derivationImageFunctionalGroup.CreateDerivationImageSequenceItem(); var derivationCodeSequence = derivationImageSequenceItem.CreateDerivationCodeSequence(); derivationCodeSequence.CodeValue = "113076"; derivationCodeSequence.CodeMeaning = "Segmentation"; derivationCodeSequence.CodingSchemeDesignator = "DCM"; derivationImageSequenceItem.DerivationCodeSequence = derivationCodeSequence; var sourceImageSequenceItem = derivationImageSequenceItem.CreateSourceImageSequenceItem(); sourceImageSequenceItem.ReferencedSopClassUid = imageSop.SopClassUid; sourceImageSequenceItem.ReferencedSopInstanceUid = imageSop.SopInstanceUid; if (frameNumber != 1) sourceImageSequenceItem.ReferencedFrameNumber2 = new[] {frameNumber}; // TODO: FIXME: replace with stock implementation when available var purposeOfReferenceCodeSequence = new Func<CodeSequenceMacro>(() => { var dicomAttribute = sourceImageSequenceItem.DicomAttributeProvider[DicomTags.PurposeOfReferenceCodeSequence]; if (dicomAttribute.IsNull || dicomAttribute.IsEmpty) { var dicomSequenceItem = new DicomSequenceItem(); dicomAttribute.Values = new[] {dicomSequenceItem}; return new CodeSequenceMacro(dicomSequenceItem); } return new CodeSequenceMacro(((DicomSequenceItem[]) dicomAttribute.Values)[0]); }).Invoke(); purposeOfReferenceCodeSequence.CodeValue = "121322"; purposeOfReferenceCodeSequence.CodeMeaning = "Source image for image processing operation"; purposeOfReferenceCodeSequence.CodingSchemeDesignator = "DCM"; derivationImageSequenceItem.SourceImageSequence = new[] {sourceImageSequenceItem}; derivationImageFunctionalGroup.DerivationImageSequence = new[] {derivationImageSequenceItem}; }
/// <summary> /// Update an <see cref="DicomAttributeCollection"/> with pixel data related tags. /// </summary> /// <param name="dataset">The collection to update.</param> public override void UpdateAttributeCollection(DicomAttributeCollection dataset) { if (dataset.Contains(DicomTags.NumberOfFrames) || NumberOfFrames > 1) dataset[DicomTags.NumberOfFrames].SetInt32(0, NumberOfFrames); if (dataset.Contains(DicomTags.PlanarConfiguration)) dataset[DicomTags.PlanarConfiguration].SetInt32(0, PlanarConfiguration); if (dataset.Contains(DicomTags.LossyImageCompression) || LossyImageCompression.Length > 0) dataset[DicomTags.LossyImageCompression].SetString(0, LossyImageCompression); if (dataset.Contains(DicomTags.LossyImageCompressionRatio) || (LossyImageCompressionRatio != 1.0f && LossyImageCompressionRatio != 0.0f)) dataset[DicomTags.LossyImageCompressionRatio].SetFloat32(0, LossyImageCompressionRatio); if (dataset.Contains(DicomTags.LossyImageCompressionMethod) || LossyImageCompressionMethod.Length > 0) dataset[DicomTags.LossyImageCompressionMethod].SetString(0, LossyImageCompressionMethod); if (dataset.Contains(DicomTags.DerivationDescription) || DerivationDescription.Length > 0) { string currentValue = dataset[DicomTags.DerivationDescription].ToString(); dataset[DicomTags.DerivationDescription].SetStringValue(DerivationDescription); if (!currentValue.Equals(DerivationDescription)) { DicomSequenceItem item = new DicomSequenceItem(); CodeSequenceMacro macro = new CodeSequenceMacro(item); macro.CodeMeaning = "Lossy Compression"; macro.CodeValue = "113040"; macro.CodingSchemeDesignator = "DCM"; macro.ContextGroupVersion = new DateTime(2005,8,22); macro.ContextIdentifier = "7203"; macro.MappingResource = "DCMR"; dataset[DicomTags.DerivationCodeSequence].AddSequenceItem(item); } } if (dataset.Contains(DicomTags.RescaleSlope) || DecimalRescaleSlope != 1.0M || DecimalRescaleIntercept != 0.0M) dataset[DicomTags.RescaleSlope].SetString(0, RescaleSlope); if (dataset.Contains(DicomTags.RescaleIntercept) || DecimalRescaleSlope != 1.0M || DecimalRescaleIntercept != 0.0M) dataset[DicomTags.RescaleIntercept].SetString(0, RescaleIntercept); if (dataset.Contains(DicomTags.WindowCenter) || LinearVoiLuts.Count > 0) Window.SetWindowCenterAndWidth(dataset, LinearVoiLuts); //Remove the palette color lut, if the pixels were translated to RGB if (dataset.Contains(DicomTags.RedPaletteColorLookupTableData) && dataset.Contains(DicomTags.BluePaletteColorLookupTableData) && dataset.Contains(DicomTags.GreenPaletteColorLookupTableData) && !HasPaletteColorLut) { dataset.RemoveAttribute(DicomTags.BluePaletteColorLookupTableDescriptor); dataset.RemoveAttribute(DicomTags.BluePaletteColorLookupTableData); dataset.RemoveAttribute(DicomTags.RedPaletteColorLookupTableDescriptor); dataset.RemoveAttribute(DicomTags.RedPaletteColorLookupTableData); dataset.RemoveAttribute(DicomTags.GreenPaletteColorLookupTableDescriptor); dataset.RemoveAttribute(DicomTags.GreenPaletteColorLookupTableData); } dataset.SaveDicomFields(this); dataset[DicomTags.PixelData] = _sq; }
public static DicomSequenceItem CreateOriginalAttributesSequence(IEnumerable<DicomAttribute> originalValues, string originalAttributesSource, string modifyingSystem, string reasonForModification) { DicomSequenceItem item = new DicomSequenceItem(); item[DicomTags.AttributeModificationDatetime] .SetDateTime(0, DateTime.Now); if (!string.IsNullOrEmpty(originalAttributesSource)) { item[DicomTags.SourceOfPreviousValues] .SetStringValue(originalAttributesSource); } if (!string.IsNullOrEmpty(modifyingSystem)) { item[DicomTags.ModifyingSystem] .SetStringValue(modifyingSystem); } if (!string.IsNullOrEmpty(reasonForModification)) { item[DicomTags.ReasonForTheAttributeModification] .SetStringValue(reasonForModification); } DicomAttributeSQ sq = new DicomAttributeSQ(DicomTags.ModifiedAttributesSequence); item[sq.Tag] = sq; DicomSequenceItem modified = new DicomSequenceItem(); sq.AddSequenceItem(modified); foreach (DicomAttribute value in originalValues) { modified[value.Tag] = value; } return item; }
/// <summary> /// Initializes a new instance of the <see cref="AlternateContainerIdentifierSequenceItem"/> class. /// </summary> /// <param name="dicomSequenceItem">The dicom sequence item.</param> public AlternateContainerIdentifierSequenceItem(DicomSequenceItem dicomSequenceItem) : base(dicomSequenceItem) { }