Exemplo n.º 1
0
        public void CreateDocument(ArtefactInfoModel model)
        {
            _fileModel = model;

            using (var document = WordprocessingDocument.Create(Path.Combine(model.Path, model.FileName), WordprocessingDocumentType.Document))
            {
                // Add a main document part.
                MainDocumentPart mainPart = document.AddMainDocumentPart();

                // Create the document structure and add some text.
                mainPart.Document = new Document();
                Body body = new Body();

                SectionProperties sectionProps = new SectionProperties();
                PageMargin        pageMargin   = new PageMargin()
                {
                    Top = 404, Right = (UInt32Value)504U, Bottom = 404, Left = (UInt32Value)504U, Header = (UInt32Value)720U, Footer = (UInt32Value)720U, Gutter = (UInt32Value)0U
                };
                sectionProps.Append(pageMargin);
                body.Append(sectionProps);

                mainPart.Document.AppendChild(body);
                //PrepareLogo(document);
            };
        }
Exemplo n.º 2
0
        private ArtefactInfoModel PrepareFileModelForSpontaneous(DatasetInstance datasetInstance, bool isSerious)
        {
            var model         = new ArtefactInfoModel();
            var generatedDate = DateTime.Now.ToString("yyyyMMddhhmmss");

            model.Path = Path.GetTempPath();
            var fileNamePrefix = isSerious ? "SAEReport_Spontaneous" : "PatientSummary_Spontaneous";

            model.FileName = $"{fileNamePrefix}{datasetInstance.Id}_{generatedDate}.docx";
            return(model);
        }
