Пример #1
0
        public async Task SearchTest()
        {
            var movies = new List <Prescription>
            {
                new Prescription()
                {
                    PatientName = "Dias"
                },
                new Prescription()
                {
                    PatientName = "Said"
                },
            };

            var fakeRepositoryMock = new Mock <IPrescriptionRepository>();

            fakeRepositoryMock.Setup(x => x.GetPrescriptionWithPredicate(It.IsAny <Expression <Func <Prescription, bool> > >())).ReturnsAsync(movies);


            var prescriptionService = new PrescriptionService(fakeRepositoryMock.Object);

            var resultPrescriptions = await prescriptionService.Search("Dias");

            Assert.Collection(resultPrescriptions, prescription =>
            {
                Assert.Equal("Dias", prescription.PatientName);
            },
                              prescription =>
            {
                Assert.Equal("Said", prescription.PatientName);
            });
        }
Пример #2
0
        public async Task GetPrescriptionsTest()
        {
            var prescriptions = new List <Prescription>
            {
                new Prescription()
                {
                    PatientName = "Said", Instruction = "Not for a child", Frequency = "2 times a day"
                },
                new Prescription()
                {
                    PatientName = "Said", Instruction = "Not for a child", Frequency = "2 times a day"
                },
            };

            var fakeRepositoryMock = new Mock <IPrescriptionRepository>();

            fakeRepositoryMock.Setup(x => x.GetPrescriptions()).ReturnsAsync(prescriptions);


            var prescriptionService = new PrescriptionService(fakeRepositoryMock.Object);

            var resultPrescriptions = await prescriptionService.GetPrescriptions();

            Assert.Collection(resultPrescriptions, prescription =>
            {
                Assert.Equal("Said", prescription.PatientName);
            },
                              prescription =>
            {
                Assert.Equal("Not for a child", prescription.Instruction);
            });
        }
Пример #3
0
        public void Find_Prescriptions_With_Empty_Search()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.AdvancedSearchPrescriptions(new PrescriptionAdvancedSearchDto("", "", new string[] { }, new string[] { }, new string[] { }));

            foundPrescriptions.ShouldNotBeEmpty();
        }
Пример #4
0
        public void Find_No_Matching_Prescriptions()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.AdvancedSearchPrescriptions(new PrescriptionAdvancedSearchDto("medicines", "Medicine Name23", new string[] { }, new string[] { }, new string[] { }));

            foundPrescriptions.ShouldBeEmpty();
        }
Пример #5
0
        public void Not_Found_Prescriptions_With_Medicines_Searh_Parameter()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> searchResult = service.FindPrescriptionsForMedicamentsParameter(1, "Kafetin");

            Assert.Empty(searchResult);
        }
Пример #6
0
        public void Find_No_Prescription_By_AppointmentId()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            Prescription foundPrescriptions = service.GetPrescriptionsForAppointment(2);

            foundPrescriptions.ShouldBeNull();
        }
Пример #7
0
        public void Find_Prescriptions()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.AdvancedSearchPrescriptions(new PrescriptionAdvancedSearchDto("medicines", "Medicine Name", new string[] { }, new string[] { }, new string[] { }));

            foundPrescriptions.ShouldHaveSingleItem();
        }
Пример #8
0
        public void Find_Prescriptions_Using_Simple_Search()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> searchResult = service.FindPrescriptionsUsingSimpleSearch(1, "Milan", "2020-08-12", "lekove", "Brufen");

            Assert.NotEmpty(searchResult);
        }
Пример #9
0
        public void Not_Found_Prescriptions_With_Comment_Searh_Parameter()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> searchResult = service.FindPrescriptionsForCommentParameter(1, "Bolnica");

            Assert.Empty(searchResult);
        }
Пример #10
0
        public void Not_Found_Prescriptions_With_Date_Searh_Parameter()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> searchResult = service.FindPrescriptionsForDateParameter(1, "2021-12-23");

            Assert.Empty(searchResult);
        }
Пример #11
0
        public ActionResult <IEnumerable <Prescription> > Get()
        {
            var service = new PrescriptionService();

            var prescriptions = service.GetAll();

            return(Ok(prescriptions));
        }
Пример #12
0
        public void Find_Prescriptions_With_Doctor_Searh_Parameter()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> searchResult = service.FindPrescriptionsForDoctorParameter(1, "Milan");

            Assert.NotEmpty(searchResult);
        }
