|
@@ -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,30 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<InpatientListResponseData> inpatientList(InpatientListRequest request) {
|
|
|
- return null;
|
|
|
+ public List<InpatientListResponseData> inpatientList(InpatientListRequest request) throws Exception {
|
|
|
+ int userId = ContextHelper.getCurrentUserIdWrapped();
|
|
|
+ int hospId = BizUtil.getCurrentHospitalId();
|
|
|
+ List<InpatientListResponseData> list = new ArrayList<>();
|
|
|
+ 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.setInpatientName(medicalCard.getPatientName());
|
|
|
+ data.setSex(medicalCard.getSex() == 1 ? "男" : "女");
|
|
|
+ Date date = DateUtil.stringToDate(medicalCard.getBirthday(), DateUtil.DADE_FROMAT_YMD);
|
|
|
+ data.setInpatientAge(IdCardUtil.getCurrentAgeCommon(date));
|
|
|
+ list.add(data);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ throw new AppMessageException("该用户没有绑定诊疗卡");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -75,13 +121,169 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DailyBillResponseData> dailyBillList(DailyBillRequest request) {
|
|
|
- return null;
|
|
|
+ public List<DailyBillResponseData> dailyBillList(DailyBillRequest request) throws Exception {
|
|
|
+ List<DailyBillResponseData> dailyBillList = new ArrayList<>();
|
|
|
+ List<MedicalCard> userMedCardList = new ArrayList<>();
|
|
|
+ int userId = ContextHelper.getCurrentUserIdWrapped();
|
|
|
+ String hospitalId = request.getHospitalDistrictId();
|
|
|
+ String date = DateUtil.formatDate(new Date(), "yyyy-MM-dd");
|
|
|
+ int hospId = Integer.parseInt(hospitalId); // fixme
|
|
|
+// String hisPatientId = "";
|
|
|
+ userMedCardList = getUserMedCardList(userId, hospId);
|
|
|
+ if (Checker.isNone(userMedCardList)) {
|
|
|
+ return dailyBillList;
|
|
|
+ }
|
|
|
+ for (MedicalCard m : userMedCardList) {
|
|
|
+ DailyBillResponseData data = new DailyBillResponseData();
|
|
|
+ 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(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", resp.getTotalAmount() / 100d);
|
|
|
+ String.format("%.2f", resp.getDepositAmount() / 100d);
|
|
|
+ String depositBalance = String.format("%.2f", 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
|
|
@@ -100,7 +302,27 @@ public class InpatientServiceImpl implements InpatientService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DepositTradeDetailsResponseData queryTradeDetails(DepositTradeDetailsRequest request) {
|
|
|
+ public DepositTradeDetailsResponseData queryTradeDetails(DepositTradeDetailsRequest request) throws Exception{
|
|
|
+ String hisPatientId = request.getHisPatientId();
|
|
|
+ if(Checker.isNone(hisPatientId)){
|
|
|
+ throw new AppMessageException("该用户没有绑定诊疗卡");
|
|
|
+ }
|
|
|
+ GetInPatInfoRequest req = GetInPatInfoRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
|
|
|
+ .build();
|
|
|
+ GetInPatInfoResponse resp = taiheServiceBlockingStub.getInPatInfo(req);
|
|
|
+ if (resp.getCode() == BaseResponse.SUCCEED) {
|
|
|
+ String admNo = resp.getAdmNo();
|
|
|
+ GetCashListRequest requ = GetCashListRequest.newBuilder()
|
|
|
+ .setPatientId(hisPatientId)
|
|
|
+ .setAdmNo(admNo)
|
|
|
+ .setHospitalId(BizUtil.getHospitalIdByTerminalId(BizUtil.getCurrentTerminalWrapped()))
|
|
|
+ .build();
|
|
|
+ GetCashListResponse res = taiheServiceBlockingStub.getCashList(requ);
|
|
|
+ DepositTradeDetailsResponseData data = new DepositTradeDetailsResponseData();
|
|
|
+ }
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|