예제 #1
0
        private void PrepareWeightForActiveReport(PatientClinicalEvent patientClinicalEvent)
        {
            List <string[]> rows  = new();
            List <string>   cells = new();

            cells.Add("Weight Date");
            cells.Add("Weight");

            rows.Add(cells.ToArray());

            var weightSeries = _patientService.GetElementValues(patientClinicalEvent.Patient.Id, "Weight(kg)", 10);

            if (weightSeries.Length > 0)
            {
                foreach (var weight in weightSeries[0].Series)
                {
                    cells = new();

                    cells.Add(weight.Name);
                    cells.Add(weight.Value.ToString());

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

            _wordDocumentService.AddRowTable(rows, new int[] { 2500, 8852 });
        }
예제 #2
0
        private async Task <bool> CheckIfSeriousAsync(PatientClinicalEvent patientClinicalEvent)
        {
            var extendable      = (IExtendable)patientClinicalEvent;
            var extendableValue = await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Is the adverse event serious?", extendable);

            return(extendableValue == "Yes");
        }
예제 #3
0
        protected void Page_Init(object sender, EventArgs e)
        {
            _context             = formContext.View;
            divCausality.Visible = false;

            if (Request.QueryString["rid"] != null)
            {
                _rid = Convert.ToInt32(Request.QueryString["rid"]);
                if (_rid > 0)
                {
                    _reportInstance = UnitOfWork.Repository <ReportInstance>().Queryable().SingleOrDefault(ri => ri.Id == _rid);

                    if (_reportInstance.WorkFlow.Description == "New Active Surveilliance Report")
                    {
                        _formMode      = FormMode.ActiveMode;
                        _clinicalEvent = UnitOfWork.Repository <PatientClinicalEvent>().Queryable().Include(pce => pce.Patient).SingleOrDefault(pce => pce.PatientClinicalEventGuid == _reportInstance.ContextGuid);

                        HandleActiveInit();
                    }
                    else
                    {
                        _formMode = FormMode.SpontaneousMode;
                        _instance = UnitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(di => di.DatasetInstanceGuid == _reportInstance.ContextGuid);

                        HandleSpontaneousInit();
                    }
                }
                else
                {
                    throw new Exception("rid parameter not passed");
                }
            }
        }
예제 #4
0
        private List <CustomAttributeDTO> getCustomAttributes(PatientClinicalEvent clinicalEvent)
        {
            var extendable = (IExtendable)clinicalEvent;

            var customAttributes = unitOfWork.Repository <PVIMS.Core.Entities.CustomAttributeConfiguration>()
                                   .Queryable()
                                   .Where(ca => ca.ExtendableTypeName == typeof(PatientClinicalEvent).Name)
                                   .ToList();

            return(customAttributes.Select(c => new CustomAttributeDTO
            {
                CustomAttributeConfigId = c.Id,
                AttributeName = c.AttributeKey,
                AttributeTypeName = c.CustomAttributeType.ToString(),
                Category = c.Category,
                EntityName = c.ExtendableTypeName,
                currentValue = GetCustomAttributeVale(extendable, c),
                lastUpdated = extendable.CustomAttributes.GetUpdatedDate(c.AttributeKey),
                lastUpdatedUser = extendable.GetUpdatedByUser(c.AttributeKey),
                Required = c.IsRequired,
                NumericMaxValue = c.NumericMaxValue,
                NumericMinValue = c.NumericMinValue,
                StringMaxLength = c.StringMaxLength,
                FutureDateOnly = c.FutureDateOnly,
                PastDateOnly = c.PastDateOnly,
            })
                   .ToList());
        }
        private async Task CustomMapAsync(PatientClinicalEvent patientClinicalEventFromRepo, PatientClinicalEventExpandedDto dto)
        {
            IExtendable patientClinicalEventExtended = patientClinicalEventFromRepo;

            // Map all custom attributes
            dto.ClinicalEventAttributes = _modelExtensionBuilder.BuildModelExtension(patientClinicalEventExtended)
                                          .Select(h => new AttributeValueDto()
            {
                Id             = h.Id,
                Key            = h.AttributeKey,
                Value          = h.TransformValueToString(),
                Category       = h.Category,
                SelectionValue = GetSelectionValue(h.Type, h.AttributeKey, h.Value.ToString())
            }).Where(s => (s.Value != "0" && !String.IsNullOrWhiteSpace(s.Value)) || !String.IsNullOrWhiteSpace(s.SelectionValue)).ToList();

            dto.ReportDate = await _customAttributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Date of Report", patientClinicalEventExtended);

            dto.IsSerious = await _customAttributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Is the adverse event serious?", patientClinicalEventExtended);

            var activity = await _reportInstanceQueries.GetExecutionStatusEventsForEventViewAsync(patientClinicalEventFromRepo.Id);

            dto.Activity = activity.ToList();

            var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.ContextGuid == patientClinicalEventFromRepo.PatientClinicalEventGuid, new string[] { "TerminologyMedDra", "Medications", "Tasks.Comments" });

            if (reportInstanceFromRepo == null)
            {
                return;
            }

            dto.SetMedDraTerm     = reportInstanceFromRepo.TerminologyMedDra?.DisplayName;
            dto.SetClassification = ReportClassification.From(reportInstanceFromRepo.ReportClassificationId).Name;
            dto.Medications       = _mapper.Map <ICollection <ReportInstanceMedicationDetailDto> >(reportInstanceFromRepo.Medications.Where(m => !String.IsNullOrWhiteSpace(m.WhoCausality) || (!String.IsNullOrWhiteSpace(m.NaranjoCausality))));
            dto.Tasks             = _mapper.Map <ICollection <TaskDto> >(reportInstanceFromRepo.Tasks.Where(t => t.TaskStatusId != Core.Aggregates.ReportInstanceAggregate.TaskStatus.Cancelled.Id));
        }
예제 #6
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);
        }
예제 #7
0
 public void InitialiseValuesForActiveDataset(string tag, PatientClinicalEvent activeReport)
 {
     foreach (DatasetCategory dc in Dataset.DatasetCategories)
     {
         foreach (DatasetCategoryElement dce in dc.DatasetCategoryElements)
         {
             // Default using default value
             if (!String.IsNullOrWhiteSpace(dce.DatasetElement.DefaultValue))
             {
                 SetInstanceValue(dce.DatasetElement, dce.DatasetElement.DefaultValue);
             }
             else
             {
                 MapValuesUsingEvent(dce, tag, activeReport);
             }
         }
     }
 }
