public async Task <IActionResult> CreateBill(int id)
        {
            var prescription = await _prescriptionContext.Prescriptions.FirstAsync(m => m.Id == id);

            if (prescription == null)
            {
                return(NotFound());
            }

            List <PrescribedDrug> prescribedDrugs = _prescriptionContext.PrescribedDrugs.Where(p => p.PrescriptionId == id).ToList();

            foreach (PrescribedDrug pd in prescribedDrugs)
            {
                Drug drug = _drugContext.Drugs.First(d => d.Id == pd.DrugId);
                if (pd.Count > drug.Stock)
                {
                    HttpContext.Session.SetString(HomeController.PrescriptionFillValidation, "Not enough " + drug.MedicalName);
                    return(RedirectToAction("Details", new { id = id }));
                }
            }

            // send messages to insurance to get values back
            var res = SendPrescription(prescription, prescribedDrugs);

            if (res != null)
            {
                return(res);
            }

            prescription.SentToInsurance = null;
            _prescriptionContext.Prescriptions.Update(prescription);
            _prescriptionContext.SaveChanges();

            return(RedirectToAction("Details", new { id = id }));
        }
        public void ImportDataFromExcel()
        {
            string filename = @"medicine.xlsx";
            string FilePath = AppDomain.CurrentDomain.BaseDirectory + filename;
            //string FilePath = "C:\\Users\\aannr\\Desktop\\‏‏תיקיה חדשה\\prescription-management-system\\medicine.xlsx";
            _Application excel = new _Excel.Application();
            Workbook     wb    = excel.Workbooks.Open(FilePath);
            Worksheet    ws    = wb.Worksheets[1];

            string name = string.Empty, genericName = string.Empty, producer = string.Empty, active = string.Empty, properties = string.Empty, ndc = string.Empty;

            for (int i = 2; i < 1001; i++)
            {
                name        = Convert.ToString(ws.Cells[1][i].Value2);
                genericName = Convert.ToString(ws.Cells[2][i].Value2);
                producer    = Convert.ToString(ws.Cells[3][i].Value2);
                active      = Convert.ToString(ws.Cells[4][i].Value2);
                properties  = Convert.ToString(ws.Cells[5][i].Value2);
                ndc         = Convert.ToString(ws.Cells[7][i].Value2);
                using (var context = new PrescriptionContext())
                {
                    var medicine = new Medicine {
                        PortionProperties = properties, ActiveIngredients = active, GenericName = ndc, Name = name, Producer = producer
                    };
                    context.Medicines.Add(medicine);
                    context.SaveChanges();
                }
            }
        }
        public IActionResult Verify(int id)
        {
            Prescription prescription = _prescriptionContext.Prescriptions.First(p => p.Id == id);

            VerifiedPhysician physician = _verificationContext.VerifiedPhysicians.FirstOrDefault(p => p.Name == prescription.PhysicianName && p.LicenseNumber == prescription.PhysicianLicenseNumber);

            prescription.PhysicianVerified = physician != null;
            _prescriptionContext.Prescriptions.Update(prescription);
            _prescriptionContext.SaveChanges();

            return(RedirectToAction("Details", "Prescriptions", new { id = prescription.Id }));
        }
        public IActionResult Verify(int id)
        {
            Prescription prescription = _prescriptionContext.Prescriptions.First(p => p.Id == id);

            VerifiedPatient patient = _verificationContext.VerifiedPatients.FirstOrDefault(p => p.Name == prescription.PatientName && p.Address == prescription.PatientAddress && p.DateOfBirth == prescription.PatientDOB);

            prescription.PatientVerified = patient != null;
            _prescriptionContext.Prescriptions.Update(prescription);
            _prescriptionContext.SaveChanges();

            return(RedirectToAction("Details", "Prescriptions", new { id = prescription.Id }));
        }