in util/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/AttributesUtil.java [103:161]
public static String attributesToQidoPath(Attributes attrs, String... includeFields)
throws DicomServiceException {
HashSet<Integer> nonEmptyKeys = new HashSet<>();
HashSet<String> includeFieldSet = new HashSet<>(Arrays.asList(includeFields));
// SpecificCharacterSet is not supported, and passing it as param or include would be wrong
attrs.remove(Tag.SpecificCharacterSet);
for (int tag : attrs.tags()) {
if (attrs.containsValue(tag)) {
nonEmptyKeys.add(tag);
} else {
includeFieldSet.add(TagUtils.toHexString(tag));
}
}
StringBuilder qidoPath = new StringBuilder();
if (nonEmptyKeys.contains(Tag.QueryRetrieveLevel)) {
switch (attrs.getString(Tag.QueryRetrieveLevel)) {
case "STUDY":
qidoPath.append("studies?limit=" + STUDIES_SERIES_LIMIT + "&");
break;
case "SERIES":
qidoPath.append("series?limit=" + STUDIES_SERIES_LIMIT + "&");
break;
case "IMAGE":
qidoPath.append("instances?limit=" + INSTANCES_LIMIT + "&");
break;
default:
throw new DicomServiceException(Status.ProcessingFailure,
"Invalid QueryRetrieveLevel specified");
}
nonEmptyKeys.remove(Tag.QueryRetrieveLevel);
} else {
throw new DicomServiceException(Status.ProcessingFailure, "No QueryRetrieveLevel specified");
}
if (includeFieldSet.size() > 0) {
for (String includeField : includeFieldSet) {
qidoPath.append("includefield=" + includeField + "&");
}
}
for (int keyTag : nonEmptyKeys) {
// non-string type search keys don't seem to exist
// multiple values are valid for UID lists, but unsupported by api. Invalid for other VRs.
String[] values = attrs.getStrings(keyTag);
if (values.length > 1) {
throw new DicomServiceException(Status.ProcessingFailure,
"Multiple values per tag not supported, tag: " + TagUtils.toHexString(keyTag));
}
for (String value : values) {
String encodedValue;
encodedValue = URLEncoder.encode(value, StandardCharsets.UTF_8);
qidoPath.append(TagUtils.toHexString(keyTag) + "=" + encodedValue + "&");
}
}
return qidoPath.toString();
}