You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
392 lines
16 KiB
392 lines
16 KiB
package com.ynxbd.common.service;
|
|
|
|
import com.ynxbd.common.bean.Dept;
|
|
import com.ynxbd.common.bean.Doctor;
|
|
import com.ynxbd.common.bean.Patient;
|
|
import com.ynxbd.common.bean.ai.AIDept;
|
|
import com.ynxbd.common.bean.ai.AIDoctor;
|
|
import com.ynxbd.common.bean.ai.AIDoctorSchedule;
|
|
import com.ynxbd.common.bean.ai.AIPatient;
|
|
import com.ynxbd.common.dao.RegisterDao;
|
|
import com.ynxbd.common.dao.his.HisRegisterDao;
|
|
import com.ynxbd.common.helper.common.DateHelper;
|
|
import com.ynxbd.common.helper.common.IDNumberHelper;
|
|
import com.ynxbd.common.helper.common.JsonHelper;
|
|
import com.ynxbd.common.helper.common.URLHelper;
|
|
import com.ynxbd.common.result.Result;
|
|
import com.ynxbd.common.result.ResultEnum;
|
|
import com.ynxbd.wx.config.AIGuidanceConfig;
|
|
import com.ynxbd.wx.config.WeChatConfig;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@Slf4j
|
|
public class AIGuidanceService {
|
|
|
|
/**
|
|
* 查询医院详细信息
|
|
*
|
|
* @param hosId 医院id
|
|
* @return result
|
|
*/
|
|
public Result getHospDetail(String hosId) {
|
|
log.info("[智能导诊]查询医院详细信息 hosId={}", hosId);
|
|
if (ObjectUtils.isEmpty(hosId)) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) {
|
|
return Result.success(ResultEnum.AI_SUCCESS, resultList);
|
|
}
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("hosId", AIGuidanceConfig.HOS_ID);
|
|
map.put("branchId", ""); // 如果有分院,则填写分院Id, 主院的分院Id为hosId本身
|
|
map.put("hosName", AIGuidanceConfig.HOS_NAME); // 如果是分院,则填写分院名称,否则填写主院名称
|
|
map.put("hosIntro", AIGuidanceConfig.HOS_INTRO);
|
|
map.put("hosLevel", AIGuidanceConfig.HOS_LEVEL);
|
|
map.put("hosAddress", AIGuidanceConfig.HOS_ADDRESS);
|
|
map.put("hosTelephone", AIGuidanceConfig.HOS_TELEPHONE);
|
|
map.put("hosImage", WeChatConfig.getBaseURL(true) + "config/logo.png");
|
|
map.put("appId", WeChatConfig.APP_ID); // 公众号appid
|
|
map.put("hosUrl", WeChatConfig.getWebReqURL(true) + "app.html"); // 公众号appid
|
|
map.put("originAppid", ""); // 小程序原始id
|
|
|
|
map.put("location", ""); // 经纬度,逗号分割
|
|
map.put("miniAppId", ""); // 经纬度,逗号分割
|
|
map.put("isHTML", false); // 介绍信息是否为HTML 文档
|
|
|
|
resultList.add(map);
|
|
return Result.success(ResultEnum.AI_SUCCESS, resultList);
|
|
}
|
|
|
|
/**
|
|
* 科室列表
|
|
*
|
|
* @param hosId 医院id
|
|
* @param branchId 分院id
|
|
* @return list
|
|
*/
|
|
public Result getDeptList(String hosId, String branchId) {
|
|
log.info("[智能导诊]科室列表查询 hosId={}, branchId={}", hosId, branchId);
|
|
if (ObjectUtils.isEmpty(hosId)) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
List<AIDept> dataList = new ArrayList<>();
|
|
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) { // 医院id校验
|
|
log.warn("[智能导诊]科室列表查询-hosId不匹配");
|
|
return Result.success(ResultEnum.AI_SUCCESS, dataList);
|
|
}
|
|
|
|
List<Dept> deptList;
|
|
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) { // 分时段
|
|
String curDate = DateHelper.getCurDate();
|
|
deptList = new HisRegisterDao().getTimeDeptList(curDate, DateHelper.getMoveDate(curDate, 7), "");
|
|
} else {
|
|
deptList = new RegService().queryHisRegDeptList();
|
|
}
|
|
|
|
String webReqURL = WeChatConfig.getWebReqURL(true);
|
|
|
|
AIDept addItem;
|
|
List<Dept> children;
|
|
for (Dept dept : deptList) {
|
|
addItem = createAIDept(webReqURL, dept);
|
|
if (addItem == null) {
|
|
continue;
|
|
}
|
|
dataList.add(addItem);
|
|
|
|
children = dept.getChildren();
|
|
if (children != null && !children.isEmpty()) {
|
|
for (Dept childDept : children) {
|
|
childDept.setSubDeptCode(childDept.getDeptCode());
|
|
childDept.setDeptCode(dept.getDeptCode());
|
|
addItem = createAIDept(webReqURL, childDept);
|
|
if (addItem == null) {
|
|
continue;
|
|
}
|
|
dataList.add(addItem);
|
|
}
|
|
}
|
|
}
|
|
return Result.success(ResultEnum.AI_SUCCESS, dataList);
|
|
}
|
|
|
|
|
|
private AIDept createAIDept(String webReqURL, Dept dept) {
|
|
AIDept item = new AIDept();
|
|
String subDeptCode = dept.getSubDeptCode();
|
|
boolean isSubDept = !ObjectUtils.isEmpty(subDeptCode);
|
|
|
|
String deptName = dept.getDeptName();
|
|
if (!ObjectUtils.isEmpty(dept.getDeptAlias())) {
|
|
deptName = dept.getDeptAlias();
|
|
}
|
|
item.setDeptId(dept.getDeptCode());
|
|
item.setDeptName(deptName);
|
|
item.setDeptIntro(dept.getDescription() == null ? "" : dept.getDescription()); // 科室简介
|
|
item.setDeptAddr(dept.getAddress() == null ? "" : dept.getAddress()); // 科室地址
|
|
item.setLevel(2);
|
|
item.setParentDeptId(isSubDept ? dept.getDeptCode() : "");
|
|
item.setFeatureFlag(0); // 是否特色科室
|
|
item.setTreatrange(""); // 诊疗范围
|
|
item.setIsHTML(true); // 介绍信息是否为HTML 文档
|
|
|
|
item.setDeptMiniWxUrl("");
|
|
item.setDeptMiniAlipayUrl("");
|
|
item.setDeptLifeAlipayUrl("");
|
|
item.setDeptEmbedAlipayUrl("");
|
|
|
|
try {
|
|
subDeptCode = isSubDept ? ("&subDeptCode=" + subDeptCode) : "";
|
|
item.setDeptUrl(webReqURL + "reg-reserve.html#/reg-doctor?deptCode=" + dept.getDeptCode() + "&deptName=" + URLHelper.encodeURL(deptName) + subDeptCode + "&hospitalArea=");
|
|
} catch (Exception e) {
|
|
log.error("[智能导诊]科室链接异常:{}", e.getMessage());
|
|
return null;
|
|
}
|
|
return item;
|
|
}
|
|
|
|
|
|
/**
|
|
* [医生列表]
|
|
*
|
|
* @param hosId 医院id
|
|
* @param branchId 分院id
|
|
* @param deptId 科室id
|
|
* @return list
|
|
*/
|
|
public Result getDoctorList(String hosId, String branchId, String deptId) {
|
|
log.info("[智能导诊]医生列表查询 hosId={}, branchId={}, deptId={}", hosId, branchId, deptId);
|
|
if (ObjectUtils.isEmpty(hosId) || ObjectUtils.isEmpty(deptId)) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) { // 医院id校验
|
|
log.warn("[智能导诊]医生列表查询-hosId不匹配");
|
|
return Result.success(ResultEnum.AI_SUCCESS, new ArrayList<>());
|
|
}
|
|
|
|
HisRegisterDao hisRegisterDao = new HisRegisterDao();
|
|
|
|
List<Doctor> doctorList;
|
|
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) { // 分时段
|
|
String curDate = DateHelper.getCurDate();
|
|
doctorList = hisRegisterDao.queryHisTimeRegDoctorList(deptId, branchId, curDate, DateHelper.getMoveDate(curDate, 7));
|
|
} else {
|
|
// 注意:需先查询今日挂号
|
|
doctorList = hisRegisterDao.queryHisRegTodayDoctorList(deptId, null); // 今日挂号
|
|
List<Doctor> resDoctorList = hisRegisterDao.queryHisResRegDoctorList(deptId, null); // 预约挂号
|
|
for (Doctor doctor : resDoctorList) {
|
|
Doctor findItem = doctorList.stream().filter(o -> o.getDoctCode().equals(doctor.getDoctCode())).findFirst().orElse(null);
|
|
if (findItem == null) {
|
|
doctorList.add(doctor);
|
|
}
|
|
}
|
|
}
|
|
|
|
List<AIDoctor> dataList = aiDoctorHandle(doctorList);
|
|
return Result.success(ResultEnum.AI_SUCCESS, dataList);
|
|
}
|
|
|
|
|
|
public List<AIDoctor> aiDoctorHandle(List<Doctor> doctorList) {
|
|
List<AIDoctor> resultList = new ArrayList<>();
|
|
String webReqURL = WeChatConfig.getWebReqURL(true);
|
|
|
|
doctorList = new DoctorService().doctorListFilter(doctorList);
|
|
|
|
RegisterDao registerDao = new RegisterDao();
|
|
List<Dept> dbDeptList = registerDao.selectDeptList();
|
|
|
|
String domain = WeChatConfig.getDomain(true);
|
|
String deptName, deptCode, headImg, doctCode;
|
|
Dept dept;
|
|
AIDoctor item;
|
|
for (Doctor doctor : doctorList) {
|
|
item = new AIDoctor();
|
|
doctCode = doctor.getDoctCode();
|
|
if (ObjectUtils.isEmpty(doctCode)) {
|
|
continue;
|
|
}
|
|
doctCode = doctCode.trim();
|
|
if ("*".equals(doctCode)) { // 任意医生
|
|
item.setDoctorId("0");
|
|
doctCode = "0";
|
|
item.setDoctorSex(1);
|
|
} else {
|
|
int doctorSex = 1;
|
|
if ("2".equals(doctor.getGenderCode())) {
|
|
doctorSex = 2;
|
|
}
|
|
item.setDoctorSex(doctorSex);
|
|
}
|
|
|
|
deptCode = doctor.getDeptCode();
|
|
deptName = doctor.getDeptName();
|
|
item.setDoctorId(doctCode);
|
|
item.setDoctorName(doctor.getDoctName());
|
|
item.setDoctorJobTitle(doctor.getTitle() == null ? "" : doctor.getTitle()); // 职称
|
|
item.setDoctorGoodat(doctor.getSkill() == null ? "" : doctor.getSkill()); // 擅长
|
|
item.setDoctorIntro(ObjectUtils.isEmpty(doctor.getDescription()) ? "暂无介绍" : doctor.getDescription()); // 介绍
|
|
headImg = doctor.getHeadImg();
|
|
if (headImg != null && !ObjectUtils.isEmpty(headImg.trim())) {
|
|
if (!headImg.contains("data:image/")) { // 不是base64
|
|
item.setDoctorImage(domain + headImg); // 头像
|
|
}
|
|
}
|
|
item.setExtraData("{}"); // 额外信息
|
|
item.setIsHTML(true);
|
|
item.setDoctorMiniWxUrl("");
|
|
item.setDoctorMiniAlipayUrl("");
|
|
item.setDoctorLifeAlipayUrl("");
|
|
item.setDoctorEmbedAlipayUrl("");
|
|
|
|
dept = registerDao.deptFilter(dbDeptList, deptCode, deptName, null, null);
|
|
if (!ObjectUtils.isEmpty(dept.getDeptAlias())) {
|
|
deptName = dept.getDeptAlias();
|
|
}
|
|
|
|
try {
|
|
//reg-doct-source?date=2026-03-02&deptCode=0501&doctCode=1477&subDeptCode=0001&deptName=%25E5%25A6%2587%25E7%25A7%2591-%25E5%25A6%2587%25E7%25A7%2591%25E6%2599%25AE%25E9%2580%259A%25E9%2597%25A8%25E8%25AF%258A&doctName=%25E6%2598%258E%25E6%25BB%25A1%25E6%25B1%259F&hospitalArea=
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("date", DateHelper.getCurDate());
|
|
map.put("deptCode", deptCode);
|
|
map.put("deptName", URLHelper.encodeURL(deptName));
|
|
map.put("doctName", URLHelper.encodeURL(doctor.getDoctName()));
|
|
map.put("doctCode", doctor.getDoctCode());
|
|
map.put("subDeptCode", "");
|
|
map.put("hospitalArea", "");
|
|
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) {
|
|
item.setDoctorUrl(webReqURL + "reg-reserve.html#/reg-doct-source" + URLHelper.mapParamsToUrl(map, true));
|
|
} else {
|
|
item.setDoctorUrl(webReqURL + "reg-reserve.html#/reg-doctor" + URLHelper.mapParamsToUrl(map, true));
|
|
}
|
|
} catch (Exception e) {
|
|
log.error("[智能导诊]医生链接异常:{}", e.getMessage());
|
|
continue;
|
|
}
|
|
resultList.add(item);
|
|
}
|
|
return resultList;
|
|
}
|
|
|
|
/**
|
|
* 4.1.5 查询就诊人列表
|
|
*
|
|
* @param patientId 患者id
|
|
* @return map
|
|
*/
|
|
public Result getPatientCardList(String patientId, String hosId, String branchId) {
|
|
List<AIPatient> cardList = new ArrayList<>();
|
|
Map<String, Object> resp = new HashMap<>();
|
|
resp.put("hospitalId", AIGuidanceConfig.HOS_ID);
|
|
resp.put("cardList", cardList);
|
|
|
|
if (!hosId.equals(AIGuidanceConfig.HOS_ID)) { // 医院id校验
|
|
log.warn("[智能导诊]查询就诊人列表-hosId不匹配");
|
|
return Result.success(ResultEnum.AI_SUCCESS, resp);
|
|
}
|
|
|
|
Patient patient = new PatientService().queryOnePatientByPatientId(patientId);
|
|
if (patient == null) {
|
|
return Result.success(ResultEnum.AI_SUCCESS, resp);
|
|
}
|
|
|
|
String birthday = patient.getBirthday();
|
|
String idCardNo = patient.getIdCardNo();
|
|
if ((ObjectUtils.isEmpty(birthday) || birthday.length() != 10) && !ObjectUtils.isEmpty(idCardNo)) {
|
|
birthday = IDNumberHelper.getBirthday(idCardNo);
|
|
}
|
|
if (birthday == null) {
|
|
return Result.success(ResultEnum.AI_SUCCESS, resp);
|
|
}
|
|
|
|
AIPatient item = new AIPatient();
|
|
item.setName(patient.getName());
|
|
item.setGender("女".equals(patient.getSex()) ? "女" : "男"); // 防空->默认男
|
|
item.setEcardNo(patientId);
|
|
item.setBirthday(birthday);
|
|
cardList.add(item);
|
|
|
|
resp.put("cardList", cardList);
|
|
return Result.success(ResultEnum.AI_SUCCESS, resp);
|
|
}
|
|
|
|
|
|
/**
|
|
* 4.1.9 获取医生号源排班信息(必选)
|
|
*
|
|
*/
|
|
public Result getDoctorSchedule(String hosId, String branchId, String doctorsJson) {
|
|
List<AIDoctorSchedule> doctors = new ArrayList<>();
|
|
|
|
if (ObjectUtils.isEmpty(doctors)) {
|
|
return Result.success(ResultEnum.AI_SUCCESS, doctors);
|
|
}
|
|
List<AIDoctorSchedule> doctorScheduleList = JsonHelper.parseArray(doctorsJson, AIDoctorSchedule.class);
|
|
if (doctorScheduleList.isEmpty()) {
|
|
return Result.success(ResultEnum.AI_SUCCESS, doctors);
|
|
}
|
|
|
|
List<Doctor> regDoctorList = new ArrayList<>();
|
|
List<Doctor> hisDoctorList;
|
|
HisRegisterDao hisRegisterDao = new HisRegisterDao();
|
|
for (AIDoctorSchedule aiDoctorSchedule : doctorScheduleList) {
|
|
String departmentId = aiDoctorSchedule.getDepartmentId();
|
|
if (ObjectUtils.isEmpty(departmentId)) {
|
|
continue;
|
|
}
|
|
|
|
if (AIGuidanceConfig.IS_SPLIT_TIME_REG) { // 分时段
|
|
String curDate = DateHelper.getCurDate();
|
|
hisDoctorList = hisRegisterDao.queryHisTimeRegDoctorList(departmentId, branchId, curDate, DateHelper.getMoveDate(curDate, 7));
|
|
} else {
|
|
hisDoctorList = hisRegisterDao.queryHisRegTodayDoctorList(departmentId, null);
|
|
List<Doctor> resDoctorList = hisRegisterDao.queryHisResRegDoctorList(departmentId, null);
|
|
for (Doctor doctor : resDoctorList) {
|
|
Doctor findItem = hisDoctorList.stream().filter(o -> o.getDoctCode().equals(doctor.getDoctCode())).findFirst().orElse(null);
|
|
if (findItem == null) {
|
|
hisDoctorList.add(doctor);
|
|
}
|
|
}
|
|
}
|
|
regDoctorList.addAll(hisDoctorList);
|
|
}
|
|
|
|
regDoctorList = new DoctorService().doctorListFilter(regDoctorList);
|
|
|
|
String domain = WeChatConfig.getDomain(true);
|
|
|
|
AIDoctorSchedule item;
|
|
String headImg;
|
|
for (Doctor doctor : regDoctorList) {
|
|
item = new AIDoctorSchedule();
|
|
item.setDocId(doctor.getDoctCode());
|
|
item.setName(doctor.getDoctName());
|
|
item.setHosId(AIGuidanceConfig.HOS_ID);
|
|
item.setDepartmentId(doctor.getDeptCode());
|
|
item.setDoctorLevel("");
|
|
item.setDescription(ObjectUtils.isEmpty(doctor.getDescription()) ? "暂无介绍" : doctor.getDescription());
|
|
headImg = doctor.getHeadImg();
|
|
if (headImg != null && !ObjectUtils.isEmpty(headImg.trim())) {
|
|
if (!headImg.contains("data:image/")) { // 不是base64
|
|
item.setIconURL(domain + headImg); // 头像
|
|
}
|
|
}
|
|
|
|
item.setUrl(""); // 挂号链接
|
|
|
|
// item.sets
|
|
doctors.add(item);
|
|
}
|
|
return Result.success(ResultEnum.AI_SUCCESS, doctors);
|
|
}
|
|
}
|
|
|