基于javaweb+mysql的springboot医院管理系统(java+springboot+layui+freemaker+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot医院管理系统(java+springboot+layui+freemaker+maven+mysql)
项目介绍
医院管理系统,分为管理员、医生、病人三种角色;
管理员主要功能包括: 首页、系统管理:医生管理、患者管理、药品管理;预约管理;病史管理;住院信息管理;管理员用户管理; 医生主要功能包括:首页、就医/查看病史;
病人主要功能包括:首页、病史、住院信息、挂号;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
技术栈
-
后端:SpringBoot
-
前端:Layui+Freemaker
使用说明
-
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
-
使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令
- 将项目中application.yml配置文件中的数据库配置改为自己的配置,配置tomcat,然后运行; 4. 运行项目,输入http://localhost:8088 登录
/**
*/
public class MyShiroRealm extends AuthorizingRealm{
@Autowired
private LoginMapper loginMapper;
@Autowired
private HttpServletRequest request;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
return null;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//获取用户信息
String username = authenticationToken.getPrincipal().toString();
String password = new String((char[]) authenticationToken.getCredentials());
Login user = loginMapper.findByUsername(username);
//验证登录账号
if (user == null) {
throw new UnknownAccountException("用户名不存在");
}
//验证密码
if(!StringUtils.equals(user.getPassword(), password)){
throw new UnknownAccountException("密码错误,请重新输入");
}
//把登录人存进session
SecurityUtils.getSubject().getSession().setAttribute("currentManager", user);
return new SimpleAuthenticationInfo(user, password, this.getName());
}
}
@Controller
public class LoginController {
@Autowired
LoginService loginService;
@RequestMapping(value = "/hospital/login")
public String loginAndregist(){
return "login®ist";
}
@RequestMapping("/admin/adminManage")
public String adminManage(HttpServletRequest request,@RequestParam(value = "username",required = false)String username){
request.setAttribute("admins",loginService.findAllAdmin(username));
return "/admin/adminManage";
}
@RequestMapping("/admin/admin/{id}")
public String adminInfo(HttpServletRequest request,@PathVariable Integer id){
request.setAttribute("admin",loginService.getAdmin(id));
return "/admin/info/admininfo";
}
@RequestMapping("/admin/adminAdd")
public String adminAddPage(){
return"admin/add/adminadd";
}
@RequestMapping(value = "/admin/admin",method = RequestMethod.POST)
@ResponseBody
public JSONObject adminAdd(@RequestBody Login login){
JSONObject json=new JSONObject();
json.put("message",loginService.addAmin(login));
return json;
}
@RequestMapping(value = "/admin/admin",method = RequestMethod.PUT)
@ResponseBody
}
}
/**
*/
public class MyShiroRealm extends AuthorizingRealm{
@Autowired
private LoginMapper loginMapper;
@Autowired
private HttpServletRequest request;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
return null;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//获取用户信息
String username = authenticationToken.getPrincipal().toString();
String password = new String((char[]) authenticationToken.getCredentials());
Login user = loginMapper.findByUsername(username);
//验证登录账号
if (user == null) {
throw new UnknownAccountException("用户名不存在");
}
//验证密码
if(!StringUtils.equals(user.getPassword(), password)){
throw new UnknownAccountException("密码错误,请重新输入");
}
//把登录人存进session
SecurityUtils.getSubject().getSession().setAttribute("currentManager", user);
return new SimpleAuthenticationInfo(user, password, this.getName());
}
}
@RequestMapping("/doctor/seekMedicalAdvice")
public String seekMedicalAdvice(HttpServletRequest request, HttpSession session,@RequestParam(value = "patientname",required = false)String patientname,@RequestParam(value = "time",required = false)String time){
Login login=(Login)session.getAttribute("login");
Doctor doctor=doctorService.getDoctorByLoginId(login.getId());
request.setAttribute("appointments" ,appointmentService.selectByDoctorId(doctor.getId(),patientname,time));
return "doctor/seekMedicalAdvice";
}
@RequestMapping("/doctor/seek/{id}")
public String seek(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patient",patientService.getPatient(id));
request.setAttribute("drugs",drugsService.getAllDrugs());
return "doctor/seek";
}
@RequestMapping(value = "/doctor/drug",method = RequestMethod.PUT)
@ResponseBody
public JSONObject drug(@RequestBody Map map){
JSONObject json=new JSONObject();
Patient patient=new Patient();
System.out.println(map);
patient.setDrugsids(DrugsUtils.vaild(map));
patient.setId(Integer.parseInt((String)map.get("patientid")));
json.put("message",patientService.seek(patient));
return json;
}
@RequestMapping(value = "/doctor/zation",method = RequestMethod.POST)
@ResponseBody
public JSONObject zation(@RequestBody Hospitalization hospitalization){
JSONObject json=new JSONObject();
json.put("message",hospitalizationService.AddHospitalization(hospitalization));
return json;
}
@RequestMapping(value = "/doctor/medicalhistory/{id}")
public String medicalhistory(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("medicalhistorys",medicalhistoryService.getMedicalhistoryByPatientId(id));
return "doctor/medicalhistory";
}
@RequestMapping( value = "/doctor/{department}",method = RequestMethod.GET)
@ResponseBody
public JSONObject getDoctorByDepartment(@PathVariable String department){
JSONObject json=new JSONObject();
json.put("doctors",doctorService.getDoctorByDepartment(department));
return json;
}
public class ShiroLoginFilter extends FormAuthenticationFilter {
/**
* 在访问controller前判断是否登录,返回json,不进行重定向。
* @param request
* @param response
* @return true-继续往下执行,false-该filter过滤器已经处理,不继续执行其他过滤器
* @throws Exception
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
if (isAjax(request)) {
HashMap<String,Object> result = new HashMap<>();
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.setContentType("application/json");
result.put("msg","未登录");
result.put("status",-1);
httpServletResponse.getWriter().write(JSONObject.toJSON(result).toString());
}/* else {
*//**
* @Mark 非ajax请求重定向为登录页面
*//*
httpServletResponse.sendRedirect("/gbq_blog/login/noLogin");
}*/
return false;
}
private boolean isAjax(ServletRequest request) {
String header = ((HttpServletRequest) request).getHeader("X-Requested-With");
return "XMLHttpRequest".equalsIgnoreCase(header);
}
}
/**
/**
*/
public class MyShiroRealm extends AuthorizingRealm{
@Autowired
private LoginMapper loginMapper;
@Autowired
private HttpServletRequest request;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
return null;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//获取用户信息
String username = authenticationToken.getPrincipal().toString();
String password = new String((char[]) authenticationToken.getCredentials());
Login user = loginMapper.findByUsername(username);
//验证登录账号
if (user == null) {
throw new UnknownAccountException("用户名不存在");
}
//验证密码
if(!StringUtils.equals(user.getPassword(), password)){
throw new UnknownAccountException("密码错误,请重新输入");
}
//把登录人存进session
SecurityUtils.getSubject().getSession().setAttribute("currentManager", user);
return new SimpleAuthenticationInfo(user, password, this.getName());
}
}
@Controller
public class HospitalizationController {
@Autowired
HospitalizationService hospitalizationService;
@Autowired
PatientService patientService;
@RequestMapping("/admin/hospitalizationManage")
public String hospitalizationManage(HttpServletRequest request,@RequestParam(value = "patientname",required = false)String patientname,@RequestParam(value = "intime",required = false)String intime){
request.setAttribute("hospitalizations",hospitalizationService.getAllHospitalizations(patientname,intime));
return "admin/hospitalizationManage";
}
@RequestMapping("/admin/hospitalizationAdd")
public String hospitalizationAddPage(HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
return"admin/add/hospitalizationadd";
}
@RequestMapping(value = "/admin/hospitalization",method = RequestMethod.POST)
@ResponseBody
public JSONObject hospitalizationAdd(@RequestBody Hospitalization hospitalization){
JSONObject json=new JSONObject();
json.put("message",hospitalizationService.AddHospitalization(hospitalization));
return json;
}
@RequestMapping(value = "/admin/hospitalization/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delHospitalization(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",hospitalizationService.deleteHospitalization(id));
return json;
}
@RequestMapping(value = "/admin/hospitalization/{id}",method = RequestMethod.GET)
public String hospitalizationInfo(HttpServletRequest request,@PathVariable Integer id){
@Controller
public class LoginController {
@Autowired
LoginService loginService;
@RequestMapping(value = "/hospital/login")
public String loginAndregist(){
return "login®ist";
}
@RequestMapping("/admin/adminManage")
public String adminManage(HttpServletRequest request,@RequestParam(value = "username",required = false)String username){
request.setAttribute("admins",loginService.findAllAdmin(username));
return "/admin/adminManage";
}
@RequestMapping("/admin/admin/{id}")
public String adminInfo(HttpServletRequest request,@PathVariable Integer id){
request.setAttribute("admin",loginService.getAdmin(id));
return "/admin/info/admininfo";
}
@RequestMapping("/admin/adminAdd")
public String adminAddPage(){
return"admin/add/adminadd";
}
@RequestMapping(value = "/admin/admin",method = RequestMethod.POST)
@ResponseBody
public JSONObject adminAdd(@RequestBody Login login){
JSONObject json=new JSONObject();
json.put("message",loginService.addAmin(login));
return json;
}
@RequestMapping(value = "/admin/admin",method = RequestMethod.PUT)
@ResponseBody
public JSONObject upAdmin(@RequestBody Login login){
JSONObject json=new JSONObject();
json.put("message",loginService.updateAdmin(login));
return json;
}
@RequestMapping(value = "/admin/admin/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delAdmin(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",loginService.delAdmin(id));
return json;
}
@RequestMapping(value = "/loginout",method = RequestMethod.GET)
public String loginout(HttpSession session){
session.removeAttribute("login");
return "login®ist";
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(filename, "utf-8"));
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
}
}
@Controller
public class DrugsController {
@Autowired
DrugsService drugsService;
@RequestMapping("admin/drugsManage")
public String drugsManage(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="type",required = false) Integer type){
Drugs drugs=new Drugs();
drugs.setName(name);
drugs.setType(type);
request.setAttribute("drugs",drugsService.getAllDrugs(drugs));
return "/admin/drugsManage";
}
@RequestMapping(value = "/admin/drug/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delDrug(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",drugsService.delDrug(id));
return json;
}
@RequestMapping(value = "/admin/drug",method = RequestMethod.POST)
@ResponseBody
public JSONObject addDrug(@RequestBody Drugs drugs){
JSONObject json=new JSONObject();
json.put("message",drugsService.addDrug(drugs));
cell.setCellValue("患者");
cell.setCellStyle(style);
cell = row.createCell(5);
cell.setCellValue("患病");
cell.setCellStyle(style);
cell = row.createCell(6);
cell.setCellValue("住院时间");
cell.setCellStyle(style);
cell = row.createCell(7);
cell.setCellValue("出院时间");
cell.setCellStyle(style);
}
//生成excel文件
public static void buildExcelFile(String filename,HSSFWorkbook workbook) throws Exception{
FileOutputStream fos = new FileOutputStream(filename);
workbook.write(fos);
fos.flush();
fos.close();
}
//浏览器下载excel
public static void buildExcelDocument(String filename, HSSFWorkbook workbook, HttpServletResponse response) throws Exception{
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(filename, "utf-8"));
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
}
}
@Controller
public class DrugsController {
@Autowired
DrugsService drugsService;
@RequestMapping("admin/drugsManage")
public String drugsManage(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="type",required = false) Integer type){
Drugs drugs=new Drugs();
}
@RequestMapping(value = "/admin/drug/{id}",method = RequestMethod.GET)
public String drugInfo(HttpServletRequest request,@PathVariable Integer id) {
request.setAttribute("drug",drugsService.getDrug(id));
return "/admin/info/drugsinfo";
}
@RequestMapping(value = "/admin/drug",method = RequestMethod.PUT)
@ResponseBody
public JSONObject updateDrug(@RequestBody Drugs drugs) {
JSONObject json=new JSONObject();
json.put("message",drugsService.updateDrug(drugs));
return json;
}
}
/**
*/
public class ShiroLoginFilter extends FormAuthenticationFilter {
/**
* 在访问controller前判断是否登录,返回json,不进行重定向。
* @param request
* @param response
* @return true-继续往下执行,false-该filter过滤器已经处理,不继续执行其他过滤器
* @throws Exception
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
public String medicalhistory(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("medicalhistorys",medicalhistoryService.getMedicalhistoryByPatientId(id));
return "doctor/medicalhistory";
}
@RequestMapping( value = "/doctor/{department}",method = RequestMethod.GET)
@ResponseBody
public JSONObject getDoctorByDepartment(@PathVariable String department){
JSONObject json=new JSONObject();
json.put("doctors",doctorService.getDoctorByDepartment(department));
return json;
}
}
@Controller
public class LoginController {
@Autowired
LoginService loginService;
@RequestMapping(value = "/hospital/login")
public String loginAndregist(){
return "login®ist";
}
@RequestMapping("/admin/adminManage")
public String adminManage(HttpServletRequest request,@RequestParam(value = "username",required = false)String username){
request.setAttribute("admins",loginService.findAllAdmin(username));
return "/admin/adminManage";
}
@RequestMapping("/admin/admin/{id}")
//登录验证
subject.login(token);
String login1 = loginService.login(login);
JSONObject json=new JSONObject();
json.put("message",login1);
session.setAttribute("login",login);
return json;
}
@RequestMapping(value = "/regest",method = RequestMethod.POST)
@ResponseBody
public JSONObject regest(@RequestBody Login login){
JSONObject json=new JSONObject();
json.put("message",loginService.regist(login));
return json;
}
@RequestMapping("/hospital/patient/index")
public String patientIndex(){
return "/patient/index";
}
@RequestMapping("/hospital/doctor/index")
public String doctorIndex(){
return "/doctor/index";
}
@RequestMapping("/hospital/admin/index")
public String adminIndex(){
return "/admin/index";
}
}
@Controller
public class AppointmentController {
@Autowired
* @return
*/
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor(){
return new LifecycleBeanPostProcessor();
}
/**
* 开启Shiro的注解(如@RequiresRoles,@RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证
* 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能
* @return
*/
@Bean
@DependsOn({"lifecycleBeanPostProcessor"})
public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){
DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
advisorAutoProxyCreator.setProxyTargetClass(true);
return advisorAutoProxyCreator;
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(){
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager());
return authorizationAttributeSourceAdvisor;
}
}
@Controller
public class PatientController {
@Autowired
PatientService patientService;
@Autowired
DoctorService doctorService;
@Autowired
AppointmentService appointmentService;
@Autowired
HospitalizationService hospitalizationService;
request.setAttribute("doctor",doctorService.getDoctor(id));
return "admin/info/doctorinfo";
}
@RequestMapping(value = "/admin/doctor",method = RequestMethod.POST)
@ResponseBody
public JSONObject AddDoctor(@RequestBody Doctor doctor){
JSONObject json=new JSONObject();
json.put("message",doctorService.addDoctor(doctor));
return json;
}
@RequestMapping(value = "/admin/doctor",method = RequestMethod.PUT)
@ResponseBody
public JSONObject updateDoctor(@RequestBody Doctor doctor){
JSONObject json=new JSONObject();
json.put("message",doctorService.upDoctor(doctor));
return json;
}
@RequestMapping("/admin/doctorAdd")
public String doctorAddPage(){
return "admin/add/doctoradd";
}
@RequestMapping("/doctor/seekMedicalAdvice")
public String seekMedicalAdvice(HttpServletRequest request, HttpSession session,@RequestParam(value = "patientname",required = false)String patientname,@RequestParam(value = "time",required = false)String time){
Login login=(Login)session.getAttribute("login");
Doctor doctor=doctorService.getDoctorByLoginId(login.getId());
request.setAttribute("appointments" ,appointmentService.selectByDoctorId(doctor.getId(),patientname,time));
return "doctor/seekMedicalAdvice";
}
@RequestMapping("/doctor/seek/{id}")
public String seek(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patient",patientService.getPatient(id));
request.setAttribute("drugs",drugsService.getAllDrugs());
return "doctor/seek";
}
@RequestMapping(value = "/doctor/drug",method = RequestMethod.PUT)
@ResponseBody
public JSONObject drug(@RequestBody Map map){
JSONObject json=new JSONObject();
Patient patient=new Patient();
System.out.println(map);
patient.setDrugsids(DrugsUtils.vaild(map));
patient.setId(Integer.parseInt((String)map.get("patientid")));
json.put("message",patientService.seek(patient));
}
String fileName = "住院信息.xls";
//生成excel文件
//ExcelUtils.buildExcelFile(fileName, workbook);
//浏览器下载excel
ExcelUtils.buildExcelDocument(fileName,workbook,response);
return "download excel";
}
}
@Controller
public class DoctorController {
@Autowired
DoctorService doctorService;
@Autowired
AppointmentService appointmentService;
@Autowired
PatientService patientService;
@Autowired
DrugsService drugsService;
@Autowired
HospitalizationService hospitalizationService;
@Autowired
MedicalhistoryService medicalhistoryService;
@RequestMapping("/admin/doctorManage")
public String doctorManage(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="certId",required = false) String certId){
request.setAttribute("doctors",doctorService.getAllDoctor(name,certId));
return "admin/doctorManage";
}
@RequestMapping(value = "/admin/doctor/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject AppointmentAdd(@RequestBody Appointment appointment){
System.out.println(appointment);
JSONObject json=new JSONObject();
json.put("message",appointmentService.addAppointment(appointment));
return json;
}
}
@Controller
public class MedicalhistoryController {
@Autowired
PatientService patientService;
@Autowired
MedicalhistoryService medicalhistoryService;
@RequestMapping("/admin/medicalhistoryManage")
public String medicalhistoryManage(HttpServletRequest request,@RequestParam(value = "doctorname",required = false)String doctorname,@RequestParam(value = "patientname",required = false)String patientname){
request.setAttribute("medicalhistorys",medicalhistoryService.getAllMedicalhistorys(doctorname,patientname));
return "admin/medicalhistoryManage";
}
@RequestMapping("/admin/medicalhistoryAdd")
public String medicalhistoryAddPage(HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
return"admin/add/medicalhistoryadd";
}
@RequestMapping(value = "/admin/medicalhistory/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delmedicalhistory(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",medicalhistoryService.delMedicalhistory(id));
return json;
}
@RequestMapping(value = "/admin/medicalhistory/{id}",method = RequestMethod.GET)
public String medicalhistoryInfo(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
request.setAttribute("medicalhistory",medicalhistoryService.getMedicalhistory(id));
return "admin/info/medicalhistoryInfo";
}
@RequestMapping(value = "/admin/medicalhistory",method = RequestMethod.PUT)