12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- 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<PatientRehabilitationPlanDO, PatientRehabilitationPlanDao> {
- @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<String, Object> 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<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId,String createUser,String createUserName) {
- for(RehabilitationDetailDO detail : details) {
- /*List<String> 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<RehabilitationDetailDO>)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<array.length();z++){
- JSONObject jsonObject = array.getJSONObject(z);
- Long timeType = jsonObject.getLong("timeType");
- Frequency frequency = frequencyDao.findByCode(jsonObject.getString("frequencyCode"));
- String executeTimes = jsonObject.getString("executeTimes");
- String[] executeTime = executeTimes.split(",");
- List<String> list = new ArrayList<>();
- if (StringUtils.isNoneBlank(executeTimes)){
- for (int i=0;i<executeTime.length;i++){
- List<String> 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 planDetails = array.toString();
- objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm"));
- List<RehabilitationDetailDO> details = objectMapper.readValue(planDetails, new TypeReference<List<RehabilitationDetailDO>>(){});
- 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<String,String> createServiceQrCode(String planDetailId, String doctorCode) throws Exception{
- //更新到康复计划居民关系表中
- Map<String, Object> param = new HashedMap();
- String fileUrl = "";
- String sql ="SELECT service_qr_code FROM wlyy_specialist.wlyy_rehabilitation_plan_detail where id='"+planDetailId+"'";
- List<Map<String,Object>> 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<String, Object> 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<String,Object> checkAfterQrCode(String planDetailId,String patietCode)throws Exception{
- Map<String,Object> 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<Map<String,Object>> 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<String> getFrequencyDate(String code,String date,String unit,String time,Long timeType) throws ParseException {
- List<String> 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<str.length;i++){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- String lastDay = sdf.format(calendar.getTime()) + " "+str[i];
- list.add(lastDay);
- }
- }else if (unit.equalsIgnoreCase("D")&&code.equalsIgnoreCase("qod")){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) +1);
- String lastDay = sdf.format(calendar.getTime()) + " "+time;
- list.add(lastDay);
- }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q0.5h")){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- String endTime = null;
- String lastDay = null;
- if (timeType == 0){
- lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- endTime = sdf.format(calendar.getTime()) + " 23:59:59";
- }else if ( timeType == 1){
- lastDay = date9;
- endTime = date21;
- }else if (timeType == 2){
- lastDay = date21;
- endTime = date9s;
- }
- Date date2 = sdf1.parse(lastDay);
- Date date3 = sdf1.parse(endTime);
- Long time1 = date2.getTime();
- for (int i=0;i<47;i++){
- time1 += 30*60*1000;
- String day = sdf1.format(time1);
- Date date4 = sdf1.parse(day);
- if (date4.compareTo(date3)==-1 || date4.compareTo(date3) == 0){
- list.add(day);
- }
- }
- }else if (unit.equalsIgnoreCase("H")&& code.equalsIgnoreCase("q2h")){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- /* String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";*/
- String endTime = null;
- String lastDay = null;
- if (timeType == 0){
- lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- endTime = sdf.format(calendar.getTime()) + " 23:59:59";
- }else if ( timeType == 1){
- lastDay = date9;
- endTime = date21;
- }else if (timeType == 2){
- lastDay = date21;
- endTime = date9s;
- }
- Date date2 = sdf1.parse(lastDay);
- Date date3 = sdf1.parse(endTime);
- calendar.setTime(date2);
- for (int i=0;i<11;i++){
- calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+2);
- Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
- System.out.print(sdf1.format(calendar.getTime()));
- if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
- list.add(sdf1.format(calendar.getTime()));
- }
- }
- }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q3h")){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- String endTime = null;
- String lastDay = null;
- if (timeType == 0){
- lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- endTime = sdf.format(calendar.getTime()) + " 23:59:59";
- }else if ( timeType == 1){
- lastDay = date9;
- endTime = date21;
- }else if (timeType == 2){
- lastDay = date21;
- endTime = date9s;
- }
- Date date2 = sdf1.parse(lastDay);
- Date date3 = sdf1.parse(endTime);
- calendar.setTime(date2);
- for (int i=0;i<7;i++){
- calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+3);
- Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
- if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
- list.add(sdf1.format(calendar.getTime()));
- }
- }
- }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q4h")){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- String endTime = null;
- String lastDay = null;
- if (timeType == 0){
- lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- endTime = sdf.format(calendar.getTime()) + " 23:59:59";
- }else if ( timeType == 1){
- lastDay = date9;
- endTime = date21;
- }else if (timeType == 2){
- lastDay = date21;
- endTime = date9s;
- }
- Date date2 = sdf1.parse(lastDay);
- Date date3 = sdf1.parse(endTime);
- calendar.setTime(date2);
- for (int i=0;i<5;i++){
- calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+4);
- Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
- if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
- list.add(sdf1.format(calendar.getTime()));
- }
- }
- }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("qh")){
- Date date1 = sdf.parse(date);
- calendar.setTime(date1);
- //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- String endTime = null;
- String lastDay = null;
- if (timeType == 0){
- lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
- endTime = sdf.format(calendar.getTime()) + " 23:59:59";
- }else if ( timeType == 1){
- lastDay = date9;
- endTime = date21;
- }else if (timeType == 2){
- lastDay = date21;
- endTime = date9s;
- }
- Date date2 = sdf1.parse(lastDay);
- Date date3 = sdf1.parse(endTime);
- calendar.setTime(date2);
- for (int i=0;i<23;i++){
- calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+1);
- Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
- if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
- list.add(sdf1.format(calendar.getTime()));
- }
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_1")){
- String date2 = DateUtil.getWeek(date,"1")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_2")){
- String date2 = DateUtil.getWeek(date,"2")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_3")){
- String date2 = DateUtil.getWeek(date,"3")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_4")){
- String date2 = DateUtil.getWeek(date,"4")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_5")){
- String date2 = DateUtil.getWeek(date,"5")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_6")){
- String date2 = DateUtil.getWeek(date,"6")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_7")){
- String date2 = DateUtil.getWeek(date,"7")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("tiw135")){
- String date2 = DateUtil.getWeek(date,"1")+" 08:00:00";
- String date4 = DateUtil.getWeek(date,"3")+" 08:00:00";
- String date5 = DateUtil.getWeek(date,"5")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- if (date4.compareTo(date3)==1){
- list.add(date2);
- }
- if (date5.compareTo(date3) == 1){
- list.add(date2);
- }
- }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("tiw246")){
- String date2 = DateUtil.getWeek(date,"2")+" 08:00:00";
- String date4 = DateUtil.getWeek(date,"4")+" 08:00:00";
- String date5 = DateUtil.getWeek(date,"6")+" 08:00:00";
- Date date1 = new Date();
- String date3 = sdf1.format(date1);
- if (date2.compareTo(date3)==1){
- list.add(date2);
- }
- if (date4.compareTo(date3)==1){
- list.add(date2);
- }
- if (date5.compareTo(date3) == 1){
- list.add(date2);
- }
- }
- return list;
- }
- public String deleteTemplate(String templateId) {
- Map<String, Object> 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<String, Object> 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<SystemMessageDO> messageList = new ArrayList<>();
- Map<String,String> 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<String,String> 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<String,Object> 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<String, Object> 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<Map<String,Object>> 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<RehabilitationDetailDO> 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> baseTeamMemberDO = baseDoctorTeamMemberDao.findUseDoctorCode(doctor);
- if (baseTeamMemberDO!=null&&baseTeamMemberDO.size()>0){
- teamCode= baseTeamMemberDO.get(0).getTeamCode();
- }
- List<BaseDoctorHospitalDO> 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<Map<String,Object>> listPackage = hibenateUtils.createSQLQuery(packageSql);
- for (Map<String,Object> 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<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
- map.put("itemList",list);
- }
- }
- return ObjEnvelop.getSuccess("操作成功",listPackage);
- }
- public List<Map<String, Object>> 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<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
- return list;
- }
- public List<Map<String,Object>> 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<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
- return list;
- }
- public List<Map<String,Object>> 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<Map<String,Object>> 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<String> 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<RehabilitationTemplateDetailDO> 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<RehabilitationTemplateDetailDO> 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<RehabilitationPlanTemplateDO> 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<TemplateDetailVo> resultList = new ArrayList<>();
- List<RehabilitationTemplateDetailDO> list = templateDetailDao.findTemplateDetailByTemplateId(templateId);
- List<RehabilitationServiceItemDO> itemDOList = serviceItemDao.findList();
- Map<String, List<RehabilitationTemplateDetailDO>> 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<RehabilitationServiceItemDO> findSystemTemplateList(){
- List<RehabilitationServiceItemDO> itemDOList = serviceItemDao.findList();
- return itemDOList;
- }
- public List<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId) {
- for(RehabilitationDetailDO detail : details) {
- /*List<String> 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<RehabilitationDetailDO>)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<RehabilitationDetailDO> updateRehabilitationPlan(String json, BaseDoctorDO doctor,String updateStatus) throws Exception {
- JSONObject object = new JSONObject(json);
- JSONArray array = object.getJSONArray("detail");
- for (int z=0;z<array.length();z++){
- JSONObject jsonObject = array.getJSONObject(z);
- Long timeType = jsonObject.getLong("timeType");
- Frequency frequency = frequencyDao.findByCode(jsonObject.getString("frequencyCode"));
- String executeTimes = jsonObject.getString("executeTimes");
- BaseDoctorDO doctor1 = doctorDao.findById(jsonObject.getString("doctor"));
- if(StringUtils.isNotBlank(executeTimes)) {
- List<String> list = new ArrayList<>();
- String[] executeTime = executeTimes.split(",");
- for (int i = 0; i < executeTime.length; i++) {
- List<String> 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<RehabilitationDetailDO> details = object1.readValue(planDetails, new TypeReference<List<RehabilitationDetailDO>>(){});
- 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<Map<String,Object>> getRehabilitationPlanLog(String planId){
- String sql ="select * from wlyy_patient_rehabilitation_plan_log where plan_id = '"+planId+"' ORDER BY create_time DESC";
- List<Map<String,Object>> 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<PatientSignInfoVO> 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<PatientRehabilitationPlanDO> planList = planListByPatient(patient);
- if(planList!=null&&planList.size()>0){
- json.put("havePlan",1);
- }else{
- json.put("havePlan",0);
- }
- return json;
- }
- public List<PatientSignInfoVO> 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<PatientSignInfoVO> patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientSignInfoVO.class));
- return patientSignInfoVOs;
- }
- /**
- * 根据居民获取康复计划
- * @param patient
- * @return
- */
- public List<PatientRehabilitationPlanDO> planListByPatient(String patient){
- List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patient);
- return list;
- }
- public JSONArray findTemplateDetailInfo(String templateId) throws Exception {
- Map<String, Object> 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<result.length();i++){
- JSONObject obj = result.getJSONObject(i);
- JSONObject reobj = obj.getJSONArray("list").getJSONObject(0);
- if(!reobj.isNull("expense")){
- Integer expense = reobj.getInt("expense");
- obj.put("expense",expense);
- }
- else{
- obj.put("expense",0);
- }
- }
- return rs.getJSONArray("detailModelList");
- }
- throw new Exception("请求获取模板明细列表失败!");
- }
- }
|