PatientController.java 23.6 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
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
package com.lyms.talkonlineweb.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lyms.talkonlineweb.domain.*;
import com.lyms.talkonlineweb.request.PatientInfoRequest;
import com.lyms.talkonlineweb.result.BaseResponse;
import com.lyms.talkonlineweb.result.PatientPcaseResult;
import com.lyms.talkonlineweb.service.*;
import com.lyms.talkonlineweb.util.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

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

@Autowired
private LymsPatientService lymsPatientService;//患者

@Autowired
private LymsPcaseService lymsPcaseService;//病例

@Autowired
private LymsIllnessService lymsIllnessService;//疾病

@Autowired
private LymsTkcardService lymsTkcardService;//问诊记录

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

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

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

@Autowired
private LymsHdepartService lymsHdepartService;//科室服务

@Autowired
private HXService hxService;

//医院
@Autowired
private LymsHospitalService lymsHospitalService;
//医生
@Autowired
private LymsDoctorService lymsDoctorService;
//关注
@Autowired
private LymsAttentionService lymsAttentionService;
@Autowired
private LymsDictService lymsDictService;

/**
* 获取患者列表
*
* @param patientInfo
* @param current
* @param size
* @return
*/
@GetMapping("sltPatientLst")
public BaseResponse sltPatientLst(PatientInfo patientInfo, int current, int size, @RequestParam(required = false) Integer qtype) {
BaseResponse baseResponse = new BaseResponse();
Page<PatientInfo> page = new Page<>(current, size);
QueryWrapper<PatientInfo> queryWrapper = Wrappers.query(patientInfo);
if (Objects.nonNull(qtype) && qtype == 1) {//从小程序购买
queryWrapper.inSql("id", "SELECT t.`pid` FROM lyms_tcard t WHERE t.`fid`=1");
}
if (Objects.nonNull(qtype) && qtype == 2) {//从医院购买
queryWrapper.inSql("id", "SELECT t.`pid` FROM lyms_tcard t WHERE t.`fid`=2");
}
Page<PatientInfo> patientPagePage = patientInfoService.page(page, queryWrapper);
List<PatientInfo> pLst = patientInfoService.list(queryWrapper);
int daiCnt = pLst.parallelStream().mapToInt(PatientInfo::getCcnt).sum();//待使用数量

List<Integer> pids = pLst.parallelStream().map(PatientInfo::getId).collect(Collectors.toList());

LymsTcard tcard = new LymsTcard();
QueryWrapper<LymsTcard> tWrapper = Wrappers.query(tcard);
if (pids.size() == 0) {
pids.add(-1);
}
tWrapper.in("pid", pids);
int sum = lymsTcardService.list(tWrapper).parallelStream().mapToInt(LymsTcard::getCnt).sum();

log.error("统计需要改动数据结构:daiCnt:{} sum:{}", daiCnt, sum);
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(">>>>>>>>>>>>>>>登记病例");
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.toString());
}

Date instDate = new Date();
//需要添加医院购买卡记录
for (int i = 0; i < patient.getCcnt(); i++) {
LymsTcard tcard = new LymsTcard();
tcard.setCnt(1);
tcard.setPcid(pcase.getPcid());
tcard.setPid(patient.getId());
tcard.setFid(2);
tcard.setCreatedby(patient.getCreatedby());
tcard.setCreatedtime(instDate);

lymsTcardService.saveOrUpdate(tcard);
}

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

/**
* 更新患者信息---小程序端使用
*
* @param patient
* @return
*/
@PostMapping("updatePatient")
public BaseResponse updatePatient(@RequestBody LymsPatient patient){
BaseResponse baseResponse=new BaseResponse();
boolean f=false;
if(Objects.nonNull(patient.getId()) ){
patient.setUpdatedtime(new Date());
f=lymsPatientService.saveOrUpdate(patient);
}
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;
}

/**
* 删除患者病例ID
*
* @param pcid
* @return
*/
@GetMapping("delPcase")
public BaseResponse delPcase(int pcid) {
BaseResponse baseResponse = new BaseResponse();
boolean f = lymsPcaseService.removeById(pcid);
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);
LymsPatient patient2=null;
if (dLst.size() > 0) {
patient2 = dLst.get(0);

String jwt = JwtUtils.createJWT("1", patient.getIdno(), Constant.JWT_TTL);
Map<String, Object> map = new HashMap<>();

patient2.setIslogin(1);

if (StringUtils.isEmpty(patient2.getHxid()) || StringUtils.isEmpty(patient2.getOpenid())) {

if (patient2.getHxid() == null) {
JSONObject json = hxService.addUser(patient2.getIdno(), Constant.COMMON_PASSWD, patient2.getPname());
JSONArray rArr = json.getJSONArray("entities");
if (rArr.size() > 0) {
patient2.setHxid(rArr.getJSONObject(0).getString("uuid"));
}
}
if (StringUtils.isEmpty(patient2.getOpenid())) {
patient2.setOpenid(WeiXinUtil.getWxOpenId(patient.getCode()));
}
lymsPatientService.saveOrUpdate(patient2);
}

patient.setPpasswd(null);
map.put("patient", patient2);
map.put("token", jwt);
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;
}

