Beispiel #1
0
        private void CreatePatientSummaryAndLink(ReportInstance reportInstance, ActivityExecutionStatusEvent newEvent)
        {
            ArtefactInfoModel path = null;

            if (reportInstance.WorkFlow.Description == "New Active Surveilliance Report")
            {
                var clinicalEvt     = _unitOfWork.Repository <PatientClinicalEvent>().Queryable().Single(pce => pce.PatientClinicalEventGuid == reportInstance.ContextGuid);
                var extendable      = (IExtendable)clinicalEvt;
                var extendableValue = extendable.GetAttributeValue("Is the adverse event serious?");
                var isSerious       = extendableValue != null?extendableValue.ToString() == "1" ? true : false : false;

                path = _artefactService.CreatePatientSummaryForActiveReport(reportInstance.ContextGuid, isSerious);
            }
            else
            {
                var sourceInstance = _unitOfWork.Repository <DatasetInstance>().Queryable().Single(di => di.DatasetInstanceGuid == reportInstance.ContextGuid);
                var isSerious      = sourceInstance.GetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "302C07C9-B0E0-46AB-9EF8-5D5C2F756BF1"));

                path = _artefactService.CreatePatientSummaryForSpontaneousReport(reportInstance.ContextGuid, (!String.IsNullOrWhiteSpace(isSerious)));
            }

            // Create patient summary and link to event
            Attachment     att;
            AttachmentType attType  = _unitOfWork.Repository <AttachmentType>().Queryable().Single(at => at.Key == "docx");
            FileStream     tempFile = File.OpenRead(path.FullPath);

            if (tempFile.Length > 0)
            {
                BinaryReader rdr    = new BinaryReader(tempFile);
                byte[]       buffer = rdr.ReadBytes((int)tempFile.Length);

                // Create the attachment
                att = new Attachment
                {
                    ActivityExecutionStatusEvent = newEvent,
                    Description    = "PatientSummary",
                    FileName       = Path.GetFileName(path.FileName),
                    AttachmentType = attType,
                    Size           = tempFile.Length,
                    Content        = buffer
                };
                newEvent.Attachments.Add(att);

                _unitOfWork.Repository <Attachment>().Save(att);
            }
            tempFile.Close();
            tempFile = null;
        }
Beispiel #2
0
        private void CreateE2BExtractAndLink(ReportInstance reportInstance, ActivityExecutionStatusEvent newEvent)
        {
            ArtefactInfoModel path = null;

            var activityInstance = reportInstance.CurrentActivity;

            DatasetInstance datasetInstance = null;
            var             evt             = activityInstance.ExecutionEvents.OrderByDescending(ee => ee.EventDateTime).First(ee => ee.ExecutionStatus.Description == "E2BINITIATED");
            var             tag             = (reportInstance.WorkFlow.Description == "New Active Surveilliance Report") ? "Active" : "Spontaneous";

            datasetInstance
                = _unitOfWork.Repository <DatasetInstance>()
                  .Queryable()
                  .Include("DatasetInstanceValues.DatasetElement.Field.FieldType")
                  .Include("DatasetInstanceValues.DatasetInstanceSubValues.DatasetElementSub.Field.FieldType")
                  .Where(di => di.Tag == tag &&
                         di.ContextID == evt.Id).SingleOrDefault();

            path = _artefactService.CreateE2B(datasetInstance.Id);

            Attachment     att;
            AttachmentType attType  = _unitOfWork.Repository <AttachmentType>().Queryable().Single(at => at.Key == "xml");
            FileStream     tempFile = File.OpenRead(path.FullPath);

            if (tempFile.Length > 0)
            {
                BinaryReader rdr    = new BinaryReader(tempFile);
                byte[]       buffer = rdr.ReadBytes((int)tempFile.Length);

                // Create the attachment
                att = new Attachment
                {
                    ActivityExecutionStatusEvent = newEvent,
                    Description    = "E2b",
                    FileName       = Path.GetFileName(path.FileName),
                    AttachmentType = attType,
                    Size           = tempFile.Length,
                    Content        = buffer
                };
                newEvent.Attachments.Add(att);

                _unitOfWork.Repository <Attachment>().Save(att);
            }
            tempFile.Close();
            tempFile = null;
        }
Beispiel #3
0
        private void CreatePatientExtractAndLink(ReportInstance reportInstance, ActivityExecutionStatusEvent newEvent)
        {
            ArtefactInfoModel path = null;

            if (reportInstance.WorkFlow.Description == "New Active Surveilliance Report")
            {
                var clinicalEvt = _unitOfWork.Repository <PatientClinicalEvent>().Queryable().Single(pce => pce.PatientClinicalEventGuid == reportInstance.ContextGuid);
                path = _artefactService.CreateActiveDatasetForDownload(clinicalEvt.Patient.Id);
            }
            else
            {
                var sourceInstance = _unitOfWork.Repository <DatasetInstance>().Queryable().Single(di => di.DatasetInstanceGuid == reportInstance.ContextGuid);
                path = _artefactService.CreateDatasetInstanceForDownload(sourceInstance.Id);
            }

            // Create patient summary and link to event
            Attachment     att;
            AttachmentType attType  = _unitOfWork.Repository <AttachmentType>().Queryable().Single(at => at.Key == "xlsx");
            FileStream     tempFile = File.OpenRead(path.FullPath);

            if (tempFile.Length > 0)
            {
                BinaryReader rdr    = new BinaryReader(tempFile);
                byte[]       buffer = rdr.ReadBytes((int)tempFile.Length);

                // Create the attachment
                att = new Attachment
                {
                    ActivityExecutionStatusEvent = newEvent,
                    Description    = "PatientExtract",
                    FileName       = Path.GetFileName(path.FileName),
                    AttachmentType = attType,
                    Size           = tempFile.Length,
                    Content        = buffer
                };
                newEvent.Attachments.Add(att);

                _unitOfWork.Repository <Attachment>().Save(att);
            }
            tempFile.Close();
            tempFile = null;
        }
Beispiel #4
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");
                }
            }
        }
        private async Task CreateE2BExtractAndLinkToExecutionEventAsync(ReportInstance reportInstance, ActivityExecutionStatusEvent executionEvent)
        {
            if (reportInstance is null)
            {
                throw new ArgumentNullException(nameof(reportInstance));
            }
            if (executionEvent is null)
            {
                throw new ArgumentNullException(nameof(executionEvent));
            }

            var e2bInstance = await GetDatasetInstance(reportInstance);

            if (e2bInstance == null)
            {
                throw new KeyNotFoundException($"Unable to locate E2B dataset for report {reportInstance.Id} for XML generation");
            }

            var artefactModel = await _xmlDocumentService.CreateE2BDocumentAsync(e2bInstance);

            using (var tempFile = File.OpenRead(artefactModel.FullPath))
            {
                if (tempFile.Length > 0)
                {
                    BinaryReader rdr = new BinaryReader(tempFile);
                    executionEvent.AddAttachment(Path.GetFileName(artefactModel.FileName),
                                                 _unitOfWork.Repository <AttachmentType>().Queryable().Single(at => at.Key == "xml"),
                                                 tempFile.Length,
                                                 rdr.ReadBytes((int)tempFile.Length),
                                                 "E2b");
                }
            }
        }