Exemplo n.º 1
0
        private List <CustomAttributeDTO> getCustomAttributes(PatientLabTest labTest)
        {
            var extendable = (IExtendable)labTest;

            var customAttributes = unitOfWork.Repository <PVIMS.Core.Entities.CustomAttributeConfiguration>()
                                   .Queryable()
                                   .Where(ca => ca.ExtendableTypeName == typeof(PatientLabTest).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 void CustomMap(PatientLabTest patientLabTestFromRepo, PatientLabTestDetailDto dto)
        {
            IExtendable patientLabTestExtended = patientLabTestFromRepo;

            // Map all custom attributes
            dto.LabTestAttributes = _modelExtensionBuilder.BuildModelExtension(patientLabTestExtended)
                                    .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();
        }
Exemplo n.º 3
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>");
        }
Exemplo n.º 4
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>");
        }
Exemplo n.º 5
0
        public override async Task <IActionResult> PatchAsync(int id, [FromBody] PatientLabTest patientLabTest)
        {
            //var attrToUpdate = _jsonApiContext.AttributesToUpdate;
            //var patientLabTestOld = _dbContextResolver.GetDbSet<PatientLabTest>().Where(m => m.Id == id).FirstOrDefault();

            //CommonMethods commonMethods = new CommonMethods();
            //List<AuditLogs> auditLogs = commonMethods.GetAuditLogValues(patientLabTestOld, patientLabTest, "PatientLabTest", attrToUpdate)
            //    //.Where(i => attrToUpdate.Keys.Any(a1 => a1.InternalAttributeName == i.PropertyName))
            //    .Select(q => new AuditLogs() { NewValue = q.NewValue, OldValue = q.OldValue, PrimaryKeyID = q.PrimaryKeyID, TableName = q.TableName, PropertyName = q.PropertyName }).ToList();
            //await _dbContextResolver.GetDbSet<AuditLogs>().AddRangeAsync(auditLogs);
            //return await base.PatchAsync(id, patientLabTest);

            //var patientLabTestInfo = await base.PatchAsync(id, patientLabTest);

            //int eventID = _dbContextResolver.GetDbSet<Event>().LastOrDefault().Id + 1;
            //List<AuditLogs> auditLogs = commonMethods.GetAuditLogValues(patientLabTestOld, patientLabTest, "PatientLabTest", attrToUpdate)
            //    //.Where(i => attrToUpdate.Keys.Any(a1 => a1.InternalAttributeName == i.PropertyName))
            //    .Select(q => new AuditLogs() { NewValue = q.NewValue, OldValue = q.OldValue, PrimaryKeyID = q.PrimaryKeyID, TableName = q.TableName, PropertyName = q.PropertyName, EventID = eventID }).ToList();
            //await _dbContextResolver.GetDbSet<AuditLogs>().AddRangeAsync(auditLogs);
            return(await base.PatchAsync(id, patientLabTest));
        }
Exemplo n.º 6
0
 public override async Task <IActionResult> PostAsync([FromBody] PatientLabTest patientLabTest)
 {
     return(await base.PostAsync(patientLabTest));
 }
