public async Task <IActionResult> LoadValid(int?page, int pageSize) { try { var tempPatientExtracts = await _patientExtractRepository.GetAll(page, pageSize); return(Ok(tempPatientExtracts.ToList())); } catch (Exception e) { var msg = $"Error loading valid Patient Extracts"; Log.Error(msg); Log.Error($"{e}"); return(StatusCode(500, msg)); } }
public async Task <string> ExportToJSonAsync(string exportDir = "", IProgress <int> progress = null) { List <DwhManifest> currentManifests = new List <DwhManifest>(); _progress = progress; var parentFolder = ""; var folderToSaveTo = ""; var siteCode = 0; var patients = await Task.Run(() => _patientExtractRepository.GetAll().ToList()); _taskCount = patients.Count; if (_taskCount > 0) { currentManifests = CreateManifests(patients); var currentSite = currentManifests.FirstOrDefault(); if (null != currentSite) { siteCode = currentSite.SiteCode; } } if (string.IsNullOrWhiteSpace(exportDir)) { //save to My Documents folderToSaveTo = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } else { folderToSaveTo = exportDir; } folderToSaveTo = folderToSaveTo.HasToEndsWith(@"\"); parentFolder = $@"{folderToSaveTo}DWapi\Exports\".HasToEndsWith(@"\"); folderToSaveTo = $@"{parentFolder}{DateTime.Today:yyyyMMMdd}-{siteCode}\".HasToEndsWith(@"\"); bool exists = Directory.Exists(folderToSaveTo); if (!exists) { Directory.CreateDirectory(folderToSaveTo); } else { // Delete All Directory.Delete(folderToSaveTo, true); Directory.CreateDirectory(folderToSaveTo); } addManifest(folderToSaveTo, currentManifests); foreach (var p in patients) { var jsonPatient = JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); //Encode jsonPatient = Base64Encode(jsonPatient); await Task.Run(() => System.IO.File.WriteAllText($"{folderToSaveTo}{p.Id}.dwh", jsonPatient)); _progressValue++; ShowPercentage(_progressValue); } await ZipExtracts(folderToSaveTo); return(parentFolder); }