Beispiel #1
0
 public static PrescriptionDto PrescriptionToDto(Prescription prescription)
 {
     var prescriptionDto = new PrescriptionDto();
     prescriptionDto.InjectFrom(prescription);
     prescriptionDto.MedicationName = prescription.Medication.GenericName;
     prescriptionDto.MedicationCode = prescription.Medication.Code;
     prescriptionDto.PatientName = prescription.Patient.FirstName + " " + prescription.Patient.LastName;
     return prescriptionDto;
 }
 private bool PrescriptionAssigned(Prescription p, ApplicationUser user)
 {
     return user.Prescriptions.Contains(p);
 }
        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));
        }