DismissService.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. package thyyxxk.webserver.service.inpatient;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.transaction.annotation.Transactional;
  6. import thyyxxk.webserver.config.exception.BizException;
  7. import thyyxxk.webserver.config.exception.ExceptionEnum;
  8. import thyyxxk.webserver.constants.Capacity;
  9. import thyyxxk.webserver.constants.sidicts.MedType;
  10. import thyyxxk.webserver.dao.his.inpatient.DismissDao;
  11. import thyyxxk.webserver.entity.ResultVo;
  12. import thyyxxk.webserver.entity.inpatient.dismiss.*;
  13. import thyyxxk.webserver.entity.inpatient.patient.Overview;
  14. import thyyxxk.webserver.entity.inpatient.patient.Patient;
  15. import thyyxxk.webserver.service.externalhttp.SiInjurySystem;
  16. import thyyxxk.webserver.service.externalhttp.SiZySrvc;
  17. import thyyxxk.webserver.utils.*;
  18. import java.math.BigDecimal;
  19. import java.util.*;
  20. /**
  21. * @author dj
  22. */
  23. @Slf4j
  24. @Service
  25. public class DismissService {
  26. private final DismissDao dao;
  27. private final SiZySrvc zySrvc;
  28. private final SiInjurySystem injury;
  29. @Autowired
  30. public DismissService(DismissDao dao, SiZySrvc zySrvc, SiInjurySystem injury) {
  31. this.dao = dao;
  32. this.zySrvc = zySrvc;
  33. this.injury = injury;
  34. }
  35. public ResultVo<Object> dismiss(Patient param) {
  36. ResultVo<List<ActOrderGroup>> actOrders = getActOrders(param.getInpatientNo(), param.getAdmissTimes());
  37. if (actOrders.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  38. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, actOrders.getMessage());
  39. }
  40. if (!actOrders.getData().isEmpty()) {
  41. return ResultVoUtil.fail(ExceptionEnum.ABNORMAL_YZ_ACT_ORDER, actOrders.getData());
  42. }
  43. ResultVo<List<NegativeFee>> calculate = calculateForDismiss(param);
  44. if (calculate.getCode() == ExceptionEnum.EXIST_NEGATIVE_FEES.getCode()) {
  45. return ResultVoUtil.fail(ExceptionEnum.EXIST_NEGATIVE_FEES, calculate.getData());
  46. }
  47. if (calculate.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  48. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, calculate.getMessage());
  49. }
  50. return ResultVoUtil.success();
  51. }
  52. public ResultVo<List<ActOrderGroup>> getActOrders(String patNo, Integer times) {
  53. final Integer ledgerSn = dao.getLedgerSn(patNo, times);
  54. if (ledgerSn < 1) {
  55. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "获取帐页数失败。");
  56. }
  57. dao.acceptFeeStepOne(patNo, times);
  58. if (dao.acceptFeeStepTwo(patNo, times) < 0) {
  59. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "接收费用失败。");
  60. }
  61. if (dao.getOrderList(patNo, times) < 0) {
  62. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询医嘱失败。");
  63. }
  64. List<ActOrderDetail> allOrders = dao.getActOrderDetail();
  65. if (allOrders == null) {
  66. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询医嘱失败。");
  67. }
  68. return analyzeActOrders(allOrders);
  69. }
  70. private ResultVo<List<ActOrderGroup>> analyzeActOrders(List<ActOrderDetail> allOrders) {
  71. HashMap<String, ActOrderGroup> temp = new HashMap<>(Capacity.DEFAULT);
  72. for (ActOrderDetail item : allOrders) {
  73. String actOrderNo = item.getActOrderNo();
  74. String fee = item.getChargeFee();
  75. if (!temp.containsKey(actOrderNo)) {
  76. ActOrderGroup aModel = new ActOrderGroup(actOrderNo, fee, item.getChargeStatus(), item.getCxFlag());
  77. if (aModel.getList() == null) {
  78. aModel.setList(new ArrayList<>());
  79. }
  80. aModel.getList().add(item);
  81. temp.put(actOrderNo, aModel);
  82. } else {
  83. temp.get(actOrderNo).setFee(DecimalUtil.add(fee, temp.get(actOrderNo).getFee()));
  84. temp.get(actOrderNo).getList().add(item);
  85. }
  86. }
  87. List<ActOrderGroup> list = new ArrayList<>();
  88. for (HashMap.Entry<String, ActOrderGroup> modelEntry : temp.entrySet()) {
  89. list.add(modelEntry.getValue());
  90. }
  91. return ResultVoUtil.success(list);
  92. }
  93. public ResultVo<List<NegativeFee>> calculateForDismiss(Patient param) {
  94. final String patNo = param.getInpatientNo();
  95. final Integer times = param.getAdmissTimes();
  96. if (!param.getMidSetl()) {
  97. Integer disActOrderCount = dao.countDisActOrders(patNo, times);
  98. if (null == disActOrderCount || disActOrderCount == 0) {
  99. disActOrderCount = dao.countDisActOrders2(patNo, times);
  100. if (null == disActOrderCount) {
  101. disActOrderCount = 0;
  102. }
  103. }
  104. if (disActOrderCount < 1) {
  105. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  106. exception.setMessage("此患者没有出院医嘱,请检查。");
  107. throw new BizException(exception);
  108. }
  109. if (disActOrderCount > 1) {
  110. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  111. exception.setMessage("此患者的出院医嘱不止一条,请检查。");
  112. throw new BizException(exception);
  113. }
  114. }
  115. if (StringUtil.isBlank(param.getDutyNurse())) {
  116. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  117. exception.setMessage("患者责任护士不能为空,请前往入院登记页面填写并保存。");
  118. throw new BizException(exception);
  119. }
  120. if (StringUtil.isBlank(param.getCountry())) {
  121. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  122. exception.setMessage("患者国籍不能为空,请前往入院登记页面填写并保存。");
  123. throw new BizException(exception);
  124. }
  125. if (StringUtil.isBlank(param.getNation())) {
  126. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  127. exception.setMessage("患者民族不能为空,请前往入院登记页面填写并保存。");
  128. throw new BizException(exception);
  129. }
  130. if (StringUtil.isBlank(param.getContactName())) {
  131. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  132. exception.setMessage("患者联系人不能为空,请前往入院登记页面填写并保存。");
  133. throw new BizException(exception);
  134. }
  135. if (StringUtil.isBlank(param.getContactRelation())) {
  136. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  137. exception.setMessage("患者联系人关系不能为空,请前往入院登记页面填写并保存。");
  138. throw new BizException(exception);
  139. }
  140. if (StringUtil.isBlank(param.getContactAddrName())) {
  141. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  142. exception.setMessage("患者联系人地址不能为空,请前往入院登记页面填写并保存。");
  143. throw new BizException(exception);
  144. }
  145. if (StringUtil.isBlank(param.getContactPhone())) {
  146. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  147. exception.setMessage("患者联系人电话不能为空,请前往入院登记页面填写并保存。");
  148. throw new BizException(exception);
  149. }
  150. if (null == param.getAdmissDate()) {
  151. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  152. exception.setMessage("没有找到入院时间,请重新获取病人信息。");
  153. throw new BizException(exception);
  154. }
  155. if (!IdCardUtil.isValidatedIdCard(param.getSocialNo())) {
  156. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "身份证不合法!");
  157. }
  158. int age = IdCardUtil.getAgeByIdCard(param.getSocialNo());
  159. if (age < 16 || age > 60) {
  160. if (param.getName().equals(param.getContactName()) ||
  161. param.getContactRelation().equals("0")) {
  162. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "16岁以下或60岁以上的患者,联系人不能填写本人。");
  163. }
  164. }
  165. Date endtime = getEndtime(param.getMidSetl(), patNo, times, param.getZjdzDatetime());
  166. Date tmpendtime = param.getMidSetl() ? endtime : DateUtil.parse("2999-12-31 23:59:59");
  167. final int ledgerSn = dao.getLedgerSn(patNo, times);
  168. if (dao.hasUnsettledStepOne(patNo, times, ledgerSn) < 0) {
  169. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  170. exception.setMessage("获取记账信息失败。");
  171. throw new BizException(exception);
  172. }
  173. if (dao.hasUnsettledStepTwo(patNo, times) > 0) {
  174. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  175. exception.setMessage("此患者有未结算的记账金额,请联系收费窗口。");
  176. throw new BizException(exception);
  177. }
  178. if (dao.hasNotAccounted(patNo, times) > 0) {
  179. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  180. exception.setMessage("此患者有未上账金额。");
  181. throw new BizException(exception);
  182. }
  183. List<String> unreceivedDrug = dao.hasUnreceivedDrugList(patNo, times);
  184. if (ListUtil.notBlank(unreceivedDrug)) {
  185. throw new BizException(ExceptionEnum.LOGICAL_HTML_ERROR, dischargeErrorMessage(unreceivedDrug));
  186. }
  187. if (dao.hasUnreceivedFees(patNo, times, tmpendtime) > 0) {
  188. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  189. exception.setMessage("此患者有未接收的费用。");
  190. throw new BizException(exception);
  191. }
  192. if (dao.hasUnSubmitDrugList(patNo, times) > 0) { // 有未提交药物清单
  193. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  194. exception.setMessage("此患者有未提交的药单。");
  195. throw new BizException(exception);
  196. }
  197. if (dao.hasUntreatedDrugWithdrawalOrder(patNo, times) > 0) {
  198. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  199. exception.setMessage("此患者有未处理的药品退药单。");
  200. throw new BizException(exception);
  201. }
  202. if (dao.hasUnconfirmedMedicalTech(patNo, times, tmpendtime) > 0) {
  203. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  204. exception.setMessage("此患者有未确认的医技。");
  205. throw new BizException(exception);
  206. }
  207. List<NegativeFee> feeNegativeList = dao.feeOrderNegative(patNo, times);
  208. if (feeNegativeList.size() > 0) {
  209. return ResultVoUtil.fail(ExceptionEnum.EXIST_NEGATIVE_FEES, feeNegativeList);
  210. }
  211. if (dao.hasSettled(patNo, times, ledgerSn) != 0) {
  212. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  213. exception.setMessage("此患者已存在结算信息。");
  214. throw new BizException(exception);
  215. }
  216. if (dao.hasUncheckedFee(patNo, times, ledgerSn) > 0) {
  217. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  218. exception.setMessage("此患者有未结账的费用。");
  219. throw new BizException(exception);
  220. }
  221. Date begntime = getBegntime(patNo, times, ledgerSn,"zy_actpatient");
  222. dismissFeeAnalyse(patNo, times, ledgerSn, begntime, tmpendtime);
  223. BigDecimal feeOffset = dao.getFeeOffset(patNo, times, ledgerSn);
  224. if (feeOffset.compareTo(BigDecimal.ZERO) != 0) {
  225. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  226. BigDecimal beforeAdmFee = dao.selectOverTimeLimitFee(patNo, times, ledgerSn, "<", begntime);
  227. if (beforeAdmFee.compareTo(BigDecimal.ZERO) != 0) {
  228. exception.setMessage("此患者明细费用与账页费用不一致,有【" + beforeAdmFee + "元】小于入院时间的费用。");
  229. throw new BizException(exception);
  230. }
  231. if (!param.getMidSetl()) {
  232. BigDecimal afterDisFee = dao.selectOverTimeLimitFee(patNo, times, ledgerSn, ">", tmpendtime);
  233. if (afterDisFee.compareTo(BigDecimal.ZERO) != 0) {
  234. exception.setMessage("此患者明细费用与账页费用不一致,有【" + afterDisFee + "元】大于出院时间的费用。");
  235. throw new BizException(exception);
  236. }
  237. exception.setMessage("此患者明细费用与账页费用不一致,请确认所有医嘱、药单等都已接收。");
  238. throw new BizException(exception);
  239. }
  240. }
  241. dao.deleteTemporaryTable(patNo, times);
  242. BriefMdtrtInfo medinfo = dao.selectMdtrtId(patNo, times, ledgerSn);
  243. if (null == medinfo) {
  244. medinfo = new BriefMdtrtInfo();
  245. }
  246. if (StringUtil.notBlank(medinfo.getMdtrtId())) {
  247. if (dao.hasDismissDiag(patNo, times) == 0) {
  248. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  249. exception.setMessage("此患者没有医保出院诊断。");
  250. throw new BizException(exception);
  251. }
  252. if (medinfo.getMedType().equals(MedType.INJURY_HOSPITALIZATION.getCode())) {
  253. ResultVo<String> feeCheck = injury.preCalculateCost(param);
  254. if (feeCheck.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  255. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  256. exception.setMessage(feeCheck.getMessage());
  257. throw new BizException(exception);
  258. }
  259. } else {
  260. Overview o = new Overview();
  261. o.setInpatientNo(patNo);
  262. o.setAdmissTimes(times);
  263. o.setLedgerSn(ledgerSn);
  264. o.setStaffId(param.getStaffId());
  265. o.setSid(param.getSid());
  266. o.setMidSetl(param.getMidSetl());
  267. if (o.getMidSetl()) {
  268. o.setBegntime(begntime);
  269. o.setEndtime(tmpendtime);
  270. }
  271. ResultVo<String> feeCheck = zySrvc.uploadFeeDetail(o);
  272. if (feeCheck.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  273. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  274. exception.setMessage(feeCheck.getMessage());
  275. throw new BizException(exception);
  276. }
  277. }
  278. }
  279. return ResultVoUtil.success();
  280. }
  281. private String dischargeErrorMessage(List<String> messages) {
  282. StringBuilder str = new StringBuilder("此患者有未接收的药单" + "<br />");
  283. for (String message : messages) {
  284. str.append(message).append("<br>");
  285. }
  286. return str.toString();
  287. }
  288. @Transactional(rollbackFor = Exception.class)
  289. public ResultVo<String> executeDischarging(MedinsSettleFee settleFee) throws BizException {
  290. updateHicNo(settleFee.getInpatientNo());
  291. settleFee.setLedgerSn(dao.getLedgerSn(settleFee.getInpatientNo(), settleFee.getAdmissTimes()));
  292. BriefMdtrtInfo medinfo = dao.selectMdtrtId(settleFee.getInpatientNo(), settleFee.getAdmissTimes(), settleFee.getLedgerSn());
  293. if (null == medinfo) {
  294. medinfo = new BriefMdtrtInfo();
  295. }
  296. // 医保病人进行医保结算
  297. if (StringUtil.notBlank(medinfo.getMdtrtId())) {
  298. dao.deleteZyLedgerFileYb(settleFee.getInpatientNo(), settleFee.getAdmissTimes(), settleFee.getLedgerSn());
  299. // 如果医院支付为正,则 现金支付 = 现金支付 + 医院支付
  300. if (!settleFee.getHospitalPay().startsWith("-")) {
  301. settleFee.setXjzf(DecimalUtil.add(settleFee.getXjzf(), settleFee.getHospitalPay()));
  302. }
  303. if (dao.insertZyLedgerFileYb(settleFee) < 1) {
  304. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  305. exception.setMessage("写医保结算表失败。");
  306. throw new BizException(exception);
  307. }
  308. } else {
  309. dao.clearMedinsInfo(settleFee.getInpatientNo(), settleFee.getAdmissTimes(), null);
  310. }
  311. if (writeReceiptTable(settleFee) < 1) {
  312. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  313. exception.setMessage("写发票表失败。");
  314. throw new BizException(exception);
  315. }
  316. int code = settleFee.getMidSetl() ? hisMiddleSettle(settleFee) : setHisStatusOut(settleFee);
  317. if (updateCostStatusToSettled(settleFee, StringUtil.notBlank(medinfo.getMdtrtId())) < 1) {
  318. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  319. exception.setMessage("更新费用状态失败。");
  320. throw new BizException(exception);
  321. }
  322. if (code < 1) {
  323. ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
  324. exception.setMessage("更新操作日志失败。" + code);
  325. throw new BizException(exception);
  326. }
  327. return ResultVoUtil.success();
  328. }
  329. private int writeReceiptTable(MedinsSettleFee indata) {
  330. if (dao.beforeWriteReceiptTable(indata.getInpatientNo(), indata.getAdmissTimes(),
  331. indata.getLedgerSn()) < 1) {
  332. return -1;
  333. }
  334. Date admissDate = getBegntime(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(), indata.getTable());
  335. Date dismissDate = getEndtime(indata.getMidSetl(), indata.getInpatientNo(), indata.getAdmissTimes(),
  336. indata.getZjdzDatetime());
  337. Date tempendtime = indata.getMidSetl() ? dismissDate : DateUtil.parse("2999-12-31 23:59:59");
  338. ReceiptEntity receiptEntity = dismissFeeAnalyse(indata.getInpatientNo(), indata.getAdmissTimes(),
  339. indata.getLedgerSn(), admissDate, tempendtime);
  340. if (indata.getLedgerSn() > 1) {
  341. admissDate = DateUtil.addOneSecond(admissDate);
  342. }
  343. if (dao.writeReceiptTable(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(), 1,
  344. admissDate, dismissDate, indata.getWardCode(), indata.getDeptCode(), dismissDate, "01",
  345. indata.getStaffId(), receiptEntity.getAdult()) < 1) {
  346. return -1;
  347. }
  348. if (null != receiptEntity.getInfant()) {
  349. return dao.writeReceiptTable(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getLedgerSn(), 4,
  350. admissDate, dismissDate, indata.getWardCode(), indata.getDeptCode(), dismissDate, "04",
  351. indata.getStaffId(), receiptEntity.getInfant());
  352. }
  353. return 1;
  354. }
  355. private ReceiptEntity dismissFeeAnalyse(String patNo, int times, int ledgerSn, Date begntime, Date endtime) {
  356. Map<String, String> ledgerMap = initReceiptMap();
  357. Map<String, String> infantMap = initReceiptMap();
  358. Map<String, String> adultMap = initReceiptMap();
  359. List<ReceiptFee> ledgerFees = dao.selectLedgerFees(patNo, times, ledgerSn, begntime, endtime);
  360. if (null == ledgerFees) {
  361. ledgerFees = new ArrayList<>();
  362. }
  363. for (ReceiptFee fee : ledgerFees) {
  364. ledgerMap.replace(fee.getBillCode(), fee.getLedgerFee());
  365. ledgerMap.replace("total", DecimalUtil.add(ledgerMap.get("total"), fee.getLedgerFee()));
  366. infantMap.replace(fee.getBillCode(), fee.getInfantFee());
  367. infantMap.replace("total", DecimalUtil.add(infantMap.get("total"), fee.getInfantFee()));
  368. adultMap.replace(fee.getBillCode(), fee.getAdultFee());
  369. adultMap.replace("total", DecimalUtil.add(adultMap.get("total"), fee.getAdultFee()));
  370. }
  371. String restype = dao.selectResponceType(patNo, times, ledgerSn);
  372. if (StringUtil.isBlank(restype)) {
  373. restype = "01";
  374. }
  375. if (restype.equals("01")) {
  376. String injurySerialNo = dao.selectInjurySerialNo(patNo, times, ledgerSn);
  377. if (StringUtil.notBlank(injurySerialNo)) {
  378. restype = "al";
  379. }
  380. }
  381. String deposit = dao.selectDepositSumamt(patNo, times, ledgerSn);
  382. if (StringUtil.isBlank(deposit)) {
  383. deposit = "0";
  384. }
  385. String balance = DecimalUtil.minus(deposit, ledgerMap.get("total"));
  386. dao.updateZyLedgerFileCharges(patNo, times, ledgerSn, deposit, balance, restype, ledgerMap);
  387. ReceiptEntity entity = new ReceiptEntity();
  388. if (DecimalUtil.compare(infantMap.get("total"), "0") == 1) {
  389. String patNo1 = patNo + "$1";
  390. String patNo6 = patNo + "$6";
  391. dao.updateInfantfee(patNo1, patNo6, times, infantMap);
  392. entity.setInfant(infantMap);
  393. }
  394. String totalCost = dao.selectTotalCharge(patNo, times);
  395. dao.updateZyActpatientCharges(patNo, totalCost, balance, restype, ledgerMap);
  396. entity.setAdult(adultMap);
  397. return entity;
  398. }
  399. private Map<String, String> initReceiptMap() {
  400. Map<String, String> map = new HashMap<>();
  401. map.put("total", "0.00");
  402. List<String> billCodes = dao.selectBillCodes();
  403. billCodes.forEach(itm -> map.put(itm, "0.00"));
  404. return map;
  405. }
  406. public Date getBegntime(String patNo, int times, int ledgerSn, String table) {
  407. return ledgerSn > 1 ? dao.selectLastLedgerAccountDate(patNo, times, ledgerSn) :
  408. dao.selectAdmissDate(patNo, times, table);
  409. }
  410. private Date getEndtime(Boolean midsetl, String patNo, Integer times, Date zjdzDate) {
  411. if (midsetl) {
  412. return zjdzDate;
  413. }
  414. Date disdate = dao.selectActOrderDisDate(patNo, times);
  415. if (null == disdate) {
  416. disdate = dao.selectActOrderDisDate2(patNo, times);
  417. }
  418. return disdate;
  419. }
  420. private int updateCostStatusToSettled(MedinsSettleFee settle, boolean medins) {
  421. if (dao.updateZyDetailCharge(settle.getInpatientNo(), settle.getAdmissTimes(), settle.getLedgerSn()) < 1) {
  422. return -1;
  423. }
  424. if (!settle.getMidSetl()) {
  425. settle.setZjdzDatetime(new Date());
  426. }
  427. if (medins) {
  428. int hasInfant = dao.hasInfant(settle.getInpatientNo(), settle.getAdmissTimes());
  429. if (hasInfant == 0) {
  430. return dao.updateCostStatusWithoutInfant(settle);
  431. }
  432. return dao.updateCostStatusWithInfant(settle);
  433. }
  434. return dao.updateZifeiCostStatus(settle);
  435. }
  436. private int setHisStatusOut(MedinsSettleFee settle) {
  437. final Date disDate;
  438. if ("zy_actpatient".equals(settle.getTable())) {
  439. disDate = dao.selectActOrderDisDate(settle.getInpatientNo(), settle.getAdmissTimes());
  440. } else {
  441. disDate = dao.selectActOrderDisDate2(settle.getInpatientNo(), settle.getAdmissTimes());
  442. }
  443. if (dao.updateZyActpatient(settle.getInpatientNo(), settle.getAdmissTimes(),
  444. disDate, settle.getStaffId(), settle.getTable()) < 1) {
  445. return -1;
  446. }
  447. if ("zy_actpatient".equals(settle.getTable())) {
  448. dao.deleteZyInactpatient(settle.getInpatientNo(), settle.getAdmissTimes());
  449. if (dao.insertZyInactpatient(settle.getInpatientNo(), settle.getAdmissTimes()) < 1) {
  450. return -2;
  451. }
  452. }
  453. final String patNo1 = settle.getInpatientNo() + "$1";
  454. final String patNo6 = settle.getInpatientNo() + "$6";
  455. dao.updateZyActpatientAgain(patNo1, patNo6, settle.getAdmissTimes(), disDate, settle.getTable());
  456. if ("zy_actpatient".equals(settle.getTable())) {
  457. dao.insertZyInactpatientAgain(patNo1, patNo6, settle.getAdmissTimes());
  458. }
  459. if (dao.updateZyAdt(settle.getInpatientNo(), settle.getAdmissTimes(), settle.getWardCode(), settle.getDeptCode(),
  460. settle.getBedNo(), disDate) < 1) {
  461. return -3;
  462. }
  463. dao.updateZyBedMi(settle.getInpatientNo(), settle.getAdmissTimes());
  464. dao.deleteZyActpatient(settle.getInpatientNo());
  465. dao.deleteZyActpatientAgain(patNo1, patNo6, settle.getAdmissTimes());
  466. return insertNewZyWorkLog(settle);
  467. }
  468. private int insertNewZyWorkLog(MedinsSettleFee param) {
  469. final String userName = dao.getOperateName(param.getStaffId());
  470. String logType = param.getMidSetl() ? "zjdz" : "cyjs";
  471. return dao.insertNewZyWorkLog(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn(),
  472. param.getWardCode(), logType, param.getDeptCode(), param.getStaffId(), userName);
  473. }
  474. private int hisMiddleSettle(MedinsSettleFee param) {
  475. param.setLedgerSn(dao.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes()));
  476. int newLedgerSn = param.getLedgerSn() + 1;
  477. dao.updateTimesBilledByIncreaseOne(param.getInpatientNo(), param.getAdmissTimes(), param.getTable());
  478. dao.insertNewLedgerFile(param.getInpatientNo(), param.getAdmissTimes(), newLedgerSn);
  479. dao.updateFeesLedgerSn(param.getInpatientNo(), param.getAdmissTimes(), newLedgerSn,
  480. param.getLedgerSn(), param.getZjdzDatetime());
  481. dao.updateZyLedgerFileTotalCharge(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn());
  482. dao.updateZyLedgerFileTotalCharge(param.getInpatientNo(), param.getAdmissTimes(), newLedgerSn);
  483. dao.clearMedinsInfo(param.getInpatientNo(), param.getAdmissTimes(), DateUtil.addOneSecond(param.getZjdzDatetime()));
  484. return insertNewZyWorkLog(param);
  485. }
  486. private void updateHicNo(String zyh) {
  487. String hicNoNew = dao.getHicNoNew(zyh);
  488. if (null != hicNoNew) {
  489. if (hicNoNew.length() > 16) {
  490. hicNoNew = hicNoNew.substring(0, 16);
  491. }
  492. dao.updateCpy(zyh, hicNoNew);
  493. if (hicNoNew.length() > 10) {
  494. hicNoNew = hicNoNew.substring(0, 10);
  495. }
  496. dao.updateHic(zyh, hicNoNew);
  497. }
  498. }
  499. }