Exemple #1
0
        private async Task PrepareEvaluationsForSpontaneousReport(DatasetInstance datasetInstance)
        {
            List <string[]> rows  = new();
            List <string>   cells = new();

            cells.Add("Test");
            cells.Add("Test Date");
            cells.Add("Test Result");

            rows.Add(cells.ToArray());

            var sourceLabElement = await _datasetElementRepository.GetAsync(dse => dse.ElementName == "Test Results");

            var sourceContexts = datasetInstance.GetInstanceSubValuesContext(sourceLabElement.ElementName);

            foreach (Guid sourceContext in sourceContexts)
            {
                var labItemValues = datasetInstance.GetInstanceSubValues(sourceLabElement.ElementName, sourceContext);

                var testDate   = labItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Test Date");
                var testResult = labItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Test Result");

                cells = new();

                cells.Add(labItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Test Name").InstanceValue);
                cells.Add(testDate != null ? Convert.ToDateTime(testDate.InstanceValue).ToString("yyyy-MM-dd") : string.Empty);
                cells.Add(testResult != null ? testResult.InstanceValue : string.Empty);

                rows.Add(cells.ToArray());
            }

            _wordDocumentService.AddRowTable(rows, new int[] { 2500, 2500, 6352 });
        }
Exemple #2
0
        private async Task <XmlNode[]> PrepareXmlNodeAsync(DatasetXmlNode datasetXmlNode, DatasetInstanceSubValue[] subItemValues = null)
        {
            if (datasetXmlNode == null)
            {
                throw new ArgumentNullException(nameof(datasetXmlNode));
            }

            List <XmlNode> xmlNodes = new List <XmlNode>();

            switch (datasetXmlNode.NodeType)
            {
            case NodeType.RootNode:
            case NodeType.StandardNode:
                var xmlStandardNode = CreateXmlNodeWithAttributes(datasetXmlNode);
                if (datasetXmlNode.DatasetElement != null)
                {
                    SetXmlNodeValueWithDatasetElement(xmlStandardNode, datasetXmlNode);
                }

                if (datasetXmlNode.DatasetElementSub != null)
                {
                    SetXmlNodeValueWithSubValues(xmlStandardNode, datasetXmlNode, subItemValues);
                }

                await ProcessNodeStructureChildrenAsync(datasetXmlNode.Id, xmlStandardNode, subItemValues);

                xmlNodes.Add(xmlStandardNode);
                break;

            case NodeType.RepeatingNode:
                if (datasetXmlNode.DatasetElement != null)
                {
                    var sourceContexts = _e2bInstance.GetInstanceSubValuesContext(datasetXmlNode.DatasetElement.ElementName);
                    foreach (Guid sourceContext in sourceContexts)
                    {
                        var xmlRepeatingNode = CreateXmlNodeWithAttributes(datasetXmlNode);
                        var values           = _e2bInstance.GetInstanceSubValues(datasetXmlNode.DatasetElement.ElementName, sourceContext);

                        await ProcessNodeStructureChildrenAsync(datasetXmlNode.Id, xmlRepeatingNode, values);

                        xmlNodes.Add(xmlRepeatingNode);
                    }
                }
                break;

            default:
                break;
            }
            return(xmlNodes.ToArray());
        }
Exemple #3
0
        public ActionResult AddSpontaneous(DatasetInstanceModel model)
        {
            DatasetInstance datasetInstance = null;

            var datasetInstanceRepository = _unitOfWork.Repository <DatasetInstance>();

            datasetInstance = datasetInstanceRepository
                              .Queryable()
                              .Include(di => di.Dataset)
                              .Include("DatasetInstanceValues.DatasetInstanceSubValues.DatasetElementSub")
                              .Include("DatasetInstanceValues.DatasetElement")
                              .SingleOrDefault(di => di.Id == model.DatasetInstanceId);

            if (ModelState.IsValid)
            {
                if (datasetInstance == null)
                {
                    ViewBag.Entity = "DatasetInstance";
                    return(View("NotFound"));
                }

                datasetInstance.Status = DatasetInstanceStatus.COMPLETE;

                var datasetElementIds = model.DatasetCategories.SelectMany(dc => dc.DatasetElements.Select(dse => dse.DatasetElementId)).ToArray();

                var datasetElements = _unitOfWork.Repository <DatasetElement>()
                                      .Queryable()
                                      .Where(de => datasetElementIds.Contains(de.Id))
                                      .ToDictionary(e => e.Id);

                var datasetElementSubs = datasetElements
                                         .SelectMany(de => de.Value.DatasetElementSubs)
                                         .ToDictionary(des => des.Id);

                try
                {
                    for (int i = 0; i < model.DatasetCategories.Length; i++)
                    {
                        for (int j = 0; j < model.DatasetCategories[i].DatasetElements.Length; j++)
                        {
                            try
                            {
                                if (model.DatasetCategories[i].DatasetElements[j].DatasetElementType != "Table")
                                {
                                    datasetInstance.SetInstanceValue(datasetElements[model.DatasetCategories[i].DatasetElements[j].DatasetElementId], model.DatasetCategories[i].DatasetElements[j].DatasetElementValue);
                                }
                            }
                            catch (DatasetFieldSetException ex)
                            {
                                // Need to rename the key in order for the message to be bound to the correct control.
                                throw new DatasetFieldSetException(string.Format("DatasetCategories[{0}].DatasetElements[{1}].DatasetElementValue", i, j), ex.Message);
                            }
                        }
                    }

                    datasetInstanceRepository.Update(datasetInstance);

                    // Instantiate new instance of work flow
                    var patientIdentifier = datasetInstance.GetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "Identification Number"));
                    if (String.IsNullOrWhiteSpace(patientIdentifier))
                    {
                        patientIdentifier = datasetInstance.GetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "Initials"));
                    }
                    var sourceIdentifier = datasetInstance.GetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "Description of reaction"));
                    _workflowService.CreateWorkFlowInstance("New Spontaneous Surveilliance Report", datasetInstance.DatasetInstanceGuid, patientIdentifier, sourceIdentifier);

                    // Prepare medications
                    List <ReportInstanceMedicationListItem> medications = new List <ReportInstanceMedicationListItem>();
                    var sourceProductElement      = _unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "Product Information");
                    var destinationProductElement = _unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "Medicinal Products");
                    var sourceContexts            = datasetInstance.GetInstanceSubValuesContext(sourceProductElement);
                    foreach (Guid sourceContext in sourceContexts)
                    {
                        var drugItemValues = datasetInstance.GetInstanceSubValues(sourceProductElement, sourceContext);
                        var drugName       = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Product").InstanceValue;

                        if (drugName != string.Empty)
                        {
                            var item = new ReportInstanceMedicationListItem()
                            {
                                MedicationIdentifier         = drugName,
                                ReportInstanceMedicationGuid = sourceContext
                            };
                            medications.Add(item);
                        }
                    }
                    _workflowService.AddOrUpdateMedicationsForWorkFlowInstance(datasetInstance.DatasetInstanceGuid, medications);

                    _unitOfWork.Complete();

                    return(RedirectToAction("FormAdded", "Public"));
                }
                catch (DatasetFieldSetException dse)
                {
                    ModelState.AddModelError(dse.Key, dse.Message);
                }
            }

            bool[] validCat;
            bool[] validMan;
            var    rule = datasetInstance.Dataset.GetRule(DatasetRuleType.MandatoryFieldsProminent);

            if (rule.RuleActive)
            {
                validCat = new[] { true, false };
                validMan = new[] { true, false };
            }
            else
            {
                validCat = new[] { false };
                validMan = new[] { true, false };
            }

            var groupedDatasetCategoryElements = datasetInstance.Dataset.DatasetCategories.Where(dc => validCat.Contains(dc.System)).OrderBy(dc => dc.CategoryOrder)
                                                 .SelectMany(dc => dc.DatasetCategoryElements).Where(dce => (rule.RuleActive && (dce.DatasetCategory.System == true && dce.DatasetElement.Field.Mandatory == true) || (dce.DatasetCategory.System == false && dce.DatasetElement.Field.Mandatory == false)) || (!rule.RuleActive && validMan.Contains(dce.DatasetElement.Field.Mandatory))).OrderBy(dce => dce.FieldOrder)
                                                 .GroupBy(dce => dce.DatasetCategory)
                                                 .ToList();

            model.DatasetCategories = groupedDatasetCategoryElements
                                      .Select(dsc => new DatasetCategoryEditModel
            {
                DatasetCategoryId          = dsc.Key.Id,
                DatasetCategoryDisplayName = String.IsNullOrWhiteSpace(dsc.Key.FriendlyName) ? dsc.Key.DatasetCategoryName : dsc.Key.FriendlyName,
                DatasetCategoryHelp        = dsc.Key.Help,
                DatasetElements            = dsc.Select(e => new DatasetElementEditModel
                {
                    DatasetElementId          = e.DatasetElement.Id,
                    DatasetElementName        = e.DatasetElement.ElementName,
                    DatasetElementDisplayName = String.IsNullOrWhiteSpace(e.FriendlyName) ? e.DatasetElement.ElementName : e.FriendlyName,
                    DatasetElementHelp        = e.Help,
                    DatasetElementRequired    = e.DatasetElement.Field.Mandatory,
                    DatasetElementDisplayed   = true,
                    DatasetElementChronic     = false,
                    DatasetElementType        = e.DatasetElement.Field.FieldType.Description,
                    DatasetElementValue       = datasetInstance.GetInstanceValue(e.DatasetElement),
                    DatasetElementSubs        = e.DatasetElement.DatasetElementSubs.Select(es => new DatasetElementSubEditModel
                    {
                        DatasetElementSubId       = es.Id,
                        DatasetElementSubName     = es.ElementName,
                        DatasetElementSubRequired = es.Field.Mandatory,
                        DatasetElementSubType     = es.Field.FieldType.Description //,
                                                                                   //DatasetElementSubValue = datasetInstance.GetInstanceSubValue(es)
                    }).ToArray()
                })
                                             .ToArray()
            })
                                      .ToArray();

            var selectTypeDatasetElements = model.DatasetCategories
                                            .SelectMany(dc => dc.DatasetElements)
                                            .Where(de => de.DatasetElementType == FieldTypes.Listbox.ToString() ||
                                                   de.DatasetElementType == FieldTypes.DropDownList.ToString())
                                            .ToArray();

            var yesNoDatasetElements = model.DatasetCategories
                                       .SelectMany(dc => dc.DatasetElements)
                                       .Where(de => de.DatasetElementType == FieldTypes.YesNo.ToString())
                                       .ToArray();

            var datasetElementRepository    = _unitOfWork.Repository <DatasetElement>();
            var datasetElementSubRepository = _unitOfWork.Repository <DatasetElementSub>();

            foreach (var element in selectTypeDatasetElements)
            {
                var elementFieldValues = datasetElementRepository.Queryable()
                                         .SingleOrDefault(de => de.Id == element.DatasetElementId)
                                         .Field.FieldValues
                                         .ToList();

                var elementFieldValueList = new List <SelectListItem> {
                    { new SelectListItem {
                          Value = "", Text = ""
                      } }
                };
                elementFieldValueList.AddRange(elementFieldValues.Select(ev => new SelectListItem {
                    Value = ev.Value, Text = ev.Value, Selected = element.DatasetElementValue == ev.Value
                }));

                ViewData.Add(element.DatasetElementName, elementFieldValueList.ToArray());
            }

            foreach (var element in yesNoDatasetElements)
            {
                var yesNo = new[] { new SelectListItem {
                                        Value = "", Text = ""
                                    }, new SelectListItem {
                                        Value = "No", Text = "No"
                                    }, new SelectListItem {
                                        Value = "Yes", Text = "Yes"
                                    } };

                var selectedYesNo = yesNo.SingleOrDefault(yn => yn.Value == element.DatasetElementValue);
                if (selectedYesNo != null)
                {
                    selectedYesNo.Selected = true;
                }

                ViewData.Add(element.DatasetElementName, yesNo);
            }

            return(View(model));
        }
