package com.yihu.rehabilitation.service; import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.yihu.fastdfs.FastDFSUtil; import com.yihu.jw.doctor.dao.BaseDoctorDao; import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao; import com.yihu.jw.entity.base.doctor.BaseDoctorDO; import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO; import com.yihu.jw.entity.base.patient.BasePatientDO; import com.yihu.jw.entity.base.team.BaseTeamMemberDO; import com.yihu.jw.entity.base.wx.WxWechatDO; import com.yihu.jw.entity.door.SignFamily; import com.yihu.jw.entity.hospital.doctor.Frequency; import com.yihu.jw.entity.hospital.message.SystemMessageDO; import com.yihu.jw.entity.patient.Message; import com.yihu.jw.entity.rehabilitation.SpecialDiseaseMessagesDO; import com.yihu.jw.entity.specialist.DoctorPatientRelationDO; import com.yihu.jw.entity.specialist.HospitalServiceItemDO; import com.yihu.jw.entity.specialist.RehabilitationServiceItemDO; import com.yihu.jw.entity.specialist.rehabilitation.*; import com.yihu.jw.entity.util.TransforSqlUtl; import com.yihu.jw.file_upload.FileUploadService; import com.yihu.jw.hospital.message.dao.SystemMessageDao; import com.yihu.jw.org.dao.BaseOrgDao; import com.yihu.jw.patient.dao.BasePatientDao; import com.yihu.jw.rehabilitation.DoctorPatientRelationDao; import com.yihu.jw.rehabilitation.RehabilitationOperateRecordsDao; import com.yihu.jw.restmodel.iot.common.UploadVO; import com.yihu.jw.restmodel.specialist.PatientSignInfoVO; import com.yihu.jw.restmodel.web.Envelop; import com.yihu.jw.restmodel.web.ListEnvelop; import com.yihu.jw.restmodel.web.MixEnvelop; import com.yihu.jw.restmodel.web.ObjEnvelop; import com.yihu.jw.rm.specialist.SpecialistMapping; import com.yihu.jw.sign.dao.MessagesDao; import com.yihu.jw.team.BaseDoctorTeamMemberDao; import com.yihu.jw.util.common.IdCardUtil; import com.yihu.jw.util.common.QrcodeUtil; import com.yihu.jw.util.date.DateUtil; import com.yihu.jw.utils.hibernate.HibenateUtils; import com.yihu.jw.wechat.dao.WechatDao; import com.yihu.mysql.query.BaseJpaService; import com.yihu.rehabilitation.dao.*; import com.yihu.rehabilitation.vo.TemplateDetailVo; import com.yihu.utils.network.HttpResponse; import com.yihu.utils.network.HttpUtils; import com.yihu.utils.security.MD5; import org.apache.commons.collections.map.HashedMap; 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.redis.core.StringRedisTemplate; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mock.web.MockMultipartFile; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; import static com.yihu.jw.entity.base.module.ModuleDO.Type.patient; /** * Created by humingfen on 2018/8/22. */ @Service @Transactional public class RehabilitationPlanService extends BaseJpaService { @Value("${specialist.url}") private String specialistUrl; @Autowired private SpecialistEvaluateSevice specialistEvaluateSevice; @Autowired private SignFamilyDao signFamilyDao; @Autowired private SystemMessageDao messageDao; @Autowired private BasePatientDao patientDao; @Autowired private JdbcTemplate jdbcTemplate; @Autowired private FrequencyDao frequencyDao; @Autowired private BaseDoctorDao doctorDao; @Autowired private PatientRehabilitationPlanDao patientRehabilitationPlanDao; @Autowired private ObjectMapper objectMapper; @Autowired private RehabilitationDetailDao rehabilitationDetailDao; @Autowired private RehabilitationManageService rehabilitationManageService; @Value("${neiwang.enable}") private Boolean isneiwang; //如果不是内网项目要转到到内网wlyy在上传 @Autowired private FastDFSUtil fastDFSUtil; @Value("${fastDFS.fastdfs_file_url}") private String fastdfs_file_url; @Autowired FileUploadService fileUploadService; @Value("${testPattern.sign}") private String isClose; @Value("${testPattern.remote_inner_url}") private String remote_inner_url; @Autowired private WechatDao wechatDao; @Value("${wechat.id}") private String wxId; @Autowired private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao; @Autowired private BaseOrgDao baseOrgDao; @Autowired private BaseDoctorTeamMemberDao baseDoctorTeamMemberDao; @Autowired private BaseDoctorHospitalDao baseDoctorHospitalDao; @Autowired private HibenateUtils hibenateUtils; @Autowired private DoctorPatientRelationDao doctorPatientRelationDao; @Autowired private RehabilitationPlanTemplateDao templateDao; @Autowired private RehabilitationTemplateDetailDao templateDetailDao; @Autowired private RehabilitationServiceItemDao serviceItemDao; @Autowired StringRedisTemplate redisTemplate; public Envelop updatePatientImgById(String planId, String patientImg) { if(patientRehabilitationPlanDao.updatePatientImgById(planId,patientImg) > 0){ return Envelop.getSuccess(SpecialistMapping.api_success); } return Envelop.getError("更新失败!"); } /*public JSONArray findTemplateInfo(String doctor, String patient) throws Exception { Map param = new HashedMap(); Long adminTeamId = null; AdminTeam team = teamService.findByLeaderCode(doctor); if(StringUtils.isBlank(patient)){ adminTeamId = team.getId(); param.put("adminTeamCode", adminTeamId); }else { param.put("doctor", doctor); param.put("patient", patient); } HttpResponse response = null; try { response = HttpUtils.doGet(specialistUrl + "svr-specialist/findRehabilitationPlanTemplate", param); } catch (Exception e) { e.printStackTrace(); } JSONObject rs = new JSONObject(response.getContent()); if ("success".equals(rs.getString("message"))) { return rs.getJSONArray("detailModelList"); } throw new Exception("请求获取模板列表失败!"); }*/ public List createRehabilitationDetail(List details, String planId,String createUser,String createUserName) { for(RehabilitationDetailDO detail : details) { /*List list = new ArrayList<>(); list.add(detail.getHospitalServiceItemId()); HospitalServiceItemDO hospitalServiceItemDO = hospitalServiceItemService.selectById(list).getDetailModelList().get(0); detail.setHospital(hospitalServiceItemDO.getHospital()); detail.setHospitalName(hospitalServiceItemDO.getHospitalName()); detail.setExpense(hospitalServiceItemDO.getExpense());*/ detail.setPlanId(planId); detail.setCreateTime(new Date()); detail.setStatus(0); detail.setUpdateTime(new Date()); detail.setCreateUser(createUser); detail.setCreateUserName(createUserName); } return (List)rehabilitationDetailDao.save(details); } //code,timeType,executeTimes public String createRehabilitationPlan(String json, BaseDoctorDO doctor) throws Exception { JSONObject object = new JSONObject(json); String patient = object.getString("patient"); String relationId=object.getString("relationId"); String teamCode=object.getString("teamCode"); BasePatientDO patientDo = patientDao.findById(patient); if (patientDo==null){ BasePatientDO basePatientDO = new BasePatientDO(); basePatientDO.setName(object.getString("patientName")); basePatientDO.setIdcard(object.getString("idCard")); basePatientDO.setMobile(object.getString("mobile")); patientDo = saveUnSignPatient(basePatientDO); } String patientName=""; if(patientDo!=null){ patientName = patientDo.getName(); } JSONArray array = object.getJSONArray("detail"); for (int z=0;z list = new ArrayList<>(); if (StringUtils.isNoneBlank(executeTimes)){ for (int i=0;i times = getFrequencyDate(frequency.getCode(),executeTime[i],frequency.getUnit(),frequency.getTime(),timeType); for (int j=0;j details = objectMapper.readValue(planDetails, new TypeReference>(){}); PatientRehabilitationPlanDO planDO = objectMapper.readValue(json.toString(), PatientRehabilitationPlanDO.class); planDO.setCreateUser(doctor.getId()); planDO.setCreateUserName(doctor.getName()); planDO = createPatientRehabilitationPlan(planDO); details = createRehabilitationDetail(details, planDO.getId(),doctor.getId(),doctor.getName()); //康复计划创建完给执行者发送消息 String planId = null; if (planDO!=null){ planId=planDO.getId(); } HashSet set = new HashSet(); for ( RehabilitationDetailDO rehabilitationDetailDO : details) { if (!set.contains(rehabilitationDetailDO.getDoctor())) { set.add(rehabilitationDetailDO.getDoctor()); SystemMessageDO message = new SystemMessageDO(); message.setSender(doctor.getId()); message.setType("19"); message.setRelationCode(rehabilitationDetailDO.getPlanId()); message.setReceiver(rehabilitationDetailDO.getDoctor()); message.setReason(doctor.getName()); specialistEvaluateSevice.sendMessage(message, rehabilitationDetailDO.getHospital(), patient, null,null); //pushMsgTask.put(rehabilitationDetailDO.getDoctor(),"20", "康复计划创建消息", "您的居民"+patientName+"的康复计划已配置完成,点击查看", ""); } } DoctorPatientRelationDO doctorPatientRelationDO = doctorPatientRelationDao.findOne(relationId); if (null!=doctorPatientRelationDO){ if (doctorPatientRelationDO.getIsManage()==null||doctorPatientRelationDO.getIsManage()==0){ doctorPatientRelationDO.setDoctor(doctor.getId()); doctorPatientRelationDO.setDoctorName(doctor.getName()); doctorPatientRelationDO.setIsManage(0); } doctorPatientRelationDO.setTeamCode(teamCode); doctorPatientRelationDO.setIsdeal("1"); doctorPatientRelationDao.save(doctorPatientRelationDO); } SignFamily signFamily = signFamilyDao.findByPatient(patient); //推送消息到IM if (signFamily != null && !set.contains(signFamily.getDoctor())) { //pushMsgTask.put(signFamily.getDoctor(),"20", "康复计划创建消息", "您的居民"+patientName+"的康复计划已配置完成,点击查看", ""); } return planId; } public MixEnvelop createServiceQrCode(String planDetailId, String doctorCode) throws Exception{ //更新到康复计划居民关系表中 Map param = new HashedMap(); String fileUrl = ""; String sql ="SELECT service_qr_code FROM wlyy_specialist.wlyy_rehabilitation_plan_detail where id='"+planDetailId+"'"; List> list = jdbcTemplate.queryForList(sql); if(list!=null && list.size()>0){ fileUrl = String.valueOf(list.get(0).get("service_qr_code")); } if (StringUtils.isEmpty(fileUrl) || "null".equals(fileUrl)){ //生成二维码图片 WxWechatDO wxWechatDO = wechatDao.findById(wxId); String appId=""; String wechat_base_url=""; if (wxWechatDO!=null){ appId=wxWechatDO.getAppId(); wechat_base_url=wxWechatDO.getBaseUrl(); } String contentJsonStr="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wechat_base_url+"/wx/html/kfgl/html/confirm-service.html"+"?paramStr="+planDetailId+","+doctorCode+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png"); UploadVO uploadVO = new UploadVO(); String originalFilename ="plan_service_qrcode" + System.currentTimeMillis()+".png"; if (isClose.equalsIgnoreCase("1")){ Map map = fileUploadService.uploadImg(new MockMultipartFile(originalFilename,originalFilename,"", ipt)); uploadVO.setFullUri(map.get("accessory").toString()); }else if(isClose.equals("2")){ String[] fs = originalFilename.split("\\."); String type = fs[1]; //内网上传 String rs = fileUploadService.request(remote_inner_url,new MockMultipartFile(originalFilename,originalFilename,"", ipt),type); com.alibaba.fastjson.JSONObject json = JSON.parseObject(rs); uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class); }else { // 得到文件的完整名称 xxx.txt /*InputStream inputStream = ipt;*/ uploadVO = fileUploadService.uploadStream(ipt,originalFilename,fastdfs_file_url); } fileUrl = uploadVO.getFullUri(); } System.out.println("服务码-----------1"+fileUrl); String sqlUpdate = "update wlyy_rehabilitation_plan_detail set service_qr_code='" + fileUrl + "' where id='" + planDetailId + "'"; jdbcTemplate.update(sqlUpdate); return MixEnvelop.getSuccess("获取二维码成功!",fileUrl); } public Map checkAfterQrCode(String planDetailId,String patietCode)throws Exception{ Map map = new HashedMap(); int result = 0; String name= ""; String sql ="SELECT p.patient,p.name FROM `wlyy_rehabilitation_plan_detail` pd LEFT JOIN wlyy_patient_rehabilitation_plan p ON pd.plan_id = p.id WHERE pd.id='"+planDetailId+"'"; sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql); List> list = jdbcTemplate.queryForList(sql); if (list!=null && list.size()>0){ if (String.valueOf(list.get(0).get("patient")).equals(patietCode)){ result =200; }else { result = -1; name=String.valueOf(list.get(0).get("name")); } }else { result = -10000; } map.put("code",result); if (StringUtils.isNotBlank(name)){ map.put("name",name); } return map; } public PatientRehabilitationPlanDO createPatientRehabilitationPlan(PatientRehabilitationPlanDO planDO) { planDO.setCreateTime(new Date()); planDO.setStatus(1); planDO.setIsVerify("0"); planDO.setUpdateTime(new Date()); return patientRehabilitationPlanDao.save(planDO); } public List getFrequencyDate(String code,String date,String unit,String time,Long timeType) throws ParseException { List list = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String nowDate = date+":00"; System.out.println("date"+date+"===code"+code); Date date6 = DateUtil.strToDateLong(nowDate); System.out.println(date6); String date9 = sdf.format(date6)+" 09:00:00";//白天 String date21 = sdf.format(date6)+" 21:00:00";//白天 String date9s = DateUtil.getNextDay(date6,1)+" 09:00:00";//晚上 Calendar calendar = Calendar.getInstance(); if (unit.equalsIgnoreCase("D")&&!code.equalsIgnoreCase("qod")){ String[] str = time.split(","); for (int i=0;i param = new HashedMap(); param.put("id", templateId); HttpResponse response = null; try { response = HttpUtils.doPost(specialistUrl + "svr-specialist/deleteRehabilitationPlanTemplate", param); } catch (Exception e) { e.printStackTrace(); } JSONObject rs = new JSONObject(response.getContent()); return rs.getString("message"); } /** * 更新计划的状态 * @param planId * @param status * @throws Exception */ public void updatePlanStatusById(String planId, Integer status,String abortReason) throws Exception{ Map param = new HashedMap(); param.put("planId", planId); param.put("status", status); param.put("abortReason",abortReason); HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePlanStatusById", param); JSONObject result = new JSONObject(response.getContent()); if (result.getInt("status")==200 && status==0){ List messageList = new ArrayList<>(); Map recieveMap = new HashMap<>(); JSONObject jsonObject =result.getJSONObject("obj"); String patientCode = jsonObject.getString("patient"); String patientName = jsonObject.getString("name"); String diseaseName = jsonObject.getString("diseaseName"); String createDoctorCode = jsonObject.getString("createUser"); JSONArray detailModelList = result.getJSONArray("detailModelList"); for (Object obj : detailModelList) { JSONObject detail = (JSONObject) obj; String doctor = detail.getString("doctor"); if (!createDoctorCode.equals(doctor)){ if (!recieveMap.containsKey(doctor)){ recieveMap.put(doctor,detail.getString("doctorName")); } } } SignFamily signFamily = signFamilyDao.findByPatient(patientCode); if (signFamily!=null){ if (!recieveMap.containsKey(signFamily.getDoctor())){ recieveMap.put(signFamily.getDoctor(),signFamily.getDoctorName()); } } for (Map.Entry entry : recieveMap.entrySet()){ //推送消息到IM //pushMsgTask.put(entry.getKey(),"20", "康复计划中止消息", "您的居民"+patientName+",已中止"+diseaseName+"康复计划,点击查看原因", ""); SystemMessageDO message = initMessage(patientName,entry.getKey(),entry.getValue(),"system","system","康复计划-中止提醒","您的居民"+patientName+",已中止"+diseaseName+"康复计划,点击查看原因。",planId,29); messageList.add(message); } messageDao.save(messageList); /*Message message = new Message(); message.setCzrq(new Date()); message.setCreateTime(new Date()); message.setContent("您的"+patientName+"签约居民,已中止康复计划,点击查看原因。"); message.setRead(1);//设置未读 if (signFamily!=null){ message.setReceiver(signFamily.getDoctor());//设置接受医生的code message.setReceiverName(signFamily.getDoctorName()); } message.setSender("system");//设置发送的用户 message.setSenderName("system"); message.setCode(UUID.randomUUID().toString().replaceAll("-", "")); message.setSenderPhoto(""); message.setTitle("康复计划-中止提醒"); message.setType(29);//康复计划中止消息提醒 message.setReadonly(1);//是否只读消息 message.setRelationCode(planId); message.setOver("1");//未处理 message.setState(1); message.setData(""); message.setDel("1");*/ //推送消息到IM // pushMsgTask.put(signFamily.getDoctor(),"20", "康复计划中止消息", "您的"+patientName+"签约居民,已中止康复计划,点击查看原因", ""); } if(result.getInt("status")!=200){ throw new Exception("请求微服务失败!"); } } private SystemMessageDO initMessage(String patientName, String doctor, String doctorName, String sender, String senderName, String title, String content, String relatioenCode, int type){ SystemMessageDO message = new SystemMessageDO(); message.setCreateTime(new Date()); message.setContent("您的服务居民"+patientName+",已中止康复计划,点击查看原因。"); message.setIsRead("1");//设置未读 message.setReceiver(doctor);//设置接受医生的code message.setReceiverName(doctorName); message.setSender(sender);//设置发送的用户 message.setSenderName(senderName); message.setCode(UUID.randomUUID().toString().replaceAll("-", "")); message.setSenderPhoto(""); message.setTitle(title); message.setType(String.valueOf(type));//康复计划中止消息提醒 message.setReadonly(1);//是否只读消息 message.setRelationCode(relatioenCode); message.setOver("0");//未处理 message.setState(1); message.setData(""); message.setDel("1"); return message; } public JSONObject getServiceItemsAfterStop(String planId)throws Exception{ JSONObject jsonObject = new JSONObject(); Map map=rehabilitationManageService.getServiceItemsAfterStop(planId); JSONArray jsonArray = new JSONArray(map.get("serviceList")); if (jsonArray!=null && jsonArray.length()>0){ jsonObject.put("patientName",jsonArray.getJSONObject(0).get("name")); jsonObject.put("abortTime",jsonArray.getJSONObject(0).get("abort_time")); jsonObject.put("hospitalName",jsonArray.getJSONObject(0).get("hospital_name")); jsonObject.put("abortReason",jsonArray.getJSONObject(0).get("abort_reason")); String patientCode = String.valueOf(jsonArray.getJSONObject(0).get("patient")); jsonObject.put("patientCode", patientCode); jsonObject.put("disease_name", jsonArray.getJSONObject(0).get("disease_name")); jsonObject.put("create_time", jsonArray.getJSONObject(0).get("create_time")); jsonObject.put("patient_img", jsonArray.getJSONObject(0).get("patient_img")); BasePatientDO patient = patientDao.findById(patientCode); if (patient!=null){ jsonObject.put("openid", patient.getOpenid()); jsonObject.put("ssc",patient.getSsc()); jsonObject.put("mobile",patient.getMobile()); } } return jsonObject; } /** * 更新居民签名照/证件照 * @param planId * @throws Exception *//* public void updatePatientImgById(String planId, String patientImg) throws Exception { Map param = new HashedMap(); param.put("planId", planId); param.put("patientImg", patientImg); HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePatientImgById", param); JSONObject result = new JSONObject(response.getContent()); if(result.getInt("status")!=200){ throw new Exception("请求微服务失败!"); } }*/ public void sendWxTemplate(String accessToken, String planId, String doctorCode, JSONObject jsonObject) { BaseDoctorDO d = doctorDao.findById(doctorCode); JSONObject json = new JSONObject(); String patient = jsonObject.getString("patientCode"); String patientName = jsonObject.get("patientName") + ""; json.put("first", patientName + "您好,您有一个康复计划已完成,请确认接收。"); json.put("toUser", patient); json.put("represented", patient);//被代理人 json.put("keyword1", jsonObject.get("disease_name") + "康复计划"); json.put("keyword2", d.getName()); json.put("keyword3", DateUtil.dateToStr(new Date ((Long) jsonObject.get("create_time")), "yyyy/MM/dd") + "-" + DateUtil.dateToStr(new Date(), "yyyy/MM/dd")); json.put("remark", "完成的康复项清单已发送给您,点击此消息可查看。"); json.put("planId", planId); if (!jsonObject.isNull("openid")) { //pushMsgTask.putWxMsg(accessToken, 27, jsonObject.get("openid") + "", patientName, json); }/*else { try { //发送代理人 JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid); if (jsonArray != null && jsonArray.length() > 0) { Patient p = patientDao.findByCode(patient); for (int i = 0; i < jsonArray.length(); i++) { JSONObject j = jsonArray.getJSONObject(i); Patient member = (Patient) j.get("member"); JSONObject data = json; data.remove("toUser"); data.put("toUser", member.getCode()); data.remove("first"); json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName())); pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 27, member.getOpenid(), p.getName(), data); } } } catch (Exception e) { e.printStackTrace(); } }*/ } public BasePatientDO saveUnSignPatient(BasePatientDO basepatientDO){ basepatientDO.setDel("1"); basepatientDO.setLocked(0); basepatientDO.setEnabled(1); String salt = randomString(5); basepatientDO.setSalt(salt); basepatientDO.setPassword(MD5.md5Hex(basepatientDO.getIdcard().substring(12,18) + "{" + salt + "}")); basepatientDO=patientDao.save(basepatientDO); return basepatientDO; } public RehabilitationOperateRecordsDO saveRehabilitationRecord(RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO){ RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(rehabilitationOperateRecordsDO.getRehabilitationDetailId()); if (!StringUtils.isNoneBlank(rehabilitationOperateRecordsDO.getId())){ rehabilitationOperateRecordsDO.setId(getCode()); } if (rehabilitationDetailDO.getExecuteTime()!=null){ rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime()); } rehabilitationOperateRecordsDO.setCompleteTime(new Date()); rehabilitationOperateRecordsDO.setCreateTime(new Date()); rehabilitationOperateRecordsDO.setUpdateTime(new Date()); rehabilitationOperateRecordsDO.setStatus(rehabilitationOperateRecordsDO.getStatus()); if (StringUtils.isEmpty(rehabilitationOperateRecordsDO.getPatientName())){ String sql ="select name from base_patient where id='"+rehabilitationOperateRecordsDO.getPatientCode()+"'"; List> list = jdbcTemplate.queryForList(sql); if (list!=null && list.size()>0){ rehabilitationOperateRecordsDO.setPatientName(String.valueOf(list.get(0).get("name"))); } } return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO); } /** * 更新康复计划项目状态 * @param status * @param planId * @return */ public MixEnvelop updatePlanStatusById(Integer status, String planId) throws Exception{ if(status == 1) { if (patientRehabilitationPlanDao.updateStatusById(status, planId) > 0) { return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId)); } }else if(status == 2){ if (patientRehabilitationPlanDao.updateStatusAndTimeById(2,planId, new Date()) > 0) { return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId)); } } return MixEnvelop.getError("更新失败!"); } public MixEnvelop abortPlanById(String planId,String abortReason){ PatientRehabilitationPlanDO patientRehabilitationPlanDO=patientRehabilitationPlanDao.findById(planId); List detailDOList = rehabilitationDetailDao.findByPlanIdAndStatus(planId,0); if(null!=patientRehabilitationPlanDO){ patientRehabilitationPlanDO.setAbortReason(abortReason); patientRehabilitationPlanDO.setAbortTime(new Date()); patientRehabilitationPlanDO.setStatus(0); patientRehabilitationPlanDO.setUpdateTime(new Date()); patientRehabilitationPlanDao.save(patientRehabilitationPlanDO); return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRehabilitationPlanDO,detailDOList); } return MixEnvelop.getError("更新失败!"); } public ObjEnvelop findServiceItemByDoctor(String doctor){ String teamCode=""; String orgCode=""; List baseTeamMemberDO = baseDoctorTeamMemberDao.findUseDoctorCode(doctor); if (baseTeamMemberDO!=null&&baseTeamMemberDO.size()>0){ teamCode= baseTeamMemberDO.get(0).getTeamCode(); } List baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctor); if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){ orgCode= baseDoctorHospitalDO.get(0).getOrgCode(); } String packageSql = "select m.service_package_id as \"servicePackageId\"," + " n.name as \"name\"" + "from base_service_package_item m left join base_service_package n on" + " m.service_package_id = n.id where 1=1 and m.service_package_id !='system' "; if(StringUtils.isNoneBlank(teamCode)){ packageSql+= " and m.team_code ='"+teamCode+"'"; }else { return null; } if(StringUtils.isNoneBlank(orgCode)){ packageSql+= " and m.org_code ='"+orgCode+"'"; }else { return null; } packageSql+=" group by m.service_package_id,n.name "; List> listPackage = hibenateUtils.createSQLQuery(packageSql); for (Map map:listPackage){ if (map.get("servicePackageId")!=null){ String sql = "select t.id as \"id\"," + " t.code as \"code\"," + " t.name as \"name\"," + " t.service_package_id as \"servicePackageId\"," + " t.price as \"price\"," + " t.fee_type as \"feeType\"," + " t.org_code as \"orgCode\"," + " t.org_name as \"orgName\"," + " t.introduce as \"introduce\"," + " t.del as \"del\"," + " t.team_code as \"teamCode\"," + " t.team_name as \"teamName\"," + " t.create_time as \"createTime\"," + " t.dict_id as \"dictId\"" + " from base_service_package_item t where 1=1 and t.service_package_id !='system' "; if (StringUtils.isNoneBlank(teamCode)) { sql += " and t.team_code ='" + teamCode + "'"; } if (StringUtils.isNoneBlank(orgCode)) { sql += " and t.org_code ='" + orgCode + "'"; } sql+=" and t.service_package_id = '"+map.get("servicePackageId").toString()+"'"; List> list = hibenateUtils.createSQLQuery(sql); map.put("itemList",list); } } return ObjEnvelop.getSuccess("操作成功",listPackage); } public List> findServiceItemInBase(String code,String name,String teamCode){ String sql = "select t.id as \"id\"," + " t.code as \"code\"," + " t.name as \"name\"," + " t.service_package_id as \"servicePackageId\"," + " t.price as \"price\"," + " t.fee_type as \"feeType\"," + " t.org_code as \"orgCode\"," + " t.org_name as \"orgName\"," + " t.introduce as \"introduce\"," + " t.del as \"del\"," + " t.team_code as \"teamCode\"," + " t.team_name as \"teamName\"," + " t.create_time as \"createTime\"," + " t.dict_id as \"dictId\"" + " from base_service_package_item t where 1=1 and t.service_package_id ='system' and t.del ='1'"; if (StringUtils.isNoneBlank(teamCode)) { sql += " and t.team_code ='" + teamCode + "'"; } if (StringUtils.isNoneBlank(code)) { sql += " and t.code ='" + code + "'"; } if (StringUtils.isNoneBlank(name)) { sql += " and t.name ='" + name + "'"; } List> list = hibenateUtils.createSQLQuery(sql); return list; } public List> findDoctorTeams(String doctor){ String sql = "select a.id as \"id\", " + " a.org_code as \"orgCode\"," + " a.org_name as \"orgName\"," + " a.name as \"name\"," + " a.leader_code as \"leaderCode\"," + " a.team_num as \"teamNum\"," + " a.qrcode as \"qrcode\"," + " a.del as \"del\"," + " a.create_time as \"createTime\"" + " from base_team a left join base_team_member b " + " on a.id = b.team_code where a.del ='1' "; if (StringUtils.isNotBlank(doctor)){ sql+=" and b.doctor_code ='"+doctor+"'"; }else{ return null; } List> list = hibenateUtils.createSQLQuery(sql); return list; } public List> findDoctorByTeams(String teamCode){ String sql = "select b.id as \"id\"," + " t.id as \"doctorId\"," + " t.name as \"doctorName\"," + " b.team_code as \"teamcode\"," + " b.org_code as \"orgcode\"" + "from base_team_member b left join base_doctor t on b.doctor_code = t.id" + " where b.del =1 "; if (StringUtils.isNotBlank(teamCode)){ sql+=" and b.team_code ='"+teamCode+"'"; }else{ return null; } List> list = hibenateUtils.createSQLQuery(sql); return list; } public ObjEnvelop createRehabilitationTemplate(RehabilitationPlanTemplateDO templateDO) { templateDO.setCreateTime(new Date()); templateDO.setDel(1); templateDO.setUpdateTime(new Date()); templateDO = templateDao.save(templateDO); String templateId = templateDO.getId(); String user = templateDO.getCreateUser(); String userName = templateDO.getCreateUserName(); //默认新增服务项 String sql = "SELECT code from wlyy.system_dict WHERE `dict_name` = 'default_service_item_id'"; List list = jdbcTemplate.queryForList(sql,String.class); if(list!=null&&list.size()>0){ list.stream().forEach(code->{ RehabilitationTemplateDetailDO detailDO = new RehabilitationTemplateDetailDO(); detailDO.setTemplateId(templateId); detailDO.setHospitalServiceItemId(code); detailDO.setCreateUser(user); detailDO.setCreateUserName(userName); detailDO.setCreateTime(new Date()); detailDO.setUpdateTime(new Date()); templateDetailDao.save(detailDO); }); } return ObjEnvelop.getSuccess(SpecialistMapping.api_success,templateDO.getId()); } public ObjEnvelop createRehabilitationTemplateDetail(List details) { for(RehabilitationTemplateDetailDO detail : details){ detail.setCreateTime(new Date()); detail.setUpdateTime(new Date()); templateDetailDao.save(detail); } return ObjEnvelop.getSuccess(SpecialistMapping.api_success,true); } public ObjEnvelop updateRehabilitationTemplateDetail(List details) { String templateId = details.get(0).getTemplateId(); if(templateId != null && templateId.length() > 0){ templateDetailDao.deleteByTemplateId(templateId); } for(RehabilitationTemplateDetailDO detail : details){ detail.setCreateTime(new Date()); detail.setUpdateTime(new Date()); templateDetailDao.save(detail); } return ObjEnvelop.getSuccess(SpecialistMapping.api_success,true); } public MixEnvelop findRehabilitationPlanTemplate(Long adminTeamCode, String doctor, String patient) { List list = templateDao.findByAdminTeamCode(adminTeamCode); return MixEnvelop.getSuccessList(SpecialistMapping.api_success, list); } /** * 根据模板id修改康复模板删除状态 * @param id * @return */ public ObjEnvelop deleteRehabilitationPlanTemplate(String id) { templateDao.updateDelById(id); return ObjEnvelop.getSuccess(SpecialistMapping.api_success,true); } /** * 根据模板id获取机构服务项目id,然后找出具体服务项目内容 * @param templateId * @return */ public ListEnvelop findTemplateDetailByTemplateId(String templateId) { List resultList = new ArrayList<>(); List list = templateDetailDao.findTemplateDetailByTemplateId(templateId); List itemDOList = serviceItemDao.findList(); Map> map = list.stream().collect(Collectors.groupingBy(RehabilitationTemplateDetailDO::getHospitalServiceItemId)); for (String code : map.keySet()){ TemplateDetailVo detailVo = new TemplateDetailVo(); detailVo.setCode(code); detailVo.setId(code); detailVo.setList(map.get(code)); for (RehabilitationServiceItemDO item:itemDOList){ if(code.equals(item.getCode())){ detailVo.setName(item.getName()); break; } } resultList.add(detailVo); } return ListEnvelop.getSuccess(SpecialistMapping.api_success,resultList); } public List findSystemTemplateList(){ List itemDOList = serviceItemDao.findList(); return itemDOList; } public List createRehabilitationDetail(List details, String planId) { for(RehabilitationDetailDO detail : details) { /*List list = new ArrayList<>(); list.add(detail.getHospitalServiceItemId()); HospitalServiceItemDO hospitalServiceItemDO = hospitalServiceItemService.selectById(list).getDetailModelList().get(0); detail.setHospital(hospitalServiceItemDO.getHospital()); detail.setHospitalName(hospitalServiceItemDO.getHospitalName()); detail.setExpense(hospitalServiceItemDO.getExpense());*/ detail.setPlanId(planId); detail.setCreateTime(new Date()); detail.setStatus(0); detail.setUpdateTime(new Date()); } return (List)rehabilitationDetailDao.save(details); } public void deleteDetailByPlanIdAndHospitalServiceItemId(String planId, String hospitalServiceItemId, Date dateShort) { rehabilitationDetailDao.deleteDetailByPlanIdAndHospitalServiceItemId(planId, hospitalServiceItemId, dateShort); } public void deleteDetailByPlanId(String planId, Date dateShort) { rehabilitationDetailDao.deleteDetailByPlanId(planId, dateShort); } public List updateRehabilitationPlan(String json, BaseDoctorDO doctor,String updateStatus) throws Exception { JSONObject object = new JSONObject(json); JSONArray array = object.getJSONArray("detail"); for (int z=0;z list = new ArrayList<>(); String[] executeTime = executeTimes.split(","); for (int i = 0; i < executeTime.length; i++) { List times = getFrequencyDate(frequency.getCode(), executeTime[i], frequency.getUnit(), frequency.getTime(), timeType); for (int j = 0; j < times.size(); j++) { if (list != null && list.size() != 0) { if (!list.contains(times.get(j))) { list.add(times.get(j)); } } else { list.add(times.get(j)); } } } StringBuffer buffer = new StringBuffer(); if (list != null && list.size() != 0) { for (int i = 0; i < list.size(); i++) { buffer.append(list.get(i) + ","); } if (StringUtils.isNoneBlank(buffer)) { buffer.deleteCharAt(buffer.length() - 1); } } jsonObject.put("executeTime", buffer); } jsonObject.remove("executeTimes"); } object.put("createUser", doctor.getId()); object.put("createUserName", doctor.getName()); String planId = object.getString("planId"); String hospitalServiceItemId = object.getString("hospitalServiceItemId"); //删除该服务项目今日之后未完成的计划 if(StringUtils.isBlank(updateStatus)||updateStatus.equals("0")){//单个服务的修改 deleteDetailByPlanIdAndHospitalServiceItemId(planId, hospitalServiceItemId, DateUtil.getDateShort(new Date())); } else{ deleteDetailByPlanId(planId, DateUtil.getDateShort(new Date())); } JSONArray array1 = new JSONArray(); for(Object planDetail : object.getJSONArray("detail")) { String expense=""; JSONObject j = (JSONObject)planDetail; if (j.get("expense") instanceof Integer){ expense= String.valueOf(j.getInt("expense")); } else{ expense = j.getString("expense"); if(expense.contains(".")){ int pointIndex = expense.indexOf("."); expense = expense.substring(0,pointIndex); } } j.put("expense",expense); if(j.has("executeTime")) { String executeTime = j.get("executeTime").toString(); String[] result = null; if (executeTime.contains(",")) { result = executeTime.split(","); } else { result = new String[1]; result[0] = executeTime; } int len = result.length; while (len > 0) { len--; JSONObject temp = new JSONObject(j.toString()); temp.put("executeTime", result[len]); temp.put("createUser", object.get("createUser")); temp.put("createUserName", object.get("createUserName")); array1.put(temp); } }else { j.put("createUser", object.get("createUser")); j.put("createUserName", object.get("createUserName")); array1.put(j); } } String planDetails = array1.toString(); ObjectMapper object1 = new ObjectMapper(); object1.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm")); List details = object1.readValue(planDetails, new TypeReference>(){}); details = createRehabilitationDetail(details, planId); String updateTime = DateUtil.dateToStr(details.get(0).getCreateTime(),"yyyy-MM-dd hh:mm:ss"); //康复计划修改 日志添加 String sql ="INSERT INTO wlyy_patient_rehabilitation_plan_log(id,plan_id,create_user,create_user_name,create_time) " + "VALUES('"+getCode()+"','"+planId+"','"+doctor.getId()+"','"+ doctor.getName()+"','"+updateTime+"')"; jdbcTemplate.execute(sql); return details; } /** * 获取康复计划修改记录 * @param planId * @return */ public List> getRehabilitationPlanLog(String planId){ String sql ="select * from wlyy_patient_rehabilitation_plan_log where plan_id = '"+planId+"' ORDER BY create_time DESC"; List> planLogList = jdbcTemplate.queryForList(sql); return planLogList; } /** * 查询单个居民信息 * * @param patient * @return * @throws Exception */ public JSONObject getPatient(String patient,String doctor) throws Exception { JSONObject json = new JSONObject(); // Patient p = patientDao.findByCode(patient); BasePatientDO p = patientDao.findById(patient); if (p == null) { throw new Exception("patient info can not find"); } // 设置患者标识 json.put("code", p.getId()); // 设置患者姓名 json.put("name", p.getName()); // 设置患者手机号 json.put("mobile", p.getMobile()); // 设置患者微信openid json.put("openid", StringUtils.isNotEmpty(p.getOpenid()) ? p.getOpenid() : ""); json.put("openidTime",DateUtil.dateToStr(p.getOpenidTime(), DateUtil.YYYY_MM_DD_HH_MM_SS)); // 设置患者联系电话 json.put("phone", p.getPhone()); // 设置患者头像 json.put("photo", p.getPhoto()); // 设置患者年龄 json.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(),p.getBirthday())); // 设置患者性别 json.put("sex", p.getSex()); // 身份证号 json.put("idcard", p.getIdcard()); //1.4.2新增medicareNumber //json.put("medicareNumber", p.()); // 设置患者居住省份 json.put("provinceName", p.getProvinceName()); json.put("cityName", p.getCityName()); json.put("townName", p.getTownName()); json.put("streetName", p.getStreetName()); // 设置患者地址 json.put("address", p.getAddress()); // 社保号 json.put("ssc", p.getSsc()); //病情类型:0健康,1高血压,2糖尿病,(1,2)高血压+糖尿病 /* json.put("disease",p.getDisease()); // 病情:0绿标,1黄标,2红标, json.put("diseaseCondition",p.getDiseaseCondition());*/ //预警状态 json.put("standardStatus",p.getStandardStatus()); //设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪 /* json.put("deviceType",p.getDeviceType()==null?"":p.getDeviceType()); //20190719 增加返回字段:档案状态(-2冻结 1未管理 2死亡3 正常4 高危) json.put("archiveStatus",p.getArchiveStatus() == null? "":p.getArchiveStatus().toString()); // 专病类型,专病名称 json.put("specialistDisease", p.getSpecialistDisease()); json.put("specialistDiseaseName", p.getSpecialistDiseaseName()); */ if (json.has("expensesStatus") && (StringUtils.isEmpty(String.valueOf(json.get("expensesStatus"))) || String.valueOf(json.get("expensesStatus")).equals("0"))) { boolean epTime = false; try { epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getId()); } catch (Exception e) { e.printStackTrace(); } if (!epTime) { json.put("expensesRemindStatus", 0); } else { json.put("expensesRemindStatus", 1); } } boolean epTime = false; try { epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getId()); } catch (Exception e) { e.printStackTrace(); } if (!epTime) { json.put("wechatFocusRemind", 0); } else { json.put("wechatFocusRemind", 1); } String timeKey = DateUtil.dateToStr(new Date(), "yyyyMMdd"); String flag = redisTemplate.opsForValue().get("renew:" + timeKey + ":" + patient); if (StringUtils.isNotBlank(flag)) { json.put("isRemindRenew", "1"); } else { json.put("isRemindRenew", "0"); } //1.4.9 是否专科医生服务 List patientSignInfoVOS =findPatientSignSpecialist(patient); if(patientSignInfoVOS!=null&&patientSignInfoVOS.size()>0){ json.put("isSpecialist",1); json.put("specialistArray", patientSignInfoVOS); }else{ json.put("isSpecialist",0); } //1.5.0 是否有康复计划 List planList = planListByPatient(patient); if(planList!=null&&planList.size()>0){ json.put("havePlan",1); }else{ json.put("havePlan",0); } return json; } public List findPatientSignSpecialist(String patient){ String sql = "SELECT " + " r.id AS relationCode, " + " r.patient, " + " r.team_code AS teamCode,r.patient_name as patientName" + // AesEncryptUtils.decryptMysql("r.patient_name","patientName") + // " r.patient_name AS patientName, " + // " d.name AS doctorName, " + ",d.name as doctorName"+ // AesEncryptUtils.decryptMysql("d.name","doctorName") + " ,d.id AS doctor, " + " d.photo, " + " d.job_title_name AS job, " + " d.sex AS sex " + " FROM " + " wlyy_doctor_patient_relation r " + " JOIN base_doctor d ON r.doctor = d.id " + " WHERE " + " r.patient ='"+patient+"' " + " AND r.`status`>=0 " ; //sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name"); List patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientSignInfoVO.class)); return patientSignInfoVOs; } /** * 根据居民获取康复计划 * @param patient * @return */ public List planListByPatient(String patient){ List list = patientRehabilitationPlanDao.findByPatients(patient); return list; } public JSONArray findTemplateDetailInfo(String templateId) throws Exception { Map param = new HashedMap(); param.put("templateId", templateId); HttpResponse response = null; try { response = HttpUtils.doGet(specialistUrl + "svr-specialist/findTemplateDetailByTemplateId", param); } catch (Exception e) { e.printStackTrace(); } JSONObject rs = new JSONObject(response.getContent()); if (rs.getInt("status") == 200) { JSONArray result = rs.getJSONArray("detailModelList"); for (int i=0;i