public async Task ReportPatientHealthAsync(Guid doctorId, Guid personId, [FromBody] HeartRateRecord latestHeartRateRecord)
        {
            string doctorMetadataDictionaryName = String.Format(DoctorMetadataDictionaryName, doctorId);
            long   doctorHealthReportCount      = -1;

            try
            {
                var doctorMetadataDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, long> >(doctorMetadataDictionaryName);

                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    doctorHealthReportCount = await doctorMetadataDictionary.AddOrUpdateAsync(tx, "HealthReportCount", 1, (key, value) => value + 1);

                    await tx.CommitAsync();
                }
            }
            catch (Exception e)
            {
                // transient error. Retry.
                ServiceEventSource.Current.Message("Exception in DoctorController Report Patient Health {0}", e.ToString());
                throw;
            }

            ServiceEventSource.Current.Message("Successfully handled patient health report Doc_ID {0} Person_ID {1} Count {2}", doctorId, personId, doctorHealthReportCount);
            return;
        }
        private async Task GenerateAndSendHealthReportAsync()
        {
            try
            {
                ConditionalValue <Guid> DoctorIdResult = await this.StateManager.TryGetStateAsync <Guid>("DoctorId");

                string          docIdStr = DoctorIdResult.Value.ToString();
                HeartRateRecord record   = new HeartRateRecord((float)this.random.NextDouble());

                await this.SaveHealthDataAsync(record);

                await FabricHttpClient.MakePostRequest <HeartRateRecord>(
                    this.doctorServiceUri,
                    this.doctorServicePartitionKey,
                    "DoctorEndpoint",
                    "doctor/health/" + docIdStr + "/" + this.Id.GetGuidId(),
                    record,
                    SerializationSelector.PBUF,
                    CancellationToken.None
                    );

                ActorEventSource.Current.Message("Health info sent from band {0} to doctor {1}", this.Id, DoctorIdResult.Value);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.Message(
                    "Band Actor failed to send health data to doctor. Exception: {0}",
                    (e is AggregateException) ? e.InnerException.ToString() : e.ToString());
            }

            return;
        }
        private async Task SaveHealthDataAsync(HeartRateRecord newRecord)
        {
            ConditionalValue <List <HeartRateRecord> > HeartRateRecords = await this.StateManager.TryGetStateAsync <List <HeartRateRecord> >("HeartRateRecords");

            if (HeartRateRecords.HasValue)
            {
                List <HeartRateRecord> records = HeartRateRecords.Value;
                records = records.Where(x => DateTimeOffset.UtcNow - ((DateTimeOffset)x.Timestamp).ToUniversalTime() <= this.TimeWindow).ToList();
                records.Add(newRecord);
                await this.StateManager.SetStateAsync <List <HeartRateRecord> >("HeartRateRecords", records);
            }
            return;
        }
예제 #4
0
        public async Task RecordHeartRate(HeartRateRecordData hr)
        {
            //Create a record
            var heartRateRecord = new HeartRateRecord()
            {
                type      = hr.type,
                startTime = ConvertToDateTime(hr.startTime),
                endTime   = ConvertToDateTime(hr.endTime),
                bpmLow    = Math.Round(hr.bpmLow, 0),
                bpmHigh   = Math.Round(hr.bpmHigh, 0),
                bpmAvg    = Math.Round(hr.bpmAvg, 0)
            };

            try
            {
                await _heartRateRecordDao.RecordHeartRate(heartRateRecord, hr.username);
            }
            catch (Exception e)
            {
                throw new CustomException("Error at record heart rate service" + e);
            }
        }
예제 #5
0
        private async Task GenerateAndSendHealthReportAsync()
        {
            try
            {
                ConditionalValue <HealthIndex> HeatlthInfoResult = await this.StateManager.TryGetStateAsync <HealthIndex>("HealthIndex");

                ConditionalValue <string> PatientInfoResult = await this.StateManager.TryGetStateAsync <string>("PatientName");

                ConditionalValue <Guid> DoctorInfoResult = await this.StateManager.TryGetStateAsync <Guid>("DoctorId");


                if (HeatlthInfoResult.HasValue && PatientInfoResult.HasValue && DoctorInfoResult.HasValue)
                {
                    ActorId         doctorId = new ActorId(DoctorInfoResult.Value);
                    HeartRateRecord record   = new HeartRateRecord((float)this.random.NextDouble());

                    await this.SaveHealthDataAsync(record);

                    IDoctorActor doctor = ActorProxy.Create <IDoctorActor>(doctorId, this.doctorActorServiceUri);

                    await
                    doctor.ReportHealthAsync(
                        this.Id.GetGuidId(),
                        PatientInfoResult.Value,
                        HeatlthInfoResult.Value);

                    ActorEventSource.Current.Message("Health info sent from band {0} to doctor {1}", this.Id, DoctorInfoResult.Value);
                }
            }
            catch (Exception e)
            {
                ActorEventSource.Current.Message(
                    "Band Actor failed to send health data to doctor. Exception: {0}",
                    (e is AggregateException) ? e.InnerException.ToString() : e.ToString());
            }

            return;
        }
예제 #6
0
        public async Task RecordHeartRate(HeartRateRecord hrr, string username)
        {
            try
            {
                //Find the account that this HR data is for
                Account acc = await _context.accounts.Where(x => x.username == username).FirstOrDefaultAsync();

                if (acc == null)
                {
                    throw new InvalidOperationException("There is no account matching the username");
                }

                hrr.accountId = acc.Id;
                hrr.account   = acc;

                //Add the record to the DB and save
                _context.heartRateRecords.Add(hrr);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                throw new CustomException("Database error while trying to create heart rate record " + e);
            }
        }
 public void AddHeartRateRecord(HeartRateRecord record)
 {
     this.heartRateHistory = this.heartRateHistory.Where(x => DateTimeOffset.UtcNow - x.Timestamp.ToUniversalTime() <= TimeWindow).ToList();
     this.heartRateHistory.Add(record);
 }