Пример #1
0
        public void ReceiveMedicalRecord()
        {
            var client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName);

            client.OnMessageAsync(async message =>
            {
                MedicalRecord medicalRecord = JsonConvert.DeserializeObject <MedicalRecord>(message.GetBody <string>());
                Patient patient             = new PatientService(medicalRecord.PatientId).Retrieve();

                if (PatientExists(patient) && !MedicalRecordExists(medicalRecord))
                {
                    await SaveMedicalRecord(medicalRecord);
                }
            });
        }
Пример #2
0
        private async Task RegisterMedicalRecord(MedicalRecordEntity entity)
        {
            // First map the XRM entity to a Data Contract using AutoMapper
            // Then add the medical record to its patient via a Patient service
            // A correlation ID identifies the medical record associated to its patient uniquely
            Mapper.Initialize(cfg => cfg.CreateMap <MedicalRecordEntity, MedicalRecord>());
            MedicalRecord medicalRecord = Mapper.Map <MedicalRecord>(entity);

            medicalRecord.CorrelationId = new PatientService(medicalRecord.PatientId).AddMedicalRecord(medicalRecord);

            // Create a connection to an Azure Service Bus Topic
            // Serialize the medical record and add the correlation ID as an extra property of the message
            var client  = TopicClient.CreateFromConnectionString(connectionString, topicName);
            var message = new BrokeredMessage(JsonConvert.SerializeObject(medicalRecord));
            // Send the message to the Topic
            await client.SendAsync(message);
        }
Пример #3
0
        public Guid AddMedicalRecord(MedicalRecord medicalRecord)
        {
            // If the patient already has this medical record
            // Return its correlation ID
            Guid?correlationId = this.patient.MedicalRecords.SingleOrDefault(r => r.Id == medicalRecord.Id)?.CorrelationId;

            if (correlationId.HasValue)
            {
                return(correlationId.Value);
            }

            // Otherwise, generate a new correlation ID
            // Persist the medical record to the data context
            medicalRecord.CorrelationId = Guid.NewGuid();
            dataContext.MedicalRecords.Add(medicalRecord);
            dataContext.SaveChanges();

            return(medicalRecord.CorrelationId);
        }
Пример #4
0
 private async Task SaveMedicalRecord(MedicalRecord medicalRecord)
 {
     dataContext.MedicalRecords.Add(medicalRecord);
     await dataContext.SaveChangesAsync();
 }