/* * Gets a requested report provided a given filter for the data corresponding to the * logged in patient */ public async Task <Report> GetReport(string userName, DateTime startDate, DateTime endDate, ReportType reportType) { var patientDetails = lapbaseNewContext.Patient.Where(p => p.Username == userName).FirstOrDefault(); byte imperialFlag = Convert.ToByte(lapbaseContext.TblUserApplicationData.Where(u => u.PatientId == patientDetails.PatientCode && u.OrganizationCode == patientDetails.OrganisationCode).Select(P => P.Imperial).FirstOrDefault()); Report result = new Report(); if (reportType == ReportType.EWL_WL) { var graphDetails = await GetPatientEWL_WL_GraphReport(patientDetails.PatientCode, patientDetails.OrganisationCode, startDate, endDate, imperialFlag); graphDetails.ForEach(res => result.AddEntry(res.EWL, "EWL (" + res.WeightMeasurment + ")", res.Weight, "Weight (" + res.WeightMeasurment + ")", res.strDateSeen)); //ToList<IReport>(); return(result); } else if (reportType == ReportType.BMI) { await lapbaseContext.TblPatientConsult.Where(p => p.PatientId == patientDetails.PatientCode && p.OrganizationCode == patientDetails.OrganisationCode && p.DateSeen >= startDate && p.DateSeen <= endDate) .OrderBy(p => p.DateSeen) .ForEachAsync(res => result.AddEntry(res.Bmiweight, ReportType.BMI.ToString(), new DateTimeOffset((DateTime)res.DateSeen).ToString("dd MMM yyyy"))); return(result); } else if (reportType == ReportType.Calorie) { await lapbaseNewContext.TaskInput.Where(p => p.PatientId == patientDetails.PatientCode && p.OrganizationCode == patientDetails.OrganisationCode && p.DateAssigned >= startDate && p.DateAssigned.Date <= endDate.Date) .OrderBy(p => p.DateAssigned) .ForEachAsync(res => result.AddEntry(res.CaloriesGained, "Calories Gained (kJ)", res.CaloriesLost, "Calories Lost (kJ)", res.DateAssigned.Date.ToString("dd MMM yyyy"))); return(result); } else// (reportType == ReportType.WeightLoss) UNUSED BLOCK { var graphDetails = await GetPatientEWL_WL_GraphReport(patientDetails.PatientCode, patientDetails.OrganisationCode, startDate, endDate, imperialFlag); graphDetails.ForEach(res => result.AddEntry(res.Weight, "Weight (" + res.WeightMeasurment + ")", res.strDateSeen)); //ToList<IReport>(); return(result); // return await GetWeightReport(patientId, organizationCode, startDate, endDate); } }