/**
* 查询单个患者信息
*
* @param patientInfo
* @return
*/
@GetMapping("queryPatient")
public BaseResponse queryPatient(PatientInfo patientInfo) {
BaseResponse baseResponse = new BaseResponse();
PatientInfo patientInfo2 = patientInfoService.getOne(Wrappers.query(patientInfo));
baseResponse.setObject(patientInfo2);
return baseResponse;
}


/**
* 传入患者id,获取病历对应的医院列表
*
* @param lymsPcase
* @return
*/
@GetMapping("getPatientHospitals")
public BaseResponse getPatientHospitals(LymsPcase lymsPcase) {
BaseResponse baseResponse = new BaseResponse();
List<LymsPcase> pcases = lymsPcaseService.list(Wrappers.query(lymsPcase));
baseResponse.setObject(pcases);
return baseResponse;
}


/**
* 查询患者在某个医院的详细诊断病历
* 需要传入患者id和医院id
*
* @param pid 患者id
* @param hid 医院id
* @return
*/
@GetMapping("getPatientHospitalPcase")
public BaseResponse getPatientHospitalPcase(int pid, int hid,
@RequestParam(required = false) String keyword) {
BaseResponse baseResponse = new BaseResponse();
Map data = new HashMap(5);
LymsPatient patient = lymsPatientService.getById(pid);
//患者基本信息
data.put("patient", patient);

//医院信息
LymsHospital hospital = lymsHospitalService.getById(pid);
data.put("hospital", hospital);

List<Integer> ilist = new ArrayList<>();
if (StringUtil.isNotEmpty(keyword)) {
LambdaQueryWrapper<LymsIllness> iwrapper = new QueryWrapper().lambda();
iwrapper.like(LymsIllness::getIname, keyword);
List<LymsIllness> illnesses = lymsIllnessService.list(iwrapper);
if (CollectionUtils.isNotEmpty(illnesses)) {
illnesses.stream().forEach(i -> {
ilist.add(i.getPcid());
});
}
}
//查询患者的就诊记录
LambdaQueryWrapper<LymsPcase> wrapper = new QueryWrapper().lambda();
wrapper.eq(LymsPcase::getPid, pid);
wrapper.eq(LymsPcase::getHid, hid);
if (StringUtil.isNotEmpty(keyword)) {
wrapper.and(i -> i.like(LymsPcase::getDname, keyword).or().like(LymsPcase::getDtname, keyword));
if (CollectionUtils.isNotEmpty(ilist)) {
wrapper.or(i -> i.in(LymsPcase::getPcid, ilist));
}
}
wrapper.orderByDesc(LymsPcase::getCreatedtime);
List<LymsPcase> lymsPcaseList = lymsPcaseService.list(wrapper);

List<PatientPcaseResult> pcases = new ArrayList<>();
if (CollectionUtils.isNotEmpty(lymsPcaseList)) {
lymsPcaseList.forEach(destModel -> {
PatientPcaseResult result = new PatientPcaseResult();
result.setPid(destModel.getPid());
result.setDepartName(destModel.getDname());
result.setCardNo(patient.getIdno());
result.setPatientName(patient.getPname());
result.setCcnt(patient.getCcnt());
result.setPhxid(patient.getHxid());
LymsDoctor doctor = lymsDoctorService.getById(destModel.getDtid());
//获得医生职位
result.setDoctorName(doctor.getDname());
LambdaQueryWrapper<LymsDict> wrapperLymsDict = new QueryWrapper().lambda();
wrapperLymsDict.eq(LymsDict::getVtype, 4);
wrapperLymsDict.eq(LymsDict::getCode, doctor.getLvl());
LymsDict dict=lymsDictService.getOne(wrapperLymsDict);
result.setDoctorLvl(dict.getValue());
//获得疾病名称
LambdaQueryWrapper<LymsIllness> wrapperLymsIllness = new QueryWrapper().lambda();
wrapperLymsIllness.eq(LymsIllness::getPcid,destModel.getPcid());
List<LymsIllness> lymsIllnessList=lymsIllnessService.list(wrapperLymsIllness);
String inames="";
for (LymsIllness lymsIllness : lymsIllnessList) {
LambdaQueryWrapper<LymsDict> wrapperLymsDict2 = new QueryWrapper().lambda();
wrapperLymsDict2.eq(LymsDict::getVtype, 3);
wrapperLymsDict2.eq(LymsDict::getCode,lymsIllness.getIid());
LymsDict dict2=lymsDictService.getOne(wrapperLymsDict2);
inames+=dict2.getValue()+",";
}
result.setIname(StringUtil.isNotEmpty(inames)?inames.substring(0, inames.length()-1):"");
//获得医生环信账号
result.setDlogin(doctor.getDlogin());
result.setDhxid(doctor.getHxid());
result.setDtid(destModel.getDtid());
result.setCreatedby(DateUtil.getYyyyMmDdHhMmSs(destModel.getCreatedtime()));
//病例id
result.setPcid(destModel.getPcid());
pcases.add(result);
});
}
data.put("pcases", pcases);

baseResponse.setObject(data);
return baseResponse;
}