Пример #13
0
        public void Find_Prescriptions_With_Empty_Search()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.SimpleSearchPrescriptions(new PrescriptionSearchDto("", "", "", ""));

            foundPrescriptions.ShouldNotBeEmpty();
        }
Пример #14
0
        public void Find_No_Matching_Prescriptions()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.SimpleSearchPrescriptions(new PrescriptionSearchDto("", "False", "", ""));

            foundPrescriptions.ShouldBeEmpty();
        }
Пример #15
0
        public void Find_Prescriptions()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.SimpleSearchPrescriptions(new PrescriptionSearchDto("Medicine Name", "", "Comment", ""));

            foundPrescriptions.ShouldHaveSingleItem();
        }
Пример #16
0
        public ActionResult <Prescription> Post([FromBody] Prescription prescription)
        {
            var service = new PrescriptionService();

            service.Store(prescription);

            return(prescription);
        }
Пример #17
0
        public async Task DeleteTest()
        {
            var fakeRepository      = Mock.Of <IPrescriptionRepository>();
            var prescriptionService = new PrescriptionService(fakeRepository);

            var prescription = new Prescription()
            {
                PatientName = "Dias", Instruction = "Not for a child", Frequency = "2 times a day"
            };
            await prescriptionService.Delete(prescription);
        }
Пример #18
0
        public ActionResult <Prescription> Get(long id)
        {
            var service = new PrescriptionService();

            var prescription = service.GetID(id);

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

            return(prescription);
        }
Пример #19
0
 private App()
 {
     EmailVerificationService = new EmailVerificationService();
     SftpService               = new SftpService();
     HttpService               = new HttpService();
     TenderService             = new TenderService();
     MedicalExaminationService = new MedicalExaminationService(
         new MedicalExaminationRepository(new MySQLStream <MedicalExamination>(), new IntSequencer()));
     PatientFeedbackService = new PatientFeedbackService(
         new PatientFeedbackRepository(new MySQLStream <PatientFeedback>(), new IntSequencer()));
     MedicalExaminationReportService = new MedicalExaminationReportService(
         new MedicalExaminationReportRepository(new MySQLStream <MedicalExaminationReport>(), new IntSequencer()));
     PrescriptionService = new PrescriptionService(
         new PrescriptionRepository(new MySQLStream <Prescription>(), new IntSequencer()));
     MedicalRecordService = new MedicalRecordService(
         new MedicalRecordRepository(new MySQLStream <MedicalRecord>(), new IntSequencer()), EmailVerificationService);
     QuestionService = new QuestionService(
         new QuestionRepository(new MySQLStream <Question>(), new IntSequencer()));
     AnswerService = new AnswerService(
         new AnswerRepository(new MySQLStream <Answer>(), new IntSequencer()), QuestionService);
     AllergiesService = new AllergiesService(
         new AllergiesRepository(new MySQLStream <Allergies>(), new IntSequencer()));
     PatientService = new PatientService(
         new PatientRepository(new MySQLStream <Patient>(), new IntSequencer()));
     SurveyService = new SurveyService(
         new SurveyRepository(new MySQLStream <Survey>(), new IntSequencer()), MedicalExaminationService, AnswerService);
     DoctorService = new DoctorService(
         new DoctorRepository(new MySQLStream <Doctor>(), new IntSequencer()));
     ReportService = new ReportService(
         new ReportRepository(new MySQLStream <Report>(), new IntSequencer()), SftpService);
     DoctorWorkDayService = new DoctorWorkDayService(
         new DoctorWorkDayRepository(new MySQLStream <DoctorWorkDay>(), new IntSequencer()), DoctorService);
     SpetialitationService = new SpetialitationService(
         new SpecialitationRepository(new MySQLStream <Specialitation>(), new IntSequencer()));
     AppointmentService = new AppointmentService(
         new AppointmentRepository(new MySQLStream <Appointment>(), new IntSequencer()), PatientService);
     EPrescriptionService = new EPrescriptionService(
         new EPrescriptionRepository(new MySQLStream <EPrescription>(), new IntSequencer()), SftpService);
     PharmacyService = new PharmacyService(
         new PharmacyRepository(new MySQLStream <Pharmacies>(), new IntSequencer()));
     RoomService = new RoomService(
         new RoomRepository(new MySQLStream <Room>(), new IntSequencer()));
     ManagerService = new ManagerService(
         new ManagerRepository(new MySQLStream <Manager>(), new IntSequencer()));
     SecretaryService = new SecretaryService(
         new SecretaryRepository(new MySQLStream <Secretary>(), new IntSequencer()));
     SystemAdministratorService = new SystemAdministratorService(
         new SystemAdministratorRepository(new MySQLStream <SystemAdministrator>(), new IntSequencer()));
     UserService = new UserService(
         new UserRepository(new MySQLStream <User>(), new IntSequencer()), PatientService, SystemAdministratorService);
 }
