PatientController.java 5.82 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
package com.lyms.talkonlineweb.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyms.talkonlineweb.domain.*;
import com.lyms.talkonlineweb.result.BaseResponse;
import com.lyms.talkonlineweb.service.*;
import com.lyms.talkonlineweb.util.Constant;
import com.lyms.talkonlineweb.util.JwtUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 患者管理
*/
@RestController
@RequestMapping("pat")
@Log4j2
public class PatientController {

@Autowired
private LymsPatientService lymsPatientService;//患者

@Autowired
private LymsPcaseService lymsPcaseService;//病例

@Autowired
private LymsIllnessService lymsIllnessService;//疾病

@Autowired
private PatientInfoService patientInfoService;//患者视图

@Autowired
private LymsTcardService lymsTcardService;//问诊卡信息

@Autowired
private LymsChatroomService lymsChatroomService;//聊天室

@Autowired
private LymsLogsService lymsLogsService;//日志记录


/**
* 获取患者列表
* @param patientInfo
* @param current
* @param size
* @return
*/
@GetMapping("sltPatientLst")
public BaseResponse sltPatientLst(PatientInfo patientInfo, int current, int size){
BaseResponse baseResponse=new BaseResponse();
Page<PatientInfo> page=new Page<>(current,size);
Page<PatientInfo> patientPagePage=patientInfoService.page(page, Wrappers.query(patientInfo));

baseResponse.setObject(patientPagePage);

return baseResponse;
}

/**
* 保存或更新患者信息
* @param patient
* @return
*/
@PostMapping("savePatient")
public BaseResponse savePatient(@Validated LymsPatient patient, BindingResult result, LymsPcase pcase, String illness){
BaseResponse baseResponse=new BaseResponse();
log.info(">>>>>>>>>>>>>>>登记病例");
log.info(">>>>>>>>>>>>>>>登记病例");
baseResponse.setErrormsg("");
LymsPatient patient2=lymsPatientService.getOne(Wrappers.query(patient).eq("idno",patient.getIdno()));
if(patient2==null){
patient.setCreatedtime(new Date());
}else{
patient.setId(patient2.getId());
patient.setUpdatedtime(new Date());
}

if(result.hasErrors()){
baseResponse.setErrorcode(1);
result.getAllErrors().forEach(e->{
baseResponse.setErrormsg(baseResponse.getErrormsg()+e.getDefaultMessage());
});
baseResponse.setErrorcode(1);
return baseResponse;
}

boolean f=lymsPatientService.saveOrUpdate(patient);

// 添加病例
pcase.setCreatedby(patient.getCreatedby());
pcase.setPid(patient.getId());
pcase.setCreatedtime(new Date());
f=lymsPcaseService.saveOrUpdate(pcase);
String[] iArr=illness.split(",");

log.info(patient);
log.info(pcase);

Map param=new HashMap();

for (int i = 0; i < iArr.length; i++) {
LymsIllness ness=new LymsIllness();
ness.setCreatedby(patient.getCreatedby());
ness.setPcid(pcase.getPcid());
ness.setIid(Integer.parseInt(iArr[i]));
ness.setCreatedtime(new Date());
param.clear();
param.put("pcid",pcase.getPcid());
param.put("iid",iArr[i]);
List<LymsIllness> iLst=lymsIllnessService.listByMap(param);
if(iLst.size()>0){
ness.setId(iLst.get(0).getId());
}
f=lymsIllnessService.saveOrUpdate(ness);
log.info(ness);
}

//需要添加医院购买卡记录
LymsTcard tcard=new LymsTcard();
tcard.setCnt(patient.getCcnt());
tcard.setPcid(pcase.getPcid());
tcard.setPid(patient.getId());
tcard.setFid(2);

lymsTcardService.saveOrUpdate(tcard);

baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

/**
* 删除患者
* @param id
* @return
*/
@GetMapping("delPatient")
public BaseResponse delPatient(int id){
BaseResponse baseResponse=new BaseResponse();
boolean f=lymsPatientService.removeById(id);
baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

/**
* 患者登录
* @param patient
* @return
*/
@PostMapping("loginPatient")
public BaseResponse loginPatient(@RequestBody LymsPatient patient){
BaseResponse baseResponse=new BaseResponse();
List<LymsPatient> dLst=lymsPatientService.list(Wrappers.query(patient));
baseResponse.setErrorcode(1);
if (dLst.size()>0) {
patient=dLst.get(0);
patient.setPpasswd(null);
baseResponse.setObject(patient);
String jwt = JwtUtils.createJWT("1", patient.getIdno(), Constant.JWT_TTL);
Map<String,Object> map=new HashMap<>();
map.put("patient",patient);
map.put("token",jwt);
patient.setIslogin(1);
lymsPatientService.update().update(patient);
baseResponse.setErrorcode(0);
baseResponse.setObject(map);
LymsLogs logEntity=new LymsLogs();
logEntity.setFunc("loginPatient");
logEntity.setLogDate(new Date());
logEntity.setMessage(String.format("login:%s name:%s",patient.getIdno(),patient.getPname()));
lymsLogsService.save(logEntity);
}
return baseResponse;
}

}