Example #1
0
        private object GetFromCacheOrOutside(Guid id)
        {
            bool cameFromoutside = false;
            var  t    = Stopwatch.StartNew();
            var  item = _dataCache.RetrieveByFunc(id, i =>
            {
                cameFromoutside = true;
                return(_getter.GetItem(i));
            });

            t.Stop();
            _storage.PutObject(Name, id, item);

            if (cameFromoutside)
            {
                _updateDependenciesByQueries.ForEach(k => k(id));
                //сообщение о том, что ресурс пришел снаружи, приходит из геттера
            }
            else
            {
                _getter.StatChannel.SendMessageAboutOneResource(id, Actions.CacheGet, t.Elapsed);
            }
            _storage.ClearObject();
            return(item);
        }
 public IActionResult PatientEdited(EditedPatient patient)
 {
     if (ModelState.IsValid)
     {
         var client = new ResourceGetter();
         if (string.IsNullOrEmpty(patient.Id))
         {
             return(RedirectToAction("Patient", "Home"));
         }
         //fetch original patient
         var originalPatient = client.GetItem <Patient>(patient.Id);
         if (originalPatient != null)
         {
             if (patient.TryMergeWithResource(originalPatient))
             {
                 client.UpdateItem(originalPatient);
             }
         }
     }
     else
     {
         return(View("EditPatient", patient));
     }
     return(RedirectToAction("Patient", "Home"));
 }
        public IActionResult EditPatient(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Patient", "Home"));
            }
            var res     = new ResourceGetter();
            var patient = res.GetItem <Patient>(id);

            if (patient == null)
            {
                return(RedirectToAction("Patient", "Home"));
            }
            var editablePatient = new EditedPatient(id);

            editablePatient.MapFromResource(patient);
            return(View(editablePatient));
        }
        public IActionResult ViewPatient(string id, string startDate = null, string endDate = null)
        {
            if (!DataValidator.TryValidateString(id, out string idValidated, 4, 50))
            {
                ViewBag.Error        = true;
                ViewBag.ErrorMessage = $"Błąd parsowania id : `{id.Substring(30)}` nie jest poprawnym ciagiem.";
                return(View());
            }
            var searchParameters = new List <Tuple <string, string> >();

            DateTime startDateValidated = DateTime.MinValue,
                     endDateValidated   = DateTime.Now;

            if (!string.IsNullOrEmpty(startDate) && DataValidator.TryValidateDateTime(startDate, out startDateValidated))
            {
                searchParameters.Add(new Tuple <string, string>("date", startDateValidated.ToString(">=yyyy-MM-dd")));
                ViewBag.startDate = startDateValidated.ToString("dd-MMMM-yyyy");
            }

            if (!string.IsNullOrEmpty(endDate) && DataValidator.TryValidateDateTime(endDate, out endDateValidated))
            {
                searchParameters.Add(new Tuple <string, string>("date", endDateValidated.ToString("<=yyyy-MM-dd")));
                ViewBag.endDate = endDateValidated.ToString("dd-MMMM-yyyy");
            }

            var resourceGetter = new ResourceGetter();
            var person         = resourceGetter.GetItem <Patient>(id);

            if (person == null)
            {
                return(View());
            }

            searchParameters.Add(new Tuple <string, string>("subject", id));
            var patientsObservations        = resourceGetter.SearchItemsWithParameters <Observation>(searchParameters);
            var patientsMedicamentsRequests = resourceGetter.SearchItemsWithParameters <MedicationRequest>("subject", id);   //use only id search parameter

            var valuableExaminations = new Dictionary <string, List <PatientValueExamination> >();
            var valueObservations    = patientsObservations.Where(x => x.Value is SimpleQuantity || x.Component.Count > 0);
            var timelineObservations = patientsObservations.Where(x => !(x.Value is SimpleQuantity) && x.Component.Count == 0).
                                       Select(x =>
            {
                DateTimeOffset?issued = x.Issued;
                return(new TimelineObject()
                {
                    Date = issued.HasValue ? x.Issued.Value.DateTime : DateTime.MinValue,
                    Header = x.Code.Coding.FirstOrDefault()?.Display ?? DefaultObservationHeader,
                    Description = x.Value.ToString(),
                    Code = x.Code.Coding.FirstOrDefault()?.Code ?? DefaultCodeNumber,
                    EventType = TimelineEvent.ObservationMisc
                });
            });

            var timelineMedications = patientsMedicamentsRequests.
                                      Where(x =>
            {
                //filter dates here seems date in MedicationRequest search parameters doesn't affect results
                var dateTime = x.AuthoredOnElement.ToDateTime() ?? DateTime.Now;
                return(dateTime >= startDateValidated && dateTime <= endDateValidated);
            }).
                                      Select(x =>
            {
                var medication = x.Medication as CodeableConcept;
                return(new TimelineObject()
                {
                    Date = (x.AuthoredOnElement.ToDateTime() ?? DateTime.MinValue),
                    Header = "Podanie leku",
                    Description = (medication.Text ?? "Nieznana nazwa leku"),
                    Code = medication.Coding.FirstOrDefault().Code ?? DefaultCodeNumber,
                    EventType = TimelineEvent.MedicationRequest
                });
            });

            foreach (var observation in valueObservations)
            {
                List <PatientValueExamination> examinations = TryGetObservationValue(observation);

                foreach (var examination in examinations)
                {
                    var code = examination.Code;
                    if (!valuableExaminations.ContainsKey(code))
                    {
                        valuableExaminations.Add(code, new List <PatientValueExamination>()
                        {
                            examination
                        });
                    }
                    else
                    {
                        valuableExaminations[code].Add(examination);
                    }
                }
            }

            var patientSummary = new PatientSummary()
            {
                Data               = person,
                Observations       = patientsObservations,
                MedicationRequests = patientsMedicamentsRequests
            };

            //add dict for graphs
            patientSummary.SetPatientValueExaminations(valuableExaminations);
            //add timeline objects and sort them
            patientSummary.AddTimelineObjects(timelineObservations.Concat(timelineMedications).ToList());

            return(View(patientSummary));
        }