public async Task <IActionResult> Post(GetPrescriptionsParameter data) { data.UserId = Helpers.GetUserId(HttpContext.User); var prescriptions = await repo.GetPrescriptions(data); return(Ok(prescriptions)); }
public async Task <IEnumerable <Prescription> > GetPrescriptions(GetPrescriptionsParameter data) { string connectionString = configuration.GetConnectionString("Default"); var commandText = "dash.GetPrescriptions"; var command = new CommandDefinition(commandText, data, commandType: CommandType.StoredProcedure); IEnumerable <Prescription> prescriptions; try { using SqlConnection connection = new SqlConnection(connectionString); var dic = new Dictionary <int, Prescription>(); var result = await connection.QueryAsync <Prescription, Patient, Image, PrescriptionPharmacy, Prescription>(command, (prescription, patient, image, pharmacy) => { if (!dic.TryGetValue(prescription.Id, out Prescription p)) { p = prescription; p.Patient = patient; p.Images = new List <Image>(); p.Pharmacies = new List <PrescriptionPharmacy>(); dic.Add(p.Id, p); } if (image != null && !p.Images.Any(a => a.Id == image.Id)) { p.Images.Add(image); } if (pharmacy != null && !p.Pharmacies.Any(a => a.Id == pharmacy.Id)) { p.Pharmacies.Add(pharmacy); } return(p); }); prescriptions = result.Distinct(); } catch (Exception ex) { logger.LogError(ex.GetExceptionMessage()); prescriptions = null; } return(prescriptions); }
public Task <ListRidsHistoryResult> GetHistoryPrescriptions(GetPrescriptionsParameter parameter, CancellationToken token) { return(_recipeService.GetHistoryPrescriptions(parameter.PatientNiss, parameter.Page, parameter.Assertion)); }