/**
* 通过患者id查询患者的基本信息
*
* @param lymsPatient
* @return
*/
@GetMapping("getPatientBaseInfo")
public BaseResponse getPatientBaseInfo(LymsPatient lymsPatient) {

BaseResponse baseResponse = new BaseResponse();

Map data = new HashMap(6);
LymsPatient patients = lymsPatientService.getById(lymsPatient.getId());

//查询患者的就诊记录
LambdaQueryWrapper<LymsPcase> wrapper = new QueryWrapper().lambda();
wrapper.eq(LymsPcase::getPid, lymsPatient.getId());
wrapper.orderByDesc(LymsPcase::getCreatedtime);
List<LymsPcase> lymsPcaseList = lymsPcaseService.list(wrapper);

data.put("pid", patients.getId());
data.put("pname", patients.getPname());
data.put("psex", patients.getSex());
data.put("birth", patients.getBirth());
if (CollectionUtils.isNotEmpty(lymsPcaseList)) {
data.put("mobile", lymsPcaseList.get(0).getMobile());
}
baseResponse.setObject(data);
return baseResponse;
}


/**
* 更新患者信息
*
* @param request
* @return
*/
@PutMapping("updatePatientInfo")
public BaseResponse updatePatientInfo(@RequestBody PatientInfoRequest request) {
BaseResponse baseResponse = new BaseResponse();
LymsPatient patients = lymsPatientService.getById(request.getPid());
patients.setBirth(request.getBirth());
patients.setPname(request.getPname());
patients.setSex(request.getPsex());
lymsPatientService.updateById(patients);

//查询患者的就诊记录
LambdaQueryWrapper<LymsPcase> wrapper = new QueryWrapper().lambda();
wrapper.eq(LymsPcase::getPid, request.getPid());
wrapper.orderByDesc(LymsPcase::getCreatedtime);
List<LymsPcase> lymsPcaseList = lymsPcaseService.list(wrapper);
if (CollectionUtils.isNotEmpty(lymsPcaseList)) {
lymsPcaseList.forEach(lymsPcase -> {
lymsPcase.setMobile(request.getMobile());
lymsPcaseService.updateById(lymsPcase);
});
}
return baseResponse;
}


/**
* 患者的问诊记录接口
*
* @param lymsTkrecord 传入患者id参数
* @return
*/
@GetMapping("getPatienttkrecord")
public BaseResponse getPatienttkrecord(LymsTkrecord lymsTkrecord) {

BaseResponse baseResponse = new BaseResponse();
LymsPatient patients = lymsPatientService.getById(lymsTkrecord.getPid());

//查询患者的就诊记录
LambdaQueryWrapper<LymsTkrecord> wrapper = new QueryWrapper().lambda();
wrapper.eq(LymsTkrecord::getPid, lymsTkrecord.getPid());
wrapper.orderByDesc(LymsTkrecord::getCreatedtime);
List<LymsTkrecord> lymsTkrecords = lymsTkcardService.list(wrapper);
Map param=new HashMap();
param.put("vtype",4);
List<LymsDict> dLst=lymsDictService.listByMap(param);

List<Map> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(lymsTkrecords)) {
for (LymsTkrecord record : lymsTkrecords) {
LymsPcase pcase = lymsPcaseService.getById(record.getPcid());
LymsHospital hospital = lymsHospitalService.getById(pcase.getHid());
LymsDoctor doctor = lymsDoctorService.getById(pcase.getDtid());

Map data = new HashMap(20);
data.put("hospitalName", pcase.getHname());
data.put("hospitalLevel", hospital.getHlevel());
data.put("doctorName", pcase.getDtname());
data.put("departName", pcase.getDname());

data.put("patientName", patients.getPname());

dLst.forEach(dd->{
if(dd.getCode()==doctor.getLvl()){
data.put("doctorLevel", dd.getValue());
}
});

StringBuilder sb = new StringBuilder();
LambdaQueryWrapper<LymsIllness> iwrapper = new QueryWrapper().lambda();
iwrapper.like(LymsIllness::getPcid, pcase.getPcid());
List<LymsIllness> illnesses = lymsIllnessService.list(iwrapper);
if (CollectionUtils.isNotEmpty(illnesses)) {
illnesses.forEach(lymsIllness -> {
sb.append(lymsIllness.getIname());
sb.append(" ");
});
}

data.put("iname", sb.toString());
data.put("createTime", DateUtil.getDateTime(record.getCreatedtime(), DateUtil.YYYY_MM_DD));
data.put("stat", record.getStat());
list.add(data);
}
}
baseResponse.setObject(list);
return baseResponse;
}

