|
@ -0,0 +1,285 @@
|
|
|
package com.yihu.jw.care.service.course;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.care.dao.course.NurseryLogDao;
|
|
|
import com.yihu.jw.care.dao.course.PatientCourseRecordDao;
|
|
|
import com.yihu.jw.care.dao.course.PatientDietRecordDao;
|
|
|
import com.yihu.jw.entity.care.course.NurseryLogDO;
|
|
|
import com.yihu.jw.entity.care.course.PatientCourseRecordDO;
|
|
|
import com.yihu.jw.entity.care.course.PatientDietRecordDO;
|
|
|
import com.yihu.jw.entity.care.course.RecruitStudentsRecordDO;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created with IntelliJ IDEA.
|
|
|
*
|
|
|
* @Author: yeshijie
|
|
|
* @Date: 2021/5/20
|
|
|
* @Description:
|
|
|
*/
|
|
|
@Service
|
|
|
public class NurseryLogService {
|
|
|
|
|
|
@Autowired
|
|
|
private NurseryLogDao nurseryLogDao;
|
|
|
@Autowired
|
|
|
private PatientDietRecordDao patientDietRecordDao;
|
|
|
@Autowired
|
|
|
private PatientCourseRecordDao patientCourseRecordDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
/**
|
|
|
* 根据托育日志id查找
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
public ObjEnvelop findRecordByNurseryLogId(String id,String type){
|
|
|
if("diet".equals(type)){
|
|
|
List<PatientDietRecordDO> dietRecordDOs = patientDietRecordDao.findByNurseryLogId(id);
|
|
|
if(dietRecordDOs.size()>0){
|
|
|
return ObjEnvelop.getSuccess("",dietRecordDOs.get(0));
|
|
|
}
|
|
|
}else if("course".equals(type)){
|
|
|
List<PatientCourseRecordDO> courseRecordDOs = patientCourseRecordDao.findByNurseryLogId(id);
|
|
|
if(courseRecordDOs.size()>0){
|
|
|
return ObjEnvelop.getSuccess("",courseRecordDOs.get(0));
|
|
|
}
|
|
|
}
|
|
|
return ObjEnvelop.getError("未找到记录");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取课程记录详情
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject nurseryDetail(String id){
|
|
|
JSONObject json = new JSONObject();
|
|
|
NurseryLogDO nurseryLogDO = nurseryLogDao.findOne(id);
|
|
|
json.put("nurseryLog",nurseryLogDO);
|
|
|
List<PatientDietRecordDO> dietRecordDOs = patientDietRecordDao.findByNurseryLogId(id);
|
|
|
List<PatientCourseRecordDO> courseRecordDOs = patientCourseRecordDao.findByNurseryLogId(id);
|
|
|
json.put("diet",dietRecordDOs.size());
|
|
|
json.put("course",courseRecordDOs.size());
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增托育日志
|
|
|
* @param patient
|
|
|
* @param patientName
|
|
|
* @param doctor
|
|
|
* @param doctorName
|
|
|
* @param orgCode
|
|
|
* @param orgName
|
|
|
* @param recordDate
|
|
|
* @return
|
|
|
*/
|
|
|
public NurseryLogDO addNurseryLog(String patient,String patientName, String doctor,String doctorName,String orgCode,String orgName,String recordDate) {
|
|
|
NurseryLogDO nurseryLogDO = new NurseryLogDO();
|
|
|
nurseryLogDO.setPatient(patient);
|
|
|
nurseryLogDO.setPatientName(patientName);
|
|
|
nurseryLogDO.setDoctorName(doctorName);
|
|
|
nurseryLogDO.setDoctor(doctor);
|
|
|
nurseryLogDO.setOrgName(orgName);
|
|
|
nurseryLogDO.setOrgCode(orgCode);
|
|
|
nurseryLogDO.setRecordDate(recordDate);
|
|
|
nurseryLogDO.setStatus("0");
|
|
|
nurseryLogDO.setCreateTime(new Date());
|
|
|
nurseryLogDao.save(nurseryLogDO);
|
|
|
return nurseryLogDO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增课程记录
|
|
|
* @return
|
|
|
*/
|
|
|
public PatientCourseRecordDO addCourseRecord(String id,String content, String enclosure) {
|
|
|
PatientCourseRecordDO recordDO = new PatientCourseRecordDO();
|
|
|
recordDO.setCreateTime(new Date());
|
|
|
recordDO.setContent(content);
|
|
|
recordDO.setEnclosure(enclosure);
|
|
|
recordDO.setNurseryLogId(id);
|
|
|
patientCourseRecordDao.save(recordDO);
|
|
|
return recordDO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增饮食记录
|
|
|
* @return
|
|
|
*/
|
|
|
public PatientDietRecordDO addDietRecord(String id,String eatFood,String eatType, String enclosure,String intake,String additionalNotes) {
|
|
|
PatientDietRecordDO recordDO = new PatientDietRecordDO();
|
|
|
recordDO.setCreateTime(new Date());
|
|
|
recordDO.setEnclosure(enclosure);
|
|
|
recordDO.setNurseryLogId(id);
|
|
|
recordDO.setEatFood(eatFood);
|
|
|
recordDO.setEatType(eatType);
|
|
|
recordDO.setIntake(intake);
|
|
|
recordDO.setAdditionalNotes(additionalNotes);
|
|
|
patientDietRecordDao.save(recordDO);
|
|
|
return recordDO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*获取托育日志列表
|
|
|
* @param orgCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public List<NurseryLogDO> findNurseryLogList(String orgCode, String recordDate){
|
|
|
String sql = "select * from base_nursery_log wf ";
|
|
|
sql+= " where wf.org_code = '"+orgCode+"'";
|
|
|
if(!StringUtil.isEmpty(recordDate)){
|
|
|
sql+=" and wf.record_date ='"+recordDate+"'";
|
|
|
}
|
|
|
sql+=" order by wf.create_time desc";
|
|
|
List<NurseryLogDO> nurseryLogDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(NurseryLogDO.class));
|
|
|
return nurseryLogDOs;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取未填写日志列表
|
|
|
* @param orgCode
|
|
|
*/
|
|
|
public JSONArray nuseryLogUnFilledIn(String orgCode,String recordDate){
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
String sql ="SELECT * from base_recruit_students_record " +
|
|
|
"where org_code = '"+orgCode+"' and `status` in ('3','6') and del =1";
|
|
|
List<RecruitStudentsRecordDO> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(RecruitStudentsRecordDO.class));
|
|
|
|
|
|
List<NurseryLogDO> nurseryLogDOs = findNurseryLogList(orgCode, recordDate);
|
|
|
List<String> nurseryList = nurseryLogDOs.stream().map(NurseryLogDO::getPatient).collect(Collectors.toList());
|
|
|
for(RecruitStudentsRecordDO recordDO:list){
|
|
|
if(nurseryList.contains(recordDO.getPatient())){
|
|
|
continue;
|
|
|
}
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("patient",recordDO.getPatient());
|
|
|
json.put("patientName",recordDO.getPatientName());
|
|
|
jsonArray.add(json);
|
|
|
}
|
|
|
return jsonArray;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*获取托育日志按月日历形式
|
|
|
* @param orgCode
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Map<String,Object> findNurseryLogByMonth(String orgCode, String patient, String patientName, String startTime, String endTime)throws Exception{
|
|
|
String sql = "select * from base_nursery_log wf ";
|
|
|
sql+= " where wf.org_code = '"+orgCode+"'";
|
|
|
if(!StringUtil.isEmpty(patient)){
|
|
|
sql+=" and wf.patient_code = '"+patient+"'";
|
|
|
}
|
|
|
if(!StringUtil.isEmpty(patientName)){
|
|
|
sql+=" and wf.patient_name like '%"+patientName+"%'";
|
|
|
}
|
|
|
if(!StringUtil.isEmpty(startTime)){
|
|
|
sql+=" and wf.record_date >='"+startTime+"'";
|
|
|
}
|
|
|
if(!org.apache.commons.lang.StringUtils.isEmpty(endTime)){
|
|
|
Date currentTime = DateUtil.strToDate(endTime + " 23:59:59");
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String dateString = formatter.format(currentTime);
|
|
|
sql+=" and wf.record_date <='"+dateString+"'";
|
|
|
}
|
|
|
|
|
|
sql+=" order by wf.create_time desc";
|
|
|
List<NurseryLogDO> nurseryLogDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(NurseryLogDO.class));
|
|
|
//按时间分组
|
|
|
Map<String,Object> date = sortNurseryLogByDate(nurseryLogDOs);
|
|
|
|
|
|
//统计每一天完成数与计划数目
|
|
|
if(date!=null&&date.size()>0){
|
|
|
for(String key : date.keySet()){
|
|
|
//获取一天的数据
|
|
|
Map<String,Object> d = (Map<String,Object>)date.get(key);
|
|
|
// 获取一天随访数据
|
|
|
List<NurseryLogDO> dateFollowups = (List<NurseryLogDO>)d.get("nurserys");
|
|
|
//统计一天各项纬度指标
|
|
|
List<Map<String,Object>> statistics = new ArrayList<>();
|
|
|
//统计单条
|
|
|
Map<String,Object> fs = sortNurseryLogList(dateFollowups);
|
|
|
Integer count = (Integer)fs.get("count");
|
|
|
if(count!=0){
|
|
|
statistics.add(fs);
|
|
|
}
|
|
|
d.put("statistics",statistics);
|
|
|
}
|
|
|
}
|
|
|
return date;
|
|
|
}
|
|
|
|
|
|
public Map<String,Object> sortNurseryLogByDate(List<NurseryLogDO> nurseryLogDOs){
|
|
|
//按时间分组
|
|
|
Map<String,Object> date = new HashedMap();
|
|
|
if(nurseryLogDOs!=null&&nurseryLogDOs.size()>0){
|
|
|
Iterator it = nurseryLogDOs.iterator();
|
|
|
while (it.hasNext()){
|
|
|
NurseryLogDO nurseryLogDO = (NurseryLogDO)it.next();
|
|
|
//1.获取日期分组
|
|
|
Map<String,Object> dateNurserys = (Map<String,Object>)date.get(nurseryLogDO.getRecordDate());
|
|
|
//判断随访时间是否已经创建分组
|
|
|
if(dateNurserys!=null&&dateNurserys.size()>0){
|
|
|
//同一天时间已经有分组则加入list
|
|
|
List<NurseryLogDO> list = (List<NurseryLogDO>)dateNurserys.get("nurserys");
|
|
|
list.add(nurseryLogDO);
|
|
|
}else{
|
|
|
//同一天的时间没有该分组则创建这天的随访计划List
|
|
|
Map<String,Object> newdateNursery = new HashedMap();
|
|
|
|
|
|
List<NurseryLogDO> dateNurseryLogs = new ArrayList<>();
|
|
|
dateNurseryLogs.add(nurseryLogDO);
|
|
|
newdateNursery.put("nurserys",dateNurseryLogs);
|
|
|
date.put(nurseryLogDO.getRecordDate(),newdateNursery);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return date;
|
|
|
}
|
|
|
|
|
|
public Map<String,Object> sortNurseryLogList(List<NurseryLogDO> nurseryLogDOs){
|
|
|
//统计完成数
|
|
|
Integer compeleCount = 0;
|
|
|
//总数
|
|
|
Integer count = 0;
|
|
|
//迭代数组
|
|
|
List<NurseryLogDO> rs = new ArrayList<>();
|
|
|
if(nurseryLogDOs!=null&&nurseryLogDOs.size()>0){
|
|
|
Iterator it = nurseryLogDOs.iterator();
|
|
|
while (it.hasNext()){
|
|
|
NurseryLogDO nurseryLogDO = (NurseryLogDO)it.next();
|
|
|
rs.add(nurseryLogDO);
|
|
|
if("1".equals(nurseryLogDO.getStatus())){
|
|
|
compeleCount++;
|
|
|
}
|
|
|
}
|
|
|
//设置总数
|
|
|
count = rs.size();
|
|
|
}
|
|
|
|
|
|
Map<String,Object> mapFollow =new HashedMap();
|
|
|
mapFollow.put("compeleCount",compeleCount);
|
|
|
mapFollow.put("count",count);
|
|
|
return mapFollow;
|
|
|
}
|
|
|
|
|
|
}
|