-
I'd like to be able to create a Dataset, specifically a Modality Worklist File (.wl) from an "order" in JSON format. As an example shown below. This is a nice format that is simple to deal with because it uses the short names from the dicom dictionary and omits the vr type. I'd like to be able to iterate through that dataset and create a .wl (DICOM file) from that and then save it to a folder on my filesystem. If I had static propertynames I could just use the '.dot' notation, but the names are dynamic as I iterate through the list, and for sequences the property values will be of type 'list', rather than 'str', which is fine because I'll have to recurse through those somehow to account for sequences. I noticed that Objects of type PersonName are sort of a special case through some other code that I wrote.
So, my question is, how can I use the dot notation with dynamic names to create a dataset from my JSON file description ? I did find this on SO, but not sure that applies here: The relevant add options from the pydicom documentation are: Add an element to the Dataset (for elements in the DICOM dictionary):
Add a sequence element to the Dataset
Add private elements to the Dataset
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
This actually sort of works, just need to have it handle sequences where sample is my sample dataset above. setattr(mwlDataSet, key, value)
|
Beta Was this translation helpful? Give feedback.
-
This might actually work: Takes in a MWL or just Gernally DICOM File description in JSON format using ShortNames and Values, and a blank dataset, and then returns a Dataset, using recursion for sequences:
I'll have to test further, but the output I am getting with the test JSON as follows, some data removed. I'll keep working on that, but looks like as easy way to create a MWL from just a JSON description as in the example.
|
Beta Was this translation helpful? Give feedback.
-
Thanks. I have not completely tested it, but it does seem to work with my sample JSON object. That is a really convenient way to create a dataset from just simple JSON. The .to_json() produces something similar for JSON, but it explicitly includes the vr's and Values. For my application, I'd like to use the simpler JSON noted above to create a DataSet and then write it to the filesystem. BTW, not sure you use Docker much. I have some Orthanc instances running with my MPPS/MWL container (Python container), and I tried sharing a mount / bind between the 2 containers. I cannot write the dataset, e.g. mwlDataSet.save_as('/MWLFiles2/test.wl') to the shared bind, but I can write to a bind that is only used by the MPPS/MWL container. Not sure if that is related to my Docker setup or something to do with the Orthanc Instance locking that folder. I get a permissions error when trying to write to the shared folder, and I get a little "lock" symbol showing up on my Mac OS Host. Could be all kinds of issues really since Mac OS has some more complicated permissions of late. I pulled some stuff from you documentation to write the file and to set the MetaHeader. I need to correctly set the Header Info to the correct data for MRImages, or pull them from the DataSet, although I think MWL files don't actually need the MetaHeader. A dcmdump of the file that is successfully written seems to check out. Is there a way to automatically set the Meta header by just reading the modality from the DataSet ?
Thanks. |
Beta Was this translation helpful? Give feedback.
Revisited this after quite a hiatus. This might actually be better because it can handle nested sequence and some other issues. Still need to really test it: