Example #1
0
        public async Task <bool> Handle(ExtractMnchArt request, CancellationToken cancellationToken)
        {
            //Extract
            int found = await _mnchArtSourceExtractor.Extract(request.Extract, request.DatabaseProtocol);

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

            //Load
            int loaded = await _mnchArtLoader.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, request.Extract);

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

            return(true);
        }
Example #2
0
        public async Task <bool> Handle(ExtractPatientMnch request, CancellationToken cancellationToken)
        {
            //Extract
            int found = await _patientSourceExtractor.Extract(request.Extract, request.DatabaseProtocol);

            //TODO Check for duplicate patients with SITE CODE
            var patientKeys = _tempPatientMnchExtractRepository.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 DuplicatePatientMnchException($"Duplicate patient(s) with PatientPK(s) {readDuplicates} found");
            }

            //Validate
            await _extractValidator.Validate(request.Extract.Id, found, nameof(PatientMnchExtract), $"{nameof(TempPatientMnchExtract)}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 MnchExtractActivityNotification(request.Extract.Id, new DwhProgress(
                                                        nameof(PatientMnchExtract),
                                                        nameof(ExtractStatus.Loaded),
                                                        found, loaded, rejected, loaded, 0)));

            return(true);
        }