private void CheckIfAtLeastHeightOrWeightArePresent(PatientMeasurement measurementExamination) { if (measurementExamination.Weight == null && measurementExamination.Height == null) { ModelState.AddModelError("Error", "One of the fields - weight or height must be present"); } }
protected override void ProcessSheet(ISheet currentSheet) { Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) => { List <PatientMeasurement> mrcs = _context.PatientMeasurements.Where(d => d.PatientId.Equals(patient.ID)).ToList(); var newWeightHeight = new PatientMeasurement() { PatientId = patient.ID }; patient = ReadRowCellsIntoPatientObject(patient, row, cellCount, newWeightHeight); var existingDates = mrcs.Select(pi => pi.DateTaken.Date).ToList(); bool dateDoesNotExist = existingDates.FindAll(d => d.Date == newWeightHeight.DateTaken.Date).ToList().Count == 0; if (newWeightHeight.DateTaken.Year > 1 && dateDoesNotExist) { if (patient.PatientMeasurements == null) { patient.PatientMeasurements = new List <PatientMeasurement>(); } patient.PatientMeasurements.Add(newWeightHeight); } Imported.Add(patient); }; InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction); }
public IActionResult Create(int patientId, PatientMeasurement measurementExamination) { var patient = _context.Patients.Where(p => p.ID == patientId).SingleOrDefault(); if (patient == null) { return(NotFound()); } measurementExamination.PatientId = patient.ID; CheckIfAtLeastHeightOrWeightArePresent(measurementExamination); if (ModelState.IsValid) { _context.Add(measurementExamination); _context.SaveChanges(); } else { Hashtable errors = ModelStateHelper.Errors(ModelState); return(StatusCode(422, Json(new { success = false, errors }))); } var patientMeasurments = _context.PatientMeasurements. Where(pm => pm.PatientId == patientId). OrderByDescending(pm => pm.DateTaken). ToList(); ViewBag.SelectedMeasurements = new List <int>(); return(PartialView(patientMeasurments)); }
private void BuildPatientMeasurement(Patient patient, DateTime?dateTaken, IDictionary record) { string csvHeight = (string)record[HEIGHT]; string csvWeight = (string)record[WEIGHT]; if (dateTaken == null) { return; } if (!string.IsNullOrEmpty(csvHeight) || !string.IsNullOrEmpty(csvHeight)) { decimal height, weight; decimal.TryParse(csvHeight, out height); decimal.TryParse(csvWeight, out weight); if (height != 0 || weight != 0) { var measurement = new PatientMeasurement(); measurement.Weight = weight; measurement.Height = height; measurement.PatientId = patient.ID; measurement.DateTaken = dateTaken.Value; var existing = _context.PatientMeasurements .Where(m => m.PatientId == patient.ID && measurement.DateTaken.Date == dateTaken.Value.Date) .FirstOrDefault(); if (existing != null) { return; } _context.PatientMeasurements.Add(measurement); } } }
private void SetPatientMeasurementProperty(PatientMeasurement measurement, PulmonaryFunctionTestResovler resolver, string propertyName, string propertyValue, IRow row, int cellCursor) { Type type = measurement.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); DateTime dateRowValue; try { if (propertyInfo != null && propertyInfo.PropertyType == typeof(DateTime)) { dateRowValue = row.GetCell(cellCursor).DateCellValue; propertyInfo.SetValue(measurement, dateRowValue); } else if (propertyInfo.PropertyType == typeof(int?) || propertyInfo.PropertyType == typeof(int)) { int propertyIntValue = Int32.Parse(propertyValue); propertyInfo.SetValue(measurement, propertyIntValue); } else if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) { propertyInfo. SetValue(measurement, Convert.ChangeType(propertyValue, typeof(DateTime)), null); } else if (propertyInfo.PropertyType == typeof(Decimal) || propertyInfo.PropertyType == typeof(Decimal?)) { decimal propertyDecValue = (decimal)Convert.ChangeType(propertyValue, typeof(Decimal)); var propertyDecMultValue = propertyDecValue * 100; if (propertyName == "Height") { resolver.Height = propertyDecValue; } propertyInfo.SetValue(measurement, propertyDecMultValue, null); } else { propertyInfo. SetValue(measurement, Convert.ChangeType(propertyValue, propertyInfo.PropertyType), null); } } catch (InvalidOperationException ex) { propertyInfo.SetValue(measurement, null); } }
private void ReadCell(Patient patient, IRow row, int cellIndex, PatientMeasurement newWeightHeight) { string header = _headers.ElementAt(cellIndex); string propertyValue = row.GetCell(cellIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(); string newObjectFields = (string)_dictonary[header]; if (newObjectFields != null) { string[] fields = newObjectFields.Split("|"); foreach (string field in fields) { var klassAndField = field.Split("."); var propertyName = klassAndField[1]; switch (klassAndField[0]) { case "PatientMeasurement": try { Type type = newWeightHeight.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); if (propertyName == "DateTaken") { DateTime qDate = DateTime.ParseExact(propertyValue, "dd-MMM-yyyy", CultureInfo.InvariantCulture); propertyInfo.SetValue(newWeightHeight, qDate); } else if (propertyName == "Height") { newWeightHeight.Height = Convert.ToDecimal(propertyValue); } else if (propertyName == "Weight") { newWeightHeight.Weight = Convert.ToDecimal(propertyValue); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(propertyValue); Console.WriteLine(klassAndField[1]); } break; } } } }
private Patient ReadCellsForPatient(Patient patient, IRow row, int cellCount) { var measurement = new PatientMeasurement(); measurement.PatientId = patient.ID; var pftResolver = new PulmonaryFunctionTestResovler(); for (int cellCursor = 0; cellCursor < cellCount; cellCursor++) { if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null) { ReadCell(patient, measurement, row, pftResolver, cellCursor); } } var pfts = pftResolver.ResolvePFTs(_context, patient); _context.PatientPulmonaryFunctionTests.AddRange(pfts); return(patient); }
private void BuildPatientMeasurement(Patient patient, DateTime dateTaken, IDictionary record) { string csvHeight = (string)record[HEIGHT]; string csvWeight = (string)record[WEIGHT]; if (!string.IsNullOrEmpty(csvHeight) || !string.IsNullOrEmpty(csvHeight)) { decimal height, weight; decimal.TryParse(csvHeight, out height); decimal.TryParse(csvWeight, out weight); if (height != 0 || weight != 0) { var measurement = new PatientMeasurement(); measurement.Weight = weight; measurement.Height = height; measurement.PatientId = patient.ID; measurement.DateTaken = dateTaken; _context.PatientMeasurements.Add(measurement); } } }
private void ReadCell(Patient patient, PatientPulmonaryFunctionTest pft, PatientHaematology hmt, IRow row, int cellCursor) { string header = _headers.ElementAt(cellCursor); string newObjectFields = (string)_dictonary[header]; if (string.IsNullOrEmpty(newObjectFields)) { return; } string propertyValue = row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(); if (!string.IsNullOrEmpty(propertyValue) && newObjectFields != null) { var klassAndField = newObjectFields.Split("."); string propertyName = klassAndField[1]; switch (klassAndField[0]) { case "PatientPulmonaryFunctionTest": var test = _context.PulmonaryFunctionTests.Where(p => p.ShortName.Equals(header)) .FirstOrDefault(); pft = new PatientPulmonaryFunctionTest(); string property = "ResultValue"; var value = row.GetCell(cellCursor).NumericCellValue; pft.GetType().GetProperty(property).SetValue(pft, (decimal)value); pft.PulmonaryFunctionTestId = test.ID; pft.PatientId = patient.ID; property = "PredictedValue"; var predHeaderIndex = _headers.FindIndex(h => h.Contains(header + "Predicted")); var predHeaderValue = row.GetCell(predHeaderIndex)?.NumericCellValue; if (predHeaderValue != null) { pft.GetType().GetProperty(property).SetValue(pft, (decimal)predHeaderValue); } var dateHeaderIndex = _headers.FindIndex(h => h.Contains("DateOfTest")); var dateCellValue = row.GetCell(dateHeaderIndex).DateCellValue; pft.GetType().GetProperty("DateTaken").SetValue(pft, dateCellValue); if (patient.PatientPulmonaryFunctionTests == null) { patient.PatientPulmonaryFunctionTests = new List <PatientPulmonaryFunctionTest>(); } patient.PatientPulmonaryFunctionTests.Add(pft); break; case "PatientMeasurement": var meas = new PatientMeasurement(); var dateIndex = _headers.FindIndex(h => h.Contains("DateOfTest")); var dateValue = row.GetCell(dateIndex).DateCellValue; meas.DateTaken = dateValue; var heightIdx = _headers.FindIndex(h => h.Contains("Height")); var heightValue = row.GetCell(heightIdx)?.NumericCellValue; var weightIdx = _headers.FindIndex(h => h.Contains("Weight")); var weightValue = row.GetCell(weightIdx)?.NumericCellValue; if (heightValue != null) { meas.Height = Convert.ToDecimal(heightValue); } if (weightValue != null) { meas.Weight = Convert.ToDecimal(weightValue); } if (patient.PatientMeasurements == null) { patient.PatientMeasurements = new List <PatientMeasurement>(); } patient.PatientMeasurements.Add(meas); break; case "PatientHaematology": if (header.Equals("HaematologyDate")) { propertyName = "DateTaken"; var hemValue = row.GetCell(cellCursor).DateCellValue; hmt.GetType().GetProperty(propertyName).SetValue(hmt, hemValue); hmt.PatientId = patient.ID; if (patient.PatientHaematologies == null) { patient.PatientHaematologies = new List <PatientHaematology>(); } patient.PatientHaematologies.Add(hmt); var hbInd = _headers.FindIndex(h => h.Contains("Hb")); var hbValue = row.GetCell(hbInd)?.NumericCellValue; if (hbValue != null) { hmt.Hb = hbValue.Value; } var wbcInd = _headers.FindIndex(h => h.Contains("WBC")); if (wbcInd != -1) { var wbcValue = row.GetCell(wbcInd)?.NumericCellValue; if (wbcValue != null) { hmt.WBC = wbcValue.Value; } } var albInd = _headers.FindIndex(h => h.Contains("Albumin")); var albVaue = row.GetCell(albInd)?.NumericCellValue; if (albVaue != null) { hmt.Albumin = albVaue.Value; } } break; } } }
private Patient ReadRowCellsIntoPatientObject(Patient patient, IRow row, int cellCount, PatientMeasurement newWeightHeight) { for (int cellCursor = row.FirstCellNum; cellCursor < cellCount; cellCursor++) { if (row.GetCell(cellCursor) != null) { ReadCell(patient, row, cellCursor, newWeightHeight); } } return(patient); }
private void ReadCell(Patient patient, PatientMeasurement measurement, IRow row, PulmonaryFunctionTestResovler pftResolver, int cellCursor) { string header = _headers.ElementAt(cellCursor); string newObjectFields = (string)_dictonary[header]; string propertyValue = row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(); if (!string.IsNullOrEmpty(propertyValue) && newObjectFields != null) { var klassAndField = newObjectFields.Split("."); switch (klassAndField[0]) { case "Patient": string propertyName = klassAndField[1]; if (propertyValue.Length > 7 && propertyName == "NhsNumber") { propertyValue = propertyValue.Remove(0, 7); } SetPatientProperty(patient, propertyName, row, cellCursor, propertyValue); break; case "PatientMeasurement": propertyName = klassAndField[1]; SetPatientMeasurementProperty(measurement, pftResolver, propertyName, propertyValue, row, cellCursor); break; case "Calculator": propertyName = klassAndField[1]; if (propertyName == "Age") { pftResolver.Age = propertyValue; } else if (propertyName == "DLCOValue") { pftResolver.DLCOValue = propertyValue; } else if (propertyName == "FEV1Value") { pftResolver.FEV1Value = propertyValue; } else if (propertyName == "KCOValue") { pftResolver.KCOValue = propertyValue; } else if (propertyName == "FVCValue") { pftResolver.FVCValue = propertyValue; } else if (propertyName == "VAValue") { pftResolver.VAValue = propertyValue; } else if (propertyName == "DateTaken") { pftResolver.DateTaken = propertyValue; measurement.DateTaken = (DateTime)Convert.ChangeType(propertyValue, typeof(DateTime)); } break; } } }