bcatt09 / PlanCheck

2 stars 0 forks source link

Implement Gantry Angle Check #6

Open travisschultz opened 3 years ago

travisschultz commented 3 years ago

Add proton check to test to make sure gantry angles are ok.

travisschultz commented 3 years ago

Gantry angle code completed and passed first check. Will probably add checks for couch angles in this as well.

travisschultz commented 3 years ago

namespace PlanCheck.Checks { class ProtonGantryAngleCheck : PlanCheckBase { protected override List MachineExemptions => DepartmentInfo.LinearAccelerators;

    public ProtonGantryAngleCheck(PlanSetup plan) : base(plan) { }

    protected override void RunTest(PlanSetup plan)
    {
        DisplayName = "Gantry Angle Checks";
        TestExplanation = "This test will ensure Gantry Angles used in plan are allowable";
        IonPlanSetup ionPlan = (IonPlanSetup)plan;
        ResultDetails = $"Gantry angle verification for: {MachineID}\n";
        Result = "Testing";

        List<int> G1CommissionedAngles = new List<int>
        {
            0,15,30,45,60,75,90,105,120,135,150,165,180
        };
        List<int> G2CommissionedAngles = new List<int>
        {
            0,15,30,45,60,75,90,105,120,135,150,165,180
        };

        foreach (IonBeam beam in ionPlan.IonBeams)
        {
            if (!beam.IsSetupField)
            {
                if(beam.TreatmentUnit.Id == DepartmentInfo.MachineNames.PRO_G1)
                {
                    if (G1CommissionedAngles.Contains((int)beam.ControlPoints.FirstOrDefault().GantryAngle))
                    {
                        ResultDetails += $"  Field: {beam.Id}: Angle: {beam.ControlPoints.FirstOrDefault().GantryAngle} - OK\n";
                    }
                    else
                    {
                        Result = "Fail";
                        DisplayColor = ResultColorChoices.Fail;
                        ResultDetails += $"FAILED - Field: {beam.Id}: Angle: {beam.ControlPoints.FirstOrDefault().GantryAngle} not in allowed list.\n";
                    }
                }

                if (beam.TreatmentUnit.Id == DepartmentInfo.MachineNames.PRO_G2)
                {
                    if (G2CommissionedAngles.Contains((int)beam.ControlPoints.FirstOrDefault().GantryAngle))
                    {
                        ResultDetails += $"  Field: {beam.Id}: Angle: {beam.ControlPoints.FirstOrDefault().GantryAngle} - OK\n";
                    }
                    else
                    {
                        Result = "Fail";
                        DisplayColor = ResultColorChoices.Fail;
                        ResultDetails += $"FAILED - Field: {beam.Id}: Angle: {beam.ControlPoints.FirstOrDefault().GantryAngle} not in allowed list.\n";
                    }
                }

            }
        }

        if (Result == "Testing")
        {
            Result = "Pass";
            DisplayColor = ResultColorChoices.Pass;
        }

    }
}

}

travisschultz commented 3 years ago

Done and cursory testing completed

class ProtonGantryAngleCheck : PlanCheckBase
{
    protected override List<string> MachineExemptions => DepartmentInfo.LinearAccelerators;

    public ProtonGantryAngleCheck(PlanSetup plan) : base(plan) { }

    protected override void RunTest(PlanSetup plan)
    {
        DisplayName = "Gantry Angle Checks";
        TestExplanation = "This test will ensure Gantry Angles used in plan are allowable";
        IonPlanSetup ionPlan = (IonPlanSetup)plan;
        ResultDetails = $"Gantry angle verification for: {MachineID}\n";
        Result = "Testing";

        List<int> G1CommissionedGantryAngles = new List<int> { 0,15,30,45,60,75,90,105,120,135,150,165,180 };
        List<int> G1CommissionedCouchAngles = new List<int> { 0,180,270 };

        List<int> G2CommissionedGantryAngles = new List<int> { 0,15,30,45,60,75,90,105,120,135,150,165,180 };
        List<int> G2CommissionedCouchAngles = new List<int> { 0, 180, 270 };

        foreach (IonBeam beam in ionPlan.IonBeams)
        {
            if (!beam.IsSetupField)
            {
                if(beam.TreatmentUnit.Id == DepartmentInfo.MachineNames.PRO_G1)
                {
                    if (G1CommissionedGantryAngles.Contains((int)beam.ControlPoints.FirstOrDefault().GantryAngle) && G1CommissionedCouchAngles.Contains((int)beam.ControlPoints.FirstOrDefault().PatientSupportAngle))
                    {
                        ResultDetails += $"  Field: {beam.Id}: Gantry: {beam.ControlPoints.FirstOrDefault().GantryAngle} Couch: {beam.ControlPoints.FirstOrDefault().PatientSupportAngle}- OK\n";
                    }
                    else
                    {
                        Result = "Fail";
                        DisplayColor = ResultColorChoices.Fail;
                        ResultDetails += $"FAILED - Field: {beam.Id}: Gantry: {beam.ControlPoints.FirstOrDefault().GantryAngle} Couch: {beam.ControlPoints.FirstOrDefault().PatientSupportAngle} not in allowed list.\n";
                    }
                }

                if (beam.TreatmentUnit.Id == DepartmentInfo.MachineNames.PRO_G2)
                {
                    if (G2CommissionedGantryAngles.Contains((int)beam.ControlPoints.FirstOrDefault().GantryAngle) && G2CommissionedCouchAngles.Contains((int)beam.ControlPoints.FirstOrDefault().PatientSupportAngle))
                    {
                        ResultDetails += $"  Field: {beam.Id}: Gantry: {beam.ControlPoints.FirstOrDefault().GantryAngle} Couch: {beam.ControlPoints.FirstOrDefault().PatientSupportAngle}- OK\n";
                    }
                    else
                    {
                        Result = "Fail";
                        DisplayColor = ResultColorChoices.Fail;
                        ResultDetails += $"FAILED - Field: {beam.Id}: Gantry: {beam.ControlPoints.FirstOrDefault().GantryAngle} Couch: {beam.ControlPoints.FirstOrDefault().PatientSupportAngle} not in allowed list.\n";
                    }
                }

            }
        }

        if (Result == "Testing")
        {
            Result = "Pass";
            DisplayColor = ResultColorChoices.Pass;
        }

    }
}