List<InstanceLocator> list = new ArrayList<InstanceLocator>();
String[] patIDs = keys.getStrings(Tag.PatientID);
String[] studyIUIDs = keys.getStrings(Tag.StudyInstanceUID);
String[] seriesIUIDs = keys.getStrings(Tag.SeriesInstanceUID);
String[] sopIUIDs = keys.getStrings(Tag.SOPInstanceUID);
DicomDirReader ddr = ddReader;
Attributes patRec = ddr.findPatientRecord(patIDs);
while (patRec != null) {
Attributes studyRec = ddr.findStudyRecord(patRec, studyIUIDs);
while (studyRec != null) {
Attributes seriesRec = ddr.findSeriesRecord(studyRec, seriesIUIDs);
while (seriesRec != null) {
Attributes instRec = ddr.findLowerInstanceRecord(seriesRec, true, sopIUIDs);
while (instRec != null) {
String cuid = instRec.getString(Tag.ReferencedSOPClassUIDInFile);
String iuid = instRec.getString(Tag.ReferencedSOPInstanceUIDInFile);
String tsuid = instRec.getString(Tag.ReferencedTransferSyntaxUIDInFile);
String[] fileIDs = instRec.getStrings(Tag.ReferencedFileID);
String uri = ddr.toFile(fileIDs).toURI().toString();
list.add(new InstanceLocator(cuid, iuid, tsuid, uri));
if (sopIUIDs != null && sopIUIDs.length == 1)
break;
instRec = ddr.findNextInstanceRecord(instRec, true, sopIUIDs);
}
if (seriesIUIDs != null && seriesIUIDs.length == 1)
break;
seriesRec = ddr.findNextSeriesRecord(seriesRec, seriesIUIDs);
}
if (studyIUIDs != null && studyIUIDs.length == 1)
break;
studyRec = ddr.findNextStudyRecord(studyRec, studyIUIDs);
}
if (patIDs != null && patIDs.length == 1)
break;
patRec = ddr.findNextPatientRecord(patRec, patIDs);
}
return list;
} catch (IOException e) {
throw new DicomServiceException(Status.UnableToCalculateNumberOfMatches, e);
}