Esempio n. 1
0
 public void SetUp()
 {
     _loader    = TestInitializer.ServiceProvider.GetService <IPatientLoader>();
     _extractor = TestInitializer.ServiceProvider.GetService <IPatientSourceExtractor>();
     _extract   = _extracts.First(x => x.Name.IsSameAs(nameof(PatientExtract)));
     _count     = _extractor.Extract(_extract, _protocol).Result;
 }
Esempio n. 2
0
        public void should_Extract(string name)
        {
            Assert.False(_extractsContext.TempPatientExtracts.Any());
            var extract = _extracts.First(x => x.Name.IsSameAs(name));

            var count = _extractor.Extract(extract, _protocol).Result;

            Assert.True(count > 0);
            _extractsContext = TestInitializer.ServiceProvider.GetService <ExtractsContext>();
            Assert.AreEqual(count, _extractsContext.TempPatientExtracts.Count());
            Log.Debug($"extracted {_extractsContext.TempPatientExtracts.Count()}");
        }
        public async Task <bool> Handle(ExtractPatient request, CancellationToken cancellationToken)
        {
            //Extract
            int found = await _patientSourceExtractor.Extract(request.Extract, request.DatabaseProtocol);

            //Check for duplicate patients
            var patientKeys = _tempPatientExtractRepository.GetAll().Select(k => k.PatientPK);
            var distinct    = new HashSet <int?>();
            var duplicates  = new HashSet <int?>();

            foreach (var key in patientKeys)
            {
                if (!distinct.Add(key))
                {
                    duplicates.Add(key);
                }
            }

            if (duplicates.Any())
            {
                var readDuplicates = string.Join(", ", duplicates.ToArray());
                throw new DuplicatePatientException($"Duplicate patient(s) with PatientPK(s) {readDuplicates} found");
            }

            //Validate
            await _extractValidator.Validate(request.Extract.Id, found, nameof(PatientExtract), $"{nameof(TempPatientExtract)}s");

            //Load
            int loaded = await _patientLoader.Load(request.Extract.Id, found, request.DatabaseProtocol.SupportsDifferential);

            int rejected =
                _extractHistoryRepository.ProcessRejected(request.Extract.Id, found - loaded, request.Extract);


            // _extractHistoryRepository.ProcessExcluded(request.Extract.Id, rejected,0);
            _extractHistoryRepository.ProcessExcluded(request.Extract.Id, rejected, request.Extract);

            //notify loaded
            DomainEvents.Dispatch(
                new ExtractActivityNotification(request.Extract.Id, new DwhProgress(
                                                    nameof(PatientExtract),
                                                    nameof(ExtractStatus.Loaded),
                                                    found, loaded, rejected, loaded, 0)));

            return(true);
        }
Esempio n. 4
0
        public async Task <bool> Handle(ExtractPatient request, CancellationToken cancellationToken)
        {
            //Extract
            int found = await _patientSourceExtractor.Extract(request.Extract, request.DatabaseProtocol);

            //Validate
            await _extractValidator.Validate(request.Extract.Id, found, nameof(PatientExtract), $"{nameof(TempPatientExtract)}s");

            //Load
            int loaded = await _patientLoader.Load(request.Extract.Id, found);

            int rejected = found - loaded;

            //notify loaded
            DomainEvents.Dispatch(
                new ExtractActivityNotification(request.Extract.Id, new DwhProgress(
                                                    nameof(PatientExtract),
                                                    nameof(ExtractStatus.Loaded),
                                                    found, loaded, rejected, loaded, 0)));

            return(true);
        }