package com.lyms.talkonlineweb.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyms.talkonlineweb.domain.LymsPatient;
import com.lyms.talkonlineweb.service.LymsPatientService;
import com.lyms.talkonlineweb.mapper.LymsPatientMapper;
import com.lyms.talkonlineweb.util.Constant;
import com.lyms.talkonlineweb.util.HXService;
import com.lyms.talkonlineweb.util.JwtUtils;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
*
*/
@Service
public class LymsPatientServiceImpl extends ServiceImpl<LymsPatientMapper, LymsPatient>
implements LymsPatientService{
@Autowired
private LymsPatientMapper lymsPatientMapper;
@Autowired
private HXService hxService;
@Override
public List<Map<String,String>> getAppPatientHospital(Integer patientId) {
return lymsPatientMapper.getAppPatientHospital(patientId);
}
@Override
public List<Map> getPatient(QueryWrapper queryWrapper) {
return lymsPatientMapper.getPatient(queryWrapper);
}
@Override
public List<Map<String,Object>> getPcInfoList() {
return lymsPatientMapper.getPcInfoList();
}
@Override
public LymsPatient addPatientHxId(LymsPatient patient) {
JSONObject hxUserJSON = hxService.getUser(patient.getIdno());
if(hxUserJSON != null && hxUserJSON.getJSONArray("entities") != null && hxUserJSON.getJSONArray("entities").size() > 0){
patient.setHxid(hxUserJSON.getJSONArray("entities").getJSONObject(0).getString("uuid"));
updateById(patient);
}else{
JSONObject json = hxService.addUser(patient.getIdno(), Constant.COMMON_PASSWD, patient.getPname());
JSONArray rArr = json.getJSONArray("entities");
if (rArr.size() > 0) {
patient.setHxid(rArr.getJSONObject(0).getString("uuid"));
updateById(patient);
}
}
return patient;
}
@Override
public LymsPatient getPatientByToken(String token) {
Claims claims = null;
try {
claims = JwtUtils.parseJWT(token);
} catch (Exception e) {
log.error("根据token获取信息异常",e);
}
String idno = claims.getSubject();
QueryWrapper<LymsPatient> query = new QueryWrapper<>();
query.eq("idno",idno);
List<LymsPatient> list = this.list(query);
if(CollectionUtils.isNotEmpty(list)){
return list.get(0);
}
throw new RuntimeException("查询患者信息异常");
}
}