/// <summary> /// This is the Main Point of Entry- in the PAS- WebApp /// </summary> /// <returns></returns> public async Task <IActionResult> Index() { //var userId = _userManager.GetUserId(HttpContext.User); //var userEmail = _userManager.GetUserName(HttpContext.User); //var u1 = HttpContext.User.Claims.ToList(); //var userClaim = HttpContext.User.FindFirst(ClaimTypes.Email).Value; AppUserDetailsVM currentUser = new AppUserDetailsVM(); var userEmail = GetLoggedInEmail(); if (userEmail != null) { //## if the user is Logged in- check- do we have a value in Cache for this User? currentUser = await _appAuthorisationService.GetActiveUserFromCache(userEmail); if (currentUser is null) { //## First time Logging in this Session (1 hour)- fetch the record from DataBase currentUser = _appUserService.FindByEmail(userEmail); //## Update the Redis Cache- for this new login _appAuthorisationService.SetActiveUserInCache(currentUser); } } //## Set Profile path of this User- So, that user can quickly go to the respective Profile (Doctor/Patient) //var claimList = ClaimsPrincipal.Current?.Identities.First().Claims.ToList(); return(View(currentUser)); }
private bool UpdateActiveUserRoleIn_DB(AppUserDetailsVM user) { ActiveRole activeRole = _context.ActiveRoles.FirstOrDefault(ar => ar.UserId == user.Id); if (activeRole is null) { //## User First time Switched Role (as a Doctor) activeRole = new ActiveRole() { OrganisationId = (user.ApplicationRole == ApplicationRole.Patient ? 0 : user.CurrentRole.OrganisationId), UserId = user.Id, RoleId = (int)user.ApplicationRole }; _context.ActiveRoles.Add(activeRole); } else { activeRole.OrganisationId = user.CurrentRole.OrganisationId; activeRole.RoleId = (int)user.ApplicationRole; _context.ActiveRoles.Update(activeRole); } _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> SearchPatient(PatientSearchVM search) { AppUserDetailsVM currentUser = await GetCurrentUser(); //## search the patient using the Search VM search.FirstName = "car"; var matchingPatients = await _patientService.SearchPatient(search); //## Doctor will Search Patients and Create a new Prescription PrescriptionCreateInitialVM vm = new PrescriptionCreateInitialVM() { DoctorId = currentUser.Id, HospitalId = currentUser.CurrentRole.OrganisationId, //PatientId = 1, SearchVM = search, PatientsList = matchingPatients, PatientsListTitle = $"Matching records", HospitalDetails = null, DoctorDetails = null }; return(View(vm)); }
/// <summary> /// This will Mapp all basic User Details- except any Role Details. /// Wait fo the User to go the page to select a role /// </summary> /// <param name="appUser"></param> /// <returns></returns> private AppUserDetailsVM MapToViewModel(User appUser) { AppUserDetailsVM mappedVM = new AppUserDetailsVM() { Id = appUser.Id, Title = ((Title)appUser.Title).ToString(), Name = $"{appUser.FirstName} {appUser.LastName}", BanglaName = appUser.BanglaName ?? "", Age = appUser.Age, DateOfBirth = appUser.DateOfBirth?.ToShortDateString(), Gender = (Gender)appUser.Gender, Mobile = appUser.Mobile, Email = appUser.Email, ShortId = appUser.ShortId ?? "", AddressBook = MapToAddressBookVM(appUser.AddressBooks), HasMultipleRoles = appUser.UserOrganisationRoles.Any() }; //## Keep the Mobile and Email in the Address book if (appUser.AddressBooks.Count >= 1) { mappedVM.AddressBook.Mobile = appUser.Mobile; mappedVM.AddressBook.Email = appUser.Email; } return(mappedVM); }
public async Task <IActionResult> SearchPatient() { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } //## Get Current Doctor's - Regular Patients var regularPatients = await _patientService.GetRegularPatientList(currentUser.Id); //## Doctor will Search Patients and Create a new Prescription PrescriptionCreateInitialVM vm = new PrescriptionCreateInitialVM() { DoctorId = currentUser.Id, HospitalId = currentUser.CurrentRole.OrganisationId, PatientId = 1, PatientsList = regularPatients, PatientsListTitle = $"Recent visitors", HospitalDetails = null, DoctorDetails = null }; SetDoctorsProfileValues(currentUser); return(View(vm)); }
public async Task <IActionResult> ViewPatient(int id) { if (id < 1) { return(RedirectToAction("Index")); } AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } AppUserDetailsVM patientDetails = await _appUserService.Find(id, true); ClinicalHistoryVM patientClinicalInfo = await _patientService.GetClinicalDetails(id); DoctorViewPatientWrapperVM vm = new DoctorViewPatientWrapperVM() { Doctor = currentUser, PatientProfileWrapper = new PatientProfileWrapperVM() { Patient = patientDetails, ClinicalInfo = patientClinicalInfo, } }; SetDoctorsProfileValues(currentUser); return(View(vm)); }
public async Task <HospitalDetailsVM> Get_DoctorChamber(string email) { AppUserDetailsVM currentUser = _cacheService.GetCacheValue <AppUserDetailsVM>(email); string redisKey = $"{CacheKey.DoctorChamber}_{currentUser.OrganisationId}"; var chamber = _cacheService.GetCacheValue <HospitalDetailsVM>(redisKey); if (chamber is null) { var organisation = await _context.Organisation .FindAsync(currentUser.CurrentRole.OrganisationId); chamber = new HospitalDetailsVM() { Id = organisation.Id, Name = organisation.Name, HeaderBangla = organisation.HeaderBangla, HeaderEnglish = organisation.HeaderEnglish, Address = organisation.Address, LogoImageUrl = organisation.LogoImageFile }; //## Now save it in the Redis Cache- for later use _cacheService.SetCacheValue(redisKey, chamber); } return(chamber); }
public async Task <AppUserDetailsVM> FindByMobile(string mobile) { var appUser = await _context.User.FirstOrDefaultAsync(p => p.Mobile == mobile); AppUserDetailsVM result = MapToViewModel(appUser); return(result); }
public AppUserDetailsVM FindByShortId(string shortId) { var appUser = _context.User.First(p => p.ShortId.Equals(shortId)); AppUserDetailsVM result = MapToViewModel(appUser); return(result); }
public async Task <IActionResult> FinishAndPreview(PrescriptionConfirmSaveVM vm) { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } return(PartialView("Areas/Doctor/Views/Prescription/_FinishAndPreview.cshtml")); }
public async Task <IActionResult> SwitchRoleToPatient(UserSwitchRoleUpdate vm) { //## Get the existing UserDetails from Redis Cache- AppUserDetailsVM cachedUser = await GetCurrentUser(); //## This is a Patient- update only ApplicationRole cachedUser.ApplicationRole = ApplicationRole.Patient; _appAuthorisationService.SetActiveUserInCache(cachedUser); return(RedirectToAction("Index", "Home", new { Area = "Patient" })); }
/// <summary>These details will be used to show Patient's Details in the Layout- Left Column</summary> /// <param name="currentUser"></param> protected void SetPatientProfileValues(AppUserDetailsVM currentUser) { CurrentUserVM vm = new CurrentUserVM() { DisplayName = currentUser.Name, LocalArea = currentUser.AddressBook.LocalArea, City = currentUser.AddressBook.City, ImageUrl = currentUser.ImageUrl, }; ViewBag.UserDetails = vm; }
public async Task <IActionResult> Create(int id) { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } if (id < 1) { return(RedirectToAction("SearchPatient", "Home", new { Area = "Doctor" })); } //## we get the PrescriptionId via Post call. use that to get Prescription info- Doctor, Hospital, Patient //## Doctor has already initiated a "New Prescription" from "Doctor/Home/StartNewPrescription()"- which is their Home page var prescription = await _prescriptionService.Find(id); if (prescription is null || prescription.Status != (int)PrescriptionStatus.Draft) { return(RedirectToAction("SearchPatient", "Home", new { Area = "Doctor" })); } var newPrescriptionId = prescription.Id; var chamber = await _appUserService.Get_DoctorChamber(currentUser.Email); AppUserDetailsVM patientDetails = await _appUserService.Find(prescription.PatientId, includeAddressBook : true); ClinicalHistoryVM clinicialInfo = await _patientService.GetClinicalDetails(patientDetails.Id); //var chiefComplaints = await _patientService.GetPatientChiefComplaints(patientDetails.Id); //## PrescriptionCreateVM- will have all necessary info to make a Prescription- //## When the Doc needs to see preview of Prescription before Print/Save var vm = new PrescriptionCreateVM() { Id = newPrescriptionId, Doctor = currentUser, //## Doctor details is at- AppUserDetailsVM.DoctorDetailsVM() ChamberDetails = chamber, PatientDetails = patientDetails, //AllergyList = clinicialInfo.AllergyList, ClinicialInfo = clinicialInfo, //## AllergyList is withi ClinicalInfo }; //## Re-factor UserDetails- 'Doctor' type values SetDoctorsProfileValues(currentUser); return(View(vm)); }
public async Task <IActionResult> GetPrescription_HTML(int id) { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } var result = await _prescriptionService.GetPrescription_HTML(id); return(Json(result)); }
public AppUserDetailsVM FindByEmail(string email) { var appUser = _context.User .Include(p => p.UserOrganisationRoles) //.ThenInclude(p=> p.Organisation) .Include(p => p.AddressBooks) .AsNoTracking() .First(p => p.Email == email); AppUserDetailsVM result = MapToViewModel(appUser); return(result); }
public async Task <ActionResult> Insert_DrugBrandForDiagnosis(DrugBrandsForDiagnosisVM vm) { if (vm is null) { return(Json("error")); } AppUserDetailsVM currentUser = await GetCurrentUser(); var result = await _drugService.Insert_DrugBrandForDiagnosis(vm, currentUser.Id); return(Json(result)); }
public async Task <IActionResult> Create_Prescription_HTML(int id, string contents) { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } var result = await _prescriptionService.Create_Prescription_HTML(id, contents); return(Json(result ? "success" : "fail")); }
public async Task <ActionResult> Insert_BrandDoseTemplate(BrandDoseTemplateCreateVM vm) { //## This will create a Template for a Specific Drug Brand. ie: 'Ibuprofen 200mg Tablet 4 Times a Day for 7 days' if (vm is null || vm.StrengthTypeText is null || vm.ModeOfDeliveryId == 0 || vm.DrugBrandId == 0 || vm.Duration == 0) { return(Json("error")); } AppUserDetailsVM currentUser = await GetCurrentUser(); var result = await _drugService.Insert_BrandDoseTemplate(vm, currentUser.Id); return(Json(result)); }
/// <summary>These details will be used to show Doctor's Details in the Layout- Left Column</summary> /// <param name="currentUser"></param> protected void SetDoctorsProfileValues(AppUserDetailsVM currentUser) { CurrentUserVM vm = new CurrentUserVM() { DisplayName = "Dr. " + currentUser.Name, Degrees = currentUser.DoctorDetails.DoctorDegrees(), Chamber = currentUser.CurrentRole.OrganisationName, ImageUrl = "user-3.png" }; //currentUser.AddressBook.LocalArea = currentUser.CurrentRole.OrganisationName; //## Current Selected Chamber ViewBag.UserDetails = vm; }
public bool SetActiveUserInCache(AppUserDetailsVM user) { if (user != null) { bool isUpdated = UpdateActiveUserRoleIn_DB(user); if (isUpdated) { _cacheService.SetCacheValue(user.Email, user); } return(isUpdated); } return(false); }
public async Task <IActionResult> Index() { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } var availableRoles = await _appAuthorisationService.GetUserRolesFromCache(currentUser.Id); currentUser.RolesList = availableRoles; //## Re-factor UserDetails- 'Doctor' type values SetDoctorsProfileValues(currentUser); return(View(currentUser)); }
public async Task <IActionResult> Index() { //## Somethig like Patient Dashboard //var _userEmail = _userManager.GetUserName(HttpContext.User); AppUserDetailsVM currentUser = await GetCurrentUser(); ClinicalHistoryVM clinicalInfo = await _patientService.GetClinicalDetails(currentUser.Id); PatientProfileWrapperVM vm = new PatientProfileWrapperVM() { Patient = currentUser, //## This is Patient Profile... Patient/Home/Index Page ClinicalInfo = clinicalInfo, LabResults = null, //## Not required in Profile Page PrescriptionList = null, //## Not required in Profile Page }; //## Re-factor UserDetails- 'Patient' type values SetPatientProfileValues(currentUser); return(View(vm)); }
public async Task <IActionResult> SwitchRole(UserSwitchRoleUpdate vm) { //## Get the existing UserDetails from Redis Cache- AppUserDetailsVM cachedUser = await GetCurrentUser(); //## Check this is not a hacker trying to allocate Roles that doesn't exist var selectedOrgRole = await _userOrgRoleService.Find(cachedUser.Id, vm.UserOrganisationRoleId); if (selectedOrgRole is null) { //## Someone tempered the data- hence no Role found for this User in the UserOrgTable return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } //## So- now we know what the User has selected to be cachedUser.ApplicationRole = (ApplicationRole)selectedOrgRole.RoleId; //cachedUser.HasAdditionalRoles = true; //## Save it in the Redis Cache- with the new UserOrgRole value cachedUser.CurrentRole = new UserRoleVM() { OrganisationId = selectedOrgRole.OrganisationId, OrganisationName = selectedOrgRole.Organisation.Name, RoleId = selectedOrgRole.RoleId, RoleName = selectedOrgRole.Role.Name }; //## Save it back in redis _appAuthorisationService.SetActiveUserInCache(cachedUser); //await _applicationUserClaimsPrincipalFactory.CreateAsync(currentUser); var areaName = ((ApplicationRole)selectedOrgRole.RoleId).ToString(); return(RedirectToAction("Index", "Home", new { Area = areaName })); }
public async Task <IActionResult> Index() { AppUserDetailsVM currentUser = await GetCurrentUser(); if (currentUser.Not_A_Doctor()) { return(RedirectToAction("AccessDenied", "Account", new { Area = "Identity" })); } //## This is the Dashboard Page of a Doctor. Can view- Chart, Profile, Search Patients and Create a new Prescription PrescriptionCreateInitialVM vm = new PrescriptionCreateInitialVM() { DoctorId = currentUser.Id, HospitalId = currentUser.CurrentRole.OrganisationId, PatientId = 1, //HospitalDetails = null, //DoctorDetails = null }; SetDoctorsProfileValues(currentUser); return(View(vm)); }
/// <summary>This will return a AppUserDetailsVM Object- which doesn't have any child entity</summary> /// <returns>AppUser Object</returns> public async Task <AppUserDetailsVM> GetActiveUserFromCache(string userEmail) { //var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; //var userEmail = Context.HttpContext.User.FindFirst(ClaimTypes.Email).Value; //if (userEmail is null) return null; //## Unauthenticated User AppUserDetailsVM currentUser = _cacheService.GetCacheValue <AppUserDetailsVM>(userEmail); IEnumerable <UserRoleVM> userRoles = null; if (currentUser is null) { currentUser = _appUserService.FindByEmail(userEmail); //## No CurrentUser info in RedisCache- Read from Table //## If this is a Doctor/Director- with additional Roles- then find out what was their Last selected Role from the DB if (currentUser.HasMultipleRoles) { //## Cache is Empty- Does the user have any 'ActiveRole' Table? var activeRole = _context.ActiveRoles .AsNoTracking() .Include(ar => ar.Organisation) .FirstOrDefault(ar => ar.UserId == currentUser.Id); //## Check- for any previous 'Active Role' in the DB Table? if (activeRole is null) { //## ActiveRole Table is empty. Means- this Doctor never SwitchedRole before- so we can assume this User as a Patient- for the first time. //## Let the User- to go to SwitchRole page and from their Insert a Record in the ActiveRole table- then we can use that info currentUser.ApplicationRole = ApplicationRole.Patient; } else { //## ActiveRole present in the DB- but not in the Cache.. so- Update the values from DB int to RedisCache currentUser.CurrentRole = new UserRoleVM() { RoleId = activeRole.RoleId, OrganisationId = activeRole.OrganisationId, OrganisationName = activeRole.Organisation.Name, OrganisationAddress = activeRole.Organisation.Address //+ ", " + activeRole.Organisation.Address }; currentUser.ApplicationRole = (ApplicationRole)activeRole.RoleId; currentUser.OrganisationId = activeRole.OrganisationId; } //## Set the Roles in the Cache SetUserRolesInCache(userRoles, currentUser.Id); } else { //## This is a Patient Only currentUser.ApplicationRole = ApplicationRole.Patient; } //## Current User seems to have multiple roles- is this User a Doctor, as well? Then read the Degrees and Specialities of this Doctor if (currentUser.Is_A_Doctor() && currentUser.DoctorDetails is null) { var specialities = await _appUserService.Get_DoctorSpeciality(currentUser.Id); var doctorDegreeList = await _appUserService.Get_DoctorDegrees(currentUser.Id); var doctorProfile = await _context.DoctorProfile.FindAsync(currentUser.Id); DoctorDetailsVM doctor = new DoctorDetailsVM() { Id = currentUser.Id, Name = currentUser.Name, BanglaName = currentUser.BanglaName, SpecialityList = specialities, DoctorDegreeList = doctorDegreeList, RegistrationNumber = doctorProfile.RegistrationNumber, HeaderEnglish = doctorProfile.HeaderEnglish, HeaderBangla = doctorProfile.HeaderBangla }; currentUser.DoctorDetails = doctor; } //## Now set the entire CurrentUserVM in the Cache- so we will have everything we need SetActiveUserInCache(currentUser); } //if (cachedUser is null) return null; //## First Time Logged in- no cache value return(currentUser); }
private void SetUserProfileValues(AppUserDetailsVM currentUser) { currentUser.ImageUrl = "user-3.png"; ViewBag.UserDetails = currentUser; }