public async Task <IActionResult> UpdatePersonalHistory(PatientPersonalHistoryVM vm) { if (vm.PatientId < 1) { return(Json(false)); } var result = await _patientService.UpdatePersonalHistory(vm); return(Json(result ? "success" : "fail")); }
public async Task <bool> UpdatePersonalHistory(PatientPersonalHistoryVM vm) { if (vm.PatientId < 1) { return(false); } ClinicalHistory ch = await _pasContext.ClinicalHistory .Include(ch => ch.User) .FirstAsync(ch => ch.UserId == vm.PatientId); ch.User.Age = DateTime.Today.Year - vm.DateOfBirth.Year; ch.User.DateOfBirth = vm.DateOfBirth; ch.BloodGroupId = (int)vm.BloodGroup; ch.Smoker = vm.SmokePerDay; ch.Drinker = (short)vm.Drinker; ch.Excercise = vm.Excercise; ch.Sports = (short)vm.Sports; ch.PersonalHistoryLastUpdated = DateTime.Now; _pasContext.ClinicalHistory.Update(ch); await _pasContext.SaveChangesAsync(); //## Now Update the Cache- if the page is reloaded- show the latest info string redisKey = $"{CacheKey.ClinicalDetails}_{vm.PatientId}"; var cachedResult = _cacheService.GetCacheValue <ClinicalHistoryVM>(redisKey); cachedResult.Age = ch.User.Age; cachedResult.DateOfBirth = vm.DateOfBirth; cachedResult.BloodGroupType = vm.BloodGroup; cachedResult.Smoker = vm.SmokePerDay; cachedResult.Drinker = vm.Drinker.ToString(); cachedResult.Excercise = vm.Excercise; cachedResult.Sports = vm.Sports; ch.PersonalHistoryLastUpdated = DateTime.Now; _cacheService.SetCacheValue(redisKey, cachedResult); //TODO: Log this Event- Patient updated Personal History return(true); }