患者随访系统java代码事例
时间: 2023-06-18 14:06:53 浏览: 51
以下是一个基于Java的患者随访系统的代码示例:
```
public class Patient {
private String name;
private int age;
private String phone;
private String address;
private String diagnosis;
private String treatment;
private Date followUpDate;
// 构造函数
public Patient(String name, int age, String phone, String address, String diagnosis, String treatment, Date followUpDate) {
this.name = name;
this.age = age;
this.phone = phone;
this.address = address;
this.diagnosis = diagnosis;
this.treatment = treatment;
this.followUpDate = followUpDate;
}
// getter 和 setter 方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDiagnosis() {
return diagnosis;
}
public void setDiagnosis(String diagnosis) {
this.diagnosis = diagnosis;
}
public String getTreatment() {
return treatment;
}
public void setTreatment(String treatment) {
this.treatment = treatment;
}
public Date getFollowUpDate() {
return followUpDate;
}
public void setFollowUpDate(Date followUpDate) {
this.followUpDate = followUpDate;
}
}
public class FollowUpSystem {
private List<Patient> patientList;
// 构造函数
public FollowUpSystem() {
patientList = new ArrayList<>();
}
// 添加患者
public void addPatient(Patient patient) {
patientList.add(patient);
}
// 根据姓名查找患者
public List<Patient> searchByName(String name) {
List<Patient> result = new ArrayList<>();
for (Patient patient : patientList) {
if (patient.getName().equals(name)) {
result.add(patient);
}
}
return result;
}
// 根据诊断查找患者
public List<Patient> searchByDiagnosis(String diagnosis) {
List<Patient> result = new ArrayList<>();
for (Patient patient : patientList) {
if (patient.getDiagnosis().equals(diagnosis)) {
result.add(patient);
}
}
return result;
}
// 根据随访日期查找患者
public List<Patient> searchByFollowUpDate(Date followUpDate) {
List<Patient> result = new ArrayList<>();
for (Patient patient : patientList) {
if (patient.getFollowUpDate().equals(followUpDate)) {
result.add(patient);
}
}
return result;
}
}
public class Main {
public static void main(String[] args) {
FollowUpSystem followUpSystem = new FollowUpSystem();
// 添加患者
followUpSystem.addPatient(new Patient("张三", 30, "12345678901", "北京市朝阳区", "感冒", "休息", new Date()));
followUpSystem.addPatient(new Patient("李四", 45, "13987654321", "北京市海淀区", "高血压", "降压药", new Date()));
followUpSystem.addPatient(new Patient("王五", 50, "15876543210", "北京市西城区", "糖尿病", "胰岛素", new Date()));
// 根据姓名查找患者
List<Patient> result1 = followUpSystem.searchByName("张三");
System.out.println("姓名为张三的患者有:" + result1.size() + " 个");
// 根据诊断查找患者
List<Patient> result2 = followUpSystem.searchByDiagnosis("高血压");
System.out.println("诊断为高血压的患者有:" + result2.size() + " 个");
// 根据随访日期查找患者
List<Patient> result3 = followUpSystem.searchByFollowUpDate(new Date());
System.out.println("今天需要随访的患者有:" + result3.size() + " 个");
}
}
```
这个示例代码实现了一个简单的患者随访系统,包括患者信息的存储和搜索功能。可以根据患者姓名、诊断和随访日期进行搜索。