public static TemporalAccessor[] getDatesFromElement(XMLStreamReader xmler, String attribute, TagType type, TemporalAccessor[] defaultValue, String separator) { if (attribute != null) { String val = xmler.getAttributeValue(null, attribute); if (val != null) { String[] strs = val.split(Pattern.quote(separator)); TemporalAccessor[] vals = new TemporalAccessor[strs.length]; for (int i = 0; i < strs.length; i++) { try { if (TagType.TIME.equals(type)) { vals[i] = LocalTime.parse(strs[i]); } else if (TagType.DATETIME.equals(type)) { vals[i] = LocalDateTime.parse(strs[i]); } else { vals[i] = LocalDate.parse(strs[i]); } } catch (Exception e) { LOGGER.error("Parse date", e); //$NON-NLS-1$ } } return vals; } } return defaultValue; }
public static TemporalAccessor getDateFromElement(XMLStreamReader xmler, String attribute, TagType type, TemporalAccessor defaultValue) { if (attribute != null) { String val = xmler.getAttributeValue(null, attribute); if (val != null) { try { if (TagType.TIME.equals(type)) { return LocalTime.parse(val); } else if (TagType.DATETIME.equals(type)) { return LocalDateTime.parse(val); } else { return LocalDate.parse(val); } } catch (Exception e) { LOGGER.error("Parse date", e); //$NON-NLS-1$ } } } return defaultValue; }
@Override public String getFormattedTagValue(Object value, String format) { if (value == null) { return StringUtil.EMPTY_STRING; } if (TagType.DICOM_PERSON_NAME.equals(type)) { if (value instanceof String[]) { return Arrays.asList((String[]) value).stream().map(TagD::getDicomPersonName) .collect(Collectors.joining(", ")); //$NON-NLS-1$ } return getDicomPersonName(value.toString()); } else if (TagType.DICOM_PERIOD.equals(type)) { return getDicomPeriod(value.toString()); } else if (TagType.DICOM_SEX.equals(type)) { return getDicomPatientSex(value.toString()); } return super.getFormattedTagValue(value, format); }
} else if (TagType.DICOM_DATE.equals(type)) { if (vmMax > 1) { String[] ss = toStrings(data); } else if (TagType.DICOM_TIME.equals(type)) { if (vmMax > 1) { String[] ss = toStrings(data); } else if (TagType.DICOM_DATETIME.equals(type)) { if (vmMax > 1) { String[] ss = toStrings(data); } else if (TagType.INTEGER.equals(type)) { if (vmMax > 1) { String[] ss = toStrings(data); } else if (TagType.FLOAT.equals(type)) { if (vmMax > 1) { String[] ss = toStrings(data); } else if (TagType.DOUBLE.equals(type)) { if (vmMax > 1) { String[] ss = toStrings(data); } else if (TagType.DICOM_SEQUENCE.equals(type)) { value = data; } else {
dataset.setString(id, dic.vrOf(id), val.toString()); } else if (TagType.DICOM_DATE.equals(type) || TagType.DICOM_TIME.equals(type) || TagType.DICOM_DATETIME.equals(type)) { if (val instanceof TemporalAccessor) { dataset.setDate(id, dic.vrOf(id), TagUtil.toLocalDate((TemporalAccessor) val)); dataset.setDate(id, dic.vrOf(id), TagUtil.toLocalDates(val)); } else if (TagType.INTEGER.equals(type)) { if (val instanceof Integer) { dataset.setInt(id, dic.vrOf(id), (Integer) val); dataset.setInt(id, dic.vrOf(id), (int[]) val); } else if (TagType.FLOAT.equals(type)) { if (val instanceof Float) { dataset.setFloat(id, dic.vrOf(id), (Float) val); dataset.setFloat(id, dic.vrOf(id), (float[]) val); } else if (TagType.DOUBLE.equals(type)) { if (val instanceof Double) { dataset.setDouble(id, dic.vrOf(id), (Double) val); } else if (TagType.DICOM_SEQUENCE.equals(type) && val instanceof Attributes[]) { Attributes[] sIn = (Attributes[]) val; Sequence sOut = dataset.newSequence(id, sIn.length);
? DicomMediaUtils.getStringArrayFromDicomElement(dataset, id, privateCreatorID, (String[]) defaultValue) : dataset.getString(privateCreatorID, id, (String) defaultValue); } else if (TagType.DICOM_DATE.equals(type) || TagType.DICOM_TIME.equals(type) || TagType.DICOM_DATETIME.equals(type)) { value = vmMax > 1 ? DicomMediaUtils.getDatesFromDicomElement(type, dataset, id, privateCreatorID, : DicomMediaUtils.getDateFromDicomElement(type, dataset, id, privateCreatorID, (TemporalAccessor) defaultValue); } else if (TagType.INTEGER.equals(type)) { value = vmMax > 1 ? DicomMediaUtils.getIntArrayFromDicomElement(dataset, id, privateCreatorID, (int[]) defaultValue) : DicomMediaUtils.getIntegerFromDicomElement(dataset, id, privateCreatorID, (Integer) defaultValue); } else if (TagType.FLOAT.equals(type)) { value = vmMax > 1 ? DicomMediaUtils.getFloatArrayFromDicomElement(dataset, id, privateCreatorID, (float[]) defaultValue) : DicomMediaUtils.getFloatFromDicomElement(dataset, id, privateCreatorID, (Float) defaultValue); } else if (TagType.DOUBLE.equals(type)) { value = vmMax > 1 ? DicomMediaUtils.getDoubleArrayFromDicomElement(dataset, id, privateCreatorID, (double[]) defaultValue) : DicomMediaUtils.getDoubleFromDicomElement(dataset, id, privateCreatorID, (Double) defaultValue); } else if (TagType.DICOM_SEQUENCE.equals(type)) { value = dataset.getSequence(privateCreatorID, id); } else {
private Object readValue(XMLStreamReader xmler) { Object value; if (isStringFamilyType()) { value = vmMax > 1 ? TagUtil.getStringArrayTagAttribute(xmler, keyword, (String[]) defaultValue) : TagUtil.getTagAttribute(xmler, keyword, (String) defaultValue); } else if (TagType.DICOM_DATE.equals(type) || TagType.DICOM_TIME.equals(type) || TagType.DICOM_DATETIME.equals(type)) { value = vmMax > 1 ? getDatesFromElement(xmler, keyword, type, (TemporalAccessor[]) defaultValue) : getDateFromElement(xmler, keyword, type, (TemporalAccessor) defaultValue); } else if (TagType.INTEGER.equals(type)) { value = vmMax > 1 ? TagUtil.getIntArrayTagAttribute(xmler, keyword, (int[]) defaultValue) : TagUtil.getIntegerTagAttribute(xmler, keyword, (Integer) defaultValue); } else if (TagType.FLOAT.equals(type)) { value = vmMax > 1 ? TagUtil.getFloatArrayTagAttribute(xmler, keyword, (float[]) defaultValue) : TagUtil.getFloatTagAttribute(xmler, keyword, (Float) defaultValue); } else if (TagType.DOUBLE.equals(type)) { value = vmMax > 1 ? TagUtil.getDoubleArrayTagAttribute(xmler, keyword, (double[]) defaultValue) : TagUtil.getDoubleTagAttribute(xmler, keyword, (Double) defaultValue); } else if (TagType.DICOM_SEQUENCE.equals(type)) { value = TagUtil.getTagAttribute(xmler, keyword, (String) defaultValue); } else { value = vmMax > 1 ? TagUtil.getStringArrayTagAttribute(xmler, keyword, (String[]) defaultValue) : TagUtil.getTagAttribute(xmler, keyword, (String) defaultValue); } return value; }
public Object getValue(Object data) { Object value = null; if (data instanceof XMLStreamReader) { XMLStreamReader xmler = (XMLStreamReader) data; if (isStringFamilyType()) { value = vmMax > 1 ? TagUtil.getStringArrayTagAttribute(xmler, keyword, (String[]) defaultValue) : TagUtil.getTagAttribute(xmler, keyword, (String) defaultValue); } else if (TagType.DATE.equals(type) || TagType.TIME.equals(type) || TagType.DATETIME.equals(type)) { value = vmMax > 1 ? TagUtil.getDatesFromElement(xmler, keyword, type, (TemporalAccessor[]) defaultValue) : TagUtil.getDateFromElement(xmler, keyword, type, (TemporalAccessor) defaultValue); } else if (TagType.INTEGER.equals(type)) { value = vmMax > 1 ? TagUtil.getIntArrayTagAttribute(xmler, keyword, (int[]) defaultValue) : TagUtil.getIntegerTagAttribute(xmler, keyword, (Integer) defaultValue); } else if (TagType.FLOAT.equals(type)) { value = vmMax > 1 ? TagUtil.getFloatArrayTagAttribute(xmler, keyword, (float[]) defaultValue) : TagUtil.getFloatTagAttribute(xmler, keyword, (Float) defaultValue); } else if (TagType.DOUBLE.equals(type)) { value = vmMax > 1 ? TagUtil.getDoubleArrayTagAttribute(xmler, keyword, (double[]) defaultValue) : TagUtil.getDoubleTagAttribute(xmler, keyword, (Double) defaultValue); } else { value = vmMax > 1 ? TagUtil.getStringArrayTagAttribute(xmler, keyword, (String[]) defaultValue) : TagUtil.getTagAttribute(xmler, keyword, (String) defaultValue); } } return value; }
public static TemporalAccessor[] getDatesFromElement(XMLStreamReader xmler, String attribute, TagType type, TemporalAccessor[] defaultValue, String separator) { if (attribute != null) { String val = xmler.getAttributeValue(null, attribute); if (val != null) { String[] strs = val.split(Pattern.quote(separator)); TemporalAccessor[] vals = new TemporalAccessor[strs.length]; for (int i = 0; i < strs.length; i++) { if (TagType.TIME.equals(type)) { vals[i] = getDicomTime(strs[i]); } else if (TagType.DATETIME.equals(type)) { vals[i] = getDicomDateTime(null, strs[i]); } else { vals[i] = getDicomDate(strs[i]); } } return vals; } } return defaultValue; }
public static TemporalAccessor[] getDatesFromDicomElement(XMLStreamReader xmler, String attribute, TagType type, TemporalAccessor[] defaultValue, String separator) { if (attribute != null) { String val = xmler.getAttributeValue(null, attribute); if (val != null) { String[] strs = val.split(Pattern.quote(separator)); TemporalAccessor[] vals = new TemporalAccessor[strs.length]; for (int i = 0; i < strs.length; i++) { if (TagType.DICOM_TIME.equals(type)) { vals[i] = TagD.getDicomTime(strs[i]); } else if (TagType.DICOM_DATETIME.equals(type)) { vals[i] = TagD.getDicomDateTime(null, strs[i]); } else { vals[i] = TagD.getDicomDate(strs[i]); } } return vals; } } return defaultValue; }
public static TemporalAccessor getDateFromDicomElement(XMLStreamReader xmler, String attribute, TagType type, TemporalAccessor defaultValue) { if (attribute != null) { String val = xmler.getAttributeValue(null, attribute); if (val != null) { if (TagType.DICOM_TIME.equals(type)) { return TagD.getDicomTime(val); } else if (TagType.DICOM_DATETIME.equals(type)) { return TagD.getDicomDateTime(null, val); } else { return TagD.getDicomDate(val); } } } return defaultValue; }
public static TemporalAccessor getDateFromElement(XMLStreamReader xmler, String attribute, TagType type, TemporalAccessor defaultValue) { if (attribute != null) { String val = xmler.getAttributeValue(null, attribute); if (val != null) { if (TagType.DICOM_TIME.equals(type)) { return getDicomTime(val); } else if (TagType.DICOM_DATETIME.equals(type)) { return getDicomDateTime(null, val); } else { return getDicomDate(val); } } } return defaultValue; }