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.
243 lines
8.9 KiB
243 lines
8.9 KiB
package com.ynxbd.common.action;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.IdcardUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.ynxbd.common.action.base.BaseAction;
|
|
import com.ynxbd.common.bean.pay.Register;
|
|
import com.ynxbd.common.dao.PWEReportDao;
|
|
import com.ynxbd.common.helper.common.JsonHelper;
|
|
import com.ynxbd.common.result.Result;
|
|
import com.ynxbd.common.result.ResultEnum;
|
|
import com.ynxbd.wx.config.MessagePushConfig;
|
|
import com.ynxbd.wx.pwe.PWEConfig;
|
|
import com.ynxbd.wx.pwe.PWEHelper;
|
|
import com.ynxbd.wx.pwe.bean.PWEResult;
|
|
import com.ynxbd.wx.pwe.bean.PWERegister;
|
|
import com.ynxbd.wx.pwe.bean.PWEReport;
|
|
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 javax.servlet.http.HttpServletRequest;
|
|
|
|
/**
|
|
* 【预问诊】
|
|
* 接口名,大写开头的接口是提供给第三方调用的。
|
|
*/
|
|
|
|
@Slf4j
|
|
@Namespace("/pwe")
|
|
public class PWEAction extends BaseAction {
|
|
|
|
/**
|
|
* [预问诊][患者端]获取小程序短链(文档中描述:用于短信)
|
|
*/
|
|
@Action("getMiniPWEUrl")
|
|
public Result getMiniPWEUrl(String registerId) {
|
|
try {
|
|
log.info("[预问诊][患者端]获取小程序短链 registerId={}", registerId);
|
|
if (ObjectUtils.isEmpty(registerId)) {
|
|
return Result.error(ResultEnum.PARAM_IS_BLANK);
|
|
}
|
|
String url = PWEHelper.getMiniPWEUrl(registerId);
|
|
return Result.success(url);
|
|
} catch (Exception e) {
|
|
return Result.error(e);
|
|
}
|
|
}
|
|
|
|
|
|
/***
|
|
* [预问诊][患者端]获取预问诊H5链接
|
|
*/
|
|
@Action("getH5PWEUrl")
|
|
public Result getH5PWEUrl(String registerId, String openid) {
|
|
try {
|
|
log.info("[预问诊][患者端]获取预问诊h5链接 registerId={}", registerId);
|
|
if (ObjectUtils.isEmpty(registerId)) {
|
|
return Result.error(ResultEnum.PARAM_IS_BLANK);
|
|
}
|
|
String url = PWEHelper.getH5PWEUrl(registerId, openid);
|
|
if (ObjectUtils.isEmpty(url)) {
|
|
log.info("[预问诊][患者端]获取预问诊H5链接失败 registerId={}, openid={}", registerId, openid);
|
|
return Result.error("获取链接失败");
|
|
}
|
|
return Result.success(url);
|
|
} catch (Exception e) {
|
|
return Result.error(e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* [预问诊][医生端]获取预问诊报告链接
|
|
*/
|
|
@Action("getPWEReportUrl")
|
|
public Result getPWEReportUrl(String deptCode, String doctCode, String doctName, String tradeNo) {
|
|
try {
|
|
log.info("[预问诊][医生端]获取预问诊报告链接 deptCode={}, doctCode={}, doctName={}, tradeNo={}", deptCode, doctCode, doctName, tradeNo);
|
|
if (ObjectUtils.isEmpty(deptCode) || ObjectUtils.isEmpty(doctCode) || ObjectUtils.isEmpty(doctName) || ObjectUtils.isEmpty(tradeNo)) {
|
|
return Result.error(ResultEnum.PARAM_IS_BLANK);
|
|
}
|
|
|
|
Register order = new PWEReportDao().selectRegOrderNo(tradeNo);
|
|
if (order == null) {
|
|
return Result.error("未找到订单信息");
|
|
}
|
|
String outTradeNo = order.getOutTradeNo();
|
|
if (ObjectUtils.isEmpty(outTradeNo)) {
|
|
return Result.error("订单没有订单号");
|
|
}
|
|
String miniPWEUrl = PWEHelper.getPWEReportUrl(deptCode, doctCode, doctName, outTradeNo);
|
|
return Result.success(miniPWEUrl);
|
|
} catch (Exception e) {
|
|
return Result.error(e);
|
|
}
|
|
}
|
|
|
|
// 返回挂号信息
|
|
|
|
/**
|
|
* [预问诊]6.3 预问诊完成通知 ReportNotify(可选)
|
|
*/
|
|
@Action("ReportNotify")
|
|
public PWEResult ReportNotify(HttpServletRequest req) {
|
|
try {
|
|
JSONObject body = PWEHelper.verifySign(req, true);
|
|
|
|
String partnerId = body.getString("partnerId");
|
|
String hospitalId = body.getString("hospitalId");
|
|
String registeredId = body.getString("registeredId");
|
|
String progress = body.getString("progress");
|
|
Register order = new PWEReportDao().selectRegOrderInfo(registeredId);
|
|
log.info("[预问诊]6.3 预问诊完成通知 partnerId={}, hospitalId={}, registeredId={}, progress={}", partnerId, hospitalId, registeredId, progress);
|
|
|
|
if ("1".equals(progress)) {
|
|
log.info("[预问诊]报告生成进度100%");
|
|
MessagePushConfig.regAIReport(order.getPatientId(), order.getOutTradeNo(), order.getOpenid());
|
|
}
|
|
return PWEResult.success();
|
|
} catch (Exception e) {
|
|
return PWEResult.error(e);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* [预问诊]6.2 挂号查询 GetRegisteredInfo(必选)
|
|
*/
|
|
@Action("GetRegisteredInfo")
|
|
public PWEResult GetRegisteredInfo(HttpServletRequest req) {
|
|
try {
|
|
JSONObject body = PWEHelper.verifySign(req, true);
|
|
|
|
String registeredId = body.getString("registeredId");
|
|
log.info("[预问诊]挂号查询 registeredId={}", registeredId);
|
|
|
|
Register order = new PWEReportDao().selectRegOrderInfo(registeredId);
|
|
if (order == null) {
|
|
return PWEResult.error("未找到挂号订单");
|
|
}
|
|
|
|
String sex = order.getSex();
|
|
String birthday = order.getBirthday();
|
|
String idCardNo = order.getIdCardNo();
|
|
|
|
int gender;
|
|
if (ObjectUtils.isEmpty(sex)) {
|
|
gender = IdcardUtil.getGenderByIdCard(idCardNo) == 0 ? 1 : 0;
|
|
} else {
|
|
gender = "男".equals(sex) ? 0 : 1;
|
|
}
|
|
|
|
int age;
|
|
if (ObjectUtils.isEmpty(birthday)) {
|
|
age = IdcardUtil.getAgeByIdCard(idCardNo);
|
|
} else {
|
|
age = DateUtil.ageOfNow(birthday);
|
|
}
|
|
|
|
PWERegister reg = new PWERegister();
|
|
reg.setName(ObjectUtils.isEmpty(order.getPatientName())? "": order.getPatientName());
|
|
reg.setSex(gender);
|
|
reg.setAge(age);
|
|
reg.setRegisteredId(order.getOutTradeNo());
|
|
|
|
reg.setDepartments(reg.getStrList(order.getDeptName()));
|
|
reg.setDepartmentIds(reg.getStrList(order.getDeptCode()));
|
|
reg.setDoctorId(order.getDoctCode());
|
|
reg.setDoctorName(order.getDoctName());
|
|
reg.setQuery("");
|
|
reg.setVisitingStatus(0);
|
|
reg.setDoctorWorkWechatId("");
|
|
|
|
return PWEResult.success(reg);
|
|
} catch (Exception e) {
|
|
return PWEResult.error(e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* [预问诊]6.4.1 报告内容推送 PushReport(必选)
|
|
*/
|
|
@Action("PushReport")
|
|
public PWEResult PushReport(HttpServletRequest req) {
|
|
try {
|
|
JSONObject body = PWEHelper.verifySign(req, false);
|
|
String registeredId = body.getString("registeredId");
|
|
log.info("[预问诊]报告内容推送 registeredId={}", registeredId);
|
|
|
|
PWEReport report = new PWEReport();
|
|
report.setRegisterId(registeredId);
|
|
report.setDataJson(JsonHelper.toJsonString(body));
|
|
|
|
PWEReport findData = new PWEReportDao().selectByRegId(registeredId);
|
|
boolean isOK;
|
|
if (findData == null) {
|
|
log.info("[预问诊]报告内容推送 新增数据 registeredId={}", registeredId);
|
|
report.setHospitalId(PWEConfig.HOSPITAL_ID);
|
|
isOK = new PWEReportDao().insert(report);
|
|
} else {
|
|
log.info("[预问诊]报告内容推送 修改数据 registeredId={}", registeredId);
|
|
isOK = new PWEReportDao().update(report);
|
|
}
|
|
|
|
if (isOK) {
|
|
return PWEResult.success();
|
|
}
|
|
return PWEResult.error("数据接收失败");
|
|
} catch (Exception e) {
|
|
return PWEResult.error(e);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* [预问诊]6.4.2 报告内容查询 QueryReport(必选)
|
|
*/
|
|
@Action("QueryReport")
|
|
public PWEResult QueryReport(HttpServletRequest req) {
|
|
try {
|
|
JSONObject body = PWEHelper.verifySign(req, true);
|
|
String registeredId = body.getString("registeredId");
|
|
log.info("[预问诊]报告内容查询 registeredId={}", registeredId);
|
|
PWEReport findData = new PWEReportDao().selectByRegId(registeredId);
|
|
if (findData == null) {
|
|
return PWEResult.error("未找到数据");
|
|
}
|
|
JSONObject jsonObject = JsonHelper.parseObject(findData.getDataJson());
|
|
if (jsonObject == null) {
|
|
return PWEResult.error("匹配到的数据为空");
|
|
}
|
|
return PWEResult.success(jsonObject);
|
|
} catch (Exception e) {
|
|
return PWEResult.error(e);
|
|
}
|
|
}
|
|
}
|
|
|