1.pom依赖
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-core</artifactId>
<version>5.22.5</version>
</dependency>
2.代码块
/**
* 获取属性对象 Attributes
*
* @param file dicom文件File
* @return
*/
public static Attributes initAttributes(File file) {
Attributes attr = null;
try {
DicomInputStream dis = new DicomInputStream(file);
dis.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
attr = dis.readDataset(-1, -1);
dis.close();
} catch (IOException e) {
log.error("获取 Attributes 失败!");
return null;
}
String characterSet = attr.getString(Tag.SpecificCharacterSet);
if (StringUtils.isBlank(characterSet) || !characterSet.equals("GB18030")) { // 设置编码,防止乱码
attr.setString(Tag.SpecificCharacterSet, VR.PN, "GB18030");
attr.setString(Tag.SpecificCharacterSet, VR.CS, "GB18030");
}
return attr;
}
3.提取文件信息
比如提取患者姓名
String patientName = attr.getString(Tag.PatientName);