Ejemplo n.º 1
0
        public async Task <ResponseDto <byte[]> > GetImage(string uri)
        {
            if (!String.IsNullOrWhiteSpace(uri))
            {
                var container = await GetImageContainer();

                var newBlob = container.GetBlockBlobReference(uri);
                var exists  = await newBlob.ExistsAsync();

                if (exists)
                {
                    await newBlob.FetchAttributesAsync();

                    long   fileByteLength = newBlob.Properties.Length;
                    byte[] fileContent    = new byte[fileByteLength];
                    for (int i = 0; i < fileByteLength; i++)
                    {
                        fileContent[i] = 0x20;
                    }
                    await newBlob.DownloadToByteArrayAsync(fileContent, 0);

                    return(ResponseDto <byte[]> .CreateSuccessResponseDto(fileContent));
                }
            }

            return(ResponseDto <byte[]> .CreateSuccessResponseDto(GetDefaultImage()));;
        }
        private async Task <ResponseDto> AddMessageToQueueAsync(string message)
        {
            try
            {
                // Retrieve storage account from connection string.
                var storageCredentials  = new StorageCredentials(_configuration["StorageName"], _configuration["StorageKey"]);
                var cloudStorageAccount = new CloudStorageAccount(storageCredentials, true);

                // Create the queue client.
                var queueClient = cloudStorageAccount.CreateCloudQueueClient();

                // Retrieve a reference to a queue.
                var queue = queueClient.GetQueueReference("referral-queue");

                // Create the queue if it doesn't already exist.
                await queue.CreateIfNotExistsAsync();

                // Create a message and add it to the queue.
                var queuemessage = new CloudQueueMessage(message);
                await queue.AddMessageAsync(queuemessage);

                return(ResponseDto.CreateSuccessResponseDto());
            }
            catch (Exception ex)
            {
                return(ResponseDto.CreateErrorResponseDto(ex.Message));
            }
        }
        public async Task <ResponseDto <List <PatientInfoDto> > > GetPatients()
        {
            var patients = await UnitOfWork.PatientRepository.Find("", 0, 20);

            var patientDtos = new List <PatientInfoDto>();

            foreach (var p in patients)
            {
                patientDtos.Add(new PatientInfoDto {
                    Name = p.Name, Value = p.AnonymizationId.ToString()
                });
            }
            return(ResponseDto <List <PatientInfoDto> > .CreateSuccessResponseDto(patientDtos));
        }
Ejemplo n.º 4
0
        public async Task <ResponseDto <string> > Post(string name, byte[] bytes)
        {
            var container = await GetImageContainer();

            BlobContainerPermissions containerPermissions = new BlobContainerPermissions()
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            };
            await container.SetPermissionsAsync(containerPermissions);

            CloudBlockBlob photo = container.GetBlockBlobReference($"{name}");
            await photo.UploadFromByteArrayAsync(bytes, 0, bytes.Length);

            return(ResponseDto <string> .CreateSuccessResponseDto(photo.Uri.ToString()));
        }
        public async Task <ResponseDto> Add(ReferralDto referral)
        {
            var user = await UnitOfWork.UserRepository.GetByMail(referral.User.Email);

            if (user == null)
            {
                user = User.CreateUser(referral.User.Email, referral.User.Name, (Language)referral.User.Language);
                await UnitOfWork.UserRepository.Add(user);

                UnitOfWork.SaveChanges();
            }

            var patient = await UnitOfWork.PatientRepository.GetByNihii(referral.Patient.Nihii);

            if (patient == null)
            {
                patient = Patient.CreatePatient(referral.Patient.Email, referral.Patient.Nihii, referral.Patient.Name, (Language)referral.Patient.Language, (Gender)referral.Patient.Gender,
                                                referral.Patient.DateOfBirth, referral.Patient.Remarks);
                await UnitOfWork.PatientRepository.Add(patient);

                UnitOfWork.SaveChanges();
            }

            var newReferral = Referral.CreateReferral(user.Id, patient.Id, ReferralStatus.Open);
            await UnitOfWork.ReferralRepository.Add(newReferral);

            foreach (var fileName in referral.FileNames)
            {
                newReferral.AddFile(ReferralFile.CreateReferralFile(newReferral.Id, $"{patient.AnonymizationId}-{fileName}"));
            }
            UnitOfWork.SaveChanges();
            await CopyBlobItems(patient.Nihii, patient.AnonymizationId, referral.FileNames);

            //await AddMessageToQueueAsync(JsonConvert.SerializeObject(new { user = user, patient = patient, referral = newReferral }));
            _searchClient.Indexers.Run(_configuration["IndexerName"]);
            await CheckIndexerStatus(newReferral.ReferralFiles.Select(p => p.FileName).ToArray(), patient.AnonymizationId, newReferral.Id);

            return(ResponseDto.CreateSuccessResponseDto());
        }
        public async Task <ResponseDto <DashboardDto> > GetDashboardInformation()
        {
            var referrals = await UnitOfWork.ReferralRepository.Find(0, 20);

            var dashboard = new DashboardDto
            {
                TotalReferrals    = referrals.Count(),
                OpenReferrals     = referrals.Count(p => p.Status == ReferralStatus.Open),
                DeniedReferrals   = referrals.Count(p => p.Status == ReferralStatus.Denied),
                ResolvedReferrals = referrals.Count(p => p.Status == ReferralStatus.Resolved),
                ReferralInfo      = new List <ReferralInfo>()
            };

            foreach (var referral in referrals)
            {
                dashboard.ReferralInfo.Add(new ReferralInfo
                {
                    Id            = referral.Id,
                    CreatedOn     = referral.CreatedOn,
                    PatientName   = referral.Patient.Name,
                    PhysicianName = referral.User.Name,
                    Remarks       = referral.Patient.Remarks,
                    Status        = (int)referral.Status
                });

                if (referral.Patient.Gender == Gender.Female)
                {
                    dashboard.FemaleRatio += 1;
                }
                else
                {
                    dashboard.MaleRatio += 1;
                }
            }

            return(ResponseDto <DashboardDto> .CreateSuccessResponseDto(dashboard));
        }