public PatientSTGQuestionnaireResolver(AspergillosisContext context) { _context = context; _questionnaires = new List <PatientSTGQuestionnaire>(); _fields = new Dictionary <string, string>(); _questionnaire = new PatientSTGQuestionnaire(); }
public void SetQuestionnaireProperty(string property, string propertyValue) { if (_questionnaire == null) { _questionnaire = new PatientSTGQuestionnaire(); } Type type = new PatientSTGQuestionnaire().GetType(); PropertyInfo propertyInfo = type.GetProperty(property); DateTime dateRowValue; if (propertyInfo != null && propertyInfo.PropertyType == typeof(DateTime)) { try { DateTime.TryParse(propertyValue, CultureInfo.CurrentUICulture, DateTimeStyles.None, out dateRowValue); propertyInfo.SetValue(_questionnaire, dateRowValue); } catch (FormatException ex) { } } else if ((propertyInfo != null) && (propertyInfo.PropertyType == typeof(decimal))) { propertyInfo.SetValue(_questionnaire, decimal.Parse(propertyValue)); } }
protected override void ProcessSheet(ISheet currentSheet) { Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) => { List <PatientSTGQuestionnaire> sgrqs = _context.PatientSTGQuestionnaires.Where(d => d.PatientId.Equals(patient.ID)).ToList(); var newSgrq = new PatientSTGQuestionnaire() { PatientId = patient.ID }; patient = ReadRowCellsIntoPatientObject(patient, row, cellCount, newSgrq); var existingDates = sgrqs.Select(pi => pi.DateTaken.Date).ToList(); bool dateDoesNotExist = existingDates.FindAll(d => d.Date == newSgrq.DateTaken.Date).ToList().Count == 0; if (newSgrq.DateTaken.Year > 1 && dateDoesNotExist) { if (patient.STGQuestionnaires == null) { patient.STGQuestionnaires = new List <PatientSTGQuestionnaire>(); } patient.STGQuestionnaires.Add(newSgrq); } Imported.Add(patient); }; InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction); }
public IActionResult Create(int patientId, PatientSTGQuestionnaire sgrq) { var patient = _context.Patients.Where(p => p.ID == patientId).SingleOrDefault(); if (patient == null) { return(NotFound()); } sgrq.PatientId = patient.ID; if (ModelState.IsValid) { _context.Add(sgrq); _context.SaveChanges(); } else { Hashtable errors = ModelStateHelper.Errors(ModelState); return(StatusCode(422, Json(new { success = false, errors }))); } var questionnaires = _context.PatientSTGQuestionnaires. Where(pm => pm.PatientId == patientId). OrderByDescending(pm => pm.DateTaken). ToList(); ViewBag.SelectedSGRQ = new List <int>(); return(PartialView(questionnaires)); }
private void ReadCell(Patient patient, IRow row, int cellIndex, PatientSTGQuestionnaire newSGRQ) { 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 "PatientSTGQuestionnaire": try { Type type = newSGRQ.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); if (propertyName == "DateTaken") { DateTime qDate = DateTime.ParseExact(propertyValue, "dd-MMM-yyyy", CultureInfo.InvariantCulture); propertyInfo.SetValue(newSGRQ, qDate); } else if (propertyName == "SymptomScore") { newSGRQ.SymptomScore = Convert.ToDecimal(propertyValue); } else if (propertyName == "ImpactScore") { newSGRQ.ImpactScore = Convert.ToDecimal(propertyValue); } else if (propertyName == "ActivityScore") { newSGRQ.ActivityScore = Convert.ToDecimal(propertyValue); } else if (propertyName == "TotalScore") { newSGRQ.TotalScore = Convert.ToDecimal(propertyValue); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(propertyValue); Console.WriteLine(klassAndField[1]); } break; } } } }
public override Task ProcessInScope(IServiceProvider serviceProvider) { using (IServiceScope scope = _serviceProvider.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <AspergillosisContext>(); var sgrqContext = scope.ServiceProvider.GetRequiredService <SGRQContext>(); var lastImportedSGRQ = context.PatientSTGQuestionnaires.OrderByDescending(q => q.DateTaken).FirstOrDefault(); var sqrqs = sgrqContext.QuestionnaireResults .Include(q => q.Questionnaire) .ThenInclude(q => q.Patient) .Where(q => q.Questionnaire.ID > Int32.Parse(lastImportedSGRQ.OriginalImportedId)); foreach (var externalSGRQ in sqrqs) { var rm2Number = externalSGRQ.Questionnaire.Patient.Identifier.ToString().Replace("CPA", ""); var patient = context.Patients .Include(p => p.STGQuestionnaires) .Where(p => p.RM2Number.Equals(rm2Number)).FirstOrDefault(); if (patient == null) { continue; } var existingDates = patient.STGQuestionnaires.Select(pi => pi.DateTaken.Date).ToList(); bool dateDoesNotExist = existingDates.FindAll(d => d.Date == externalSGRQ.Questionnaire.DateOfEntry.Date).ToList().Count == 0; if (dateDoesNotExist) { var sgrq = new PatientSTGQuestionnaire(); sgrq.PatientId = patient.ID; sgrq.SymptomScore = (decimal)externalSGRQ.SymptomScore; sgrq.ImpactScore = (decimal)externalSGRQ.ImpactScore; sgrq.ActivityScore = (decimal)externalSGRQ.ActivityScore; sgrq.TotalScore = (decimal)externalSGRQ.TotalScore; sgrq.DateTaken = externalSGRQ.Questionnaire.DateOfEntry; sgrq.OriginalImportedId = externalSGRQ.Questionnaire.ID.ToString(); context.PatientSTGQuestionnaires.Add(sgrq); } } _logger.LogInformation("Import Finished at: " + DateTime.Now.ToString()); context.SaveChanges(); return(Task.CompletedTask); } }
public async Task <IActionResult> SGRQ() { var sqrqs = _sqrqContext.QuestionnaireResults .Include(q => q.Questionnaire) .ThenInclude(q => q.Patient) .Where(q => q.Questionnaire.DateOfEntry > SGRQ_START_IMPORT_DATE); foreach (var externalSGRQ in sqrqs) { var rm2Number = externalSGRQ.Questionnaire.Patient.Identifier.ToString().Replace("CPA", ""); var patient = _context.Patients .Include(p => p.STGQuestionnaires) .Where(p => p.RM2Number.Equals(rm2Number)).FirstOrDefault(); if (patient == null) { continue; } var existingDates = patient.STGQuestionnaires.Select(pi => pi.DateTaken.Date).ToList(); bool dateDoesNotExist = existingDates.FindAll(d => d.Date == externalSGRQ.Questionnaire.DateOfEntry.Date).ToList().Count == 0; if (dateDoesNotExist) { var sgrq = new PatientSTGQuestionnaire(); sgrq.PatientId = patient.ID; sgrq.SymptomScore = (decimal)externalSGRQ.SymptomScore; sgrq.ImpactScore = (decimal)externalSGRQ.ImpactScore; sgrq.ActivityScore = (decimal)externalSGRQ.ActivityScore; sgrq.TotalScore = (decimal)externalSGRQ.TotalScore; sgrq.DateTaken = externalSGRQ.Questionnaire.DateOfEntry; sgrq.OriginalImportedId = externalSGRQ.Questionnaire.ID.ToString(); _context.PatientSTGQuestionnaires.Add(sgrq); } } await _context.SaveChangesAsync(); return(Ok()); }
private PatientSTGQuestionnaire BuildPatientSTGQuestionnaire(Patient patient, IDictionary record) { var sgrquestionare = new PatientSTGQuestionnaire(); sgrquestionare.PatientId = patient.ID; sgrquestionare.SymptomScore = decimal.Parse((string)record[SYMPTOM_SCORE]); sgrquestionare.ImpactScore = decimal.Parse((string)record[IMPACT_SCORE]); sgrquestionare.ActivityScore = decimal.Parse((string)record[ACTIVITY_SCORE]); sgrquestionare.TotalScore = decimal.Parse((string)record[TOTAL_SCORE]); string dateTaken = (string)record[DATE_TAKEN]; try { sgrquestionare.DateTaken = DateTime.ParseExact(dateTaken, "yyyy-MM-dd", CultureInfo.InvariantCulture); } catch (FormatException) { try { sgrquestionare.DateTaken = Convert.ToDateTime(dateTaken); } catch (FormatException) { Console.WriteLine(dateTaken); } } _context.Entry(patient).Collection(p => p.STGQuestionnaires).Load(); var dates = patient.STGQuestionnaires.Select(sgrq => sgrq.DateTaken.Date).ToList(); var existingDbDates = dates.FindAll(d => d.Date == sgrquestionare.DateTaken.Date); if (existingDbDates.Count > 0) { return(sgrquestionare); } if (sgrquestionare.IsValid()) { Imported.Add(sgrquestionare); } return(sgrquestionare); }
private Patient ReadRowCellsIntoPatientObject(Patient patient, IRow row, int cellCount, PatientSTGQuestionnaire newSgrq) { for (int cellCursor = row.FirstCellNum; cellCursor < cellCount; cellCursor++) { if (row.GetCell(cellCursor) != null) { ReadCell(patient, row, cellCursor, newSgrq); } } return(patient); }