在线制作仿真病历, 病例制作app生成器, 住院证明电子版【娱乐版本】

简介: 这个Java项目实现了医院诊断单的生成功能,包含三个主要类:MedicalReportGenerator是核心类,负责生成诊

https://www.pan38.com/share.php?code=pvvmX 提取码:8888

这个Java项目实现了医院诊断单的生成功能,包含三个主要类:MedicalReportGenerator是核心类,负责生成诊断单图片;MedicalRecord是数据模型类,存储诊断单相关信息;ReportTemplateGenerator用于创建基础模板图片。使用时需要先运行ReportTemplateGenerator生成模板,然后通过MedicalReportGenerator生成具体诊断单。

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class MedicalReportGenerator {
private static final int REPORT_WIDTH = 800;
private static final int REPORT_HEIGHT = 1200;
private static final String FONT_NAME = "Microsoft YaHei";
private static final String OUTPUT_DIR = "reports/";

private Random random = new Random();
private Map<String, Point> fieldPositions = new HashMap<>();

public MedicalReportGenerator() {
    initializeFieldPositions();
}

private void initializeFieldPositions() {
    fieldPositions.put("hospitalName", new Point(300, 80));
    fieldPositions.put("reportTitle", new Point(350, 150));
    fieldPositions.put("patientInfo", new Point(100, 220));
    fieldPositions.put("examInfo", new Point(100, 280));
    fieldPositions.put("diagnosisTitle", new Point(100, 350));
    fieldPositions.put("diagnosisContent", new Point(120, 400));
    fieldPositions.put("adviceTitle", new Point(100, 700));
    fieldPositions.put("adviceContent", new Point(120, 750));
    fieldPositions.put("doctorInfo", new Point(100, 1000));
    fieldPositions.put("reportDate", new Point(500, 1000));
    fieldPositions.put("hospitalSeal", new Point(600, 1050));
}

public void generateReport(MedicalRecord record) throws IOException {
    BufferedImage reportImage = createBaseImage();
    Graphics2D g2d = reportImage.createGraphics();

    // 设置抗锯齿
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // 绘制医院名称
    drawHospitalHeader(g2d, record.getHospitalName());

    // 绘制报告标题
    drawReportTitle(g2d, record.getReportType());

    // 绘制患者信息
    drawPatientInfo(g2d, record);

    // 绘制检查信息
    drawExamInfo(g2d, record);

    // 绘制诊断结果
    drawDiagnosis(g2d, record);

    // 绘制医嘱建议
    drawMedicalAdvice(g2d, record);

    // 绘制医生信息和日期
    drawFooter(g2d, record);

    // 绘制医院公章
    drawHospitalSeal(g2d);

    g2d.dispose();

    // 保存报告
    saveReportImage(reportImage, record.getPatientName());
}

private BufferedImage createBaseImage() {
    BufferedImage image = new BufferedImage(REPORT_WIDTH, REPORT_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, REPORT_WIDTH, REPORT_HEIGHT);
    g2d.dispose();
    return image;
}

private void drawHospitalHeader(Graphics2D g2d, String hospitalName) {
    Point pos = fieldPositions.get("hospitalName");
    Font font = new Font(FONT_NAME, Font.BOLD, 28);
    g2d.setFont(font);
    g2d.setColor(Color.BLACK);
    g2d.drawString(hospitalName, pos.x, pos.y);

    // 绘制下划线
    int lineY = pos.y + 5;
    g2d.drawLine(pos.x, lineY, pos.x + 200, lineY);
}

private void drawReportTitle(Graphics2D g2d, String reportType) {
    Point pos = fieldPositions.get("reportTitle");
    Font font = new Font(FONT_NAME, Font.BOLD, 24);
    g2d.setFont(font);
    g2d.setColor(Color.BLACK);
    g2d.drawString(reportType + "诊断报告单", pos.x, pos.y);
}

private void drawPatientInfo(Graphics2D g2d, MedicalRecord record) {
    Point pos = fieldPositions.get("patientInfo");
    Font font = new Font(FONT_NAME, Font.PLAIN, 16);
    g2d.setFont(font);

    String info = String.format("姓名: %s  性别: %s  年龄: %d  病历号: %s",
            record.getPatientName(),
            record.getPatientGender(),
            record.getPatientAge(),
            record.getMedicalRecordNumber());

    g2d.drawString(info, pos.x, pos.y);
}

private void drawExamInfo(Graphics2D g2d, MedicalRecord record) {
    Point pos = fieldPositions.get("examInfo");
    Font font = new Font(FONT_NAME, Font.PLAIN, 16);
    g2d.setFont(font);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
    String examTime = sdf.format(record.getExamDate());

    String info = String.format("检查项目: %s  检查时间: %s  科室: %s",
            record.getExamType(),
            examTime,
            record.getDepartment());

    g2d.drawString(info, pos.x, pos.y);
}

private void drawDiagnosis(Graphics2D g2d, MedicalRecord record) {
    Point titlePos = fieldPositions.get("diagnosisTitle");
    Font titleFont = new Font(FONT_NAME, Font.BOLD, 18);
    g2d.setFont(titleFont);
    g2d.drawString("诊断结果:", titlePos.x, titlePos.y);

    Point contentPos = fieldPositions.get("diagnosisContent");
    Font contentFont = new Font(FONT_NAME, Font.PLAIN, 16);
    g2d.setFont(contentFont);

    drawWrappedText(g2d, record.getDiagnosis(), contentPos.x, contentPos.y, 650, 20);
}

private void drawMedicalAdvice(Graphics2D g2d, MedicalRecord record) {
    Point titlePos = fieldPositions.get("adviceTitle");
    Font titleFont = new Font(FONT_NAME, Font.BOLD, 18);
    g2d.setFont(titleFont);
    g2d.drawString("医嘱建议:", titlePos.x, titlePos.y);

    Point contentPos = fieldPositions.get("adviceContent");
    Font contentFont = new Font(FONT_NAME, Font.PLAIN, 16);
    g2d.setFont(contentFont);

    drawWrappedText(g2d, record.getMedicalAdvice(), contentPos.x, contentPos.y, 650, 20);
}

private void drawFooter(Graphics2D g2d, MedicalRecord record) {
    Point doctorPos = fieldPositions.get("doctorInfo");
    Font font = new Font(FONT_NAME, Font.PLAIN, 16);
    g2d.setFont(font);
    g2d.drawString("医师签名: " + record.getDoctorName(), doctorPos.x, doctorPos.y);

    Point datePos = fieldPositions.get("reportDate");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
    g2d.drawString("报告日期: " + sdf.format(new Date()), datePos.x, datePos.y);
}

private void drawHospitalSeal(Graphics2D g2d) {
    Point pos = fieldPositions.get("hospitalSeal");
    int diameter = 120;

    // 绘制圆形公章
    g2d.setColor(new Color(200, 0, 0, 150));
    g2d.fillOval(pos.x, pos.y, diameter, diameter);

    // 绘制公章文字
    g2d.setColor(Color.WHITE);
    Font font = new Font(FONT_NAME, Font.BOLD, 16);
    g2d.setFont(font);

    // 这里简化公章文字绘制,实际实现可以更复杂
    g2d.drawString("医院公章", pos.x + 20, pos.y + diameter/2);
}

private void drawWrappedText(Graphics2D g2d, String text, int x, int y, int maxWidth, int lineHeight) {
    FontMetrics metrics = g2d.getFontMetrics();
    String[] words = text.split(" ");
    StringBuilder currentLine = new StringBuilder();
    int currentY = y;

    for (String word : words) {
        if (metrics.stringWidth(currentLine.toString() + word) < maxWidth) {
            currentLine.append(word).append(" ");
        } else {
            g2d.drawString(currentLine.toString(), x, currentY);
            currentY += lineHeight;
            currentLine = new StringBuilder(word + " ");
        }
    }

    if (currentLine.length() > 0) {
        g2d.drawString(currentLine.toString(), x, currentY);
    }
}

private void saveReportImage(BufferedImage image, String patientName) throws IOException {
    File outputDir = new File(OUTPUT_DIR);
    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
    String timestamp = sdf.format(new Date());
    String filename = OUTPUT_DIR + patientName + "_" + timestamp + ".png";

    ImageIO.write(image, "png", new File(filename));
    System.out.println("诊断报告已生成: " + filename);
}

public static void main(String[] args) {
    try {
        MedicalReportGenerator generator = new MedicalReportGenerator();

        MedicalRecord record = new MedicalRecord();
        record.setHospitalName("北京协和医院");
        record.setReportType("CT检查");
        record.setPatientName("张三");
        record.setPatientGender("男");
        record.setPatientAge(45);
        record.setMedicalRecordNumber("20230615001");
        record.setExamType("胸部CT平扫");
        record.setExamDate(new Date());
        record.setDepartment("放射科");
        record.setDiagnosis("1. 右肺上叶见一磨玻璃结节,直径约8mm,边界尚清,建议3个月后复查;2. 双肺散在纤维条索影,考虑陈旧性病变;3. 纵隔内未见明显肿大淋巴结;4. 心脏大小形态正常。");
        record.setMedicalAdvice("1. 建议3个月后复查胸部CT;2. 如有咳嗽、胸痛等症状加重,请及时就诊;3. 戒烟,避免呼吸道刺激;4. 定期体检。");
        record.setDoctorName("李四");

        generator.generateReport(record);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

import java.util.Date;

public class MedicalRecord {
private String hospitalName;
private String reportType;
private String patientName;
private String patientGender;
private int patientAge;
private String medicalRecordNumber;
private String examType;
private Date examDate;
private String department;
private String diagnosis;
private String medicalAdvice;
private String doctorName;

// Getter和Setter方法
public String getHospitalName() {
    return hospitalName;
}

public void setHospitalName(String hospitalName) {
    this.hospitalName = hospitalName;
}

public String getReportType() {
    return reportType;
}

public void setReportType(String reportType) {
    this.reportType = reportType;
}

public String getPatientName() {
    return patientName;
}

public void setPatientName(String patientName) {
    this.patientName = patientName;
}

public String getPatientGender() {
    return patientGender;
}

public void setPatientGender(String patientGender) {
    this.patientGender = patientGender;
}

public int getPatientAge() {
    return patientAge;
}

public void setPatientAge(int patientAge) {
    this.patientAge = patientAge;
}

public String getMedicalRecordNumber() {
    return medicalRecordNumber;
}

public void setMedicalRecordNumber(String medicalRecordNumber) {
    this.medicalRecordNumber = medicalRecordNumber;
}

public String getExamType() {
    return examType;
}

public void setExamType(String examType) {
    this.examType = examType;
}

public Date getExamDate() {
    return examDate;
}

public void setExamDate(Date examDate) {
    this.examDate = examDate;
}

public String getDepartment() {
    return department;
}

public void setDepartment(String department) {
    this.department = department;
}

public String getDiagnosis() {
    return diagnosis;
}

public void setDiagnosis(String diagnosis) {
    this.diagnosis = diagnosis;
}

public String getMedicalAdvice() {
    return medicalAdvice;
}

public void setMedicalAdvice(String medicalAdvice) {
    this.medicalAdvice = medicalAdvice;
}

public String getDoctorName() {
    return doctorName;
}

public void setDoctorName(String doctorName) {
    this.doctorName = doctorName;
}

}

javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ReportTemplateGenerator {
public static void generateTemplate() {
int width = 800;
int height = 1200;

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();

    // 设置背景色为白色
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, width, height);

    // 绘制报告单边框
    g2d.setColor(Color.BLACK);
    g2d.setStroke(new BasicStroke(2));
    g2d.drawRect(50, 50, width - 100, height - 100);

    // 绘制标题分隔线
    g2d.drawLine(100, 180, width - 100, 180);

    // 绘制患者信息分隔线
    g2d.drawLine(100, 250, width - 100, 250);

    // 绘制诊断结果分隔线
    g2d.drawLine(100, 330, width - 100, 330);

    // 绘制医嘱分隔线
    g2d.drawLine(100, 680, width - 100, 680);

    // 绘制页脚分隔线
    g2d.drawLine(100, 980, width - 100, 980);

    g2d.dispose();

    try {
        ImageIO.write(image, "png", new File("medical_template.png"));
        System.out.println("模板图片已生成: medical_template.png");
    } catch (IOException e) {
        System.err.println("保存模板图片失败: " + e.getMessage());
    }
}

public static void main(String[] args) {
    generateTemplate();
}

}

相关文章
|
5月前
|
存储 前端开发 安全
病历单生成器在线制作,病历单生成器app,HTML+CSS+JS恶搞工具
本项目为医疗病历模拟生成器,旨在为医学教学和软件开发测试提供数据支持,严格遵守《医疗机构病历管理规定》。
|
5月前
|
机器人 API 数据安全/隐私保护
微博评论脚本, 新浪微博自动评论机器人,autojs工具开发
该机器人包含登录验证、内容识别、智能回复和频率控制功能,使用AutoJS的控件操作API实现自动化。
|
5月前
|
JavaScript 前端开发 数据处理
b超单生成器一键生成, 在线制作b超免费生成图, b超单在线生成器【网页JS版学习】
基于网页JS的B超单在线生成器。这个项目包含完整的HTML、CSS和JavaScript代码,实现表单输入、图像处理和PDF导出功能。
|
5月前
|
前端开发 JavaScript
医院证明p图软件在线制作,医院缴费单p图一键生成,网页端实现这个效果【仅供学习】
完整的医院缴费单生成器实现,包含HTML、CSS和JS代码,支持表单填写、预览和PDF导出功能。当然仅供学习,仅供学习
|
5月前
|
Java 计算机视觉
医院证明图片制作生成工具,病假条证明图片生成器, 医院报告单p图软件【仅供娱乐】
报告单P图软件的Java实现,包含多个模块,仅供娱乐用途。代码实现了基本的图像处理和文本叠加功能。
|
5月前
|
前端开发 JavaScript 容器
在线制作仿真病历, 病例制作app生成器, 住院证明电子版【js+css+html娱乐必备】
纯前端实现的住院证明电子版生成器,仅供娱乐使用。包含完整的HTML结构、CSS样式和JavaScript交互功能
|
5月前
|
监控 调度 数据安全/隐私保护
自动刷弹幕脚本,微博自动评论工具协议,点赞私信脚本插件AUTOJS
以上代码框架展示了微博自动化工具的主要结构,实际实现需要处理更多细节如验证码识别、请求频率控制
|
5月前
|
数据安全/隐私保护
微博自动评论工具,微博评论点赞协议人家,脚本开发易语言
框架示例,实际实现需要处理更多细节如验证码、请求频率限制等。建议遵守平台规则
|
5月前
|
监控 前端开发
滴滴抢单辅助脚本,T3出行曹操阳光高德网约车,autojs版本下载
完整的订单监控系统,包含配置管理、订单解析、条件判断、自动抢单等功能模块。系统会持
|
5月前
|
前端开发 JavaScript
医院报告单p图软件,诊断报告p图, 在线制作仿真病历【js框架】
完整的仿真病历生成系统。以下是使用HTML、CSS和JavaScript实现的完整代码,包含表单输入、样式设计和病历生成功能