public PrescriptionsController(Prescription view) { this.view = view; this.reservationModel = new Models.Reservation(); this.doctorModel = new Models.Doctor(); this.allergenModel = new Models.Allergen(); this.medicamentModel = new Models.Medicament(); this.prescriptionModel = new Models.Prescription(); this.prescriptionMedicamentModel = new Models.PrescriptionMedicament(); }
/** * Controller to handle selection of a table row */ public void handleTableRowSelection() { try { Cursor.Current = Cursors.WaitCursor; this.handleResetButton(); var selectedRow = this.view.ReservationsTable.DataGrid.SelectedRows.Count > 0 ? this.view.ReservationsTable.DataGrid.SelectedRows[0] : null; if (selectedRow != null) { int id = (int)selectedRow.Cells[0].Value; this.reservations.ForEach(async(item) => { if (item.Id == id) { this.selectedReservation = item; this.view.SelectedReservationLabel.Text = this.selectedReservation.Id.ToString(); // Populate list box with medicaments this.view.MedicamentsListBox.Items.Clear(); this.view.MedicamentsListBox.Refresh(); if (this.medicaments != null && this.medicaments.Count > 0) { this.medicaments.ForEach((medicament) => { this.view.MedicamentsListBox.Items.Add(medicament); }); } // Read prescription for selected reservation this.selectedPrescription = await prescriptionModel.readPrescriptionForReservation( this.selectedReservation.Id ); // If there is an existing prescription, show its content if (this.selectedPrescription != null) { List <Models.PrescriptionMedicament> pm = await prescriptionMedicamentModel.readMedicamentsForPrescription( this.selectedPrescription.Id ); this.selectedPrescriptionMedicaments = pm; this.view.DescriptionTxtBox.ReadOnly = true; this.view.MedicamentsListBox.Enabled = false; this.view.SubmitBtn.Enabled = false; this.view.DescriptionTxtBox.Text = this.selectedPrescription.Description; for (int i = 0; i < this.view.MedicamentsListBox.Items.Count; i += 1) { Models.Medicament m = (Models.Medicament) this.view.MedicamentsListBox.Items[i]; pm.ForEach((pmItem) => { if (pmItem.Medicament == m.Id) { this.view.MedicamentsListBox.SetSelected(i, true); } }); } } } }); } Cursor.Current = Cursors.Arrow; } catch (Exception e) { string caption = "Problem në lexim"; MessageBox.Show(e.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/** * Controller to handle submit button */ public async void handleSubmitButton() { try { if (this.selectedReservation == null) { string message = "Nuk është zgjedhur asnjë rezervim"; MessageBox.Show(message, "Problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Extract selected medicaments List <Models.Medicament> selectedMedicaments = new List <Models.Medicament>(); for (int i = 0; i < this.view.MedicamentsListBox.SelectedItems.Count; i += 1) { Models.Medicament medicament = (Models.Medicament) this.view.MedicamentsListBox.SelectedItems[i]; selectedMedicaments.Add(medicament); } // Check for allergens int patientId = this.selectedReservation.Patient.Id; List <Models.Allergen> allergens = await this.allergenModel.readAllergensForPatient(patientId); string patientAllergens = ""; if (allergens != null && allergens.Count > 0) { allergens.ForEach((item) => { for (int i = 0; i < selectedMedicaments.Count; i += 1) { if (item.Medicament.Id == selectedMedicaments[i].Id) { patientAllergens = $"{patientAllergens}{(patientAllergens.Length > 0 ? ", " : "")}{selectedMedicaments[i].Name}"; } } }); } if (patientAllergens.Length > 0) { string message = $"Pacienti është alergjik ndaj medikamenteve të mëposhtme:\n{patientAllergens}"; MessageBox.Show(message, "Problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // If no allergens, create prescription and prescription medicaments long prescriptionId = await prescriptionModel.createPrescription( this.view.DescriptionTxtBox.Text, this.selectedReservation.Id ); await prescriptionMedicamentModel.createPrescriptionMedicaments( prescriptionId, selectedMedicaments ); string message2 = "Receta u shtua me sukses"; MessageBox.Show(message2, "Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information); this.handleTableRowSelection(); } catch (Exception e) { string caption = "Problem në shkrim"; MessageBox.Show(e.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public MedicamentsController(Medicaments view) { this.view = view; this.medicamentModel = new Models.Medicament(); }