コード例 #1
0
        private LoincLabDataEditModel GetLoincLabData(DataRow row)
        {
            var model = new LoincLabDataEditModel
            {
                MemberId    = GetRowValue(row, "MembID"),
                Gmpi        = GetRowValue(row, "GMPI"),
                Loinc       = GetRowValue(row, "LOINC"),
                ResultValue = GetRowValue(row, "ResultValue"),
                ResultUnits = GetRowValue(row, "ResultUnits"),
                RefRange    = GetRowValue(row, "RefRange"),
                DoS         = GetRowValue(row, "DOS")
            };

            //try
            //{
            //    model.LoincDescription = GetRowValue(row, "LOINCDesc");
            //}
            //catch (Exception ex)
            //{
            //   // _logger.Error("exception: " + exception.Message);
            //}

            return(model);
        }
コード例 #2
0
        public void Parse()
        {
            try
            {
                _logger.Info("Running Loinc Lab Data");

                if (!DirectoryOperationsHelper.CreateDirectoryIfNotExist(_settings.LoincLabDataPath))
                {
                    _logger.Info(string.Format("Folder could not be created. Please check path: {0} ", _settings.LoincLabDataPath));
                    return;
                }

                var loincMediaLocation = _mediaRepository.GetLoincMediaLocation();
                var archiveLocation    = _mediaRepository.GetLoincArchiveMediaLocation();

                var loincLabfiles = DirectoryOperationsHelper.GetFiles(_settings.LoincLabDataPath, "*.csv");
                if (loincLabfiles.IsNullOrEmpty())
                {
                    _logger.Info(string.Format("No csv file found at following location {0}", _settings.LoincLabDataPath));
                }
                else
                {
                    UploadLoincFiles(loincLabfiles, loincMediaLocation.PhysicalPath, (long)OutboundUploadType.LoincLabData);
                }

                var uploadedFiles = _outboundUploadRepository.GetAllUploadedFilesByType((long)OutboundUploadType.LoincLabData);
                if (uploadedFiles.IsNullOrEmpty())
                {
                    _logger.Info("No new files uploaded for Loinc Lab Data.");
                    return;
                }

                foreach (var uploadedFile in uploadedFiles)
                {
                    try
                    {
                        var file = GetFile(uploadedFile.FileId);

                        if (!System.IO.File.Exists(loincMediaLocation.PhysicalPath + file.Path))
                        {
                            _logger.Info("File not found : " + loincMediaLocation.PhysicalPath + file.Path);
                            continue;
                        }

                        uploadedFile.StatusId       = (long)OutboundUploadStatus.Parsing;
                        uploadedFile.ParseStartTime = DateTime.Now;
                        _outboundUploadRepository.Save(uploadedFile);

                        _logger.Info("Importing File : " + file.Path);

                        var loincLabData = _csvReader.ReadWithTextQualifierLargeData(loincMediaLocation.PhysicalPath + file.Path);

                        var csvStringBuilder = new StringBuilder();
                        csvStringBuilder.Append(LogHeader + Environment.NewLine);

                        long totalRows = 0, successRows = 0;

                        foreach (var dataTable in loincLabData)
                        {
                            if (dataTable.Rows.Count == 0)
                            {
                                _logger.Info("No records found for file : " + loincMediaLocation.PhysicalPath + file.Path);
                                continue;
                            }
                            foreach (DataRow row in dataTable.Rows)
                            {
                                totalRows++;
                                LoincLabDataEditModel model = null;

                                model = GetLoincLabData(row);

                                var errorRow = model.MemberId + "," + model.Gmpi + "," + model.Loinc + "," + model.LoincDescription + "," + model.ResultValue + "," + model.ResultUnits + "," + model.RefRange + "," + model.DoS;

                                try
                                {
                                    if (model != null && !model.IsEmpty())
                                    {
                                        var domain = new LoincLabData
                                        {
                                            MemberId         = model.MemberId,
                                            Gmpi             = model.Gmpi,
                                            Loinc            = model.Loinc,
                                            LoincDescription = model.LoincDescription,
                                            ResultValue      = model.ResultValue,
                                            ResultUnits      = model.ResultUnits,
                                            RefRange         = model.RefRange,
                                            DateOfService    = GetRowDateValue(model.DoS),
                                            Year             = DateTime.Today.Year,
                                            DateCreated      = DateTime.Now,
                                            UploadId         = uploadedFile.Id,
                                        };

                                        _loincLabDataRepository.Save(domain);
                                    }

                                    successRows++;
                                }
                                catch (Exception ex)
                                {
                                    _logger.Error(string.Format("Some Error Occurred Message: {0} \n stack Trace: {1}", ex.Message, ex.StackTrace));
                                    csvStringBuilder.Append(errorRow + "," + ex.Message + Environment.NewLine);
                                }
                            }
                        }

                        if (successRows < totalRows)
                        {
                            var logFileName = file.Path + "_Log.csv";

                            var logFile = SaveLogFile(_settings.LoincLabDataPath + logFileName, csvStringBuilder);
                            uploadedFile.LogFileId = logFile.Id;
                        }

                        uploadedFile.SuccessUploadCount = successRows;
                        uploadedFile.FailedUploadCount  = totalRows - successRows;
                        uploadedFile.ParseEndTime       = DateTime.Now;
                        uploadedFile.StatusId           = successRows > 0 ? (long)OutboundUploadStatus.Parsed : (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(uploadedFile);

                        if (successRows > 1)
                        {
                            System.IO.File.Move(loincMediaLocation.PhysicalPath + file.Path, archiveLocation.PhysicalPath + file.Path);
                            ((IFileRepository)_fileRepository).MarkasArchived(file.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        uploadedFile.StatusId = (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(uploadedFile);
                        _logger.Error(string.Format("while Parsing File"));
                        _logger.Error("Ex Message" + ex.Message);
                        _logger.Error("Ex Stack Trace " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while Parsing Loinc Lab Data Files.");
                _logger.Error(ex);
            }
        }