SiQueryService.java 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  1. package thyyxxk.webserver.service.medicalinsurance;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import thyyxxk.webserver.config.exception.BizException;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.YesOrNo;
  10. import thyyxxk.webserver.constants.sidicts.*;
  11. import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao;
  12. import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao;
  13. import thyyxxk.webserver.entity.ResultVo;
  14. import thyyxxk.webserver.entity.dictionary.CodeName;
  15. import thyyxxk.webserver.entity.markmtfees.MzVisit;
  16. import thyyxxk.webserver.entity.medicalinsurance.inpatient.InHspPsnInfo;
  17. import thyyxxk.webserver.entity.medicalinsurance.outpatient.SpcChrDiseAcct;
  18. import thyyxxk.webserver.entity.medicalinsurance.query.*;
  19. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail;
  20. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
  21. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.TimesList;
  22. import thyyxxk.webserver.entity.medicalinsurance.setllist.*;
  23. import thyyxxk.webserver.entity.inpatient.ZyActpatient;
  24. import thyyxxk.webserver.service.redislike.RedisLikeService;
  25. import thyyxxk.webserver.utils.*;
  26. import java.math.BigDecimal;
  27. import java.time.LocalDate;
  28. import java.util.*;
  29. /**
  30. * @description: 医保查询服务
  31. * @author: DingJie
  32. * @create: 2021-06-23 16:35:23
  33. **/
  34. @Slf4j
  35. @Service
  36. public class SiQueryService {
  37. private static final String RESULT_CODE = "infcode";
  38. private static final String ERROR_MESSAGE = "err_msg";
  39. private static final String OUTPUT = "output";
  40. private final ExecService exec;
  41. private final SiQueryDao dao;
  42. private final SiSetlinfoDao setlinfoDao;
  43. private final RedisLikeService redis;
  44. @Autowired
  45. public SiQueryService(ExecService exec, SiQueryDao dao, SiSetlinfoDao setlinfoDao, RedisLikeService redis) {
  46. this.exec = exec;
  47. this.dao = dao;
  48. this.setlinfoDao = setlinfoDao;
  49. this.redis = redis;
  50. }
  51. public ResultVo<SiPatInfo> getSiPatInfo(QryPsnBsInfo qryPsnBsInfo) {
  52. SiPatInfo siPatInfo = dao.selectSiPatInfo(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes(), qryPsnBsInfo.getLedgerSn());
  53. if (null == siPatInfo) {
  54. siPatInfo = new SiPatInfo();
  55. }
  56. return ResultVoUtil.success(siPatInfo);
  57. }
  58. public String fetchPsnNo(String socialNo, String admdvs) {
  59. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OBTAIN_BASIC_PERSON_INFO, admdvs);
  60. JSONObject data = new JSONObject();
  61. data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  62. String psnCertType = dao.selectPsnCertTypeBoSocialNo(socialNo);
  63. psnCertType = StringUtil.isBlank(psnCertType) ? PsnCertType.RESIDENT_IDENTITY_CARD.getCode() : psnCertType;
  64. data.put("psn_cert_type", psnCertType);
  65. data.put("mdtrt_cert_no", socialNo);
  66. data.put("certno", socialNo);
  67. input.getJSONObject("input").put("data", data);
  68. JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO);
  69. log.info("【操作员:{}】,人员基本信息获取:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  70. if (null == result) {
  71. return ExceptionEnum.NETWORK_ERROR.getMessage();
  72. }
  73. if (null == result.getInteger(RESULT_CODE)) {
  74. return "医保中心报错:" + result.getString("message");
  75. }
  76. if (result.getIntValue(RESULT_CODE) == 0) {
  77. JSONObject output = result.getJSONObject(OUTPUT);
  78. JSONObject baseinfo = output.getJSONObject("baseinfo");
  79. String psnNo = baseinfo.getString("psn_no");
  80. if (StringUtil.notBlank(psnNo)) {
  81. return "SUCCESS:" + psnNo;
  82. }
  83. }
  84. return "无法查询到患者的医保个人编码。";
  85. }
  86. public ResultVo<PsnBaseInfo> obtainBasicPersonInfo(QryPsnBsInfo qryPsnBsInfo) {
  87. if (null == qryPsnBsInfo.getOnlyQry() && StringUtil.isBlank(qryPsnBsInfo.getMedType())) {
  88. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请选择患者的医疗类别!");
  89. }
  90. if (StringUtil.isBlank(qryPsnBsInfo.getSocialNo()) && StringUtil.notBlank(qryPsnBsInfo.getPatNo())
  91. && qryPsnBsInfo.getPatNo().length() >= 15) {
  92. qryPsnBsInfo.setSocialNo(qryPsnBsInfo.getPatNo());
  93. }
  94. if (StringUtil.isBlank(qryPsnBsInfo.getSocialNo())) {
  95. QryPsnBsInfo qpbi = dao.selectMzSocialAndName(qryPsnBsInfo.getPatNo());
  96. if (null == qpbi || StringUtil.isBlank(qpbi.getSocialNo())) {
  97. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的证件号码不能为空,请补充!");
  98. }
  99. if (null == qryPsnBsInfo.getTimes()) {
  100. qryPsnBsInfo.setTimes(qpbi.getTimes());
  101. }
  102. qryPsnBsInfo.setName(qpbi.getName());
  103. qryPsnBsInfo.setSocialNo(qpbi.getSocialNo());
  104. qryPsnBsInfo.setPsnCertType(qpbi.getPsnCertType());
  105. qryPsnBsInfo.setLedgerSn(0);
  106. }
  107. if (null != qryPsnBsInfo.getLedgerSn() && qryPsnBsInfo.getLedgerSn() != 0) {
  108. qryPsnBsInfo.setLedgerSn(dao.selectMaxLedgerSn(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes()));
  109. }
  110. if (StringUtil.isBlank(qryPsnBsInfo.getStaffId())) {
  111. qryPsnBsInfo.setStaffId(TokenUtil.getInstance().getTokenUserId());
  112. }
  113. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OBTAIN_BASIC_PERSON_INFO, qryPsnBsInfo.getAdmdvs());
  114. JSONObject data = new JSONObject();
  115. String psnCertType = StringUtil.isBlank(qryPsnBsInfo.getPsnCertType()) ?
  116. dao.selectPsnCertType(qryPsnBsInfo.getPatNo()) : qryPsnBsInfo.getPsnCertType();
  117. psnCertType = StringUtil.isBlank(psnCertType) ? PsnCertType.RESIDENT_IDENTITY_CARD.getCode() : psnCertType;
  118. data.put("psn_cert_type", psnCertType);
  119. data.put("mdtrt_cert_type", psnCertType.equals("01") ? MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode() : MdtrtCertType.OTHER.getCode());
  120. data.put("mdtrt_cert_no", qryPsnBsInfo.getSocialNo());
  121. data.put("certno", qryPsnBsInfo.getSocialNo());
  122. if (StringUtil.notBlank(qryPsnBsInfo.getName())) {
  123. data.put("psn_name", qryPsnBsInfo.getName());
  124. }
  125. input.getJSONObject("input").put("data", data);
  126. JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO);
  127. log.info("【操作员:{}】,人员基本信息获取:\n参数:{},\n结果:{}", qryPsnBsInfo.getStaffId(), input, result);
  128. if (null == result) {
  129. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  130. }
  131. if (null == result.getInteger(RESULT_CODE)) {
  132. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  133. }
  134. if (result.getIntValue(RESULT_CODE) == 0) {
  135. JSONObject output = result.getJSONObject(OUTPUT);
  136. JSONObject baseinfo = output.getJSONObject("baseinfo");
  137. PsnBaseInfo psnBaseinfo = JSONObject.parseObject(baseinfo.toJSONString(), PsnBaseInfo.class);
  138. psnBaseinfo.setPatNo(qryPsnBsInfo.getPatNo());
  139. psnBaseinfo.setTimes(qryPsnBsInfo.getTimes());
  140. psnBaseinfo.setLedgerSn(qryPsnBsInfo.getLedgerSn());
  141. psnBaseinfo.setMedType(qryPsnBsInfo.getMedType());
  142. psnBaseinfo.setGendName(Gend.get(psnBaseinfo.getGend()).getName());
  143. psnBaseinfo.setPsnCertTypeName(PsnCertType.get(psnBaseinfo.getPsnCertType()).getName());
  144. Naty naty = Naty.get(psnBaseinfo.getNaty());
  145. if (null != naty) {
  146. psnBaseinfo.setNatyName(naty.getName());
  147. }
  148. List<IdetInfo> idetInfos = new ArrayList<>();
  149. JSONArray idet = output.getJSONArray("idetinfo");
  150. for (int i = 0; i < idet.size(); i++) {
  151. JSONObject item = idet.getJSONObject(i);
  152. IdetInfo info = JSONObject.parseObject(item.toJSONString(), IdetInfo.class);
  153. PsnIdetType psnIdetType = PsnIdetType.get(info.getPsnIdetType());
  154. if (null != psnIdetType) {
  155. psnBaseinfo.setPsnIdetType(psnIdetType.getCode());
  156. info.setPsnIdetTypeName(psnIdetType.getName());
  157. }
  158. idetInfos.add(info);
  159. }
  160. if (StringUtil.notBlank(psnBaseinfo.getPsnIdetType())) {
  161. dao.updatePsnIdetType(psnBaseinfo.getPsnIdetType(), psnBaseinfo.getPsnNo());
  162. }
  163. psnBaseinfo.setIdetinfo(idetInfos);
  164. if (new Integer(1).equals(qryPsnBsInfo.getNeedSaving())) {
  165. dao.updateZyActpatient(psnBaseinfo);
  166. psnBaseinfo.setBalc("0");
  167. int saved = dao.selectSiZyInfoCount(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes(), qryPsnBsInfo.getLedgerSn());
  168. if (saved == 0) {
  169. dao.insertSiZyInfoPsnNo(psnBaseinfo);
  170. } else {
  171. dao.updateSiZyInfoPsnNo(psnBaseinfo);
  172. }
  173. log.info("患者基本信息已更新:{}", psnBaseinfo);
  174. output.put("times", qryPsnBsInfo.getTimes());
  175. }
  176. List<InsuInfo> list = new ArrayList<>();
  177. JSONArray insuinfo = output.getJSONArray("insuinfo");
  178. for (int i = 0; i < insuinfo.size(); i++) {
  179. JSONObject item = insuinfo.getJSONObject(i);
  180. InsuInfo info = JSONObject.parseObject(item.toJSONString(), InsuInfo.class);
  181. Insutype insutype = Insutype.get(info.getInsutype());
  182. if (null != insutype) {
  183. info.setInsutypeName(insutype.getName());
  184. }
  185. PsnType psnType = PsnType.get(info.getPsnType());
  186. if (null != psnType) {
  187. info.setPsnTypeName(psnType.getName());
  188. }
  189. if (null != info.getPsnInsuStas()) {
  190. if (info.getPsnInsuStas().equals(YesOrNo.YES.getCodeStr())) {
  191. info.setPsnInsuStasName("正常参保");
  192. } else {
  193. info.setPsnInsuStasName("暂停参保");
  194. }
  195. }
  196. if (null != info.getCvlservFlag()) {
  197. if (info.getCvlservFlag().equals(YesOrNo.YES.getCodeStr())) {
  198. info.setCvlservFlagName("是");
  199. } else {
  200. info.setCvlservFlagName("否");
  201. }
  202. }
  203. info.setInsuplcAdmdvsName(redis.getRegionName(info.getInsuplcAdmdvs()));
  204. list.add(info);
  205. }
  206. psnBaseinfo.setInsuinfo(list);
  207. return ResultVoUtil.success(psnBaseinfo);
  208. }
  209. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  210. }
  211. public ResultVo<List<MedInsInfo>> obtainMedicalInstitutionInfo(String type, String fuzzyName) {
  212. JSONObject input = exec.makeTradeHeader(SiFunction.OBTAIN_MEDICAL_INSTITUTION_INFO);
  213. JSONObject medinsinfo = new JSONObject();
  214. medinsinfo.put("fixmedins_type", type);
  215. medinsinfo.put("fixmedins_name", fuzzyName);
  216. input.getJSONObject("input").put("medinsinfo", medinsinfo);
  217. JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_MEDICAL_INSTITUTION_INFO);
  218. log.info("【操作员:{}】,获取定点医药机构信息:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  219. if (null == result) {
  220. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  221. }
  222. if (null == result.getInteger(RESULT_CODE)) {
  223. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  224. }
  225. if (result.getIntValue(RESULT_CODE) == 0) {
  226. JSONArray output = result.getJSONObject(OUTPUT).getJSONArray("medinsinfo");
  227. List<MedInsInfo> list = new ArrayList<>();
  228. for (int i = 0; i < output.size(); i++) {
  229. JSONObject item = output.getJSONObject(i);
  230. MedInsInfo info = JSONObject.parseObject(item.toJSONString(), MedInsInfo.class);
  231. info.setFixmedinsAdmdvs(info.getFixmedinsCode().substring(1, 7));
  232. info.setFixmedinsAdmdvsName(redis.getRegionName(info.getFixmedinsAdmdvs()));
  233. FixmedinsType fixmedinsType = FixmedinsType.get(info.getFixmedinsType());
  234. if (null != fixmedinsType) {
  235. info.setFixmedinsTypeName(fixmedinsType.getName());
  236. }
  237. HospLv hospLv = HospLv.get(info.getHospLv());
  238. if (null != hospLv) {
  239. info.setHospLvName(hospLv.getName());
  240. }
  241. list.add(info);
  242. }
  243. return ResultVoUtil.success(list);
  244. }
  245. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  246. }
  247. public ResultVo<List<MdtrtInfo>> queryVisitInfo(BscQryPrm q) {
  248. CodeName codeName = dao.selectPsnNoByPatNoAndMedType(q.getPatNo(), q.getMedType());
  249. if (null == codeName) {
  250. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到患者该医疗类别的我院就诊记录。");
  251. }
  252. q.setPsnNo(codeName.getName());
  253. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_VISIT_INFO, codeName.getCode());
  254. String ref = JSONObject.toJSONStringWithDateFormat(q, "yyyy-MM-dd HH:mm:ss");
  255. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  256. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_VISIT_INFO);
  257. log.info("【操作员:{}】,查询就诊信息:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  258. if (null == result) {
  259. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  260. }
  261. if (null == result.getInteger(RESULT_CODE)) {
  262. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  263. }
  264. if (result.getIntValue(RESULT_CODE) == 0) {
  265. JSONObject output = result.getJSONObject(OUTPUT);
  266. JSONArray mdts = output.getJSONArray("mdtrtinfo");
  267. List<MdtrtInfo> list = new ArrayList<>();
  268. for (int i = 0; i < mdts.size(); i++) {
  269. JSONObject item = mdts.getJSONObject(i);
  270. MdtrtInfo mdtrtInfo = JSONObject.parseObject(item.toJSONString(), MdtrtInfo.class);
  271. if (null != mdtrtInfo.getInsuOptins()) {
  272. mdtrtInfo.setInsuOptinsName(redis.getRegionName(mdtrtInfo.getInsuOptins()));
  273. }
  274. SiEnumReflectUtil.mdtrtInfoReflect(mdtrtInfo);
  275. list.add(mdtrtInfo);
  276. }
  277. return ResultVoUtil.success(list);
  278. }
  279. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  280. }
  281. public ResultVo<List<DiseInfo>> queryDiagnosisInfo(BscQryPrm q) {
  282. String admdvs = dao.selectAdmdvsByPsnNo(q.getPsnNo());
  283. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_DIAGNOSIS_INFO, admdvs);
  284. JSONObject data = new JSONObject();
  285. data.put("psn_no", q.getPsnNo());
  286. data.put("mdtrt_id", q.getMdtrtId());
  287. input.getJSONObject("input").put("data", data);
  288. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_DIAGNOSIS_INFO);
  289. log.info("【操作员:{}】,查询诊断信息:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  290. if (null == result) {
  291. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  292. }
  293. if (null == result.getInteger(RESULT_CODE)) {
  294. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  295. }
  296. if (result.getIntValue(RESULT_CODE) == 0) {
  297. JSONObject output = result.getJSONObject(OUTPUT);
  298. List<DiseInfo> list = new ArrayList<>();
  299. JSONArray diseInfos = output.getJSONArray("diseinfo");
  300. for (int i = 0; i < diseInfos.size(); i++) {
  301. JSONObject item = diseInfos.getJSONObject(i);
  302. DiseInfo diseInfo = JSONObject.parseObject(item.toJSONString(), DiseInfo.class);
  303. SiEnumReflectUtil.diseInfoReflect(diseInfo);
  304. list.add(diseInfo);
  305. }
  306. return ResultVoUtil.success(list);
  307. }
  308. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  309. }
  310. public ResultVo<SetlInfo> querySettlementInfo(BscQryPrm q) {
  311. SiPatInfo siPatInfo = getSiPatInfo(q);
  312. if (null == siPatInfo) {
  313. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者的医保登记信息!");
  314. }
  315. JSONObject output = execute5203(siPatInfo);
  316. JSONObject obj = output.getJSONObject("setlinfo");
  317. if (null == obj) {
  318. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到该次就诊的结算明细。");
  319. }
  320. SetlInfo setlInfo = JSONObject.parseObject(obj.toJSONString(), SetlInfo.class);
  321. ClrType clrType = ClrType.get(setlInfo.getClrType());
  322. if (null != clrType) {
  323. setlInfo.setClrTypeName(clrType.getName());
  324. }
  325. MedType medType = MedType.get(setlInfo.getMedType());
  326. if (null != medType) {
  327. setlInfo.setMedTypeName(medType.getName());
  328. }
  329. PsnType psnType = PsnType.get(setlInfo.getPsnType());
  330. if (null != psnType) {
  331. setlInfo.setPsnTypeName(psnType.getName());
  332. }
  333. Insutype insutype = Insutype.get(setlInfo.getInsutype());
  334. if (null != insutype) {
  335. setlInfo.setInsutypeName(insutype.getName());
  336. }
  337. JSONArray setldetail = output.getJSONArray("setldetail");
  338. if (null != setldetail && !setldetail.isEmpty()) {
  339. List<SiSetldetail> list = new ArrayList<>();
  340. for (int i = 0; i < setldetail.size(); i++) {
  341. SiSetldetail setldtel = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class);
  342. FundPayType fundPayType = FundPayType.get(setldtel.getFundPayType());
  343. if (null != fundPayType) {
  344. setldtel.setFundPayTypeName(fundPayType.getName());
  345. }
  346. list.add(setldtel);
  347. }
  348. setlInfo.setSetldetail(list);
  349. }
  350. return ResultVoUtil.success(setlInfo);
  351. }
  352. public SiPatInfo getSiPatInfo(BscQryPrm q) {
  353. if (null == q.getMdtrtId()) {
  354. if (null == q.getLedgerSn()) {
  355. q.setLedgerSn(0);
  356. }
  357. return dao.selectSiPatInfo(q.getPatNo(), q.getTimes(), q.getLedgerSn());
  358. }
  359. return dao.selectSiPatInfoByMdtrtId(q.getMdtrtId());
  360. }
  361. public JSONObject execute5203(SiPatInfo siPatInfo) {
  362. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SETTLEMENT_INFO, siPatInfo.getInsuplcAdmdvs());
  363. JSONObject data = new JSONObject();
  364. data.put("psn_no", siPatInfo.getPsnNo());
  365. data.put("setl_id", siPatInfo.getSetlId());
  366. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  367. input.getJSONObject("input").put("data", data);
  368. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SETTLEMENT_INFO);
  369. log.info("【操作员:{}】,查询结算信息:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  370. if (null == result) {
  371. throw new BizException(ExceptionEnum.NETWORK_ERROR);
  372. }
  373. if (null == result.getInteger(RESULT_CODE)) {
  374. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  375. }
  376. if (result.getIntValue(RESULT_CODE) == 0) {
  377. JSONObject output = result.getJSONObject(OUTPUT);
  378. if (null == output.getJSONObject("setlinfo").getString("setl_id")) {
  379. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者的医保结算信息。");
  380. }
  381. return output;
  382. }
  383. throw new BizException(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  384. }
  385. public ResultVo<Map<String, Object>> queryFeeDetails(QryFeeDetl q) {
  386. SiPatInfo psninfo = dao.selectSiPatInfoByMdtrtId(q.getMdtrtId());
  387. if (null == psninfo) {
  388. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的医保登记信息。");
  389. }
  390. Map<String, Object> map = new HashMap<>();
  391. map.put("psninfo", psninfo);
  392. if (!q.getType().equals("settled")) {
  393. List<SiSetlFeeDetl> list = dao.selectTempCharge(psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn());
  394. if (null == list || list.isEmpty()) {
  395. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有已经上传的医保费用。");
  396. }
  397. map.put("feedtle", list);
  398. map.put("analyse", analyseFeedtle(list));
  399. return ResultVoUtil.success(map);
  400. }
  401. List<SiSetlFeeDetl> list = dao.selectFeeDetlList(psninfo.getMdtrtId(), psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn());
  402. if (!list.isEmpty()) {
  403. map.put("feedtle", list);
  404. map.put("analyse", analyseFeedtle(list));
  405. return ResultVoUtil.success(map);
  406. }
  407. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, psninfo.getInsuplcAdmdvs());
  408. JSONObject data = new JSONObject();
  409. data.put("psn_no", psninfo.getPsnNo());
  410. data.put("setl_id", psninfo.getSetlId());
  411. data.put("mdtrt_id", psninfo.getMdtrtId());
  412. input.getJSONObject("input").put("data", data);
  413. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS);
  414. log.info("【操作员:{}】,【就诊信息查询】查询费用明细:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  415. if (null == result) {
  416. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  417. }
  418. if (null == result.getInteger(RESULT_CODE)) {
  419. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  420. }
  421. if (result.getIntValue(RESULT_CODE) == 0) {
  422. JSONArray output = result.getJSONArray(OUTPUT);
  423. if (null == output || output.isEmpty()) {
  424. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到费用明细。");
  425. }
  426. for (int i = 0; i < output.size(); i++) {
  427. JSONObject feeJson = output.getJSONObject(i);
  428. String feedetlSn = feeJson.getString("feedetl_sn");
  429. if (feedetlSn.contains("_")) {
  430. String[] arr = feedetlSn.split("_");
  431. feeJson.replace("feedetl_sn", arr[arr.length - 1]);
  432. }
  433. list.add(JSONObject.parseObject(feeJson.toJSONString(), SiSetlFeeDetl.class));
  434. if (list.size() == 30) {
  435. dao.insertSetlFeeDetlBatch(list);
  436. list.clear();
  437. }
  438. }
  439. if (!list.isEmpty()) {
  440. dao.insertSetlFeeDetlBatch(list);
  441. }
  442. list = dao.selectFeeDetlList(psninfo.getMdtrtId(), psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn());
  443. map.put("feedtle", list);
  444. map.put("analyse", analyseFeedtle(list));
  445. return ResultVoUtil.success(map);
  446. }
  447. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  448. }
  449. private Map<String, String[]> analyseFeedtle(List<SiSetlFeeDetl> fees) {
  450. Map<String, String[]> map = new HashMap<>();
  451. map.put("zhj", new String[]{"合计", "0.00", "0.00", "0.00", "0.00"});
  452. fees.forEach(itm -> {
  453. ChrgitmLv chrgitmLv = ChrgitmLv.get(itm.getChrgitmLv());
  454. if (null == chrgitmLv) {
  455. chrgitmLv = ChrgitmLv.SELF_PAY;
  456. itm.setChrgitmLvName(chrgitmLv.getName());
  457. }
  458. String[] all = map.get("zhj");
  459. sumChargeFeeByType(itm, chrgitmLv, all);
  460. if (map.containsKey(itm.getMedChrgitmType())) {
  461. String[] dtle = map.get(itm.getMedChrgitmType());
  462. sumChargeFeeByType(itm, chrgitmLv, dtle);
  463. } else {
  464. String[] dtle = new String[5];
  465. MedChrgitmType type = MedChrgitmType.get(itm.getMedChrgitmType());
  466. if (type == null) {
  467. type = MedChrgitmType.OTH;
  468. itm.setMedChrgitmType(type.getCode());
  469. }
  470. dtle[0] = type.getName();
  471. dtle[1] = itm.getDetItemFeeSumamt();
  472. switch (chrgitmLv) {
  473. case FIRST_CLASS:
  474. dtle[2] = itm.getDetItemFeeSumamt();
  475. dtle[3] = "0.00";
  476. dtle[4] = "0.00";
  477. break;
  478. case SECOND_CLASS:
  479. dtle[3] = itm.getDetItemFeeSumamt();
  480. dtle[2] = "0.00";
  481. dtle[4] = "0.00";
  482. break;
  483. case SELF_PAY:
  484. dtle[4] = itm.getDetItemFeeSumamt();
  485. dtle[3] = "0.00";
  486. dtle[2] = "0.00";
  487. break;
  488. }
  489. map.put(type.getCode(), dtle);
  490. }
  491. });
  492. String total = map.get("zhj")[1];
  493. for (Map.Entry<String, String[]> entry : map.entrySet()) {
  494. if (!entry.getKey().equals("zhj")) {
  495. String percentage = DecimalUtil.percentage(entry.getValue()[1], total);
  496. entry.getValue()[0] = entry.getValue()[0] + "(" + percentage + ")";
  497. }
  498. }
  499. return map;
  500. }
  501. private void sumChargeFeeByType(SiSetlFeeDetl itm, ChrgitmLv chrgitmLv, String[] dtle) {
  502. dtle[1] = DecimalUtil.add(dtle[1], itm.getDetItemFeeSumamt());
  503. switch (chrgitmLv) {
  504. case FIRST_CLASS:
  505. dtle[2] = DecimalUtil.add(dtle[2], itm.getDetItemFeeSumamt());
  506. break;
  507. case SECOND_CLASS:
  508. dtle[3] = DecimalUtil.add(dtle[3], itm.getDetItemFeeSumamt());
  509. break;
  510. case SELF_PAY:
  511. dtle[4] = DecimalUtil.add(dtle[4], itm.getDetItemFeeSumamt());
  512. break;
  513. }
  514. }
  515. public ResultVo<List<TrtInfo>> checkPersonTreatment(BscQryPrm q) {
  516. String admdvs = q.getAdmdvs();
  517. if (StringUtil.isBlank(admdvs)) {
  518. admdvs = dao.selectAdmdvs(q.getPatNo(), q.getTimes());
  519. }
  520. JSONObject input = exec.makeTradeHeaderWithInsureArea(
  521. SiFunction.CHECK_PERSON_TREATMENT, admdvs);
  522. JSONObject data = new JSONObject();
  523. data.put("psn_no", q.getPsnNo());
  524. data.put("insutype", q.getInsutype());
  525. data.put("fixmedins_code", SiUtil.INSTITUTION_ID);
  526. data.put("med_type", q.getMedType());
  527. data.put("begntime", DateUtil.formatDatetime(q.getBegntime()));
  528. input.getJSONObject("input").put("data", data);
  529. JSONObject result = exec.executeTrade(input, SiFunction.CHECK_PERSON_TREATMENT);
  530. log.info("【操作员:{}】,人员待遇享受检查:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  531. if (null == result) {
  532. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  533. }
  534. if (null == result.getInteger(RESULT_CODE)) {
  535. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  536. }
  537. if (result.getIntValue(RESULT_CODE) == 0) {
  538. List<TrtInfo> list = new ArrayList<>();
  539. JSONObject output = result.getJSONObject(OUTPUT);
  540. JSONArray trtinfo = output.getJSONArray("trtinfo");
  541. for (int i = 0; i < trtinfo.size(); i++) {
  542. JSONObject obj = trtinfo.getJSONObject(i);
  543. TrtInfo item = JSONObject.parseObject(obj.toJSONString(), TrtInfo.class);
  544. TrtChkType trtChkType = TrtChkType.get(item.getTrtChkType());
  545. if (null != trtChkType) {
  546. item.setTrtChkTypeName(trtChkType.getName());
  547. }
  548. FundPayType fundPayType = FundPayType.get(item.getFundPayType());
  549. if (null != fundPayType) {
  550. item.setFundPayTypeName(fundPayType.getName());
  551. }
  552. if (null != item.getTrtEnjymntFlag()) {
  553. if (item.getTrtEnjymntFlag().equals(YesOrNo.YES.getCodeStr())) {
  554. item.setTrtEnjymntFlagName("是");
  555. } else {
  556. item.setTrtEnjymntFlagName("否");
  557. }
  558. }
  559. list.add(item);
  560. }
  561. return ResultVoUtil.success(list);
  562. }
  563. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  564. }
  565. public ResultVo<List<InHspPsnInfo>> queryInHospitalPatientsInfo(BscQryPrm q) {
  566. if (StringUtil.notBlank(q.getPatNo())) {
  567. String psnNo = dao.selectPsnNo(q.getPatNo());
  568. if (null == psnNo) {
  569. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】没有找到此患者在我院的医保在院信息,请核实。");
  570. }
  571. q.setPsnNo(psnNo);
  572. }
  573. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_IN_HOSPITAL_PATIENTS_INFO,
  574. dao.selectAdmdvsByPatNoAndPsnNo(q.getPatNo(), q.getPsnNo()));
  575. JSONObject data = new JSONObject();
  576. data.put("psn_no", q.getPsnNo());
  577. data.put("begntime", DateUtil.formatDatetime(q.getBegntime()));
  578. data.put("endtime", null == q.getEndtime() ? DateUtil.now() : DateUtil.formatDatetime(q.getEndtime()));
  579. input.getJSONObject("input").put("data", data);
  580. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_IN_HOSPITAL_PATIENTS_INFO);
  581. log.info("【操作员:{}】,在院信息查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  582. if (null == result) {
  583. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  584. }
  585. if (null == result.getInteger(RESULT_CODE)) {
  586. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  587. }
  588. if (result.getIntValue(RESULT_CODE) == 0) {
  589. JSONObject output = result.getJSONObject(OUTPUT);
  590. JSONArray pts = output.getJSONArray("data");
  591. if (pts.isEmpty()) {
  592. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到医保在院的患者信息。");
  593. }
  594. List<InHspPsnInfo> list = new ArrayList<>();
  595. for (int i = 0; i < pts.size(); i++) {
  596. JSONObject item = pts.getJSONObject(i);
  597. InHspPsnInfo inHspPsnInfo = JSONObject.parseObject(item.toJSONString(), InHspPsnInfo.class);
  598. SiEnumReflectUtil.inHspPsnInfoReflect(inHspPsnInfo);
  599. list.add(inHspPsnInfo);
  600. }
  601. if (list.size() == 1 && null != q.getTimes()) {
  602. InHspPsnInfo info = list.get(0);
  603. dao.updateInhospInfo(q.getPatNo(), q.getTimes(), q.getLedgerSn(), info.getMdtrtId(), info.getInsutype());
  604. }
  605. return ResultVoUtil.success(list);
  606. }
  607. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  608. }
  609. public ResultVo<List<RefMedin>> queryPersonnelTransferHospitalInfo(BscQryPrm q) {
  610. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_TRANSFER_HOSPITAL_INFO, dao.selectAdmdvsByPatNoAndPsnNo(q.getPatNo(), q.getPsnNo()));
  611. JSONObject data = new JSONObject();
  612. data.put("psn_no", q.getPsnNo());
  613. data.put("begntime", DateUtil.formatDatetime(q.getBegntime()));
  614. data.put("endtime", DateUtil.formatDatetime(q.getEndtime()));
  615. input.getJSONObject("input").put("data", data);
  616. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_TRANSFER_HOSPITAL_INFO);
  617. log.info("【操作员:{}】,转院信息查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  618. if (null == result) {
  619. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  620. }
  621. if (null == result.getInteger(RESULT_CODE)) {
  622. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  623. }
  624. if (result.getIntValue(RESULT_CODE) == 0) {
  625. JSONObject output = result.getJSONObject(OUTPUT);
  626. JSONArray array = output.getJSONArray("refmedin");
  627. if (null == array || array.isEmpty()) {
  628. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到符合条件的转院信息。");
  629. }
  630. List<RefMedin> list = new ArrayList<>();
  631. for (int i = 0; i < array.size(); i++) {
  632. JSONObject obj = array.getJSONObject(i);
  633. RefMedin item = JSONObject.parseObject(obj.toJSONString(), RefMedin.class);
  634. Insutype insutype = Insutype.get(item.getInsutype());
  635. if (null != insutype) {
  636. item.setInsutypeName(insutype.getName());
  637. }
  638. DclaSouc dclaSouc = DclaSouc.get(item.getDclaSouc());
  639. if (null != dclaSouc) {
  640. item.setDclaSoucName(dclaSouc.getName());
  641. }
  642. PsnCertType psnCertType = PsnCertType.get(item.getPsnCertType());
  643. if (null != psnCertType) {
  644. item.setPsnCertTypeName(psnCertType.getName());
  645. }
  646. item.setGendName(Gend.get(item.getGend()).getName());
  647. if (null != item.getInsuOptins()) {
  648. item.setInsuOptinsName(redis.getRegionName(item.getInsuOptins()));
  649. }
  650. if (null != item.getOutFlag()) {
  651. if (item.getOutFlag().equals(YesOrNo.YES.getCodeStr())) {
  652. item.setOutFlagName("是");
  653. } else {
  654. item.setOutFlagName("否");
  655. }
  656. }
  657. if (null != item.getHospAgreReflFlag()) {
  658. if (item.getHospAgreReflFlag().equals(YesOrNo.YES.getCodeStr())) {
  659. item.setHospAgreReflFlagName("是");
  660. } else {
  661. item.setHospAgreReflFlagName("否");
  662. }
  663. }
  664. list.add(item);
  665. }
  666. return ResultVoUtil.success(list);
  667. }
  668. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  669. }
  670. public ResultVo<List<MedUseRcd>> querySpecialChronicDiseasesMedicalRecord(BscQryPrm q) {
  671. if (null == q.getPsnNo()) {
  672. String psnNo = dao.selectPsnNo(q.getPatNo());
  673. if (null == psnNo) {
  674. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】未找到此患者的医保参保信息,请核实。");
  675. }
  676. q.setPsnNo(psnNo);
  677. }
  678. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_MEDICAL_RECORD, dao.selectAdmdvsByPsnNo(q.getPsnNo()));
  679. JSONObject data = new JSONObject();
  680. data.put("psn_no", q.getPsnNo());
  681. data.put("begntime", DateUtil.formatDatetime(q.getBegntime()));
  682. data.put("endtime", DateUtil.formatDatetime(q.getEndtime()));
  683. input.getJSONObject("input").put("data", data);
  684. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_MEDICAL_RECORD);
  685. log.info("【操作员:{}】,人员慢特病用药记录查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  686. if (null == result) {
  687. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  688. }
  689. if (null == result.getInteger(RESULT_CODE)) {
  690. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  691. }
  692. if (result.getIntValue(RESULT_CODE) == 0) {
  693. JSONObject output = result.getJSONObject(OUTPUT);
  694. JSONArray array = output.getJSONArray("feedetail");
  695. if (null == array || array.isEmpty()) {
  696. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到此人的慢特病用药记录。");
  697. }
  698. List<MedUseRcd> list = new ArrayList<>();
  699. for (int i = 0; i < array.size(); i++) {
  700. JSONObject obj = array.getJSONObject(i);
  701. MedUseRcd item = JSONObject.parseObject(obj.toJSONString(), MedUseRcd.class);
  702. list.add(item);
  703. }
  704. return ResultVoUtil.success(list);
  705. }
  706. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  707. }
  708. public ResultVo<List<CumInfo>> queryPersonnelCumulativeInfo(BscQryPrm q) {
  709. String admdvs = q.getAdmdvs();
  710. if (StringUtil.isBlank(admdvs)) {
  711. admdvs = dao.selectAdmdvsByPsnNo(q.getPsnNo());
  712. }
  713. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO, admdvs);
  714. JSONObject data = new JSONObject();
  715. data.put("psn_no", q.getPsnNo());
  716. data.put("cum_ym", q.getCumYm());
  717. input.getJSONObject("input").put("data", data);
  718. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO);
  719. log.info("【操作员:{}】,人员累计信息查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  720. if (null == result) {
  721. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  722. }
  723. if (null == result.getInteger(RESULT_CODE)) {
  724. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  725. }
  726. if (result.getIntValue(RESULT_CODE) == 0) {
  727. JSONObject output = result.getJSONObject(OUTPUT);
  728. JSONArray array = output.getJSONArray("cuminfo");
  729. List<CumInfo> list = new ArrayList<>();
  730. for (int i = 0; i < array.size(); i++) {
  731. JSONObject obj = array.getJSONObject(i);
  732. CumInfo item = JSONObject.parseObject(obj.toJSONString(), CumInfo.class);
  733. Insutype insutype = Insutype.get(item.getInsutype());
  734. if (null != insutype) {
  735. item.setInsutypeName(insutype.getName());
  736. }
  737. list.add(item);
  738. }
  739. return ResultVoUtil.success(list);
  740. }
  741. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  742. }
  743. public ResultVo<List<SpcChrDiseAcct>> querySpecialChronicDiseasesAccreditation(BscQryPrm q) {
  744. if (null == q.getPsnNo()) {
  745. String psnNo = dao.selectPsnNo(q.getPatNo());
  746. if (null == psnNo) {
  747. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】未找到此患者的医保参保信息,请核实。");
  748. }
  749. q.setPsnNo(psnNo);
  750. }
  751. if (StringUtil.isBlank(q.getAdmdvs())) {
  752. String admdvs = StringUtil.isBlank(q.getPatNo()) ? dao.selectAdmdvsByPsnNo(q.getPsnNo()) : dao.selectAdmdvsByPatNo(q.getPatNo());
  753. q.setAdmdvs(admdvs);
  754. }
  755. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION, q.getAdmdvs());
  756. JSONObject data = new JSONObject();
  757. data.put("psn_no", q.getPsnNo());
  758. input.getJSONObject("input").put("data", data);
  759. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION);
  760. log.info("【操作员:{}】,人员慢特病备案查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  761. if (null == result) {
  762. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  763. }
  764. if (null == result.getInteger(RESULT_CODE)) {
  765. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  766. }
  767. if (result.getIntValue(RESULT_CODE) == 0) {
  768. JSONObject output = result.getJSONObject(OUTPUT);
  769. JSONArray details = output.getJSONArray("feedetail");
  770. if (null == details || details.isEmpty()) {
  771. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到此患者的慢特病备案信息。");
  772. }
  773. List<SpcChrDiseAcct> list = new ArrayList<>();
  774. Calendar calendar = Calendar.getInstance();
  775. calendar.add(Calendar.DATE,-1);
  776. Date now = calendar.getTime();
  777. for (int i = 0; i < details.size(); i++) {
  778. JSONObject detail = details.getJSONObject(i);
  779. SpcChrDiseAcct spcChrDiseAcct = JSONObject.parseObject(detail.toJSONString(), SpcChrDiseAcct.class);
  780. if (null != q.getNeedAllRcd() && 1 == q.getNeedAllRcd()) {
  781. list.add(spcChrDiseAcct);
  782. } else {
  783. if (now.before(spcChrDiseAcct.getEnddate())) {
  784. spcChrDiseAcct.setPatNo(q.getPatNo());
  785. spcChrDiseAcct.setTimes(q.getTimes());
  786. list.add(spcChrDiseAcct);
  787. }
  788. }
  789. }
  790. if (!list.isEmpty()) {
  791. return ResultVoUtil.success(list);
  792. }
  793. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
  794. }
  795. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  796. }
  797. public ResultVo<List<PsnFixMedin>> queryPersonnelAssignmentInfo(BscQryPrm q) {
  798. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_ASSIGNMENT_INFO, q.getAdmdvs());
  799. JSONObject data = new JSONObject();
  800. data.put("psn_no", q.getPsnNo());
  801. data.put("biz_appy_type", q.getBizAppyType());
  802. input.getJSONObject("input").put("data", data);
  803. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_ASSIGNMENT_INFO);
  804. log.info("【操作员:{}】,人员定点信息查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  805. if (null == result) {
  806. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  807. }
  808. if (null == result.getInteger(RESULT_CODE)) {
  809. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  810. }
  811. if (result.getIntValue(RESULT_CODE) == 0) {
  812. JSONObject output = result.getJSONObject(OUTPUT);
  813. JSONArray array = output.getJSONArray("psnfixmedin");
  814. if (null == array || array.isEmpty()) {
  815. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的定点信息。");
  816. }
  817. List<PsnFixMedin> list = new ArrayList<>();
  818. for (int i = 0; i < array.size(); i++) {
  819. JSONObject obj = array.getJSONObject(i);
  820. PsnFixMedin item = JSONObject.parseObject(obj.toJSONString(), PsnFixMedin.class);
  821. Insutype insutype = Insutype.get(item.getInsutype());
  822. if (null != insutype) {
  823. item.setInsutypeName(insutype.getName());
  824. }
  825. list.add(item);
  826. }
  827. return ResultVoUtil.success(list);
  828. }
  829. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  830. }
  831. public ResultVo<List<TimesList>> fetchSiTimesList(String patNo, Integer type) {
  832. List<TimesList> list = dao.fetchSiTimesList(patNo, type);
  833. if (type == 11) {
  834. List<TimesList> mipList = dao.getMipayTimesList(patNo + "%");
  835. for (TimesList mip : mipList) {
  836. String[] arr = mip.getHisOrdNum().split("_");
  837. mip.setTimes(Integer.parseInt(arr[1]));
  838. mip.setLedgerSn(0);
  839. list.add(mip);
  840. }
  841. }
  842. if (list.isEmpty()) {
  843. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "此患者没有有效的结算信息。");
  844. }
  845. return ResultVoUtil.success(list);
  846. }
  847. public ResultVo<String> queryInsuplcAdmdvsByMdtrtId(String mdtrtId) {
  848. return ResultVoUtil.success(dao.selectInsuplcAdmdvsByMdtrtId(mdtrtId));
  849. }
  850. public ResultVo<InptntSetlmtLst> queryInpatientSetlList(SetlIndex index) {
  851. if (null == index.getTimes() && StringUtil.isBlank(index.getLabel())) {
  852. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算条目不能为空!");
  853. }
  854. String[] arr = index.getLabel().split("_");
  855. if (StringUtil.notBlank(index.getLabel()) && !index.getPatNo().contains("-")) {
  856. index.setSetlId(arr[0]);
  857. index.setTimes(Integer.parseInt(arr[1]));
  858. index.setLedgerSn(Integer.parseInt(arr[2]));
  859. } else {
  860. index.setLedgerSn(0);
  861. index.setTimes(Integer.parseInt(arr[1]));
  862. index.setSetlId(dao.selectSetlId(index.getPatNo(), index.getTimes(), index.getLedgerSn()));
  863. }
  864. SiPatInfo siPatInfo = dao.selectSiPatInfo(index.getPatNo(), index.getTimes(), index.getLedgerSn());
  865. if (null == siPatInfo) {
  866. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!");
  867. }
  868. CuminfoInYear cuminfo = getYearCuminfo(index.getSetlId(), siPatInfo.getPsnNo(), siPatInfo.getInsuplcAdmdvs());
  869. if (cuminfo.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  870. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, cuminfo.getMessage());
  871. }
  872. InptntSetlmtLst lst;
  873. if (index.getLedgerSn() == 0) {
  874. lst = dao.selectJzSetlinfo(index.getSetlId());
  875. } else {
  876. lst = dao.selectZySetlinfo(index.getSetlId(), "zy_inactpatient");
  877. if (null == lst) {
  878. lst = dao.selectZySetlinfo(index.getSetlId(), "zy_actpatient");
  879. if (null == lst) {
  880. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!");
  881. }
  882. }
  883. }
  884. lst.setInHospdays(DateUtil.daysBetween(lst.getEndtime(), lst.getBegntime()));
  885. PsnIdetType psnIdetType = PsnIdetType.get(lst.getPsnIdetType());
  886. if (null != psnIdetType) {
  887. lst.setPsnIdetTypeName(psnIdetType.getName());
  888. }
  889. Admdvs admdvs = Admdvs.get(lst.getInsuplcAdmdvs());
  890. if (null == admdvs) {
  891. lst.setInsuplcAdmdvsName(redis.getRegionName(lst.getInsuplcAdmdvs()));
  892. } else {
  893. lst.setInsuplcAdmdvsName(admdvs.getName());
  894. }
  895. lst.setFixmedinsName(SiUtil.INSTITUTION_NAME);
  896. lst.setGendName(Gend.get(lst.getGend()).getName());
  897. SiEnumReflectUtil.inptntSetlmtLstReflect(lst);
  898. ResultVo<List<SiSetlFeeDetl>> chrgrsvo = getChrgitems(lst.getPsnNo(), lst.getSetlId(), lst.getMdtrtId(), lst.getInsuplcAdmdvs());
  899. if (!chrgrsvo.getCode().equals(ExceptionEnum.SUCCESS.getCode())) {
  900. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgrsvo.getMessage());
  901. }
  902. ChrgItemLvInfo chrgItemLvInfo = analyzeParticularChrgitmLv(chrgrsvo.getData());
  903. lst.setChrgItemLvInfo(chrgItemLvInfo);
  904. lst.setCuminfo(cuminfo);
  905. ResultVo<PolItemInfo> polItemRes = listPolItemCodePayInfo(lst.getPsnNo(), lst.getMdtrtId(), lst.getSetlId(), lst.getInsuplcAdmdvs());
  906. if (polItemRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  907. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, polItemRes.getMessage());
  908. }
  909. lst.setPolItemInfo(polItemRes.getData());
  910. return ResultVoUtil.success(lst);
  911. }
  912. public ResultVo<OtptntSetlmtLst> queryOutpatientSetlList(SetlIndex index) {
  913. if (null == index.getTimes() && StringUtil.isBlank(index.getLabel())) {
  914. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算条目不能为空!");
  915. }
  916. index.setLedgerSn(0);
  917. if (StringUtil.notBlank(index.getLabel())) {
  918. String[] arr = index.getLabel().split("_");
  919. index.setSetlId(arr[0]);
  920. index.setTimes(Integer.parseInt(arr[1]));
  921. if (arr[2].contains("^")) {
  922. index.setHisOrdNum(arr[2].replaceAll("\\^", "_"));
  923. }
  924. } else {
  925. index.setSetlId(dao.selectSetlId(index.getPatNo(), index.getTimes(), index.getLedgerSn()));
  926. }
  927. SiPatInfo siPatInfo;
  928. if (StringUtil.isBlank(index.getHisOrdNum())) {
  929. siPatInfo = dao.selectSiPatInfo(index.getPatNo(), index.getTimes(), index.getLedgerSn());
  930. } else {
  931. siPatInfo = dao.selectSiPatInfo2(index.getHisOrdNum());
  932. }
  933. if (null == siPatInfo) {
  934. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!");
  935. }
  936. CuminfoInYear cuminfo = getYearCuminfo(index.getSetlId(), siPatInfo.getPsnNo(), siPatInfo.getInsuplcAdmdvs());
  937. if (cuminfo.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  938. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, cuminfo.getMessage());
  939. }
  940. OtptntSetlmtLst lst;
  941. if (StringUtil.isBlank(index.getHisOrdNum())) {
  942. lst = dao.selectMzSetlifo(index.getPatNo(), index.getTimes());
  943. } else {
  944. String hiExtData = dao.getHiExtData(index.getHisOrdNum());
  945. if (StringUtil.isBlank(hiExtData)) {
  946. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!");
  947. }
  948. MzVisit mzVisit = dao.getMzVisit(index);
  949. if (null == mzVisit) {
  950. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的就诊信息!");
  951. }
  952. JSONObject obj = JSONObject.parseObject(hiExtData);
  953. JSONObject setlObj = obj.getJSONObject("setlinfo");
  954. lst = JSONObject.toJavaObject(setlObj, OtptntSetlmtLst.class);
  955. lst.setAdmDeptName(mzVisit.getVisitDeptName());
  956. lst.setBegntime(mzVisit.getVisitDate());
  957. lst.setDiseName(mzVisit.getIcdText().split(",")[0]);
  958. lst.setChfpdrName(mzVisit.getDoctorCode());
  959. }
  960. if (null == lst) {
  961. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!");
  962. }
  963. lst.setPsnCertTypeName(PsnCertType.get(lst.getPsnCertType()).getName());
  964. lst.setPsnIdetTypeName(PsnIdetType.getName(lst.getPsnIdetType()));
  965. lst.setChfpdrName(redis.getEmployeeName(lst.getChfpdrName()));
  966. Admdvs admdvs = Admdvs.get(lst.getInsuplcAdmdvs());
  967. if (null == admdvs) {
  968. lst.setInsuplcAdmdvsName(redis.getRegionName(lst.getInsuplcAdmdvs()));
  969. } else {
  970. lst.setInsuplcAdmdvsName(admdvs.getName());
  971. }
  972. SiEnumReflectUtil.outptntSetlmtLstReflect(lst);
  973. List<BrfChrgitm> chrgitms = dao.selectMzBrfChrgitms(index.getPatNo(), index.getTimes());
  974. lst.setCuminfo(cuminfo);
  975. lst.setFixmedinsName(SiUtil.INSTITUTION_NAME);
  976. Insutype insutype = Insutype.get(lst.getInsutype());
  977. if (insutype == Insutype.BASIC_MEDICAL_INSURANCE_FOR_EMPLOYEES) {
  978. ResultVo<List<SiSetlFeeDetl>> chrgrsvo = getChrgitems(lst.getPsnNo(), lst.getSetlId(), lst.getMdtrtId(), lst.getInsuplcAdmdvs());
  979. if (!chrgrsvo.getCode().equals(ExceptionEnum.SUCCESS.getCode())) {
  980. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgrsvo.getMessage());
  981. }
  982. ChrgItemLvInfo chrgItemLvInfo = analyzeParticularChrgitmLv(chrgrsvo.getData());
  983. lst.setChrgItemLvInfo(chrgItemLvInfo);
  984. ResultVo<PolItemInfo> polItemRes = listPolItemCodePayInfo(lst.getPsnNo(), lst.getMdtrtId(), lst.getSetlId(), lst.getInsuplcAdmdvs());
  985. if (polItemRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  986. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, polItemRes.getMessage());
  987. }
  988. lst.setPolItemInfo(polItemRes.getData());
  989. } else {
  990. analyzeMzChrgitm(lst, chrgitms);
  991. }
  992. return ResultVoUtil.success(lst);
  993. }
  994. private ResultVo<PolItemInfo> listPolItemCodePayInfo(String psnNo, String mdtrtId, String setlId, String insuplc) {
  995. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.LIST_POL_ITEM_CODE_PAY_INFO, insuplc);
  996. JSONObject data = new JSONObject();
  997. data.put("psn_no", psnNo);
  998. data.put("mdtrt_id", mdtrtId);
  999. data.put("setl_id", setlId);
  1000. input.getJSONObject("input").put("data", data);
  1001. JSONObject result = exec.executeTrade(input, SiFunction.LIST_POL_ITEM_CODE_PAY_INFO);
  1002. log.info("【操作员:{}】,政策信息查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  1003. if (null == result) {
  1004. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  1005. }
  1006. if (null == result.getInteger("code")) {
  1007. String message = result.getString("message");
  1008. if (null == message) {
  1009. message = result.getString(ERROR_MESSAGE);
  1010. }
  1011. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + message);
  1012. }
  1013. if (result.getIntValue("code") != 0) {
  1014. String message = result.getString("message");
  1015. if (null == message) {
  1016. message = result.getString(ERROR_MESSAGE);
  1017. }
  1018. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心出错:" + message);
  1019. }
  1020. PolItemInfo polItemInfo = new PolItemInfo();
  1021. JSONArray array = result.getJSONArray("data");
  1022. BigDecimal selfPaySum = new BigDecimal(0);
  1023. BigDecimal fundPaySum = new BigDecimal(0);
  1024. List<PolicyItem> policyItems = new ArrayList<>();
  1025. for (int i = 0; i < array.size(); i++) {
  1026. JSONObject polObj = array.getJSONObject(i);
  1027. PolicyItem policyItem = JSONObject.parseObject(JSONObject.toJSONString(polObj), PolicyItem.class);
  1028. policyItems.add(policyItem);
  1029. selfPaySum = selfPaySum.add(policyItem.getSelfPayAmt());
  1030. fundPaySum = fundPaySum.add(policyItem.getFundPayAmt());
  1031. }
  1032. polItemInfo.setAllPsnAmt(selfPaySum);
  1033. polItemInfo.setAllFundAmt(fundPaySum);
  1034. polItemInfo.setAllSum(fundPaySum.add(selfPaySum));
  1035. polItemInfo.setPolicyItems(policyItems);
  1036. return ResultVoUtil.success(polItemInfo);
  1037. }
  1038. public CuminfoInYear getYearCuminfo(String setlId, String psnNo, String admdvs) {
  1039. CuminfoInYear cuminfo = dao.selectCumInfo(setlId);
  1040. if (null != cuminfo) {
  1041. cuminfo.setCode(ExceptionEnum.SUCCESS.getCode());
  1042. return cuminfo;
  1043. }
  1044. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO, admdvs);
  1045. JSONObject data = new JSONObject();
  1046. data.put("psn_no", psnNo);
  1047. data.put("cum_ym", "");
  1048. input.getJSONObject("input").put("data", data);
  1049. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO);
  1050. cuminfo = new CuminfoInYear();
  1051. if (null == result) {
  1052. cuminfo.setCode(ExceptionEnum.NETWORK_ERROR.getCode());
  1053. cuminfo.setMessage(ExceptionEnum.NETWORK_ERROR.getMessage());
  1054. return cuminfo;
  1055. }
  1056. if (null == result.getInteger(RESULT_CODE)) {
  1057. cuminfo.setCode(ExceptionEnum.LOGICAL_ERROR.getCode());
  1058. cuminfo.setMessage("医保中心报错:" + result.getString("message"));
  1059. return cuminfo;
  1060. }
  1061. if (result.getIntValue(RESULT_CODE) != 0) {
  1062. cuminfo.setCode(ExceptionEnum.NETWORK_ERROR.getCode());
  1063. cuminfo.setMessage("医保中心出错:" + result.getString("message"));
  1064. return cuminfo;
  1065. }
  1066. cuminfo.setCode(ExceptionEnum.SUCCESS.getCode());
  1067. String year = String.valueOf(LocalDate.now().getYear());
  1068. JSONArray cuminfos = result.getJSONObject(OUTPUT).getJSONArray("cuminfo");
  1069. log.info("累计信息:{}", cuminfos);
  1070. for (int i = 0; i < cuminfos.size(); i++) {
  1071. JSONObject itm = cuminfos.getJSONObject(i);
  1072. if (itm.getString("year").equals(year)) {
  1073. switch (itm.getString("cum_type_code")) {
  1074. // 本年住院次数
  1075. case "C0000_BIZ2101":
  1076. case "C0000_BIZ2102":
  1077. case "C0000_BIZ2106":
  1078. case "C0000_BIZ2107":
  1079. case "C0000_BIZ22":
  1080. case "C0000_BIZ52":
  1081. cuminfo.addYearAdmtimesZy(itm.getDoubleValue("cum"));
  1082. break;
  1083. // 本年门诊次数
  1084. case "C0000_BIZ11":
  1085. case "C0000_BIZ13":
  1086. case "C0000_BIZ14":
  1087. case "C0000_BIZ51":
  1088. case "C0000_BIZ9901":
  1089. case "C0000_BIZ9903":
  1090. case "C0000_BIZ9904":
  1091. cuminfo.addYearAdmtimesMz(itm.getDoubleValue("cum"));
  1092. break;
  1093. // 本年度住院分段计算费用累计
  1094. case "S0000_BIZ2101":
  1095. case "S0000_BIZ2102":
  1096. case "S0000_BIZ2106":
  1097. case "S0000_BIZ2107":
  1098. case "S0000_BIZ22":
  1099. case "S0000_BIZ52":
  1100. cuminfo.addYearPeriodFeeSumZy(itm.getDoubleValue("cum"));
  1101. break;
  1102. // 本年度门诊分段计算费用累计
  1103. case "S0000_BIZ11":
  1104. case "S0000_BIZ13":
  1105. case "S0000_BIZ14":
  1106. case "S0000_BIZ51":
  1107. case "S0000_BIZ9901":
  1108. case "S0000_BIZ9903":
  1109. case "S0000_BIZ9904":
  1110. cuminfo.addYearPeriodFeeSumMz(itm.getDoubleValue("cum"));
  1111. break;
  1112. // 住院医疗费合计
  1113. case "F0000_BIZ2101":
  1114. case "F0000_BIZ2102":
  1115. case "F0000_BIZ2106":
  1116. case "F0000_BIZ2107":
  1117. case "F0000_BIZ22":
  1118. case "F0000_BIZ52":
  1119. cuminfo.addYearFeeSumZy(itm.getDoubleValue("cum"));
  1120. break;
  1121. // 门诊医疗费合计
  1122. case "F0000_BIZ11":
  1123. case "F0000_BIZ13":
  1124. case "F0000_BIZ14":
  1125. case "F0000_BIZ51":
  1126. case "F0000_BIZ9901":
  1127. case "F0000_BIZ9903":
  1128. case "F0000_BIZ9904":
  1129. cuminfo.addYearFeeSumMz(itm.getDoubleValue("cum"));
  1130. break;
  1131. // 住院已付起付线
  1132. case "Q0000_BIZ2101":
  1133. case "Q0000_BIZ2102":
  1134. case "Q0000_BIZ2106":
  1135. case "Q0000_BIZ2107":
  1136. case "Q0000_BIZ22":
  1137. case "Q0000_BIZ52":
  1138. cuminfo.addYearPayedbegnlineZy(itm.getDoubleValue("cum"));
  1139. break;
  1140. // 门诊已付起付线
  1141. case "Q0000_BIZ11":
  1142. case "Q0000_BIZ13":
  1143. case "Q0000_BIZ14":
  1144. case "Q0000_BIZ51":
  1145. case "Q0000_BIZ9901":
  1146. case "Q0000_BIZ9903":
  1147. case "Q0000_BIZ9904":
  1148. cuminfo.addYearPayedbegnlineMz(itm.getDoubleValue("cum"));
  1149. break;
  1150. // 住院统筹支付
  1151. case "D310101_BIZ2101":
  1152. case "D310101_BIZ2102":
  1153. case "D310101_BIZ2106":
  1154. case "D310101_BIZ2107":
  1155. case "D310101_BIZ22":
  1156. case "D310101_BIZ52":
  1157. case "D390101_BIZ2101":
  1158. case "D390101_BIZ2102":
  1159. case "D390101_BIZ2106":
  1160. case "D390101_BIZ2107":
  1161. case "D390101_BIZ22":
  1162. case "D390101_BIZ52":
  1163. cuminfo.addYearFundpaysZy(itm.getDoubleValue("cum"));
  1164. break;
  1165. // 门诊统筹支付
  1166. case "D310101_BIZ11":
  1167. case "D310101_BIZ13":
  1168. case "D310101_BIZ14":
  1169. case "D310101_BIZ51":
  1170. case "D310101_BIZ9901":
  1171. case "D310101_BIZ9903":
  1172. case "D310101_BIZ9904":
  1173. case "D390101_BIZ11":
  1174. case "D390101_BIZ13":
  1175. case "D390101_BIZ14":
  1176. case "D390101_BIZ51":
  1177. case "D390101_BIZ9901":
  1178. case "D390101_BIZ9903":
  1179. case "D390101_BIZ9904":
  1180. cuminfo.addYearFundpaysMz(itm.getDoubleValue("cum"));
  1181. break;
  1182. // 住院政策自费
  1183. case "Z0000_BIZ2101_LAB101":
  1184. case "Z0000_BIZ2102_LAB101":
  1185. case "Z0000_BIZ22_LAB101":
  1186. case "Z0000_BIZ2106_LAB101":
  1187. case "Z0000_BIZ2107_LAB101":
  1188. case "Z0000_BIZ52_LAB101":
  1189. case "Z0000_BIZ2101_LAB103":
  1190. case "Z0000_BIZ2102_LAB103":
  1191. case "Z0000_BIZ22_LAB103":
  1192. case "Z0000_BIZ2106_LAB103":
  1193. case "Z0000_BIZ2107_LAB103":
  1194. case "Z0000_BIZ52_LAB103":
  1195. cuminfo.addYearPolicySelfpayZy(itm.getDoubleValue("cum"));
  1196. break;
  1197. // 住院政策自付
  1198. case "Z0000_BIZ2101_LAB102":
  1199. case "Z0000_BIZ2102_LAB102":
  1200. case "Z0000_BIZ22_LAB102":
  1201. case "Z0000_BIZ2106_LAB102":
  1202. case "Z0000_BIZ2107_LAB102":
  1203. case "Z0000_BIZ52_LAB102":
  1204. cuminfo.addYearPreSelfpayZy(itm.getDoubleValue("cum"));
  1205. break;
  1206. // 门诊政策自费
  1207. case "Z0000_BIZ11_LAB101":
  1208. case "Z0000_BIZ13_LAB101":
  1209. case "Z0000_BIZ14_LAB101":
  1210. case "Z0000_BIZ51_LAB101":
  1211. case "Z0000_BIZ9901_LAB101":
  1212. case "Z0000_BIZ9903_LAB101":
  1213. case "Z0000_BIZ9904_LAB101":
  1214. case "Z0000_BIZ11_LAB103":
  1215. case "Z0000_BIZ13_LAB103":
  1216. case "Z0000_BIZ14_LAB103":
  1217. case "Z0000_BIZ51_LAB103":
  1218. case "Z0000_BIZ9901_LAB103":
  1219. case "Z0000_BIZ9903_LAB103":
  1220. case "Z0000_BIZ9904_LAB103":
  1221. cuminfo.addYearPolicySelfpayMz(itm.getDoubleValue("cum"));
  1222. break;
  1223. // 门诊政策自付
  1224. case "Z0000_BIZ11_LAB102":
  1225. case "Z0000_BIZ13_LAB102":
  1226. case "Z0000_BIZ14_LAB102":
  1227. case "Z0000_BIZ51_LAB102":
  1228. case "Z0000_BIZ9901_LAB102":
  1229. case "Z0000_BIZ9903_LAB102":
  1230. case "Z0000_BIZ9904_LAB102":
  1231. cuminfo.addYearPreSelfpayMz(itm.getDoubleValue("cum"));
  1232. break;
  1233. // 住院大额基金支付
  1234. case "D330101_BIZ2101":
  1235. case "D330101_BIZ2102":
  1236. case "D330101_BIZ2106":
  1237. case "D330101_BIZ2107":
  1238. case "D330101_BIZ22":
  1239. case "D330101_BIZ52":
  1240. cuminfo.addYearBigAmtpaysZy(itm.getDoubleValue("cum"));
  1241. break;
  1242. // 门诊大额基金支付
  1243. case "D330101_BIZ11":
  1244. case "D330101_BIZ13":
  1245. case "D330101_BIZ14":
  1246. case "D330101_BIZ51":
  1247. case "D330101_BIZ9901":
  1248. case "D330101_BIZ9903":
  1249. case "D330101_BIZ9904":
  1250. cuminfo.addYearBigAmtpaysMz(itm.getDoubleValue("cum"));
  1251. break;
  1252. // 住院大病保险支付
  1253. case "D390201_BIZ2101":
  1254. case "D390201_BIZ2102":
  1255. case "D390201_BIZ2106":
  1256. case "D390201_BIZ2107":
  1257. case "D390201_BIZ22":
  1258. case "D390201_BIZ52":
  1259. cuminfo.addYearBigdssInspaysZy(itm.getDoubleValue("cum"));
  1260. break;
  1261. // 门诊大病保险支付
  1262. case "D390201_BIZ11":
  1263. case "D390201_BIZ13":
  1264. case "D390201_BIZ14":
  1265. case "D390201_BIZ51":
  1266. case "D390201_BIZ9901":
  1267. case "D390201_BIZ9903":
  1268. case "D390201_BIZ9904":
  1269. cuminfo.addYearBigdssInspaysMz(itm.getDoubleValue("cum"));
  1270. break;
  1271. // 住院医疗救助支付
  1272. case "D610101_BIZ2101":
  1273. case "D610101_BIZ2102":
  1274. case "D610101_BIZ2106":
  1275. case "D610101_BIZ2107":
  1276. case "D610101_BIZ22":
  1277. case "D610101_BIZ52":
  1278. cuminfo.addYearMafpaysZy(itm.getDoubleValue("cum"));
  1279. break;
  1280. // 门诊医疗救助支付
  1281. case "D610101_BIZ11":
  1282. case "D610101_BIZ13":
  1283. case "D610101_BIZ14":
  1284. case "D610101_BIZ51":
  1285. case "D610101_BIZ9901":
  1286. case "D610101_BIZ9903":
  1287. case "D610101_BIZ9904":
  1288. cuminfo.addYearMafpaysMz(itm.getDoubleValue("cum"));
  1289. break;
  1290. // 住院个人账户支付
  1291. case "D310201_BIZ2101":
  1292. case "D310201_BIZ2102":
  1293. case "D310201_BIZ2106":
  1294. case "D310201_BIZ2107":
  1295. case "D310201_BIZ22":
  1296. case "D310201_BIZ52":
  1297. cuminfo.addYearAcctPayZy(itm.getDoubleValue("cum"));
  1298. break;
  1299. // 门诊个人账户支付
  1300. case "D310201_BIZ11":
  1301. case "D310201_BIZ13":
  1302. case "D310201_BIZ14":
  1303. case "D310201_BIZ51":
  1304. case "D310201_BIZ9901":
  1305. case "D310201_BIZ9903":
  1306. case "D310201_BIZ9904":
  1307. cuminfo.addYearAcctPayMz(itm.getDoubleValue("cum"));
  1308. break;
  1309. // 大病保险合规费用
  1310. case "TS390201":
  1311. cuminfo.addYearBigdssLegalFee(itm.getDoubleValue("cum"));
  1312. break;
  1313. }
  1314. }
  1315. }
  1316. return cuminfo;
  1317. }
  1318. public ResultVo<List<SiSetlFeeDetl>> getChrgitems(SiSetlinfo setlinfo) {
  1319. return getChrgitems(setlinfo.getPsnNo(), setlinfo.getSetlId(), setlinfo.getMdtrtId(), setlinfo.getInsuplcAdmdvs());
  1320. }
  1321. private ResultVo<List<SiSetlFeeDetl>> getChrgitems(String psnNo, String setlId, String mdtrtId, String admdvs) {
  1322. List<SiSetlFeeDetl> list = dao.selectAllSetlFeeDtle(mdtrtId);
  1323. if (!list.isEmpty()) {
  1324. return ResultVoUtil.success(list);
  1325. }
  1326. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, admdvs);
  1327. JSONObject data = new JSONObject();
  1328. data.put("psn_no", psnNo);
  1329. data.put("setl_id", setlId);
  1330. data.put("mdtrt_id", mdtrtId);
  1331. input.getJSONObject("input").put("data", data);
  1332. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS);
  1333. log.info("【操作员:{}】,【结算单查询】查询费用明细:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  1334. if (null == result) {
  1335. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  1336. }
  1337. if (null == result.getInteger(RESULT_CODE)) {
  1338. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  1339. }
  1340. if (0 == result.getInteger(RESULT_CODE)) {
  1341. JSONArray output = result.getJSONArray(OUTPUT);
  1342. if (null == output || output.isEmpty()) {
  1343. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到费用明细。");
  1344. }
  1345. for (int i = 0; i < output.size(); i++) {
  1346. JSONObject feeItem = output.getJSONObject(i);
  1347. feeItem.replace("feedetl_sn", i + 1);
  1348. SiSetlFeeDetl fee = JSONObject.parseObject(feeItem.toJSONString(), SiSetlFeeDetl.class);
  1349. if (StringUtil.isBlank(fee.getSetlId())) {
  1350. fee.setSetlId(setlId);
  1351. }
  1352. list.add(fee);
  1353. if (list.size() == 30) {
  1354. dao.insertSetlFeeDetlBatch(list);
  1355. list.clear();
  1356. }
  1357. }
  1358. if (!list.isEmpty()) {
  1359. dao.insertSetlFeeDetlBatch(list);
  1360. }
  1361. return ResultVoUtil.success(dao.selectAllSetlFeeDtle(mdtrtId));
  1362. }
  1363. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, result.getString(ERROR_MESSAGE));
  1364. }
  1365. private ChrgItemLvInfo analyzeParticularChrgitmLv(List<SiSetlFeeDetl> chrgitms) {
  1366. Map<String, BigDecimal> map = new HashMap<>();
  1367. map.put("allfeeSum", new BigDecimal(0));
  1368. map.put("totalFrst", new BigDecimal(0));
  1369. map.put("totalScnd", new BigDecimal(0));
  1370. map.put("totalThrd", new BigDecimal(0));
  1371. chrgitms.forEach(itm -> {
  1372. BigDecimal itmfeeSum = new BigDecimal(itm.getDetItemFeeSumamt());
  1373. map.replace("allfeeSum", map.get("allfeeSum").add(itmfeeSum));
  1374. if (itm.getChrgitmLv().equals(ChrgitmLv.FIRST_CLASS.getCode())) {
  1375. map.replace("totalFrst", map.get("totalFrst").add(itmfeeSum));
  1376. } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) {
  1377. map.replace("totalScnd", map.get("totalScnd").add(itmfeeSum));
  1378. } else {
  1379. map.replace("totalThrd", map.get("totalThrd").add(itmfeeSum));
  1380. }
  1381. String typeKey = itm.getMedChrgitmType();
  1382. String lvKey = typeKey + "-" + itm.getChrgitmLv();
  1383. if (map.containsKey(typeKey)) {
  1384. map.replace(typeKey, map.get(typeKey).add(itmfeeSum));
  1385. } else {
  1386. map.put(typeKey, itmfeeSum);
  1387. }
  1388. if (map.containsKey(lvKey)) {
  1389. map.replace(lvKey, map.get(lvKey).add(itmfeeSum));
  1390. } else {
  1391. map.put(lvKey, itmfeeSum);
  1392. }
  1393. });
  1394. ChrgItemLvInfo chrgItemLvInfo = new ChrgItemLvInfo();
  1395. chrgItemLvInfo.setAllfeeSum(map.get("allfeeSum"));
  1396. chrgItemLvInfo.setAllfeeFrst(map.get("totalFrst"));
  1397. chrgItemLvInfo.setAllfeeScnd(map.get("totalScnd"));
  1398. chrgItemLvInfo.setAllfeeThrd(map.get("totalThrd"));
  1399. chrgItemLvInfo.setWestMedFeeSum(map.get("09"));
  1400. chrgItemLvInfo.setWestMedFeeFrst(map.get("09-01"));
  1401. chrgItemLvInfo.setWestMedFeeScnd(map.get("09-02"));
  1402. chrgItemLvInfo.setWestMedFeeThrd(map.get("09-03"));
  1403. chrgItemLvInfo.setHerbalSum(map.get("10"));
  1404. chrgItemLvInfo.setHerbalFrst(map.get("10-01"));
  1405. chrgItemLvInfo.setHerbalScnd(map.get("10-02"));
  1406. chrgItemLvInfo.setHerbalThrd(map.get("10-03"));
  1407. chrgItemLvInfo.setChnsPtntSum(map.get("11"));
  1408. chrgItemLvInfo.setChnsPtntFrst(map.get("11-01"));
  1409. chrgItemLvInfo.setChnsPtntScnd(map.get("11-02"));
  1410. chrgItemLvInfo.setChnsPtntThrd(map.get("11-03"));
  1411. chrgItemLvInfo.setClinicSum(map.get("02"));
  1412. chrgItemLvInfo.setClinicFrst(map.get("02-01"));
  1413. chrgItemLvInfo.setClinicScnd(map.get("02-02"));
  1414. chrgItemLvInfo.setClinicThrd(map.get("02-03"));
  1415. chrgItemLvInfo.setTreatSum(map.get("05"));
  1416. chrgItemLvInfo.setTreatFrst(map.get("05-01"));
  1417. chrgItemLvInfo.setTreatScnd(map.get("05-02"));
  1418. chrgItemLvInfo.setTreatThrd(map.get("05-03"));
  1419. chrgItemLvInfo.setSurgerySum(map.get("06"));
  1420. chrgItemLvInfo.setSurgeryFrst(map.get("06-01"));
  1421. chrgItemLvInfo.setSurgeryScnd(map.get("06-02"));
  1422. chrgItemLvInfo.setSurgeryThrd(map.get("06-03"));
  1423. chrgItemLvInfo.setNursingSum(map.get("07"));
  1424. chrgItemLvInfo.setNursingFrst(map.get("07-01"));
  1425. chrgItemLvInfo.setNursingScnd(map.get("07-02"));
  1426. chrgItemLvInfo.setNursingThrd(map.get("07-03"));
  1427. chrgItemLvInfo.setSntryMtrlsSum(map.get("08"));
  1428. chrgItemLvInfo.setSntryMtrlsFrst(map.get("08-01"));
  1429. chrgItemLvInfo.setSntryMtrlsScnd(map.get("08-02"));
  1430. chrgItemLvInfo.setSntryMtrlsThrd(map.get("08-03"));
  1431. chrgItemLvInfo.setExamSum(map.get("04"));
  1432. chrgItemLvInfo.setExamFrst(map.get("04-01"));
  1433. chrgItemLvInfo.setExamScnd(map.get("04-02"));
  1434. chrgItemLvInfo.setExamThrd(map.get("04-03"));
  1435. chrgItemLvInfo.setNrmlTrtmtSum(map.get("12"));
  1436. chrgItemLvInfo.setNrmlTrtmtFrst(map.get("12-01"));
  1437. chrgItemLvInfo.setNrmlTrtmtScnd(map.get("12-02"));
  1438. chrgItemLvInfo.setNrmlTrtmtThrd(map.get("12-03"));
  1439. chrgItemLvInfo.setInspectSum(map.get("03"));
  1440. chrgItemLvInfo.setInspectFrst(map.get("03-01"));
  1441. chrgItemLvInfo.setInspectScnd(map.get("03-02"));
  1442. chrgItemLvInfo.setInspectThrd(map.get("03-03"));
  1443. chrgItemLvInfo.setRegisterSum(map.get("13"));
  1444. chrgItemLvInfo.setRegisterFrst(map.get("13-01"));
  1445. chrgItemLvInfo.setRegisterScnd(map.get("13-02"));
  1446. chrgItemLvInfo.setRegisterThrd(map.get("13-03"));
  1447. chrgItemLvInfo.setBedfeeSum(map.get("01"));
  1448. chrgItemLvInfo.setBedfeeFrst(map.get("01-01"));
  1449. chrgItemLvInfo.setBedfeeScnd(map.get("01-02"));
  1450. chrgItemLvInfo.setBedfeeThrd(map.get("01-03"));
  1451. chrgItemLvInfo.setOthfeeSum(map.get("14"));
  1452. chrgItemLvInfo.setOthfeeFrst(map.get("14-01"));
  1453. chrgItemLvInfo.setOthfeeScnd(map.get("14-02"));
  1454. chrgItemLvInfo.setOthfeeThrd(map.get("14-03"));
  1455. return chrgItemLvInfo;
  1456. }
  1457. private void analyzeMzChrgitm(OtptntSetlmtLst lst, List<BrfChrgitm> chrgitms) {
  1458. Map<String, BigDecimal> map = new HashMap<>();
  1459. map.put("allfeeSum", BigDecimal.valueOf(0));
  1460. map.put("totalThrd", BigDecimal.valueOf(0));
  1461. map.put("totalScnd", BigDecimal.valueOf(0));
  1462. map.put("othSum", BigDecimal.valueOf(0));
  1463. map.put("othThrd", BigDecimal.valueOf(0));
  1464. map.put("othScnd", BigDecimal.valueOf(0));
  1465. chrgitms.forEach(itm -> {
  1466. map.replace("allfeeSum", map.get("allfeeSum").add(BigDecimal.valueOf(itm.getChargeFee())));
  1467. if (itm.getChrgitmLv().equals(ChrgitmLv.SELF_PAY.getCode())) {
  1468. map.replace("totalThrd", map.get("totalThrd").add(BigDecimal.valueOf(itm.getChargeFee())));
  1469. } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) {
  1470. map.replace("totalScnd", map.get("totalScnd").add(BigDecimal.valueOf(itm.getChargeFee())));
  1471. }
  1472. String typeKey = itm.getMedChrgitmType();
  1473. if (!typeKey.equals("09") && !typeKey.equals("11")) {
  1474. map.replace("othSum", map.get("othSum").add(BigDecimal.valueOf(itm.getChargeFee())));
  1475. if (itm.getChrgitmLv().equals(ChrgitmLv.SELF_PAY.getCode())) {
  1476. map.replace("othThrd", map.get("othThrd").add(BigDecimal.valueOf(itm.getChargeFee())));
  1477. } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) {
  1478. map.replace("othScnd", map.get("othScnd").add(BigDecimal.valueOf(itm.getChargeFee())));
  1479. }
  1480. } else {
  1481. String lvKey = typeKey + "-" + itm.getChrgitmLv();
  1482. if (map.containsKey(typeKey)) {
  1483. map.replace(typeKey, map.get(typeKey).add(BigDecimal.valueOf(itm.getChargeFee())));
  1484. } else {
  1485. map.put(typeKey, BigDecimal.valueOf(itm.getChargeFee()));
  1486. }
  1487. if (map.containsKey(lvKey)) {
  1488. map.replace(lvKey, map.get(lvKey).add(BigDecimal.valueOf(itm.getChargeFee())));
  1489. } else {
  1490. map.put(lvKey, BigDecimal.valueOf(itm.getChargeFee()));
  1491. }
  1492. }
  1493. });
  1494. lst.setAllfeeSum(map.get("allfeeSum"));
  1495. lst.setAllfeeThrd(map.get("totalThrd"));
  1496. lst.setAllfeeScnd(map.get("totalScnd"));
  1497. lst.setWestMedFeeSum(map.get("09"));
  1498. lst.setWestMedFeeThrd(map.get("09-03"));
  1499. lst.setWestMedFeeScnd(map.get("09-02"));
  1500. lst.setChnsPtntSum(map.get("11"));
  1501. lst.setChnsPtntThrd(map.get("11-03"));
  1502. lst.setChnsPtntScnd(map.get("11-02"));
  1503. lst.setMedsrvcSum(map.get("othSum"));
  1504. lst.setMedsrvcThrd(map.get("othThrd"));
  1505. lst.setMedsrvcScnd(map.get("othScnd"));
  1506. }
  1507. public ResultVo<List<SiMzMatnDise>> queryMzMatnDises() {
  1508. return ResultVoUtil.success(dao.selectAllMzMatnDises());
  1509. }
  1510. public ResultVo<List<SetlStatisticResult>> selectSetlinfoStatistics(SetlCondition condition) {
  1511. List<BaseSetlStatistics> baseStatistics = getBaseStatistics(condition);
  1512. if (null == baseStatistics || baseStatistics.isEmpty()) {
  1513. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
  1514. }
  1515. Map<String, String> regionMap = new HashMap<>();
  1516. Map<String, List<BaseSetlStatistics>> admdvsSetldataMap = new HashMap<>();
  1517. List<BaseSetlStatistics> setlListUpload = new ArrayList<>();
  1518. baseStatistics.forEach(itm -> {
  1519. itm.setInsutypeName(Insutype.getName(itm.getInsutype()));
  1520. itm.setInsuplcAdmdvsName(redis.getRegionName(itm.getInsuplcAdmdvs()));
  1521. String key;
  1522. if (condition.getAdmdvsType() == 5 || condition.getAdmdvsType() == 6) {
  1523. key = itm.getInsuplcAdmdvs();
  1524. } else {
  1525. key = itm.getInsuplcAdmdvs().substring(0, 4) + "00";
  1526. }
  1527. String admdvsName = regionMap.get(key);
  1528. if (null == admdvsName) {
  1529. CodeName region = dao.selectAdmdvsNameAndParentName(key);
  1530. if (null == region) {
  1531. region = dao.selectAdmdvsName(key);
  1532. }
  1533. if (null == region) {
  1534. key = itm.getInsuplcAdmdvs().substring(0, 2) + "0000";
  1535. region = dao.selectAdmdvsNameAndParentName(key);
  1536. }
  1537. if (null == region) {
  1538. admdvsName = "未知";
  1539. } else {
  1540. admdvsName = region.getCode() + region.getName();
  1541. }
  1542. regionMap.put(key, admdvsName);
  1543. }
  1544. if (admdvsSetldataMap.containsKey(admdvsName)) {
  1545. admdvsSetldataMap.get(admdvsName).add(itm);
  1546. } else {
  1547. List<BaseSetlStatistics> tempList = new ArrayList<>();
  1548. tempList.add(itm);
  1549. admdvsSetldataMap.put(admdvsName, tempList);
  1550. }
  1551. itm.setMedTypeName(MedType.getName(itm.getMedType()));
  1552. setlListUpload.add(itm);
  1553. });
  1554. List<SetlStatisticResult> resultList = new ArrayList<>();
  1555. for (Map.Entry<String, List<BaseSetlStatistics>> entry : admdvsSetldataMap.entrySet()) {
  1556. List<BaseSetlStatistics> admdvsSetldataList = entry.getValue();
  1557. SetlStatisticResult resultItem = new SetlStatisticResult();
  1558. resultItem.setAdmdvsName(entry.getKey());
  1559. resultItem.setInsuplcAdmdvs(entry.getValue().get(0).getInsuplcAdmdvs().substring(0, 4) + "00");
  1560. resultItem.setPsnSumamt(admdvsSetldataList.size());
  1561. if (StringUtil.notBlank(condition.getInsutype())) {
  1562. resultItem.setInsutype(condition.getInsutype());
  1563. resultItem.setInsutypeName(Insutype.getName(condition.getInsutype()));
  1564. resultItem.setChildKey(entry.getKey() + "-" + resultItem.getInsutypeName());
  1565. } else {
  1566. resultItem.setInsutypeName("-");
  1567. resultItem.setChildKey(entry.getKey());
  1568. }
  1569. fillSetlStatisticResult(resultList, admdvsSetldataList, resultItem);
  1570. }
  1571. if (StringUtil.isBlank(condition.getInsutype())) {
  1572. for (SetlStatisticResult resultItem : resultList) {
  1573. Map<String, List<BaseSetlStatistics>> insutypeSetldataMap = new HashMap<>();
  1574. String admdvsName = resultItem.getAdmdvsName();
  1575. List<BaseSetlStatistics> admdvsSetldataList = admdvsSetldataMap.get(admdvsName);
  1576. for (BaseSetlStatistics baseSetlStatistics : admdvsSetldataList) {
  1577. if (insutypeSetldataMap.containsKey(baseSetlStatistics.getInsutypeName())) {
  1578. insutypeSetldataMap.get(baseSetlStatistics.getInsutypeName()).add(baseSetlStatistics);
  1579. } else {
  1580. List<BaseSetlStatistics> tmpList = new ArrayList<>();
  1581. tmpList.add(baseSetlStatistics);
  1582. insutypeSetldataMap.put(baseSetlStatistics.getInsutypeName(), tmpList);
  1583. }
  1584. }
  1585. if (insutypeSetldataMap.size() == 1) {
  1586. resultItem.setInsutype(admdvsSetldataList.get(0).getInsutype());
  1587. resultItem.setInsutypeName(admdvsSetldataList.get(0).getInsutypeName());
  1588. continue;
  1589. }
  1590. List<SetlStatisticResult> children = new ArrayList<>();
  1591. for (Map.Entry<String, List<BaseSetlStatistics>> entry : insutypeSetldataMap.entrySet()) {
  1592. List<BaseSetlStatistics> insutypeSetldataList = entry.getValue();
  1593. SetlStatisticResult result = new SetlStatisticResult();
  1594. result.setAdmdvsName(resultItem.getAdmdvsName());
  1595. result.setInsuplcAdmdvs(resultItem.getInsuplcAdmdvs());
  1596. result.setPsnSumamt(insutypeSetldataList.size());
  1597. result.setInsutype(entry.getValue().get(0).getInsutype());
  1598. result.setInsutypeName(entry.getValue().get(0).getInsutypeName());
  1599. result.setChildKey(resultItem.getAdmdvsName() + "-" + result.getInsutypeName());
  1600. result.setIsChildren(true);
  1601. fillSetlStatisticResult(children, insutypeSetldataList, result);
  1602. }
  1603. resultItem.setChildren(children);
  1604. }
  1605. }
  1606. resultList.get(0).setShangChuanJieSuanDan(setlListUpload);
  1607. return ResultVoUtil.success(resultList);
  1608. }
  1609. private List<BaseSetlStatistics> getBaseStatistics(SetlCondition condition) {
  1610. String begntime = condition.getMonth() + "-01 00:00:00.000";
  1611. String endtime = DateUtil.getMonthEndtime(condition.getMonth());
  1612. String insutype = condition.getInsutype();
  1613. if (StringUtil.isBlank(insutype)) {
  1614. insutype = "%%";
  1615. }
  1616. switch (condition.getAdmdvsType()) {
  1617. case 1:
  1618. return dao.selectBaseSetlStatisticsInProvinceLevel(begntime, endtime, insutype, condition.getSetlType());
  1619. case 2:
  1620. return dao.selectBaseSetlStatisticsInChangshaCity(begntime, endtime, insutype, condition.getSetlType());
  1621. case 3:
  1622. return dao.selectBaseSetlStatisticsInProvinceOtherCities(begntime, endtime, insutype, condition.getSetlType());
  1623. case 4:
  1624. return dao.selectBaseSetlStatisticsOutProvince(begntime, endtime, insutype, condition.getSetlType());
  1625. case 5:
  1626. return dao.selectBaseSetlStatisticsInChangshaCounty(begntime, endtime, insutype, condition.getSetlType());
  1627. case 6:
  1628. return dao.selectBaseSetlStatisticsInLiuYangCity(begntime, endtime, insutype, condition.getSetlType());
  1629. default:
  1630. return dao.selectBaseSetlStatisticsInAllPlaces(begntime, endtime, insutype, condition.getSetlType());
  1631. }
  1632. }
  1633. private void fillSetlStatisticResult(List<SetlStatisticResult> resultList, List<BaseSetlStatistics> admdvsSetldataList, SetlStatisticResult resultItem) {
  1634. String medfeeSumamt = "0";
  1635. String baseMedFundpaySumamt = "0";
  1636. String bigDssFundpaySumamt = "0";
  1637. String clvFundpaySumamt = "0";
  1638. String acctpaySumamt = "0";
  1639. String othFundpaySumamt = "0";
  1640. String fundpaySumamt = "0";
  1641. for (BaseSetlStatistics itm : admdvsSetldataList) {
  1642. medfeeSumamt = DecimalUtil.add(medfeeSumamt, itm.getMedfeeSumamt());
  1643. baseMedFundpaySumamt = DecimalUtil.add(baseMedFundpaySumamt, itm.getHifpPay());
  1644. bigDssFundpaySumamt = DecimalUtil.add(bigDssFundpaySumamt, itm.getHifmiPay());
  1645. clvFundpaySumamt = DecimalUtil.add(clvFundpaySumamt, itm.getCvlservPay());
  1646. acctpaySumamt = DecimalUtil.add(acctpaySumamt, itm.getAcctPay());
  1647. fundpaySumamt = DecimalUtil.add(fundpaySumamt, itm.getFundPaySumamt(), itm.getAcctPay());
  1648. String othpay = DecimalUtil.minusLink(itm.getFundPaySumamt(), itm.getHifpPay(), itm.getHifmiPay(), itm.getCvlservPay());
  1649. othFundpaySumamt = DecimalUtil.add(othFundpaySumamt, othpay);
  1650. }
  1651. resultItem.setMedfeeSumamt(medfeeSumamt);
  1652. resultItem.setBaseMedFundpaySumamt(baseMedFundpaySumamt);
  1653. resultItem.setBigDssFundpaySumamt(bigDssFundpaySumamt);
  1654. resultItem.setClvFundpaySumamt(clvFundpaySumamt);
  1655. resultItem.setAcctpaySumamt(acctpaySumamt);
  1656. resultItem.setOthFundpaySumamt(othFundpaySumamt);
  1657. resultItem.setFundpaySumamt(fundpaySumamt);
  1658. resultList.add(resultItem);
  1659. }
  1660. public ResultVo<List<SiSetlinfo>> selectSetldetailStatistics(SetlCondition condition) {
  1661. String begntime = condition.getMonth() + "-01 00:00:00.000";
  1662. String endtime = DateUtil.getMonthEndtime(condition.getMonth());
  1663. String admdvsStatement = getAdmdvsStatement(condition.getAdmdvsType());
  1664. String insutype = condition.getInsutype();
  1665. if (StringUtil.isBlank(insutype)) {
  1666. insutype = "%%";
  1667. }
  1668. List<SiSetlinfo> list = setlinfoDao.selectMyList(condition.getSetlType(), insutype, admdvsStatement, begntime, endtime);
  1669. list.forEach(item -> {
  1670. if (null != item.getHospPartAmt()) {
  1671. item.setFundPaySumamt(DecimalUtil.minusDouble(item.getFundPaySumamt(), item.getHospPartAmt()));
  1672. }
  1673. item.setInsuplcAdmdvsName(redis.getRegionName(item.getInsuplcAdmdvs()));
  1674. FilterUtil.filterCodeToName(item);
  1675. });
  1676. return ResultVoUtil.success(list);
  1677. }
  1678. private String getAdmdvsStatement(int admdvstype) {
  1679. switch (admdvstype) {
  1680. case 1:
  1681. return " and insuplc_admdvs='439900' ";
  1682. case 2:
  1683. return " and insuplc_admdvs like '4301%' and insuplc_admdvs not in ('430121','430181') ";
  1684. case 3:
  1685. return " and insuplc_admdvs like '43%' and insuplc_admdvs not like '4301%' ";
  1686. case 4:
  1687. return " and insuplc_admdvs not like '43%' ";
  1688. case 5:
  1689. return " and insuplc_admdvs='430121' ";
  1690. case 6:
  1691. return " and insuplc_admdvs='430181' ";
  1692. default:
  1693. return "";
  1694. }
  1695. }
  1696. public ResultVo<List<ZyActpatient>> weiJieSuanZaiYuanHuanZhe(String patNo, String startTime, String endTime, String name, String certno) {
  1697. List<ZyActpatient> actpatients = dao.zaiYuanHuanZheXinXi(patNo, startTime, endTime, StringUtil.isContainChinese(name), certno);
  1698. Map<String, String> insuplcAdmdvs = new HashMap<>();
  1699. for (ZyActpatient actpatient : actpatients) {
  1700. if (StringUtil.isBlank(actpatient.getInsuplcAdmdvsName())) {
  1701. String key = actpatient.getInsuplcAdmdvs().substring(0, 4) + "00";
  1702. if (insuplcAdmdvs.containsKey(key)) {
  1703. actpatient.setInsuplcAdmdvsName(insuplcAdmdvs.get(key));
  1704. } else {
  1705. String insuplcAdmdvsName = redis.getRegionName(key);
  1706. insuplcAdmdvs.put(key, insuplcAdmdvsName);
  1707. actpatient.setInsuplcAdmdvsName(insuplcAdmdvsName);
  1708. }
  1709. }
  1710. }
  1711. return ResultVoUtil.success(actpatients);
  1712. }
  1713. public ResultVo<String> checkRegisterDate(String patNo, Integer times) {
  1714. if (dao.selectLedgerCount(patNo, times) == 1) {
  1715. return ResultVoUtil.success();
  1716. }
  1717. Date ledgerAccountDate = dao.selectMaxLedgerAccountDate(patNo, times);
  1718. if (null == ledgerAccountDate) {
  1719. return ResultVoUtil.success();
  1720. }
  1721. Date registerDate = dao.selectRegisterDate(patNo);
  1722. if (null == registerDate) {
  1723. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保登记日期不能为空。");
  1724. }
  1725. Calendar ledgerCalendar = Calendar.getInstance();
  1726. ledgerCalendar.setTime(ledgerAccountDate);
  1727. Calendar registerCalendar = Calendar.getInstance();
  1728. registerCalendar.setTime(registerDate);
  1729. if (registerCalendar.after(ledgerCalendar)) {
  1730. return ResultVoUtil.success();
  1731. }
  1732. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保登记日期【%s】不能小于断账日期【%s】,请修改。", DateUtil.formatDatetime(registerDate), DateUtil.formatDatetime(ledgerAccountDate)));
  1733. }
  1734. public void saveCumInfo(SiSetlinfo setlinfo) {
  1735. new SaveCumInfo(dao, setlinfo).start();
  1736. }
  1737. class SaveCumInfo extends Thread {
  1738. private final SiQueryDao dao;
  1739. private final SiSetlinfo setlinfo;
  1740. SaveCumInfo (SiQueryDao dao, SiSetlinfo setlinfo) {
  1741. this.dao = dao;
  1742. this.setlinfo = setlinfo;
  1743. }
  1744. @Override
  1745. public void run() {
  1746. if (dao.selectCumInfoCount(setlinfo.getSetlId()) == 0) {
  1747. CuminfoInYear cuminfo = getYearCuminfo(setlinfo.getSetlId(), setlinfo.getPsnNo(), setlinfo.getInsuplcAdmdvs());
  1748. if (cuminfo.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  1749. cuminfo.setSetlId(setlinfo.getSetlId());
  1750. dao.insertCumInfo(cuminfo);
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }