public async Task RegisterPatientAsync(Guid doctorId, [FromBody] PatientRegistrationRecord record)
        {
            string doctorPatientDictionaryName  = String.Format(DoctorPatientDictionaryName, doctorId);
            string doctorMetadataDictionaryName = String.Format(DoctorMetadataDictionaryName, doctorId);
            long   doctorPatientCount           = -1;

            try
            {
                var doctorPatientDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <Guid, PatientRegistrationRecord> >(doctorPatientDictionaryName);

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

                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    if (!(await doctorPatientDictionary.TryGetValueAsync(tx, record.PatientId)).HasValue)
                    {
                        await doctorPatientDictionary.SetAsync(tx, record.PatientId, record);

                        doctorPatientCount = await doctorMetadataDictionary.AddOrUpdateAsync(tx, "PatientCount", 1, (key, value) => value + 1);
                    }

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

            ServiceEventSource.Current.Message("Successfully registered patient {0}. PL: {1} D: {2} Count {3}", doctorId, doctorPatientDictionaryName, doctorMetadataDictionaryName, doctorPatientCount);
            return;
        }
        private async Task RegisterPatientReminder()
        {
            ConditionalValue <Guid> DoctorIdResult = await this.StateManager.TryGetStateAsync <Guid>("DoctorId");

            var docIdStr = DoctorIdResult.Value.ToString();

            var prr = new PatientRegistrationRecord(
                await this.StateManager.GetStateAsync <string>("PatientName"),
                this.Id.GetGuidId(),
                await this.StateManager.GetStateAsync <HealthIndex>("HealthIndex")
                );

            await FabricHttpClient.MakePostRequest <PatientRegistrationRecord>(
                this.doctorServiceUri,
                new ServicePartitionKey(HashUtil.getLongHashCode(docIdStr)),
                "DoctorEndpoint",
                "/doctor/new/patient/" + docIdStr,
                prr,
                SerializationSelector.PBUF,
                CancellationToken.None
                );
        }