Example #1
0
        private async Task CreatePatientSummaryAndLinkToExecutionEventAsync(ReportInstance reportInstance, ActivityExecutionStatusEvent executionEvent)
        {
            if (reportInstance is null)
            {
                throw new ArgumentNullException(nameof(reportInstance));
            }

            if (executionEvent is null)
            {
                throw new ArgumentNullException(nameof(executionEvent));
            }

            var artefactModel = reportInstance.WorkFlow.Description == "New Active Surveilliance Report" ?
                                await _artefactService.CreatePatientSummaryForActiveReportAsync(reportInstance.ContextGuid) :
                                await _artefactService.CreatePatientSummaryForSpontaneousReportAsync(reportInstance.ContextGuid);

            using (var tempFile = File.OpenRead(artefactModel.FullPath))
            {
                if (tempFile.Length > 0)
                {
                    BinaryReader rdr = new BinaryReader(tempFile);
                    executionEvent.AddAttachment(Path.GetFileName(artefactModel.FileName),
                                                 await _attachmentTypeRepository.GetAsync(at => at.Key == "docx"),
                                                 tempFile.Length,
                                                 rdr.ReadBytes((int)tempFile.Length),
                                                 "PatientSummary");
                }
            }
        }