예제 #8
0
        private void PopulateMetaTables()
        {
            Patient patient = new Patient();

            ProcessInsertEntity(patient, "Patient");
            patient = null;

            PatientMedication patientMedication = new PatientMedication();

            ProcessInsertEntity(patientMedication, "PatientMedication");
            patientMedication = null;

            PatientClinicalEvent patientClinicalEvent = new PatientClinicalEvent();

            ProcessInsertEntity(patientClinicalEvent, "PatientClinicalEvent");
            patientClinicalEvent = null;

            PatientCondition patientCondition = new PatientCondition();

            ProcessInsertEntity(patientCondition, "PatientCondition");
            patientCondition = null;

            PatientLabTest patientLabTest = new PatientLabTest();

            ProcessInsertEntity(patientLabTest, "PatientLabTest");
            patientLabTest = null;

            Encounter encounter = new Encounter(patient);

            ProcessInsertEntity(encounter, "Encounter");
            encounter = null;

            CohortGroupEnrolment cohortGroupEnrolment = new CohortGroupEnrolment();

            ProcessInsertEntity(cohortGroupEnrolment, "CohortGroupEnrolment");
            cohortGroupEnrolment = null;

            PatientFacility patientFacility = new PatientFacility();

            ProcessInsertEntity(patientFacility, "PatientFacility");
            patientFacility = null;

            _summary += String.Format("<li>INFO: All meta data seeded...</li>");
        }
예제 #9
0
        private void CheckColumnsExist()
        {
            Patient patient = new Patient();

            ProcessEntity(patient, "Patient");
            patient = null;

            PatientMedication patientMedication = new PatientMedication();

            ProcessEntity(patientMedication, "PatientMedication");
            patientMedication = null;

            PatientClinicalEvent patientClinicalEvent = new PatientClinicalEvent();

            ProcessEntity(patientClinicalEvent, "PatientClinicalEvent");
            patientClinicalEvent = null;

            PatientCondition patientCondition = new PatientCondition();

            ProcessEntity(patientCondition, "PatientCondition");
            patientCondition = null;

            PatientLabTest patientLabTest = new PatientLabTest();

            ProcessEntity(patientLabTest, "PatientLabTest");
            patientLabTest = null;

            Encounter encounter = new Encounter(patient);

            ProcessEntity(encounter, "Encounter");
            encounter = null;

            CohortGroupEnrolment cohortGroupEnrolment = new CohortGroupEnrolment();

            ProcessEntity(cohortGroupEnrolment, "CohortGroupEnrolment");
            cohortGroupEnrolment = null;

            PatientFacility patientFacility = new PatientFacility();

            ProcessEntity(patientFacility, "PatientFacility");
            patientFacility = null;

            _summary += String.Format("<li>INFO: All columns checked and verified...</li>");
        }
        private async Task CustomMapAsync(PatientClinicalEvent patientClinicalEventFromRepo, PatientClinicalEventDetailDto dto)
        {
            IExtendable patientClinicalEventExtended = patientClinicalEventFromRepo;

            // Map all custom attributes
            dto.ClinicalEventAttributes = _modelExtensionBuilder.BuildModelExtension(patientClinicalEventExtended)
                                          .Select(h => new AttributeValueDto()
            {
                Id             = h.Id,
                Key            = h.AttributeKey,
                Value          = h.TransformValueToString(),
                Category       = h.Category,
                SelectionValue = GetSelectionValue(h.Type, h.AttributeKey, h.Value.ToString())
            }).Where(s => (s.Value != "0" && !String.IsNullOrWhiteSpace(s.Value)) || !String.IsNullOrWhiteSpace(s.SelectionValue)).ToList();

            dto.ReportDate = await _customAttributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Date of Report", patientClinicalEventExtended);

            dto.IsSerious = await _customAttributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Is the adverse event serious?", patientClinicalEventExtended);
        }