Пример #20
0
        public void Find_Prescriptions_With_Doctor_And_Date_Searh_Parameter()
        {
            PrescriptionService         service             = new PrescriptionService(CreateStubRepository());
            Dictionary <string, string> parametersForSearch = new Dictionary <string, string>();
            List <string> logicOperators = new List <string>();

            parametersForSearch.Add("Doktoru", "Milan");
            parametersForSearch.Add("Datumu", "2020-10-05");
            logicOperators.Add("I");

            List <Prescription> searchResult = service.FindPrescriptionsUsingAdvancedSearch(1, parametersForSearch, logicOperators);

            searchResult.ShouldNotBeEmpty();
        }
Пример #21
0
        public void Find_No_Prescriptions_AND()
        {
            PrescriptionService service = new PrescriptionService(CreateStubRepository());

            List <Prescription> foundPrescriptions = service.AdvancedSearchPrescriptions(new PrescriptionAdvancedSearchDto("medicines", "Medicine Name", new string[1] {
                "comment"
            }, new string[1] {
                "Comment23"
            }, new string[1] {
                "and"
            }));

            foundPrescriptions.ShouldBeEmpty();
        }
Пример #22
0
        public void Find_Prescriptions_With_Comment_Or_Medicaments_Searh_Parameter()
        {
            PrescriptionService         service             = new PrescriptionService(CreateStubRepository());
            Dictionary <string, string> parametersForSearch = new Dictionary <string, string>();
            List <string> logicOperators = new List <string>();

            parametersForSearch.Add("Sadržaju", "Redovno");
            parametersForSearch.Add("Lekovima", "Brufen");
            logicOperators.Add("ILI");

            List <Prescription> searchResult = service.FindPrescriptionsUsingAdvancedSearch(1, parametersForSearch, logicOperators);

            searchResult.ShouldNotBeEmpty();
        }
Пример #23
0
        public void PrescriptionExistsTest()
        {
            int UserId = 1;

            var fakeRepositoryMock = new Mock <IPrescriptionRepository>();

            fakeRepositoryMock.Setup(x => x.PrescriptionExists(UserId)).Returns(true);

            var prescriptionService = new PrescriptionService(fakeRepositoryMock.Object);

            var isExist = prescriptionService.PrescriptionExists(UserId);

            Assert.True(isExist);
        }
Пример #24
0
        public ActionResult Delete(long id)
        {
            var service = new PrescriptionService();

            var prescription = service.GetID(id);

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

            service.Delete(prescription);

            return(Ok());
        }
Пример #25
0
        public ActionResult <Prescription> Put(long id, [FromBody] Prescription prescription)
        {
            var service = new PrescriptionService();

            if (service.GetID(id) == null)
            {
                return(NotFound());
            }

            prescription.PrescriptionID = id;

            service.Store(prescription);

            return(prescription);
        }
