public IActionResult RegisterPatient(string id, string pracId)
        {
            List <MonitorModel> monitorList;
            string cachePatientKey = "Patients" + pracId;
            string cacheMonitorKey = "Monitor" + pracId;
            var    patientList     = _cache.GetObject <Dictionary <string, PatientModel> >(cachePatientKey);
            var    pat             = patientList[id];
            //Create new monitor
            var monitor = new MonitorModel("Cholesterol" + id);

            monitor.Update(pat);
            //Check existing object in cache
            if (_cache.ExistObject <List <PatientViewModel> >(cacheMonitorKey) == true)
            {
                monitorList = _cache.GetObject <List <MonitorModel> >(cacheMonitorKey);

                bool notExist = true;
                for (int i = 0; i < monitorList.Count; i++)
                {
                    if (monitorList[i].Id == monitor.Id)
                    {
                        monitorList[i] = monitor;
                        notExist       = false;
                    }
                }
                if (notExist)
                {
                    monitorList.Add(monitor);
                }
            }
            else
            {
                monitorList = new List <MonitorModel>
                {
                    monitor
                };
            }
            _cache.SetObject(cacheMonitorKey, monitorList);
            _cache.SetObject(cachePatientKey, patientList);
            return(RedirectToAction("UpdateMonitorView", "Monitor", new { pracId = pracId }));
        }
Example #2
0
        //This method load all unique patients from the server and store the list in cache
        public IActionResult LoadPatient(string id)
        {
            string cacheKey         = "Patients" + id;
            var    patientViewModel = new PatientViewModel();

            if (_cache.ExistObject <Dictionary <string, PatientModel> >(cacheKey) == true)
            {
                Console.WriteLine("exist cache");
                var patientList = _cache.GetObject <Dictionary <string, PatientModel> >(cacheKey);
                patientViewModel.PatientList = patientList;
                TempData["PracId"]           = id;
                ViewData["PractitionerId"]   = id;
                return(View(patientViewModel));
            }
            else
            {
                Console.WriteLine("create new cache");
                patientViewModel.PatientList = _practitioner.GetTotalPatients(id);
                _cache.SetObject(cacheKey, patientViewModel.PatientList);
                TempData["PracId"]         = id;
                ViewData["PractitionerId"] = id;
                return(View(patientViewModel));
            }
        }