예제 #11
0
        protected void Page_Init(object sender, EventArgs e)
        {
            Master.SetPageHeader(new Models.PageHeaderDetail()
            {
                Title = "Naranjo Causality Assessment", SubTitle = "", Icon = "fa fa-dashboard fa-fw", MetaPageId = 0
            });

            _context             = formContext.View;
            divCausality.Visible = false;

            if (Request.QueryString["rid"] != null)
            {
                _rid = Convert.ToInt32(Request.QueryString["rid"]);
                if (_rid > 0)
                {
                    _reportInstance = UnitOfWork.Repository <ReportInstance>().Queryable().SingleOrDefault(ri => ri.Id == _rid);

                    if (_reportInstance.WorkFlow.Description == "New Active Surveilliance Report")
                    {
                        Master.SetMenuActive("ActiveReporting");

                        _formMode      = FormMode.ActiveMode;
                        _clinicalEvent = UnitOfWork.Repository <PatientClinicalEvent>().Queryable().Include(pce => pce.Patient).SingleOrDefault(pce => pce.PatientClinicalEventGuid == _reportInstance.ContextGuid);

                        HandleActiveInit();
                    }
                    else
                    {
                        Master.SetMenuActive("SpontaneousReporting");

                        _formMode = FormMode.SpontaneousMode;
                        _instance = UnitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(di => di.DatasetInstanceGuid == _reportInstance.ContextGuid);

                        HandleSpontaneousInit();
                    }
                }
                else
                {
                    throw new Exception("rid parameter not passed");
                }
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            Master.SetPageHeader(new Models.PageHeaderDetail()
            {
                Title = "MedDRA Terminology", SubTitle = "", Icon = "fa fa-dashboard fa-fw", MetaPageId = 0
            });

            _clinicalEvent = null;
            _instance      = null;

            if (Request.QueryString["rid"] != null)
            {
                _rid = Convert.ToInt32(Request.QueryString["rid"]);
                if (_rid > 0)
                {
                    _reportInstance = UnitOfWork.Repository <ReportInstance>().Queryable().SingleOrDefault(ri => ri.Id == _rid);

                    if (_reportInstance.WorkFlow.Description == "New Active Surveilliance Report")
                    {
                        Master.SetMenuActive("ActiveReporting");

                        _clinicalEvent = UnitOfWork.Repository <PatientClinicalEvent>().Queryable().Include(pce => pce.Patient).SingleOrDefault(pce => pce.PatientClinicalEventGuid == _reportInstance.ContextGuid);
                        _formMode      = FormMode.ActiveMode;
                    }
                    else
                    {
                        Master.SetMenuActive("SpontaneousReporting");

                        _instance = UnitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(di => di.DatasetInstanceGuid == _reportInstance.ContextGuid);
                        _formMode = FormMode.SpontaneousMode;
                    }
                }
                else
                {
                    throw new Exception("rid parameter not passed");
                }
            }

            LoadCommonItems();
            RenderButtons();
        }
        private async Task UpdateValuesUsingSourceAsync(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, Dataset dataset)
        {
            var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user     = await _userRepository.GetAsync(u => u.UserName == userName);

            if (dataset.DatasetName.Contains("(R2)"))
            {
                await SetInstanceValuesForActiveRelease2Async(e2bInstance, activeReport);
            }
            if (dataset.DatasetName.Contains("(R3)"))
            {
                //var term = _workFlowService.GetTerminologyMedDraForReportInstance(activeReport.PatientClinicalEventGuid);

                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "N.1.2 Batch Number"), "MSH.PViMS-B01000" + activeReport.Id.ToString());
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "N.1.5 Date of Batch Transmission"), DateTime.Now.ToString("yyyyMMddHHmmsss"));
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "N.2.r.1 Message Identifier"), "MSH.PViMS-B01000" + activeReport.Id.ToString() + "-" + DateTime.Now.ToString("mmsss"));
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "N.2.r.4 Date of Message Creation"), DateTime.Now.ToString("yyyyMMddHHmmsss"));
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "C.1.1 Sender’s (case) Safety Report Unique Identifier"), String.Format("ZA-MSH.PViMS-{0}-{1}", DateTime.Today.ToString("yyyy"), activeReport.Id.ToString()));
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "C.1.2 Date of Creation"), DateTime.Now.ToString("yyyyMMddHHmmsss"));
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "C.1.8.1 Worldwide Unique Case Identification Number"), String.Format("ZA-MSH.PViMS-{0}-{1}", DateTime.Today.ToString("yyyy"), activeReport.Id.ToString()));
                //e2bInstance.SetInstanceValue(_unitOfWork.Repository<DatasetElement>().Queryable().Single(dse => dse.ElementName == "E.i.2.1b MedDRA Code for Reaction / Event"), term.DisplayName);
            }
        }
        private void MapTestRelatedFields(DatasetInstance e2bInstance, PatientClinicalEvent activeReport)
        {
            var destinationTestElement = _unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.DatasetElementGuid.ToString() == "693A2E8C-B041-46E7-8687-0A42E6B3C82E"); // Test History

            foreach (PatientLabTest labTest in activeReport.Patient.PatientLabTests.Where(lt => lt.TestDate >= activeReport.OnsetDate).OrderByDescending(lt => lt.TestDate))
            {
                var newContext = Guid.NewGuid();

                e2bInstance.SetInstanceSubValue(destinationTestElement.DatasetElementSubs.Single(des => des.ElementName == "Test Date"), labTest.TestDate.ToString("yyyyMMdd"), (Guid)newContext);
                e2bInstance.SetInstanceSubValue(destinationTestElement.DatasetElementSubs.Single(des => des.ElementName == "Test Name"), labTest.LabTest.Description, (Guid)newContext);

                var testResult = !String.IsNullOrWhiteSpace(labTest.LabValue) ? labTest.LabValue : !String.IsNullOrWhiteSpace(labTest.TestResult) ? labTest.TestResult : "";
                e2bInstance.SetInstanceSubValue(destinationTestElement.DatasetElementSubs.Single(des => des.ElementName == "Test Result"), testResult, (Guid)newContext);

                var testUnit = labTest.TestUnit != null ? labTest.TestUnit.Description : "";
                if (!String.IsNullOrWhiteSpace(testUnit))
                {
                    e2bInstance.SetInstanceSubValue(destinationTestElement.DatasetElementSubs.Single(des => des.ElementName == "Test Unit"), testUnit, (Guid)newContext);
                }
                ;

                var lowRange = labTest.ReferenceLower;
                if (!String.IsNullOrWhiteSpace(lowRange))
                {
                    e2bInstance.SetInstanceSubValue(destinationTestElement.DatasetElementSubs.Single(des => des.ElementName == "Low Test Range"), lowRange, (Guid)newContext);
                }
                ;

                var highRange = labTest.ReferenceUpper;
                if (!String.IsNullOrWhiteSpace(highRange))
                {
                    e2bInstance.SetInstanceSubValue(destinationTestElement.DatasetElementSubs.Single(des => des.ElementName == "High Test Range"), highRange, (Guid)newContext);
                }
                ;
            }
        }
예제 #15
0
        private void PrepareEvaluationsForActiveReport(PatientClinicalEvent patientClinicalEvent)
        {
            List <string[]> rows  = new();
            List <string>   cells = new();

            cells.Add("Test");
            cells.Add("Test Date (yyyy-mm-dd)");
            cells.Add("Test Result");

            rows.Add(cells.ToArray());

            foreach (PatientLabTest labTest in patientClinicalEvent.Patient.PatientLabTests.Where(lt => lt.TestDate >= patientClinicalEvent.OnsetDate).OrderByDescending(lt => lt.TestDate))
            {
                cells = new();

                cells.Add(labTest.LabTest.Description);
                cells.Add(labTest.TestDate.ToString("yyyy-MM-dd"));
                cells.Add(labTest.TestResult);

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

            _wordDocumentService.AddRowTable(rows, new int[] { 2500, 2500, 6352 });
        }
        private object MapPrimarySourceRelatedFields(DatasetInstance e2bInstance, PatientClinicalEvent activeReport)
        {
            IExtendable activeReportExtended = activeReport;

            object objectValue = activeReportExtended.GetAttributeValue("Name of reporter");
            var    fullName    = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(fullName))
            {
                if (fullName.Contains(" "))
                {
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "C35D5F5A-D539-4EEE-B080-FF384D5FBE08"), fullName.Substring(0, fullName.IndexOf(" ")));                                                 //Reporter Given Name
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "F214C619-EE0E-433E-8F52-83469778E418"), fullName.Substring(fullName.IndexOf(" ") + 1, fullName.Length - (fullName.IndexOf(" ") + 1))); //Reporter Family Name
                }
                else
                {
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "C35D5F5A-D539-4EEE-B080-FF384D5FBE08"), fullName); //Reporter Given Name
                }
            }

            objectValue = activeReportExtended.GetAttributeValue("Profession");
            var profession = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(profession))
            {
                var selectionValue = _unitOfWork.Repository <SelectionDataItem>().Queryable().Single(sdi => sdi.AttributeKey == "Profession" && sdi.SelectionKey == profession).Value;

                switch (selectionValue.Trim())
                {
                case "Dentist":
                case "RN":
                case "Other health professional":
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "3=Other Health Professional");    //Qualification
                    break;

                case "Medical Doctor":
                case "Physician":
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "1=Physician");
                    break;

                case "Patient":
                case "Consumer or other non health professional":
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "5=Consumer or other non health professional");
                    break;

                case "RPh":
                case "Pharmacist":
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "2=Pharmacist");
                    break;

                case "Lawyer":
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "4=Lawyer");
                    break;

                default:
                    break;
                }
            }

            return(objectValue);
        }
