public IActionResult Create([Bind("LastName,FirstName,DOB,Gender, RM2Number, PatientStatusId, DateOfDeath, PostCode, GenericNote")] Patient patient, PatientDiagnosis[] diagnoses, PatientDrug[] drugs, PatientSTGQuestionnaire[] sTGQuestionnaires, PatientImmunoglobulin[] patientImmunoglobulin, PatientRadiologyFinding[] patientRadiologyFinding, PatientMedicalTrial[] patientMedicalTrial, PatientDrugLevel[] drugLevels, PatientSurgery[] surgeries, PatientAllergicIntoleranceItem[] allergies, PatientPulmonaryFunctionTest[] patientPulmonaryFunctionTest, PatientNACDates patientNACDates, PatientMeasurement[] patientMeasurement, PatientMRCScore[] patientMRCScore, CaseReportFormResult[] caseReportFormResult, PatientSmokingDrinkingStatus patientSmokingDrinkingStatus) { var existingPatient = _context.Patients.FirstOrDefault(x => x.RM2Number == patient.RM2Number); patient.CaseReportFormResults = new List <CaseReportFormResult>(); _patientManager.Request = Request; CheckIsUnique(existingPatient); if (caseReportFormResult != null && caseReportFormResult.Length > 0 && caseReportFormResult[0].Results != null) { var results = caseReportFormResult[0].Results.ToArray(); _caseReportFormManager.CreateCaseReportFormForResults(patient, results); patient.CaseReportFormResults.Add(caseReportFormResult[0]); _caseReportFormManager.LockForm(caseReportFormResult[0].CaseReportFormId); } _patientManager.AddCollectionsFromFormToPatients(patient, ref diagnoses, ref drugs, ref sTGQuestionnaires, patientImmunoglobulin, ref patientRadiologyFinding); _patientManager.AddMedicalTrials(patient, patientMedicalTrial); _patientManager.AddDrugLevels(patient, drugLevels); _patientManager.AddPatientSurgeries(patient, surgeries); _patientManager.AddPatientAllergiesIntolerances(patient, allergies); _patientManager.AddPatientPFTs(patient, patientPulmonaryFunctionTest); _patientManager.AddPatientMeasurements(patient, patientMeasurement); _patientManager.AddMRCScores(patient, patientMRCScore); _patientManager.AddPatientNACDates(patient, patientNACDates); AddOrSkipSmokingStatus(patient, patientSmokingDrinkingStatus); try { if (ModelState.IsValid) { _context.Add(patient); _context.SaveChanges(); _externalImport.Add(ExternalPatient.BuildFromPatient(patient)); var externalPatient = new ExternalPatient(); _externalImport.SaveChanges(); return(Json(new { result = "ok" })); } else { Hashtable errors = ModelStateHelper.Errors(ModelState); return(Json(new { success = false, errors })); } } catch (DbUpdateException ex) { return(null); } }