public async Task TestResourceDoesNotExistShouldReturnErrorCode()
        {
            var interactor = new ReadResourceInteractor(new InMemoryFhirRepository(), new InMemorySearchRepository());
            var response   = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "kasfasagdssg", ResourceType = "Patient" });

            Assert.AreEqual(ResponseCode.ResourceNotFound, response.Code);
        }
        static DependencyResolver()
        {
            var iotaRepository = new CachedIotaRestRepository(
                new FallbackIotaClient(new List <string> {
                "https://nodes.devnet.thetangle.org:443"
            }, 5000),
                new PoWSrvService());

            var channelFactory      = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default);

            var encryption      = new RijndaelEncryption("somenicekey", "somenicesalt");
            var resourceTracker = new SqlLiteResourceTracker(channelFactory, subscriptionFactory, encryption);

            var fhirRepository = new IotaFhirRepository(
                iotaRepository,
                new FhirJsonTryteSerializer(),
                resourceTracker,
                new SqlLiteDeterministicSeedManager(
                    resourceTracker,
                    new IssSigningHelper(new Curl(), new Curl(), new Curl()),
                    new AddressGenerator(),
                    iotaRepository,
                    encryption));

            var fhirParser       = new FhirJsonParser();
            var searchRepository = new SqlLiteSearchRepository(fhirParser);

            CreateResourceInteractor   = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository);
            ReadResourceInteractor     = new ReadResourceInteractor(fhirRepository, searchRepository);
            ValidateResourceInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser);
            SearchResourcesInteractor  = new SearchResourcesInteractor(fhirRepository, searchRepository);
            ResourceTracker            = resourceTracker;
        }
 public FhirGlucoseService(
     CreateResourceInteractor createResourceInteractor,
     UpdateResourceInteractor updateResourceInteractor,
     ReadResourceInteractor readResourceInteractor,
     ISearchRepository searchRepository)
 {
     this.CreateResourceInteractor = createResourceInteractor;
     this.UpdateResourceInteractor = updateResourceInteractor;
     this.ReadResourceInteractor   = readResourceInteractor;
     this.SearchRepository         = searchRepository;
 }
        public async Task TestRepositoryThrowsExceptionShouldReturnErrorCode()
        {
            var repository = new Mock <IFhirRepository>();

            repository.Setup(r => r.ReadResourceAsync(It.IsAny <string>())).ThrowsAsync(new Exception());

            var interactor = new ReadResourceInteractor(repository.Object, new InMemorySearchRepository());
            var response   = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "kasfasagdssg", ResourceType = "Patient" });

            Assert.AreEqual(ResponseCode.Failure, response.Code);
        }
        /// <inheritdoc />
        protected override void Load(ContainerBuilder builder)
        {
            var connectionSupplier = new DefaultDbConnectionSupplier();
            var iotaRepository     = new CachedIotaRestRepository(
                new FallbackIotaClient(new List <string> {
                "https://nodes.devnet.thetangle.org:443"
            }, 5000),
                new PoWSrvService(),
                null,
                connectionSupplier,
                $"{DependencyResolver.LocalStoragePath}\\iotacache.sqlite");

            var channelFactory      = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default);

            var encryption      = new RijndaelEncryption("somenicekey", "somenicesalt");
            var resourceTracker = new SqlLiteResourceTracker(
                channelFactory,
                subscriptionFactory,
                encryption,
                connectionSupplier,
                $"{DependencyResolver.LocalStoragePath}\\iotafhir.sqlite");

            var seedManager = new SqlLiteDeterministicSeedManager(
                resourceTracker,
                new IssSigningHelper(new Curl(), new Curl(), new Curl()),
                new AddressGenerator(),
                iotaRepository,
                encryption,
                connectionSupplier,
                $"{DependencyResolver.LocalStoragePath}\\iotafhir.sqlite");

            var fhirRepository   = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, seedManager);
            var fhirParser       = new FhirJsonParser();
            var searchRepository = new SqlLiteSearchRepository(fhirParser, connectionSupplier, $"{DependencyResolver.LocalStoragePath}\\resources.sqlite");

            var createInteractor     = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository);
            var readInteractor       = new ReadResourceInteractor(fhirRepository, searchRepository);
            var validationInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser);
            var searchInteractor     = new SearchResourcesInteractor(fhirRepository, searchRepository);

            var resourceImporter = new ResourceImporter(searchRepository, fhirRepository, seedManager);

            builder.RegisterInstance(createInteractor);
            builder.RegisterInstance(readInteractor);
            builder.RegisterInstance(validationInteractor);
            builder.RegisterInstance(searchInteractor);
            builder.RegisterInstance(resourceImporter);
            builder.RegisterInstance(seedManager).As <ISeedManager>();
            builder.RegisterInstance(subscriptionFactory);
        }