예제 #17
0
        private void setCustomAttributes(IEnumerable <CustomAttributeDTO> customAttributes, PatientClinicalEvent clinicalEvent)
        {
            if (customAttributes != null)
            {
                var clinicalEventConditionExtended = (IExtendable)clinicalEvent;

                foreach (var customAttribute in customAttributes)
                {
                    switch (customAttribute.AttributeTypeName)
                    {
                    case "Numeric":
                        decimal number = 0M;
                        if (decimal.TryParse(customAttribute.currentValue, out number))
                        {
                            clinicalEventConditionExtended.SetAttributeValue(customAttribute.AttributeName, number, User.Identity.Name);
                        }
                        break;

                    case "Selection":
                        Int32 selection = 0;
                        if (Int32.TryParse(customAttribute.currentValue, out selection))
                        {
                            clinicalEventConditionExtended.SetAttributeValue(customAttribute.AttributeName, selection, User.Identity.Name);
                        }
                        break;

                    case "DateTime":
                        DateTime parsedDate = DateTime.MinValue;
                        if (DateTime.TryParse(customAttribute.currentValue, out parsedDate))
                        {
                            clinicalEventConditionExtended.SetAttributeValue(customAttribute.AttributeName, parsedDate, User.Identity.Name);
                        }
                        break;

                    case "String":
                    default:
                        clinicalEventConditionExtended.SetAttributeValue(customAttribute.AttributeName, customAttribute.currentValue ?? string.Empty, User.Identity.Name);
                        break;
                    }
                }
            }
        }
        private async Task MapDrugRelatedFieldsAsync(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, ReportInstance reportInstance)
        {
            string[] validNaranjoCriteria = { "Possible", "Probable", "Definite" };
            string[] validWHOCriteria     = { "Possible", "Probable", "Certain" };

            var destinationProductElement = await _datasetElementRepository.GetAsync(de => de.DatasetElementGuid.ToString() == "E033BDE8-EDC8-43FF-A6B0-DEA6D6FA581C", new string[] { "DatasetElementSubs" }); // Medicinal Products

            foreach (ReportInstanceMedication med in reportInstance.Medications)
            {
                var newContext = Guid.NewGuid();

                var patientMedication = await _patientMedicationRepository.GetAsync(pm => pm.PatientMedicationGuid == med.ReportInstanceMedicationGuid, new string[] { "Concept.MedicationForm" });

                IExtendable mcExtended = patientMedication;

                var character = "";
                character = (validNaranjoCriteria.Contains(med.NaranjoCausality) || validWHOCriteria.Contains(med.WhoCausality)) ? "1=Suspect" : "2=Concomitant";
                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Characterization"), character, (Guid)newContext);

                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Medicinal Product"), patientMedication.Concept.ConceptName, (Guid)newContext);

                var objectValue = mcExtended.GetAttributeValue("Batch Number");
                var batchNumber = objectValue != null?objectValue.ToString() : "";

                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Batch Number"), batchNumber, (Guid)newContext);

                objectValue = mcExtended.GetAttributeValue("Comments");
                var comments = objectValue != null?objectValue.ToString() : "";

                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Additional Information"), comments, (Guid)newContext);

                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Dosage Text"), patientMedication.DoseFrequency, (Guid)newContext);

                var form = patientMedication?.Concept?.MedicationForm?.Description;
                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Dosage Form"), form, (Guid)newContext);

                var startdate = patientMedication.StartDate;
                e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Start Date"), startdate.ToString("yyyyMMdd"), (Guid)newContext);

                var enddate = patientMedication.EndDate;
                if (enddate.HasValue)
                {
                    e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug End Date"), Convert.ToDateTime(enddate).ToString("yyyyMMdd"), (Guid)newContext);

                    var rduration = (Convert.ToDateTime(enddate) - Convert.ToDateTime(startdate)).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);
                }

                if (int.TryParse(patientMedication.Dose, out int n))
                {
                    e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Structured Dosage"), patientMedication.Dose, (Guid)newContext);
                }
                ;
                var doseUnit = MapDoseUnitForActive(patientMedication.DoseUnit);
                if (!string.IsNullOrWhiteSpace(doseUnit))
                {
                    e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Structured Dosage Unit"), doseUnit, (Guid)newContext);
                }
                ;

                objectValue = mcExtended.GetAttributeValue("Clinician action taken with regard to medicine if related to AE");
                var drugAction = objectValue != null?objectValue.ToString() : "";

                if (!string.IsNullOrWhiteSpace(drugAction))
                {
                    drugAction = MapDrugActionForActive(drugAction);
                }
                ;
                if (!string.IsNullOrWhiteSpace(drugAction))
                {
                    e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Action"), drugAction, (Guid)newContext);
                }
                ;

                // Causality
                if (med.WhoCausality != null)
                {
                    e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Reaction Assessment"), med.ReportInstance.TerminologyMedDra.DisplayName, (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"), med.WhoCausality.ToLowerInvariant() == "ignored" ? "" : med.WhoCausality, (Guid)newContext);
                }
                else
                {
                    if (med.NaranjoCausality != null)
                    {
                        e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Reaction Assessment"), med.ReportInstance.TerminologyMedDra.DisplayName, (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"), med.NaranjoCausality.ToLowerInvariant() == "ignored" ? "" : med.NaranjoCausality, (Guid)newContext);
                    }
                }
            } // foreach (ReportInstanceMedication med in reportInstance.Medications)
        }
