public void ConvertToJson() { var testDir = Path.Combine(TestDirPath, "convertToJson"); JsonDicomConverter jsonConverter = new JsonDicomConverter( ); Directory.CreateDirectory(testDir); foreach (string file in Directory.GetFiles(DicomHelpers.GetSampleImagesFolder( ))) { string fullPath = Path.Combine(testDir, Path.GetFileName(file)); fo.DicomDataset sourceDS = fo.DicomFile.Open(file).Dataset; jsonConverter.WriteInlineBinary = true; string sourceJsonDicom = jsonConverter.Convert(sourceDS); System.IO.File.WriteAllText(fullPath + ".jsn", sourceJsonDicom); fo.DicomDataset targetDs = jsonConverter.Convert(sourceJsonDicom); var dsF = new fo.DicomFile(targetDs); dsF.Save(fullPath + ".jsn.dcm"); string destJsonDicom = jsonConverter.Convert(targetDs); System.IO.File.WriteAllText(fullPath + ".gen.jsn", destJsonDicom); Assert.AreEqual(sourceJsonDicom, destJsonDicom); } }
public void Pacs_Storage_Images( ) { EnsureCodecsLoaded( ); StoreService.StoreDicom(DicomHelper.GetDicomDataset(2), new DataAccess.InstanceMetadata( )); int counter = 0; foreach (string file in Directory.GetFiles(DicomHelpers.GetSampleImagesFolder( ))) { var dataset = fo.DicomFile.Open(file).Dataset; //reason is to shorten the path where the DS is stored. //location include the UIDs, so make sure your storage // folder is close to the root when keeping the original UIDs dataset.AddOrUpdate(fo.DicomTag.PatientID, "Patient_" + counter); dataset.AddOrUpdate(fo.DicomTag.StudyInstanceUID, "Study_" + counter); dataset.AddOrUpdate(fo.DicomTag.SeriesInstanceUID, "Series_" + counter); dataset.AddOrUpdate(fo.DicomTag.SOPInstanceUID, "Instance_" + counter); StoreService.StoreDicom(dataset, new DataAccess.InstanceMetadata( )); counter++; } }
public void ConvertToXml( ) { var testDir = Path.Combine(TestDirPath, "convertToXml"); var xmlConverter = new XmlDicomConverter( ) { WriteInlineBinary = true }; Directory.CreateDirectory(testDir); //fo.DicomDataset sourceDS = Helper.GetDicomDataset ( 10 ).Clone ( fo.DicomTransferSyntax.ExplicitVRLittleEndian ) ; foreach (string file in Directory.GetFiles(DicomHelpers.GetSampleImagesFolder( ))) { string fullPath = Path.Combine(testDir, Path.GetFileName(file)); fo.DicomDataset sourceDS = fo.DicomFile.Open(file).Dataset; var sourceXmlDicom = xmlConverter.Convert(sourceDS); System.IO.File.WriteAllText(fullPath + ".xml", sourceXmlDicom); fo.DicomDataset targetDs = xmlConverter.Convert(sourceXmlDicom); var dsF = new fo.DicomFile(targetDs); dsF.FileMetaInfo.TransferSyntax = fo.DicomTransferSyntax.Parse(targetDs.Get(fo.DicomTag.TransferSyntaxUID, targetDs.InternalTransferSyntax.ToString( ))); dsF.Save(fullPath + ".gen.dcm"); var destXmlDicom = xmlConverter.Convert(targetDs); System.IO.File.WriteAllText(fullPath + ".gen.xml", destXmlDicom); //private tags with private creator will cause this to fail //VR for OW change to OB Assert.AreEqual(sourceXmlDicom, destXmlDicom); } }