Пример #1
0
        //public static async Task<List<InPatientModel>> GetInPatients_all(int id)
        //{
        //    List<InPatientModel> inpatients = new List<InPatientModel>();
        //    using (SqlConnection dbConn = new SqlConnection(connectionString))
        //    {
        //        var query = "SELECT * from In_Patient";
        //        SqlDataReader reader;

        //        try
        //        {
        //            dbConn.Open();
        //            SqlCommand cmd = new SqlCommand(query, dbConn);
        //            reader = await cmd.ExecuteReaderAsync();
        //            if (reader.HasRows)
        //            {
        //                while (reader.Read())
        //                {
        //                    InPatientModel inpatinetItem = new InPatientModel();
        //                    inpatinetItem.ID = reader.GetInt32(0);
        //                    inpatinetItem.PatientID = reader.GetInt32(1);
        //                    inpatinetItem.AdmissionDate = reader.GetDateTime(5);
        //                    inpatinetItem.AdmissionFee = reader.GetInt32(4);
        //                    inpatinetItem.RoomID = reader.GetDateTime(5);
        //                    inpatinetItem.DischargeDate = reader.GetDateTime(5);
        //                    inpatients.Add(inpatinetItem);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            reader = null;
        //            Console.WriteLine(ex);

        //        }
        //        finally
        //        {
        //            dbConn.Close();
        //        }

        //        return inpatients;
        //    }
        //}

        //public static async Task<List<InPatientModel>> GetInPatients(int id)
        //{
        //    List<InPatientModel> inpatients = new List<InPatientModel>();
        //    using (SqlConnection dbConn = new SqlConnection(connectionString))
        //    {
        //        var query = "SELECT * from In_Patient where Patient_ID=" + id;
        //        SqlDataReader reader;

        //        try
        //        {
        //            dbConn.Open();
        //            SqlCommand cmd = new SqlCommand(query, dbConn);
        //            reader = await cmd.ExecuteReaderAsync();
        //            if (reader.HasRows)
        //            {
        //                while (reader.Read())
        //                {
        //                    InPatientModel inpatinetItem = new InPatientModel();
        //                    inpatinetItem.ID = reader.GetInt32(0);
        //                    inpatinetItem.PatientID = reader.GetInt32(1);
        //                    inpatinetItem.DoctorID = reader.GetInt32(2);
        //                    inpatinetItem.RoomID = reader.GetInt32(3);
        //                    inpatinetItem.WardID = reader.GetInt32(4);
        //                    inpatinetItem.DateAddmitted = reader.GetDateTime(5);
        //                    inpatinetItem.DateDischarged = reader.GetDateTime(5);
        //                    inpatients.Add(inpatinetItem);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            reader = null;
        //            Console.WriteLine(ex);

        //        }
        //        finally
        //        {
        //            dbConn.Close();
        //        }

        //        return inpatients;
        //    }
        //}

        //public static async Task<List<AddmissionModel>> GetWardDetails()
        //{
        //    List<AddmissionModel> wards = new List<AddmissionModel>();
        //    using (SqlConnection dbConn = new SqlConnection(connectionString))
        //    {
        //        var query = "SELECT Ward.ID, Ward.Name, Doctor.ID, Doctor.Name,Room.ID, Room.Name, Room.Price FROM Room INNER JOIN Ward ON Room.WardID = Ward.ID INNER JOIN Doctor ON Ward.DoctorID = Doctor.ID WHERE Room.IsAvailable = 1";
        //        SqlDataReader reader;

        //        try
        //        {
        //            dbConn.Open();
        //            SqlCommand cmd = new SqlCommand(query, dbConn);
        //            reader = await cmd.ExecuteReaderAsync();
        //            if (reader.HasRows)
        //            {
        //                while (reader.Read())
        //                {
        //                    AddmissionModel wardItem = new AddmissionModel();
        //                    wardItem.WardID = reader.GetInt32(0);
        //                    wardItem.WardName = reader.GetString(1);
        //                    wardItem.DoctorID = reader.GetInt32(2);
        //                    wardItem.DoctorName = reader.GetString(3);
        //                    wardItem.RoomID = reader.GetInt32(4);
        //                    wardItem.RoomName = reader.GetString(5);
        //                    wardItem.RoomPrice = reader.GetDecimal(6);
        //                    wards.Add(wardItem);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            reader = null;
        //            Console.WriteLine(ex);

        //        }
        //        finally
        //        {
        //            dbConn.Close();
        //        }

        //        return wards;
        //    }
        //}


        public static async Task <bool> AddInPatient(InPatientModel inpatient)
        {
            String sql = "insert into In_Patient(Patient_ID,AddmittedDate, RoomID) values('" + inpatient.PatientID + "',@dateADD , '" + inpatient.RoomID + "')";

            using (SqlConnection dbConn = new SqlConnection(connectionString))
            {
                try
                {
                    dbConn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    cmd.Connection  = dbConn;
                    cmd.Parameters.AddWithValue("@dateADD", inpatient.DateAddmitted);
                    await cmd.ExecuteNonQueryAsync();

                    dbConn.Close();
                    await RoomService.UpdateRoomAvailability(inpatient.RoomID);

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(false);
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }//end of add
Пример #2
0
        public async Task <IHttpActionResult> AdmitPatient(InPatientModel addmission)
        {
            if (addmission == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            if (await AddmissionService.AddInPatient(addmission))
            {
                return(Ok("Patient Addmission Successfull!"));
            }
            else
            {
                return(BadRequest("Addmission Failed!"));
            }
        }