Пример #26
0
        public static void Test()
        {
            try
            {
                Console.WriteLine("Connecting to database...");
                using (var init = new InitDatabaseService())
                {
                    Console.WriteLine("Connection successful.\nResetting the database...");
                    init.Reset();
                    Console.WriteLine("Reset successful.\nLoading data...");

                    //create dummy pharmacy
                    Pharmacy pharm = new Pharmacy(1, "CSV Pharmacy", "19187661052", "1400 chrissartin street");
                    using (var service = new PharmacyService())
                    {
                        service.Create(pharm);
                    }
                    //create dummy patient
                    Patient patient  = new Patient(1, "Chris", "Sartin", new DateTime(2000, DateTime.Today.Month, DateTime.Today.Day), "77777", "19183994836", "*****@*****.**", pharm);
                    Patient patient1 = new Patient(2, "Matthew", "Miller", new DateTime(2000, DateTime.Today.Month, DateTime.Today.Day), "8675309", "19187661052", "*****@*****.**", pharm);

                    using (var service = new PatientService())
                    {
                        service.Create(patient);
                        service.Create(patient1);
                    }
                    //create dummy drug
                    Drug drug = new Drug(1, "Taco Medication");
                    using (var service = new DrugService())
                    {
                        service.Create(drug);
                    }
                    //create dummy prescription
                    Prescription prescription  = new Prescription(1, patient, drug, 7, 7);
                    Prescription prescription1 = new Prescription(2, patient1, drug, 6, 6);

                    using (var service = new PrescriptionService())
                    {
                        service.Create(prescription);
                        service.Create(prescription1);
                    }
                    EventRefill RefillEvent;

                    //create dummy event
                    using (var service = new EventService())
                    {
                        //create dummy eventRefill
                        Event Event  = new Event(patient, "this is a message", EventStatus.ToSend, EventType.REFILL);
                        Event Event1 = new Event(patient, "refill test event", EventStatus.Sent, EventType.REFILL);
                        Event Event2 = new Event(patient1, "this is a test", EventStatus.Fill, EventType.REFILL);
                        RefillEvent = new EventRefill(prescription, Event);
                        EventRefill RefillEvent1 = new EventRefill(prescription1, Event1);
                        EventRefill RefillEvent2 = new EventRefill(prescription1, Event2);
                        using (var service2 = new EventRefillService())
                        {
                            service.Create(Event);
                            service2.Create(RefillEvent);

                            service.Create(Event1);
                            service2.Create(RefillEvent1);

                            service.Create(Event2);
                            service2.Create(RefillEvent2);
                        }

                        //create dummy birthdayevent
                        Event BirthdayEvent = new Event(patient, "this is a message", EventStatus.ToSend, EventType.BIRTHDAY);
                        service.Create(BirthdayEvent);

                        //create dummy recallevent
                        Event = new Event(patient, "this is a message", EventStatus.ToSend, EventType.REFILL);
                        EventRecall RecallEvent = new EventRecall(Event);
                        using (var service2 = new EventRecallService())
                        {
                            service.Create(Event);
                            service2.Create(RecallEvent);
                        }

                        //create dummy eventhistory
                        EventHistory history = new EventHistory(Event, EventStatus.InActive, new DateTime(2000, 7, 14));
                        using (var service2 = new EventHistoryService())
                        {
                            service2.Create(history);
                        }
                    }

                    //create dummy pharmacist in the pharmacy
                    Pharmacist pharmacist  = new Pharmacist("James", "Taco", "*****@*****.**", "18884443333", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist1 = new Pharmacist("Matthew", "Miller", "*****@*****.**", "19187661052", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist2 = new Pharmacist("Luke", "Thorne", "*****@*****.**", "14056932048", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist3 = new Pharmacist("Emily", "Pielemeier", "*****@*****.**", "13177536066", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist4 = new Pharmacist("Tom", "Hartnett", "*****@*****.**", "14696671743", new byte[] { 0 }, new byte[] { 0 });

                    using (var service = new PharmacistService())
                    {
                        service.Create(pharmacist);
                        service.Create(pharmacist1);
                        service.Create(pharmacist2);
                        service.Create(pharmacist3);
                        service.Create(pharmacist4);
                    }


                    //create dummy fillhistory
                    FillHistory fill = new FillHistory(RefillEvent, pharmacist, new DateTime(2000, 7, 14));
                    using (var service = new FillHistoryService())
                    {
                        service.Create(fill);
                    }

                    //create dummy sysadmins (us)
                    SystemAdmin admin  = new SystemAdmin("testing", "the stuff", "*****@*****.**", "19184661052", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin1 = new SystemAdmin("Tom", "Hartnett", "*****@*****.**", "14696671743", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin2 = new SystemAdmin("Luke", "Thorne", "*****@*****.**", "14056932048", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin3 = new SystemAdmin("Jon", "Hartnett", "*****@*****.**", "14696671064", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin4 = new SystemAdmin("Emily", "Pielemeier", "*****@*****.**", "13177536066", new byte[] { 0 }, new byte[] { 0 });
                    using (var service = new SystemAdminService())
                    {
                        service.Create(admin);
                        service.Create(admin1);
                        service.Create(admin2);
                        service.Create(admin3);
                        service.Create(admin4);
                    }

                    //create dummy job
                    Job job = new Job(pharm, pharmacist, true, false);
                    using (var service = new JobService())
                    {
                        service.Create(job);
                        Job j1 = new Job(pharm, pharmacist1, true, true);
                        service.Create(j1);
                        Job j2 = new Job(pharm, pharmacist2, true, true);
                        service.Create(j2);
                        Job j3 = new Job(pharm, pharmacist3, true, true);
                        service.Create(j3);
                        Job j4 = new Job(pharm, pharmacist4, true, true);
                        service.Create(j4);
                    }

                    init.LoadFromFile(@"..\..\App_Data\Scrubbed_Data.xlsx - Sheet1.csv", pharm);
                    Console.WriteLine("Loading data successful.\nAll tests successful...");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadKey();
            }
        }
Пример #27
0
 public PrescriptionController(MyDbContext dbContext)
 {
     this.dbContext      = dbContext;
     PrescriptionService = new PrescriptionService(new PrescriptionRepository(dbContext));
 }
 /// <summary>This constructor injects the PrescriptionController with matching PrescriptionService.</summary>
 public PrescriptionController()
 {
     PrescriptionService = new PrescriptionService(new PrescriptionRepository());
 }
Пример #29
0
        static void Main(string[] args)
        {
            MedicineService     medicineService     = new MedicineService();
            PrescriptionService prescriptionService = new PrescriptionService();
            OrderService        orderService        = new OrderService();

            string command = " ";

            do
            {
                Menu.ShowMainMenu();
                command = Console.ReadLine();
                switch (command)
                {
                case "1":     // MEDICINE

                    do
                    {
                        Menu.ShowPharmacyMenu();
                        command = Console.ReadLine();
                        switch (command)
                        {
                        case "1":         // SHOW MEDICINE
                            var list = medicineService.GetMedicines();

                            Menu.ShowMedicinesHeader();
                            foreach (var row in list)
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.Append($"{row.Id.ToString().PadRight(4, ' ')} | ");
                                sb.Append($"{row.Name.PadRight(15, ' ')} | ");
                                sb.Append($"{row.Manufacturer.PadRight(15, ' ')} | ");
                                sb.Append($"{row.Price.ToString().PadRight(10, ' ')} | ");
                                sb.Append($"{row.Amount.ToString().PadRight(10, ' ')} | ");
                                sb.Append($"{row.WithPrescription.ToString().PadRight(10, ' ')} | ");
                                Console.WriteLine((sb));
                            }

                            Menu.GreenText("\nNaciśnij dowolny klawisz aby powrócić do poprzedniego menu");
                            Console.ReadKey();
                            break;

                        case "2":         // ADD MEDICINE

                            Menu.GreenText("Podaj nazwę leku");
                            var name = Console.ReadLine();
                            Menu.GreenText("Podaj producenta leku");
                            var manufacturer = Console.ReadLine();
                            Menu.GreenText("Podaj cenę leku (000.00)");
                            var price = DecimalParse(Console.ReadLine());
                            Menu.GreenText("Podaj ilość (000.00)");
                            var amount = DecimalParse(Console.ReadLine());
                            Menu.GreenText("Czy lek jest na receptę (Y/N)");
                            var withPrescription = TrueOrFalse(Console.ReadLine());
                            var id = 0;
                            medicineService.AddMedicine(id, name, manufacturer, price, amount,
                                                        withPrescription);
                            break;

                        case "3":         // EDIT MEDICINE
                            var commandEdit = " ";
                            do
                            {
                                Menu.GreenText("Wpisz ID leku który chcesz edytować");
                                var medicineId = IntParse(Console.ReadLine());
                                var existId    = Exist(medicineId);
                                Menu.ShowMedicinesHeader();
                                var list2 = medicineService.GetMedicinesById(existId);
                                foreach (var row in list2)
                                {
                                    StringBuilder sb = new StringBuilder();
                                    sb.Append($"{row.Id.ToString().PadRight(4, ' ')} | ");
                                    sb.Append($"{row.Name.PadRight(15, ' ')} | ");
                                    sb.Append($"{row.Manufacturer.PadRight(15, ' ')} | ");
                                    sb.Append($"{row.Price.ToString().PadRight(10, ' ')} | ");
                                    sb.Append($"{row.Amount.ToString().PadRight(10, ' ')} | ");
                                    sb.Append($"{row.WithPrescription.ToString().PadRight(10, ' ')} | ");
                                    Console.WriteLine((sb));
                                }

                                Menu.ShowMedicinesManagement();
                                commandEdit = Console.ReadLine();
                                switch (commandEdit)
                                {
                                case "1":             // EDIT NAME
                                    Menu.GreenText("Wpisz nową nazwę:");
                                    var nameName = Console.ReadLine();
                                    medicineService.EditName(medicineId, nameName);
                                    commandEdit = "9";
                                    break;

                                case "2":             // EDIT MANUFACTURER
                                    Menu.GreenText("Wpisz nowego producenta:");
                                    var nameManuf = Console.ReadLine();
                                    medicineService.EditManufacturer(medicineId, nameManuf);
                                    commandEdit = "9";
                                    break;

                                case "3":             // EDIT PRICE
                                    Menu.GreenText("Wpisz nową cenę:");
                                    var namePrice = DecimalParse(Console.ReadLine());
                                    medicineService.EditPrice(medicineId, namePrice);
                                    commandEdit = "9";
                                    break;

                                case "4":             // EDIT AMOUNT
                                    Menu.GreenText("Wpisz nową ilość:");
                                    var nameAmount = DecimalParse(Console.ReadLine());
                                    medicineService.EditAmount(medicineId, nameAmount);
                                    commandEdit = "9";
                                    break;

                                case "5":             // EDIT PRESCRIPION
                                    Menu.GreenText("Wpisz czy wymagana recepta (Y/N):");
                                    var namePresc = TrueOrFalse(Console.ReadLine());
                                    medicineService.EditWithPrescription(medicineId, namePresc);
                                    commandEdit = "9";
                                    break;
                                }
                            } while (commandEdit != "9");


                            break;

                        case "4":         // REMOVE MEDICINE

                            Menu.GreenText("Wpisz ID leku do usunięcia:");
                            var removeId = IntParse(Console.ReadLine());
                            medicineService.RemoveMedicine(removeId);
                            break;
                        }
                    } while (command != "9");

                    break;

                case "2":     // SALE

                    do
                    {
                        Menu.ShowSaleMenu();
                        command = Console.ReadLine();
                        switch (command)
                        {
                        case "1":         // NEW ORDER
                            do
                            {
                                Menu.ShowPrescriptionMenu();
                                command = Console.ReadLine();
                                switch (command)
                                {
                                case "1":             // With Prescription
                                    Console.WriteLine("Podaj PESEL klienta");
                                    var clientPesel = Console.ReadLine();
                                    var clientName  = "";
                                    if (!prescriptionService.IsExistPrescriptionUser(clientPesel))
                                    {
                                        Menu.GreenText("Podaj imię i nazwisko klienta");
                                        clientName = Console.ReadLine();
                                    }
                                    else
                                    {
                                        clientName =
                                            prescriptionService.GetPrescriptionClientName(clientPesel);
                                    }

                                    Menu.GreenText("Podaj numer recepty");
                                    var clientPrescription = Console.ReadLine();
                                    var prescriptionId     = prescriptionService.AddPrescription(clientName, clientPesel, clientPrescription);         // dodawanie do bazy prescription, (zwraca ID prescriprion)

                                    var cc1 = "";
                                    do
                                    {
                                        Menu.GreenText("Podaj ID leku");
                                        var medicineId      = IntParse(Console.ReadLine());
                                        var existMedicineId = Exist(medicineId);

                                        Menu.GreenText("Podaj ilość");
                                        var amount     = DecimalParse(Console.ReadLine());
                                        var amountInDB = medicineService.CheckAmount(existMedicineId);
                                        if (amount > amountInDB)
                                        {
                                        }

                                        amount = amountInDB - amount;
                                        medicineService.GetMedicinesById(existMedicineId);             // dodanie danych do listy
                                        medicineService.EditAmount(medicineId, amount);

                                        orderService.AddOrder(prescriptionId, existMedicineId, amount);
                                        Menu.GreenText("Aby zakończyć realizowanie recepty wciśnij 9");
                                        Menu.GreenText("Aby dodać kolejny lek wciśnij dowolny klawisz");
                                        cc1 = Console.ReadLine();
                                    } while (cc1 != "9");

                                    break;

                                case "2":             // Without Prescription

                                    Menu.GreenText("Podaj ID leku");
                                    var medicineIdWithoutPrescription      = IntParse(Console.ReadLine());
                                    var existMedicineIdWithoutPrescription = Exist(medicineIdWithoutPrescription);

                                    Menu.GreenText("Podaj ilość");
                                    var amountWithoutPrescription     = DecimalParse(Console.ReadLine());
                                    var amountInDBWithoutPrescription = medicineService.CheckAmount(existMedicineIdWithoutPrescription);
                                    if (amountWithoutPrescription > amountInDBWithoutPrescription)
                                    {
                                    }

                                    amountWithoutPrescription = amountInDBWithoutPrescription - amountWithoutPrescription;
                                    medicineService.GetMedicinesById(existMedicineIdWithoutPrescription);             // dodanie danych do listy
                                    medicineService.EditAmount(medicineIdWithoutPrescription, amountWithoutPrescription);

                                    int?WithoutPrescription = null;
                                    orderService.AddOrder(WithoutPrescription, existMedicineIdWithoutPrescription, amountWithoutPrescription);
                                    Console.ReadKey();
                                    break;
                                }
                            } while (command != "9");

                            break;
                            Console.ReadKey();
                            break;

                        case "2":         // Show prescription

                            var           list = orderService.GetOrder();
                            StringBuilder sb1  = new StringBuilder();
                            sb1.Append("ID".PadRight(10, ' ') + "| ");
                            sb1.Append("MedicineId".PadRight(10, ' ') + "| ");
                            sb1.Append("PrescriptionId".PadRight(10, ' ') + "| ");
                            sb1.Append("Date".PadRight(10, ' ') + "| ");
                            sb1.Append("Amount".PadRight(10, ' ') + "| ");
                            Console.WriteLine((sb1));
                            foreach (var row in list)
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.Append($"{row.Id.ToString().PadRight(10, ' ')} | ");
                                sb.Append($"{row.MedicineId.ToString().PadRight(10, ' ')} | ");
                                sb.Append($"{row.PrescriptionId.ToString().PadRight(10, ' ')} | ");
                                sb.Append($"{row.Date.ToString().PadRight(10, ' ')} | ");
                                sb.Append($"{row.Amount.ToString().PadRight(10, ' ')} | ");
                                Console.WriteLine((sb));
                            }

                            Menu.GreenText("\nNaciśnij dowolny klawisz aby powrócić do poprzedniego menu");
                            Console.ReadKey();
                            break;

                        case "3":         // Show order

                            var           list3 = prescriptionService.GetPrescription();
                            StringBuilder sb3   = new StringBuilder();
                            sb3.Append("ID".PadRight(10, ' ') + "| ");
                            sb3.Append("CustomerName".PadRight(10, ' ') + "| ");
                            sb3.Append("Pesel".PadRight(10, ' ') + "| ");
                            sb3.Append("PrescriptionNumber".PadRight(10, ' ') + "| ");
                            Console.WriteLine((sb3));
                            foreach (var row in list3)
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.Append($"{row.Id.ToString().PadRight(4, ' ')} | ");
                                sb.Append($"{row.CustomerName.PadRight(15, ' ')} | ");
                                sb.Append($"{row.Pesel.PadRight(15, ' ')} | ");
                                sb.Append($"{row.PrescriptionNumber.PadRight(10, ' ')} | ");
                                Console.WriteLine((sb));
                            }

                            Menu.GreenText("\nNaciśnij dowolny klawisz aby powrócić do poprzedniego menu");
                            Console.ReadKey();
                            break;
                        }
                    } while (command != "9");

                    break;
                }
            } while (command != "0");
        }
        static void Main(string[] args)
        {
            var customerService     = new CustomerService();
            var medicineService     = new MedicineService();
            var orderService        = new OrderService();
            var prescriptionService = new PrescriptionService();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Witaj w programie do prowadzenia apteki.");
                Console.WriteLine("Co chcesz zrobić. Podaj komendę i zatwierdź enter: ");
                Console.WriteLine("1 - Dodaj zamówienie");
                Console.WriteLine("2 - Zarządzaj apteką");
                Console.WriteLine("exit - wyjście z programu");

                string mainCommand = Console.ReadLine();
                if (mainCommand == "1")
                {
                    while (true)
                    {
                        //bool pass = false;
                        Console.Clear();
                        Console.WriteLine("Wyswietlanie ekranu logowania. ");
                        var customers = customerService.GetCustomers();
                        Console.WriteLine("Podaj numer klienta: ");
                        int selectedCustomerId = customerService.GetCustomerIdFromUser(customers);
                        Console.WriteLine("Dodawanie nowego zamówienia.");
                        Console.WriteLine("Wybierz: 1 - bez recepty, 2 - na receptę.");
                        string commandNewOrder = Console.ReadLine();
                        if (commandNewOrder == "1")
                        {
                            Console.WriteLine("Dodawanie zamówienia bez recepty.");
                            bool            withPrescription = false;
                            List <Medicine> medicines        = medicineService.GetMedicines(withPrescription);
                            orderService.AddOrderWithoutPrescrToDB(medicineService, medicines, selectedCustomerId);
                        }
                        else if (commandNewOrder == "2")
                        {
                            Console.WriteLine("Dodawanie zamówienia na receptę.");
                            int    prescriptionId = prescriptionService.AddPrescriptionToDB();
                            string nextMedicine   = "t";
                            while (nextMedicine == "t")
                            {
                                List <Medicine> medicinesWithPresc = medicineService.GetMedicines(true);
                                Console.WriteLine("Dodawanie zamówienia na receptę.");
                                orderService.AddOrderWithPrescrToDB(medicineService, medicinesWithPresc, selectedCustomerId, prescriptionId);
                                Console.WriteLine("Czy chcesz dodać kolejną pozycję na recepcie [t/n]?");
                                nextMedicine = Console.ReadLine();
                            }
                            Console.WriteLine("Zakończono dodawanie recepty i przypisanych leków.");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Niewłaściwy numer czynności.");
                        }
                    }
                }
                else if (mainCommand == "2")
                {
                    while (true)
                    {
                        Console.WriteLine("Podaj czynność:");
                        Console.WriteLine("1 - Edytuj stan leków bez recepty.");
                        Console.WriteLine("2 - Edytuj stan leków na receptę.");
                        Console.WriteLine("3 - Pokaż wszystkie leki na danej recepcie.");
                        Console.WriteLine("4 - Pokaż wszystkie recepty dla danego leku.");
                        Console.WriteLine("5 - Usun lek");
                        Console.WriteLine("6 - Dodaj lek");
                        Console.WriteLine("up - wyjdź z menu");
                        string manageCommand = Console.ReadLine();
                        if (manageCommand == "1" || manageCommand == "2")
                        {
                            if (manageCommand == "1")
                            {
                                medicineService.GetMedicines(false);
                            }
                            else if (manageCommand == "2")
                            {
                                medicineService.GetMedicines(true);
                            }
                            Console.WriteLine("Podaj numer leku: ");
                            int medId = Int32.Parse(Console.ReadLine());
                            medicineService.UpdateMedicine(medId);
                            // nie aktualizuje sie cena leku prawidlowo
                        }
                        else if (manageCommand == "3")
                        {
                            prescriptionService.GetPrescriptions();
                            Console.WriteLine("Podaj numer recepty: ");
                            int prescriptionId = Int32.Parse(Console.ReadLine());
                            prescriptionService.ShowPrescriptionWithMedicines(prescriptionId);
                        }
                        else if (manageCommand == "4")
                        {
                            medicineService.GetMedicines(true);
                            Console.WriteLine("Podaj numer leku: ");
                            int medId = Int32.Parse(Console.ReadLine());
                            medicineService.showMedicineWithPrescriptions(medId);
                        }
                        else if (manageCommand == "5")
                        {
                            Console.WriteLine("todo: Delete");
                        }
                        else if (manageCommand == "6")
                        {
                            Console.WriteLine("todo: Add");
                        }
                        else if (manageCommand == "up")
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Błędna komenda. Spróbuj ponownie.");
                        }
                    }
                }
                else if (mainCommand == "exit")
                {
                    Console.WriteLine("Do widzenia.");
                    break;
                }
                else
                {
                    Console.WriteLine("Zła komenda. Spróbuj ponownie.");
                }
            }
        }