Mô tả yêu cầu hệ thống
Mô tả nghiệp vụ hệ thống
Ta có cơ sở dữ liệu của chương trình quản lý khám chữa bệnh nhân một khoa của một bệnh viện như sau:
Bệnh viện tiếp nhận nhiều bệnh nhân và lưu trữ thông tin chi tiết của từng người, bao gồm mã bệnh nhân, tên, ngày sinh, giới tính, nghề nghiệp, quê quán, dân tộc và đối tượng Khi bệnh nhân đến khám, họ sẽ được thực hiện khám tổng quát cơ bản, từ đó tạo hồ sơ bệnh án với các thông tin như mã bệnh án, bác sĩ, ngày khám, lý do khám, tình trạng, tiền sử bệnh, huyết áp, cân nặng, nhiệt độ, phương án và tiền khám Sau đó, bệnh nhân sẽ được xét nghiệm tại phòng xét nghiệm, với hồ sơ xét nghiệm ghi rõ mã bệnh án, xét nghiệm, ngày xét nghiệm, kết quả, kết luận, bác sĩ xét nghiệm và tiền xét nghiệm Khi hoàn tất xét nghiệm, bệnh nhân sẽ nhận bệnh án kết luận với mã bệnh án, bệnh, phương án điều trị và lời dặn của bác sĩ Cuối cùng, bệnh án thuốc sẽ bao gồm mã bệnh án, thuốc, số lượng, số ngày dùng, liều dùng, cách dùng và thành tiền Bệnh nhân có thể khám nhiều lần và bệnh viện sẽ lưu giữ tất cả hồ sơ bệnh án để theo dõi trong các lần khám tiếp theo.
Bệnh viện lưu trữ thông tin chi tiết về bác sĩ, bao gồm mã bác sĩ, tên, ngày sinh, giới tính, quê quán, chuyên môn, trình độ và điện thoại, cho phép mỗi bác sĩ khám cho nhiều bệnh nhân khác nhau Ngoài ra, bệnh viện cũng ghi nhận tất cả thông tin về thuốc, như mã thuốc, tên thuốc, công dụng, đơn vị tính, thành phần và đơn giá Các thông tin liên quan đến nghề nghiệp, quê quán, dân tộc, đối tượng, bệnh, phương án, kết luận, tình trạng, xét nghiệm, trình độ, chuyên môn và đơn vị tính cũng được lưu giữ, bao gồm cả tên và mã.
1.2 Mô tả nghiệp vụ hệ thống
Bệnh viện tiếp nhận nhiều bệnh nhân đến khám và chữa bệnh, do đó sẽ lưu trữ hồ sơ của tất cả bệnh nhân Hồ sơ này bao gồm các thông tin quan trọng như mã bệnh nhân, tên, ngày sinh, giới tính, nghề nghiệp, quê quán, dân tộc và tình trạng ưu tiên.
Bệnh nhân sẽ được khám tổng quát bao gồm huyết áp, cân nặng, và nhiệt độ, cùng với việc điều tra tình trạng bệnh để bệnh viện sắp xếp bác sĩ phù hợp Sau đó, bệnh nhân sẽ trải qua quá trình xét nghiệm và nhận đơn thuốc từ bác sĩ dựa trên tình trạng bệnh Khi hoàn tất, bệnh nhân sẽ có bệnh án kết luận với các thông tin cần thiết như mã bệnh án, bệnh, phương án điều trị và lời dặn của bác sĩ Bệnh án xét nghiệm sẽ bao gồm mã bệnh án, các xét nghiệm, ngày xét nghiệm, kết luận, kết quả, bác sĩ thực hiện xét nghiệm và chi phí xét nghiệm Bệnh án thuốc sẽ ghi rõ mã bệnh án, mã thuốc, số lượng, số ngày dùng, liều dùng, cách dùng và thành tiền Bệnh nhân có thể quay lại khám nhiều lần và bệnh viện sẽ lưu trữ tất cả bản ghi bệnh án.
Bệnh viện lưu trữ thông tin chi tiết của tất cả bác sĩ, bao gồm mã bác sĩ, tên, ngày sinh, giới tính, quê quán, chuyên môn, trình độ và số điện thoại Mỗi bác sĩ có thể khám cho nhiều bệnh nhân tại các thời điểm khác nhau Ngoài ra, bệnh viện cũng lưu bản ghi về tất cả các loại thuốc, với thông tin như mã thuốc, tên thuốc, công dụng, đơn vị tính, thành phần và đơn giá.
Thiết kế chức năng hệ thống
2.1 Sơ đồ phân rã chức năng.
2.2 Mô tả chức năng lá.
Bệnh nhân: Hiển thị thông tin chi tiết về bệnh nhân, cho phép người sử dụng thực hiện các thao tác như thêm, xóa, sửa và lưu thông tin mới, nhằm cập nhật và thay đổi thông tin bệnh nhân một cách dễ dàng và hiệu quả.
Bác sĩ: Hiển thị thông tin chi tiết về bác sĩ, cho phép người dùng thực hiện các thao tác như thêm, xóa, sửa và lưu thông tin mới để cập nhật dữ liệu bác sĩ một cách hiệu quả.
Thuốc là một phần quan trọng trong việc quản lý thông tin y tế, cho phép người dùng dễ dàng thêm, xóa, sửa và lưu trữ thông tin về thuốc Tính năng này giúp cập nhật và thay đổi thông tin liên quan đến bệnh thuốc một cách hiệu quả, đảm bảo người dùng luôn có được dữ liệu chính xác và kịp thời.
- Danh sách hồ sơ bệnh án: hiển thị về danh sách bệnh án, cho phép người dùng tra cứu danh sách bệnh án theo mã bệnh nhân.
- Thông tin các bệnh án: cho phép người dùng tra cứu thông tin các bệnh án theo mã bệnh án.
- Bệnh nhân: Tìm các bệnh nhân theo tên, lý do khám, mã bệnh
- Bệnh án: Tìm các bệnh án theo bác sĩ, ngày đến khám và nhiệt độ của người bệnh
- Thông tin bệnh án: Báo cáo thông tin đầy đủ của một bệnh án theo mã bệnh án để đưa ra bản cáo cP thể
- Danh sách bệnh án: Báo cáo tất cả danh sách bệnh án theo bác sĩ
- Thông tin thuốc: Báo cáo thông tin đầy đủ của thuốc theo loại thuốc để nắm rõ bệnh viện đang có những loại thuốc nào
Cho phép người dùng thao tác nhập các thông tin về đối tượng cần thêm vào
Bước 1: Kiểm tra tính chính xác và các hàm bắt lỗi dữ liệu
- Nếu sai báo lỗi và xóa trắng dữ liệu
- Nếu đúng chuyển sang bước 2
Bước 2: Kiểm tra khóa chính đã có trong CSDL
Nếu có thì thông báo lỗi và xóa trắng dữ liệu
Bước 3: cập nhật vào CSDL
Bước 4: đưa ra dữ liệu đã nhập, kết thúc
Sửa thông tin khi người dùng muốn thay đổi đổi dữ liệu
Bước 1: click vào datagridview để chọn đối tượng cần sửa
Bước 2: Nhập dữ liệu cần thay đổi
Bước 4: Kiểm tra dữ liệu và các hàm bắt lỗi nếu có.
Nếu đúng thì lưu lại dữ liệu đã sửa và xóa trắng các nhập dữ liệu
Nếu sai hay thiếu dữ liệu thì báo lỗi và quay lại bước 2
- Khi chọn nút bỏ qua, các dữ liệu ở ô nhập dữ liệu sẽ xóa trắng
Thoát khỏi chương trình hiện hành và về formmain
Xóa dữ liệu trong CSDL
Bước 1: click vào datagridview và chọn dữ liêu cần xóa
Nếu có thì xóa dữ liệu, hiển thị thông báo
Nếu không, hiển thị lỗi
Tìm kiếm thông tin theo điều kiện lọc
Bước 1: Nhập thông tin cần tìm kiếm
Bước 2: Kiểm tra thông tin có tồn tại hay không
Nếu có thì hiện ra thông tin cần tìm kiếm
- Nếu không thì thông báo nhập lại thông tin và xóa trắng dữ liệu đầu vào
● Chức năng tìm kiếm lại
Các ô điều kiện tìm kiếm sẽ xóa trắng, cho phép người dùng tiếp tPc tìm kiếm lại thông tin
Báo cáo thông tin theo điều kiện lọc
Bước 1: Nhập thông tin cần báo cáo
Bước 2: Kiểm tra thông tin có tồn tại hay không Nếu có thì hiện ra thông tin cần báo cáo
- Nếu không thì thông báo nhập lại thông tin Bước 3: In báo cáo ra file Excel
Giải quyết vấn đề
Thiết kế cơ sở dữ liệu
Dựa vào cơ sở dữ liệu, nhóm đã thiết kế được sơ đồ quan hệ sau:
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaNN nvarchar 50 Khóa chính Mã nghề nghiệp
2 TenNN nvarchar 100 Tên nghề nghiệp
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaQ nvarchar 50 Khóa chính Mã quê
Kiểu dữ liệu Kích thước
1 MaDT nvarchar 50 Khóa chính Mã dân tộc
2 TenDT nvarchar 50 Tên dân tộc
Kiểu dữ liệu Kích thước
1 MaĐT nvarchar 50 Khóa chính Mã đối tượng
2 TenĐT nvarchar 50 Tên đối tượng
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaBN nvarchar 50 Khóa chính Mã bệnh nhân
2 TenBN nvarchar 100 Tên bệnh nhân
5 MaNN nvarchar 50 Khóa ngoại Mã nghề
6 MaQ nvarchar 50 Khóa ngoại Mã quê
7 MaDT nvarchar 50 Khóa ngoại Mã dân tộc
8 MaĐV nvarchar 50 Khóa ngoại Mã đối tượng
Kiểu dữ liệu Kích thước
1 MaCM nvarchar 50 Khóa chính Mã chuyên môn
2 TenCM nvarchar 100 Tên chuyên môn
Kiểu dữ liệu Kích thước
1 MaTĐ nvarchar 50 Khóa chính Mã trình độ
2 TenTĐ nvarchar 50 Tên trình độ
Kiểu dữ liệu Kích thước
1 MaBS nvarchar 50 Khóa chính Mã bác sĩ
2 TenBS nvarchar 50 Tên bác sĩ
5 MaCM nvarchar 50 Khóa ngoại Mã chuyên môn
6 MaQ nvarchar 50 Khóa ngoại Mã quê
7 MaTĐ varchar 50 Khóa ngoại Mã trình độ
8 SĐT nvarchar 15 Số điện thoại
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaTT nvarchar 50 Khóa chính Mã tình trạng
2 TenTT nvarchar 100 Tên tình trạng
Kiểu dữ liệu Kích thước
1 MaPA nvarchar 50 Khóa chính Mã phương án
2 TenPA nvarchar 100 Tên phương án
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaBA nvarchar 50 Khóa chính Mã bệnh án
2 MaBN nvarchar 50 Khóa ngoại Mã bệnh nhân
3 MaBS nvarchar 50 Khóa ngoại Mã bác sĩ
5 LiDoKham nvarchar 150 Lí do khám
6 MaTT nvarchar 50 Khóa ngoại Mã tình trạng
7 MaPA nvarchar 50 Khóa ngoại Mã phương án
8 TienSuBenh nvarchar 150 Tiền sử bệnh
Kiểu dữ liệu Kích thước
1 MaPA nvarchar 50 Khóa chính Mã phương án
2 TenPA nvarchar 50 Tên phương án
Kiểu dữ liệu Kích thước
1 MaPA nvarchar 50 Khóa chính Mã phương án
2 TenPA nvarchar 50 Tên phương án
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaT nvarchar 50 Khóa chính Mã thuốc
3 MaCD nvarchar 50 Khóa ngoại Mã công dPng
4 MaĐV nvarchar 50 Khóa ngoại Mã đơn vị tính
Kiểu dữ liệu Kích thước
1 MaBA nvarchar 50 Khóa chính Mã bệnh án
2 MaT nvarchar 50 Khóa chính Mã thuốc
4 SoNgayDu ng float Số ngày dùng
Kiểu dữ liệu Kích thước
1 MaB nvarchar 50 Khóa chính Mã bệnh
Kiểu dữ liệu Kích thước
1 MaBA nvarchar 50 Thành phần khóa chính
2 MaB nvarchar 50 Thành phần khóa chính
3 MaPA nvarchar 50 Khóa ngoại Mã phương án
4 LoiDanBS nvarchar 150 Lời dặn bác sĩ
Kiểu dữ liệu Kích thước
1 MaXN nvarchar 50 Khóa chính Mã xét nghiệm
2 TenXN nvarchar 50 Tên xét nghiệm
STT Tên trường Kiểu dữ liệu Kích thước Khóa Giải thích
1 MaKL nvarchar 50 Khóa chính Mã kết luận
2 TenKL nvarchar 100 Tên kết luận
Kiểu dữ liệu Kích thước
1 MaBA nvarchar 50 Thành phần khóa chính
2 MaXN nvarchar 50 Thành phần khóa chính
3 MaKL nvarchar 50 Khóa ngoại Mã két luận
4 NgayXN datetime Ngày xét nghiệm
6 BacSiXN nvarchar 50 Bác sĩ xét nghiệm
7 TienXN float Tiền xét nghiệm
Thiết kế hệ thống
The code snippet provided is a C# file named Main.cs, which is part of the BàiTapLon_QuanLyBenhNhan_Nhom8.Forms namespace It includes essential using directives for various NET libraries, such as System, System.Collections.Generic, System.ComponentModel, System.Data, System.Drawing, System.Linq, System.Text, System.Threading.Tasks, and System.Windows.Forms, indicating that it is designed for a Windows Forms application focused on patient management.
{ public partial class Formmain : Form
} private void Formmain_Load( object sender, EventArgs e) {
} private void mnubenhnhan_Click( object sender, EventArgs e) {
Forms.TimKiemBenhNhan a = new Forms.TimKiemBenhNhan(); a.Show();
} private void mnubacsi_Click( object sender, EventArgs e) {
Forms.BacSi a = new Forms.BacSi(); a.Show();
} private void thoátToolStripMenuItem_Click( object sender, EventArgs e) { if(MessageBox.Show("ban co muon xoa khong","thong bao",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
} private void mnubcaothongtinbenhan_Click( object sender, EventArgs e) {
Forms.BaoCaoThongTinBenhAn a = new Forms.BaoCaoThongTinBenhAn(); a.Show();
} private void b nhNhânToolStripMenuItem_Click( ệ object sender, EventArgs e) {
Forms.BenhNhan a = new Forms.BenhNhan(); a.Show();
} private void thu cToolStripMenuItem_Click( ố object sender, EventArgs e) {
Forms.Thuoc a = new Forms.Thuoc(); a.Show();
} private void danhSáchB nhÁnToolStripMenuItem_Click( ệ object sender, EventArgs e) {
Forms.DanhSachHoSoBenhAn a = new Forms.DanhSachHoSoBenhAn(); a.Show();
} private void thôngTinB nhÁnToolStripMenuItem_Click( ệ object sender, EventArgs e) {
Forms.ThongTinBenhAn a = new Forms.ThongTinBenhAn(); a.Show();
} private void b nhÂnToolStripMenuItem_Click( ệ object sender, EventArgs e) {
Forms.TimKiemBenhAn a = new Forms.TimKiemBenhAn(); a.Show();
} private void danhSáchB nhÁnToolStripMenuItem1_Click( ệ object sender, EventArgs e)
Forms.BaoCaoDanhSachBenhAn a = new Forms.BaoCaoDanhSachBenhAn(); a.Show();
} private void thôngTinThu cToolStripMenuItem_Click( ố object sender, EventArgs e) {
Forms.BaoCaoThongTinThuoc a = new Forms.BaoCaoThongTinThuoc(); a.Show();
The code snippet provided is part of a C# application for managing patient records, specifically within the "BàiTapLon_QuanLyBenhNhan_Nhom8.Forms" namespace It utilizes essential libraries such as System, System.Collections.Generic, System.Data, System.Drawing, System.Linq, System.Text, System.Threading.Tasks, System.Windows.Forms, and System.Data.SqlClient, indicating that it is designed for a Windows Forms application that interacts with a SQL Server database.
{ public partial class Dangnhap : Form
} private void btndangnhap_Click( object sender, EventArgs e) {
Funcions.Funcion.ketnoi(); string sql; sql = "select TenDN, MaDN from Tbldangnhap where TenDN=N'" + txttendangnhap.Text + "'and MaDN=N'" + txtmatkhau.Text + "'" ;
SqlCommand a = new SqlCommand(sql, Funcions.Funcion.Conn); SqlDataReader reader = a.ExecuteReader(); if (reader.Read() == true )
Form batdau = new Formmain(); batdau.Show();
MessageBox.Show("ban nhap sai tai khoan hoac mat khau" , "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error); txttendangnhap.Text = "" ; txtmatkhau.Text = "" ; txttendangnhap.Focus();
} private void btnthoat_Click( object sender, EventArgs e)
{ if (MessageBox.Show( "ban co muon thoat khong" , "thong bao" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
} private void Dangnhap_Load( object sender, EventArgs e)
2.1.3 Giao diện các form thông tin. a) Thuoc.cs
The provided code snippet is a C# program that includes essential namespaces for a Windows Forms application, specifically for managing patient records It utilizes various libraries such as System, System.Collections.Generic, System.ComponentModel, System.Data, System.Drawing, System.Linq, System.Text, System.Threading.Tasks, and System.Windows.Forms The code is structured within a namespace called BàiTapLon_QuanLyBenhNhan_Nhom8.Forms, indicating its purpose in the context of a group project focused on patient management.
{ public partial class Thuoc : Form
} private void Thuoc_Load( object sender, EventArgs e)
Funcions.Funcion.fillcombo("SELECT MaDV,MaDV FROM Tbldonvitinh", comboBoxmadonvi, "MaDV" , "TenDV"); comboBoxmadonvi.SelectedIndex = -1;
The function `fillcombo` populates the combo box `comboBoxmacong` with data from the SQL query "SELECT MaCD, TenCD FROM Tblcongdung," setting the selected index to -1 The `load_datagridview` function is called to populate `dataGridView1`, while the text box `textBoxmathuoc` and buttons `buttonluu`, `buttonboqua`, `buttonsua`, and `buttonxoa` are all disabled for user interaction.
} void load_datagridview(DataGridView data1)
{ string sql = "select * from Tthuoc" ; bang01 = Funcions.Funcion.GetDataTable(sql); data1.DataSource = bang01;
{ textBoxmathuoc.Text = "" ; textBoxtenthuoc.Text = "" ; textBoxthanhphan.Text = "" ; textBoxdongia.Text = "" ; comboBoxmadonvi.Text = "" ; comboBoxmacong.Text = "" ;
} private void buttgithem_Click( object sender, EventArgs e)
{ reset(); textBoxmathuoc.Focus(); buttonluu.Enabled = true ; buttonsua.Enabled = false ; buttonxoa.Enabled = false ; buttonboqua.Enabled = true ; textBoxmathuoc.Enabled = true ;
} private void buttonluu_Click( object sender, EventArgs e)
MessageBox.Show("ch a nh p mã thu c" ư ậ ố ); textBoxmathuoc.Focus();
MessageBox.Show("ch a nh p tên thu c" ư ậ ố ); textBoxtenthuoc.Focus();
MessageBox.Show("ch a ch n mã công d ng" ư ọ ụ );
MessageBox.Show("ch a ch n mã đ n v " ư ọ ơ ị );
MessageBox.Show("ch a nh p thành ph n thu c" ư ậ ầ ố ); textBoxthanhphan.Focus();
} else if (Int32.TryParse(textBoxdongia.Text, out int a) == false ) {
MessageBox.Show("nh p sai đ n giá" ậ ơ ); textBoxdongia.Focus();
{ string check = "SELECT MaT from Tthuoc WHERE MaT=N'" + textBoxmathuoc.Text.Trim() + "'" ; if(Funcions.Funcion.checkkey(check))
MessageBox.Show( "da co ma thuoc nay" , "thong bao" ,
MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxmathuoc.Text = "" ; textBoxmathuoc.Focus();
} string sql1 = "INSERT INTO Tthuoc VALUES(N'" + textBoxmathuoc.Text.Trim() + "', N'" + textBoxtenthuoc.Text.Trim() + "', N'" + comboBoxmacong.SelectedValue.ToString() + "', N'" + comboBoxmadonvi.SelectedValue.ToString() + "',N'" + textBoxthanhphan.Text.Trim() + "', '" + textBoxdongia.Text.Trim() + "' )" ;
Funcions.Funcion.runsql(sql1); load_datagridview(dataGridView1); reset(); buttonsua.Enabled = false ; buttonxoa.Enabled = false ;
} private void dataGridView1_Click( object sender, EventArgs e)
The current row values from the data grid are assigned to various text boxes and combo boxes, including the medication code, name, component, unit code, and price The save and add buttons are disabled, while the edit, delete, and cancel buttons are enabled for further actions.
} private void buttonboqua_Click( object sender, EventArgs e)
{ reset(); buttgithem.Enabled = true ; buttonluu.Enabled = false ; buttonsua.Enabled = false ; buttonxoa.Enabled = false ;
} private void buttonxoa_Click( object sender, EventArgs e)
MessageBox.Show("chon thuoc đ xóa" ể , "" , MessageBoxButtons.OK); return ;
MessageBox.Show("khong co gi đ xóa" ể , "" , MessageBoxButtons.OK); return ;
} string caulenh = "delete from Tthuoc where MaT= N'" + textBoxmathuoc.Text.Trim() + "'" ; if (MessageBox.Show( "b n có mu n xóa khong" ạ ố , "xóa d li u" ữ ệ , MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
} load_datagridview(dataGridView1); reset(); buttonboqua.Enabled = true ; buttonluu.Enabled = false ; buttonsua.Enabled = false ; buttgithem.Enabled = true ;
} private void buttonsua_Click( object sender, EventArgs e)
MessageBox.Show("chon thuoc đ sua" ể , "" , MessageBoxButtons.OK); return ;
MessageBox.Show("khong co gi đ sua" ể , "" , MessageBoxButtons.OK); return ;
MessageBox.Show( "hay nhap don gia de sua" , "thong bao" ,
MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxdongia.Focus(); return ;
MessageBox.Show( "hay nhap ten thuoc de sua" , "thong bao" ,
MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxtenthuoc.Focus(); return ;
MessageBox.Show( "hay nhap thanh phan de sua" , "thong bao" ,
MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxthanhphan.Focus(); return ;
MessageBox.Show( "hay chon cong dung" , "thong bao" ,
MessageBoxButtons.OK, MessageBoxIcon.Warning); comboBoxmacong.Focus(); return ;
MessageBox.Show( "hay chon don vi" , "thong bao" , MessageBoxButtons.OK, MessageBoxIcon.Warning); comboBoxmadonvi.Focus(); return ;
} string caulenh = "update Tthuoc set MaT=N'" + textBoxmathuoc.Text.Trim() +
"',TenT=N'" + textBoxtenthuoc.Text.Trim() + "',MaCD=N'" + comboBoxmacong.Text +
"',MaDV=N'" + comboBoxmadonvi.Text + "',ThanhPhan=N'" + textBoxthanhphan.Text.Trim() +
"',DonGia='" + textBoxdongia.Text.Trim() + "' where MaT='" + textBoxmathuoc.Text.Trim() + "' " ;
Funcions.Funcion.runsql(caulenh); load_datagridview(dataGridView1); reset(); buttonsua.Enabled = false ; buttonxoa.Enabled = false ; buttonboqua.Enabled = true ; buttonluu.Enabled = true ; buttgithem.Enabled = false ;
} private void buttondong_Click( object sender, EventArgs e)
The provided code snippet is a C# program that utilizes Windows Forms to create a user interface for managing patient information It includes necessary namespaces such as System, System.Collections.Generic, System.ComponentModel, System.Data, System.Drawing, System.Linq, System.Text, System.Threading.Tasks, and System.Windows.Forms The main class, BenhNhan, is defined within the namespace BàiTapLon_QuanLyBenhNhan_Nhom8.Forms, indicating its role in a larger patient management system developed by Group 8.
} private void BenhNhan_Load(object sender, EventArgs e) {
21 txtmabn.Enabled = false; btnluu.Enabled = false; btnboqua.Enabled = false;
Funcions.Funcion.fillcombo("select MaNN,TenNN from Tblnghenghiep", cbnghe, "MaNN", "TenNN"); cbnghe.SelectedIndex = -1;
Funcions.Funcion.fillcombo("select MaQ,TenQ from Tblque", cbque, "MaQ",
Funcions.Funcion.fillcombo("select MaDT,TenDT from Tbldantoc", cbdantoc,
Funcions.Funcion.fillcombo("select MaDTuong,TenDTuong from
Tbldoituong", cbdoituong, "MaDTuong", "TenDTuong"); cbdantoc.SelectedIndex = -1; resetvalue(); load_datagrid();
{ txtmabn.Text = ""; chkgtinh.Checked = false; mskngsinh.Text = ""; txttenbn.Text = ""; cbque.Text = ""; cbdantoc.Text = ""; cbdoituong.Text = ""; cbnghe.Text = "";
The SQL query retrieves patient data by selecting various attributes, including patient ID, name, gender, date of birth, occupation code, hometown code, ethnicity code, and subject code from the Tblbenhnhan table The resulting data is then assigned to the data source of the dgridbenhnhan grid Each column of the grid is labeled appropriately, with headers for patient ID, name, gender, date of birth, occupation code, hometown code, ethnicity code, and subject code.
} private void btnthem_Click(object sender, EventArgs e)
{ btnsua.Enabled = false; btnxoa.Enabled = false; btnboqua.Enabled = true; btnluu.Enabled = true; btnthem.Enabled = false; txtmabn.Focus(); txtmabn.Enabled = true; resetvalue();
} private void dgridbenhnhan_Click(object sender, EventArgs e)
MessageBox.Show("ban dang o che do them moi", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("khong co du lieu trong bang", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
The code snippet retrieves values from the currently selected row in a data grid named `dgridbenhnhan` It extracts various identifiers such as `MaNN`, `MaQ`, `MaDT`, and `MaDTuong`, and assigns them to string variables The patient's ID and name are set in the text fields `txtmabn` and `txttenbn`, respectively Additionally, the code checks the gender value; if it equals "Nam," the gender checkbox `chkgtinh` is checked, otherwise, it remains unchecked The patient's birth date is populated in the `mskngsinh` field, and the profession is fetched from the database using a function that retrieves the value of `TenNN`.
Tblnghenghiep where MaNN=N'" + ma + "'"); cbque.Text = Funcions.Funcion.getfiedvalues("select TenQ from Tblque where MaQ=N'" + mai + "'"); cbdantoc.Text = Funcions.Funcion.getfiedvalues("select TenDT from Tbldantoc where MaDT=N'" + mao + "'");
23 cbdoituong.Text = Funcions.Funcion.getfiedvalues("select TenDTuong from Tbldoituong where MaDTuong=N'" + mae + "'"); btnsua.Enabled = true; btnxoa.Enabled = true; btnboqua.Enabled = true;
} private void btnsua_Click(object sender, EventArgs e)
{ string sql, gt; if (txtmabn.Text == "")
MessageBox.Show("ban chua chon de sua", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
MessageBox.Show("khong co du lieu trong bang", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("ban chua nhap ten hang", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); txttenbn.Focus(); return;
MessageBox.Show("Bạn phải nhập ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Warning); mskngsinh.Focus(); return;
MessageBox.Show("Bạn chưa chọn nghề nghiệp", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbnghe.Focus(); return;
MessageBox.Show("Bạn chưa chọn dân tộc", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); cbdantoc.Focus(); return;
MessageBox.Show("Bạn chưa chọn quê quán", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); cbque.Focus(); return;
MessageBox.Show("Bạn chưa chọn đối tượng", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); cbdoituong.Focus(); return;
} if (!Funcions.Funcion.ktrangaysinh(mskngsinh.Text))
MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Warning); mskngsinh.Text = ""; mskngsinh.Focus(); return;
} if (chkgtinh.Checked == true) gt = "Nam"; else gt = "Nữ"; sql = "update Tblbenhnhan set TenBN=N'" + txttenbn.Text.Trim().ToString() +
"',GT=N'" + gt + "',NS='" + Funcions.Funcion.datetime( mskngsinh.Text) +
"',MaNN=N'" + cbnghe.SelectedValue.ToString() + "',MaQ=N'" + cbque.SelectedValue.ToString() + "',MaDT=N'" + cbdantoc.SelectedValue.ToString() + "',MaDTuong = N'" + cbdoituong.SelectedValue.ToString() + "' WHERE MaBN=N'" + txtmabn.Text + "'";
Funcions.Funcion.runsql(sql); load_datagrid(); resetvalue(); btnboqua.Enabled = false;
} private void btnxoa_Click(object sender, EventArgs e)
MessageBox.Show("k con du lieu de xoa", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
MessageBox.Show("ban chua chon du lieu de xoa", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
} if (MessageBox.Show("ban co muon xoa khong", "thong bao",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { sql = "delete from Tblbenhnhan where MaBN=N'" + txtmabn.Text.Trim() +
Funcions.Funcion.runsql(sql); resetvalue(); load_datagrid();
} private void btnluu_Click(object sender, EventArgs e)
{ string sql, gt; if (txtmabn.Text == "")
MessageBox.Show("chua nhap ma benh nhan", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); txtmabn.Focus(); return;
MessageBox.Show("chua nhap ten benh nhan", "thong bao",
MessageBoxButtons.OK, MessageBoxIcon.Warning); txttenbn.Focus(); return;
MessageBox.Show("Bạn phải nhập ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Warning); mskngsinh.Focus(); return;
} if (!Funcions.Funcion.ktrangaysinh(mskngsinh.Text))
MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); mskngsinh.Text = ""; mskngsinh.Focus(); return;
MessageBox.Show("Bạn chưa chọn nghề nghiệp", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbnghe.Focus(); return;
MessageBox.Show("Bạn chưa chọn dân tộc", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbdantoc.Focus(); return;
MessageBox.Show("Bạn chưa chọn quê quán", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbque.Focus(); return;
MessageBox.Show("Bạn chưa chọn đối tượng", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbdoituong.Focus(); return;
} if (chkgtinh.Checked == true) gt = "nam"; else gt = "nữ"; sql = "SELECT MaBN FROM Tblbenhnhan WHERE MaBN=N'" + txttenbn.Text.Trim() + "'"; if (Funcions.Funcion.checkkey(sql))
MessageBox.Show("Mã bệnh nhân này đã có, bạn phải nhập mã khác",
"Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtmabn.Focus(); txtmabn.Text = ""; return;
The SQL command inserts patient data into the Tblbenhnhan table, including fields such as patient ID (MaBN), name (TenBN), gender (GT), date of birth (NS), occupation (MaNN), hometown (MaQ), ethnicity (MaDT), and insurance type (MaDTuong) The values are retrieved from user input fields, ensuring that the data is properly trimmed and formatted for insertion.
Funcions.Funcion.runsql(sql); load_datagrid(); resetvalue(); btnthem.Enabled = true; btnsua.Enabled = true; btnxoa.Enabled = true; btnluu.Enabled = false; btnboqua.Enabled = false; txtmabn.Enabled = false;
} private void btnboqua_Click(object sender, EventArgs e)
{ btnboqua.Enabled = false; btnthem.Enabled = true; btnsua.Enabled = true; btnxoa.Enabled = true; btnluu.Enabled = false; txtmabn.Enabled = false; resetvalue();
} private void btnthoat_Click(object sender, EventArgs e)
The provided code snippet is part of a C# Windows Forms application, specifically within the namespace "BàiTapLon_QuanLyBenhNhan_Nhom8.Forms." It defines a partial class named "BacSi," which inherits from the Form class, indicating that it is likely designed to create a user interface for managing patient information The code includes necessary using directives for various namespaces, allowing for functionalities like data handling, graphical representation, and user interactions within the application.
} private void BacSi_Load(object sender, EventArgs e) { load_dgr_Bacsi(); btnThem.Enabled = true;
29 btnSua.Enabled = true; btnXoa.Enabled = true; btnLuu.Enabled = false; btnBoqua.Enabled = false; txtMaBS.Enabled = false;
Funcions.Funcion.fillcombo("select MaCM,TenCM from Tblchuyenmon", cboCM, "MaCM", "TenCM"); cboCM.SelectedIndex = -1;
Funcions.Funcion.fillcombo("select MaTD,TenTD from Tbltrinhdo", cboTD,
Funcions.Funcion.fillcombo("select MaQ,TenQ from Tblque", cbQQ, "MaQ",
} private void load_dgr_Bacsi()
The SQL query retrieves data about doctors, including their ID, name, gender, date of birth, hometown, specialty, qualification, and phone number, by joining multiple tables: Tblbacsi, Tblchuyenmon, Tbltrinhdo, and Tblque The resulting data is displayed in a DataGridView, with customized column headers for clarity User input for adding rows is disabled, and the grid is set to allow programmatic editing only.
{ txtMaBS.Text = ""; txtTenBS.Text = ""; txtSDT.Text = ""; cboCM.Text = ""; cboTD.Text = ""; cbQQ.Text = ""; mskNS.Text = ""; ckbGT.Checked = false;
} private void btnThoat_Click_1(object sender, EventArgs e)
} private void btnThem_Click_1(object sender, EventArgs e) { btnThem.Enabled = false; btnSua.Enabled = false; btnXoa.Enabled = false; btnLuu.Enabled = true; ; btnBoqua.Enabled = true; resetvalue(); txtMaBS.Enabled = true; txtMaBS.Focus();
} private void btnSua_Click_1(object sender, EventArgs e) { if (table.Rows.Count == 0)
MessageBox.Show("Không còn dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải có tên bác sĩ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải chọn quê quán", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải chọn chuyên môn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải chọn trình độ", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải có số điện thoại", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải có ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
} if (!Funcions.Funcion.ktrangaysinh(mskNS.Text))
MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Warning); mskNS.Text = ""; mskNS.Focus(); return;
} string GT; if (ckbGT.Checked == true)
GT = "Nữ"; string sql; sql = "update tblBacsi set TenBS=N'" + txtTenBS.Text + "',SDT= N'" + Convert.ToInt32(txtSDT.Text) + "',GT =N'" + GT + "',MaTD=N'" + cboTD.SelectedValue.ToString() + "',MaQ=N'" + cbQQ.SelectedValue.ToString() +
"',MaCM=N'" + cboCM.SelectedValue.ToString() + "',NS=N'" +
Funcions.Funcion.datetime(mskNS.Text) + "' where MaBS =N'" + txtMaBS.Text + "'"; Funcions.Funcion.runsql(sql); resetvalue(); load_dgr_Bacsi(); btnBoqua.Enabled = false;
} private void btnXoa_Click_1(object sender, EventArgs e)
MessageBox.Show("Không còn dữ liệu", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("chưa chọn bản ghi nào để xoá", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
To delete a record from the Tblbacsi table, a confirmation message box prompts the user with the question, "Do you want to delete?" If the user selects "OK," the SQL command executes to remove the entry corresponding to the identifier provided in the txtMaBS text box After the deletion, the data grid for doctors is refreshed, and the input values are reset.
} private void btnLuu_Click_1(object sender, EventArgs e)
MessageBox.Show("Phải nhập tên mã bác sĩ", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải nhập tên bác sĩ", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải chọn quê quán", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải chọn chuyên môn", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải chọn trình độ", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải nhập số điện thoại", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
MessageBox.Show("Phải nhập ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
} if (!Funcions.Funcion.ktrangaysinh(mskNS.Text))
MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Warning); mskNS.Text = ""; mskNS.Focus(); return;
} string GT; if (ckbGT.Checked == true)
GT = "Nữ"; string sql; sql = "SELECT MaBS FROM Tblbacsi WHERE MaBS=N'" + txtTenBS.Text.Trim() + "'"; if (Funcions.Funcion.checkkey(sql))
MessageBox.Show("Mã bác sĩ này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaBS.Focus(); txtMaBS.Text = ""; return;
(MaBS,TenBS,GT,NS,MaQ,MaCM,MaTD,SDT) VALUES(N'" + txtMaBS.Text +
Funcions.Funcion.datetime(mskNS.Text) + "',N'" + cbQQ.SelectedValue.ToString() +
"',N'" + cboCM.SelectedValue.ToString() + "',N'" + cboTD.SelectedValue.ToString() +
Funcions.Funcion.runsql(sql); load_dgr_Bacsi(); resetvalue(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnBoqua.Enabled = false; btnLuu.Enabled = false; txtMaBS.Enabled = false;
} private void btnBoqua_Click_1(object sender, EventArgs e)
{ resetvalue(); btnBoqua.Enabled = false; btnThem.Enabled = true; btnXoa.Enabled = true; btnSua.Enabled = true; btnLuu.Enabled = false; txtMaBS.Enabled = false;
} private void dgrBacsi_Click(object sender, EventArgs e)
{ string a, b, c; if (btnThem.Enabled == false)
MessageBox.Show("Đang ở chế độ thêm mới!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); txtMaBS.Focus(); return;
MessageBox.Show("Không có dữ liệu!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information); return;
The code snippet retrieves and displays data from the selected row in a DataGridView named "dgrBacsi." It assigns the values of "MaBS," "TenBS," "SDT," and "NS" to the corresponding text fields: txtMaBS, txtTenBS, txtSDT, and mskNS Additionally, it fetches the "MaQ" value to retrieve the corresponding "TenQ" from the "Tblque" table using a SQL query Lastly, it stores the "MaCM" value for further processing.
The code retrieves the name of the specialty from the "Tblchuyenmon" table using the selected specialty ID, and it populates the corresponding dropdown It also fetches the name of the qualification from the "Tbltrinhdo" table based on the selected qualification ID Additionally, it checks the gender of the selected doctor, enabling the gender checkbox accordingly Lastly, the edit, delete, and cancel buttons are activated for user interaction.
“ Một bệnh nhân có nhiều hồ sơ bệnh án, khi chọn một bệnh nhân sẽ hiện danh sách các bệnh án của bệnh nhân đó”
1 Trả lời các câu hỏi trong bước “Phân tích câu hỏi”
3 Giao diện sau khi xử lý
Danh sách hồ sơ bênh án TimKiemBenhNhan Form
Danh sách hồ sơ bệnh án Lable1 Lable
Mã Bệnh Nhân Lable2 Lable cbomabenhnhan Combobox
Tra cứu bệnh án btntracuu Button
Tra cứu lại btntracuulai Button
Tra cứu danh sách groupbox1 Groupbox
4 Code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BàiTapLon_QuanLyBenhNhan_Nhom8.Forms
{ public partial class DanhSachHoSoBenhAn : Form
} private void DanhSachHoSoBenhAn_Load( object sender, EventArgs e) {
Funcions.Funcion.fillcombo("select distinct MaBN from Tblhosobenhan", cbomabenhnhan, "MaBN" , "MaBN"); cbomabenhnhan.SelectedIndex = -1; loadDataTraCuu();