Exemple #4
0
        private void RenderSpontaneousMeds()
        {
            TableRow  row;
            TableCell cell;

            Panel pnl;
            HtmlGenericControl btn;
            HtmlGenericControl ul;
            HtmlGenericControl li;
            LinkButton         lbtn;

            DateTime tempdt;

            string[] validNaranjoCriteria = { "Possible", "Probable" };

            // Clear existing rows as function can be called second timewithout reload
            var delete = new ArrayList();

            foreach (TableRow temprow in dt_1.Rows)
            {
                if (temprow.Cells[0].Text != "Medication")
                {
                    delete.Add(temprow);
                }
            }
            foreach (TableRow temprow in delete)
            {
                dt_1.Rows.Remove(temprow);
            }

            var element  = UnitOfWork.Repository <DatasetElement>().Queryable().Include(de1 => de1.DatasetElementSubs).SingleOrDefault(u => u.ElementName == "Product Information");
            var contexts = _instance.GetInstanceSubValuesContext(element);

            foreach (ReportInstanceMedication med in _reportInstance.Medications)
            {
                var drugName       = "";
                var drugItemValues = _instance.GetInstanceSubValues(element, med.ReportInstanceMedicationGuid);
                drugName = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Product").InstanceValue;

                if (drugName != string.Empty)
                {
                    row = new TableRow();

                    cell      = new TableCell();
                    cell.Text = drugName;
                    row.Cells.Add(cell);

                    var startElement = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Start Date");
                    var start        = startElement != null?DateTime.TryParse(startElement.InstanceValue, out tempdt) ? Convert.ToDateTime(startElement.InstanceValue).ToString("yyyy-MM-dd") : "" : "";

                    cell      = new TableCell();
                    cell.Text = start;
                    row.Cells.Add(cell);

                    var stopElement = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug End Date");
                    var stop        = stopElement != null?DateTime.TryParse(stopElement.InstanceValue, out tempdt) ? Convert.ToDateTime(stopElement.InstanceValue).ToString("yyyy-MM-dd") : "" : "";

                    cell      = new TableCell();
                    cell.Text = stop;
                    row.Cells.Add(cell);

                    var indicationElement = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Indication");
                    var indication        = indicationElement != null?DateTime.TryParse(indicationElement.InstanceValue, out tempdt) ? Convert.ToDateTime(indicationElement.InstanceValue).ToString("yyyy-MM-dd") : "" : "";

                    cell      = new TableCell();
                    cell.Text = indication;
                    row.Cells.Add(cell);

                    var causality = "<span class=\"label label-info\">NOT SET</span>";
                    if (med.NaranjoCausality != null)
                    {
                        causality = String.Format("<span class=\"badge txt-color-white bg-color-red\" style=\"padding:5px;width:80px;\"> {0} </span>", med.NaranjoCausality);
                    }

                    cell      = new TableCell();
                    cell.Text = causality;
                    row.Cells.Add(cell);

                    if (_context != formContext.SetCausality)
                    {
                        cell = new TableCell();
                        pnl  = new Panel()
                        {
                            CssClass = "btn-group"
                        };

                        btn = new HtmlGenericControl("button");
                        btn.Attributes.Add("class", "btn btn-default dropdown-toggle");
                        btn.Attributes.Add("data-toggle", "dropdown");
                        btn.Controls.Add(new Label()
                        {
                            Text = "Action "
                        });
                        btn.Controls.Add(new Label()
                        {
                            CssClass = "caret"
                        });
                        pnl.Controls.Add(btn);

                        ul = new HtmlGenericControl("ul");
                        ul.Attributes.Add("class", "dropdown-menu pull-right");

                        li   = new HtmlGenericControl("li");
                        lbtn = new LinkButton()
                        {
                            ID   = "sc" + med.ReportInstanceMedicationGuid.ToString(),
                            Text = "Set Causality"
                        };
                        lbtn.Click += btnSetSpontaneousCausality_Click;
                        li.Controls.Add(lbtn);
                        ul.Controls.Add(li);

                        li   = new HtmlGenericControl("li");
                        lbtn = new LinkButton()
                        {
                            ID   = "im" + med.ReportInstanceMedicationGuid.ToString(),
                            Text = "Ignore Medication"
                        };
                        lbtn.Click += btnIgnoreSpontaneousMedication_Click;
                        li.Controls.Add(lbtn);
                        ul.Controls.Add(li);

                        pnl.Controls.Add(ul);
                        cell.Controls.Add(pnl);
                        row.Cells.Add(cell);
                    }
                    else
                    {
                        cell      = new TableCell();
                        cell.Text = string.Empty;
                        row.Cells.Add(cell);
                    }

                    dt_1.Rows.Add(row);
                }
            }
            // Hide columns where necessary
            if (_context == formContext.SetCausality)
            {
                dt_1.HideColumn(5); // Action column
            }
            else
            {
                dt_1.ShowColumn(5); // Action column
            }
            dt_1.HideColumn(3);     // Type of indication column
        }
        private void SetInstanceValuesForSpontaneousRelease2(DatasetInstance e2bInstance, DatasetInstance spontaneousReport, User currentUser)
        {
            // ************************************* ichicsrmessageheader
            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Message Header").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Message Number").DatasetElement, e2bInstance.Id.ToString("D8"));
            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Message Header").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Message Date").DatasetElement, DateTime.Today.ToString("yyyyMMddhhmmss"));

            // ************************************* safetyreport
            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Safety Report").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Safety Report ID").DatasetElement, string.Format("PH-FDA-{0}", spontaneousReport.Id.ToString("D5")));
            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Safety Report").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Transmission Date").DatasetElement, DateTime.Today.ToString("yyyyMMdd"));
            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Safety Report").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Report Type").DatasetElement, "1");

            var seriousReason = spontaneousReport.GetInstanceValue("Reaction serious details");

            if (!String.IsNullOrWhiteSpace(seriousReason))
            {
                var sd  = "2=No";
                var slt = "2=No";
                var sh  = "2=No";
                var sdi = "2=No";
                var sca = "2=No";
                var so  = "2=No";

                switch (seriousReason)
                {
                case "Resulted in death":
                    sd = "1=Yes";
                    break;

                case "Is life-threatening":
                    slt = "1=Yes";
                    break;

                case "Is a congenital anomaly/birth defect":
                    sca = "1=Yes";
                    break;

                case "Requires hospitalization or longer stay in hospital":
                    sh = "1=Yes";
                    break;

                case "Results in persistent or significant disability/incapacity (as per reporter's opinion)":
                    sdi = "1=Yes";
                    break;

                case "Other medically important condition":
                    so = "1=Yes";
                    break;

                default:
                    break;
                }

                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "B4EA6CBF-2D9C-482D-918A-36ABB0C96EFA"), sd);  //Seriousness Death
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "26C6F08E-B80B-411E-BFDC-0506FE102253"), slt); //Seriousness Life Threatening
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "837154A9-D088-41C6-A9E2-8A0231128496"), sh);  //Seriousness Hospitalization
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "DDEBDEC0-2A90-49C7-970E-B7855CFDF19D"), sdi); //Seriousness Disabling
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "DF89C98B-1D2A-4C8E-A753-02E265841F4F"), sca); //Seriousness Congenital Anomaly
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "33A75547-EF1B-42FB-8768-CD6EC52B24F8"), so);  //Seriousness Other
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "510EB752-2D75-4DC3-8502-A4FCDC8A621A"), "1"); //Serious
            }
            else
            {
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "510EB752-2D75-4DC3-8502-A4FCDC8A621A"), "2"); //Serious
            }

            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Safety Report").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Date report was first received").DatasetElement, spontaneousReport.Created.ToString("yyyyMMdd"));
            e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Safety Report").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Date of most recent info").DatasetElement, spontaneousReport.Created.ToString("yyyyMMdd"));

            // ************************************* primarysource
            var fullName = spontaneousReport.GetInstanceValue("Reporter Name");

            if (!String.IsNullOrWhiteSpace(fullName))
            {
                if (fullName.Contains(" "))
                {
                    e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Primary Source").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Reporter Given Name").DatasetElement, fullName.Substring(0, fullName.IndexOf(" ")));
                    e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Primary Source").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Reporter Family Name").DatasetElement, fullName.Substring(fullName.IndexOf(" ") + 1, fullName.Length - (fullName.IndexOf(" ") + 1)));
                }
                else
                {
                    e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Primary Source").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Reporter Given Name").DatasetElement, fullName);
                }
            }

            MapSenderAndReceivedRelatedFields(e2bInstance);

            // ************************************* patient
            var dob      = spontaneousReport.GetInstanceValue("Date of Birth");
            var onset    = spontaneousReport.GetInstanceValue("Reaction known start date");
            var recovery = spontaneousReport.GetInstanceValue("Reaction date of recovery");

            if (!String.IsNullOrWhiteSpace(dob))
            {
                e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Patient").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Patient Birthdate").DatasetElement, Convert.ToDateTime(dob).ToString("yyyyMMdd"));

                if (!String.IsNullOrWhiteSpace(onset))
                {
                    var age = (Convert.ToDateTime(onset) - Convert.ToDateTime(dob)).Days;
                    e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Patient").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Patient Onset Age").DatasetElement, age.ToString());
                    e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Patient").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Patient Onset Age Unit").DatasetElement, "804=Day");
                }
            }

            // ************************************* reaction
            var term    = spontaneousReport.GetInstanceValue("TerminologyMedDra");
            var termOut = "NOT SET";

            if (!String.IsNullOrWhiteSpace(term))
            {
                var termid = Convert.ToInt32(term);
                termOut = _unitOfWork.Repository <TerminologyMedDra>().Queryable().Single(u => u.Id == termid).DisplayName;
            }
            ;
            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.ElementName == "Reaction MedDRA LLT"), termOut);
            if (!String.IsNullOrWhiteSpace(onset))
            {
                e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Reaction").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Reaction Start Date").DatasetElement, Convert.ToDateTime(onset).ToString("yyyyMMdd"));
            }
            ;
            if (!String.IsNullOrWhiteSpace(onset) && !String.IsNullOrWhiteSpace(recovery))
            {
                var rduration = (Convert.ToDateTime(recovery) - Convert.ToDateTime(onset)).Days;
                e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Reaction").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Reaction Duration").DatasetElement, rduration.ToString());
                e2bInstance.SetInstanceValue(e2bInstance.Dataset.DatasetCategories.Single(dc => dc.DatasetCategoryName == "Reaction").DatasetCategoryElements.Single(dce => dce.DatasetElement.ElementName == "Reaction Duration Unit").DatasetElement, "804=Day");
            }

            // ************************************* drug
            var destinationProductElement = _unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "Medicinal Products");
            var sourceContexts            = spontaneousReport.GetInstanceSubValuesContext("Product Information");

            foreach (Guid sourceContext in sourceContexts)
            {
                var drugItemValues = spontaneousReport.GetInstanceSubValues("Product Information", sourceContext);
                var drugName       = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Product").InstanceValue;

                if (drugName != string.Empty)
                {
                    Guid?newContext = e2bInstance.GetContextForInstanceSubValue(destinationProductElement, destinationProductElement.DatasetElementSubs.SingleOrDefault(des => des.ElementName == "Medicinal Product"), drugName);
                    if (newContext != null)
                    {
                        var reportInstanceMedication = _unitOfWork.Repository <ReportInstanceMedication>().Queryable().Single(x => x.ReportInstanceMedicationGuid == sourceContext);

                        // Causality
                        if (reportInstanceMedication.WhoCausality != null)
                        {
                            e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Reaction Assessment"), spontaneousReport.GetInstanceValue("Description of reaction"), (Guid)newContext);
                            e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Method of Assessment"), "WHO Causality Scale", (Guid)newContext);
                            e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Assessment Result"), reportInstanceMedication.WhoCausality.ToLowerInvariant() == "ignored" ? "" : reportInstanceMedication.WhoCausality, (Guid)newContext);
                        }
                        else
                        {
                            if (reportInstanceMedication.NaranjoCausality != null)
                            {
                                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Reaction Assessment"), spontaneousReport.GetInstanceValue("Description of reaction"), (Guid)newContext);
                                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Method of Assessment"), "Naranjo Causality Scale", (Guid)newContext);
                                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Assessment Result"), reportInstanceMedication.NaranjoCausality.ToLowerInvariant() == "ignored" ? "" : reportInstanceMedication.NaranjoCausality, (Guid)newContext);
                            }
                        }

                        // Treatment Duration
                        var startValue = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Start Date");
                        var endValue   = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug End Date");
                        if (startValue != null && endValue != null)
                        {
                            var rduration = (Convert.ToDateTime(endValue.InstanceValue) - Convert.ToDateTime(startValue.InstanceValue)).Days;
                            e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Treatment Duration"), rduration.ToString(), (Guid)newContext);
                            e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Treatment Duration Unit"), "804=Day", (Guid)newContext);
                        }

                        // Dosage
                        if (drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Strength") != null && drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Dose Number") != null)
                        {
                            decimal strength = ConvertValueToDecimal(drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Strength").InstanceValue);
                            decimal dosage   = ConvertValueToDecimal(drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Dose Number").InstanceValue);

                            decimal dosageCalc = strength * dosage;
                            e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Structured Dosage"), dosageCalc.ToString(), (Guid)newContext);
                        }
                    }
                }
            }
        }
