Esempio n. 1
0
        public async Task <IActionResult> Stats(DoctorStatsViewModel viewModel)
        {
            viewModel.Stats = await _statsService.GetDoctorStats(viewModel.Id,
                                                                 viewModel.Start, viewModel.End);

            return(View(viewModel));
        }
Esempio n. 2
0
        public async Task <IActionResult> Stats(string Id, string returnUrl)
        {
            if (string.IsNullOrEmpty(Id))
            {
                Id = _userManager.GetUserId(User);
            }
            var now = DateTime.Now;
            var vm  = new DoctorStatsViewModel()
            {
                Start     = new DateTime(now.Year, now.Month, 1),
                End       = now.Date,
                ReturnUrl = returnUrl
            };

            vm.Stats = await _statsService.GetDoctorStats(Id, vm.Start, vm.End);

            return(View(vm));
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Post([FromUri] int countyId, [FromUri] Guid doctorId, [FromBody] DoctorStatsViewModel stats)
        {
            try
            {
                IReliableDictionary <int, string> countyNameDictionary =
                    await this.stateManager.GetOrAddAsync <IReliableDictionary <int, string> >(Service.CountyNameDictionaryName);

                IReliableDictionary <Guid, CountyDoctorStats> countyHealth =
                    await
                    this.stateManager.GetOrAddAsync <IReliableDictionary <Guid, CountyDoctorStats> >(
                        string.Format(Service.CountyHealthDictionaryName, countyId));

                using (ITransaction tx = this.stateManager.CreateTransaction())
                {
                    await
                    countyHealth.SetAsync(
                        tx,
                        doctorId,
                        new CountyDoctorStats(stats.PatientCount, stats.HealthReportCount, stats.DoctorName, new HealthIndex(stats.AverageHealthIndex)));

                    // Add the county only if it does not already exist.
                    ConditionalValue <string> getResult = await countyNameDictionary.TryGetValueAsync(tx, countyId);

                    if (!getResult.HasValue)
                    {
                        await countyNameDictionary.AddAsync(tx, countyId, String.Empty);
                    }

                    // finally, commit the transaction and return a result
                    await tx.CommitAsync();
                }

                return(this.Ok());
            }
            catch (Exception e)
            {
                return(this.InternalServerError(e));
            }
        }
        public async Task SendHealthReportToCountyAsync()
        {
            try
            {
                ConditionalValue <DoctorActorState> doctorStateResult = await this.StateManager.TryGetStateAsync <DoctorActorState>("DoctorActorState");

                if (doctorStateResult.HasValue)
                {
                    DoctorActorState state = doctorStateResult.Value;

                    if (state.PersonHealthStatuses.Count > 0)
                    {
                        DoctorStatsViewModel payload = new DoctorStatsViewModel(
                            state.PersonHealthStatuses.Count,
                            state.HealthReportCount,
                            await this.GetAveragePatientHealthInfoAsync(),
                            state.Name);

                        ServicePartitionKey partitionKey = new ServicePartitionKey(state.CountyInfo.CountyId);
                        Guid id = this.Id.GetGuidId();

                        ServicePartitionClient <HttpCommunicationClient> servicePartitionClient =
                            new ServicePartitionClient <HttpCommunicationClient>(
                                this.clientFactory,
                                this.countyServiceInstanceUri,
                                partitionKey);

                        await servicePartitionClient.InvokeWithRetryAsync(
                            client =>
                        {
                            Uri serviceAddress = new Uri(
                                client.BaseAddress,
                                string.Format(
                                    "county/health/{0}/{1}",
                                    partitionKey.Value.ToString(),
                                    id));

                            HttpWebRequest request   = WebRequest.CreateHttp(serviceAddress);
                            request.Method           = "POST";
                            request.ContentType      = "application/json";
                            request.KeepAlive        = false;
                            request.Timeout          = (int)client.OperationTimeout.TotalMilliseconds;
                            request.ReadWriteTimeout = (int)client.ReadWriteTimeout.TotalMilliseconds;

                            using (Stream requestStream = request.GetRequestStream())
                            {
                                using (BufferedStream buffer = new BufferedStream(requestStream))
                                {
                                    using (StreamWriter writer = new StreamWriter(buffer))
                                    {
                                        JsonSerializer serializer = new JsonSerializer();
                                        serializer.Serialize(writer, payload);
                                        buffer.Flush();
                                    }

                                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                                    {
                                        ActorEventSource.Current.Message("Doctor Sent Data to County: {0}", serviceAddress);
                                        return(Task.FromResult(true));
                                    }
                                }
                            }
                        }
                            );
                    }
                }
            }
            catch (Exception e)
            {
                ActorEventSource.Current.Message("DoctorActor failed to send health report to county service Outer Exception: {0}", e.ToString());
            }
        }