老年人评估系统开发记录03(知觉评估)

知觉评估

今天来完成老人的知觉评估,对于老人的直接评估,在数据库层面是实现对于通过表单的形式实现对于数据的添加.提交之后保存到数据库之中


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加感知觉与沟通评估</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Roboto', sans-serif;
            background: linear-gradient(135deg, #f6f9fc, #eef3f6);
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            width: 50%;
            background: #fff;
            padding: 30px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
        }
        h2 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin: 10px 0 5px;
            color: #555;
        }
        input[type="text"], input[type="number"], select {
            width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            transition: border-color 0.3s ease-in-out;
        }
        input[type="text"]:focus, input[type="number"]:focus, select:focus {
            border-color: #007bff;
        }
        input[type="submit"] {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease-in-out;
        }
        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>添加感知觉与沟通评估</h2>
    <form action="${pageContext.request.contextPath}/AddCommunicationServlet" method="post">
        <div class="container">
                <div class="form-group">
                    <label for="assessmentID">评估编号</label>
                    <input type="text" id="assessmentID" name="assessmentID" required
                           placeholder="请输入唯一评估标识符">
                </div>

                <div class="form-group">
                    <label for="consciousnessLevel">意识水平评估</label>
                    <p class="form-description">评估标准:0=清醒,1=嗜睡,2=昏睡,3=昏迷</p>
                    <select id="consciousnessLevel" name="consciousnessLevel" required>
                        <option value="0">0: 神志清醒</option>
                        <option value="1">1: 嗜睡状态</option>
                        <option value="2">2: 昏睡状态</option>
                        <option value="3">3: 昏迷状态</option>
                    </select>
                </div>

            <label for="visionLevel">视力评分:</label>
            <select id="visionLevel" name="visionLevel" required>
                <option value="0">0: 能看清书报上的标准字体</option>
                <option value="1">1: 能看清楚大字体</option>
                <option value="2">2: 视力有限</option>
                <option value="3">3: 辨认物体有困难</option>
                <option value="4">4: 没有视力</option>
            </select>

            <label for="hearingLevel">听力评分:</label>
            <select id="hearingLevel" name="hearingLevel" required>
                <option value="0">0: 可正常交谈</option>
                <option value="1">1: 轻声说话或距离超过2米时听不清</option>
                <option value="2">2: 正常交流有些困难</option>
                <option value="3">3: 大声说话才能部分听见</option>
                <option value="4">4: 完全听不见</option>
            </select>

            <label for="communicationLevel">沟通交流评分:</label>
            <select id="communicationLevel" name="communicationLevel" required>
                <option value="0">0: 无困难</option>
                <option value="1">1: 需要增加时间或帮助</option>
                <option value="2">2: 表达或理解有困难</option>
                <option value="3">3: 不能表达或理解</option>
            </select>

                <input type="submit" value="提交评估结果">
        </div>
            </form>

</div>
</body>
</html>


package com.QixunQiu.service;

import com.QixunQiu.mapper.DailyMapper;
import com.QixunQiu.pojo.Daily;
import com.QixunQiu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class DailyService {
    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
    public List<Daily> selectDaily(String AssessmentID) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        DailyMapper dailyMapper = sqlSession.getMapper(DailyMapper.class);
        List<Daily> dailyList=dailyMapper.select(AssessmentID);
        sqlSession.close();
        return dailyList;
    }

    public void addDaily(Daily daily) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        DailyMapper dailyMapper = sqlSession.getMapper(DailyMapper.class);
        dailyMapper.add(daily);
        sqlSession.commit();
        sqlSession.close();
    }
}



在servlet实现在数据库层面对于数据的存储

package com.QixunQiu.web;

import com.QixunQiu.pojo.Communication;
import com.QixunQiu.service.CommunicationService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/AddCommunicationServlet")
public class AddCommunicationServlet extends HttpServlet {
    private CommunicationService communicationService = new CommunicationService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String assessmentID=request.getParameter("assessmentID");
        int consciousnessLevel=Integer.parseInt(request.getParameter("consciousnessLevel"));
        int visionLevel=Integer.parseInt(request.getParameter("visionLevel"));
        int hearingLevel=Integer.parseInt(request.getParameter("hearingLevel"));
        int communicationLevel=Integer.parseInt(request.getParameter("communicationLevel"));

        int overallGrade;
        if (consciousnessLevel == 0 && visionLevel <= 1 && hearingLevel <= 1 && communicationLevel == 0) {
            overallGrade = 0;
        } else if (consciousnessLevel == 0 && (visionLevel == 2 || hearingLevel == 2) || communicationLevel == 1) {
            overallGrade = 1;
        } else if ((consciousnessLevel == 0 && (visionLevel == 3 || hearingLevel == 3) || communicationLevel == 2) ||
                (consciousnessLevel == 1 && visionLevel <= 3 && hearingLevel <= 3 && communicationLevel <= 2)) {
            overallGrade= 2;
        } else {
            overallGrade= 3;
        }

        Communication communication = new Communication();
        communication.setAssessmentID(assessmentID);
        communication.setConsciousnessLevel(consciousnessLevel);
        communication.setVisionLevel(visionLevel);
        communication.setHearingLevel(hearingLevel);
        communication.setCommunicationLevel(communicationLevel);
        communication.setOverallGrade(overallGrade);
        communicationService.add(communication);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

posted @ 2025-02-18 21:51  元始天尊123  阅读(14)  评论(0)    收藏  举报