views:

308

answers:

4

Greetings,

I am currently trying to learn some Java programming. To do this I'm trying to make something actually useful. Because I'm studying Medical Imaging, I though I would write my own Dicom Api in Java.

Part of the Dicom Standard is a Data Dictionary containing attributes used in Dicom Files. These attributes have to following properties.

(Group,Element) Description

For example:
(0x0002,0x0000) Length
(0x0002,0x0002) MediaStoredSOPClassUID
(0x0002,0x0010) TransferSyntaxUID
(0x0003,0x0003) Length

I was wondering how I should implement these in my API. The options I have thought of are:

  • Enum, problem with that is that unique attributes could have the same description.

enum Attributes{ Length(0x0002,0x0000), Length(0x0003,0x0000, }

  • A static class with just some constants containing the properties. Also the problem with the names excists.
  • A xml file containing this data.

I really would like to use xml for this, because of the tabularity of the data and easy access. But is there any way I can include this in my Api.

~Timo Willemsen

+1  A: 

a map will work best for you, define a class that will hold a dicom entry :

public class DicomEntry
{
private: 
    private string group;
    private string element;
    private string vr;
    private string name;

    public string  key() { return String.format("(%s,%s)",group,element); } 
}

also create a map that will hold all the entries

Map<string,DicomEntry> mp=new HashMap<string, DicomEntry>();

after reading each line from your dictionary file into an entry class object de add it the map

 mp.put(de.key(), de)

since the combination of group and element is unique you wound have any collisions

Alon
Okay. First sorry. I thought my intial questions was a bit vague, so I edited it. Sorry for the mix-up. This is also something I thought of.Only the thing that troubles me is this part of your answer "after reading each line from your dictionary file into an entry class object" I know how to do file io. But to design this, I would still have to include a static (xml, csv, txt) file in my API.
Timo Willemsen
I don't see a way around it, hard coding the dictionary into the java source is bad form and will force your to recompile if attributes are added or abstracted from the set. what so bad about including such a file? btw - I prefer to use csv file as it is more readable for humans
Alon
I honestly don't have a good reason why it's not a good idea. Thanks I'll try to work it out.
Timo Willemsen
+2  A: 

To ease the access, the XML file should be placed in the classpath so that you can get its location by ClassLoader#getResource() or its contents by ClassLoader#getResourceAsStream().

To read/evaluate/write the XML file with a standard API, I can recommend StAX. If the XML file is relatively large (over tens of megabytes), then I can recommend VTD-XML more.

Alternatively, if the file is not so large and it are pure key-value pairs, then you can also consider properties files, which you can easily manage with java.util.Properties API which basically extends Map.

BalusC
Thanks a lot! I was not aware of the excistance of properties files. Combined with the answer of Alon I think I can work this out properly.
Timo Willemsen
A: 

You might also want to study other DICOM sources. PixelMed, in particular, contains an XML and XSLT based validator. Several DICOM plugins are available for ImageJ.

trashgod
Thanks for the information. Pixelmed is one of my examples ^^. I was not aware of the ImageJ plugins.
Timo Willemsen
+1  A: 

Here is PS 3.6-2008 as XML as used in GDCM:

http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Source/DataDictionary/Part6.xml?view=markup

As mentionned above, I would also add VM and Retired flag:

 public class DicomEntry {  private: 
     private ushort group;
     private ushort element;
     private string vr;
     private string vm;
     private boolean retired;
     private string name;
     public string  key() { return String.format("(%s,%s)",group,element);
 } }
malat