DVH Eval for plan sum

Feb 28, 2014 at 3:53 PM

I am not a programmer by any means, but can dabble with rudimentary scripts.
I use Eclipse v11.

I would like to have a script that evaluates DVHs for predetermined structures for a plan-sum and presents the user with a window showing if predetermined criteria have been met. We can do this in Eclipse directly using Plan Objectives for single plans, but cannot do this with plan-sums. Many of our final patient plans are a composite of more than one plan.

As an example:
Structure Name: B-Wall
Criteria: The volume of B-Wall receiving 47Gy must be less than 53% of the structure volume. To put this conversely, 53% of the B-Wall volume must receive less than or equal to 47Gy.
Indicator of Pass/Fail or, better yet, also show the volume of B-Wall at 47Gy.

Structure Name: PTV1
Criteria: 95% of the PTV1 volume must be => 76.95Gy
Indicator of Pass/Fail and show vol of PTV1 at 76.95Gy.

Is there a code snippet available for a Plan Sum object that would show me (a relative novice) how to do this so I can build from that for all the other structures and criterial that we evaluate? If I can create this script, it would save our dosimetrists a great deal of time.

Mar 1, 2014 at 1:28 AM
Edited Mar 3, 2014 at 10:49 PM
I have uploaded a new project PlanQualityMetrics that you could use as a start for generating the kind of report you need for both plans and plansums.

Download a sample report.

Regarding your question about PlanSums, see specifically file DvhExtensions.cs, this file extends ESAPI to add the convenience methods GetDoseAtVolume and GetVolumeAtDose to the PlanningItem class, which is the base class for both PlanSetup and PlanSum.

You would add and configure the metrics you want to report on for your enterprise in the file UserDefinedMetrics.cs, and set the structure IDs to search for in field 'searchIds' as they are defined in your enterprise. For example, in the code below, for the PenileBulb, the script reports on the mean dose limit, checking that it is below 50 Gy. When the mean dose is between 50 + 5% (50 - 52.5), the report shows a warning in yellow. When the mean dose is above 52.5 Gy the report shows a failure in red. The report also includes a check for D90 < 50 Gy, reporting a failure if D90 >50.
    public static class PenileBulb
      public static PlanQualityMetric[] PQMs = 
        new MeanDoseLimit(new DoseValue(50.0,DoseValue.DoseUnit.Gy), 1.05),
        new DoseAtVolume("D90 < 50 Gy", 90.0, new DoseValue(50, DoseValue.DoseUnit.Gy), 1.0)
      public static string[] searchIds = { "Penile Bulb", "PENILE_BULB", "penilebulb" };
When your metrics are properly defined, you need to make sure they are included in PQMReporter.WriteDoseStatisticsXML_Prostate2GyOrLess or WriteDoseStatisticsXML_HeadAndNeck2GyOrLess, or add your own method for other sites.
      // find stats for the penile bulb structure
      addStructurePQM(plan, ss, PenileBulb.searchIds, PenileBulb.PQMs, writer);
Mar 3, 2014 at 12:48 PM
Thank you. You have given me a lot to work with and I can't wait to get started. I especially like the fact that you can also indicate warning levels. Many protocols provide for a marginal pass criteria (acceptable variation), so being able to display that as part of the evaluation tool is very nice.

Thanks again,
Mar 3, 2014 at 2:04 PM
My thanks as well. A DVH evaluator was the first clinical project I wanted to implement using the scripting tools. This a great starting point.

Mar 3, 2014 at 10:39 PM
So I have made some modifications to the UserDefinedMetrics.cs code to modify structure lists and dose/volume criteria to match our Prostate planning schema. I added a Sigmoid structure and also update PQMReporter.WriteDoseStatisticsXML_Prostate2GyOrLess section. I put a copy of all the files in the ...Filedata\ProgramData\PublishedScripts directory. I launch the UserDefinedMetrics.cs script file and get a box-full of messages.

New questions have come up. Do I need to compile any of the code that you posted and I subsequent modified? I assume that I launch the UserDefinedMetrics.cs script from the ...Filedata\ProgramData\PublishedScripts directory. Do any of the other files need to be deployed elsewhere within the environment in order for it to work?

Mar 3, 2014 at 10:47 PM
The project is a binary plugin that compiles to "PlanQualityMetrics.esapi.dll" in the plugins directory. That file would be the one that gets copied to the PublishedScripts directory.

Start with Getting Started with ESAPI v11.

You need to compile the entire project that was uploaded using Microsoft Visual Studio 2010 Professional, or you can download the free version Visual Studio Express as mentioned in the getting started documentation.
Mar 3, 2014 at 10:52 PM
Ah ha! That explains a lot. Should have known to read the manual :)
Mar 4, 2014 at 5:06 PM
Success! I have generated the PlanQualityMetrics.esapi.dll and run it successfully for both a single plan and a plan sum for a prostate. -Thank you!

One of the limitations I see with this model is that the metrics are hard-coded into the dll. I am wondering if it would be possible to have a centralized location to keep the User Defined Metrics which can be edited as needed without requiring re-compiling the project.

