public SaveOrderDocumentationDataResponse SaveOrderDocumentationData(SaveOrderDocumentationDataRequest request)
        {
            var order = this.PersistenceContext.Load <Order>(request.OrderRef);

            ExtendedPropertyUtils.Update(order.ExtendedProperties, request.OrderExtendedProperties);

            var dicomSeriesAssembler = new DicomSeriesAssembler();

            foreach (var detail in request.ModalityPerformedProcedureSteps)
            {
                var mpps = this.PersistenceContext.Load <ModalityPerformedProcedureStep>(detail.ModalityPerformendProcedureStepRef);
                ExtendedPropertyUtils.Update(mpps.ExtendedProperties, detail.ExtendedProperties);
                dicomSeriesAssembler.SynchronizeDicomSeries(mpps, detail.DicomSeries, this.PersistenceContext);
            }

            // add new order notes
            var noteAssembler = new OrderNoteAssembler();

            noteAssembler.SynchronizeOrderNotes(order, request.OrderNotes, CurrentUserStaff, this.PersistenceContext);

            // assign all procedures for this order to the specified interpreter (or unassign them, if null)
            var interpreter = request.AssignedInterpreter == null
                                ? null
                                : this.PersistenceContext.Load <Staff>(request.AssignedInterpreter.StaffRef, EntityLoadFlags.Proxy);

            foreach (var procedure in order.Procedures)
            {
                if (procedure.IsPerformed)
                {
                    var interpretationStep = GetPendingInterpretationStep(procedure);
                    if (interpretationStep != null)
                    {
                        interpretationStep.Assign(interpreter);
                    }
                }
            }

            this.PersistenceContext.SynchState();

            var planAssembler = new ProcedurePlanAssembler();

            return(new SaveOrderDocumentationDataResponse(planAssembler.CreateProcedurePlanSummary(order, this.PersistenceContext)));
        }
        private bool Save(bool completeDocumentation)
        {
            // only do validation if they are completing the documentation, not if they are just saving a draft
            if (completeDocumentation)
            {
                if (this.HasValidationErrors)
                {
                    ShowValidation(true);
                    return(false);
                }
            }

            try
            {
                // allow extension pages to save data
                var veto = false;
                foreach (var page in _extensionPages)
                {
                    veto = veto || !page.Save(completeDocumentation);
                }
                if (veto)
                {
                    return(false);
                }

                _orderDetailsComponent.SaveData();
                _ppsComponent.SaveData();
                Platform.GetService <IModalityWorkflowService>(service =>
                {
                    var saveRequest = new SaveOrderDocumentationDataRequest(
                        _procedurePlan.OrderRef,
                        _orderExtendedProperties,
                        _orderNotes,
                        new List <ModalityPerformedProcedureStepDetail>(_ppsComponent.PerformedProcedureSteps),
                        _assignedRadiologist);

                    var saveResponse = service.SaveOrderDocumentationData(saveRequest);

                    if (completeDocumentation)
                    {
                        var completeRequest  = new CompleteOrderDocumentationRequest(saveResponse.ProcedurePlan.OrderRef);
                        var completeResponse = service.CompleteOrderDocumentation(completeRequest);

                        RefreshProcedurePlanSummary(completeResponse.ProcedurePlan);
                    }
                    else
                    {
                        RefreshProcedurePlanSummary(saveResponse.ProcedurePlan);
                    }
                });

                return(true);
            }
            catch (FaultException <ConcurrentModificationException> )
            {
                // bug #3469: we handle this exception explicitly, so we can instruct the user to close the workspace
                this.Host.ShowMessageBox(SR.MessageConcurrentModificationCloseWorkspace, MessageBoxActions.Ok);

                _saveEnabled = false;
                NotifyPropertyChanged("SaveEnabled");

                _completeEnabled = false;
                NotifyPropertyChanged("CompleteEnabled");
            }
            catch (Exception e)
            {
                ExceptionHandler.Report(e, this.Host.DesktopWindow);
            }

            return(false);
        }