public void Init() { _serviceProvider = new ServiceCollection() .AddTransient <ICbsSendService, CbsSendService>() .BuildServiceProvider(); /* * 22704|TOGONYE DISPENSARY|KIRINYAGA * 22696|HERTLANDS MEDICAL CENTRE|NAROK */ _bag = TestDataFactory.ManifestMessageBag(2, 22704, 22696); _mpiBag = TestDataFactory.MpiMessageBag(5, 22704, 22696); }
public void Init() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var connectionString = config["ConnectionStrings:DwapiConnection"]; _serviceProvider = new ServiceCollection() .AddDbContext <UploadContext>(o => o.UseSqlServer(connectionString)) .AddTransient <ICbsSendService, CbsSendService>() .AddTransient <ICbsPackager, CbsPackager>() .AddTransient <ICbsExtractReader, CbsExtractReader>() .BuildServiceProvider(); /* * 22704|TOGONYE DISPENSARY|KIRINYAGA * 22696|HERTLANDS MEDICAL CENTRE|NAROK */ _bag = TestDataFactory.ManifestMessageBag(2, 10001, 10002); _mpiBag = TestDataFactory.MpiMessageBag(5, 10001, 10002); }
public async Task <List <SendMpiResponse> > SendMpiAsync(SendManifestPackageDTO sendTo, MpiMessageBag messageBag) { var responses = new List <SendMpiResponse>(); var client = Client ?? new HttpClient(); int sendCound = 0; int count = 0; int total = messageBag.Messages.Count; DomainEvents.Dispatch(new CbsStatusNotification(sendTo.ExtractId, ExtractStatus.Sending)); foreach (var message in messageBag.Messages) { count++; try { var msg = JsonConvert.SerializeObject(message); var response = await client.PostAsJsonAsync(sendTo.GetUrl($"{_endPoint.HasToEndsWith("/")}mpi"), message); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsJsonAsync <SendMpiResponse>(); responses.Add(content); var sentIds = message.MasterPatientIndices.Select(x => x.Id).ToList(); sendCound += sentIds.Count; DomainEvents.Dispatch(new CbsExtractSentEvent(sentIds, SendStatus.Sent)); } else { var error = await response.Content.ReadAsStringAsync(); DomainEvents.Dispatch(new CbsExtractSentEvent(message.MasterPatientIndices.Select(x => x.Id).ToList(), SendStatus.Failed, error)); throw new Exception(error); } } catch (Exception e) { Log.Error(e, $"Send Extracts Error"); throw; } DomainEvents.Dispatch(new CbsSendNotification(new SendProgress(nameof(MasterPatientIndex), Common.GetProgress(count, total), sendCound))); } DomainEvents.Dispatch(new CbsStatusNotification(sendTo.ExtractId, ExtractStatus.Sent, sendCound)); return(responses); }
public Task <List <SendMpiResponse> > SendMpiAsync(SendManifestPackageDTO sendTo) { return(SendMpiAsync(sendTo, MpiMessageBag.Create(_packager.GenerateDtoMpi().ToList()))); }