|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||
See:
Description
| Packages | |
|---|---|
| jdcm | |
Sample code.
Reading dicom files
try {
DicomFile dicomFile = new DicomFile("DicomFile.dcm");
System.out.println(dicomFile);
} catch(IOException e) {}
StoreSCU
import java.util.*;
import java.io.*;
import java.net.*;
import jdcm.*;
public class StoreSCU {
public StoreSCU() {
}
public static void main(String args[]) {
try{
StaticProperties.VERBOSE = true;
//retrieve dicom SOP Class UID and transfer syntax UID in file
DicomFile dicomFile = new DicomFile("DicomFile.dcm");
String affectedSOPClass = dicomFile.getAffectedSOPClassUID();
String transfertSyntax = dicomFile.getTransferSyntaxUID();
//connect and create an association object
Socket socket = new Socket("localhost",5555);
//prepare a request object with calling title,called title,
//abstract syntax and transfer syntax.
A_Associate associate = new A_Associate(socket,"JDCM","ANY_SCP",affectedSOPClass,transfertSyntax);
//send the request
associate.writeRQ();
//receive the response and analyse the response
int statusRPS = associate.readRPS();
if (statusRPS == A_Associate.ASSOCIATION_REJECTED)
return;
//create a C-STORE REQUEST, send it and receive the response
C_Store store = new C_Store(associate);
store.writeRQ(dicomFile.getDicomSet());
store.readRPS();
//release the association
A_Release release = new A_Release(associate);
release.writeRQ();
release.readRPS();
//close conection
associate.close();
socket.close();
} catch(IOException e) {}
}
}
FindSCU
import jdcm.*;
import java.net.*;
public class FindSCU {
public static void main(String args[]) {
try{
//connect and create an association object
Socket socket = new Socket("localhost",5555);
//prepare a request object with calling title,called title,
//information model and transfer syntax.
A_Associate associate = new A_Associate(socket,"JDCM","ANY_SCP",StaticProperties.SOPClass_PatientRootQueryRetrieveInformationModelFIND,StaticProperties.TS_BIG_ENDIAN_EXPLICIT);
//send the request
associate.writeRQ();
//receive the response and analyse the response
int status = associate.readRPS();
if (status == A_Associate.ASSOCIATION_REJECTED)
return;
//create a C-FIND REQUEST and send it
C_Find find = new C_Find(associate);
find.setAffectedSOPClassUID(StaticProperties.SOPClass_PatientRootQueryRetrieveInformationModelFIND);
//prepare C-FIND message
DicomSet dicomSet = new DicomSet();
dicomSet.setElement(new DicomElement(0x0008,0x0052,"CS","PATIENT"));
dicomSet.setElement(new DicomElement(0x0010,0x0010,"PN","*"));
dicomSet.setElement(new DicomElement(0x0010,0x0020,"LO","*"));
dicomSet.setElement(new DicomElement(0x0010,0x0040,"CS","*"));
find.writeRQ(dicomSet);
//receive the responses
do{
dicomSet = find.readRPS();
status = find.getStatus();
//print reponses
System.out.println();
System.out.println(dicomSet);
//analyse status responses (pending or succesfully)
} while(status != 0);
//release association
A_Release release = new A_Release(associate);
release.writeRQ();
//close conecction
associate.close();
socket.close();
} catch(Exception e) {}
}
}
MoveSCU
import java.net.*;
import java.io.*;
import jdcm.*;
public class MoveSCU {
public static void main(String args[]) {
try {
//connect and create an association object
Socket socket = new Socket("localhost",5555);
//prepare a request object with calling title,called title,
// information model and transfer syntax
A_Associate associate = new A_Associate(socket,"JDCM","ANY_SCP",StaticProperties.SOPClass_PatientRootQueryRetrieveInformationModelMOVE,StaticProperties.TS_LITTLE_ENDIAN_EXPLICIT);
//send the request
associate.writeRQ();
//receive the response and analyse the response
int status = associate.readRPS();
if ( status == A_Associate.ASSOCIATION_REJECTED)
return;
//create a C-MOVE REQUEST and send it
C_Move move = new C_Move(associate);
move.setAffectedSOPClassUID(StaticProperties.SOPClass_PatientRootQueryRetrieveInformationModelMOVE);
//prepare C-MOVE message
DicomSet dicomSet = new DicomSet();
dicomSet.setElement(new DicomElement(0x0008,0x0052,"PN","STUDY"));
dicomSet.setElement(new DicomElement(0x0010,0x0020,"LO","95492"));
dicomSet.setElement(new DicomElement(0x0020,0x000d,"UI","1.2.124.113532.129.195.3.60.20021004.101853.990083"));
move.setCstoreSubOp ("JDCM");
move.writeRQ(dicomSet);
//receive the responses
do{
dicomSet = move.readRPS();
status = move.getStatus();
//print reponses
System.out.println();
System.out.println(dicomSet);
//analyse status responses (pending or succesfully)
} while(status != 0);
//release association
A_Release release = new A_Release(associate);
release.writeRQ();
//close conecction
associate.close();
socket.close();
} catch(IOException e) {}
}
}
StoreSCP
import java.net.*;
import java.io.*;
import jdcm.*;
public class StoreSCP extends DCMServer {
private A_Associate associate;
public StoreSCP(Socket socket) throws IOException {
super(socket);
}
//incoming assocition
public void A_Associate(A_Associate associate) throws IOException {
this.associate = associate;
associate.readRQ();
//Everything you need to know about the
//association is provided in the associate object
System.out.println("CallingEntity "+associate.getCallingEntity());
System.out.println("CalledEntity "+associate.getCalledEntity());
associate.writeRPS();
}
//Verification SCP (C-ECHO)
public void C_Echo(DimseService dimseService) throws IOException {
dimseService.readRQ();
dimseService.setStatus(0x0000);
dimseService.writeRPS(null);
}
//Storeage SCP (C-STORE)
public void C_Store(DimseService dimseService) throws IOException {
DicomSet dicomSet = dimseService.readRQ();
boolean anonyme = true;
try {
//data set saved to receivedFile.dcm
((C_Store) dimseService).writeFile("receivedFile.dcm");
dimseService.setStatus(0x0000);
} catch(IOException e) {
//Failed received stream
dimseService.setStatus(0xA700);
}
dimseService.writeRPS(null);
}
//release
public void A_Release(A_Release release) throws IOException {
release.readRQ ();
release.writeRPS ();
associate.close ();
}
//When an application acts as an association receiver, it waits
//for incoming TCP/IP connections with the accept() method from
//java.net.ServerSocket and devotes a thread (StoreSCP class) to
//every incoming association.
public static void main(String[] args){
try {
StoreSCP storeSCP;
Socket socket;
ServerSocket serverSocket =new ServerSocket(4567);
//start a serversocket
while(true) {
socket = serverSocket.accept();
storeSCP = new StoreSCP(socket);
storeSCP.start();
}
} catch(Exception e){}
}
}
Creating dicom File
try {
//Secondary Capture data set
DicomSet ds = new DicomSet();
ds.setElement(new DicomElement(0x0008,0x0008,"UI",new String[] {"DERIVED","SECONDARY"}));
ds.setElement(new DicomElement(0x0008,0x0016,"UI","1.2.840.10008.5.1.4.1.1.7"));
ds.setElement(new DicomElement(0x0008,0x0018,"UI",StaticProperties.UIDGenerator()));
ds.setElement(new DicomElement(0x0008,0x0020,"DA","19961029"));
ds.setElement(new DicomElement(0x0008,0x0020,"TM","151859.000000"));
ds.setElement(new DicomElement(0x0008,0x0020,"TM","710000"));
ds.setElement(new DicomElement(0x0008,0x0060,"CS","DV"));
ds.setElement(new DicomElement(0x0008,0x0090,"PN","Dr Peter"));
ds.setElement(new DicomElement(0x0010,0x0010,"PN","MATT"));
ds.setElement(new DicomElement(0x0010,0x0020,"LO","710000"));
ds.setElement(new DicomElement(0x0010,0x0030,"DA","19961029"));
ds.setElement(new DicomElement(0x0010,0x0040,"CS","M"));
ds.setElement(new DicomElement(0x0020,0x000d,"UI",StaticProperties.UIDGenerator()));
ds.setElement(new DicomElement(0x0020,0x000e,"UI",StaticProperties.UIDGenerator()));
ds.setElement(new DicomElement(0x0020,0x0010,"SH","710000"));
ds.setElement(new DicomElement(0x0020,0x0011,"IS","1"));
ds.setElement(new DicomElement(0x0020,0x0013,"IS","1"));
ds.setElement(new DicomElement(0x0028,0x0002,"US",1));
ds.setElement(new DicomElement(0x0028,0x0004,"CS","MONOCHROME2"));
ds.setElement(new DicomElement(0x0028,0x0006,"US",1));
ds.setElement(new DicomElement(0x0028,0x0010,"US",480));
ds.setElement(new DicomElement(0x0028,0x0011,"US",640));
ds.setElement(new DicomElement(0x0028,0x0100,"US",8));
ds.setElement(new DicomElement(0x0028,0x0101,"US",8));
ds.setElement(new DicomElement(0x0028,0x0102,"US",7));
ds.setElement(new DicomElement(0x0028,0x0103,"US",0));
DicomSet ds2 = new DicomSet();
ds2.setElement(new DicomElement(0x0029,0x2523,"FD",0.6));
ds2.setElement(new DicomElement(0x0029,0x2801,"FL",new double[]{1463.49,1540.18}));
DicomSequence sequence = new DicomSequence(ds2,true);
ds.setElement(new DicomElement(0x0029,0x25cd,"SQ",sequence));
//prepare pixel data
byte[] raw = new byte[640*480];
for (int i = 0; i < 640;i++)
for (int j = 0; j< 480;j++)
raw[j*640+i] = (byte)(i + j);
ds.setElement(new DicomElement(0x7fe0,0x0010,"OB",raw));
//write file with litte explicit syntax transfer
DicomFile dicomFile = new DicomFile(ds);
dicomFile.setTransferSyntaxUID(StaticProperties.TS_LITTLE_ENDIAN_EXPLICIT);
dicomFile.write("dcmfile.dcm");
} catch(IOException e){}
Copyright © 2001-2006, JDCM
|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||