Example #1
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            if (this.selectedTestNameListBox.Items.Count > 0)
            {
                foreach (string s in this.selectedTestNameListBox.Items)
                {
                    labTestList.ForEach(x => { if (x.Name.Equals(s))
                                               {
                                                   selectedLabTestList.Add(x);
                                               }
                                        });
                }

                Lab_Order labOrder = new Lab_Order(this.visitDTO.ID, DateTime.Now);
                this.labOrderController.OrderLabs(labOrder, selectedLabTestList.ToArray());
                this.selectedTestNameListBox.Items.Clear();
                Form         successfullPersistDialog = new SuccessfullPersistDialog("Lab Order Submitted Successfully!!");
                DialogResult result = successfullPersistDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.ParentForm.DialogResult = DialogResult.Cancel;
                }
            }
            else
            {
                this.messageLabel.Visible = true;
                this.messageLabel.Text    = "Please select atlease one test to proceed!!";
            }
        }
        /// <summary>
        /// Orders a new set of labs tests for a Visit
        /// </summary>
        /// <param name="order">The Lab_Order itself</param>
        /// <param name="relation">The relation of Lab_Orders_have_Lab_Tests</param>
        /// <returns>Whether or not the insertions succeeded</returns>
        public bool OrderLabs(Lab_Order order, Lab_Test[] tests)
        {
            if (order == null || tests == null)
            {
                throw new ArgumentNullException("order and tests cannot be null");
            }
            if (order.VisitID == null)
            {
                throw new ArgumentNullException("order's visitID cannot be null");
            }
            foreach (Lab_Test test in tests)
            {
                if (test.Code == null)
                {
                    throw new ArgumentNullException("tests' Codes cannot be null");
                }
            }

            using (TransactionScope scope = new TransactionScope())
            {
                int?labOrderID = Lab_OrderDAL.InsertLab_Order(order);
                if (labOrderID == null)
                {
                    throw new Exception("Invalid Lab Order");
                }
                foreach (Lab_Test test in tests)
                {
                    Lab_Orders_have_Lab_TestsDAL.InsertLab_Orders_have_Lab_Tests(new Lab_Orders_have_Lab_Tests(labOrderID, test.Code, null, null, null));
                }
                scope.Complete();
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// Inserts a new Lab_Order into the db
        /// </summary>
        /// <param name="order">The order to insert</param>
        /// <returns>ID of the newly inserted Lab_order, or null if the insertion failed</returns>
        public static int?InsertLab_Order(Lab_Order order)
        {
            int?   id = null;
            String insertStatement = @"INSERT INTO Lab_Order (visitID, dateOrdered)
                                        OUTPUT inserted.id
			                            VALUES (@visitID, @dateOrdered)"            ;

            using (SqlConnection connection = GetSQLConnection.GetConnection())
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(insertStatement, connection))
                {
                    command.Parameters.AddWithValue("@visitID", order.VisitID);
                    command.Parameters.AddWithValue("@dateOrdered", order.DateOrdered);

                    id = Convert.ToInt32(command.ExecuteScalar());
                }
            }
            return(id);
        }