public PrescriptionModel(mp_prescription prescription, mp_pharmacy mp_pharmacy) { id = prescription.id; profile_id = prescription.profile_id; created_at = prescription.created_at; comment = prescription.comment; clinician_id = prescription.clinician_id; if (prescription.pharmacy_id.HasValue) { pharmacy = mp_pharmacy.name; pharmacy_email = mp_pharmacy.email; pharmacy_address = mp_pharmacy.address; pharmacy_phone = mp_pharmacy.phone; } clinician = new DoctorModel(prescription.clinician_); profile = new MemberModel(prescription.profile_); drugs = new List <DrugModel>(); foreach (var drug in prescription.mp_prescription_drug) { drugs.Add(new DrugModel(drug)); } drug_count = drugs.Count; }
public long AddPrescription(mp_prescription prescription) { prescription.created_at = DateTime.Now; _context.mp_prescription.Add(prescription); _context.SaveChanges(); return(prescription.id); }
public async Task <IActionResult> PostPrescription(mp_prescription prescription) { var user_id = _userManager.GetUserId(HttpContext.User); var clinician = _clinicianService.Get().FirstOrDefault(e => e.user_id == user_id); prescription.clinician_id = clinician.id; prescription.created_by = user_id; var prescription_id = _prescriptionService.AddPrescription(prescription); var collection = Request.Form; var drugs = collection["drug"].ToList(); var dosages = collection["dosage"].ToList(); var drug_text = ""; var prescription_drugs = new List <mp_prescription_drug>(); for (var i = 0; i < drugs.Count; i++) { prescription_drugs.Add(new mp_prescription_drug { drug = drugs[i], dosage = dosages[i], prescription_id = prescription_id }); drug_text += drugs[i] + " " + dosages[i] + ","; } _prescriptionService.AddPrescriptionDrugs(prescription_drugs); //get the profile information var profile = _profileService.Get(prescription.profile_id); var notification = new mp_notification { created_by = "sys_admin", created_by_name = "System Admin", notification_type = 7, read = 0, user_id = profile.user_id, notification = "Hi " + profile.last_name + " " + profile.first_name + ", Your prescription information has been updated, check your prescriptions for the details.", title = "New Prescription" }; NotificationUtil.Add(notification); await _emailSender.SendEmailAsync(profile.email, "New Prescription - MySpace MyTime", $"Hi " + profile.last_name + " " + profile.first_name + ", Your prescription information has been updated, check your prescriptions for the details."); if (prescription.pharmacy_id.HasValue) { //get the email of the pharmacy var pharmacy = _pharmacyService.Get().FirstOrDefault(e => e.id == prescription.pharmacy_id.Value); if (pharmacy != null && !string.IsNullOrEmpty(pharmacy.email)) { await _emailSender.SendEmailAsync(profile.email, "New Prescription - MySpace MyTime", $"The following prescriptions have been sent for " + profile.last_name + " " + profile.first_name + " - " + profile.unique_id.ToString("D10") + " .<br/>" + drug_text); } } return(Ok(200)); }