On a more global scale, I am imagining that the Plan Name could contain text indicating which User Defined Metrics should be pulled to evaluate the plan. For example, the PlanID might read Prost_3625 and the Plan Name RTOG_0938-1. In the User Defined Metrics table there would be all the requirements of treating a patient in accordance with RTOG 0938 Arm 1. Another section would contain RTOG_0938-2 and yet another section with PSVN_MDxx and other sections for HN plans and Lung plans etc all in one easy-to-manage file.

Do you see any limitations to moving in this direction? If not, what would you propose as the best 'container' to manage the look-up information?

Mar 4, 2014 at 8:23 PM
Edited Mar 4, 2014 at 8:24 PM
Glad to hear you are able to compile.

There are a number of other fields you could use in the plan, like Plan.Comment, Plan.ProtocolID that may be better suited to this type of use.

How you store a configuration file is your choice; you could start by using a centrally located XML document that is accessible by all users. One could create an XML document with the sort of schema below, then do a lookup based on Plan.ProtocolID (or comment or plan name) to pull in the set of Metrics to use. You'll notice it's a whole lot of work get rid of the 'hard coding', which is why I didn't do it with my script. Each time you made a change in your configuration file, you would still then have to validate that it is giving you the proper results. You may find it is more efficient to just hard code your metrics and redo your commissioning and validation work of the updated script with each change.
<?xml version="1.0" encoding="utf-8"?>
          <Id>Penile Bulb</Id>
            <name>D90 &lt; 50 Gy</name>
Jul 21, 2014 at 3:45 PM
Is it possible to get the user login and password screen to pop up when running this as script within Eclipse? I'd like to be able to have my MDs review this report and grab a digital signature using a workflow that is similar to what they use to approve a plan (pressing F4 and putting in their ARIA username and password)
Jul 21, 2014 at 8:48 PM
At the end of the day, you will have to implement your own "signature" for this process. At most you could get a "has been authenticated by Varian" response from the API. I wouldn't exactly call that a digital signature. If the physician is logged into Eclipse, you can get the ScriptContext.CurrentUser which means they have been authenticated. What happens if you call Application.CreateApplication(username, password) from within Eclipse? Does it crash? That would also be an authentication step.
Aug 14, 2014 at 10:59 PM
Is there a way to grab the DVH criteria from physician prescription?... , not hard coded/not from external xml files...
Sep 3, 2014 at 4:08 PM
Instead of listing the Targets for the plan report, I would like to list ALL the PTV's which are categorized with DicomType. Below is an example but I'm getting an error underneath the "select" command that says "Are you missing a cast?"
 Structure target=           
      (              from s in ss.Structures
                     where (s.DicomType == "PTV")
                     select s.DicomType.All;
Sep 3, 2014 at 8:55 PM
To select all that are type PTV, do this:
                  var structureList = (from s in ss.Structures where s.DicomType == "PTV" select s);
                  // structureList is a list of structures of of type IEnumberable<Structure>
To select a single structure, do something like:
                  Structure firstPTV = (from s in ss.Structures where s.DicomType == "PTV" select s).First();
Sep 17, 2014 at 1:25 AM
In a related problem, is it possible to specify D105 % criterion ? In other words, would something like the follwoing work:
new DoseAtVolume("PTV D105*", 105.0, new DoseValue(1600, DoseValue.DoseUnit.cGy), 0.9375,
                    VolumePresentation.Relative, DoseValuePresentation.Absolute, PQMUtilities.LimitType.upper),
If it does, would it also be possible to obtain the 105% volume that is calculated?

Jul 20, 2016 at 10:52 PM
I'm finally implementing PQM into my clinic, and I'm working on the problem of different standards for different sites. I can see that the default project comes 2 different methods for write dose statistics (HeadandNeck2GyOrLess and Prostate2GyOrLess). However, I can't figure out what plan properties the program is keying in on to choose which method to use. Anyone able to point me in the right direction?

Thank you.
Sep 1 at 5:33 PM
cho232 wrote:
Is it possible to get the user login and password screen to pop up when running this as script within Eclipse? I'd like to be able to have my MDs review this report and grab a digital signature using a workflow that is similar to what they use to approve a plan (pressing F4 and putting in their ARIA username and password)
It's possible to prompt the user for a user ID and password, but you'd have to implement this yourself. You can then use the Oncology System Platform (OSP) to authenticate the user. You may generate a digital signature out of this, but it seems like a complex task (see https://en.wikipedia.org/wiki/Digital_signature). However, there may be libraries that do this for you.

A simpler method would be to first authenticate the user using the OSP, and then to check whether the user is an Oncologist (authorization). If he or she is authorized to approve the report (perhaps a PDF), you could add something to the PDF confirming that the user was authorized. There also appear to be ways to sign the PDF digitally (see https://stackoverflow.com/questions/378247/digitally-sign-pdf-files).

This won't solve your digital signature problem, but I've written a blog post about using the OSP to authenticate and then authorize a user in order to perform an action. See http://www.carlosjanderson.com/authentication-and-authorization-using-the-osp.