123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921 |
- 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.patient.Message;
- import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
- import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
- import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationOperateRecordsDO;
- import com.yihu.jw.entity.util.TransforSqlUtl;
- import com.yihu.jw.file_upload.FileUploadService;
- import com.yihu.jw.org.dao.BaseOrgDao;
- import com.yihu.jw.patient.dao.BasePatientDao;
- import com.yihu.jw.rehabilitation.RehabilitationOperateRecordsDao;
- import com.yihu.jw.restmodel.iot.common.UploadVO;
- import com.yihu.jw.restmodel.web.Envelop;
- 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.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.FrequencyDao;
- import com.yihu.rehabilitation.dao.PatientRehabilitationPlanDao;
- import com.yihu.rehabilitation.dao.RehabilitationDetailDao;
- import com.yihu.rehabilitation.dao.SignFamilyDao;
- 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.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.*;
- /**
- * 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 MessagesDao 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;
- @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;
- 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");
- BasePatientDO patientDo = null;
- if (!StringUtils.isNoneBlank(patient)){
- BasePatientDO basePatientDO = new BasePatientDO();
- basePatientDO.setName(object.getString("patientName"));
- basePatientDO.setIdcard(object.getString("idCard"));
- basePatientDO.setMobile(object.getString("mobile"));
- patientDo = saveUnSignPatient(basePatientDO);
- }else {
- patientDo = patientDao.findById(patient);
- }
- 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;
- HashSet set = new HashSet();
- for ( RehabilitationDetailDO rehabilitationDetailDO : details) {
- if (!set.contains(rehabilitationDetailDO.getDoctor())) {
- set.add(rehabilitationDetailDO.getDoctor());
- planId = rehabilitationDetailDO.getPlanId();
- Message message = new Message();
- 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+"的康复计划已配置完成,点击查看", "");
- }
- }
- 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 rs = fileUploadService.request(remote_inner_url,new MockMultipartFile(originalFilename,originalFilename,"", ipt),null);
- 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.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";
- Date date6 = DateUtil.strToDateLong(nowDate);
- 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<Message> 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+"康复计划,点击查看原因", "");
- Message 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 Message initMessage(String patientName,String doctor,String doctorName,String sender,String senderName,String title,String content,String relatioenCode,int type){
- Message message = new Message();
- message.setCzrq(new Date());
- message.setCreateTime(new Date());
- message.setContent("您的服务居民"+patientName+",已中止康复计划,点击查看原因。");
- message.setRead(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(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{
- Map<String, Object> param = new HashedMap();
- param.put("planId", planId);
- HttpResponse response = HttpUtils.doGet(specialistUrl + "svr-specialist/getServiceItemsAfterStop", param);
- JSONObject result = new JSONObject(response.getContent());
- JSONObject jsonObject = new JSONObject();
- if(result.getInt("status")!=200){
- throw new Exception("请求微服务失败!");
- }
- if (result.getInt("status")==200){
- jsonObject = result.getJSONObject("obj");
- JSONArray jsonArray = jsonObject.getJSONArray("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_item 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;
- }
- }
|