Exemplo n.º 3
0
        private ArtefactInfoModel PrepareFileModelForActive(PatientClinicalEvent patientClinicalEvent, bool isSerious)
        {
            var model         = new ArtefactInfoModel();
            var generatedDate = DateTime.Now.ToString("yyyyMMddhhmmss");

            model.Path = Path.GetTempPath();
            var fileNamePrefix = isSerious ? "SAEReport_Active" : "PatientSummary_Active";

            model.FileName = $"{fileNamePrefix}{patientClinicalEvent.Patient.Id}_{generatedDate}.docx";
            return(model);
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        public async Task <ArtefactInfoModel> CreateDatasetInstanceForDownloadAsync(long datasetInstanceId)
        {
            var model         = new ArtefactInfoModel();
            var generatedDate = DateTime.Now.ToString("yyyyMMddhhmmss");

            model.Path     = Path.GetTempPath();
            model.FileName = $"InstanceDataExtract_{generatedDate}.xlsx";

            //using (var pck = new ExcelPackage(new FileInfo(model.FullPath)))
            //{
            //    // Create XLS
            //    var ws = pck.Workbook.Worksheets.Add("Spontaneous ID " + datasetInstanceId);
            //    ws.View.ShowGridLines = true;

            //    // Write headers
            //    ws.Cells["A1"].Value = "Dataset Name";
            //    ws.Cells["B1"].Value = "Dataset Category";
            //    ws.Cells["C1"].Value = "Element Name";
            //    ws.Cells["D1"].Value = "Field Type";
            //    ws.Cells["E1"].Value = "Value";

            //    //Set the first header and format it
            //    using (var r = ws.Cells["A1:E1"])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Bold));
            //        r.Style.Font.Color.SetColor(System.Drawing.Color.White);
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
            //        r.Style.Fill.PatternType = ExcelFillStyle.Solid;
            //        r.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(23, 55, 93));
            //    }

            //    // Write content
            //    var datasetInstance = await _datasetInstanceRepository.GetAsync(di => di.Id == datasetInstanceId);
            //    if (datasetInstance == null)
            //    {
            //        throw new KeyNotFoundException(nameof(datasetInstance));
            //    }

            //    var count = 1;
            //    // Loop through and render main table
            //    foreach (var value in datasetInstance.DatasetInstanceValues.Where(div1 => div1.DatasetElement.System == false && div1.DatasetElement.Field.FieldType.Description != "Table").OrderBy(div2 => div2.Id))
            //    {
            //        count += 1;
            //        ws.Cells["A" + count].Value = datasetInstance.Dataset.DatasetName;
            //        ws.Cells["B" + count].Value = value.DatasetElement.DatasetCategoryElements.Single(dce => dce.DatasetCategory.Dataset.Id == datasetInstance.Dataset.Id).DatasetCategory.DatasetCategoryName;
            //        ws.Cells["C" + count].Value = value.DatasetElement.ElementName;
            //        ws.Cells["D" + count].Value = value.DatasetElement.Field.FieldType.Description;
            //        ws.Cells["E" + count].Value = value.InstanceValue;
            //    };

            //    // Loop through and render sub tables
            //    var maxcount = 5;
            //    var subcount = 1;
            //    foreach (var value in datasetInstance.DatasetInstanceValues.Where(div1 => div1.DatasetElement.System == false && div1.DatasetElement.Field.FieldType.Description == "Table").OrderBy(div2 => div2.Id))
            //    {
            //        count += 2;
            //        ws.Cells["A" + count].Value = datasetInstance.Dataset.DatasetName;
            //        ws.Cells["B" + count].Value = value.DatasetElement.DatasetCategoryElements.Single(dce => dce.DatasetCategory.Dataset.Id == datasetInstance.Dataset.Id).DatasetCategory.DatasetCategoryName;
            //        ws.Cells["C" + count].Value = value.DatasetElement.ElementName;
            //        ws.Cells["D" + count].Value = value.DatasetElement.Field.FieldType.Description;
            //        ws.Cells["E" + count].Value = string.Empty;

            //        if (value.DatasetInstanceSubValues.Count > 0)
            //        {
            //            // Write headers
            //            count += 1;
            //            foreach (var subElement in value.DatasetElement.DatasetElementSubs.Where(des1 => des1.System == false).OrderBy(des2 => des2.Id))
            //            {
            //                ws.Cells[GetExcelColumnName(subcount) + count].Value = subElement.ElementName;
            //                subcount++;
            //                maxcount = subcount > maxcount ? subcount : maxcount;
            //            }

            //            //Set the sub header and format it
            //            using (var r = ws.Cells["A" + count + ":" + GetExcelColumnName(subcount) + count])
            //            {
            //                r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Bold));
            //                r.Style.Font.Color.SetColor(System.Drawing.Color.White);
            //                r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
            //                r.Style.Fill.PatternType = ExcelFillStyle.Solid;
            //                r.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(23, 55, 93));
            //            }

            //            // Get unique contexts
            //            var contexts = datasetInstance.GetInstanceSubValuesContext(value.DatasetElement.ElementName);
            //            foreach (var context in contexts)
            //            {
            //                count += 1;
            //                subcount = 1;
            //                foreach (var subvalue in datasetInstance.GetInstanceSubValues(value.DatasetElement.ElementName, context))
            //                {
            //                    subcount = value.DatasetElement.DatasetElementSubs.ToList().IndexOf(subvalue.DatasetElementSub) + 1;
            //                    ws.Cells[GetExcelColumnName(subcount) + count].Value = subvalue.InstanceValue;
            //                }
            //            }
            //        }
            //    };

            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(maxcount) + count])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    pck.Save();
            //}

            return(model);
        }
