in util/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/AttributesUtil.java [198:229]
private static void setAttributeValue(Attributes attrs, int tag, VR vr, JSONArray jsonValues)
throws DicomServiceException {
if (vr == VR.PN) {
setPatientNames(attrs, tag, jsonValues);
} else if (vr.isStringType() || vr == VR.AT) {
String[] values = jsonValues.toList().stream().map(Object::toString)
.collect(Collectors.toList()).toArray(new String[]{});
attrs.setString(tag, vr, values);
} else if (vr.isIntType()) {
int[] values = jsonValues.toList().stream().mapToInt(i -> Integer.parseInt(i.toString()))
.toArray();
attrs.setInt(tag, vr, values);
} else {
switch (vr) {
case SQ:
Sequence sequence = attrs.newSequence(tag, jsonValues.length());
for (Object seqElement : jsonValues) {
Attributes seqElementAttributes = jsonToAttributes((JSONObject) seqElement);
sequence.add(seqElementAttributes);
}
break;
case FL:
case FD:
double[] dValues = jsonValues.toList().stream().mapToDouble(i -> ((BigDecimal) i).doubleValue()).toArray();
attrs.setDouble(tag, vr, dValues);
break;
default:
throw new DicomServiceException(Status.ProcessingFailure,
"Unsupported VR " + vr.toString());
}
}
}