예제 #19
0
        private async Task <List <KeyValuePair <string, string> > > PrepareAdverseEventForActiveReportAsync(PatientClinicalEvent patientClinicalEvent, ReportInstance reportInstance, bool isSerious)
        {
            var extendable = (IExtendable)patientClinicalEvent;
            List <KeyValuePair <string, string> > rows = new();

            rows.Add(new KeyValuePair <string, string>("Source Description", patientClinicalEvent.SourceDescription));
            rows.Add(new KeyValuePair <string, string>("MedDRA Term", reportInstance.TerminologyMedDra?.MedDraTerm));
            rows.Add(new KeyValuePair <string, string>("Onset Date (yyyy-mm-dd)", patientClinicalEvent.OnsetDate.HasValue ? patientClinicalEvent.OnsetDate.Value.ToString("yyyy-MM-dd") : ""));
            rows.Add(new KeyValuePair <string, string>("Resolution Date (yyyy-mm-dd)", patientClinicalEvent.ResolutionDate.HasValue ? patientClinicalEvent.ResolutionDate.Value.ToString("yyyy-MM-dd") : ""));

            if (patientClinicalEvent.OnsetDate.HasValue && patientClinicalEvent.ResolutionDate.HasValue)
            {
                rows.Add(new KeyValuePair <string, string>("Duration", $"${(patientClinicalEvent.ResolutionDate.Value - patientClinicalEvent.OnsetDate.Value).Days} days"));
            }
            else
            {
                rows.Add(new KeyValuePair <string, string>("Duration", string.Empty));
            }

            rows.Add(new KeyValuePair <string, string>("Outcome", await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Outcome", extendable)));

            if (isSerious)
            {
                rows.Add(new KeyValuePair <string, string>("Seriousness", await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Seriousness", extendable)));
                rows.Add(new KeyValuePair <string, string>("Classification", ReportClassification.From(reportInstance.ReportClassificationId).Name));
                rows.Add(new KeyValuePair <string, string>("Severity Grade", await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Severity Grade", extendable)));
                rows.Add(new KeyValuePair <string, string>("SAE Number", await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "FDA SAE Number", extendable)));
            }

            return(rows);
        }
예제 #20
0
 private async Task UpdateReportInstanceIdentifiers(Patient patientFromRepo, PatientClinicalEvent clinicalEventToUpdate)
 {
     await _workFlowService.UpdateSourceIdentifierForReportInstanceAsync(
         contextGuid : clinicalEventToUpdate.PatientClinicalEventGuid,
         sourceIdentifier : clinicalEventToUpdate.SourceTerminologyMedDra?.DisplayName ?? clinicalEventToUpdate.SourceDescription);
 }
예제 #21
0
        private List <KeyValuePair <string, string> > PrepareConditionsForActiveReport(PatientClinicalEvent patientClinicalEvent)
        {
            List <KeyValuePair <string, string> > rows = new();

            var i = 0;

            foreach (PatientCondition patientCondition in patientClinicalEvent.Patient.PatientConditions.Where(pc => pc.OnsetDate <= patientClinicalEvent.OnsetDate).OrderByDescending(c => c.OnsetDate))
            {
                i += 1;
                rows.Add(new KeyValuePair <string, string>("Condition", patientCondition.TerminologyMedDra.MedDraTerm));
                rows.Add(new KeyValuePair <string, string>("Start Date (yyyy-mm-dd)", patientCondition.OnsetDate.ToString("yyyy-MM-dd")));
                rows.Add(new KeyValuePair <string, string>("End Date (yyyy-mm-dd)", patientCondition.OutcomeDate.HasValue ? patientCondition.OutcomeDate.Value.ToString("yyyy-MM-dd") : ""));
            }

            return(rows);
        }
예제 #22
0
        public List <ActivityExecutionStatusForPatient> GetExecutionStatusEventsForEventView(PatientClinicalEvent clinicalEvent)
        {
            List <ActivityExecutionStatusForPatient> results = new List <ActivityExecutionStatusForPatient>();

            var reportInstance = _unitOfWork.Repository <ReportInstance>().Queryable().SingleOrDefault(ri => ri.ContextGuid == clinicalEvent.PatientClinicalEventGuid);

            if (reportInstance != null)
            {
                var result = new ActivityExecutionStatusForPatient();
                result.PatientClinicalEvent = clinicalEvent;

                var items = _unitOfWork.Repository <ActivityExecutionStatusEvent>().Queryable().Where(aese => aese.ActivityInstance.ReportInstance.Id == reportInstance.Id).OrderBy(aese => aese.EventDateTime);
                foreach (ActivityExecutionStatusEvent item in items)
                {
                    var activityItem = new ActivityExecutionStatusForPatient.ActivityExecutionStatusInfo()
                    {
                        Comments   = item.Comments,
                        Status     = item.ExecutionStatus.FriendlyDescription,
                        StatusDate = item.EventDateTime.ToString("yyyy-MM-dd")
                    };
                    result.ActivityItems.Add(activityItem);
                }
                ;

                results.Add(result);
            }

            return(results);
        }
예제 #23
0
        private void MapValuesUsingEvent(DatasetCategoryElement dce, string tag, PatientClinicalEvent clinicalEvent)
        {
            IExtendable ptExtended = clinicalEvent.Patient;
            IExtendable ceExtended = clinicalEvent;

            if (dce.DestinationMappings.Where(dm => dm.Tag == tag).Count() > 0)
            {
                // Get the value to be translated
                var    mapping     = dce.DestinationMappings.Single(dm => dm.Tag == tag);
                string sourceValue = string.Empty;
                object objectValue;

                if (mapping.MappingType == MappingType.AttributeToElement || mapping.MappingType == MappingType.AttributeToValue)
                {
                    if (!String.IsNullOrWhiteSpace(mapping.PropertyPath) && !String.IsNullOrWhiteSpace(mapping.Property))
                    {
                        switch (mapping.PropertyPath)
                        {
                        case "Patient":
                            objectValue = ptExtended.GetAttributeValue(mapping.Property);
                            sourceValue = objectValue != null?objectValue.ToString() : "";

                            break;

                        case "PatientClinicalEvent":
                            objectValue = ceExtended.GetAttributeValue(mapping.Property);
                            sourceValue = objectValue != null?objectValue.ToString() : "";

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrWhiteSpace(mapping.Property))
                        {
                            objectValue = ceExtended.GetAttributeValue(mapping.Property);
                            sourceValue = objectValue != null?objectValue.ToString() : "";
                        }
                    }
                }
                else
                {
                    Object src = clinicalEvent;
                    if (mapping.MappingType == MappingType.FirstClassToElement || mapping.MappingType == MappingType.FirstClassToValue)
                    {
                        if (!String.IsNullOrWhiteSpace(mapping.PropertyPath))
                        {
                            switch (mapping.PropertyPath)
                            {
                            case "Patient":
                                src = clinicalEvent.Patient;
                                break;

                            default:
                                break;
                            }
                        }
                        objectValue = src.GetType().GetProperty(mapping.Property).GetValue(src, null);
                        sourceValue = objectValue != null?objectValue.ToString() : "";
                    }
                }

                // Translate the value
                if (!String.IsNullOrWhiteSpace(sourceValue))
                {
                    var formattedValue = TranslateSourceValueForElement(mapping, sourceValue);

                    if (!String.IsNullOrWhiteSpace(formattedValue))
                    {
                        SetInstanceValue(dce.DatasetElement, formattedValue);
                    }
                }
            }
        }
        private void MapPatientRelatedFields(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, out DateTime?onset, out DateTime?recovery)
        {
            IExtendable activeReportExtended = activeReport;
            IExtendable patientExtended      = activeReport.Patient;

            var init = String.Format("{0}{1}", activeReport.Patient.FirstName.Substring(0, 1), activeReport.Patient.Surname.Substring(0, 1));

            if (!String.IsNullOrWhiteSpace(init))
            {
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "A0BEAB3A-0B0A-457E-B190-1B66FE60CA73"), init);
            }
            ;                                                                                                                                                                                                                               //Patient Initial

            var dob = activeReport.Patient.DateOfBirth;

            onset    = activeReport.OnsetDate;
            recovery = activeReport.ResolutionDate;
            if (dob.HasValue)
            {
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "4F71B7F4-4317-4680-B3A3-9C1C1F72AD6A"), dob.Value.ToString("yyyyMMdd")); //Patient Birthdate

                if (onset.HasValue)
                {
                    var age = onset.Value.Year - dob.Value.Year;
                    if (dob.Value > onset.Value.AddYears(-age))
                    {
                        age--;
                    }

                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "E10C259B-DD2C-4F19-9D41-16FDDF9C5807"), age.ToString()); //Patient Onset Age
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "CA9B94C2-E1EF-407B-87C3-181224AF637A"), "801=Year");     //Patient Onset Age Unit
                }
            }

            var encounter = _unitOfWork.Repository <Encounter>().Queryable().OrderByDescending(e => e.EncounterDate).FirstOrDefault(e => e.Patient.Id == activeReport.Patient.Id && e.Archived == false & e.EncounterDate <= activeReport.OnsetDate);

            if (encounter != null)
            {
                var encounterInstance = _unitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(ds => ds.Dataset.DatasetName == "Chronic Treatment" && ds.ContextId == encounter.Id);
                if (encounterInstance != null)
                {
                    var weight = encounterInstance.GetInstanceValue("Weight (kg)");
                    if (!String.IsNullOrWhiteSpace(weight))
                    {
                        e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "89A6E687-A220-4319-AAC1-AFBB55C81873"), weight);
                    }
                    ;                                                                                                                                                                                                                                   //Patient Weight

                    var height = encounterInstance.GetInstanceValue("Height (cm)");
                    if (!String.IsNullOrWhiteSpace(height))
                    {
                        e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "40DAD435-8282-4B3E-B65E-3478FF55D028"), height);
                    }
                    ;                                                                                                                                                                                                                                   //Patient Height

                    var lmp = encounterInstance.GetInstanceValue("Date of last menstrual period");
                    if (!String.IsNullOrWhiteSpace(lmp))
                    {
                        e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "93253F91-60D1-4161-AF1A-F3ABDD140CB9"), Convert.ToDateTime(lmp).ToString("yyyyMMdd"));
                    }
                    ;                                                                                                                                                                                                                                                                      //Patient Last Menstrual Date

                    var gest = encounterInstance.GetInstanceValue("Estimated gestation (weeks)");
                    if (!String.IsNullOrWhiteSpace(gest))
                    {
                        e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "B6BE9689-B6B2-4FCF-8918-664AFC91A4E0"), gest);       //Gestation Period
                        e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1F174413-2A1E-45BD-B5C4-0C8F5DFFBFF4"), "803=Week"); //Gestation Period Unit
                    }
                    ;
                }
            }

            var objectValue = activeReportExtended.GetAttributeValue("Weight (kg)");
            var weightKg    = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(weightKg))
            {
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "89A6E687-A220-4319-AAC1-AFBB55C81873"), weightKg);
            }
            ;

            objectValue = activeReportExtended.GetAttributeValue("Height (cm)");
            var heightCm = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(heightCm))
            {
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "40DAD435-8282-4B3E-B65E-3478FF55D028"), heightCm);
            }
            ;

            objectValue = patientExtended.GetAttributeValue("Gender");
            var patientSex = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(patientSex))
            {
                if (patientSex == "1")
                {
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "59498520-172C-42BC-B30C-E249F94E412A"), "1=Male");
                }
                if (patientSex == "2")
                {
                    e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "59498520-172C-42BC-B30C-E249F94E412A"), "2=Female");
                }
            }
            ;
        }
        private async Task SetInstanceValuesForActiveRelease2Async(DatasetInstance e2bInstance, PatientClinicalEvent activeReport)
        {
            var reportInstance = await _reportInstanceRepository.GetAsync(ri => ri.ContextGuid == activeReport.PatientClinicalEventGuid, new string[] { "Medications", "TerminologyMedDra" });

            // ************************************* ichicsrmessageheader
            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "7FF710CB-C08C-4C35-925E-484B983F2135"), e2bInstance.Id.ToString("D8"));             // Message Number
            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "693614B6-D5D5-457E-A03B-EAAFA66E6FBD"), DateTime.Today.ToString("yyyyMMddhhmmss")); // Message Date

            MapSafetyReportRelatedFields(e2bInstance, activeReport, reportInstance);
            MapPrimarySourceRelatedFields(e2bInstance, activeReport);
            MapSenderAndReceivedRelatedFields(e2bInstance);

            DateTime?onset, recovery;

            MapPatientRelatedFields(e2bInstance, activeReport, out onset, out recovery);

            await MapReactionRelatedFieldsAsync(e2bInstance, activeReport, reportInstance, onset, recovery);

            MapTestRelatedFields(e2bInstance, activeReport);
            await MapDrugRelatedFieldsAsync(e2bInstance, activeReport, reportInstance);
        }