Exemplo n.º 7
0
        public HttpResponseMessage Post(JObject items)
        {
            if (items == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NoContent, "No records to process "));
            }

            dynamic json = items;

            List <PatientLabTest> synchedPatientLabTest = new List <PatientLabTest>();

            IList <PatientLabTestDTO> patientLabTests = ((JArray)json.items)
                                                        .Select(t => new PatientLabTestDTO
            {
                PatientId                = ((dynamic)t).PatientId,
                PatientLabTestId         = ((dynamic)t).PatientLabTestId,
                PatientLabTestIdentifier = ((dynamic)t).PatientLabTestIdentifier,
                TestDate         = ((dynamic)t).TestDate != null ? ((dynamic)t).TestDate : null,
                TestName         = ((dynamic)t).TestName,
                TestResult       = (((dynamic)t).TestResult != null && ((dynamic)t).TestResult != "") ? ((dynamic)t).TestResult : null,
                TestUnit         = (((dynamic)t).TestUnit != null && ((dynamic)t).TestUnit != "") ? ((dynamic)t).TestUnit : default(decimal?),
                LabValue         = (((dynamic)t).LabValue != null && ((dynamic)t).LabValue != "") ? ((dynamic)t).LabValue : default(int?),
                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 labTestUnits = unitOfWork.Repository <LabTestUnit>().Queryable().ToList();
            var labTests     = unitOfWork.Repository <LabTest>().Queryable().ToList();

            foreach (PatientLabTestDTO labTest in patientLabTests)
            {
                PatientLabTest obj = unitOfWork.Repository <PatientLabTest>()
                                     .Queryable()
                                     .SingleOrDefault(e => e.PatientLabTestGuid == labTest.PatientLabTestIdentifier);

                if (obj == null)
                {
                    obj = new PatientLabTest
                    {
                        PatientLabTestGuid = labTest.PatientLabTestIdentifier,
                        Patient            = unitOfWork.Repository <Patient>().Queryable().SingleOrDefault(e => e.Id == labTest.PatientId),
                        //Id = labTest.PatientLabTestId,
                        TestDate   = labTest.TestDate,
                        TestResult = labTest.TestResult,
                        LabValue   = labTest.LabValue,
                        LabTest    = labTests.SingleOrDefault(e => e.Description == labTest.TestName),
                        TestUnit   = labTestUnits.SingleOrDefault(e => e.Id == labTest.TestUnit)
                    };

                    setCustomAttributes(labTest.customAttributes, obj);

                    unitOfWork.Repository <PatientLabTest>().Save(obj);
                    synchedPatientLabTest.Add(obj);
                }
                else
                {
                    obj.TestDate   = labTest.TestDate;
                    obj.TestResult = labTest.TestResult;
                    obj.LabValue   = labTest.LabValue;
                    obj.LabTest    = labTests.SingleOrDefault(e => e.Description == labTest.TestName);
                    obj.TestUnit   = labTestUnits.SingleOrDefault(e => e.Id == labTest.TestUnit);

                    setCustomAttributes(labTest.customAttributes, obj);
                    synchedPatientLabTest.Add(obj);
                    unitOfWork.Repository <PatientLabTest>().Update(obj);
                }
            }

            unitOfWork.Complete();

            var insertedObjs = synchedPatientLabTest.Select(p => new PatientLabTestDTO
            {
                PatientId                = p.Patient.Id,
                PatientLabTestId         = p.Id,
                PatientLabTestIdentifier = p.PatientLabTestGuid,
                TestName         = p.LabTest != null ? p.LabTest.Description : "",
                TestDate         = p.TestDate,
                TestResult       = p.TestResult,
                LabValue         = p.LabValue,
                TestUnit         = p.TestUnit != null ? p.TestUnit.Id : 0,
                customAttributes = getCustomAttributes(p)
            }).ToArray();

            return(Request.CreateResponse(HttpStatusCode.OK, insertedObjs));
        }
Exemplo n.º 8
0
        private void setCustomAttributes(IEnumerable <CustomAttributeDTO> customAttributes, PatientLabTest labTest)
        {
            if (customAttributes != null)
            {
                var labTestConditionExtended = (IExtendable)labTest;

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

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

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

                    case "String":
                    default:
                        labTestConditionExtended.SetAttributeValue(customAttribute.AttributeName, customAttribute.currentValue ?? string.Empty, User.Identity.Name);
                        break;
                    }
                }
            }
        }
