用python语言写一个患者信息管理系统
时间: 2023-09-04 13:15:07 浏览: 45
好的,下面是一个简单的患者信息管理系统,使用Python语言和SQLite数据库:
```python
import sqlite3
# 连接数据库
conn = sqlite3.connect('patient.db')
c = conn.cursor()
# 创建表
c.execute('''CREATE TABLE IF NOT EXISTS patients
(id integer primary key, name text, age integer, gender text, phone text)''')
# 添加患者信息
def add_patient(name, age, gender, phone):
c.execute("INSERT INTO patients (name, age, gender, phone) VALUES (?, ?, ?, ?)", (name, age, gender, phone))
conn.commit()
# 查找患者信息
def find_patient(name):
c.execute("SELECT * FROM patients WHERE name=?", (name,))
return c.fetchall()
# 更新患者信息
def update_patient(name, age, gender, phone):
c.execute("UPDATE patients SET age=?, gender=?, phone=? WHERE name=?", (age, gender, phone, name))
conn.commit()
# 删除患者信息
def delete_patient(name):
c.execute("DELETE FROM patients WHERE name=?", (name,))
conn.commit()
# 查询所有患者信息
def get_all_patients():
c.execute("SELECT * FROM patients")
return c.fetchall()
# 关闭数据库连接
def close_connection():
c.close()
conn.close()
```
使用方法:
首先,导入上述代码所在的Python文件:
```python
from patient_management_system import *
```
然后,可以使用以下函数来添加、查找、更新、删除患者信息:
```python
# 添加患者信息
add_patient('张三', 25, '男', '123456789')
# 查找患者信息
print(find_patient('张三'))
# 更新患者信息
update_patient('张三', 30, '男', '987654321')
# 删除患者信息
delete_patient('张三')
```
最后,可以使用以下函数来查询所有患者信息:
```python
# 查询所有患者信息
print(get_all_patients())
```
注意,使用完毕后需要调用 `close_connection()` 函数关闭数据库连接。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)