Exemple #6
0
        private async Task PrepareMedicationsForSpontaneousReportAsync(DatasetInstance datasetInstance)
        {
            var reportInstance = await _reportInstanceRepository.GetAsync(ri => ri.ContextGuid == datasetInstance.DatasetInstanceGuid, new string[] { "Medications" });

            if (reportInstance == null)
            {
                return;
            }
            ;

            var sourceProductElement = await _datasetElementRepository.GetAsync(dse => dse.ElementName == "Product Information");

            var sourceContexts = datasetInstance.GetInstanceSubValuesContext(sourceProductElement.ElementName);

            var i = 0;

            foreach (ReportInstanceMedication med in reportInstance.Medications)
            {
                i += 1;

                List <string[]> rows  = new();
                List <string>   cells = new();

                cells.Add($"Drug {i}");
                cells.Add("Start Date");
                cells.Add("End Date");
                cells.Add("Dose");
                cells.Add("Route");
                cells.Add("Indication");

                rows.Add(cells.ToArray());

                cells = new();

                var drugItemValues = datasetInstance.GetInstanceSubValues(sourceProductElement.ElementName, med.ReportInstanceMedicationGuid);

                var startValue = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Start Date");
                var endValue   = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug End Date");
                var dose       = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Dose number");
                var route      = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug route of administration");
                var indication = drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Drug Indication");

                cells.Add(drugItemValues.SingleOrDefault(div => div.DatasetElementSub.ElementName == "Product").InstanceValue);
                cells.Add(startValue != null ? Convert.ToDateTime(startValue.InstanceValue).ToString("yyyy-MM-dd") : string.Empty);
                cells.Add(endValue != null ? Convert.ToDateTime(endValue.InstanceValue).ToString("yyyy-MM-dd") : string.Empty);
                cells.Add(dose != null ? dose.InstanceValue : string.Empty);
                cells.Add(route != null ? route.InstanceValue : string.Empty);
                cells.Add(indication != null ? indication.InstanceValue : string.Empty);

                rows.Add(cells.ToArray());

                _wordDocumentService.AddRowTable(rows, new int[] { 2500, 1250, 1250, 1250, 1250, 3852 });
                _wordDocumentService.AddTableHeader("C.1 CLINICIAN ACTION TAKEN WITH REGARD TO MEDICINE");
                _wordDocumentService.AddOneColumnTable(new List <string>()
                {
                    ""
                });
                _wordDocumentService.AddTableHeader("C.2 EFFECT OF DECHALLENGE/ RECHALLENGE");
                _wordDocumentService.AddOneColumnTable(new List <string>()
                {
                    ""
                });
                _wordDocumentService.AddTableHeader("C.3 NOTES");
                _wordDocumentService.AddOneColumnTable(new List <string>()
                {
                    ""
                });
            }
        }