Exemplo n.º 9
0
        public ActionResult AddPatientLabTest(PatientLabTestAddModel model)
        {
            ViewBag.MenuItem = CurrentMenuItem;

            var returnUrl = (TempData["returnUrl"] ?? string.Empty).ToString();

            ViewBag.ReturnUrl = returnUrl;

            var patient = unitOfWork.Repository <Patient>().Get(model.PatientId);

            if (patient == null)
            {
                ViewBag.Entity = "Patient";
                return(View("NotFound"));
            }

            if (model.TestDate < patient.DateOfBirth)
            {
                ModelState.AddModelError("TestDate", "Test Date should be after Date Of Birth");
            }

            if (ModelState.IsValid)
            {
                var labTest = unitOfWork.Repository <LabTest>().Get(model.LabTestId);

                if (labTest == null)
                {
                    ViewBag.Entity = "Lab Test";
                    return(View("NotFound"));
                }

                try
                {
                    var labTestUnit    = unitOfWork.Repository <LabTestUnit>().Queryable().SingleOrDefault(lu => lu.Id == model.LabTestUnitId);
                    var patientLabTest = new PatientLabTest
                    {
                        Patient        = patient,
                        LabTest        = labTest,
                        TestDate       = model.TestDate,
                        TestResult     = model.TestResult,
                        LabValue       = model.LabValue,
                        TestUnit       = labTestUnit,
                        ReferenceLower = model.ReferenceLower,
                        ReferenceUpper = model.ReferenceUpper
                    };

                    if (model.CustomAttributes != null)
                    {
                        var patientLabTestExtended = (IExtendable)patientLabTest;
                        var customAttributes       = unitOfWork.Repository <CustomAttributeConfiguration>().Queryable().Where(ca => ca.ExtendableTypeName == typeof(PatientLabTest).Name).ToList();

                        for (int i = 0; i < model.CustomAttributes.Length; i++)
                        {
                            var attributeConfig = GetFrameworkCustomAttributeConfig(customAttributes, model.CustomAttributes[i].Name);

                            // If there is not custom attribute configured with this name, ignore.
                            if (attributeConfig == null)
                            {
                                continue;
                            }

                            try
                            {
                                if (attributeConfig.IsRequired && string.IsNullOrWhiteSpace(model.CustomAttributes[i].Value))
                                {
                                    ModelState.AddModelError(string.Format("CustomAttributes[{0}].Value", i), string.Format("{0} is required.", model.CustomAttributes[i].Name));
                                    continue;
                                }

                                switch (model.CustomAttributes[i].Type)
                                {
                                case "Numeric":
                                    decimal number = 0M;
                                    if (decimal.TryParse(model.CustomAttributes[i].Value, out number))
                                    {
                                        patientLabTestExtended.ValidateAndSetAttributeValue(attributeConfig, number, User.Identity.Name);
                                    }
                                    break;

                                case "Selection":
                                    Int32 selection = 0;
                                    if (Int32.TryParse(model.CustomAttributes[i].Value, out selection))
                                    {
                                        patientLabTestExtended.ValidateAndSetAttributeValue(attributeConfig, selection, User.Identity.Name);
                                    }
                                    break;

                                case "DateTime":
                                    DateTime parsedDate = DateTime.MinValue;
                                    if (DateTime.TryParse(model.CustomAttributes[i].Value, out parsedDate))
                                    {
                                        patientLabTestExtended.ValidateAndSetAttributeValue(attributeConfig, parsedDate, User.Identity.Name);
                                    }
                                    break;

                                case "String":
                                default:
                                    patientLabTestExtended.ValidateAndSetAttributeValue(attributeConfig, model.CustomAttributes[i].Value ?? string.Empty, User.Identity.Name);
                                    break;
                                }
                            }
                            catch (CustomAttributeValidationException ve)
                            {
                                ModelState.AddModelError(string.Format("CustomAttributes[{0}].Value", i), ve.Message);
                                continue;
                            }
                        }
                    }

                    if (ModelState.IsValid)
                    {
                        unitOfWork.Repository <PatientLabTest>().Save(patientLabTest);
                        unitOfWork.Complete();

                        HttpCookie cookie = new HttpCookie("PopUpMessage");
                        cookie.Value = "Test and procedure added successfully";
                        Response.Cookies.Add(cookie);

                        return(Redirect("/Patient/PatientView.aspx?pid=" + patientLabTest.Patient.Id.ToString()));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", string.Format("Unable to add the Patient Lab Test: {0}", ex.Message));
                }
            }

            // Prepare custom attributes
            var cattributes = unitOfWork.Repository <CustomAttributeConfiguration>()
                              .Queryable()
                              .Where(ca => ca.ExtendableTypeName == typeof(PatientLabTest).Name)
                              .ToList();

            model.CustomAttributes = cattributes.Select(c => new CustomAttributeAddModel
            {
                Name            = c.AttributeKey,
                Detail          = c.AttributeDetail == null ? "" : "(" + c.AttributeDetail + ")",
                Type            = c.CustomAttributeType.ToString(),
                IsRequired      = c.IsRequired,
                StringMaxLength = c.StringMaxLength,
                NumericMinValue = c.NumericMinValue,
                NumericMaxValue = c.NumericMaxValue,
                PastDateOnly    = c.PastDateOnly,
                FutureDateOnly  = c.FutureDateOnly
            })
                                     .ToArray();

            var selectiondataRepository = unitOfWork.Repository <SelectionDataItem>();

            if (model.CustomAttributes != null)
            {
                foreach (var selectCustomAttribute in model.CustomAttributes.Where(c => c.Type == VPS.CustomAttributes.CustomAttributeType.Selection.ToString()))
                {
                    ViewData[selectCustomAttribute.Name] = selectiondataRepository
                                                           .Queryable()
                                                           .Where(sd => sd.AttributeKey == selectCustomAttribute.Name)
                                                           .Select(s => new SelectListItem
                    {
                        Value = s.SelectionKey,
                        Text  = s.Value
                    })
                                                           .ToArray();
                }
            }

            var labTests = new List <SelectListItem> {
                { new SelectListItem {
                      Value = "", Text = ""
                  } }
            };

            labTests.AddRange(unitOfWork.Repository <LabTest>()
                              .Queryable()
                              .Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.Description
            })
                              .OrderBy(c => c.Text)
                              .ToArray());
            ViewBag.LabTests = labTests;

            var labTestUnits = new List <SelectListItem> {
                { new SelectListItem {
                      Value = "", Text = ""
                  } }
            };

            labTestUnits.AddRange(unitOfWork.Repository <LabTestUnit>()
                                  .Queryable()
                                  .OrderBy(c => c.Description)
                                  .Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.Description
            })
                                  .ToArray());
            ViewBag.LabTestUnits = labTestUnits;

            var labResults = new List <SelectListItem> {
                { new SelectListItem {
                      Value = "", Text = ""
                  } }
            };

            labResults.AddRange(unitOfWork.Repository <LabResult>()
                                .Queryable()
                                .OrderBy(c => c.Description)
                                .Select(c => new SelectListItem
            {
                Value = c.Description,
                Text  = c.Description
            })
                                .ToArray());
            ViewBag.TestResults = labResults;

            TempData["returnUrl"] = returnUrl;

            return(View(model));
        }