GDCM memo
Move Scu
1) Study >> Series move
2) Study >> image move
1) Study からSeriesを抽出。series単位で move
2) Study >> image move
1) Study からSeriesを抽出。series単位で move
var scp = new gdcm.ServiceClassUser(); ushort port = 11112; ushort portScp = 104; string aetcalled = "DCM4CHEE"; string aetcalling = "any"; string host = "192.168.0.100"; // string patId = "12345"; //sendmove var scu = new gdcm.ServiceClassUser(); //scu.SetHostname("192.168.17.13"); scu.SetAETitle("any"); scu.SetHostname(host); scu.SetAETitle(aetcalling);// scu.SetPort(port); scu.SetTimeout(1d); scu.SetCalledAETitle(aetcalled); // InitializeConnection if (!scu.InitializeConnection()) { Console.WriteLine("Err :Init"); return; } var generator = new PresentationContextGenerator(); var retDatasets = new DataSetArrayType(); // Find SCU var theTagPair = new gdcm.KeyValuePairArrayType(); theTagPair.Add(new gdcm.KeyValuePairType(new gdcm.Tag(0x0010, 0x0020), patId)); theTagPair.Add(new gdcm.KeyValuePairType(new gdcm.Tag(0x0020, 0x000D), "*")); //StudyInstanceUID var findquery = gdcm.CompositeNetworkFunctions.ConstructQuery(gdcm.ERootType.eStudyRootType, gdcm.EQueryLevel.eStudy, theTagPair); if (!generator.GenerateFromUID(findquery.GetAbstractSyntaxUID())) { Console.WriteLine("Err :VerificationSOPClass"); return; } scu.SetPresentationContexts(generator.GetPresentationContexts()); string studyInstanceUid = string.Empty; string seriesInstanceUid = string.Empty; if (!scu.StartAssociation()) { Console.WriteLine("Err :StartAssociation"); return; } if (scu.SendFind(findquery, retDatasets)) { if (retDatasets.Count > 0) { foreach (gdcm.DataSet d in retDatasets) Console.WriteLine("StudyInstanceUID :" + d.GetDataElement(new gdcm.Tag(0x0020, 0x000D)).toString()); // Find Last StudyInstancUID to SeriesInstanceUID theTagPair = new KeyValuePairArrayType(); studyInstanceUid=retDatasets[retDatasets.Count - 1].GetDataElement(new gdcm.Tag(0x0020, 0x000D)).GetValue().toString(); Console.WriteLine(studyInstanceUid); theTagPair.Add(new gdcm.KeyValuePairType(new gdcm.Tag(0x0020, 0x000D), studyInstanceUid)); theTagPair.Add(new gdcm.KeyValuePairType(new gdcm.Tag(0x0020, 0x000E), "*")); findquery = gdcm.CompositeNetworkFunctions.ConstructQuery(gdcm.ERootType.eStudyRootType, gdcm.EQueryLevel.eSeries, theTagPair); if (!generator.GenerateFromUID(findquery.GetAbstractSyntaxUID())) { Console.WriteLine("Err :VerificationSOPClass"); return; } scu.SetPresentationContexts(generator.GetPresentationContexts()); retDatasets=new DataSetArrayType(); if (scu.SendFind(findquery, retDatasets)) { Console.WriteLine(retDatasets.Count); if (retDatasets.Count > 0) { foreach (gdcm.DataSet d in retDatasets) Console.WriteLine("SeriesInstanceUID :" + d.GetDataElement(new gdcm.Tag(0x0020, 0x000D)).toString()); } } } } if (!scu.StopAssociation()) { Console.WriteLine("Err :scu StopAssociation"); return; } // if (retDatasets.Count == 0) return; var moveds = new gdcm.DataSet(); // Last SeriesInstanceUID moveds.Insert(retDatasets[0].GetDataElement(new gdcm.Tag(0x0020, 0x000D))); moveds.Insert(retDatasets[0].GetDataElement(new gdcm.Tag(0x0020, 0x000E))); // var movequery = gdcm.CompositeNetworkFunctions.ConstructQuery(gdcm.ERootType.eStudyRootType, gdcm.EQueryLevel.eImage, moveds, true); // if (!generator.GenerateFromUID(movequery.GetAbstractSyntaxUID())) { Console.WriteLine("Err :VerificationSOPClass"); return; } scu.SetPresentationContexts(generator.GetPresentationContexts()); scu.SetPortSCP(portScp); //PortSCU if (!scu.StartAssociation()) { Console.WriteLine("Err :scu StartAssociation"); return; } var data = new gdcm.DataSetArrayType(); if (!scu.SendMove(movequery, data)) Console.WriteLine("Err : SendMove"); if (!scu.StopAssociation()) { Console.WriteLine("Err :scu StopAssociation"); return; } foreach (gdcm.DataSet d in data) { // represent Photmetric Interpretation if(d.FindDataElement(new gdcm.Tag(0x0028,0004))) Console.WriteLine(d.GetDataElement(new gdcm.Tag(0x0028,0004)).GetValue().toString()); } Console.WriteLine("...End");
2) Study から imageごとに move
var scp = new gdcm.ServiceClassUser(); ushort port = 11112; ushort portScp = 104; string aetcalled = "DCM4CHEE"; string aetcalling = "any"; string host = "192.168.0.100"; // string patId = "12345"; //sendmove var scu = new gdcm.ServiceClassUser(); //scu.SetHostname("192.168.17.13"); scu.SetAETitle("any"); scu.SetHostname(host); scu.SetAETitle(aetcalling);// scu.SetPort(port); scu.SetTimeout(1d); scu.SetCalledAETitle(aetcalled); // InitializeConnection if (!scu.InitializeConnection()) { Console.WriteLine("Err :Init"); return; } var generator = new PresentationContextGenerator(); var retDatasets = new DataSetArrayType(); // Find SCU var theTagPair = new gdcm.KeyValuePairArrayType(); theTagPair.Add(new KeyValuePairType(new gdcm.Tag(0x0010, 0x0020), patId)); theTagPair.Add(new KeyValuePairType(new gdcm.Tag(0x0008, 0x0018), "*"));//SOPInstanceUID var findquery = gdcm.CompositeNetworkFunctions.ConstructQuery(gdcm.ERootType.eStudyRootType, gdcm.EQueryLevel.eImage, theTagPair); if (!generator.GenerateFromUID(findquery.GetAbstractSyntaxUID())) { Console.WriteLine("Err :VerificationSOPClass"); return; } scu.SetPresentationContexts(generator.GetPresentationContexts()); if (!scu.StartAssociation()) { Console.WriteLine("Err :StartAssociation"); return; } if (!scu.SendFind(findquery, retDatasets)) { Console.WriteLine("Err :SendFind"); return; } if (!scu.StopAssociation()) { Console.WriteLine("Err :scu StopAssociation"); return; } // if (retDatasets.Count == 0) return; var moveds = new gdcm.DataSet(); moveds.Insert(retDatasets[0].GetDataElement(new gdcm.Tag(0x0010, 0x0020))); moveds.Insert(retDatasets[0].GetDataElement(new gdcm.Tag(0x0020, 0x000D))); moveds.Insert(retDatasets[0].GetDataElement(new gdcm.Tag(0x0020, 0x000E))); // var movequery = gdcm.CompositeNetworkFunctions.ConstructQuery(gdcm.ERootType.eStudyRootType, gdcm.EQueryLevel.eImage, moveds, true); // if (!generator.GenerateFromUID(movequery.GetAbstractSyntaxUID())) { Console.WriteLine("Err :VerificationSOPClass"); return; } scu.SetPresentationContexts(generator.GetPresentationContexts()); scu.SetPortSCP(portScp); if (!scu.StartAssociation()) { Console.WriteLine("Err :scu StartAssociation"); return; } for (int i = 0; i < retDatasets.Count; i++) { var queryds = movequery.GetQueryDataSet(); var instanceuid = retDatasets[i].GetDataElement(new gdcm.Tag(0x0008, 0x0018)); Console.WriteLine(instanceuid.toString()); queryds.Replace(instanceuid); var data = new gdcm.DataSetArrayType(); if (!scu.SendMove(movequery, data)) { Console.WriteLine("Err : SendMove"); break; } var d = data[0]; // represent Photmetric Interpretation if (d.FindDataElement(new gdcm.Tag(0x0028, 0004))) Console.WriteLine(d.GetDataElement(new gdcm.Tag(0x0028, 0004)).GetValue().toString()); } if (!scu.StopAssociation()) { Console.WriteLine("Err :scu StopAssociation"); return; } Console.WriteLine("End");