瀏覽代碼

代码修改

LAPTOP-KB9HII50\70708 1 年之前
父節點
當前提交
f9b01efb11

+ 367 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/controller/DoctorHealthRecordController.java

@ -0,0 +1,367 @@
package com.yihu.jw.hospital.module.health.controller;
import com.yihu.jw.entity.base.health.PatientHealthRecordDiet;
import com.yihu.jw.entity.base.health.PatientHealthRecordMedication;
import com.yihu.jw.entity.base.health.PatientHealthRecordSports;
import com.yihu.jw.hospital.module.common.BaseController;
import com.yihu.jw.hospital.module.health.service.PatientHealthRecordService;
import com.yihu.jw.hospital.module.jw.service.JwArchivesService;
import com.yihu.jw.hospital.module.rehabilitation.service.PatientRecordService;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * 医生端:健康记录控制类
 *
 * @author George
 */
@RestController
@RequestMapping(value = "/doctor/health_record")
@Api(description = "健康记录")
public class DoctorHealthRecordController extends BaseController {
    @Autowired
    private PatientHealthRecordService patientHealthRecordService;
    @Autowired
    private JwArchivesService jwArchivesService;
    @Value("${demo.flag}")
    private Boolean demoFlag;
    @Autowired
    private PatientRecordService patientRecordService;
    /**
     * 患者最近填写的运动、用药、饮食内容
     *
     * @param patient 患者标识
     * @return
     */
    @RequestMapping(value = "recent", method = RequestMethod.GET)
    @ApiOperation("根据患者标志获取最近的保健记录")
    public String recent(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20160901001")
                         @RequestParam(value = "patient", required = true) String patient) {
        try {
            JSONObject json = patientHealthRecordService.findRecentByPatient(patient);
            if (json != null) {
                return write(200, "查询成功", "data", json);
            } else {
                return error(-1, "查询失败");
            }
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    /**
     * 运动记录查询接口
     *
     * @param patient  患者标识
     * @param pagesize 分页大小
     * @return
     */
    @RequestMapping(value = "list_sports", method = RequestMethod.POST)
    @ApiOperation("获取患者运动记录")
    public String sports(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20160901001")
                         @RequestParam(value = "patient", required = true) String patient,
                         @ApiParam(name = "start", value = "开始时间", defaultValue = "2017-05-15 00:00:00")
                         @RequestParam(value = "start", required = true) String start,
                         @ApiParam(name = "end", value = "结束时间", defaultValue = "2017-05-15 12:00:00")
                         @RequestParam(value = "end", required = true) String end,
                         @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                         @RequestParam(value = "page", required = true) int page,
                         @ApiParam(name = "pagesize", value = "每页记录数", defaultValue = "10")
                         @RequestParam(value = "pagesize", required = true) int pagesize) {
        try {
            Page<PatientHealthRecordSports> data = patientHealthRecordService.findSportsByPatientPage(patient, start, end, page, pagesize);
            if (data != null) {
                JSONArray array = new JSONArray();
                for (PatientHealthRecordSports record : data) {
                    if (record == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    json.put("id", record.getId());
                    // 设置记录标识
                    json.put("code", record.getCode());
                    // 设置记录日期
                    json.put("record_date", DateUtil.dateToStrShort(record.getRecordDate()));
                    json.put("sortDate", DateUtil.dateToStrLong(record.getSortDate()));
                    // 设置运动时长(分钟)
                    json.put("sports_time", record.getSportsTime());
                    // 设置运动强度
                    json.put("sports_type", record.getSportsTypeName());
                    // 设置运动类型
                    json.put("sports", record.getSportsName());
                    array.put(json);
                }
                return write(200, "查询成功", "list", array);
            } else {
                return error(-1, "查询失败");
            }
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    /**
     * 用药记录查询接口
     *
     * @param patient  患者标识
     * @param pagesize 分页大小
     * @return
     */
    @RequestMapping(value = "list_medication", method = {RequestMethod.GET})
    @ApiOperation("获取患者用药记录")
    public String medication(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20160901001")
                             @RequestParam(value = "patient", required = true) String patient,
                             @ApiParam(name = "start", value = "开始")
                             @RequestParam(required = false) String start,
                             @ApiParam(name = "end", value = "结束")
                             @RequestParam(required = false) String end,
                             @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                             @RequestParam(required = false) Integer page,
                             @ApiParam(name = "sortDate", value = "日期")
                             @RequestParam(required = false) String sortDate,
                             @ApiParam(name = "pagesize", value = "每页记录数", defaultValue = "10")
                             @RequestParam(required = true) int pagesize) {
        try {
            Page<PatientHealthRecordMedication> data = null;
            if (!StringUtils.isEmpty(sortDate)) {
                data = patientHealthRecordService.findMedicationByPatient(patient, DateUtil.strToDateLong(sortDate), page, pagesize);
            } else {
                data = patientHealthRecordService.findMedicalByPatientPage(patient, start, end, page, pagesize);
            }
            if (data != null) {
                JSONArray array = new JSONArray();
                for (PatientHealthRecordMedication record : data) {
                    if (record == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    json.put("id", record.getId());
                    // 设置记录标识
                    json.put("code", record.getCode());
                    // 设置记录日期
                    json.put("record_date", DateUtil.dateToStrShort(record.getRecordDate()));
                    json.put("sortDate", DateUtil.dateToStrLong(record.getSortDate()));
                    // 药品名称
                    json.put("medicines", record.getMedicinesName());
                    array.put(json);
                }
                return write(200, "查询成功", "list", array);
            } else {
                return error(-1, "查询失败");
            }
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    /**
     * 饮食记录查询接口
     *
     * @param patient  患者标识
     * @param page     页码
     * @param pagesize 分页大小
     * @return
     */
    @RequestMapping(value = "list_diet", method = RequestMethod.POST)
    @ApiOperation("饮食记录查询接口")
    public String diet(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20160901001")
                       @RequestParam(value = "patient", required = true) String patient,
                       @ApiParam(name = "start", value = "开始")
                       @RequestParam(required = true) String start,
                       @ApiParam(name = "end", value = "结束")
                       @RequestParam(required = false) String end,
                       @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                       @RequestParam(required = true) int page,
                       @ApiParam(name = "pagesize", value = "每页记录数", defaultValue = "10")
                       @RequestParam(required = true) int pagesize) {
        try {
            Page<PatientHealthRecordDiet> data = patientHealthRecordService.findDietByPatientPage(patient, start, end, page, pagesize);
            if (data != null) {
                JSONArray array = new JSONArray();
                for (PatientHealthRecordDiet record : data) {
                    if (record == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    json.put("id", record.getId());
                    // 设置记录标识
                    json.put("code", record.getCode());
                    // 设置记录日期
                    json.put("record_date", DateUtil.dateToStrShort(record.getRecordDate()));
                    json.put("sortDate", DateUtil.dateToStrLong(record.getSortDate()));
                    // 设置饮食内容
                    json.put("content", record.getContent());
                    // 设置图片URL,多图以逗号分隔
                    json.put("images", record.getImages());
                    array.put(json);
                }
                return write(200, "查询成功", "list", array);
            } else {
                return error(-1, "查询失败");
            }
        } catch (Exception e) {
            return errorResult(e);
        }
    }
//    @RequestMapping(value = "list_medical", method = RequestMethod.POST)
//    @ApiOperation("查询居民健康体检列表")
//    public String medical(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20160901001")
//                          @RequestParam(value = "patient", required = true) String patient,
//                          @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
//                          @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
//                          @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
//                          @RequestParam(value = "pageSize", required = false) Integer pageSize) {
//        try {
//
//            if (demoFlag) {
//                String res = patientRecordService.getJosnFileResullt("list_medical");
//                return res;
//            } else {
//                Patient p = patientService.findByCode(patient);
//                if (p != null) {
//                    JSONArray re = jwArchivesService.getEhrSickMedicalList(p.getIdcard(), pageIndex, pageSize);
//                    return write(200, "查询成功", "list", re);
//                } else {
//                    return error(-1, "患者不存在");
//                }
//            }
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return errorResult(e);
//        }
//    }
    @RequestMapping(value = "medical_detail", method = RequestMethod.POST)
    @ApiOperation("查询居民健康体检详情信息")
    public String medical_detail(@ApiParam(name = "medicalNo", value = "体检ID", defaultValue = "1249652")
                                 @RequestParam(value = "medicalNo", required = true) String medicalNo) {
        try {
            if (demoFlag) {
                String res = patientRecordService.getJosnFileResullt("medical_detail");
                return res;
            } else {
                JSONObject json = jwArchivesService.getEhrSickMedicalRecord(medicalNo);
                return write(200, "查询成功", "medical_detail", json);
            }
        } catch (ServiceException se) {
            return write(-1, se.getMessage());
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    /**
     * 根据区域查询体检详情信息
     */
//    @ApiOperation("根据区域查询体检详情信息")
//    @PostMapping(value = "areaMedicalDetail")
//    public String areaMedicalDetail(@ApiParam(name = "areaCode", value = "区域code", defaultValue = "350205")
//                                    @RequestParam(value = "areaCode", required = false) String areaCode,
//                                    @ApiParam(name = "patientId", value = "用户id", defaultValue = "")
//                                    @RequestParam(value = "patientId", required = false) String patientId) {
//        try {
//            //查询出区域的签约人
//            if (StringUtils.isBlank(areaCode) && StringUtils.isBlank(patientId)) {
//                return write(-1, "参数为空");
//            }
//            String result = patientRecordService.areaMedicalDetail(areaCode, patientId, demoFlag);
//            return result;
//        } catch (ServiceException se) {
//            System.out.println(se);
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            System.out.println(e);
//            return errorResult(e);
//        }
//    }
    /**
     * 保存体检详情信息
     */
//    @ApiOperation("保存体检详情信息")
//    @PostMapping(value = "saveMedicalDetail")
//    public String saveMedicalDetail(@ApiParam(name = "medicalNo", value = "体检号", defaultValue = "10891028")
//                                    @RequestParam(value = "medicalNo", required = false) String medicalNo,
//                                    @ApiParam(name = "findType", value = "查询类型 1查本地2查远程", defaultValue = "1")
//                                    @RequestParam(value = "findType", required = false) String findType,
//                                    @ApiParam(name = "findAll", value = "是否查全部,yes是 temp走补录", defaultValue = "yes")
//                                    @RequestParam(value = "findAll", required = false) String findAll) {
//        try {
//            //查询出区域的签约人
//            if (StringUtils.isBlank(medicalNo) && StringUtils.isBlank(findAll)) {
//                return write(-1, "参数为空");
//            }
//            String result = patientRecordService.saveMedicalDetailMethod(findType, findAll);
//            return result;
//
//        } catch (ServiceException se) {
//            System.out.println(se);
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            System.out.println(e);
//            return errorResult(e);
//        }
//    }
    /**
     * patient/archives/event
     * /smjk/GetResidentEventListJson
     * 接口地址 /base/CallEhrInterface
     */
//    @ApiOperation("保存健康档案信息")
//    @PostMapping(value = "saveHealthRecord")
//    public String saveHealthRecord(
//            @ApiParam(name = "idcard", value = "身份证号", defaultValue = "") @RequestParam(value = "idcard", required = false) String idcard) {
//        try {
//            String result = patientRecordService.saveHealthRecord(idcard);
//            return result;
//        } catch (ServiceException se) {
//            System.out.println(se);
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            System.out.println(e);
//            return errorResult(e);
//        }
//    }
    @RequestMapping(value = "dietDetail", method = RequestMethod.GET)
    @ApiOperation("饮食记录详情接口")
    public String dietDetail(@ApiParam(name = "id", value = "饮食记录ID")
                             @RequestParam(value = "id") Long dietId) {
        try {
            JSONObject json = patientHealthRecordService.findById(dietId);
            if (json.getInt("status") == 200) {
                return write(200, "查询成功!", "data", json.getJSONObject("data"));
            } else {
                return error(-1, json.getString("msg"));
            }
        } catch (Exception e) {
            return errorResult(e);
        }
    }
}

+ 441 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/controller/PatientHealthRecordController.java

@ -0,0 +1,441 @@
package com.yihu.jw.hospital.module.health.controller;
import com.yihu.jw.entity.base.health.*;
import com.yihu.jw.hospital.module.common.BaseController;
import com.yihu.jw.hospital.module.health.service.MedicinesService;
import com.yihu.jw.hospital.module.health.service.PatientHealthRecordService;
import com.yihu.jw.hospital.module.health.service.SportsService;
import com.yihu.jw.im.service.ImService;
import com.yihu.jw.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
/**
 * 健康记录控制类
 * @author George
 *
 */
@RestController
@RequestMapping(value = "/patient/health_record")
@Api(description = "患者端-健康记录")
public class PatientHealthRecordController extends BaseController {
	@Autowired
	private SportsService sportsService;
	@Autowired
	private MedicinesService medicinesService;
	@Autowired
	private PatientHealthRecordService patientHealthRecordService;
	@Autowired
	private com.yihu.jw.util.common.CommonUtil CommonUtil;
	@Autowired
	private ImService imService;
	@Value("$wechat.id")
	private String wechatId;
	/**
	 * 保健记录更改接口(包括手动记录的修改和所有的删除)
	 *
	 * @param id
	 * @param type   饮食1,运动2,用药3
	 * @param value1 记录时间
	 * @param value2 饮食内容CONTETN  时长 用药
	 * @param value3 上传图片 强度
	 * @param value4 运动项目
	 * @return
	 */
	@ApiOperation("保健记录更改接口(包括手动记录的修改和所有的删除)")
	@RequestMapping(value = "/modifyHealthCare", method = RequestMethod.POST)
	public String modifyHealthCare(@RequestParam long id,
								   @RequestParam int type,
								   @RequestParam(required = false) String value1,
								   @RequestParam(required = false) String value2,
								   @RequestParam(required = false) String value3,
								   @RequestParam(required = false) String value4) {
		try {
			if(type==1&&StringUtils.isNotBlank(value3)){
			    String images = "";
                String[] imgs = value3.split(",");
                for (String img:imgs){
                    if(img.contains("group1/")){
                        images+=img+",";
                    }
                }
                if(StringUtils.isNotEmpty(images)&&images.lastIndexOf(",")==images.length()-1){
                    images = images.substring(0,images.length()-1);
                }
				// 从微信服务器获取图片
                value3 = imService.fetchWxImages(wechatId);
				if(StringUtils.isNotEmpty(value3)){
					value3 = CommonUtil.copyTempImage(value3);
				}
				if(StringUtils.isNotEmpty(value3)){
                    value3=value3+","+images.trim();
                }else {
                    value3=images;
                }
			}
			patientHealthRecordService.modifyHealthCare(id, type, value1, value2, value3, value4);
			return write(200, "更改成功!");
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "更改失败!");
		}
	}
	/**
	 * 运动强度查询接口
	 * @return
	 */
	@ApiOperation("运动强度查询接口")
	@RequestMapping(value = "sports_type", method ={RequestMethod.GET})
	public String sportsType() {
		try {
			JSONArray array = new JSONArray();
			List<SportsType> list = sportsService.finsAllSportsType();
			if (list != null) {
				for (SportsType temp : list) {
					if (temp == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("code", temp.getCode());
					json.put("name", temp.getName());
					array.put(json);
				}
			}
			return write(200, "查询成功", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 运动类型查询接口
	 * @return
	 */
	@ApiOperation("运动类型查询接口")
	@RequestMapping(value = "sports", method ={ RequestMethod.GET})
	public String sports() {
		try {
			JSONArray array = new JSONArray();
			List<Sports> list = sportsService.finsAllSports();
			if (list != null) {
				for (Sports temp : list) {
					if (temp == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("code", temp.getCode());
					json.put("name", temp.getName());
					array.put(json);
				}
			}
			return write(200, "查询成功", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 查询药品列表
	 * @return
	 */
	@RequestMapping(value = "medicines", method ={RequestMethod.GET})
	@ApiOperation("查询药品列表")
	public String medicines() {
		try {
			JSONArray array = new JSONArray();
			List<Medicines> list = medicinesService.findAllMedicines(1);
			if (list != null) {
				for (Medicines temp : list) {
					if (temp == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("code", temp.getCode());
					json.put("name", temp.getName());
					array.put(json);
				}
			}
			return write(200, "查询成功", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 添加运动记录
	 * @param record_date 记录时间
	 * @param sportsTime 运动时长(分)
	 * @param sportsType 运动强度标识
	 * @param sports 运动类型标识
	 * @return
	 */
	@RequestMapping(value = "add_sports", method ={ RequestMethod.POST})
	@ApiOperation("添加运动记录")
	public String addSports(String record_date, double sportsTime, String sportsType, String sports) {
		try {
			PatientHealthRecordSports record = new PatientHealthRecordSports();
			record.setDel("1");
			record.setCzrq(new Date());
			record.setPatient(getRepUID());
//			record.setPatient(getUID());
			record.setRecordDate(DateUtil.strToDateShort(record_date));
			record.setSortDate(DateUtil.strToDateAppendNowTime(record_date, DateUtil.YYYY_MM_DD_HH_MM_SS));
			record.setSportsTime(sportsTime);
			if (patientHealthRecordService.addSports(record, sportsType, sports) != null) {
				return success("保存成功");
			} else {
				return error(-1, "保存失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "保存失败");
		}
	}
	/**
	 * 添加用药记录
	 * @param record_date 记录时间
	 * @param medicines 药品标识
	 * @param medicines_name 药品名称
	 * @return
	 */
	@RequestMapping(value = "add_medication", method ={ RequestMethod.POST})
	@ApiOperation("添加用药记录")
	public String addMedication(String record_date, String medicines, String medicines_name) {
		try {
			PatientHealthRecordMedication record = new PatientHealthRecordMedication();
			record.setDel("1");
			record.setCzrq(new Date());
			record.setPatient(getRepUID());
//			record.setPatient(getUID());
			record.setRecordDate(DateUtil.strToDateShort(record_date));
			record.setSortDate(DateUtil.strToDateAppendNowTime(record_date, DateUtil.YYYY_MM_DD_HH_MM_SS));
			record.setMedicines(medicines);
			record.setMedicinesName(medicines_name);
			if (patientHealthRecordService.addMedication(record) != null) {
				return success("保存成功");
			} else {
				return error(-1, "保存失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "保存失败");
		}
	}
	/**
	 * 添加饮食记录接口
	 * @param record_date 记录时间
	 * @param content 饮食内容
	 * @param images 图片HTTP地址,多图以逗号分隔
	 * @return
	 */
	@RequestMapping(value = "add_diet", method ={ RequestMethod.POST})
	@ApiOperation("添加饮食记录接口")
	public String add(String record_date, String content, @RequestParam(required = false) String images) {
		try {
			PatientHealthRecordDiet record = new PatientHealthRecordDiet();
			record.setDel("1");
			record.setCzrq(new Date());
			record.setPatient(getRepUID());
			record.setRecordDate(DateUtil.strToDateShort(record_date));
			record.setSortDate(DateUtil.strToDateAppendNowTime(record_date, DateUtil.YYYY_MM_DD_HH_MM_SS));
			record.setContent(content);
			// 从微信服务器获取图片
			if (StringUtils.isEmpty(images)) {
				images = imService.fetchWxImages(wechatId);
			}
			if (StringUtils.isNotEmpty(images)) {
				images = CommonUtil.copyTempImage(images);
			}
			record.setImages(images);
			if (patientHealthRecordService.addDiet(record) != null) {
				return success("保存成功");
			} else {
				return error(-1, "保存失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "保存失败");
		}
	}
	/**
	 * 最近填写的运动、用药、饮食内容
	 * @return
	 */
	@RequestMapping(value = "recent", method ={ RequestMethod.GET})
	@ApiOperation("最近填写的运动、用药、饮食内容")
	public String recent() {
		try {
			JSONObject json = patientHealthRecordService.findRecentByPatient(getRepUID());
			if (json != null) {
				return write(200, "查询成功", "data", json);
			} else {
				return error(-1, "查询失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 运动记录查询接口
	 * @param pagesize 分页大小
	 * @return
	 */
	@RequestMapping(value = "list_sports", method ={RequestMethod.GET})
	@ApiOperation("运动记录查询接口")
	public String sports(String start,String end,int page, int pagesize) {
		try {
			Page<PatientHealthRecordSports> data = patientHealthRecordService.findSportsByPatientPage(getRepUID(), start,end,page, pagesize);
			if (data != null) {
				JSONArray array = new JSONArray();
				for (PatientHealthRecordSports record : data) {
					if (record == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", record.getId());
					// 设置记录标识
					json.put("code", record.getCode());
					// 设置记录日期
					json.put("record_date", DateUtil.dateToStrShort(record.getRecordDate()));
					json.put("sortDate", DateUtil.dateToStrLong(record.getSortDate()));
					// 设置运动时长(分钟)
					json.put("sports_time", record.getSportsTime());
					// 设置运动强度
					json.put("sports_type", record.getSportsTypeName());
					// 设置运动类型
					json.put("sports", record.getSportsName());
					array.put(json);
				}
				return write(200, "查询成功", "list", array);
			} else {
				return error(-1, "查询失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 用药记录查询接口
	 * @param pagesize 分页大小
	 * @return
	 */
	@RequestMapping(value = "list_medication", method ={RequestMethod.GET})
	@ApiOperation("用药记录查询接口")
	public String medication(String start,String end,int page, int pagesize) {
		try {
			Page<PatientHealthRecordMedication> data = patientHealthRecordService.findMedicalByPatientPage(getRepUID(), start, end, page, pagesize);
			if (data != null) {
				JSONArray array = new JSONArray();
				for (PatientHealthRecordMedication record : data) {
					if (record == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", record.getId());
					// 设置记录标识
					json.put("code", record.getCode());
					// 设置记录日期
					json.put("record_date", DateUtil.dateToStrShort(record.getRecordDate()));
					json.put("sortDate", DateUtil.dateToStrLong(record.getSortDate()));
					// 药品名称
					json.put("medicines", record.getMedicinesName());
					array.put(json);
				}
				return write(200, "查询成功", "list", array);
			} else {
				return error(-1, "查询失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 饮食记录查询接口
	 * @param pagesize 分页大小
	 * @return
	 */
	@RequestMapping(value = "list_diet", method ={ RequestMethod.GET})
	@ApiOperation("饮食记录查询接口")
	public String diet(String start,String end,int page,int pagesize) {
		try {
			Page<PatientHealthRecordDiet> data = patientHealthRecordService.findDietByPatientPage(getRepUID(),start,end,page, pagesize);
			if (data != null) {
				JSONArray array = new JSONArray();
				for (PatientHealthRecordDiet record : data) {
					if (record == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", record.getId());
					// 设置记录标识
					json.put("code", record.getCode());
					// 设置记录日期
					json.put("record_date", DateUtil.dateToStrShort(record.getRecordDate()));
					json.put("sortDate", DateUtil.dateToStrLong(record.getSortDate()));
					// 设置饮食内容
					json.put("content", record.getContent());
					// 设置图片URL,多图以逗号分隔
					json.put("images", record.getImages());
					array.put(json);
				}
				return write(200, "查询成功", "list", array);
			} else {
				return error(-1, "查询失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	@RequestMapping(value = "dietDetail", method =RequestMethod.GET)
	@ApiOperation("饮食记录详情接口")
	public String dietDetail(@ApiParam(name = "id", value = "饮食记录ID")
								 @RequestParam(value = "id") Long dietId) {
		try {
			JSONObject json = patientHealthRecordService.findById(dietId);
			if(json.getInt("status") == 200) {
				return write(200, "查询成功!", "data", json.getJSONObject("data"));
			}else {
				return error(-1, json.getString("msg"));
			}
		} catch (Exception e) {
			return error(-1, "查询失败!");
		}
	}
}

+ 28 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/service/MedicinesService.java

@ -0,0 +1,28 @@
package com.yihu.jw.hospital.module.health.service;
import com.yihu.jw.entity.base.health.Medicines;
import com.yihu.jw.health.MedicinesDao;
import com.yihu.jw.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Component
@Transactional(rollbackFor = Exception.class)
public class MedicinesService extends BaseJpaService {
	@Autowired
	private MedicinesDao medicinesDao;
	/**
	 * 查询所有的药品信息
	 * @param type 药品类型:1健康记录
	 * @return	 */
	public List<Medicines> findAllMedicines(int type) {
		return medicinesDao.findAll(type);
	}
}

+ 383 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/service/PatientHealthRecordService.java

@ -0,0 +1,383 @@
package com.yihu.jw.hospital.module.health.service;
import com.yihu.jw.entity.base.health.*;
import com.yihu.jw.health.*;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import java.text.SimpleDateFormat;
import java.util.*;
@Component
@Transactional(rollbackFor = Exception.class)
public class PatientHealthRecordService extends BaseJpaService {
	@Autowired
	private SportsTypeDao sportsTypeDao;
	@Autowired
	private SportsDao sportsDao;
	@Autowired
	private MedicinesDao medicinesDao;
	@Autowired
	private PatientHealthRecordMedicationDao patientHealthRecordMedicationDao;
	@Autowired
	private PatientHealthRecordDietDao patientHealthRecordDietDao;
	@Autowired
	private PatientHealthRecordSportsDao patientHealthRecordSportsDao;
	@Autowired
	private FoodCompDao foodCompDao;
	/**
	 * 更改保健记录(包括手动记录的修改和所有的删除)
	 *
	 * @param id
	 * @param type   饮食1,运动2,用药3
	 * @param value1 记录时间
	 * @param value2 饮食内容CONTETN  时长 用药
	 * @param value3 上传图片 强度
	 * @param value4 运动项目
	 */
	public void modifyHealthCare(long id, int type, String value1, String value2, String value3, String value4) throws Exception {
		//value类字段值均为空为删除
		if (StringUtils.isEmpty(value1) && StringUtils.isEmpty(value2) && StringUtils.isEmpty(value3) && StringUtils.isEmpty(value4)) {
			switch (type) {
				case 1:
					patientHealthRecordDietDao.deleteDiet(id);
					break;
				case 2:
					patientHealthRecordSportsDao.deleteSports(id);
					break;
				case 3:
					patientHealthRecordMedicationDao.deleteMedication(id);
					break;
			}
		} else {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date recordDate = sdf.parse(value1);
			switch (type) {
				case 1:
					patientHealthRecordDietDao.modifyDiet(id, recordDate, value2, value3);
					break;
				case 2:
					SportsType sportsType = sportsTypeDao.findByCode(value3);
					String typeName = sportsType.getName();
					Sports sport = sportsDao.findByCode(value4);
					String sportName = sport.getName();
					Double sportsTime = Double.parseDouble(value2);
					patientHealthRecordSportsDao.modifySports(id, recordDate, sportsTime, value3, typeName, value4, sportName);
					break;
				case 3:
					Medicines medicines = medicinesDao.findByCode(value2);
					String medicinesName = medicines.getName();
					patientHealthRecordMedicationDao.modifyMedication(id, recordDate, value2, medicinesName);
					break;
			}
		}
	}
	/**
	 * 添加运动记录
	 * @param record 运动记录对象
	 * @return
	 */
	public PatientHealthRecordSports addSports(PatientHealthRecordSports record, String sportsType, String sports) {
		record.setCode(getCode());
		record.setSportsType(sportsType);
		record.setSportsTypeName(sportsTypeDao.findByCode(sportsType).getName());
		record.setSports(sports);
		record.setSportsName(sportsDao.findByCode(sports).getName());
		return patientHealthRecordSportsDao.save(record);
	}
	/**
	 * 添加用药记录
	 * @param record 用药记录对象
	 * @return
	 */
	public PatientHealthRecordMedication addMedication(PatientHealthRecordMedication record) {
		record.setCode(getCode());
		return patientHealthRecordMedicationDao.save(record);
	}
	/**
	 * 添加饮食记录
	 * @param record 饮食记录对象
	 * @return
	 */
	public PatientHealthRecordDiet addDiet(PatientHealthRecordDiet record) {
		record.setCode(getCode());
		return	 patientHealthRecordDietDao.save(record);
	}
	/**
	 * 按分类查询患者运动记录
	 * @param patient 患者标识
	 * @param
	 * @param pageSize 分页大小
	 * @return
	 */
	public Page<PatientHealthRecordSports> findSportsByPatient(String patient, Date sortDate, int pageSize) {
		if (pageSize <= 0) {
			pageSize = 10;
		}
		// 排序
		Sort sort = Sort.by(Direction.DESC, "sortDate");
		// 分页信息
		PageRequest pageRequest = PageRequest.of(0, pageSize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		// 患者标志
		filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
		if(sortDate != null){
			filters.put("sortDate", new SearchFilter("sortDate", Operator.LT, sortDate));
		}
		// 未作废
		filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
		Specification<PatientHealthRecordSports> spec = DynamicSpecifications.bySearchFilter(filters.values(), PatientHealthRecordSports.class);
		return patientHealthRecordSportsDao.findAll(spec, pageRequest);
	}
	/**
	 * 查询运动记录
	 *
	 * @param patient
	 * @param start
	 * @param end
	 * @param page
	 * @param pagesize
	 * @return
	 */
	public Page<PatientHealthRecordSports> findSportsByPatientPage(String patient,String start,String end,int page,int pagesize){
		if(page > 0) {
			page = page -1;
		}
		PageRequest pageRequest = PageRequest.of(page,pagesize);
		return patientHealthRecordSportsDao.findSportsByPatient(patient, DateUtil.strToDate(start, DateUtil.YYYY_MM_DD_HH_MM_SS)
				,DateUtil.strToDate(end,DateUtil.YYYY_MM_DD_HH_MM_SS),pageRequest);
	}
	/**
	 * 查询用药记录
	 *
	 * @param patient
	 * @param start
	 * @param end
	 * @param page
	 * @param pagesize
	 * @return
	 */
	public Page<PatientHealthRecordMedication> findMedicalByPatientPage(String patient,String start,String end,int page,int pagesize){
		if(page > 0)
		{
			page = page -1;
		}
		PageRequest pageRequest = PageRequest.of(page,pagesize);
		return patientHealthRecordMedicationDao.findMedicalByPatient(patient, DateUtil.strToDate(start,DateUtil.YYYY_MM_DD_HH_MM_SS)
				,DateUtil.strToDate(end,DateUtil.YYYY_MM_DD_HH_MM_SS),pageRequest);
	}
	/**
	 * 查询饮食记录
	 *
	 * @param patient
	 * @param start
	 * @param end
	 * @param page
	 * @param pagesize
	 * @return
	 */
	public Page<PatientHealthRecordDiet> findDietByPatientPage(String patient,String start,String end,int page,int pagesize){
		if(page > 0) {
			page = page -1;
		}
		PageRequest pageRequest = PageRequest.of(page,pagesize);
		return patientHealthRecordDietDao.findDietByPatient(patient, DateUtil.strToDate(start,DateUtil.YYYY_MM_DD_HH_MM_SS)
				,DateUtil.strToDate(end,DateUtil.YYYY_MM_DD_HH_MM_SS),pageRequest);
	}
	/**
	 * 按分类查询患者用药记录
	 * @param patient 患者标识
	 * @param pageSize 分页大小
	 * @return
	 */
	public Page<PatientHealthRecordMedication> findMedicationByPatient(String patient, Date sortDate,Integer page, int pageSize) {
		if(page==null){
			page = 0;
		}else if(page > 0)
		{
			page = page -1;
		}
		if (pageSize <= 0) {
			pageSize = 10;
		}
		// 排序
		Sort sort = Sort.by(Direction.DESC, "sortDate");
		// 分页信息
		PageRequest pageRequest = PageRequest.of(page, pageSize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		// 患者标志
		filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
		if(sortDate != null){
			filters.put("sortDate", new SearchFilter("sortDate", Operator.LT, sortDate));
		}
		// 未作废
		filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
		Specification<PatientHealthRecordMedication> spec = DynamicSpecifications.bySearchFilter(filters.values(), PatientHealthRecordMedication.class);
		return patientHealthRecordMedicationDao.findAll(spec, pageRequest);
	}
	/**
	 * 按分类查询患者饮食记录
	 * @param patient 患者标识
	 * @param
	 * @param pageSize 分页大小
	 * @return
	 */
	public Page<PatientHealthRecordDiet> findDietByPatient(String patient, Date sortDate, int pageSize) {
		if (pageSize <= 0) {
			pageSize = 10;
		}
		// 排序
		Sort sort = Sort.by(Direction.DESC, "sortDate");
		// 分页信息
		PageRequest pageRequest = PageRequest.of(0, pageSize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		// 患者标志
		filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
		if(sortDate != null){
			filters.put("sortDate", new SearchFilter("sortDate", Operator.LT, sortDate));
		}
		// 未作废
		filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
		Specification<PatientHealthRecordDiet> spec = DynamicSpecifications.bySearchFilter(filters.values(), PatientHealthRecordDiet.class);
		return patientHealthRecordDietDao.findAll(spec, pageRequest);
	}
	/**
	 * 查询患者最近填写的运动、用药、饮食内容
	 * @param patient
	 * @return
	 */
	public JSONObject findRecentByPatient(String patient) {
		JSONObject jsonObject = new JSONObject();
		// 查询最近的运动
		Page<PatientHealthRecordSports> sports = patientHealthRecordSportsDao.findRecentByPatient(patient, PageRequest.of(0, 1));
		// 查询最近的用药
		Page<PatientHealthRecordMedication> medication = patientHealthRecordMedicationDao.findRecentByPatient(patient, PageRequest.of(0, 1));
		// 查询最近的饮食
		Page<PatientHealthRecordDiet> diet = patientHealthRecordDietDao.findRecentByPatient(patient, PageRequest.of(0, 1));
		// 查询最近的药盒使用记录
//		Page<KitDrugUseRecord> kitDrugUseRecords = kitDrugUseRecordDao.findRecentByPatient(patient, PageRequest.of(0, 1));
		if (sports != null && sports.getSize() > 0) {
			JSONObject sportObject = new JSONObject();
			for (PatientHealthRecordSports temp : sports) {
				sportObject.put("sports", temp.getSportsName());
				sportObject.put("sports_time", temp.getSportsTime());
				sportObject.put("sports_type", temp.getSportsType());
				sportObject.put("sports_typeName", temp.getSportsTypeName());
				sportObject.put("czrq", DateUtil.dateToStr(temp.getCzrq(), DateUtil.YYYY_MM_DD));
				sportObject.put("recordDate", DateUtil.dateToStr(temp.getRecordDate(), DateUtil.YYYY_MM_DD));
				sportObject.put("source","1".equals(temp.getSource())?1:0);
			}
			jsonObject.put("sprot",sportObject);
		}
		if (medication != null) {
			JSONObject medicationObject = new JSONObject();
			for (PatientHealthRecordMedication temp : medication) {
				medicationObject.put("medication", temp.getMedicinesName());
				medicationObject.put("recordDate",DateUtil.dateToStr(temp.getRecordDate(), DateUtil.YYYY_MM_DD));
				medicationObject.put("source","1".equals(temp.getSource())?1:0);
			}
			jsonObject.put("medication",medicationObject);
		}
		if (diet != null) {
			JSONObject dietObject = new JSONObject();
			for (PatientHealthRecordDiet temp : diet) {
				dietObject.put("diet", temp.getContent());
				dietObject.put("recordDate",DateUtil.dateToStr(temp.getRecordDate(), DateUtil.YYYY_MM_DD));
				dietObject.put("images",temp.getImages());
				dietObject.put("source","1".equals(temp.getSource())?1:0);
			}
			jsonObject.put("diet",dietObject);
		}
//		if(kitDrugUseRecords!=null){
//			JSONObject dietObject = new JSONObject();
//			for (KitDrugUseRecord temp : kitDrugUseRecords) {
//				dietObject.put("recordDate",DateUtil.dateToStr(temp.getUseTime(), DateUtil.YYYY_MM_DD));
//				dietObject.put("deviceSn",temp.getDeviceSn());
//				List<KitDrugDetail> kitDrugDetailList = kitDrugDetailDao.findByRelationCodeAndType(temp.getCode(),1);
//				if(kitDrugDetailList.size()>0){
//					dietObject.put("drugDetail",kitDrugDetailList.get(0).getDrugName());
//				}else{
//					dietObject.put("drugDetail","");
//				}
//			}
//			jsonObject.put("kitDrugUseRecords",dietObject);
//		}
		return jsonObject;
	}
	//根据居民饮食记录ID查看详情
    public JSONObject findById(Long id) {
		JSONObject res = new JSONObject();
		List<FoodComp> patientFoodCompList = new ArrayList<>();
		//居民记录详情
		PatientHealthRecordDiet patientHealthRecordDiet = patientHealthRecordDietDao.findById(id).orElse(null);
		if(patientHealthRecordDiet != null){
			com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
			json.put("dietDetail", patientHealthRecordDiet);
			//查看居民吃的相关食物热量
			List<FoodComp> foodCompList = foodCompDao.findAllFoodByPidNot(0L);
			String content = patientHealthRecordDiet.getContent();
			for(FoodComp foodComp : foodCompList){
				//判断居民所吃的食物是否在热量字典表
				if(content.contains(foodComp.getName())){
					patientFoodCompList.add(foodComp);
				}
			}
			if(patientFoodCompList.size() > 0){
				json.put("foodCompList", patientFoodCompList);
			}
			res.put("status", 200);
			res.put("data", json);
		}else {
			res.put("status", -1);
			res.put("msg", "居民饮食记录详情不存在");
		}
		return res;
    }
}

+ 41 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/service/SportsService.java

@ -0,0 +1,41 @@
package com.yihu.jw.hospital.module.health.service;
import com.yihu.jw.entity.base.health.Sports;
import com.yihu.jw.entity.base.health.SportsType;
import com.yihu.jw.health.SportsDao;
import com.yihu.jw.health.SportsTypeDao;
import com.yihu.jw.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Component
@Transactional(rollbackFor = Exception.class)
public class SportsService extends BaseJpaService {
	@Autowired
	private SportsTypeDao sportsTypeDao;
	@Autowired
	private SportsDao sportsDao;
	/**
	 * 查询所有的运动强度
	 * @return
	 */
	public List<SportsType> finsAllSportsType() {
		return sportsTypeDao.findAll();
	}
	
	/**
	 * 查询所有的运动类型
	 * @return
	 */
	public List<Sports> finsAllSports() {
		return sportsDao.findAll();
	}
}