public async Task <IHttpActionResult> PostPrescription(PrescribeBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var patient = await userManager.FindByIdAsync(model.PatientId); if (patient == null) { return(NotFound()); } var medication = await db.Medication.FindAsync(new Guid(model.MedicationId)); if (medication == null) { return(NotFound()); } var prescription = new Prescription() { PrescriptionId = Guid.NewGuid(), Medication = medication, Dosage = model.Dosage, Frequency = model.Frequency, StartDate = model.StartDate, EndDate = model.EndDate, Notes = model.Notes, Patient = patient }; db.Prescription.Add(prescription); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (PrescriptionExists(prescription.PrescriptionId)) { return(Conflict()); } else { throw; } } return(Created("prescriptions/" + prescription.PrescriptionId, ToDto.PrescriptionToDto(prescription))); }
public async Task <IHttpActionResult> GetPrescriptions(string id) { var user = await _userManager.FindByIdAsync(id); if (user == null) { return(NotFound()); } var prescriptionsDto = new List <PrescriptionDto>(); foreach (var prescription in user.Prescriptions) { prescriptionsDto.Add(ToDto.PrescriptionToDto(prescription)); } return(Ok(prescriptionsDto)); }
public async Task <IHttpActionResult> GetPrescriptions(string providerId) { var provider = await userManager.FindByIdAsync(providerId); if (provider == null) { return(NotFound()); } List <PrescriptionDto> prescriptionsDto = new List <PrescriptionDto>(); foreach (var careTeam in provider.ProviderCareTeams) { foreach (var prescription in careTeam.Patient.Prescriptions) { prescriptionsDto.Add(ToDto.PrescriptionToDto(prescription)); } } return(Ok(prescriptionsDto)); }