/// <summary>
		/// Initialize this worklist item from the specified procedure step and related entities.
		/// </summary>
		/// <param name="step"></param>
		/// <param name="timeField"></param>
		/// <remarks>
		/// This method is not efficient for generating a large number of worklist items from a large set of procedure steps,
		/// because it causes a large number of secondary references and collections to be initiliazed.
		/// Use <see cref="WorklistItem.InitializeFromTuple"/> instead.
		/// </remarks>
		public override void InitializeFromProcedureStep(ProcedureStep step, WorklistItemField timeField)
		{
			var reportingStep = step.As<ReportingProcedureStep>();
			if (reportingStep != null && reportingStep.ReportPart != null)
			{
				this.ReportRef = reportingStep.ReportPart.Report.GetRef();
				this.ReportPartIndex = reportingStep.ReportPart.Index;
				this.HasErrors = reportingStep.Is<TranscriptionReviewStep>()
					? reportingStep.As<TranscriptionReviewStep>().HasErrors : false;
			}

			base.InitializeFromProcedureStep(step, timeField);
		}
        /// <summary>
        /// Initialize this worklist item from the specified procedure step and related entities.
        /// </summary>
        /// <param name="step"></param>
        /// <param name="timeField"></param>
        /// <remarks>
        /// This method is not efficient for generating a large number of worklist items from a large set of procedure steps,
        /// because it causes a large number of secondary references and collections to be initiliazed.
        /// Use <see cref="WorklistItem.InitializeFromTuple"/> instead.
        /// </remarks>
        public override void InitializeFromProcedureStep(ProcedureStep step, WorklistItemField timeField)
        {
            var reportingStep = step.As <ReportingProcedureStep>();

            if (reportingStep != null && reportingStep.ReportPart != null)
            {
                this.ReportRef       = reportingStep.ReportPart.Report.GetRef();
                this.ReportPartIndex = reportingStep.ReportPart.Index;
                this.HasErrors       = reportingStep.Is <TranscriptionReviewStep>()
                                        ? reportingStep.As <TranscriptionReviewStep>().HasErrors : false;
            }

            base.InitializeFromProcedureStep(step, timeField);
        }
        /// <summary>
        /// Gets the value for the specified time field from the specified procedure step or its associated entities.
        /// </summary>
        /// <param name="step"></param>
        /// <param name="timeField"></param>
        /// <returns></returns>
        protected override DateTime?GetTimeValue(ProcedureStep step, WorklistItemField timeField)
        {
            var reportingStep = step.As <ReportingProcedureStep>();

            if (reportingStep != null)
            {
                if (timeField == WorklistItemField.ReportPartPreliminaryTime)
                {
                    return(reportingStep.ReportPart.PreliminaryTime);
                }

                if (timeField == WorklistItemField.ReportPartCompletedTime)
                {
                    return(reportingStep.ReportPart.CompletedTime);
                }
            }

            return(base.GetTimeValue(step, timeField));
        }
        public ProcedureStepDetail CreateProcedureStepDetail(ProcedureStep ps, IPersistenceContext context)
        {
            var staffAssembler    = new StaffAssembler();
            var modalityAssembler = new ModalityAssembler();

            return(new ProcedureStepDetail(
                       ps.GetRef(),
                       ps.Name,
                       ps.GetClass().Name,
                       ps.Is <ModalityProcedureStep>() ? ps.As <ModalityProcedureStep>().Description : null,
                       EnumUtils.GetEnumValueInfo(ps.State, context),
                       ps.CreationTime,
                       ps.Scheduling == null ? null : ps.Scheduling.StartTime,
                       ps.StartTime,
                       ps.EndTime,
                       ps.AssignedStaff == null ? null : staffAssembler.CreateStaffSummary(ps.AssignedStaff, context),
                       ps.PerformingStaff == null ? null : staffAssembler.CreateStaffSummary(ps.PerformingStaff, context),
                       ps.Is <ModalityProcedureStep>() ? modalityAssembler.CreateModalitySummary(ps.As <ModalityProcedureStep>().Modality) : null));
        }
		/// <summary>
		/// Gets the value for the specified time field from the specified procedure step or its associated entities.
		/// </summary>
		/// <param name="step"></param>
		/// <param name="timeField"></param>
		/// <returns></returns>
		protected override DateTime? GetTimeValue(ProcedureStep step, WorklistItemField timeField)
		{
			var reportingStep = step.As<ReportingProcedureStep>();
			if(reportingStep != null)
			{
				if(timeField == WorklistItemField.ReportPartPreliminaryTime)
					return reportingStep.ReportPart.PreliminaryTime;

				if(timeField == WorklistItemField.ReportPartCompletedTime)
					return reportingStep.ReportPart.CompletedTime;
			}

			return base.GetTimeValue(step, timeField);
		}
        public ProcedureStepSummary CreateProcedureStepSummary(ProcedureStep ps, IPersistenceContext context)
        {
            var assembler         = new ProcedureAssembler();
            var modalityAssembler = new ModalityAssembler();

            return(new ProcedureStepSummary(
                       ps.GetRef(),
                       ps.Name,
                       EnumUtils.GetEnumValueInfo(ps.State, context),
                       ps.StartTime,
                       ps.EndTime,
                       ps.Is <ModalityProcedureStep>() ? modalityAssembler.CreateModalitySummary(ps.As <ModalityProcedureStep>().Modality) : null,
                       assembler.CreateProcedureSummary(ps.Procedure, context)));
        }