public DoctorStatsViewModel(int patientCount, long healthReportCount, HealthIndex averageHealthIndex, string doctorName) { this.PatientCount = patientCount; this.HealthReportCount = healthReportCount; this.AverageHealthIndex = averageHealthIndex; this.DoctorName = doctorName; }
public async Task <BandDataViewModel> GetBandDataAsync() { try { ConditionalValue <BandActorState> BandActorStateResult = await this.StateManager.TryGetStateAsync <BandActorState>("BandActorState"); if (BandActorStateResult.HasValue) { BandActorState state = BandActorStateResult.Value; HealthIndexCalculator ic = this.indexCalculator; HealthIndex hi = state.HealthIndex; int healthIndex = ic.ComputeIndex(hi); return(new BandDataViewModel( state.DoctorId, this.Id.GetGuidId(), state.PatientName, state.CountyInfo, healthIndex, state.HeartRateHistory)); } } catch (Exception e) { throw new ArgumentException(string.Format("Exception inside band actor {0}|{1}|{2}", this.Id, this.Id.Kind, e)); } throw new ArgumentException(string.Format("No band actor state {0}|{1}|{2}", this.Id, this.Id.Kind)); }
public DoctorPatientState(Guid id, string name, HealthIndex healthIndex, HealthIndex heartRateIndex) { this.Id = id; this.Name = name; this.HealthIndex = healthIndex; this.HeartRateIndex = heartRateIndex; }
public Fruit(String name, int count, int unitPrice) { Id = Guid.NewGuid(); HealthIndex = HealthIndex.Average; Name = name; Count = count; UnitPrice = unitPrice; }
public Vegetable(String name, int count, int unitPrice) { Id = Guid.NewGuid(); HealthIndex = HealthIndex.Good; Name = name; Count = count; UnitPrice = unitPrice; }
public PatientDataViewModel( Guid patientId, string name, HealthIndex healthIndex) { this.PatientId = patientId; this.PatientName = name; this.HealthIndex = healthIndex; }
public BandDataViewModel( Guid doctorId, Guid bandId, string patientName, CountyRecord countyInfo, HealthIndex healthIndexValue, IEnumerable <HeartRateRecord> heartRateHistory) { this.DoctorId = doctorId; this.PersonId = bandId; this.PersonName = patientName; this.CountyInfo = countyInfo; this.HealthIndexValue = healthIndexValue; this.HeartRateHistory = heartRateHistory; }
private async Task <HealthIndex> GetAveragePatientHealthInfoAsync() { ConditionalValue <long> healthReportCountResult = await this.StateManager.TryGetStateAsync <long>("HealthReportCount"); if (healthReportCountResult.HasValue && healthReportCountResult.Value > 0) { Dictionary <Guid, DoctorPatientState> patientHealthReports = await this.StateManager.GetStateAsync <Dictionary <Guid, DoctorPatientState> >("PersonHealthStatuses"); HealthIndex avgHealth = this.indexCalculator.ComputeAverageIndex(patientHealthReports.Select(x => x.Value.HealthIndex)); ActorEventSource.Current.ActorMessage(this, "Average patient Health Calculated: {0}", avgHealth); return(avgHealth); } else { ActorEventSource.Current.ActorMessage(this, "No patient health available"); return(this.indexCalculator.ComputeIndex(-1)); } }
public async Task <DeviceDataViewModel> GetDeviceDataAsync() { try { //check to see if the patient name is set //if not this actor object hasn't been initialized //and we can skip the rest of the checks ConditionalValue <string> PatientInfoResult = await this.StateManager.TryGetStateAsync <string>("PatientName"); if (PatientInfoResult.HasValue) { ConditionalValue <CountyRecord> CountyInfoResult = await this.StateManager.TryGetStateAsync <CountyRecord>("CountyInfo"); ConditionalValue <Guid> DoctorInfoResult = await this.StateManager.TryGetStateAsync <Guid>("DoctorId"); ConditionalValue <HealthIndex> HeatlthInfoResult = await this.StateManager.TryGetStateAsync <HealthIndex>("HealthIndex"); ConditionalValue <List <HeartRateRecord> > HeartRateRecords = await this.StateManager.TryGetStateAsync <List <HeartRateRecord> >("HeartRateRecords"); HealthIndexCalculator ic = this.indexCalculator; HealthIndex healthIndex = ic.ComputeIndex(HeatlthInfoResult.Value); return(new DeviceDataViewModel( DoctorInfoResult.Value, this.Id.GetGuidId(), PatientInfoResult.Value, CountyInfoResult.Value, healthIndex, HeartRateRecords.Value)); } } catch (Exception e) { throw new ArgumentException(string.Format("Exception inside band actor {0}|{1}|{2}", this.Id, this.Id.Kind, e)); } throw new ArgumentException(string.Format("No band actor state {0}|{1}", this.Id, this.Id.Kind)); }
public async Task ReportHealthAsync(Guid personId, string personName, HealthIndex healthIndex, HealthIndex heartRateIndex) { ConditionalValue <DoctorActorState> doctorActorStateResult = await this.StateManager.TryGetStateAsync <DoctorActorState>("DoctorActorState"); if (doctorActorStateResult.HasValue) { DoctorActorState state = doctorActorStateResult.Value; state.PersonHealthStatuses[personId] = new DoctorPatientState(personId, personName, healthIndex, heartRateIndex); state.HealthReportCount++; await this.StateManager.SetStateAsync <DoctorActorState>("DoctorActorState", state); ActorEventSource.Current.Message( "DoctorActor {0} Recieved health report from band {1} with value {2}", this.Id.GetGuidId(), personId, healthIndex); } return; }
public async Task ReportHealthAsync(Guid personId, string personName, HealthIndex healthIndex) { ConditionalValue <Dictionary <Guid, DoctorPatientState> > patientReportResult = await this.StateManager.TryGetStateAsync <Dictionary <Guid, DoctorPatientState> >("PersonHealthStatuses"); ConditionalValue <long> healthReportCountResult = await this.StateManager.TryGetStateAsync <long>("HealthReportCount"); if (patientReportResult.HasValue) { patientReportResult.Value[personId] = new DoctorPatientState(personId, personName, healthIndex); await this.StateManager.SetStateAsync <Dictionary <Guid, DoctorPatientState> >("PersonHealthStatuses", patientReportResult.Value); await this.StateManager.SetStateAsync <long>("HealthReportCount", healthReportCountResult.Value + 1); ActorEventSource.Current.Message( "DoctorActor {0} Recieved health report from band {1} with value {2}", this.Id.GetGuidId(), personId, healthIndex); } return; }
public CountyDoctorStats(int patientCount, long healthReportCount, string doctorName, HealthIndex averageHealthIndex) { this.PatientCount = patientCount; this.HealthReportCount = healthReportCount; this.AverageHealthIndex = averageHealthIndex; this.DoctorName = doctorName; }
public NationalCountyStats(int doctorCount, int patientCount, long healthReportCount, HealthIndex averageHealthIndex) { this.AverageHealthIndex = averageHealthIndex; this.DoctorCount = doctorCount; this.PatientCount = patientCount; this.HealthReportCount = healthReportCount; }
public HealthIndex ComputeIndex(HealthIndex value) { return(new HealthIndex(value.GetValue(), (this.calculationMode == CalculationMode.Simple) ? false : true)); }
/// <summary> /// Constructor /// </summary> /// <param name="helthIndex"></param> public Product(HealthIndex helthIndex) { HealthIndex = HealthIndex; Id = new Guid(); }
protected override async Task RunAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { await Task.Delay(TimeSpan.FromSeconds(1)); ConcurrentDictionary <int, List <KeyValuePair <Guid, string> > > countyDoctorMap = new ConcurrentDictionary <int, List <KeyValuePair <Guid, string> > >(); using (ITransaction tx = this.StateManager.CreateTransaction()) { var doctorDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <Guid, DoctorCreationRecord> >(DoctorRegistrationDictionaryName); var enumerator = (await doctorDictionary.CreateEnumerableAsync(tx)).GetAsyncEnumerator(); while (await enumerator.MoveNextAsync(cancellationToken)) { var doctorListItem = enumerator.Current; Guid doctorId = doctorListItem.Key; int countyId = doctorListItem.Value.CountyInfo.CountyId; string name = doctorListItem.Value.DoctorName; //TODO: Evaluate if this will correctly always add, or if it will get overwritten countyDoctorMap.AddOrUpdate( countyId, new List <KeyValuePair <Guid, string> >() { new KeyValuePair <Guid, string>(doctorId, name) }, (id, existingList) => { existingList.Add(new KeyValuePair <Guid, string>(doctorId, name)); return(existingList); } ); } await tx.CommitAsync(); } foreach (KeyValuePair <int, List <KeyValuePair <Guid, string> > > info in countyDoctorMap) //should actually be able to do these in parallel { List <DoctorStatsViewModel> countyDoctorStats = new List <DoctorStatsViewModel>(); foreach (var docInfo in info.Value) //these should go in parallel too { int patientCount = 0; long healthReportCount = 0; string doctorMetadataDictionaryName = String.Format(DoctorMetadataDictionaryName, docInfo.Key); var doctorMetadataDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, long> >(doctorMetadataDictionaryName); using (ITransaction tx = this.StateManager.CreateTransaction()) { var reportCountResult = await doctorMetadataDictionary.TryGetValueAsync(tx, "HealthReportCount"); if (reportCountResult.HasValue) { healthReportCount = reportCountResult.Value; } var patientCountResult = await doctorMetadataDictionary.TryGetValueAsync(tx, "PatientCount"); if (patientCountResult.HasValue) { patientCount = (int)patientCountResult.Value; } await tx.CommitAsync(); } HealthIndex avgHealthIndex = await GetAveragePatientHealthInfoAsync(docInfo.Key, cancellationToken); countyDoctorStats.Add(new DoctorStatsViewModel(docInfo.Key, info.Key, patientCount, healthReportCount, avgHealthIndex, docInfo.Value)); } await FabricHttpClient.MakePostRequest <List <DoctorStatsViewModel> >( this.CountyServiceUri, new ServicePartitionKey(info.Key), "CountyEndpoint", "county/health/", countyDoctorStats, SerializationSelector.PBUF, cancellationToken ); } } catch (TimeoutException te) { // transient error. Retry. ServiceEventSource.Current.ServiceMessage( this.Context, "DoctorService encountered an exception trying to send data to County Service: TimeoutException in RunAsync: {0}", te.ToString()); } catch (FabricNotReadableException fnre) { // transient error. Retry. ServiceEventSource.Current.ServiceMessage( this.Context, "DoctorService encountered an exception trying to send data to County Service: FabricNotReadableException in RunAsync: {0}", fnre.ToString()); } catch (FabricTransientException fte) { // transient error. Retry. ServiceEventSource.Current.ServiceMessage( this.Context, "DoctorService encountered an exception trying to send data to County Service: FabricTransientException in RunAsync: {0}", fte.ToString()); } catch (HttpRequestException hre) { ServiceEventSource.Current.ServiceMessage( this.Context, "DoctorService encountered an exception trying to send data to County Service: HttpRequestException in RunAsync: {0}", hre.ToString()); } catch (FabricNotPrimaryException) { // not primary any more, time to quit. return; } catch (ProtoException pbe) { ServiceEventSource.Current.ServiceMessage( this.Context, "DoctorService encountered an exception trying to send data to County Service: ProtoException in RunAsync: {0}", pbe.ToString()); } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(this.Context, "{0}", ex.ToString()); throw; } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { HealthIndex healthIndex = value as HealthIndex? ?? HealthIndex.Unknown; return(_colors[healthIndex]); }
public PatientRegistrationRecord(string name, Guid id, HealthIndex healthIndex) { this.PatientName = name; this.PatientId = id; this.PatientHealthIndex = healthIndex; }