Beispiel #1
0
        public IActionResult ImportPatientCredentials(ImportPatientCredentials importPatientCredentials)
        {
            // if all goes well, redirect to import patients with a success message
            // otherwise, r
            if (!CsvProcessor.IsCsv(importPatientCredentials.File))
            {
                ViewData["ErrorMessage"] = "Could not upload patients, the file provided was not a CSV file.";
                return(View(viewName: "ImportPatients"));
            }

            List <string>  errorMessages = new List <string>();
            List <Patient> patients      = CsvProcessor.ReadPatients(importPatientCredentials.File, errorMessages);

            // No patients parsed then return with errors. If there are patients parsed but the user does not want to upload
            // if there are errors, then simply return with errors
            if (patients.Count == 0 || (errorMessages.Count > 0 && !importPatientCredentials.UploadWithErrors))
            {
                ViewData["ErrorMessage"] = "No patients were uploaded, check the file matches the format required.";
                return(View(viewName: "ImportPatients"));
            }

            int successfulInserts = PatientProcessor.SavePatients(Patient.Convert(patients), errorMessages);

            if (errorMessages.Count != 0)
            {
                ViewData["ErrorMessages"] = errorMessages;
            }

            ViewData["SuccessMessage"] = $"{successfulInserts} Patients were uploaded successfully.";
            return(View(viewName: "ImportPatients"));
        }