Пример #6
0
        private void InjectDependencies(IServiceCollection services)
        {
            var iotaRepository = new CachedIotaRestRepository(
                new FallbackIotaClient(new List <string> {
                "https://nodes.devnet.thetangle.org:443"
            }, 5000),
                new PoWService(new CpuPearlDiver()));

            var channelFactory      = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default);

            var encryption      = new RijndaelEncryption("somenicekey", "somenicesalt");
            var resourceTracker = new SqlLiteResourceTracker(channelFactory, subscriptionFactory, encryption);

            var seedManager = new SqlLiteDeterministicSeedManager(
                resourceTracker,
                new IssSigningHelper(new Curl(), new Curl(), new Curl()),
                new AddressGenerator(),
                iotaRepository,
                encryption);

            var fhirRepository   = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, seedManager);
            var fhirParser       = new FhirJsonParser();
            var searchRepository = new SqlLiteSearchRepository(fhirParser);

            var createInteractor       = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository);
            var readInteractor         = new ReadResourceInteractor(fhirRepository, searchRepository);
            var readVersionInteractor  = new ReadResourceVersionInteractor(fhirRepository);
            var readHistoryInteractor  = new ReadResourceHistoryInteractor(fhirRepository);
            var capabilitiesInteractor = new GetCapabilitiesInteractor(fhirRepository, new AppConfigSystemInformation(this.Configuration));
            var validationInteractor   = new ValidateResourceInteractor(fhirRepository, fhirParser);
            var searchInteractor       = new SearchResourcesInteractor(fhirRepository, searchRepository);
            var deleteInteractor       = new DeleteResourceInteractor(fhirRepository, searchRepository);

            var resourceImporter = new ResourceImporter(searchRepository, fhirRepository, seedManager);

            services.AddScoped(provider => createInteractor);
            services.AddScoped(provider => readInteractor);
            services.AddScoped(provider => capabilitiesInteractor);
            services.AddScoped(provider => validationInteractor);
            services.AddScoped(provider => searchInteractor);
            services.AddScoped(provider => resourceImporter);
            services.AddScoped(provider => readVersionInteractor);
            services.AddScoped(provider => readHistoryInteractor);
            services.AddScoped(provider => deleteInteractor);

            services.AddScoped <ISeedManager>(provider => seedManager);
            services.AddSingleton <IMemoryCache>(new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptions()));
        }
        public async Task TestResourceTypeMismatchShouldReturnErrorCode()
        {
            var resource = FhirResourceProvider.Patient;

            resource.Id = "SOMEFHIRCONFORMID";

            var repository = new InMemoryFhirRepository();

            repository.Resources.Add(resource);

            var interactor = new ReadResourceInteractor(repository, new InMemorySearchRepository());
            var response   = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "SOMEFHIRCONFORMID", ResourceType = "Observation" });

            Assert.AreEqual(ResponseCode.ResourceNotFound, response.Code);
        }
        public async Task TestResourceExistsShouldReturnResourceAndSuccess()
        {
            var resource = FhirResourceProvider.Patient;

            resource.Id = "SOMEFHIRCONFORMID";

            var repository = new InMemoryFhirRepository();

            repository.Resources.Add(resource);

            var interactor = new ReadResourceInteractor(repository, new InMemorySearchRepository());
            var response   = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "SOMEFHIRCONFORMID", ResourceType = "Patient" });

            Assert.AreEqual(ResponseCode.Success, response.Code);
            Assert.IsTrue(response.Resource.IsExactly(resource));
        }
Пример #9
0
 public FhirController(
     CreateResourceInteractor createResourceInteractor,
     ReadResourceInteractor readResourceInteractor,
     GetCapabilitiesInteractor capabilitiesInteractor,
     ValidateResourceInteractor validateResourceInteractor,
     SearchResourcesInteractor searchResourcesInteractor,
     ReadResourceVersionInteractor readResourceVersionInteractor,
     ReadResourceHistoryInteractor readResourceHistoryInteractor,
     DeleteResourceInteractor deleteResourceInteractor)
 {
     this.CreateResourceInteractor      = createResourceInteractor;
     this.ReadResourceInteractor        = readResourceInteractor;
     this.CapabilitiesInteractor        = capabilitiesInteractor;
     this.ValidateResourceInteractor    = validateResourceInteractor;
     this.SearchResourcesInteractor     = searchResourcesInteractor;
     this.ReadResourceVersionInteractor = readResourceVersionInteractor;
     this.ReadResourceHistoryInteractor = readResourceHistoryInteractor;
     this.DeleteResourceInteractor      = deleteResourceInteractor;
 }
