Implementing a Query/Retrieve SCU
Query/Retrieve service is made up of two phases:
- the SCU sends some data element to the SCP (specific patient, specific date of exam, etc...) and the SCP answers with a list of objects it can send that satisfy the conditions.
 - the SCU sends a list of objects (usually from the list returned at phase 1) and the SCP sends these objects.
 
Here is a example using DeCaMino that asks the archive at server.hospital.com for all images concerning a patient whose ID is 1234. The images will be sent by the archive using the storage service, so a Storage SCP must first be started by the application running the Query/Retrieve SCU:
DicomReader reader = new DicomReader();
PeerAE peer = new PeerAE(InetAddress.getByName("server.hospital.com"), "ARCHIVE");
QueryRetrieveSCU scu = new QueryRetrieveSCU(peer, reader);
new StorageSCP(o -> {
  reader.setInput(o);
  DicomMetadata dmd = reader.getDicomMetadata();
  /* Do something with received image */
}).start();
Identifier query = new Identifier(Identifier.MODEL_QR_PATIENT_ROOT, Identifier.LEVEL_PATIENT);
query.set(Tag.PatientID, 1234);
for (Identifier id: scu.find(query)) {
  /* Received a response, ask the SCP to move the object to us */
  scu.move(query);
}
scu.close();