示例#1
0
        /// <summary>
        /// Submits the specified assessment by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="patientId">The patient id.</param>
        /// <returns><see cref="ActionResult"/> of the action.</returns>
        /// <exception cref="System.Web.HttpException">500;Submit assessment failed.</exception>
        public async Task <ActionResult> Submit(long id, long patientId)
        {
            if (_patientAccessControlManager.CanAccessPatient(patientId))
            {
                var requestDispatcher = CreateAsyncRequestDispatcher();
                requestDispatcher.Add(new SubmitAssessmentRequest {
                    AssessmentKey = id, Username = PatientAccessControlManager.GetCurrentUserName()
                });
                requestDispatcher.Add(new GetPatientDtoByKeyRequest {
                    PatientKey = patientId
                });
                var submitResponse = await requestDispatcher.GetAsync <SubmitAssessmentResponse> ();

                var patientResponse = requestDispatcher.Get <GetPatientDtoResponse>();

                if (submitResponse.AssessmentKey == 0)
                {
                    throw new HttpException(500, "Submit assessment failed.");
                }

                ViewData["Patient"]             = patientResponse.DataTransferObject;
                ViewData["AssessmentId"]        = id;
                ViewData["AssessmentViewModel"] =
                    new AssessmentViewModel(id,
                                            _routeNavigationService,
                                            "ReviewSection",
                                            null, new CompletenessResults("", 1, 0)
                {
                    CompletenessResultsPerRuleSet = new Dictionary <string, CompletenessResults> ()
                });

                return(View(id));
            }
            return(HttpNotFound());
        }
示例#2
0
        public async Task <HttpResponseMessage> Report(long id)
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                var patientRequestDisptacher = CreateAsyncRequestDispatcher();
                patientRequestDisptacher.Add(new GetPatientDtoByAssessmentKeyRequest {
                    AssessmentKey = id
                });

                var patientResponse = patientRequestDisptacher.Get <GetPatientDtoResponse>();


                if (patientResponse != null && patientResponse.DataTransferObject != null &&
                    _patientAccessControlManager.CanAccessPatient(patientResponse.DataTransferObject.Key))
                {
                    var requestDispatcher = CreateAsyncRequestDispatcher();
                    requestDispatcher.Add(new ViewReportRequest
                    {
                        AssessmentKey          = id,
                        ReportTempalteFilePath = HttpContext.Current.Server.MapPath(_reportTemplateFilePath),
                        AppendixFilePath       = HttpContext.Current.Server.MapPath(_appendixFilePath),
                        InterviewerName        = PatientAccessControlManager.GetCurrentUserName(),
                    });

                    var viewReportResponse = await requestDispatcher.GetAsync <FileStreamResponse>();

                    if (viewReportResponse.FileStream != null)
                    {
                        var stream = new MemoryStream(viewReportResponse.FileStream)
                        {
                            Position = 0
                        };
                        response.Content = new StreamContent(stream);

                        response.Content.Headers.ContentDisposition =
                            new ContentDispositionHeaderValue("attachment")
                        {
                            FileName = string.Format("AssessmentReport_{0}.pdf", id)
                        };
                        response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    }
                    else
                    {
                        response.StatusCode = HttpStatusCode.NotFound;
                    }
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NotFound;
                }
            }
            catch (IOException)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }
            return(response);
        }