微信后端代码
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.

553 lines
22 KiB

package com.ynxbd.common.action;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ynxbd.ali.helper.AliUploadHelper;
import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.Dept;
import com.ynxbd.common.bean.Doctor;
import com.ynxbd.common.bean.enums.MerchantEnum;
import com.ynxbd.common.bean.pay.Register;
import com.ynxbd.common.dao.RegisterDao;
import com.ynxbd.common.dao.his.HisRegisterDao;
import com.ynxbd.common.helper.common.DateHelper;
import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.service.DoctorService;
import com.ynxbd.common.service.RegService;
import com.ynxbd.wx.wxfactory.ReqParamHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author wsq
* @Date 2020/10/27 17:13
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserve
*/
@Slf4j
@Namespace("/register")
public class RegisterAction extends BaseAction {
/**
* [推送] 获取预约今日的所有患者openId
*
* @return openId列表
*/
@Action("getTodayRegOpenId")
public Result getTodayRegOpenId() {
return Result.success(new RegisterDao().selectTodayRegisterOpenId());
}
/**
* [科室]获取科室信息
*/
@Action("getDeptInfo")
public Result getDeptInfo(String deptCode) {
log.info("[科室]获取科室信息 deptCode={}", deptCode);
if (deptCode == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
Dept dept = new RegisterDao().selectDeptByDeptCode(deptCode);
if (dept == null) {
return Result.error(ResultEnum.DATA_NOT_FOUND);
}
return Result.success(dept);
}
/**
* [医生]查询医生信息
*/
@Action("getDoctorInfo")
public Result getDoctorInfo(String doctCode) {
log.info("[医生]查询医生信息 doctCode={}", doctCode);
if (doctCode == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
Doctor doctor = new RegisterDao().selectDoctorByDoctCode(doctCode);
if (doctor == null) {
return Result.error(ResultEnum.DATA_NOT_FOUND);
}
new DoctorService().docStateHandle(doctor, doctor);
return Result.success(doctor);
}
/**
* [分时段挂号]查询科室列表
*
* @return 科室列表
*/
@Action("getTimeDeptList")
public Result getTimeDeptList(String merCode, String begDate, String endDate, String deptCode) {
log.info("[分时段挂号]查询科室列表 begDate={}, endDate={}", begDate, endDate);
if (begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Dept> deptList = new HisRegisterDao().getTimeDeptList(begDate, endDate, deptCode);
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(merCode);
if (MerchantEnum.ALI.equals(merchantEnum)) {
AliUploadHelper.uploadDept(deptList, true);
}
return Result.success(deptList);
}
/**
* [挂号]查询科室列表
*
* @param isReserve 是否为预约挂号 { true:预约挂号; false:今日挂号 }
* @param hasSourcesFlag 有号源标识 { 1:仅返回有号源科室; 0:有无号源科室都返回默认值}
* @param isDeptTypeGroup 是否按deptType分组
*/
@Action("getRegDeptList")
public Result getRegDeptList(String merCode, Boolean isReserve, String hasSourcesFlag, Boolean isDeptTypeGroup) {
log.info("[挂号]查询科室列表 isReserve={}, hasSourcesFlag={}, isDeptTypeGroup={}", isReserve, hasSourcesFlag, isDeptTypeGroup);
if (isDeptTypeGroup == null) {
isDeptTypeGroup = false;
}
if (isReserve == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
log.info("[{}挂号] 获取科室列表", isReserve ? "预约" : "今日");
HisRegisterDao hisRegisterDao = new HisRegisterDao();
List<Dept> deptList = isReserve
? hisRegisterDao.getRegResDeptList()
: hisRegisterDao.getRegTodayDeptList(hasSourcesFlag);
if (!isDeptTypeGroup) { // 不按deptType分组
return Result.success(deptList);
}
List<Dept> resultList = new ArrayList<>();
List<Dept> deptTypeList = new ArrayList<>();
for (Dept dept : deptList) {
if (!ObjectUtils.isEmpty(dept.getDeptTypeCode())) {
deptTypeList.add(dept);
} else {
resultList.add(dept);
}
}
Map<String, List<Dept>> stringListMap = deptTypeList.stream().collect(Collectors.groupingBy(Dept::getDeptTypeCode));
Dept dept;
String deptTypeName;
List<Dept> groupList;
for (Map.Entry<String, List<Dept>> entry : stringListMap.entrySet()) {
groupList = entry.getValue();
dept = groupList.get(0);
deptTypeName = dept.getDeptTypeName();
if (ObjectUtils.isEmpty(deptTypeName)) {
deptTypeName = groupList.stream().map(Dept::getDeptName).collect(Collectors.joining("、"));
}
dept.setDeptName(deptTypeName);
dept.setDeptCode(groupList.stream().map(Dept::getDeptCode).collect(Collectors.joining(",")));
resultList.add(dept);
}
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(merCode);
if (MerchantEnum.ALI.equals(merchantEnum)) {
AliUploadHelper.uploadDept(resultList, isReserve);
}
return Result.success(resultList);
}
/**
* [挂号]查询科室的下的医生列表
*/
@Action("getRegDoctorList")
public Result getRegDoctorList(String regDate, String deptCode, String timeInterval) {
if (deptCode == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
log.info("[{}挂号] 查询科室的下的医生列表 deptCode={}, regDate={}, timeInterval={}", (regDate == null ? "现场" : "预约"), deptCode, regDate, timeInterval);
HisRegisterDao hisRegisterDao = new HisRegisterDao();
List<Doctor> doctorList = new ArrayList<>();
for (String code : deptCode.split(",")) {
doctorList.addAll((regDate == null)
? hisRegisterDao.getRegTodayDoctorList(code, timeInterval)
: hisRegisterDao.getRegReserveDoctorList(code, regDate)
);
}
doctorList = new DoctorService().docListHandle(doctorList);
return Result.success(doctorList);
}
/**
* [预约挂号]获取预约记录
*/
@Action("getReserveHistory")
public Result getReserveHistory(String begDate, String endDate, String patientId) {
log.info("[预约挂号]查询挂号记录 patientId={}, begDate={},endDate={}", patientId, begDate, endDate);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Register> resultList = new HisRegisterDao().getRegReserveHistory(patientId, null);
return Result.success(resultList);
}
/**
* [挂号]查询挂号记录
*/
@Action("getSiteHistory")
public Result getSiteHistory(String begDate, String endDate, String patientId) {
try {
log.info("[挂号]查询挂号记录 patientId={}, begDate={},endDate={}", patientId, begDate, endDate);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
patientId = getDecodeString(patientId);
List<Register> regRecords = new RegService().getHisRegRecords(patientId, begDate, endDate);
return Result.success(regRecords);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* [挂号]查询挂号历史
*/
@Action("getHisRegRecords")
public Result getRegHistory(String begDate, String endDate, String patientId) {
try {
log.info("[挂号]查询挂号记录 patientId={}, begDate={},endDate={}", patientId, begDate, endDate);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
patientId = getDecodeString(patientId);
List<Register> regRecords = new RegService().getHisRegRecords(patientId, begDate, endDate);
return Result.success(regRecords);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* [预约挂号]获取预约记录
*/
@Action("getHisRegReserveRecords")
public Result getHisRegReserveRecords(String begDate, String endDate, String patientId) {
log.info("[预约挂号]查询预约记录 patientId={}, begDate={},endDate={}", patientId, begDate, endDate);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Register> dataList = new RegService().getHisRegReserveRecords(patientId, null);
return Result.success(dataList);
}
/**
* [挂号]查询某天某个科室某个类型的号源是否被占用
*/
@Action("hasReg")
public Result hasReg(String regDate, String deptCode, String patientId) {
log.info("[挂号]查询号源是否被占用regDate={}, deptCode={}, patientId={}", regDate, deptCode, patientId);
if (regDate == null || deptCode == null || patientId == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
if (new RegisterDao().hasReg(patientId, regDate, deptCode)) {
log.info("[挂号]同一天,同一科室,已挂过号");
return Result.error(ResultEnum.REG_TODAY_HAS);
}
return Result.success();
}
/**
* [分时段挂号]查询医生列表
*
* @return 医生列表
*/
@Action("getTimeDoctorList")
public Result getTimeDoctorList(String begDate, String endDate, String deptCode, String subDeptCode) {
log.info("[分时段挂号]查询医生列表 begDate={}, endDate={}, deptCode={}, subDeptCode={}", begDate, endDate, deptCode, subDeptCode);
if (deptCode == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Doctor> doctorList = new HisRegisterDao().getTimeDoctorList(deptCode, subDeptCode, begDate, endDate);
doctorList = new DoctorService().docListHandle(doctorList);
return Result.success(doctorList);
}
/**
* [分时段挂号]查询号源
*
* @return 号源
*/
@Action("getTimeSourceList")
public Result getTimeSourceList(String begDate, String endDate, String deptCode, String doctCode, String subDeptCode) {
log.info("[分时段挂号]查询号源 begDate={}, endDate={}, deptCode={}, subDeptCode={}, doctCode={}", begDate, endDate, deptCode, subDeptCode, doctCode);
if (deptCode == null || doctCode == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Map<Object, Object>> dataList = new HisRegisterDao().getRegTimeSource(deptCode, subDeptCode, doctCode, begDate, endDate);
return Result.success(dataList);
}
@Action("getDoctorSchedule")
public Result getDoctorSchedule(String begDate, String endDate, String doctCode) {
log.info("[医生排班信息] begDate={}, endDate={}, doctCode={}", begDate, endDate, doctCode);
if (doctCode == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
return Result.success(new HisRegisterDao().getDoctorSchedule(begDate, endDate, doctCode));
}
/**
* 查询待预约记录
*
* @param begDate 开始时间
* @param endDate 结束时间
* @return 待预约记录
*/
@Action("getReSignInRecord")
public Result getReSignInRecord(String begDate, String endDate) {
log.info("[查询预约待签到记录] begDate={}, endDate={}", begDate, endDate);
if (begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
return Result.success(new HisRegisterDao().getReSignInRecord(begDate, endDate));
}
/**
* 执行预约签到
*
* @param transNo 预约时的交易流水号
* @return 预约签到结果
*/
@Action("handleSignIn")
public Result handleSignIn(String transNo) {
log.info("[执行预约签到] transNo={}", transNo);
if (transNo == null || transNo.isEmpty()) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
return Result.success(new HisRegisterDao().handleSignIn(transNo));
}
/**
* 查询待预约记录
*
* @param begDate 开始时间
* @param endDate 结束时间
* @return 待预约记录
*/
@Action("getReLineSignInRecord")
public Result getReLineSignInRecord(String patientId, String begDate, String endDate) {
log.info("[查询预约待签到记录(包含今日挂号)] patientId-{} begDate={}, endDate={}", patientId, begDate, endDate);
if (patientId == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String decodePatientId = getDecodeString(patientId);
if (decodePatientId == null) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
if (begDate == null || endDate == null) {
begDate = DateHelper.getCurDate() + " 06:00:00";
endDate = DateHelper.getCurDate() + " 23:59:59";
}
JSONArray dataList = new HisRegisterDao().getReLineSignInRecord(begDate, endDate);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("date", DateHelper.getCurDateTime());
if (dataList == null || dataList.isEmpty()) {
dataMap.put("list", new ArrayList<>());
return Result.success(dataMap);
}
List<Object> findDataList = dataList.stream().filter(iter -> Objects.equals(((JSONObject) iter).getString("PatientId"), decodePatientId)).collect(Collectors.toList());
dataMap.put("list", findDataList);
return Result.success(dataMap);
}
/**
* 执行预约签到
*
* @param treatNum 门诊号
* @return 预约签到结果
*/
@Action("handleLineSignIn")
public Result handleLineSignIn(String treatNum) {
log.info("[执行预约签到(只进行分诊叫号)] treatNum={}", treatNum);
if (treatNum == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
return Result.success(new HisRegisterDao().handleLineSignIn(treatNum));
}
/**
* 查询预约今天号源的患者信息用以推送候诊信息
*
* @param startTime 开始时间范围
* @param endTime 结束时间范围
* @return 候诊人群
*/
@Action("getTodayRegRecord")
public Result getTodayRegRecord(String startTime, String endTime) {
log.info("[候诊推送信息] begTime={}, endTime={}", startTime, endTime);
if (startTime == null || endTime == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
return Result.success(new RegisterDao().selectTodayRegRecord(startTime, endTime));
}
/**
* [就医助手]根据挂号日期范围查询挂号记录
*/
@Action("getRegRecordsByOpenId")
public Result getRegRecordsByOpenId(String begDate, String endDate, String openid) {
try {
log.info("[就医助手]根据挂号日期范围,查询挂号记录 begDate={}, endDate={}, openid={}", begDate, endDate, openid);
if (begDate == null || endDate == null || openid == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<Register> regList = new RegisterDao().selectListByRegDate(begDate, endDate, openid);
for (Register item : regList) {
item.setEnId(ReqParamHelper.encode(String.valueOf(item.getId())));
item.setId(null);
item.filterInfo(); // 数据过滤
}
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("date", DateHelper.getCurDateTime());
dataMap.put("list", regList);
return Result.success(dataMap);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* [就医助手]查询HIS挂号记录
*/
@Action("getHisRegInfo")
public Result getHisRegInfo(String regDate, String patientId, String hisTransNo, String openId) {
log.info("[就医助手]查询HIS挂号信息 regDate={}, patientId={}, hisTransNo={} openId={}", regDate, patientId, hisTransNo, openId);
patientId = getDecodeString(patientId);
if (ObjectUtils.isEmpty(regDate) || ObjectUtils.isEmpty(patientId)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
try {
Register record = new RegService().findHisRegRecord(patientId, regDate, hisTransNo);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("date", DateHelper.getCurDateTime());
dataMap.put("info", record);
return Result.success(dataMap);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* [就医助手]修改流程状态
*/
@Action("updateRegMedToolMark")
public Result updateRegMedToolMark(String id, String medToolMark, String openId) {
id = getDecodeString(id);
log.info("[就医助手]修改流程状态 id={}, medToolMark={}, openId={}", id, medToolMark, openId);
if (ObjectUtils.isEmpty(id) || medToolMark == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
try {
boolean isOK = new RegService().updateRegMedToolMark(id, medToolMark, openId);
return Result.isOK(isOK);
} catch (Exception e) {
return Result.error(e);
}
}
// /**
// * [预约挂号]获取指定科室医生信息
// */
// @Action("getReserveDoctorList")
// public String getReserveDoctorList() {
// String deptCode = request.getParameter("deptCode");
// String regDate = request.getParameter("regDate");
// if (regDate == null) {
// return Result.error(ResultEnum.PARAM_NOT_COMPLETE);
// }
//
// if (deptCode == null) deptCode = "0310";
// List<Doctor> doctors = new HisRegisterDao().getRegReserveDoctList(deptCode, regDate);
// RegisterDao registerDao = new RegisterDao();
// String description; // 特长
// for (Doctor item : doctors) {
// Doctor doctor = registerDao.selectDoctorByCodeOName(item.getDoctCode(), item.getDoctName());
// if (doctor != null) {
// item.setTitle(doctor.getTitle());
// item.setHeadImg(doctor.getHeadImg());
// item.setPym(doctor.getPym());
// description = doctor.getDescription();
// if (description != null && !"".equals(description)) { // 医生特长以wx为主
// item.setDescription(description);
// }
// }
// }
// return Result.success(doctors);
// }
//
// /**
// * [现场挂号]获取指定科室医生信息
// */
// @Action("getSiteDoctorList")
// public String getSiteDoctorList() {
// String deptCode = request.getParameter("deptCode");
//
// if (deptCode == null) deptCode = "";
//
// List<Doctor> doctors = new HisRegisterDao().getRegSiteDoctList(deptCode);
// RegisterDao registerDao = new RegisterDao();
// String description; // 特长
// for (Doctor item : doctors) {
// Doctor doctor = registerDao.selectDoctorByCodeOName(item.getDoctCode(), item.getDoctName());
// if (doctor != null) {
// String title = item.getTitle();
// if (title == null) {
// item.setTitle(doctor.getTitle());
// }
// item.setHeadImg(doctor.getHeadImg());
// item.setPym(doctor.getPym());
// description = doctor.getDescription();
// if (description != null && !"".equals(description)) { // 医生特长以wx为主
// item.setDescription(description);
// }
// }
// }
// return Result.success(doctors);
// }
// /**
// * [预约挂号]获取所有科室信息
// */
// @Action("getReserveDeptList")
// public String getReserveDeptList() {
// log.info("[预约挂号]查询科室");
// List<Dept> resultList = new HisRegisterDao().getRegReserveDeptList();
// return Result.success(resultList);
// }
}