public ActionResult GetPatientWithTests(PatientTestResponseModel responseModel) { var patient = patientService.GetAllPatients().ToList().Find(x => x.Id == responseModel.PatientId); if (patient != null) { var formulas = testService.GetFormulas().ToList(); patient.TestResults = testService.GetTestResultsFromView().Where(x => x.PatientId == patient.Id).ToList(); foreach (var testResult in patient.TestResults) { var formula = formulas.Find(x => x.TestId == testResult.OtherTestId); testResult.Formula = formula; if (patient.Gender.HasValue && patient.Gender == 2 && patient.AgeInYears > 13) //Female { testResult.NormalRange = GetNormalRange(testResult.OtherTestId)?.ValFemale; } else if (patient.AgeInYears < 3) //Neonatal { testResult.NormalRange = GetNormalRange(testResult.OtherTestId)?.ValNoenatal; } else if (patient.AgeInYears < 14) //Children { testResult.NormalRange = GetNormalRange(testResult.OtherTestId)?.ValChild; } testResult.TestGroup = testService.GetTestGroups().ToList()?.Find(x => x.Id == testResult.GroupId); testResult.TestGroupOrderId = (int)(testResult.TestGroup?.OrderNo); testResult.TestTitle = testService.GetTestTitles().ToList()?.Find(x => x.Id == testResult.TitleId); testResult.TestTitleOrderId = (int)(testResult.TestTitle?.OrderBy); testResult.OtherTest = testService.GetOtherTests().ToList()?.Find(x => x.Id == testResult.OtherTestId); testResult.OtherTestOrderId = (int)(testResult.OtherTest?.OrderBy); } responseModel.TestResults = patient.TestResults; if (responseModel != null) { return(Ok(GetResponse(ResponseType.OBJECT, ResponseStatusCode.SUCCESS, responseModel))); } else { return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "No patients found", "Please register a patient")))); } } else { throw new Exception("Patient does not exist"); } }