Medical Information Management System Database--MySQL
- Friendship
-
- 1. Database design of student achievement management system--MySQL
- 2. Mail management database design--MySQL
- 3. Database design of ordering system--SQL Server
- 4. Database Design of Commodity Management System--SQL Server
- 5. SQL Server medical information management system database [English version - source code] -- (Medical Management System Database)
- 6. SQL Server Cinema Database Management System [English Version - Source Code] -- (Movie Theatre Management System Database)
- First, the creation of the database
- 2. Based on the database, the following must be completed
Friendship
1. Database design of student achievement management system – MySQL
Student Grade Management System Database Design – MySQL
2. Mail management database design – MySQL
Email Management Database Design – MySQL
3. Database design of ordering system – SQL Server
Ordering system database design – SQL Server
4. Database design of commodity management system – SQL Server
Commodity management system database design – SQL Server
5. SQL Server Medical Information Management System Database [English Version - Source Code] – (Medical Management System Database)
6. SQL Server Cinema Database Management System [English Version - Source Code] – (Movie Theatre Management System Database)
First, the creation of the database
Design a database and describe the function of the database (about 100 words). The database contains at least three data tables, each table has no less than 5 fields, and each table adds at least 5 test records. It is required to set the primary key for each data table, set the foreign key for the data association between the tables, and select the appropriate data type for the field.
Medical information management system: In view of the current serious epidemic situation, this database is designed to facilitate the clinic to better manage medical treatment information, so as to realize the information storage, query, etc. Modifications, etc., the database contains a total of 6 tables, namely: clinic staff information table, patient basic information table, drug information table, appointment table, patient medical record table, prescription table.
Click to get the source code:
MySQL medical information management system database (source code)
create database
All tables and views
Clinic Staff Information Form
Patient Information Form
Drug Information Form
Patient Appointment Form
Patient Medical Record Information Form
Prescription Form
2. Based on the database, the following must be completed
2.1 Data query
① Multi-table join query join on
query entry In the doctors who joined in June 2019, the patients treated by each doctor are required to display: the name of the doctor, the number of patients treated, sorted by the number of patients treated from large to small; the
query statement :
SELECT u.name, p.number
FROM users_info AS u INNER JOIN
(SELECT doctor_id, COUNT(*) AS number FROM patients_info
GROUP BY doctor_id) AS p ON u.id = p.doctor_id
WHERE MONTH(u.hire_date) = 6
ORDER BY p.number DESC;
search result:
② Advanced query select aggregate function from where group by having
to query patients with more than 1 drug type, requiring display: patient id, name, condition description, diagnosis result, treatment plan, number of drugs, sorted by patient id
Query statement:
SELECT pa.pt_id,
pa.name,
c.description,
c.diagnosis,
c.therapy,
pr.number
FROM patients_info AS pa, case_history AS c,
(SELECT c_id, COUNT(c_id) AS number FROM prescriptions
GROUP BY c_id HAVING COUNT(c_id) > 1) AS pr
WHERE pa.pt_id = c.pt_id AND
c.c_id = pr.c_id
ORDER BY pa.pt_id;
search result:
③ Subquery >= > <= = in >=all <all =any (choose 2) to
query patients with the same medication, requiring display: drug name, medication usage, patient name, gender, age, condition description, diagnosis Results and treatment plans are first sorted in ascending order by drug name, and then in descending order by drug usage.
Query statement:
SELECT dr.name AS drug_name,
pr.quantity AS dosage,
pa.name,
pa.gender,
pa.age,
ca.description,
ca.diagnosis,
ca.therapy
FROM patients_info AS pa INNER JOIN
case_history AS ca ON pa.pt_id = ca.pt_id INNER JOIN
prescriptions AS pr ON pr.c_id = ca.c_id INNER JOIN
drugs_info AS dr ON dr.d_id = pr.d_id
WHERE dr.d_id IN (SELECT p.d_id FROM prescriptions AS p,
case_history AS c WHERE p.c_id = c.c_id GROUP BY p.d_id
HAVING COUNT(c.pt_id) > 1)
ORDER BY drug_name ASC, dosage DESC;
search result:
2.2 Functions
① To customize a function, you need to call the function based on the data table.
Create function: Get the employee type based on the clinic employee id
Create statement:
DELIMITER //
CREATE FUNCTION get_user_type_by_id(id INT)
RETURNS VARCHAR(300)
BEGIN
RETURN (
SELECT CONCAT('name: ', u.name, ' ', 'user_type: ', u.user_type)
FROM users_info AS u
WHERE u.id = id);
END//
DELIMITER ;
Screenshot of calling function:
② Customize a function, requiring one of the flow control statements in the function body
Create function: enter the user id, check the user's salary level, if the salary is less than 5000, it will display "normal", if it is greater than or equal to 5000 and less than 10000, it will display "medium", and if it is greater than or equal to 10000, it will display "high salary"
.
DELIMITER //
CREATE FUNCTION check_salary_level(id INT)
RETURNS VARCHAR(8)
BEGIN
DECLARE u_salary INT;
SELECT salary into u_salary FROM users_info AS u WHERE u.id = id;
IF u_salary < 5000 THEN
RETURN '一般';
ELSEIF u_salary >= 10000 THEN
RETURN '高薪';
ELSE
RETURN '中等';
END IF;
END//
DELIMITER ;
Screenshot of calling function:
2.3 Views
(1) Create an examination view and view the view
Create a patient view: It is required to display basic patient information and medical record information.
Create statement:
CREATE VIEW v_patients AS
SELECT pa.pt_id,
pa.name,
pa.gender,
pa.age,
ca.description,
ca.diagnosis,
ca.therapy
FROM patients_info AS pa INNER JOIN
ase_history AS ca ON pa.pt_id = ca.pt_id;
View view:
2.4 Stored procedures
(1) Customize the stored procedure with input parameters to complete the call.
Create a stored procedure: For each additional patient, the corresponding diagnosis doctor's salary is automatically increased by 99.
Create a statement:
DELIMITER //
CREATE DEFINER = CURRENT_USER PROCEDURE add_patient(
IN pname VARCHAR(50) charset 'utf8',
IN pgender VARCHAR(10),
IN page TINYINT,
IN ptel VARCHAR(20),
IN paddress VARCHAR(100) charset 'utf8',
IN pcreation_date DATE,
IN pdoctor_id INT
)
DETERMINISTIC
BEGIN
INSERT INTO patients_info (name, gender, age, tel, address, creation_date, doctor_id)
VALUES (pname, pgender, page, ptel, paddress, pcreation_date, pdoctor_id);
UPDATE users_info
SET salary = salary + 99
WHERE id = pdoctor_id;
COMMIT;
END//
DELIMITER ;
Call screenshot:
(2) Customize the stored procedure with input and output parameters to complete the call.
Create a stored procedure: Every time a prescription is created, the corresponding quantity of medicines contained in the prescription needs to be deducted from the medicine inventory in the medicine information table, and the deducted quantity of the medicine in stock is output.
Create statement:
DELIMITER //
CREATE DEFINER = CURRENT_USER PROCEDURE add_prescription(
IN d_quantity INT,
IN case_id INT,
IN drug_id VARCHAR(30),
IN p_type VARCHAR(20),
OUT d_stock_number INT -- 库存数量
)
DETERMINISTIC
BEGIN
INSERT INTO prescriptions (quantity, c_id, d_id, type)
VALUES (d_quantity, case_id, drug_id, p_type);
UPDATE drugs_info
SET stock_number = stock_number - d_quantity
WHERE d_id = drug_id;
SELECT stock_number INTO d_stock_number FROM drugs_info WHERE d_id = drug_id;
COMMIT;
END//
DELIMITER ;
Call screenshot:
2.5 Triggers
① Create triggers to modify data. And compare the comparison before and after the trigger is executed.
Trigger function: Real-time update of drug inventory
Create statement:
DELIMITER //
CREATE TRIGGER update_info
AFTER INSERT ON prescriptions FOR EACH ROW
BEGIN
UPDATE drugs_info SET stock_number = stock_number - new.quantity
WHERE new.d_id = d_id;
END//
DELIMITER ;
Comparison screenshots before and after trigger execution: