当前位置:实例文章 » 其他实例» [文章]护网实训场景二-

护网实训场景二-

发布人:shili8 发布时间:2025-01-15 09:53 阅读次数:0

**护网实训场景二**

**场景描述**

护网是一款基于区块链技术的医疗保健平台,旨在提高医疗服务的透明度、安全性和可信度。护网实训场景二要求开发者实现以下功能:

1. **用户注册与登录**
2. **病人信息管理**
3. **医生信息管理**
4. **就诊记录管理**
5. **药品管理**

**技术栈**

* 后端:Spring Boot* 前端:Vue.js* 数据库:MySQL**用户注册与登录**

### 用户注册

java// User.java@Entitypublic class User {
 @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;
 private String username;
 private String password;
 // getters and setters}

// UserController.java@RestController@RequestMapping("/api/users")
public class UserController {
 @Autowired private UserService userService;

 @PostMapping public ResponseEntity register(@RequestBody User user) {
 User registeredUser = userService.register(user);
 return ResponseEntity.ok(registeredUser);
 }
}


### 用户登录
java// LoginController.java@RestController@RequestMapping("/api/login")
public class LoginController {
 @Autowired private UserService userService;

 @PostMapping public ResponseEntity login(@RequestBody User user) {
 String token = userService.login(user);
 return ResponseEntity.ok(token);
 }
}


**病人信息管理**

### 病人信息表
sqlCREATE TABLE patients (
 id INT PRIMARY KEY AUTO_INCREMENT,
 name VARCHAR(255),
 age INT,
 address VARCHAR(255)
);


### 病人信息服务类
java// PatientService.java@Servicepublic class PatientService {
 @Autowired private PatientRepository patientRepository;

 public List getAllPatients() {
 return patientRepository.findAll();
 }

 public Patient getPatientById(Long id) {
 return patientRepository.findById(id).orElse(null);
 }
}


### 病人信息控制器
java// PatientController.java@RestController@RequestMapping("/api/patients")
public class PatientController {
 @Autowired private PatientService patientService;

 @GetMapping public ResponseEntity> getAllPatients() {
 List patients = patientService.getAllPatients();
 return ResponseEntity.ok(patients);
 }

 @GetMapping("/{id}")
 public ResponseEntity getPatientById(@PathVariable Long id) {
 Patient patient = patientService.getPatientById(id);
 return ResponseEntity.ok(patient);
 }
}


**医生信息管理**

### 医生信息表
sqlCREATE TABLE doctors (
 id INT PRIMARY KEY AUTO_INCREMENT,
 name VARCHAR(255),
 age INT,
 department VARCHAR(255)
);


### 医生信息服务类
java// DoctorService.java@Servicepublic class DoctorService {
 @Autowired private DoctorRepository doctorRepository;

 public List getAllDoctors() {
 return doctorRepository.findAll();
 }

 public Doctor getDoctorById(Long id) {
 return doctorRepository.findById(id).orElse(null);
 }
}


### 医生信息控制器
java// DoctorController.java@RestController@RequestMapping("/api/doctors")
public class DoctorController {
 @Autowired private DoctorService doctorService;

 @GetMapping public ResponseEntity> getAllDoctors() {
 List doctors = doctorService.getAllDoctors();
 return ResponseEntity.ok(doctors);
 }

 @GetMapping("/{id}")
 public ResponseEntity getDoctorById(@PathVariable Long id) {
 Doctor doctor = doctorService.getDoctorById(id);
 return ResponseEntity.ok(doctor);
 }
}


**就诊记录管理**

### 就诊记录表
sqlCREATE TABLE appointments (
 id INT PRIMARY KEY AUTO_INCREMENT,
 patient_id INT,
 doctor_id INT,
 date DATE,
 time TIME);


### 就诊记录服务类
java// AppointmentService.java@Servicepublic class AppointmentService {
 @Autowired private AppointmentRepository appointmentRepository;

 public List getAllAppointments() {
 return appointmentRepository.findAll();
 }

 public Appointment getAppointmentById(Long id) {
 return appointmentRepository.findById(id).orElse(null);
 }
}


### 就诊记录控制器
java// AppointmentController.java@RestController@RequestMapping("/api/appointments")
public class AppointmentController {
 @Autowired private AppointmentService appointmentService;

 @GetMapping public ResponseEntity> getAllAppointments() {
 List appointments = appointmentService.getAllAppointments();
 return ResponseEntity.ok(appointments);
 }

 @GetMapping("/{id}")
 public ResponseEntity getAppointmentById(@PathVariable Long id) {
 Appointment appointment = appointmentService.getAppointmentById(id);
 return ResponseEntity.ok(appointment);
 }
}


**药品管理**

### 药品表
sqlCREATE TABLE medicines (
 id INT PRIMARY KEY AUTO_INCREMENT,
 name VARCHAR(255),
 price DECIMAL(10,2)
);


### 药品服务类
java// MedicineService.java@Servicepublic class MedicineService {
 @Autowired private MedicineRepository medicineRepository;

 public List getAllMedicines() {
 return medicineRepository.findAll();
 }

 public Medicine getMedicineById(Long id) {
 return medicineRepository.findById(id).orElse(null);
 }
}


### 药品控制器
java// MedicineController.java@RestController@RequestMapping("/api/medicines")
public class MedicineController {
 @Autowired private MedicineService medicineService;

 @GetMapping public ResponseEntity> getAllMedicines() {
 List medicines = medicineService.getAllMedicines();
 return ResponseEntity.ok(medicines);
 }

 @GetMapping("/{id}")
 public ResponseEntity getMedicineById(@PathVariable Long id) {
 Medicine medicine = medicineService.getMedicineById(id);
 return ResponseEntity.ok(medicine);
 }
}


以上是护网实训场景二的实现代码。

相关标签:
其他信息

其他资源

Top