MLC Leaf Width
The leaf widths of the multileaf collimator (MLC) are not provided by the Eclipse API (ESAPI). Yet there are cases where this information is needed, like in plan checks or in calculations of aperture complexity. Here I will show you how to use the Entity Framework to get the MLC leaf widths from the ARIA database.
MLC Tables in the ARIA Database
First, we need to know where this information is located in the database. Fortunately, there is a table called MLCLeaf, which contains a field named Width. The MLCLeaf table is a child table of MLCBank, which is itself a child table of MLC. If your clinic has only one MLC, then you know which row in the MLC table to use. Otherwise, we need to get the correct MLC that was used in a specific treatment.
We can get this information using the FieldAddOn table. It has relationships to the AddOn and Radiation tables. The AddOn table contains the devices in the treatment machines, such as wedges, trays, and MLCs. The Radiation table contains the information about treatments, like those delivered by a field (also called a beam). Its parent table is PlanSetup.
Therefore, we’re going to get the MLC leaf widths in the following way. We’ll get to the correct Radiation table row by using the Patient, Course, PlanSetup, and Beam IDs, all of which we can get with ESAPI. We’ll then go through the FieldAddOn rows that reference the Radiation row and find the one that represents an MLC (an AddOn of type “MLC”). Finally, we’ll use the corresponding MLC row to get to MLCBank and then to all the MLCLeaf rows that belong to it.
Using the Entity Framework
I’ve already discussed how to use the Entity Framework in the blog post Access the ARIA Database with the Entity Framework. Therefore, I won’t go into too much detail here. Please refer to the blog post if you need more information.
Create a new class library project named “AriaEntities” in your solution and delete the file Class.cs. Add a new item to your project of type “ADO.NET Entity Data Model” and name it “AriaEntityContext.” Choose “Code First from Database” and configure the connection to your ARIA database. Then select the following tables: Patient, Course, PlanSetup, Radiation, FieldAddOn, AddOn, MLC, MLCBank, and MLCLeaf. Finally, add the following line to the constructor of the AriaEntityContext class:
Back in your main project, you can create a method (or an extension method, see Enhance ESAPI with Extension Methods) to obtain the leaf widths:
// We need to pass the PlanSetup in order to get the Patient and Course
private IEnumerable<double> GetLeafWidths(PlanSetup plan, Beam beam)
var course = plan.Course;
var patient = course.Patient;
using (var ac = new AriaEntityContext())
// Use ESAPI IDs to get to the ARIA Radiation row
var dbPatient = ac.Patients.First(p => p.PatientId == patient.Id);
var dbCourse = dbPatient.Courses.First(c => c.CourseId == course.Id);
var dbPlan = dbCourse.PlanSetups.First(ps => ps.PlanSetupId == plan.Id);
var dbRad = dbPlan.Radiations.First(r => r.RadiationId == beam.Id);
// Use the RadiationSer to get to the MLC add-on
var dbFieldAddOns = ac.FieldAddOns.Where(f => f.RadiationSer == dbRad.RadiationSer);
var dbMlcAddOn = dbFieldAddOns.First(f => f.AddOn.AddOnType == "MLC");
// Use the MLC row to get to the leaves (and their width)
// Note: We only need to use one of the MLC banks because
// the leaf widths are the same between leaf pairs
var dbMlc = dbMlcAddOn.AddOn.MLC;
var dbMlcLeaves = dbMlc.MLCBanks.First().MLCLeaves;
return dbMlcLeaves.Select(lf => lf.Width);
Note that the Entity Framework automatically created collection properties to represent table relationships. For example, we were able to obtain the plans in a course by accessing the Course.PlanSetup collection property. Also, the code doesn’t do any error checking, but in a real application it’s important to check for possible failures.
This has been a more complex example of using the Entity Framework to access the ARIA database. Nevertheless, we never needed to write any SQL commands ourselves.