예제 #26
0
        public async Task <HttpResponseMessage> Post(JObject items)
        {
            if (items == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NoContent, "No records to process "));
            }

            dynamic json = items;

            List <PatientClinicalEvent> synchedPatientClinicalEvents = new List <PatientClinicalEvent>();

            IList <PatientClinicalEventDTO> patientClinicalEvents = await Task.Run(() => ((JArray)json.items)
                                                                                   .Select(t => new PatientClinicalEventDTO
            {
                PatientClinicalEventId = ((dynamic)t).PatientClinicalEventId,
                PatientClinicalEventIdentifier = ((dynamic)t).PatientClinicalEventIdentifier,
                PatientId = ((dynamic)t).PatientId,
                OnsetDate = ((dynamic)t).OnsetDate != null ? ((dynamic)t).OnsetDate : null,
                ReportedDate = ((dynamic)t).ReportedDate != null ? ((dynamic)t).ReportedDate : null,
                ResolutionDate = ((dynamic)t).ResolutionDate != null ? ((dynamic)t).ResolutionDate : null,
                Description = ((dynamic)t).Description,
                MedDraId = ((dynamic)t).MedDraId,
                customAttributes = ((dynamic)t).customAttributes == null ? null : ((JArray)(((dynamic)t).customAttributes))
                                   .Select(x => new CustomAttributeDTO
                {
                    CustomAttributeConfigId = ((dynamic)x).CustomAttributeConfigId,
                    AttributeTypeName = ((dynamic)x).AttributeTypeName,
                    AttributeName = ((dynamic)x).AttributeName,
                    Category = ((dynamic)x).Category,
                    EntityName = ((dynamic)x).EntityName,
                    currentValue = ((dynamic)x).currentValue,
                    lastUpdated = ((dynamic)x).lastUpdated != "" ? ((dynamic)x).lastUpdated : null,
                    lastUpdatedUser = ((dynamic)x).lastUpdatedUser,
                    Required = ((dynamic)x).Required,
                    NumericMaxValue = ((dynamic)x).NumericMaxValue != "" ? ((dynamic)x).NumericMaxValue : null,
                    NumericMinValue = ((dynamic)x).NumericMinValue != "" ? ((dynamic)x).NumericMinValue : null,
                    StringMaxLength = ((dynamic)x).StringMaxLength != "" ? ((dynamic)x).StringMaxLength : null,
                    FutureDateOnly = ((dynamic)x).FutureDateOnly != "" ? ((dynamic)x).FutureDateOnly : null,
                    PastDateOnly = ((dynamic)x).PastDateOnly != "" ? ((dynamic)x).PastDateOnly : null
                }).ToList()
            }).ToList());

            var termResults = await Task.Run(() => unitOfWork.Repository <TerminologyMedDra>()
                                             .Queryable().ToList());

            foreach (PatientClinicalEventDTO patientEvent in patientClinicalEvents)
            {
                PatientClinicalEvent obj = await unitOfWork.Repository <PatientClinicalEvent>()
                                           .Queryable()
                                           .SingleOrDefaultAsync(e => e.PatientClinicalEventGuid == patientEvent.PatientClinicalEventIdentifier);

                if (obj == null)
                {
                    obj = new PatientClinicalEvent
                    {
                        PatientClinicalEventGuid = patientEvent.PatientClinicalEventIdentifier,
                        Patient = unitOfWork.Repository <Patient>().Queryable().SingleOrDefault(e => e.Id == patientEvent.PatientId),
                        //Id = patientEvent.PatientClinicalEventId,
                        OnsetDate               = patientEvent.OnsetDate,
                        ResolutionDate          = patientEvent.ResolutionDate,
                        SourceDescription       = patientEvent.Description,
                        SourceTerminologyMedDra = termResults.FirstOrDefault(e => e.Id == patientEvent.MedDraId)
                    };

                    setCustomAttributes(patientEvent.customAttributes, obj);

                    unitOfWork.Repository <PatientClinicalEvent>().Save(obj);
                    synchedPatientClinicalEvents.Add(obj);
                }
                else
                {
                    obj.OnsetDate               = patientEvent.OnsetDate;
                    obj.ResolutionDate          = patientEvent.ResolutionDate;
                    obj.SourceDescription       = patientEvent.Description;
                    obj.SourceTerminologyMedDra = termResults.FirstOrDefault(e => e.Id == patientEvent.MedDraId);

                    setCustomAttributes(patientEvent.customAttributes, obj);

                    unitOfWork.Repository <PatientClinicalEvent>().Update(obj);
                    synchedPatientClinicalEvents.Add(obj);
                }
            }

            unitOfWork.Complete();

            DateTime dttemp;
            var      insertedObjs = synchedPatientClinicalEvents.Select(p => new PatientClinicalEventDTO
            {
                PatientId = p.Patient.Id,
                PatientClinicalEventIdentifier = p.PatientClinicalEventGuid,
                PatientClinicalEventId         = p.Id,
                Description      = p.SourceDescription,
                MedDraId         = p.SourceTerminologyMedDra.Id,
                OnsetDate        = p.OnsetDate,
                ResolutionDate   = p.ResolutionDate,
                ReportedDate     = DateTime.TryParse(GetCustomAttributeValue(unitOfWork.Repository <CustomAttributeConfiguration>().Queryable().SingleOrDefault(c => c.ExtendableTypeName == "PatientClinicalEvent" && c.AttributeKey == "Date of Report"), (IExtendable)p), out dttemp) ? dttemp : (DateTime?)null,
                customAttributes = getCustomAttributes(p)
            }).ToArray();

            return(Request.CreateResponse(HttpStatusCode.OK, insertedObjs));
        }
        private void MapSafetyReportRelatedFields(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, ReportInstance reportInstance)
        {
            IExtendable activeReportExtended = activeReport;

            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "6799CAD0-2A65-48A5-8734-0090D7C2D85E"), string.Format("PH.FDA.{0}", reportInstance.Id.ToString("D6"))); //Safety Report ID
            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "9C92D382-03AF-4A52-9A2F-04A46ADA0F7E"), DateTime.Today.ToString("yyyyMMdd"));                           //Transmission Date
            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "AE53FEB2-FF27-4CD5-AD54-C3FFED1490B5"), "2");                                                           //Report Type

            activeReportExtended = activeReport;
            var objectValue = activeReportExtended.GetAttributeValue("Is the adverse event serious?");
            var serious     = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(serious))
            {
                var selectionValue = _unitOfWork.Repository <SelectionDataItem>().Queryable().Single(sdi => sdi.AttributeKey == "Is the adverse event serious?" && sdi.SelectionKey == serious).Value;
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "510EB752-2D75-4DC3-8502-A4FCDC8A621A"), selectionValue == "Yes" ? "1=Yes" : "2=No"); //Serious
            }

            objectValue = activeReportExtended.GetAttributeValue("Seriousness");
            var seriousReason = objectValue != null?objectValue.ToString() : "";

            if (!String.IsNullOrWhiteSpace(seriousReason) && serious == "1")
            {
                var selectionValue = _unitOfWork.Repository <SelectionDataItem>().Queryable().Single(si => si.AttributeKey == "Seriousness" && si.SelectionKey == seriousReason).Value;

                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 (selectionValue)
                {
                case "Death":
                    sd = "1=Yes";
                    break;

                case "Life threatening":
                    slt = "1=Yes";
                    break;

                case "A congenital anomaly or birth defect":
                    sca = "1=Yes";
                    break;

                case "Initial or prolonged hospitalization":
                    sh = "1=Yes";
                    break;

                case "Persistent or significant disability or incapacity":
                    sdi = "1=Yes";
                    break;

                case "A medically important event":
                    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
            }

            objectValue = activeReportExtended.GetAttributeValue("Date of Report");
            var reportDate = objectValue != null?objectValue.ToString() : "";

            DateTime tempdt;

            if (DateTime.TryParse(reportDate, out tempdt))
            {
                e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "65ADEF15-961A-4558-B864-7832D276E0E3"), Convert.ToDateTime(reportDate).ToString("yyyyMMdd")); //Date report was first received
            }
            e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "A10C704D-BC1D-445E-B084-9426A91DB63B"), DateTime.Today.ToString("yyyyMMdd"));                     //Date of most recent info
        }
        private async Task MapReactionRelatedFieldsAsync(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, ReportInstance reportInstance, DateTime?onset, DateTime?recovery)
        {
            var terminologyMedDra = reportInstance.TerminologyMedDra;
            var term = terminologyMedDra != null ? terminologyMedDra.DisplayName : "";

            if (!String.IsNullOrWhiteSpace(term))
            {
                var datasetElement = await _datasetElementRepository.GetAsync(dse => dse.DatasetElementGuid.ToString() == "C8DD9A5E-BD9A-488D-8ABF-171271F5D370");

                e2bInstance.SetInstanceValue(datasetElement, term);;
            }
            ;  //Reaction MedDRA LLT

            if (onset != null)
            {
                var datasetElement = await _datasetElementRepository.GetAsync(dse => dse.DatasetElementGuid.ToString() == "1EAD9E11-60E6-4B27-9A4D-4B296B169E90");

                e2bInstance.SetInstanceValue(datasetElement, Convert.ToDateTime(onset).ToString("yyyyMMdd"));
            }
            ;  //Reaction Start Date

            if (recovery != null)
            {
                var datasetElement = await _datasetElementRepository.GetAsync(dse => dse.DatasetElementGuid.ToString() == "3A0F240E-8B36-48F6-9527-77E55F6E7CF1");

                e2bInstance.SetInstanceValue(datasetElement, Convert.ToDateTime(recovery).ToString("yyyyMMdd"));
            }
            ;  // Reaction End Date

            if (onset != null && recovery != null)
            {
                var rduration      = (Convert.ToDateTime(recovery) - Convert.ToDateTime(onset)).Days;
                var datasetElement = await _datasetElementRepository.GetAsync(dse => dse.DatasetElementGuid.ToString() == "0712C664-2ADD-44C0-B8D5-B6E83FB01F42");

                e2bInstance.SetInstanceValue(datasetElement, rduration.ToString()); //Reaction Duration

                datasetElement = await _datasetElementRepository.GetAsync(dse => dse.DatasetElementGuid.ToString() == "F96E702D-DCC5-455A-AB45-CAEFF25BF82A");

                e2bInstance.SetInstanceValue(datasetElement, "804=Day"); //Reaction Duration Unit
            }
        }
