诊所信息管理系统
项目简介
为一个诊所设计一个信息管理系统。
设计医生和患者两种角色,在此基础上,通过增加患者和账单,使他们共用于表示一家诊所的信息管理。
功能要求
管理员用户名: admin
管理员密码: 123456
管理员:
- 添加患者的用户名和密码
- 重置患者的用户名和密码
- 添加医生的账号记录,包括医生的专业说明,年龄,姓名和挂号费用
- 添加患者的门诊记录,包括医生信息,患者信息,门诊费用,医药费,诊断
- 显示每个患者的门诊记录
- 能够统计患者的门诊费用
患者:
7. 修改自己的密码和基础信息
8. 查看自己的门诊记录和花费等
类设计
- Clinic 诊所
- Doctor 医生
- Patient 患者
实现代码
- main.cpp
//
// Created by ling on 2021/6/16.
//
#include "clinic.h"
int main() {
Clinic clinic;
clinic.loginAdmin("admin", "123456");
clinic.addUser("admin", "123456", "Patient.Ling", 25);
clinic.loginUser("admin", "123456");
clinic.loginAdmin("admin", "123456");
clinic.resetUser(1, "123456789");
clinic.loginUser("admin", "123456");
clinic.loginUser("admin", "123456789");
clinic.loginAdmin("admin", "123456");
clinic.addBill(1, 1, "肠胃炎", 10);
clinic.addDoctor("Doc.Ling", 35, "肠胃专家", 24.6);
clinic.addBill(1, 1, "肠胃炎", 10);
clinic.listBill();
clinic.listPatientBill(1);
return 0;
}
- clinic.h
#ifndef __CLINIC_H__
#define __CLINIC_H__
#include <string>
#include <vector>
#include "unordered_map"
using namespace std;
struct Patient {
/* data */
int id;
string name;
int age;
string username;
string password;
};
struct Doctor {
/* data */
int id;
string name;
int age;
string info;
double office_visit_fee;
};
struct Bill {
/* data */
int id;
Doctor doctor;
Patient patient;
string diagnosis;
double medicine_cost;
double office_visit_fee;
void printf() const;
};
class Clinic {
private:
string m_admin_username;
string m_admin_password;
int m_state; // 0-admin 1-user
private:
typedef pair<int, vector<Bill>> PatientBillPair;
unordered_map<int, vector<Bill>> m_bills;
std::vector<Patient> m_patients;
std::vector<Doctor> m_doctors;
private:
typedef pair<string, Patient> KeyPatientPair;
unordered_map<string, Patient> m_user_table;
public:
Clinic();
Clinic(string admin_username, string admin_password);
public:
typedef int STATE;
STATE STATE_ADMIN = 0;
STATE STATE_USER = 1;
private:
void setState(STATE state);
bool checkState(STATE state);
public:
bool loginAdmin(string username, string password);
public:
bool addDoctor(string name, int age, string info, double office_visit_fee);
bool addBill(int doctor_id, int patient_id, string diagnosis, double medicine_cost);
public:
void listBill();
void listPatientBill(int patient_id);
public:
bool loginUser(string username, string password);
bool addUser(string username, string password, string name, int age);
bool resetUser(int user_id, string password);
};
#endif
- clinic.cpp
#include "clinic.h"
#include <iostream>
#include <stdexcept>
Clinic::Clinic() {
m_admin_username = "admin";
m_admin_password = "123456";
}
Clinic::Clinic(string admin_username, string admin_password) {
m_admin_username = admin_username;
m_admin_password = admin_password;
}
void Clinic::setState(Clinic::STATE state) {
if (state == 0) {
cout << "切换诊所信息管理系统状态为: 管理员身份" << endl;
} else {
cout << "切换诊所信息管理系统状态为: 普通用户身份" << endl;
}
m_state = state;
};
bool Clinic::checkState(STATE state) {
if (m_state == state) {
cout << "权限正常" << endl;
return true;
} else {
cout << "权限异常" << endl;
return false;
}
}
bool Clinic::loginAdmin(string username, string password) {
if (username == m_admin_username && password == m_admin_password) {
cout << "管理员账号登陆成功" << endl;
setState(STATE_ADMIN);
return true;
} else {
cout << "管理员账号登陆失败" << endl;
return false;
}
}
bool Clinic::loginUser(string username, string password) {
string key;
key.append(username);
key.append(password);
if (m_user_table.find(key) != m_user_table.end()) {
cout << "普通账户登陆成功" << endl;
setState(STATE_USER);
return true;
} else {
cout << "普通账户登陆失败" << endl;
return false;
}
}
bool Clinic::addUser(string username, string password, string name, int age) {
if (!checkState(STATE_ADMIN)) {
cout << "只有管理员身份才能执行此操作" << endl;
return false;
}
string key;
key.append(username);
key.append(password);
if (m_user_table.find(key) == m_user_table.end()) {
Patient patient = Patient{
.id = (int) m_patients.size() + 1,
.name = name,
.age = age,
.username = username,
.password = password};
m_user_table.insert(Clinic::KeyPatientPair(key, patient));
m_patients.push_back(patient);
cout << "添加普通用户[" << name << "]成功" << endl;
return true;
} else {
cout << "普通用户[" << name << "]已存在" << endl;
return false;
}
}
bool Clinic::resetUser(int user_id, string password) {
if (!checkState(STATE_ADMIN)) {
cout << "只有管理员身份才能执行此操作" << endl;
return false;
}
try {
Patient patient = m_patients.at(user_id - 1);
string key;
key.append(patient.username);
key.append(patient.password);
m_user_table.erase(key);
key.clear();
key.append(patient.username);
key.append(password);
patient.password = password;
m_user_table.insert(Clinic::KeyPatientPair(key, patient));
cout << "重置普通用户密码成功" << endl;
return true;
}
catch (out_of_range) {
cout << "不存在该普通用户" << endl;
return false;
}
};
bool Clinic::addDoctor(string name, int age, string info, double office_visit_fee) {
if (!checkState(STATE_ADMIN)) {
cout << "只有管理员身份才能执行此操作" << endl;
return false;
}
Doctor doctor = Doctor{
.id = int(m_doctors.size() + 1),
.name = name,
.age = age,
.info = info,
.office_visit_fee = office_visit_fee};
m_doctors.push_back(doctor);
cout << "添加医生[" << name << "]信息成功" << endl;
return true;
};
bool Clinic::addBill(int doctor_id, int patient_id, string diagnosis, double medicine_cost) {
if (!checkState(STATE_ADMIN)) {
cout << "只有管理员身份才能执行此操作" << endl;
return false;
}
try {
Doctor doctor = m_doctors.at(doctor_id - 1);
Patient patient = m_patients.at(patient_id - 1);
Bill bill = Bill{
.doctor = doctor,
.patient = patient,
.diagnosis = diagnosis,
.medicine_cost = medicine_cost,
.office_visit_fee = doctor.office_visit_fee};
m_bills[patient_id].push_back(bill);
cout << "生成看病记录成功" << endl;
return true;
}
catch (out_of_range) {
cout << "生成看病记录失败" << endl;
return false;
}
};
void Bill::printf() const {
cout << "======== 看病记录 BEGIN ========" << endl;
cout << "病人: " << patient.name << endl;
cout << "医生: " << doctor.name << endl;
cout << "诊断: " << diagnosis << endl;
cout << "医药费用: " << medicine_cost << endl;
cout << "挂号费用: " << office_visit_fee << endl;
cout << "======== 看病记录 END ========" << endl;
};
void Clinic::listBill() {
for (auto &m_bill : m_bills) {
for (auto &bill : m_bill.second) {
bill.printf();
}
}
}
void Clinic::listPatientBill(int patient_id) {
try {
Patient patient = m_patients.at(patient_id - 1);
vector<Bill> bills = m_bills.at(patient.id);
for (auto bill = bills.begin(); bill != bills.end(); ++bill) {
bill->printf();
}
} catch (out_of_range) {
cout << "病人记录未找到" << endl;
}
}