public DoctorPrescription() { InitializeComponent(); viewModel = new DoctorPrescriptionViewModel(); BindingContext = viewModel; viewModel.ButtonEvent += BeginButtonAnimation; }
public ResultViewModel Execute(DoctorPrescriptionViewModel prescription, int doctorId) { var result = new ResultViewModel(); try { if (!prescription.Medicines.Any()) { throw new Exception("Empty medicine list"); } var doctor = context.Doctors.First(d => d.ID == doctorId); var patient = context.Patients.First(p => p.ID == prescription.Patient.Id); var assignedMedicines = prescription.Medicines.Select(m => { var med = AutoMapper.Mapper.Map <AssignedMedicine>(m); med.StockMedicine = context.Medicines .First(c => c.ID == m.StockId); med.PricePerOne = m.PricePerOne * (1 - m.Refundation); return(med); }).ToList(); doctor.IssuedPresciptions.Add(new MedicalPrescription { Medicines = assignedMedicines, Doctor = doctor, Patient = patient, CreationTime = DateTime.Now, VerificationState = VerificationState.NotVerified }); context.SaveChanges(); } catch (Exception ex) { logger.LogError(ex, ex.Message); result.Succes = false; result.Message = ex.Message; } return(result); }
public IActionResult AddPrescription([FromBody] DoctorPrescriptionViewModel prescription) { var systemUser = userManager.GetUserAsync(User).Result; var doctor = context.Doctors.First(d => d.SystemUser.Id == systemUser.Id); ResultViewModel result = null; if (ModelState.IsValid && prescription.Medicines.Length > 0) { result = addPrescription.Execute(prescription, doctor.ID); } else { result = new ResultViewModel { Succes = false, Message = "Normy recepty nie zostały spełnione" }; } return(Json(result)); }
public void Should_Not_AddPrescription_No_Meds() { // given var expectedResult = false; var expectedPrescriptionCount = context.MedicalPrescriptions.Count(); var loggerMock = new Mock <ILogger <AddPrescriptionUseCase> >(); var useCase = new AddPrescriptionUseCase(context, loggerMock.Object); var doctor = context.Doctors.First(); var presc = new DoctorPrescriptionViewModel { Patient = Map <PatientViewModel>(context.Patients.First()), Medicines = new MedicineViewModel [] { } }; // when var actualResult = useCase.Execute(presc, doctor.ID); // then Assert.AreEqual(expectedResult, actualResult.Succes); Assert.AreEqual(expectedPrescriptionCount, context.MedicalPrescriptions.Count()); }
public DoctorPrescriptionView() { InitializeComponent(); viewModel = new DoctorPrescriptionViewModel(); BindingContext = viewModel; }