/**
* 查询患者关注的医生记录
*
* @param lymsAttention 传入患者id参数
* @return
*/
@GetMapping("getPatientAttentions")
public BaseResponse getPatientAttentions(LymsAttention lymsAttention) {

BaseResponse baseResponse = new BaseResponse();
//查询患者的关注医生记录
LambdaQueryWrapper<LymsAttention> wrapper = new QueryWrapper().lambda();
wrapper.eq(LymsAttention::getPid, lymsAttention.getPid());
wrapper.orderByDesc(LymsAttention::getCreatedtime);
List<LymsAttention> lymsAttentions = lymsAttentionService.list(wrapper);
Map param=new HashMap();
param.put("vtype",4);
List<LymsDict> dLst=lymsDictService.listByMap(param);

List<Map> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(lymsAttentions)) {
for (LymsAttention attention : lymsAttentions) {
LymsDoctor doctor = lymsDoctorService.getById(attention.getDid());
LymsHdepart depart = lymsHdepartService.getById(doctor.getDpid());
LymsHospital hospital = lymsHospitalService.getById(doctor.getHid());
Map data = new HashMap(20);
data.put("doctorName", doctor.getDname());
data.put("departName", depart.getDname());

data.put("doctorImage", doctor.getHeadimg());
data.put("hospitalName", depart.getHname());
data.put("hospitalLevel", hospital.getHlevel());
data.put("doctorDesc", doctor.getIntro());
dLst.forEach(dd->{
if(dd.getCode()==doctor.getLvl()){
data.put("doctorLevel", dd.getValue());
}
});
list.add(data);
}
}
baseResponse.setObject(list);
return baseResponse;
}
/**
* 小程序用户端-登录后显示用户病历所在医院
*
* @param patientId 传入患者id
* @return 医院id和医院名称
*/
@GetMapping("getAppPatientHospital")
public BaseResponse getAppPatientHospital(Integer patientId) {
BaseResponse baseResponse = new BaseResponse();
List<Map<String,String>>patientListMap=lymsPatientService.getAppPatientHospital(patientId);
baseResponse.setObject(patientListMap);
return baseResponse;
}

/**
* 更新患者待用卡数量---小程序端使用
*
* @param patient 患者ID
* @return
*/
@GetMapping("updateCcnt")
public BaseResponse updateCcnt(LymsPatient patient){
BaseResponse baseResponse=new BaseResponse();
boolean f=false;
LymsPatient patient2=lymsPatientService.getById(patient.getId());
if(Objects.nonNull(patient2)){//验证问诊卡次数
int cnt=patient2.getCcnt()-1;
if (cnt < 0) {
baseResponse.setErrorcode(1);
baseResponse.setErrormsg("问诊卡次数错误");
return baseResponse;
}else{
patient.setCcnt(cnt);
}
}
if(Objects.nonNull(patient.getId()) ){
patient.setUpdatedtime(new Date());
f=lymsPatientService.saveOrUpdate(patient);
}
baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

/**
* 患者统计待使用和总量问诊卡信息
* @return
*/
@GetMapping("cardStat")
public BaseResponse cardStat(){
BaseResponse baseResponse = new BaseResponse();
Map<String,Object> rs= lymsTcardService.cardStat();
baseResponse.setObject(rs);
return baseResponse;
}
/**
* 小程序-用户关注医生保存关注记录
* @return
*/
@PostMapping("saveAttention")
public BaseResponse saveAttention(@RequestBody LymsAttention lymsAttention){
BaseResponse baseResponse=new BaseResponse();
try {
lymsAttentionService.save(lymsAttention);
baseResponse.setErrormsg("成功");
} catch (Exception e) {
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
return baseResponse;
}
}