예제 #29
0
        private async Task <List <KeyValuePair <string, string> > > PrepareBasicInformationForActiveReportAsync(PatientClinicalEvent patientClinicalEvent)
        {
            var extendable        = (IExtendable)patientClinicalEvent;
            var patientExtendable = (IExtendable)patientClinicalEvent.Patient;
            List <KeyValuePair <string, string> > rows = new();

            rows.Add(new KeyValuePair <string, string>("Patient Name", patientClinicalEvent.Patient.FullName));
            rows.Add(new KeyValuePair <string, string>("Date of Birth (yyyy-mm-dd)", patientClinicalEvent.Patient.DateOfBirth.HasValue ? patientClinicalEvent.Patient.DateOfBirth.Value.ToString("yyyy-MM-dd") : ""));
            rows.Add(new KeyValuePair <string, string>("Age Group", patientClinicalEvent.Patient.AgeGroup));

            if (patientClinicalEvent.OnsetDate.HasValue && patientClinicalEvent.Patient.DateOfBirth.HasValue)
            {
                rows.Add(new KeyValuePair <string, string>("Age at time of onset", $"{CalculateAge(patientClinicalEvent.Patient.DateOfBirth.Value, patientClinicalEvent.OnsetDate.Value).ToString()} years"));
            }
            else
            {
                rows.Add(new KeyValuePair <string, string>("Age at time of onset", string.Empty));
            }

            rows.Add(new KeyValuePair <string, string>("Gender", await _attributeService.GetCustomAttributeValueAsync("Patient", "Gender", patientExtendable)));
            rows.Add(new KeyValuePair <string, string>("Ethnic Group", await _attributeService.GetCustomAttributeValueAsync("Patient", "Ethnic Group", patientExtendable)));
            rows.Add(new KeyValuePair <string, string>("Facility", patientClinicalEvent.Patient.CurrentFacility.Facility.FacilityName));
            rows.Add(new KeyValuePair <string, string>("Region", ""));
            //rows.Add(new KeyValuePair<string, string>("Medical Record Number", await _attributeService.GetCustomAttributeValueAsync("Patient", "Medical Record Number", extendable)));
            //rows.Add(new KeyValuePair<string, string>("Identity Number", await _attributeService.GetCustomAttributeValueAsync("Patient", "Patient Identity Number", extendable)));

            rows.Add(new KeyValuePair <string, string>("Weight (kg)", await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Weight (kg)", extendable)));
            rows.Add(new KeyValuePair <string, string>("Height (cm)", await _attributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Height (cm)", extendable)));

            return(rows);
        }
예제 #30
0
파일: Dataset.cs 프로젝트: MSH/PViMS-2
        public DatasetInstance CreateInstance(int contextId, string tag, EncounterTypeWorkPlan encounterTypeWorkPlan, DatasetInstance spontaneousReport, PatientClinicalEvent activeReport)
        {
            var instance = new DatasetInstance(this, contextId, tag, encounterTypeWorkPlan);

            foreach (DatasetCategory category in DatasetCategories)
            {
                foreach (DatasetCategoryElement element in category.DatasetCategoryElements)
                {
                    if (element.DatasetElement.Field.FieldType.Description == "Table")
                    {
                        instance.AddInstanceValue(element.DatasetElement, "<<Table>>");
                    }
                }
            }

            if (spontaneousReport != null)
            {
                instance.InitialiseValuesForSpontaneousDataset(tag, spontaneousReport);
            }
            if (activeReport != null)
            {
                instance.InitialiseValuesForActiveDataset(tag, activeReport);
            }

            return(instance);
        }