Script to pull DVH data

Dec 5, 2016 at 7:18 PM
Hi,

I'm new to codeplex and am wondering if anyone would be willing to help me setup a simple code that could be used to pull some data from the DVH. I need specific data points and was hoping I could filter by specific patients as well. Please let me know if anyone is willing to help me get started. Thanks so much!

Tricia
Dec 6, 2016 at 10:01 PM
If anyone has time to help, I'm using the DVH lookup.cs code and need some help editing the code to include a few specific things:
  1. volume
  2. mean dose
  3. max dose
  4. Ci-sec (for HDR plans)
Any help is greatly appreciated! :)

Best,
Tricia
Coordinator
Dec 28, 2016 at 6:33 PM
Edited Dec 28, 2016 at 6:33 PM
Hi Tricia,

If you need to do multiple patients, it may be best to write a stand-alone app. The simplest way to do this (I think) is to write a Python script. It's easy to get the first three items, but I'm not familiar with Ci-sec. A few months I go, I wrote a blog post on exporting the DVH itself using Python (http://www.carlosjanderson.com/export-dvhs-to-a-csv-file-using-python/). I can help you edit that code to get what you want. However, you need to have a "thick" Eclipse client installed on your computer as well as IronPython. I can also help you write a C# app to do the same thing if you can't install Python.
Jan 12 at 7:03 PM
Hi redcurry,

Thanks so much for your response! I'm currently getting Iron Python all set up on my computer so I can run the script. I'm working on a thick client and downloaded IronPython (and added it to my path) but I'm still running into issues preventing me from running your script (as is). I posted a question on stack overflow to see if I could get some help with this: http://stackoverflow.com/questions/41620812/running-iron-python-not-recognizing-command

Once this issue is resolved, I'm going to play around with running your script (and am actually very excited about it!). I have a few questions, if you have some time:
  1. I'm not sure I understand how I could feed multiple IDs into the script to pull data for many patients at once. Could I write that directly into the script?
  2. Also, is there a reference that you're aware of that will list the unique identifiers for the different data points in Eclipse? I'm thinking of some sort of ERD with the field identifiers, although I know that would likely be very complicated given the Eclispe data model.
Those were my first questions although I'm sure I'll have others once I'm able to use the code and see that results. Again, I can't thank you enough for your response.

Best,
Tricia
Jan 13 at 3:53 PM
Hey, thanks for the help on the stackoverflow issue. I'm able to run the script but it appears that I don't have the "VMS.TPS.Common.Model.API.dll" file in C:\Program Files (x86)\Varian\Vision\13.6\Bin64

Do you know if thick clients are always supposed to have that assembly? I think we used to have it before we upgraded to v13.6 but now I'm not sure.

Thanks again for your help!
Jan 13 at 4:25 PM
I was able to get the API by downloading the .msi file in the Eclipse scripting manual, which I should have done in the first place. Now I'm running into an issue because my computer is 64-bit and the .dll files are 32-bit, I think? Are you able to run the script on a 64-bit machine and if so, how? Or are you using a 32-bit machine?
Coordinator
Jan 13 at 4:49 PM
Instead of running ipy, try running ipy64. Let me know if that works.
Jan 13 at 6:30 PM
Now I'm able to run it with the following prompt:

C:\Program Files (x86)\IronPython 2.7>ipy64 Projects\hydrogel-spacer.py :90003919 test.csv

The error I get says:

Traceback (most recent call last):
File "Projects\hydrogel-spacer.py", line 39, in ,module.
AttributeError: NoneType object has no attribute Courses



I'm looking at the object model in the API scripting reference guide and it appears that Patient does have an attribute Course, so I'm not sure why this is having trouble. This patient (90003919) has multiple courses. Do you think that's an issue?
Jan 13 at 7:15 PM
It looks like the issue was with how I was typing the patient ID, so that's resolved. Now I think I'm having an issue because some of the courses associated with the patient don't have any structure sets because they were created just to track dose.

I'm trying to figure out the syntax for filtering the for loop to ignore plans with no structure set.
Jan 13 at 8:49 PM
We've been pushing through these errors and have finally gotten the script to run successfully!

Now we're trying to make some adjustments so that we only pull back DVH data for a specific structure, however we're having trouble filtering by the structure because it looks like it might use a different ID than what's displayed in Eclipse. Have you ever tried this?

Also, I'm trying to open more than one patient at a time but I see that the app.OpenPatientById() will only accept one argument. Do you know of a way to iterate through a list of patients?

Thanks!
Coordinator
Jan 13 at 9:38 PM
I'm glad you've got the script to run!

The structure ID in ESAPI should be exactly the same as what's displayed in Eclipse. Make sure that the structure ID doesn't have a space at the end or at the beginning. The IDs need to match exactly for your script to find it.

You can't have multiple patients open at the same time, but you can iterate through them by first closing the previous patient (I believe it's app.ClosePatient) and then open the next patient.
Mar 16 at 5:19 PM
Do you know the syntax for specifying a volume that I'd like to get the dvh Dose for? For example, rather than have the script give me the results of all the dvh points of all volumes at 0.01 increments, could I call for a specific volume? Also, do you know the syntax for returning dvh data in percentage format, rather than absolute volume? I'm guessing I just change these lines of code but I'm not sure of the exact syntax. I tried "Percent" but it failed.
                    # Get the cumulative DVH in absolute units
                    dvhData = plan.GetDVHCumulativeData(structure,
                        DoseValuePresentation.Absolute,
                        VolumePresentation.AbsoluteCm3, 0.01)
Mar 24 at 6:03 PM
the date is way past March 16 (i.e. the day of the last post), but:

Search the API help for: DoseValuePresentation / VolumePresentation

These both have 'relative' and 'absolute' presentations.
Coordinator
Mar 25 at 9:09 PM
The code you included is inside a nested loop that goes through all the structures (volumes) in all plans of all courses. If you know the course ID, plan ID, and structure ID, then you can replace the loops and code with:
course = [c for c in patient.Courses if c.Id == "MyCourseID"][0]
plan = [p for p in course.PlanSetups if p.Id == "MyPlanID"][0]
structure = [s for s in plan.StructureSet.Structures if s.Id == "MyStructureID"][0]
dvhData = plan.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, 0.01)
Of course, replace "MyCourseID", "MyPlanID", and "MyStructureID" with the correct IDs. I haven't run this code myself, but it should work. :)

If you want the volume to be in percentage, replace VolumePresentation.AbsoluteCm3 with VolumePresentation.Relative.