ryekayo
ryekayo

Reputation: 2431

Parsing DICOM tags to an ArrayList<String>

I am using dcm4chee2 to parse through tags with their DicomInputStream and DicomObject. I am then converting the metadata into a ArrayList of type String. However, when I use the toString() method to convert the tags from DicomObject to a String, I am noticing I am not getting a full list of DICOM tags, VR Codes, and Description. Can anyone tell me if there is another DicomObject method I should be using to get a full list rather than the toString()?

Here is the code I currently have:

    ArrayList<String> dicomTags = new ArrayList<String>();
    DicomInputStream din = null;
    FileOutputStream fos = new FileOutputStream("dicomTagResults.txt");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    din = new DicomInputStream(new File(pathName));
    try {
        DicomObject dcmObj = din.readDicomObject();
        dicomTags.add(dcmObj.toString());
        for (String findMatch : dicomTags){
            System.out.println(findMatch.toString());
            oos.writeObject(dicomTags);
            oos.close();
        }

    }
    catch (IOException e)
    {
        e.printStackTrace();
        return;
    }

Upvotes: 0

Views: 1501

Answers (1)

cneller
cneller

Reputation: 1582

You can use

toStringBuffer(StringBuffer sb, DicomObjectToStringParam param)

and define a different DicomObjectToStringParam object (I suspect that it is not providing all of the attributes because the defaults are too small for your dataset).

If you truly want to loop through all of the attributes, you're probably better off using

Iterator<DicomElement> data = dcmObj.datasetIterator();

and handling the sequence elements appropriately as you loop through the iterator.

Upvotes: 4

Related Questions