Exemplo n.º 8
0
        public ArtefactInfoModel CreateActiveDatasetForDownload(long[] patientIds, long cohortGroupId)
        {
            var model         = new ArtefactInfoModel();
            var generatedDate = DateTime.Now.ToString("yyyyMMddhhmmss");

            model.Path     = Path.GetTempPath();
            model.FileName = $"ActiveDataExtract_{generatedDate}.xlsx";

            //using (var pck = new ExcelPackage(new FileInfo(model.FullPath)))
            //{
            //    // *************************************
            //    // Create sheet - Patient
            //    // *************************************
            //    var ws = pck.Workbook.Worksheets.Add("Patient");
            //    ws.View.ShowGridLines = true;

            //    var rowCount = 1;
            //    var colCount = 1;

            //    var patientquery = _unitOfWork.Repository<Patient>().Queryable().Where(p => p.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        patientquery = patientquery.Where(p => patientIds.Contains(p.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        patientquery = patientquery.Where(p => p.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }

            //    var patients = patientquery.OrderBy(p => p.Id).ToList();
            //    foreach (Patient patient in patients)
            //    {
            //        ProcessEntity(patient, ref ws, ref rowCount, ref colCount, "Patient");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - PatientMedication
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("PatientMedication");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var medicationquery = _unitOfWork.Repository<PatientMedication>().Queryable().Where(pm => pm.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        medicationquery = medicationquery.Where(pm => patientIds.Contains(pm.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        medicationquery = medicationquery.Where(pm => pm.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var medications = medicationquery.OrderBy(pm => pm.Id).ToList();
            //    foreach (PatientMedication medication in medications)
            //    {
            //        ProcessEntity(medication, ref ws, ref rowCount, ref colCount, "PatientMedication");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - PatientClinicalEvent
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("PatientClinicalEvent");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var eventquery = _unitOfWork.Repository<PatientClinicalEvent>().Queryable().Where(pc => pc.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        eventquery = eventquery.Where(pc => patientIds.Contains(pc.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        eventquery = eventquery.Where(pc => pc.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var events = eventquery.OrderBy(pc => pc.Id).ToList();
            //    foreach (PatientClinicalEvent clinicalEvent in events)
            //    {
            //        ProcessEntity(clinicalEvent, ref ws, ref rowCount, ref colCount, "PatientClinicalEvent");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - PatientCondition
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("PatientCondition");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var conditionquery = _unitOfWork.Repository<PatientCondition>().Queryable().Where(pc => pc.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        conditionquery = conditionquery.Where(pc => patientIds.Contains(pc.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        conditionquery = conditionquery.Where(pc => pc.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var conditions = conditionquery.OrderBy(pc => pc.Id).ToList();
            //    foreach (PatientCondition condition in conditions)
            //    {
            //        ProcessEntity(condition, ref ws, ref rowCount, ref colCount, "PatientCondition");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - PatientLabTest
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("PatientLabTest");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var labtestquery = _unitOfWork.Repository<PatientLabTest>().Queryable().Where(pl => pl.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        labtestquery = labtestquery.Where(pl => patientIds.Contains(pl.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        labtestquery = labtestquery.Where(pl => pl.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var labTests = labtestquery.OrderBy(pl => pl.Id).ToList();
            //    foreach (PatientLabTest labTest in labTests)
            //    {
            //        ProcessEntity(labTest, ref ws, ref rowCount, ref colCount, "PatientLabTest");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - Encounter
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("Encounter");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var encounterquery = _unitOfWork.Repository<Encounter>().Queryable().Where(e => e.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        encounterquery = encounterquery.Where(e => patientIds.Contains(e.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        encounterquery = encounterquery.Where(e => e.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var encounters = encounterquery.OrderBy(e => e.Id).ToList();
            //    foreach (Encounter encounter in encounters)
            //    {
            //        ProcessEntity(encounter, ref ws, ref rowCount, ref colCount, "Encounter");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - CohortGroupEnrolment
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("CohortGroupEnrolment");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var enrolmentquery = _unitOfWork.Repository<CohortGroupEnrolment>().Queryable().Where(e => e.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        enrolmentquery = enrolmentquery.Where(e => patientIds.Contains(e.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        enrolmentquery = enrolmentquery.Where(e => e.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var enrolments = enrolmentquery.OrderBy(e => e.Id).ToList();
            //    foreach (CohortGroupEnrolment enrolment in enrolments)
            //    {
            //        ProcessEntity(enrolment, ref ws, ref rowCount, ref colCount, "CohortGroupEnrolment");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - PatientFacility
            //    // *************************************
            //    ws = pck.Workbook.Worksheets.Add("PatientFacility");
            //    ws.View.ShowGridLines = true;

            //    rowCount = 1;
            //    colCount = 1;

            //    var facilityquery = _unitOfWork.Repository<PatientFacility>().Queryable().Where(pf => pf.Archived == false);
            //    if (patientIds.Length > 0)
            //    {
            //        facilityquery = facilityquery.Where(pf => patientIds.Contains(pf.Patient.Id));
            //    }
            //    if (cohortGroupId > 0)
            //    {
            //        facilityquery = facilityquery.Where(pf => pf.Patient.CohortEnrolments.Any(cge => cge.CohortGroup.Id == cohortGroupId));
            //    }
            //    var facilities = facilityquery.OrderBy(pf => pf.Id).ToList();
            //    foreach (PatientFacility facility in facilities)
            //    {
            //        ProcessEntity(facility, ref ws, ref rowCount, ref colCount, "PatientFacility");
            //    }
            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(colCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    pck.Save();
            //}

            return(model);
        }
Exemplo n.º 9
0
        public ArtefactInfoModel CreateSpontaneousDatasetForDownload()
        {
            var model         = new ArtefactInfoModel();
            var generatedDate = DateTime.Now.ToString("yyyyMMddhhmmss");

            model.Path     = Path.GetTempPath();
            model.FileName = $"SpontaneousDataExtract_{generatedDate}.xlsx";

            //using (var pck = new ExcelPackage(new FileInfo(model.FullPath)))
            //{
            //    // *************************************
            //    // Create sheet - Main Spontaneous
            //    // *************************************
            //    var ws = pck.Workbook.Worksheets.Add("Spontaneous");
            //    ws.View.ShowGridLines = true;

            //    var rowCount = 1;
            //    var colCount = 2;
            //    var maxColCount = 1;

            //    List<string> columns = new List<string>();

            //    // Header
            //    ws.Cells["A1"].Value = "Unique Identifier";

            //    var dataset = _unitOfWork.Repository<Dataset>().Queryable().Single(ds => ds.DatasetName == "Spontaneous Report");
            //    foreach (DatasetCategory category in dataset.DatasetCategories)
            //    {
            //        foreach (DatasetCategoryElement element in category.DatasetCategoryElements.Where(dce => dce.DatasetElement.System == false && dce.DatasetElement.Field.FieldType.Description != "Table"))
            //        {
            //            ws.Cells[GetExcelColumnName(colCount) + "1"].Value = element.DatasetElement.ElementName;
            //            columns.Add(element.DatasetElement.ElementName);
            //            colCount += 1;
            //        }
            //    }
            //    maxColCount = colCount - 1;

            //    //Set the header and format it
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(maxColCount) + "1"])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Bold));
            //        r.Style.Font.Color.SetColor(System.Drawing.Color.White);
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
            //        r.Style.Fill.PatternType = ExcelFillStyle.Solid;
            //        r.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(23, 55, 93));
            //    }

            //    // Data
            //    foreach (ReportInstance reportInstance in _unitOfWork.Repository<ReportInstance>()
            //        .Queryable()
            //        .Where(ri => ri.WorkFlow.WorkFlowGuid.ToString() == "4096D0A3-45F7-4702-BDA1-76AEDE41B986" && ri.Activities.Any(a => a.QualifiedName == "Confirm Report Data" && a.CurrentStatus.Description != "DELETED")))
            //    {
            //        DatasetInstance datasetInstance = _unitOfWork.Repository<DatasetInstance>().Queryable().Single(di => di.DatasetInstanceGuid == reportInstance.ContextGuid);

            //        rowCount += 1;
            //        ws.Cells["A" + rowCount].Value = datasetInstance.DatasetInstanceGuid.ToString();

            //        foreach (var value in datasetInstance.DatasetInstanceValues.Where(div1 => div1.DatasetElement.System == false && div1.DatasetElement.Field.FieldType.Description != "Table").OrderBy(div2 => div2.Id))
            //        {
            //            colCount = columns.IndexOf(value.DatasetElement.ElementName) + 2;
            //            ws.Cells[GetExcelColumnName(colCount) + rowCount].Value = value.InstanceValue;
            //        };
            //    }

            //    //format row
            //    using (var r = ws.Cells["A1:" + GetExcelColumnName(maxColCount) + rowCount])
            //    {
            //        r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //        r.AutoFitColumns();
            //    }

            //    // *************************************
            //    // Create sheet - Sub tables
            //    // *************************************
            //    foreach (DatasetCategory category in dataset.DatasetCategories)
            //    {
            //        foreach (DatasetCategoryElement element in category.DatasetCategoryElements.Where(dce => dce.DatasetElement.System == false && dce.DatasetElement.Field.FieldType.Description == "Table"))
            //        {
            //            ws = pck.Workbook.Worksheets.Add(element.DatasetElement.ElementName);
            //            ws.View.ShowGridLines = true;

            //            // Write headers
            //            colCount = 2;
            //            rowCount = 1;

            //            ws.Cells["A1"].Value = "Unique Identifier";

            //            foreach (var subElement in element.DatasetElement.DatasetElementSubs.Where(des1 => des1.System == false).OrderBy(des2 => des2.Id))
            //            {
            //                ws.Cells[GetExcelColumnName(colCount) + "1"].Value = subElement.ElementName;
            //                colCount += 1;
            //            }
            //            maxColCount = colCount - 1;

            //            //Set the header and format it
            //            using (var r = ws.Cells["A1:" + GetExcelColumnName(maxColCount) + "1"])
            //            {
            //                r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Bold));
            //                r.Style.Font.Color.SetColor(System.Drawing.Color.White);
            //                r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
            //                r.Style.Fill.PatternType = ExcelFillStyle.Solid;
            //                r.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(23, 55, 93));
            //            }

            //            // Data
            //            foreach (var value in _unitOfWork.Repository<DatasetInstanceValue>()
            //                .Queryable()
            //                .Where(div1 => div1.DatasetElement.Id == element.DatasetElement.Id && div1.DatasetInstanceSubValues.Count > 0 && div1.DatasetInstance.Status == Core.ValueTypes.DatasetInstanceStatus.COMPLETE).OrderBy(div2 => div2.Id))
            //            {
            //                // Get report and ensure it is not deleted
            //                ReportInstance reportInstance = _unitOfWork.Repository<ReportInstance>().Queryable().SingleOrDefault(ri => ri.ContextGuid == value.DatasetInstance.DatasetInstanceGuid);

            //                if (reportInstance != null)
            //                {
            //                    if (reportInstance.Activities.Any(a => a.QualifiedName == "Confirm Report Data" && a.CurrentStatus.Description != "DELETED"))
            //                    {
            //                        // Get unique contexts
            //                        var contexts = value.DatasetInstance.GetInstanceSubValuesContext(value.DatasetElement.ElementName);
            //                        foreach (var context in contexts)
            //                        {
            //                            rowCount += 1;
            //                            ws.Cells["A" + rowCount].Value = value.DatasetInstance.DatasetInstanceGuid.ToString();

            //                            foreach (var subvalue in value.DatasetInstance.GetInstanceSubValues(value.DatasetElement.ElementName, context))
            //                            {
            //                                if (subvalue.DatasetElementSub.System == false)
            //                                {
            //                                    colCount = value.DatasetElement.DatasetElementSubs.ToList().IndexOf(subvalue.DatasetElementSub) + 2;
            //                                    ws.Cells[GetExcelColumnName(colCount) + rowCount].Value = subvalue.InstanceValue;
            //                                }
            //                            }
            //                        }
            //                    }
            //                }
            //            }
            //            //format row
            //            using (var r = ws.Cells["A1:" + GetExcelColumnName(maxColCount) + rowCount])
            //            {
            //                r.Style.Font.SetFromFont(new System.Drawing.Font("Arial", 10, FontStyle.Regular));
            //                r.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            //                r.AutoFitColumns();
            //            }
            //        }
            //    }

            //    pck.Save();
            //}

            return(model);
        }
Exemplo n.º 10
0
 private void SaveFormattedXML(ArtefactInfoModel artefactModel)
 {
     WriteXMLContentToFile(artefactModel.FullPath, ConvertXMLToFormattedText());
 }