protected override void RunTest(PlanSetup plan) { PlanSetupApprovalStatus approvalStatus = plan.ApprovalStatus; DisplayName = "Plan Approval"; Result = ""; ResultDetails = $"Status: {AddSpaces(approvalStatus.ToString())}"; DisplayColor = ResultColorChoices.Warn; TestExplanation = "Displays plan approval\nAlso checks that plan has been reviewed by a physician\nReviewed timestamp is estimated based on target structure or CT image approval"; // Not Approved yet if (approvalStatus != PlanSetupApprovalStatus.ExternallyApproved && approvalStatus != PlanSetupApprovalStatus.PlanningApproved && approvalStatus != PlanSetupApprovalStatus.Reviewed && approvalStatus != PlanSetupApprovalStatus.TreatmentApproved) { return; } // Has been Approved or Reviewed else { // Hasn't been "Reviewed" if (plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.Reviewed).Count() < 1) { Result = "Warning"; ResultDetails += "Plan has not been \"Reviewed\"\nVerify that a physician has reviewed the plan"; } // Has been Reviewed if (plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.Reviewed).Count() > 0) { // Get user who marked plan as "Reviewed" last ApprovalHistoryEntry reviewedHistoryEntry = plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.Reviewed).Last(); string reviewedUserDisplayName = reviewedHistoryEntry.UserDisplayName; string reviewedUserName = reviewedHistoryEntry.UserId; string reviewedDateTime = reviewedHistoryEntry.ApprovalDateTime.ToString("dddd, MMMM d, yyyy H:mm:ss tt"); string reviewedUserNameMinusDomain = reviewedUserName.Substring(reviewedUserName.IndexOf('\\') + 1); if (DepartmentInfo.GetRadOncUserNames(Department).Count > 0) { // Check approval user name against physician list if (!DepartmentInfo.GetRadOncUserNames(Department).Contains(reviewedUserNameMinusDomain)) { Result = "Warning"; ResultDetails += $"\n\"Reviewed\" by {reviewedUserDisplayName} at {reviewedDateTime}\nVerify that a physician reviewed the plan"; } else { DisplayColor = ResultColorChoices.Pass; ResultDetails += $"\nReviewed by: {reviewedUserName} at {reviewedDateTime}"; } } // No physician user names have been defined for this site else { TestNotImplemented(); } } // Has been Planning Approved if (plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.PlanningApproved).Count() > 0) { // Get user who marked plan as "Planning Approved" last ApprovalHistoryEntry planningApprovedHistoryEntry = plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.PlanningApproved).Last(); string planningApprovedUserDisplayName = planningApprovedHistoryEntry.UserDisplayName; string planningApprovedDateTime = planningApprovedHistoryEntry.ApprovalDateTime.ToString("dddd, MMMM d, yyyy H:mm:ss tt"); DisplayColor = ResultColorChoices.Pass; ResultDetails += $"\nPlanning Approved by: {planningApprovedUserDisplayName} at {planningApprovedDateTime}"; } // Has been Treatment Approved if (plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.TreatmentApproved).Count() > 0) { // Get user who marked plan as "Treatment Approved" last ApprovalHistoryEntry treatApprovedHistoryEntry = plan.ApprovalHistory.Where(x => x.ApprovalStatus == PlanSetupApprovalStatus.TreatmentApproved).Last(); string treatApprovedUserDisplayName = treatApprovedHistoryEntry.UserDisplayName; string treatApprovedDateTime = treatApprovedHistoryEntry.ApprovalDateTime.ToString("dddd, MMMM d, yyyy H:mm:ss tt"); DisplayColor = ResultColorChoices.Pass; ResultDetails += $"\nPlanning Approved by: {treatApprovedUserDisplayName} at {treatApprovedDateTime}"; } } }
static void Execute(Application app) { // Iterate through all patients int counter = 0; foreach (var patientSummary in app.PatientSummaries) { // Stop after when a few records have been found if (counter > 10) { break; } // For the test purpose we are interesting in patient records created during the last 6 months DateTime startDate = DateTime.Now - TimeSpan.FromDays(30 * 6); if (patientSummary.CreationDateTime > startDate) { // Retrieve patient information Patient patient = app.OpenPatient(patientSummary); if (patient == null) { throw new ApplicationException("Cannot open patient " + patientSummary.Id); } // Iterate through all patient courses... foreach (var course in patient.Courses) { // ... and plans foreach (var planSetup in course.PlanSetups) { try { // For the test purpose we will look into approved plans with calculated 3D dose only... PlanSetupApprovalStatus status = planSetup.ApprovalStatus; if ((status == PlanSetupApprovalStatus.PlanningApproved || status == PlanSetupApprovalStatus.TreatmentApproved) && planSetup.Dose != null) { // ... select dose values to be in absolute unit planSetup.DoseValuePresentation = DoseValuePresentation.Absolute; // ... and display information about max dose string message = string.Format("Patient: {0}, Course: {1}, Plan: {2}, Max dose: {3}", patient.Id, course.Id, planSetup.Id, planSetup.Dose.DoseMax3D.ToString()); Console.WriteLine(message); counter = counter + 1; } } catch (ApplicationException exception) { // In case of any error we will display some useful information... string errorMsg = string.Format("Exception was thrown. Patient Id: {0}, Course: {1}, Exception: {2}", patient.Id, course.Id, exception.Message); Console.WriteLine(errorMsg); // ... and then move to the next patient continue; } } } // Close the current patient, otherwise we will not be able to open another patient app.ClosePatient(); } } }