|
@@ -1,5 +1,17 @@
|
|
|
package com.ywt.alipaympapi.service.impl;
|
|
|
|
|
|
+import com.ywt.alipaympapi.core.utils.*;
|
|
|
+import com.ywt.alipaympapi.models.BaseResponse;
|
|
|
+import com.ywt.alipaympapi.models.enums.LastChoiceEnum;
|
|
|
+import com.ywt.alipaympapi.models.vo.InpatientVo;
|
|
|
+import com.ywt.core.exception.AppMessageException;
|
|
|
+import com.ywt.gapi.Result;
|
|
|
+import com.ywt.gapi.ResultCode;
|
|
|
+import com.ywt.gapi.third.taihe.*;
|
|
|
+import com.ywt.gapi.user.GetMedicalCardListRequest;
|
|
|
+import com.ywt.gapi.user.GetMedicalCardListResponse;
|
|
|
+import com.ywt.gapi.user.MedicalCard;
|
|
|
+import com.ywt.gapi.user.UserServiceGrpc;
|
|
|
import com.ywt.request.inpatient.DailyBillDetailsRequest;
|
|
|
import com.ywt.request.inpatient.DailyBillRequest;
|
|
|
import com.ywt.request.inpatient.DepositTradeDetailsRequest;
|
|
@@ -37,10 +49,14 @@ import com.ywt.response.inpatient.SettlementExecuteResponseData;
|
|
|
import com.ywt.response.inpatient.SettlementListResponseData;
|
|
|
import com.ywt.response.inpatient.SettlementQueryResponseData;
|
|
|
import com.ywt.alipaympapi.service.InpatientService;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import sun.util.calendar.BaseCalendar;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author
|
|
@@ -49,6 +65,14 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class InpatientServiceImpl implements InpatientService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaiheServiceGrpc.TaiheServiceBlockingStub taiheServiceBlockingStub;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserServiceGrpc.UserServiceBlockingStub userServiceBlockingStub;
|
|
|
+
|
|
|
@Override
|
|
|
public SettlementQueryResponseData informTradeResult(SettlementQueryRequest request) {
|
|
|
return null;
|
|
@@ -65,8 +89,35 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<InpatientListResponseData> inpatientList(InpatientListRequest request) {
|
|
|
- return null;
|
|
|
+ public List<InpatientListResponseData> inpatientList(InpatientListRequest request) throws Exception {
|
|
|
+ int userId = Checker.parseInt(request.getUserId());
|
|
|
+ List<InpatientListResponseData> list = new ArrayList<>();
|
|
|
+ if (userId <= 0) return list; // 这个接口进入小程序首页就会调用;如果用户没有授权,返回空数据,而不是弹出获取用户信息授权(会违反小程序审核规则);
|
|
|
+
|
|
|
+ int hospId = BizUtil.getCurrentHospitalId();
|
|
|
+ GetMedicalCardListRequest getMedicalCardListRequest = GetMedicalCardListRequest.newBuilder()
|
|
|
+ .setHospitalId(hospId)
|
|
|
+ .setUserId(userId)
|
|
|
+ .setFlag(0)
|
|
|
+ .build();
|
|
|
+ GetMedicalCardListResponse getMedicalCardListResponse = userServiceBlockingStub.getMedicalCardList(getMedicalCardListRequest);
|
|
|
+ Result result = getMedicalCardListResponse.getResult();
|
|
|
+ if (result.getCode() == ResultCode.SUCCEED) {
|
|
|
+ for (MedicalCard medicalCard : getMedicalCardListResponse.getMedicalCardsList()) {
|
|
|
+ InpatientListResponseData data = new InpatientListResponseData();
|
|
|
+ data.setPatientId(medicalCard.getPatientId());
|
|
|
+ data.setInpatientId(medicalCard.getPatientId());
|
|
|
+ data.setInpatientName(medicalCard.getPatientName());
|
|
|
+ data.setSex(medicalCard.getSex() == 1 ? "男" : "女");
|
|
|
+ Date date = DateUtil.stringToDate(medicalCard.getBirthday(), DateUtil.DADE_FROMAT_YMD);
|
|
|
+ data.setInpatientAge(Integer.parseInt(getAgeFromMedicalCard(medicalCard)));
|
|
|
+ InpatientVo vo = getInpatientVo(userId, medicalCard.getPatientId());
|
|
|
+ data.setAdmNo(Checker.getStringValue(vo.getAdmNo()));
|
|
|
+ list.add(data);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -75,13 +126,165 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DailyBillResponseData> dailyBillList(DailyBillRequest request) {
|
|
|
- return null;
|
|
|
+ public List<DailyBillResponseData> dailyBillList(DailyBillRequest request) throws Exception {
|
|
|
+ int userId = Checker.parseInt(request.getUserId());
|
|
|
+ List<DailyBillResponseData> dailyBillList = new ArrayList<>();
|
|
|
+ if (userId <= 0) return dailyBillList; // 这个接口进入小程序首页就会调用;如果用户没有授权,返回空数据,而不是弹出获取用户信息授权(会违反小程序审核规则);
|
|
|
+
|
|
|
+ String date = DateUtil.formatDate(new Date(), "yyyy-MM-dd");
|
|
|
+ int hospId = BizUtil.getCurrentHospitalId();
|
|
|
+ List<MedicalCard> userMedCardList = getUserMedCardList(userId, hospId);
|
|
|
+ if (Checker.isNone(userMedCardList)) {
|
|
|
+ return dailyBillList;
|
|
|
+ }
|
|
|
+ for (MedicalCard m : userMedCardList) {
|
|
|
+ DailyBillResponseData data = new DailyBillResponseData();
|
|
|
+ String hisPatientId = m.getHisPatientId();
|
|
|
+ InpatientVo vo = getInpatientVo(userId, hisPatientId);
|
|
|
+ String totalAmount = Checker.getStringValue(vo.getTotalAmount());
|
|
|
+ String depositBalance = Checker.getStringValue(vo.getDepositBalance());
|
|
|
+ String admNo = Checker.getStringValue(vo.getAdmNo());
|
|
|
+ GetDayFeeListRequest req = GetDayFeeListRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setBillDate(date)
|
|
|
+ .setHospitalId(hospId)
|
|
|
+ .setAdmNo(admNo)
|
|
|
+ .build();
|
|
|
+ GetDayFeeListResponse resp = taiheServiceBlockingStub.getDayFeeList(req);
|
|
|
+ int todaySpend = 0;
|
|
|
+ if (resp.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ List<DayFeeListItem> list = resp.getListList();
|
|
|
+ for (DayFeeListItem item : list) {
|
|
|
+ todaySpend += item.getTotalAmt();
|
|
|
+ }
|
|
|
+ String patientName = Checker.getStringValue(resp.getPatientName());
|
|
|
+ data.setDepositBalance(depositBalance);
|
|
|
+ data.setSpendTotal(totalAmount);
|
|
|
+ data.setInpatientName(patientName);
|
|
|
+ data.setInpatientId(Checker.getStringValue(hisPatientId));
|
|
|
+ data.setCheckInDate(Checker.getStringValue(""));
|
|
|
+ data.setSpendToday(String.format("%.2f", todaySpend / 100d));
|
|
|
+ data.setId(Checker.getStringValue(""));
|
|
|
+ dailyBillList.add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dailyBillList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据 userId & hospitalId 获取用户可用就诊卡列表
|
|
|
+ */
|
|
|
+ public List<MedicalCard> getUserMedCardList(int userId, int hospitalId) throws AppMessageException {
|
|
|
+ GetMedicalCardListRequest getMedicalCardListRequest = GetMedicalCardListRequest.newBuilder()
|
|
|
+ .setHospitalId(hospitalId)
|
|
|
+ .setUserId(userId)
|
|
|
+ .build();
|
|
|
+ GetMedicalCardListResponse getMedicalCardListResponse = userServiceBlockingStub.getMedicalCardList(getMedicalCardListRequest);
|
|
|
+ Result result = getMedicalCardListResponse.getResult();
|
|
|
+ if (result.getCode() != ResultCode.SUCCEED) throw new AppMessageException(result.getInfo());
|
|
|
+ return getMedicalCardListResponse.getMedicalCardsList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private InpatientVo getInpatientVo(int userId, String hisPatientId) throws Exception {
|
|
|
+ InpatientVo vo = new InpatientVo();
|
|
|
+ GetInPatInfoRequest req = GetInPatInfoRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setHospitalId(BizUtil.getCurrentHospitalId())
|
|
|
+ .build();
|
|
|
+ GetInPatInfoResponse resp = taiheServiceBlockingStub.getInPatInfo(req);
|
|
|
+ if (resp.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ String totalAmount = String.format("%.2f", Checker.getDoubleValue(resp.getTotalAmount() / 100d));
|
|
|
+ String depositBalance = String.format("%.2f", Checker.getDoubleValue(resp.getDepositBalance() / 100d));
|
|
|
+ vo.setAdmNo(resp.getAdmNo());
|
|
|
+ vo.setTotalAmount(totalAmount);
|
|
|
+ vo.setDepositBalance(depositBalance);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户ID获取用户诊疗卡信息(选择上一次选择的诊疗卡,或者是第一张)
|
|
|
+ *
|
|
|
+ * @return {@link MedicalCard}
|
|
|
+ */
|
|
|
+ private MedicalCard getMedicalCardByHisPatientId(int userId) {
|
|
|
+ MedicalCard medicalCard = null;
|
|
|
+ // 则获取当前用户的第一张诊疗卡,或者是上一次选择的诊疗卡(优先)
|
|
|
+ GetMedicalCardListRequest getMedicalCardListRequest = GetMedicalCardListRequest.newBuilder()
|
|
|
+ .setUserId(userId)
|
|
|
+ .build();
|
|
|
+ GetMedicalCardListResponse getMedicalCardListResponse = userServiceBlockingStub.getMedicalCardList(getMedicalCardListRequest);
|
|
|
+ Result result = getMedicalCardListResponse.getResult();
|
|
|
+ if (result.getCode() == ResultCode.SUCCEED) {
|
|
|
+ List<MedicalCard> cardList = getMedicalCardListResponse.getMedicalCardsList();
|
|
|
+ if (!Checker.isNone(cardList)) {
|
|
|
+ medicalCard = cardList.stream().filter(p -> p.getLastChoice() == LastChoiceEnum.True.getValue()).findFirst().orElse(null);
|
|
|
+ if (Checker.isNone(medicalCard)) {
|
|
|
+ medicalCard = cardList.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return medicalCard;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DailyBillDetailsResponseData dailyBillDetail(DailyBillDetailsRequest request) {
|
|
|
- return null;
|
|
|
+ public DailyBillDetailsResponseData dailyBillDetail(DailyBillDetailsRequest request) throws Exception {
|
|
|
+ DailyBillDetailsResponseData data = new DailyBillDetailsResponseData();
|
|
|
+ int userId = ContextHelper.getCurrentUserIdWrapped();
|
|
|
+ int hospitalId = BizUtil.getCurrentHospitalId();
|
|
|
+ String date = request.getBillDate();
|
|
|
+ List<MedicalCard> userMedCardList = new ArrayList<>();
|
|
|
+ userMedCardList = getUserMedCardList(userId, hospitalId);
|
|
|
+ if (Checker.isNone(userMedCardList)) {
|
|
|
+ throw new AppMessageException("该用户没有绑定诊疗卡");
|
|
|
+ }
|
|
|
+ for (MedicalCard m : userMedCardList) {
|
|
|
+ if (m.getPatientId().equals(request.getHisPatientId())) {
|
|
|
+ InpatientVo vo = null;
|
|
|
+ String admNo = "";
|
|
|
+ String hisPatientId = m.getHisPatientId();
|
|
|
+ vo = getInpatientVo(userId, hisPatientId);
|
|
|
+ String totalAmount = Checker.getStringValue(vo.getTotalAmount());
|
|
|
+ String depositBalance = Checker.getStringValue(vo.getDepositBalance());
|
|
|
+ admNo = Checker.getStringValue(vo.getAdmNo());
|
|
|
+ GetDayFeeListRequest req = GetDayFeeListRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setBillDate(request.getBillDate())
|
|
|
+ .setHospitalId(hospitalId)
|
|
|
+ .setAdmNo(admNo)
|
|
|
+ .build();
|
|
|
+ GetDayFeeListResponse resp = taiheServiceBlockingStub.getDayFeeList(req);
|
|
|
+ int todaySpend = 0;
|
|
|
+ if (resp.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ List<SettlementQueryResponseData.Item> payItemList = new ArrayList<>();
|
|
|
+ List<DayFeeListItem> list = resp.getListList();
|
|
|
+ for (DayFeeListItem item : list) {
|
|
|
+ SettlementQueryResponseData.Item it = new SettlementQueryResponseData.Item();
|
|
|
+ it.setItemName(Checker.getStringValue(item.getItemName()));
|
|
|
+ it.setItemCount(Checker.getIntegerValue(Integer.parseInt(Checker.getStringValue(item.getQuantity()))));
|
|
|
+ it.setItemPrice(String.format("%.2f", item.getPrice() / 100d));
|
|
|
+ it.setItemAmount(String.format("%.2f", item.getTotalAmt() / 100d));
|
|
|
+ todaySpend += item.getTotalAmt();
|
|
|
+ payItemList.add(it);
|
|
|
+ }
|
|
|
+ data.setBillDate(request.getBillDate());
|
|
|
+ data.setDepositBalance(depositBalance);
|
|
|
+ data.setInpatientName(m.getPatientName());
|
|
|
+ data.setPayItemList(payItemList);
|
|
|
+ data.setSpendTotal(totalAmount);
|
|
|
+ data.setSpendToday(String.format("%.2f", todaySpend / 100d));
|
|
|
+ data.setCheckInDate(Checker.getStringValue(""));
|
|
|
+ data.setInpatientId(resp.getPatientId());
|
|
|
+ data.setId(Checker.getStringValue(""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -95,13 +298,97 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DepositTradeListResponseData> queryTradeList(DepositTradeListRequest request) {
|
|
|
- return null;
|
|
|
+ public List<DepositTradeListResponseData> queryTradeList(DepositTradeListRequest request) throws Exception {
|
|
|
+ String hisPatientId = request.getInpatientId();
|
|
|
+ List<DepositTradeListResponseData> depositList = new ArrayList<>();
|
|
|
+ if (Checker.isNone(hisPatientId)) {
|
|
|
+ throw new AppMessageException("该用户没有绑定诊疗卡");
|
|
|
+ }
|
|
|
+ GetInPatInfoRequest req = GetInPatInfoRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setHospitalId(BizUtil.getCurrentHospitalId())
|
|
|
+ .build();
|
|
|
+ GetInPatInfoResponse resp = taiheServiceBlockingStub.getInPatInfo(req);
|
|
|
+ if (resp.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ String admNo = Checker.getStringValue(resp.getAdmNo());
|
|
|
+ GetCashListRequest requ = GetCashListRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setAdmNo(admNo)
|
|
|
+ .setHospitalId(BizUtil.getCurrentHospitalId())
|
|
|
+ .build();
|
|
|
+ GetCashListResponse res = taiheServiceBlockingStub.getCashList(requ);
|
|
|
+ if (res.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ List<CashListItem> list = res.getListList();
|
|
|
+ DepositTradeListResponseData da = new DepositTradeListResponseData();
|
|
|
+ for (CashListItem i : list) {
|
|
|
+ da.setInpatientName(Checker.getStringValue(i.getPayUserName()));
|
|
|
+ da.setAmount(String.format("%.2f", i.getPayAmout() / 100d));
|
|
|
+ da.setOutTradeNo(i.getReceiptNo());
|
|
|
+ da.setPayTime(i.getPayDate() + "" + i.getPayTime());
|
|
|
+ da.setTradeNo(Checker.getStringValue(""));
|
|
|
+ da.setDepositId(Checker.getStringValue(""));
|
|
|
+ String depositBalance = String.format("%.2f", resp.getDepositBalance() / 100d);
|
|
|
+ da.setDepositBalance(depositBalance);
|
|
|
+ da.setStatus(Checker.getStringValue(""));
|
|
|
+ da.setDepositId(Checker.getStringValue(i.getReceiptNo()));
|
|
|
+ da.setAdmNo(Checker.getStringValue(admNo));
|
|
|
+ depositList.add(da);
|
|
|
+ }
|
|
|
+ return depositList;
|
|
|
+ }
|
|
|
+ return depositList;
|
|
|
+ }
|
|
|
+ return depositList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DepositTradeDetailsResponseData queryTradeDetails(DepositTradeDetailsRequest request) {
|
|
|
- return null;
|
|
|
+ public DepositTradeDetailsResponseData queryTradeDetails(DepositTradeDetailsRequest request) throws Exception {
|
|
|
+ String hisPatientId = request.getHisPatientId();
|
|
|
+ if (Checker.isNone(hisPatientId)) {
|
|
|
+ throw new AppMessageException("该用户没有绑定诊疗卡");
|
|
|
+ }
|
|
|
+ if (Checker.isNone(request.getReceiptNo())) {
|
|
|
+ throw new AppMessageException("没有押金缴纳记录");
|
|
|
+ }
|
|
|
+ GetInPatInfoRequest req = GetInPatInfoRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setHospitalId(BizUtil.getCurrentHospitalId())
|
|
|
+ .build();
|
|
|
+ GetInPatInfoResponse resp = taiheServiceBlockingStub.getInPatInfo(req);
|
|
|
+ if (resp.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ String admNo = Checker.getStringValue(resp.getAdmNo());
|
|
|
+ GetCashListRequest requ = GetCashListRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setAdmNo(admNo)
|
|
|
+ .setHospitalId(BizUtil.getCurrentHospitalId())
|
|
|
+ .build();
|
|
|
+ GetCashListResponse res = taiheServiceBlockingStub.getCashList(requ);
|
|
|
+ DepositTradeDetailsResponseData data = new DepositTradeDetailsResponseData();
|
|
|
+ if (res.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ List<CashListItem> list = res.getListList();
|
|
|
+ DepositTradeDetailsResponseData da = new DepositTradeDetailsResponseData();
|
|
|
+ for (CashListItem i : list) {
|
|
|
+ if (request.getReceiptNo().equals(i.getReceiptNo())) {
|
|
|
+ {
|
|
|
+ da.setInpatientName(Checker.getStringValue(i.getPayUserName()));
|
|
|
+ da.setAmount(String.format("%.2f", i.getPayAmout() / 100d));
|
|
|
+ da.setOutTradeNo(i.getReceiptNo());
|
|
|
+ da.setPayTime(i.getPayDate() + "" + i.getPayTime());
|
|
|
+ da.setTradeNo(Checker.getStringValue(""));
|
|
|
+ da.setDepositId(Checker.getStringValue(""));
|
|
|
+ String depositBalance = String.format("%.2f", resp.getDepositBalance() / 100d);
|
|
|
+ da.setDepositBalance(depositBalance);
|
|
|
+ da.setStatus(Checker.getStringValue(i.getPayFlag()));
|
|
|
+ da.setInpatientNo(hisPatientId);
|
|
|
+ return da;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new AppMessageException("没有押金缴纳记录");
|
|
|
+ }
|
|
|
+ throw new AppMessageException("没有押金缴纳记录");
|
|
|
+ }
|
|
|
+ throw new AppMessageException("没有押金缴纳记录");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -134,6 +421,30 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private String getAgeFromMedicalCard(MedicalCard card) {
|
|
|
+ int age = -1;
|
|
|
+ String idNo = card.getIdNo();
|
|
|
+ String birthday = card.getBirthday();
|
|
|
+ if (!StringHelper.isNullOrEmpty(idNo)) {
|
|
|
+ try {
|
|
|
+ age = IdCardUtil.getCurrentAge(idNo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("IsvMedicCardServiceImpl#getAgeFromMedicalCard(idNo = {}): 无法获取年龄 {}", idNo, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ } else if (!StringHelper.isNullOrEmpty(birthday)) {
|
|
|
+ try {
|
|
|
+ age = IdCardUtil.getCurrentAgeByBirthday(birthday, IdCardUtil.DATE_PATTERN2);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("IsvMedicCardServiceImpl#getAgeFromMedicalCard(birthday = {}): 无法获取年龄 {}", birthday, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 不返回年龄为 "-1"
|
|
|
+ if (age < 0) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return String.valueOf(age);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public InpatientDetailsResponseData inpatientDetails(InpatientDetailsRequest request) {
|
|
|
return null;
|