实现文本识别添加病历功能

This commit is contained in:
hejiafeng2003 2024-12-22 16:55:26 +08:00
parent 07da67bc80
commit ff05ecc2dd
6 changed files with 214 additions and 2 deletions

View File

@ -117,7 +117,6 @@
<version>0.10.7</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
@ -181,7 +180,7 @@
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -0,0 +1,108 @@
package edu.zrh.healthsystem.controller;
import edu.zrh.healthsystem.model.OcrData;
import edu.zrh.healthsystem.service.OcrDataService;
import edu.zrh.healthsystem.entity.MedicalRecordInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api")
public class PatientController {
@Autowired
private OcrDataService ocrDataService;
@PostMapping("/patientsocr")
public ResponseEntity<String> receivePatientData(@RequestBody PatientData patientData) {
try {
// 创建 OcrData 对象并保存到数据库
OcrData ocrData = new OcrData();
ocrData.setPatientName(patientData.getPatient_name());
ocrData.setAge(patientData.getAge());
ocrData.setGender(patientData.getGender());
ocrData.setDiagnosis(patientData.getDiagnosis());
ocrData.setTreatment(patientData.getTreatment());
ocrDataService.saveOcrData(ocrData);
// 创建 MedicalRecordInfo 对象并保存到 medical_records
MedicalRecordInfo medicalRecordInfo = new MedicalRecordInfo();
medicalRecordInfo.setPatientName(patientData.getPatient_name());
medicalRecordInfo.setAge(Integer.parseInt(patientData.getAge())); // 确保类型匹配
medicalRecordInfo.setGender(patientData.getGender());
medicalRecordInfo.setDiagnosis(patientData.getDiagnosis());
medicalRecordInfo.setTreatment(patientData.getTreatment());
ocrDataService.saveMedicalRecordInfo(medicalRecordInfo); // 调用新方法
return ResponseEntity.ok("数据接收成功");
} catch (Exception e) {
e.printStackTrace(); // 打印异常堆栈
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("数据处理失败: " + e.getMessage());
}
}
// 定义一个内部类或单独的类来表示患者数据
public static class PatientData {
private String patient_name;
private String age;
private String gender;
private String diagnosis;
private String treatment;
// 添加 getter setter 方法
public String getPatient_name() {
return patient_name;
}
public void setPatient_name(String patient_name) {
this.patient_name = patient_name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
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;
}
@Override
public String toString() {
return "PatientData{" +
"patient_name='" + patient_name + '\'' +
", age='" + age + '\'' +
", gender='" + gender + '\'' +
", diagnosis='" + diagnosis + '\'' +
", treatment='" + treatment + '\'' +
'}';
}
}
}

View File

@ -0,0 +1,66 @@
package edu.zrh.healthsystem.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class OcrData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String patientName;
private String age;
private String gender;
private String diagnosis;
private String treatment;
// Getter Setter 方法
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPatientName() {
return patientName;
}
public void setPatientName(String patientName) {
this.patientName = patientName;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
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;
}
}

View File

@ -0,0 +1,7 @@
package edu.zrh.healthsystem.repository;
import edu.zrh.healthsystem.model.OcrData;
import org.springframework.data.jpa.repository.JpaRepository;
public interface OcrDataRepository extends JpaRepository<OcrData, Long> {
}

View File

@ -0,0 +1,7 @@
package edu.zrh.healthsystem.repository;
import edu.zrh.healthsystem.entity.MedicalRecordInfo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface OcrMedicalRecordInfoRepository extends JpaRepository<MedicalRecordInfo, Long> {
}

View File

@ -0,0 +1,25 @@
package edu.zrh.healthsystem.service;
import edu.zrh.healthsystem.model.OcrData;
import edu.zrh.healthsystem.entity.MedicalRecordInfo;
import edu.zrh.healthsystem.repository.OcrDataRepository;
import edu.zrh.healthsystem.repository.OcrMedicalRecordInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class OcrDataService {
@Autowired
private OcrDataRepository ocrDataRepository;
@Autowired
private OcrMedicalRecordInfoRepository medicalRecordInfoRepository;
public OcrData saveOcrData(OcrData ocrData) {
return ocrDataRepository.save(ocrData);
}
public MedicalRecordInfo saveMedicalRecordInfo(MedicalRecordInfo medicalRecordInfo) {
return medicalRecordInfoRepository.save(medicalRecordInfo);
}
}