Here first answer :
/**
- Modify metadata dicom
- not vr= SQ
- @param file : input File
- @param tagChooser: choosing tag
- @param aModify : "valueString"
- @param vr : vr of Tag choosing
- @param newString : new String
- exemple:
try {
Dicom.changementTag(chooser.getSelectedFile(), Tag.PatientName , "Dimitri",
VR.PN, "piane" );
} catch (IOException e) {
e.printStackTrace();
}
*/
public static void changementTag(File file, int tagChooser, String aModify, VR vr, String newString ) throws IOException{
DicomInputStream dis = new DicomInputStream(file);
DicomObject dio = dis.readDicomObject();
dis.close();
boolean change = false;
if(dio.getString(tagChooser).equals(aModify )){
dio.putString(tagChooser, vr, newString);
change = true;
}
if(change){
FileOutputStream fos = new FileOutputStream( new File(file.getParent()+ "/"file.getName() "(" + "modifier"+ ")"+".dcm"));
BufferedOutputStream bos = new BufferedOutputStream(fos);
DicomOutputStream dos = new DicomOutputStream(bos);
dos.writeDicomFile(dio);
dos.close();
}
}
or orther method following :
/**
- Modify metadata dicom
- not vr= SQ
- @param file : input File
- @param tagChooser: choosing tag
- @param aModify : "valueString"
- @param vr : vr of Tag choosing
- @param newString : new String
- Example:
- JChooser choix = new JChooser();
int retour = choix.showOpenDialog(parent);
*
- if(retour == JFileChooser.APPROVE_OPTION){
fileInput = choix.getSelectedFile();
JFileChooser saveDicom = new JFileChooser();
saveDicom.setMultiSelectionEnabled(false);
saveDicom.showSaveDialog(null);
File fileOutput =saveDicom.getSelectedFile();
} else return;
- changementTag2(fileInput, int tagChooser, String aModify, VR vr, String newString, fileOutput)
*/
public static void changementTag2(File fileInput, int tagChooser, String
aModify, VR vr, String newString, File fileOutput ) throws IOException{
DicomInputStream dis = new DicomInputStream(fileInput);
DicomObject dio = dis.readDicomObject();
dis.close();
boolean change = false;
if(dio.getString(tagChooser).equals(aModify )){
dio.putString(tagChooser, vr, newString);
change = true;
}
if(change){
FileOutputStream fos = new FileOutputStream(fileOutput +".dcm");
BufferedOutputStream bos = new BufferedOutputStream(fos);
DicomOutputStream dos = new DicomOutputStream(bos);
dos.writeDicomFile(dio);
dos.close();
}
}
and the file
displayTag who are differents methods for processing metadata DICOM with dcm4che2.