/// <summary>
        /// Instantiates new instance of <see cref="InputArguments"/>.
        /// </summary>
        /// <param name="inputArguments">Represents input artuments passed when starting the program</param>
        /// <exception cref="ArgumentNullException"><paramref name="inputArguments"/> is <see langword="null"/></exception>
        public InputSettingsProvider(InputArguments inputArguments)
        {
            if (inputArguments == null)
            {
                throw new ArgumentNullException(nameof(inputArguments));
            }

            mInputArguments = inputArguments;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles retrieving of all patients.
        /// </summary>
        /// <param name="inputArguments">Parsed program input arguments</param>
        /// <param name="writer">Writer the serialized result will be written into</param>
        /// <returns>Represents an asynchronous operation</returns>
        private async Task HandleAllPatients(InputArguments inputArguments, TextWriter writer)
        {
            var query = mPatientInfoProvider.GetPatients();
            if (inputArguments.UseCache)
            {
                query = query.LoadFromCache();
            }

            await writer.WriteAsync(JsonConvert.SerializeObject(await query.ToListAsync()));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles retrieving of single patient or downloading images for single patient.
        /// </summary>
        /// <param name="inputArguments">Parsed program input arguments</param>
        /// <param name="writer">Writer the serialized result will be written into</param>
        /// <returns>Represents an asynchronous operation</returns>
        private async Task HandleSinglePatient(InputArguments inputArguments, TextWriter writer)
        {
            var patient = await mPatientInfoProvider.GetPatientByBirthNumberAsync(inputArguments.Identifier, inputArguments.UseCache);

            if (inputArguments.Download)
            {
                await mPatientInfoProvider.DownloadImagesAsync(patient);
            }
            else
            {
                await writer.WriteAsync(JsonConvert.SerializeObject(patient));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles downloading of study related data.
        /// </summary>
        /// <param name="inputArguments">Parsed program input arguments</param>
        /// <param name="writer">Writer the serialized result will be written into</param>
        /// <exception cref="ArgumentException">Wrong <see cref="InputArguments.Type"/> in <paramref name="inputArguments"/>. Expected value is 'study'.</exception>
        /// <returns>Represents an asynchronous operation</returns>
        public async Task HandleTypeAsync(InputArguments inputArguments, TextWriter writer)
        {
            if (!inputArguments.Type.Equals("study", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("Type has to be 'study'", nameof(inputArguments));
            }

            if (inputArguments.Identifier != null)
            {
                await HandleSingleStudy(inputArguments, writer);
            }
            else
            {
                await HandleMultipleStudies(inputArguments, writer);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            if (!File.Exists("NLog.config"))
            {
                System.Console.Error.WriteLine("Could not found NLog.config, terminating");
                return;
            }

            var originalOut = System.Console.Out;
            System.Console.SetOut(TextWriter.Null);
            
            var installer = new Installer();
            var container = new WindsorContainer().Install(new CommonInstaller());
            installer.Install(container);

            var settingsProvider = container.Resolve<ISettingsProvider>();
            var parser = container.Resolve<IBirthNumberParser>();
            
            var inputArguments = new InputArguments(settingsProvider, parser);
            if (CommandLine.Parser.Default.ParseArguments(args, inputArguments))
            {
                var errors = inputArguments.Validate().ToList();
                if (errors.Any())
                {
                    System.Console.Error.WriteLine("Program could not create any request due to the following input errors:");
                    System.Console.Error.WriteLine();
                    System.Console.Error.WriteLine(string.Join(Environment.NewLine, errors));

                    return;
                }
            }
            else
            {
                return;
            }

            var inputSettingsProvider = new InputSettingsProvider(inputArguments);
            container.Register(Component.For<ISettingsProvider>().Instance(inputSettingsProvider).IsDefault().Named("InputSettingsProvider"));

            var typeHandlerSelector = container.Resolve<ITypeHandlerSelector>();
            var handler = typeHandlerSelector.SelectTypeHandler(inputArguments.Type);
            handler.HandleTypeAsync(inputArguments, originalOut).Wait();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles retrieving of multiple studies.
        /// </summary>
        /// <param name="inputArguments">Parsed program input arguments</param>
        /// <param name="writer">Writer the serialized result will be written into</param>
        /// <returns>Represents an asynchronous operation</returns>
        private async Task HandleMultipleStudies(InputArguments inputArguments, TextWriter writer)
        {
            IDicomQuery<StudyInfo> query;
            if (inputArguments.ParentIdentifier != null)
            {
                var patient = await mPatientInfoProvider.GetPatientByBirthNumberAsync(inputArguments.ParentIdentifier, inputArguments.UseCache);
                query = mStudyInfoProvider.GetStudiesForPatient(patient);
            }
            else
            {
                query = mStudyInfoProvider.GetStudies();
            }

            if (inputArguments.UseCache)
            {
                query = query.LoadFromCache();
            }

            await writer.WriteAsync(JsonConvert.SerializeObject(await query.ToListAsync()));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles retrieving of single study or downloading images for single study.
        /// </summary>
        /// <param name="inputArguments">Parsed program input arguments</param>
        /// <param name="writer">Writer the serialized result will be written into</param>
        /// <returns>Represents an asynchronous operation</returns>
        private async Task HandleSingleStudy(InputArguments inputArguments, TextWriter writer)
        {
            var study = await mStudyInfoProvider.GetStudyByIDAsync(inputArguments.Identifier, inputArguments.UseCache);

            if (inputArguments.Download)
            {
                await mStudyInfoProvider.DownloadImagesAsync(study);
            }
            else
            {
                await writer.WriteAsync(JsonConvert.SerializeObject(study));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles retrieving of multiple series.
        /// </summary>
        /// <param name="inputArguments">Parsed program input arguments</param>
        /// <param name="writer">Writer the serialized result will be written into</param>
        /// <returns>Represents an asynchronous operation</returns>
        private async Task HandleMultipleSeries(InputArguments inputArguments, TextWriter writer)
        {
            IDicomQuery<SeriesInfo> query;
            if (inputArguments.ParentIdentifier != null)
            {
                var study = await mStudyInfoProvider.GetStudyByIDAsync(inputArguments.ParentIdentifier, inputArguments.UseCache);
                query = mSeriesInfoProvider.GetSeriesForStudy(study);
            }
            else
            {
                query = mSeriesInfoProvider.GetSeries();
            }

            if (inputArguments.UseCache)
            {
                query = query.LoadFromCache();
            }

            await writer.WriteAsync(JsonConvert.SerializeObject(await query.ToListAsync()));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Handles retrieving of single series.
 /// </summary>
 /// <param name="inputArguments">Parsed program input arguments</param>
 /// <param name="writer">Writer the serialized result will be written into</param>
 /// <returns>Represents an asynchronous operation</returns>
 private async Task HandleSingleSeries(InputArguments inputArguments, TextWriter writer)
 {
     var series = await mSeriesInfoProvider.GetSeriesByIDAsync(inputArguments.Identifier, inputArguments.UseCache);
     await writer.WriteAsync(JsonConvert.SerializeObject(series));
 }