Пример #10
0
        public async Task RunAsync(int rounds)
        {
            var repository = new RestIotaRepository(
                new FallbackIotaClient(
                    new List <string>
            {
                "https://nodes.thetangle.org:443",
                "http://node04.iotatoken.nl:14265",
                "http://node05.iotatoken.nl:16265",
                "https://nodes.thetangle.org:443",
                "http://iota1.heidger.eu:14265",
                "https://nodes.iota.cafe:443",
                "https://potato.iotasalad.org:14265",
                "https://durian.iotasalad.org:14265",
                "https://turnip.iotasalad.org:14265",
                "https://nodes.iota.fm:443",
                "https://tuna.iotasalad.org:14265",
                "https://iotanode2.jlld.at:443",
                "https://node.iota.moe:443",
                "https://wallet1.iota.town:443",
                "https://wallet2.iota.town:443",
                "http://node03.iotatoken.nl:15265",
                "https://node.iota-tangle.io:14265",
                "https://pow4.iota.community:443",
                "https://dyn.tangle-nodes.com:443",
                "https://pow5.iota.community:443",
            },
                    5000),
                new PoWSrvService());

            var fhirRepository     = new IotaFhirRepository(repository, new FhirJsonTryteSerializer(), new InMemoryResourceTracker());
            var resourceInteractor = new CreateResourceInteractor(fhirRepository);
            var readInteractor     = new ReadResourceInteractor(fhirRepository);

            var measurement = new GlucoseMeasurementValue {
                GlucoseConcentrationMolL = 5.4f, BaseTime = DateTime.UtcNow
            };
            var resourceId = string.Empty;

            var n = 0;

            while (n < rounds)
            {
                n++;
                this.Tracker.Update(n);

                // The example sends an observation. Nevertheless it does not make a difference from a technical perspective
                // what resource is sent, as long as its size fits one IOTA transaction
                var response = await resourceInteractor.ExecuteAsync(new CreateResourceRequest { Resource = ObservationFactory.FromMeasurement(measurement) });

                if (string.IsNullOrEmpty(resourceId))
                {
                    resourceId = response.LogicalId;
                }
            }

            foreach (var trackingEntry in fhirRepository.ResultTimes)
            {
                this.Logger.Log($"Create: {trackingEntry.CreateTime:0000} | Attach: {trackingEntry.AttachTime:0000}");
            }

            await readInteractor.ExecuteAsync(new ReadResourceRequest { ResourceId = resourceId });

            foreach (var readEntry in fhirRepository.ReadTimes)
            {
                this.Logger.Log($"Read: {readEntry.ReadTime:0000}");
            }
        }
Пример #11
0
        /// <inheritdoc />
        protected override void Load(ContainerBuilder builder)
        {
            var iotaRepository = new RestIotaRepository(
                new FallbackIotaClient(new List <string> {
                "https://nodes.devnet.thetangle.org:443"
            }, 5000),
                new PoWService(new CpuPearlDiver()));

            var channelFactory      = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default);

            var encryption      = new RijndaelEncryption("somenicekey", "somenicesalt");
            var resourceTracker = new ResourceTracker(
                channelFactory,
                subscriptionFactory,
                encryption,
                $"{DependencyResolver.LocalStoragePath}\\resources.sqlite");

            var seedManager = new SeedManager(
                resourceTracker,
                new IssSigningHelper(new Curl(), new Curl(), new Curl()),
                new AddressGenerator(),
                iotaRepository,
                encryption,
                $"{DependencyResolver.LocalStoragePath}\\seedmanager.sqlite");

            var fhirRepository   = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, seedManager);
            var fhirParser       = new FhirJsonParser();
            var searchRepository = new SearchRepository($"{DependencyResolver.LocalStoragePath}\\search.sqlite");

            var createInteractor     = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository);
            var readInteractor       = new ReadResourceInteractor(fhirRepository, searchRepository);
            var validationInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser);
            var searchInteractor     = new SearchResourcesInteractor(fhirRepository, searchRepository);

            var resourceImporter = new ResourceImporter(searchRepository, fhirRepository, seedManager);

            builder.RegisterInstance(searchRepository).As <ISearchRepository>();
            builder.RegisterInstance(resourceTracker).As <IResourceTracker>();

            builder.RegisterInstance(createInteractor);
            builder.RegisterInstance(readInteractor);
            builder.RegisterInstance(validationInteractor);
            builder.RegisterInstance(searchInteractor);
            builder.RegisterInstance(resourceImporter);
            builder.RegisterInstance(seedManager).As <ISeedManager>();
            builder.RegisterInstance(subscriptionFactory);
            builder.RegisterInstance(fhirRepository).As <IFhirRepository>();
            builder.RegisterInstance(new AndroidLogout()).As <ILogout>();

            var backgroundWorker = new BackgroundWorkerService();

            var glucoseService = new FhirGlucoseService(
                new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository),
                new UpdateResourceInteractor(fhirRepository, fhirParser),
                new ReadResourceInteractor(fhirRepository, searchRepository),
                searchRepository);
            var glucoseRepository = new DexcomGlucoseManagementRepository(new RestClient("https://sandbox-api.dexcom.com"));

            //backgoundWorker.RegisterTaskWorker(new ContinuousGlucoseTaskWorker(glucoseService, glucoseRepository));
            backgroundWorker.RegisterTaskWorker(new AggregateGlucoseTaskWorker(glucoseService, glucoseRepository));
        }