zh_his_api_controller.go 79KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363
  1. package zh
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "github.com/axgle/mahonia"
  12. "math"
  13. "math/rand"
  14. "os"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. type ZHHisApiController struct {
  20. controllers.BaseAuthAPIController
  21. }
  22. type ResultTwo struct {
  23. ErrMsg string `json:"err_msg"`
  24. InfRefmsgid string `json:"inf_refmsgid"`
  25. Infcode int64 `json:"infcode"`
  26. Output struct {
  27. Baseinfo struct {
  28. Age float64 `json:"age"`
  29. Brdy string `json:"brdy"`
  30. Certno string `json:"certno"`
  31. Gend string `json:"gend"`
  32. Naty string `json:"naty"`
  33. PsnCertType string `json:"psn_cert_type"`
  34. PsnName string `json:"psn_name"`
  35. PsnNo string `json:"psn_no"`
  36. } `json:"baseinfo"`
  37. Idetinfo []interface{} `json:"idetinfo"`
  38. Iinfo []struct {
  39. Balc float64 `json:"balc"`
  40. CvlservFlag string `json:"cvlserv_flag"`
  41. EmpName string `json:"emp_name"`
  42. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  43. Insutype string `json:"insutype"`
  44. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  45. PausInsuDate string `json:"paus_insu_date"`
  46. PsnInsuDate string `json:"psn_insu_date"`
  47. PsnInsuStas string `json:"psn_insu_stas"`
  48. PsnType string `json:"psn_type"`
  49. } `json:"insuinfo"`
  50. } `json:"output"`
  51. RefmsgTime string `json:"refmsg_time"`
  52. RespondTime string `json:"respond_time"`
  53. Signtype interface{} `json:"signtype"`
  54. WarnInfo interface{} `json:"warn_info"`
  55. }
  56. type ResultTwo10265 struct {
  57. ErrMsg string `json:"err_msg"`
  58. InfRefmsgid string `json:"inf_refmsgid"`
  59. Infcode string `json:"infcode"`
  60. Output struct {
  61. Baseinfo struct {
  62. Age float64 `json:"age"`
  63. Brdy string `json:"brdy"`
  64. Certno string `json:"certno"`
  65. Gend string `json:"gend"`
  66. Naty string `json:"naty"`
  67. PsnCertType string `json:"psn_cert_type"`
  68. PsnName string `json:"psn_name"`
  69. PsnNo string `json:"psn_no"`
  70. } `json:"baseinfo"`
  71. Idetinfo []interface{} `json:"idetinfo"`
  72. Iinfo []struct {
  73. Balc float64 `json:"balc"`
  74. CvlservFlag string `json:"cvlserv_flag"`
  75. EmpName string `json:"emp_name"`
  76. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  77. Insutype string `json:"insutype"`
  78. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  79. PausInsuDate string `json:"paus_insu_date"`
  80. PsnInsuDate string `json:"psn_insu_date"`
  81. PsnInsuStas string `json:"psn_insu_stas"`
  82. PsnType string `json:"psn_type"`
  83. } `json:"insuinfo"`
  84. } `json:"output"`
  85. RefmsgTime string `json:"refmsg_time"`
  86. RespondTime string `json:"respond_time"`
  87. Signtype interface{} `json:"signtype"`
  88. WarnInfo interface{} `json:"warn_info"`
  89. }
  90. type ResultThree struct {
  91. Cainfo interface{} `json:"cainfo"`
  92. ErrMsg string `json:"err_msg"`
  93. InfRefmsgid string `json:"inf_refmsgid"`
  94. Infcode int64 `json:"infcode"`
  95. Output struct {
  96. Result struct {
  97. MdtrtID string `json:"mdtrt_id"`
  98. } `json:"result"`
  99. } `json:"output"`
  100. RefmsgTime string `json:"refmsg_time"`
  101. RespondTime string `json:"respond_time"`
  102. Signtype interface{} `json:"signtype"`
  103. WarnMsg interface{} `json:"warn_msg"`
  104. }
  105. type ResultThree10265 struct {
  106. Cainfo interface{} `json:"cainfo"`
  107. ErrMsg string `json:"err_msg"`
  108. InfRefmsgid string `json:"inf_refmsgid"`
  109. Infcode string `json:"infcode"`
  110. Output struct {
  111. Result struct {
  112. MdtrtID string `json:"mdtrt_id"`
  113. } `json:"result"`
  114. } `json:"output"`
  115. RefmsgTime string `json:"refmsg_time"`
  116. RespondTime string `json:"respond_time"`
  117. Signtype interface{} `json:"signtype"`
  118. WarnMsg interface{} `json:"warn_msg"`
  119. }
  120. type ResultFour struct {
  121. Cainfo string `json:"cainfo"`
  122. ErrMsg string `json:"err_msg"`
  123. InfRefmsgid string `json:"inf_refmsgid"`
  124. Infcode int64 `json:"infcode"`
  125. Output struct {
  126. Result []struct {
  127. BasMednFlag string `json:"bas_medn_flag"`
  128. ChldMedcFlag string `json:"chld_medc_flag"`
  129. ChrgitmLv string `json:"chrgitm_lv"`
  130. Cnt float64 `json:"cnt"`
  131. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  132. DrtReimFlag string `json:"drt_reim_flag"`
  133. FeedetlSn string `json:"feedetl_sn"`
  134. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  135. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  136. InscpScpAmt float64 `json:"inscp_scp_amt"`
  137. ListSpItemFlag string `json:"list_sp_item_flag"`
  138. LmtUsedFlag string `json:"lmt_used_flag"`
  139. MedChrgitmType string `json:"med_chrgitm_type"`
  140. Memo string `json:"memo"`
  141. OverlmtAmt float64 `json:"overlmt_amt"`
  142. PreselfpayAmt float64 `json:"preselfpay_amt"`
  143. Pric float64 `json:"pric"`
  144. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  145. SelfpayProp float64 `json:"selfpay_prop"`
  146. } `json:"result"`
  147. } `json:"output"`
  148. RefmsgTime string `json:"refmsg_time"`
  149. RespondTime string `json:"respond_time"`
  150. Signtype string `json:"signtype"`
  151. WarnMsg string `json:"warn_msg"`
  152. }
  153. type ResultFour10265 struct {
  154. Cainfo string `json:"cainfo"`
  155. ErrMsg string `json:"err_msg"`
  156. InfRefmsgid string `json:"inf_refmsgid"`
  157. Infcode string `json:"infcode"`
  158. Output struct {
  159. Result []struct {
  160. BasMednFlag string `json:"bas_medn_flag"`
  161. ChldMedcFlag string `json:"chld_medc_flag"`
  162. ChrgitmLv string `json:"chrgitm_lv"`
  163. Cnt float64 `json:"cnt"`
  164. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  165. DrtReimFlag string `json:"drt_reim_flag"`
  166. FeedetlSn string `json:"feedetl_sn"`
  167. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  168. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  169. InscpScpAmt float64 `json:"inscp_scp_amt"`
  170. ListSpItemFlag string `json:"list_sp_item_flag"`
  171. LmtUsedFlag string `json:"lmt_used_flag"`
  172. MedChrgitmType string `json:"med_chrgitm_type"`
  173. Memo string `json:"memo"`
  174. OverlmtAmt float64 `json:"overlmt_amt"`
  175. PreselfpayAmt float64 `json:"preselfpay_amt"`
  176. Pric float64 `json:"pric"`
  177. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  178. SelfpayProp float64 `json:"selfpay_prop"`
  179. } `json:"result"`
  180. } `json:"output"`
  181. RefmsgTime string `json:"refmsg_time"`
  182. RespondTime string `json:"respond_time"`
  183. Signtype string `json:"signtype"`
  184. WarnMsg string `json:"warn_msg"`
  185. }
  186. type ResultFive struct {
  187. Balc float64 `json:"balc"`
  188. CvlservFlag string `json:"cvlserv_flag"`
  189. EmpName string `json:"emp_name"`
  190. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  191. Insutype string `json:"insutype"`
  192. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  193. PausInsuDate string `json:"paus_insu_date"`
  194. PsnInsuDate string `json:"psn_insu_date"`
  195. PsnInsuStas string `json:"psn_insu_stas"`
  196. PsnType string `json:"psn_type"`
  197. }
  198. type ResultSeven struct {
  199. Cainfo string `json:"cainfo"`
  200. ErrMsg string `json:"err_msg"`
  201. InfRefmsgid string `json:"inf_refmsgid"`
  202. Infcode int64 `json:"infcode"`
  203. Output struct {
  204. Setldetail []interface{} `json:"setldetail"`
  205. Setlinfo struct {
  206. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  207. AcctPay float64 `json:"acct_pay"`
  208. ActPayDedc float64 `json:"act_pay_dedc"`
  209. Age float64 `json:"age"`
  210. Balc float64 `json:"balc"`
  211. Brdy string `json:"brdy"`
  212. Certno string `json:"certno"`
  213. ClrOptins string `json:"clr_optins"`
  214. ClrType string `json:"clr_type"`
  215. ClrWay string `json:"clr_way"`
  216. CvlservFlag string `json:"cvlserv_flag"`
  217. CvlservPay float64 `json:"cvlserv_pay"`
  218. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  219. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  220. Gend string `json:"gend"`
  221. HifesPay float64 `json:"hifes_pay"`
  222. HifmiPay float64 `json:"hifmi_pay"`
  223. HifpPay float64 `json:"hifp_pay"`
  224. HospPartAmt float64 `json:"hosp_part_amt"`
  225. InscpScpAmt float64 `json:"inscp_scp_amt"`
  226. Insutype string `json:"insutype"`
  227. MafPay float64 `json:"maf_pay"`
  228. MdtrtCertType string `json:"mdtrt_cert_type"`
  229. HifobPay float64 `json:"hifob_pay"`
  230. MdtrtID string `json:"mdtrt_id"`
  231. MedType string `json:"med_type"`
  232. MedfeeSumamt float64 `json:"medfee_sumamt"`
  233. MedinsSetlID string `json:"medins_setl_id"`
  234. Naty string `json:"naty"`
  235. OthPay float64 `json:"oth_pay"`
  236. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  237. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  238. PreselfpayAmt float64 `json:"preselfpay_amt"`
  239. PsnCashPay float64 `json:"psn_cash_pay"`
  240. PsnCertType string `json:"psn_cert_type"`
  241. PsnName string `json:"psn_name"`
  242. PsnNo string `json:"psn_no"`
  243. PsnPartAmt float64 `json:"psn_part_amt"`
  244. PsnType string `json:"psn_type"`
  245. SetlID string `json:"setl_id"`
  246. SetlTime string `json:"setl_time"`
  247. } `json:"setlinfo"`
  248. } `json:"output"`
  249. RefmsgTime string `json:"refmsg_time"`
  250. RespondTime string `json:"respond_time"`
  251. Signtype interface{} `json:"signtype"`
  252. WarnMsg interface{} `json:"warn_msg"`
  253. }
  254. type ResultSeven10265 struct {
  255. Cainfo string `json:"cainfo"`
  256. ErrMsg string `json:"err_msg"`
  257. InfRefmsgid string `json:"inf_refmsgid"`
  258. Infcode string `json:"infcode"`
  259. Output struct {
  260. Setldetail []interface{} `json:"setldetail"`
  261. Setlinfo struct {
  262. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  263. AcctPay float64 `json:"acct_pay"`
  264. ActPayDedc float64 `json:"act_pay_dedc"`
  265. Age float64 `json:"age"`
  266. Balc float64 `json:"balc"`
  267. Brdy string `json:"brdy"`
  268. Certno string `json:"certno"`
  269. ClrOptins string `json:"clr_optins"`
  270. ClrType string `json:"clr_type"`
  271. ClrWay string `json:"clr_way"`
  272. CvlservFlag string `json:"cvlserv_flag"`
  273. CvlservPay float64 `json:"cvlserv_pay"`
  274. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  275. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  276. Gend string `json:"gend"`
  277. HifesPay float64 `json:"hifes_pay"`
  278. HifmiPay float64 `json:"hifmi_pay"`
  279. HifpPay float64 `json:"hifp_pay"`
  280. HospPartAmt float64 `json:"hosp_part_amt"`
  281. InscpScpAmt float64 `json:"inscp_scp_amt"`
  282. Insutype string `json:"insutype"`
  283. MafPay float64 `json:"maf_pay"`
  284. MdtrtCertType string `json:"mdtrt_cert_type"`
  285. HifobPay float64 `json:"hifob_pay"`
  286. MdtrtID string `json:"mdtrt_id"`
  287. MedType string `json:"med_type"`
  288. MedfeeSumamt float64 `json:"medfee_sumamt"`
  289. MedinsSetlID string `json:"medins_setl_id"`
  290. Naty string `json:"naty"`
  291. OthPay float64 `json:"oth_pay"`
  292. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  293. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  294. PreselfpayAmt float64 `json:"preselfpay_amt"`
  295. PsnCashPay float64 `json:"psn_cash_pay"`
  296. PsnCertType string `json:"psn_cert_type"`
  297. PsnName string `json:"psn_name"`
  298. PsnNo string `json:"psn_no"`
  299. PsnPartAmt float64 `json:"psn_part_amt"`
  300. PsnType string `json:"psn_type"`
  301. SetlID string `json:"setl_id"`
  302. SetlTime string `json:"setl_time"`
  303. } `json:"setlinfo"`
  304. } `json:"output"`
  305. RefmsgTime string `json:"refmsg_time"`
  306. RespondTime string `json:"respond_time"`
  307. Signtype interface{} `json:"signtype"`
  308. WarnMsg interface{} `json:"warn_msg"`
  309. }
  310. type ResultSixteen struct {
  311. Cainfo string `json:"cainfo"`
  312. ErrMsg string `json:"err_msg"`
  313. InfRefmsgid string `json:"inf_refmsgid"`
  314. Infcode int64 `json:"infcode"`
  315. Output struct {
  316. Setldetail []interface{} `json:"setldetail"`
  317. Setlinfo struct {
  318. MdtrtID string `json:"mdtrt_id"`
  319. SetlID string `json:"setl_id"`
  320. ClrOptins string `json:"clr_optins"`
  321. SetlTime string `json:"setl_time"`
  322. MedfeeSumamt float64 `json:"medfee_sumamt"`
  323. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  324. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  325. PreselfpayAmt float64 `json:"preselfpay_amt"`
  326. InscpScpAmt float64 `json:"inscp_scp_amt"`
  327. ActPayDedc float64 `json:"act_pay_dedc"`
  328. HifpPay float64 `json:"hifp_pay"`
  329. PoolPropSe float64 `json:"pool_prop_selfpay"`
  330. Lfpay float64 `json:"selfpay"`
  331. CvlservPay float64 `json:"cvlserv_pay"`
  332. HifesPay float64 `json:"hifes_pay"`
  333. HifmiPay float64 `json:"hifmi_pay"`
  334. HifobPay float64 `json:"hifob_pay"`
  335. MafPay float64 `json:"maf_pay"`
  336. OthPay float64 `json:"oth_pay"`
  337. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  338. PsnPartAmt float64 `json:"psn_part_amt"`
  339. AcctPay float64 `json:"acct_pay"`
  340. Balc float64 `json:"balc"`
  341. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  342. HospPartAmt float64 `json:"hosp_part_amt"`
  343. MedinsSetlID string `json:"medins_setl_id"`
  344. PdnCashPay string `json:"pdn_cash_pay"`
  345. } `json:"setlinfo"`
  346. } `json:"output"`
  347. RefmsgTime string `json:"refmsg_time"`
  348. RespondTime string `json:"respond_time"`
  349. Signtype interface{} `json:"signtype"`
  350. WarnMsg interface{} `json:"warn_msg"`
  351. }
  352. type ResultSixteen10265 struct {
  353. Cainfo string `json:"cainfo"`
  354. ErrMsg string `json:"err_msg"`
  355. InfRefmsgid string `json:"inf_refmsgid"`
  356. Infcode string `json:"infcode"`
  357. Output struct {
  358. Setldetail []interface{} `json:"setldetail"`
  359. Setlinfo struct {
  360. MdtrtID string `json:"mdtrt_id"`
  361. SetlID string `json:"setl_id"`
  362. ClrOptins string `json:"clr_optins"`
  363. SetlTime string `json:"setl_time"`
  364. MedfeeSumamt float64 `json:"medfee_sumamt"`
  365. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  366. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  367. PreselfpayAmt float64 `json:"preselfpay_amt"`
  368. InscpScpAmt float64 `json:"inscp_scp_amt"`
  369. ActPayDedc float64 `json:"act_pay_dedc"`
  370. HifpPay float64 `json:"hifp_pay"`
  371. PoolPropSe float64 `json:"pool_prop_selfpay"`
  372. Lfpay float64 `json:"selfpay"`
  373. CvlservPay float64 `json:"cvlserv_pay"`
  374. HifesPay float64 `json:"hifes_pay"`
  375. HifmiPay float64 `json:"hifmi_pay"`
  376. HifobPay float64 `json:"hifob_pay"`
  377. MafPay float64 `json:"maf_pay"`
  378. OthPay float64 `json:"oth_pay"`
  379. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  380. PsnPartAmt float64 `json:"psn_part_amt"`
  381. AcctPay float64 `json:"acct_pay"`
  382. Balc float64 `json:"balc"`
  383. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  384. HospPartAmt float64 `json:"hosp_part_amt"`
  385. MedinsSetlID string `json:"medins_setl_id"`
  386. PdnCashPay string `json:"pdn_cash_pay"`
  387. } `json:"setlinfo"`
  388. } `json:"output"`
  389. RefmsgTime string `json:"refmsg_time"`
  390. RespondTime string `json:"respond_time"`
  391. Signtype interface{} `json:"signtype"`
  392. WarnMsg interface{} `json:"warn_msg"`
  393. }
  394. type Custom struct {
  395. DetItemFeeSumamt string
  396. Cut string
  397. FeedetlSn string
  398. Price string
  399. MedListCodg string
  400. Type int64
  401. AdviceId int64
  402. ProjectId int64
  403. ItemId int64
  404. }
  405. type ResultEmpty struct {
  406. Cainfo interface{} `json:"cainfo"`
  407. ErrMsg string `json:"err_msg"`
  408. InfRefmsgid string `json:"inf_refmsgid"`
  409. Infcode int64 `json:"infcode"`
  410. Output struct {
  411. } `json:"output"`
  412. RefmsgTime string `json:"refmsg_time"`
  413. RespondTime string `json:"respond_time"`
  414. Signtype interface{} `json:"signtype"`
  415. WarnMsg interface{} `json:"warn_msg"`
  416. }
  417. type ResultEmpty10265 struct {
  418. Cainfo interface{} `json:"cainfo"`
  419. ErrMsg string `json:"err_msg"`
  420. InfRefmsgid string `json:"inf_refmsgid"`
  421. Infcode string `json:"infcode"`
  422. Output struct {
  423. } `json:"output"`
  424. RefmsgTime string `json:"refmsg_time"`
  425. RespondTime string `json:"respond_time"`
  426. Signtype interface{} `json:"signtype"`
  427. WarnMsg interface{} `json:"warn_msg"`
  428. }
  429. type CustomResult struct {
  430. BasMednFlag string `json:"bas_medn_flag"`
  431. ChldMedcFlag string `json:"chld_medc_flag"`
  432. ChrgitmLv string `json:"chrgitm_lv"`
  433. Cnt float64 `json:"cnt"`
  434. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  435. DrtReimFlag string `json:"drt_reim_flag"`
  436. FeedetlSn string `json:"feedetl_sn"`
  437. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  438. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  439. InscpScpAmt float64 `json:"inscp_scp_amt"`
  440. ListSpItemFlag string `json:"list_sp_item_flag"`
  441. LmtUsedFlag string `json:"lmt_used_flag"`
  442. MedChrgitmType string `json:"med_chrgitm_type"`
  443. Memo string `json:"memo"`
  444. OverlmtAmt float64 `json:"overlmt_amt"`
  445. PreselfpayAmt float64 `json:"preselfpay_amt"`
  446. Pric float64 `json:"pric"`
  447. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  448. SelfpayProp float64 `json:"selfpay_prop"`
  449. }
  450. func ZHHisManagerApiRegistRouters() {
  451. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  452. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  453. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  454. beego.Router("/zh/api/presettle/get", &ZHHisApiController{}, "get:GetPreSettleInfo")
  455. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  456. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  457. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  458. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  459. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  460. beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
  461. }
  462. func (c *ZHHisApiController) GetZHPatientInfo() {
  463. id_card_no := c.GetString("id_card_no")
  464. admin_user_id, _ := c.GetInt64("admin_user_id")
  465. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  466. if patient.ID == 0 {
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  468. return
  469. }
  470. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  471. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  472. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  473. if config.IsOpen == 1 {
  474. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  475. var dat map[string]interface{}
  476. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  477. fmt.Println(dat)
  478. } else {
  479. fmt.Println(err)
  480. }
  481. userJSONBytes, _ := json.Marshal(dat)
  482. var res ResultTwo
  483. var resTwo10265 ResultTwo10265
  484. if miConfig.Code == "H15049901371" {
  485. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  486. utils.ErrorLog("解析失败:%v", err)
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  488. return
  489. }
  490. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  491. res.Infcode = Infcode
  492. res.ErrMsg = resTwo10265.ErrMsg
  493. res.Output = resTwo10265.Output
  494. res.InfRefmsgid = resTwo10265.InfRefmsgid
  495. res.RespondTime = resTwo10265.RespondTime
  496. res.WarnInfo = resTwo10265.WarnInfo
  497. } else {
  498. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  499. utils.ErrorLog("解析失败:%v", err)
  500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  501. return
  502. }
  503. }
  504. var insutypes []string
  505. var insutype string
  506. var is390 int = 0
  507. var is310 int = 0
  508. for _, item := range res.Output.Iinfo {
  509. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  510. insutypes = append(insutypes, item.Insutype)
  511. }
  512. }
  513. if len(insutypes) == 1 {
  514. insutype = insutypes[0]
  515. } else {
  516. for _, i := range insutypes {
  517. if i == "390" {
  518. is390 = 1
  519. }
  520. if i == "310" {
  521. is310 = 1
  522. }
  523. }
  524. }
  525. if is390 == 1 {
  526. insutype = "390"
  527. }
  528. if is310 == 1 {
  529. insutype = "310"
  530. }
  531. if len(insutypes) == 0 {
  532. insutype = "310"
  533. }
  534. if res.Infcode != 0 {
  535. c.ServeSuccessJSON(map[string]interface{}{
  536. "failed_code": -10,
  537. "msg": res.ErrMsg,
  538. })
  539. } else {
  540. c.ServeSuccessJSON(map[string]interface{}{
  541. "failed_code": 0,
  542. "info": res,
  543. "insutype": insutype,
  544. })
  545. }
  546. }
  547. }
  548. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  549. id, _ := c.GetInt64("id")
  550. record_time := c.GetString("record_time")
  551. name := c.GetString("name")
  552. phone := c.GetString("phone")
  553. id_card_type, _ := c.GetInt64("id_card_type")
  554. certificates, _ := c.GetInt64("certificates")
  555. id_card_no := c.GetString("id_card_no")
  556. doctor, _ := c.GetInt64("doctor")
  557. admin_user_id, _ := c.GetInt64("admin_user_id")
  558. department, _ := c.GetInt64("department")
  559. adm_bed, _ := c.GetInt64("adm_bed")
  560. diagnosis_ids := c.GetString("diagnosis")
  561. sick_type, _ := c.GetInt64("sick_type")
  562. start_time := c.GetString("start_time")
  563. insuplc_admdvs := c.GetString("insuplc_admdvs")
  564. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  565. social_type, _ := c.GetInt64("social_type")
  566. psn_type, _ := c.GetInt64("psn_type")
  567. //reg_type, _ := c.GetInt64("p_type")
  568. med_type, _ := c.GetInt64("med_type")
  569. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  570. timeLayout := "2006-01-02"
  571. loc, _ := time.LoadLocation("Local")
  572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  573. if err != nil {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. recordDateTime := theTime.Unix()
  578. adminInfo := c.GetAdminUserInfo()
  579. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  580. if record.ID != 0 {
  581. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  583. return
  584. }
  585. }
  586. var patient service.Patients
  587. if id == 0 {
  588. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  589. } else {
  590. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  591. }
  592. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  593. sickConfig, _ := service.FindSickById(sick_type)
  594. departmentInfo, _ := service.GetDepartMentDetail(department)
  595. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  596. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  597. result, request_log, result_log := service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", certificates, name)
  598. //fmt.Println(request_log)
  599. //fmt.Println(result_log)
  600. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  601. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  602. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  603. var dat map[string]interface{}
  604. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  605. fmt.Println(dat)
  606. } else {
  607. fmt.Println(err)
  608. }
  609. userJSONBytes, _ := json.Marshal(dat)
  610. //
  611. //var res2 ResultTwo
  612. //if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  613. // utils.ErrorLog("解析失败:%v", err)
  614. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  615. // return
  616. //}
  617. var res2 ResultTwo
  618. var resTwo10265 ResultTwo10265
  619. if miConfig.Code == "H15049901371" {
  620. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  621. utils.ErrorLog("解析失败:%v", err)
  622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  623. return
  624. }
  625. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  626. res2.Infcode = Infcode
  627. res2.ErrMsg = resTwo10265.ErrMsg
  628. res2.Output = resTwo10265.Output
  629. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  630. res2.RespondTime = resTwo10265.RespondTime
  631. res2.WarnInfo = resTwo10265.WarnInfo
  632. } else {
  633. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  634. utils.ErrorLog("解析失败:%v", err)
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  636. return
  637. }
  638. }
  639. //InsuplcAdmdvs = res2.Output.
  640. if social_type != 0 {
  641. } else {
  642. }
  643. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  644. infoStr := string(Iinfos)
  645. var rf []*ResultFive
  646. json.Unmarshal([]byte(infoStr), &rf)
  647. var insutypes []*ResultFive
  648. var insutype string
  649. var is390 int = 0
  650. var is310 int = 0
  651. for _, item := range rf {
  652. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  653. insutypes = append(insutypes, item)
  654. }
  655. }
  656. if len(insutypes) == 1 {
  657. insutype = insutypes[0].Insutype
  658. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  659. } else {
  660. for _, i := range insutypes {
  661. if i.Insutype == "390" {
  662. is390 = 1
  663. }
  664. if i.Insutype == "310" {
  665. is310 = 1
  666. }
  667. }
  668. }
  669. if is390 == 1 {
  670. insutype = "390"
  671. }
  672. if is310 == 1 {
  673. insutype = "310"
  674. }
  675. if len(insutypes) == 0 {
  676. insutype = "310"
  677. }
  678. if len(insutypes) == 2 {
  679. insutype = strconv.FormatInt(social_type, 10)
  680. }
  681. //for _, item := range rf {
  682. // if item.Insutype == insutype {
  683. // insuplc_admdvs = item.InsuplcAdmdvs
  684. // }
  685. //}
  686. if res2.Infcode == 0 {
  687. //var insutypes []string
  688. //
  689. //var insutype string
  690. //var is390 int = 0
  691. //var is310 int = 0
  692. //for _, item := range res2.Output.Iinfo {
  693. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  694. // insutypes = append(insutypes, item.Insutype)
  695. // }
  696. //}
  697. //if len(insutypes) == 1 {
  698. // insutype = insutypes[0]
  699. //} else {
  700. // for _, i := range insutypes {
  701. // if i == "390" {
  702. // is390 = 1
  703. // }
  704. //
  705. // if i == "310" {
  706. // is310 = 1
  707. // }
  708. // }
  709. //}
  710. //if is390 == 1 {
  711. // insutype = "390"
  712. //}
  713. //if is310 == 1 {
  714. // insutype = "310"
  715. //}
  716. //
  717. //if len(insutypes) == 0 {
  718. // insutype = "310"
  719. //}
  720. if len(insuplc_admdvs) == 0 {
  721. insuplc_admdvs = miConfig.InsuplcAdmdvs
  722. }
  723. timestamp := time.Now().Unix()
  724. tempTime := time.Unix(timestamp, 0)
  725. timeFormat := tempTime.Format("20060102150405")
  726. chrgBchno := rand.Intn(100000) + 10000
  727. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  728. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  729. var struct2401 service.Struct2401
  730. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  731. struct2401.Insutype = insutype
  732. struct2401.MdtrtCertType = "02"
  733. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  734. if miConfig.Code == "H15049901371" {
  735. if med_type == 14 {
  736. if insutype == "390" {
  737. struct2401.MedType = "9933"
  738. } else if insutype == "310" {
  739. struct2401.MedType = "990502"
  740. }
  741. } else if med_type == 11 {
  742. struct2401.MedType = "11"
  743. }
  744. } else {
  745. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  746. }
  747. struct2401.IptNo = ipt_otp_no
  748. struct2401.AtddrNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  749. struct2401.ChfpdrName = doctorInfo.UserName
  750. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  751. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  752. struct2401.AdmDeptName = departmentInfo.Name
  753. struct2401.AdmBed = deviceNumber.Number
  754. struct2401.AdmBed = "待定"
  755. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  756. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  757. struct2401.Begntime = start_time
  758. struct2401.DiseCodg = sickConfig.CountryCode
  759. struct2401.DiseName = sickConfig.ClassName
  760. var dises []service.DiseinfoStruct
  761. for index, item := range diagnosisConfig {
  762. var dise service.DiseinfoStruct
  763. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  764. dise.DiagType = "1"
  765. if index == 0 {
  766. dise.MaindiagFlag = "1"
  767. } else {
  768. dise.MaindiagFlag = "2"
  769. }
  770. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  771. dise.DiseDorName = doctorInfo.UserName
  772. dise.DiagCode = item.CountryCode
  773. dise.DiagName = item.ClassName
  774. dise.DiagDept = departmentInfo.Name
  775. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  776. dise.DiagTime = timeFormatOne
  777. dises = append(dises, dise)
  778. }
  779. struct2401.Diseinfo = dises
  780. result, request_log := service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  781. saveLog(result, request_log, "2401", "入医登记")
  782. var dat map[string]interface{}
  783. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  784. fmt.Println(dat)
  785. } else {
  786. fmt.Println(err)
  787. }
  788. userJSONBytes, _ := json.Marshal(dat)
  789. var res ResultThree
  790. var resThree10265 ResultThree10265
  791. if miConfig.Code == "H15049901371" {
  792. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  793. utils.ErrorLog("解析失败:%v", err)
  794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  795. return
  796. }
  797. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  798. res.Infcode = Infcode
  799. res.ErrMsg = resThree10265.ErrMsg
  800. res.Output = resThree10265.Output
  801. res.InfRefmsgid = resThree10265.InfRefmsgid
  802. res.RespondTime = resThree10265.RespondTime
  803. } else {
  804. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  805. utils.ErrorLog("解析失败:%v", err)
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  807. return
  808. }
  809. }
  810. if res.Infcode == 0 {
  811. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  812. //fmt.Println(result2)
  813. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  814. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  815. infoStr := string(Iinfos)
  816. idetinfoStr := string(Idetinfos)
  817. inHospital := &models.HisHospitalCheckRecord{
  818. PatientId: id,
  819. Name: name,
  820. MedicalTreatmentType: med_type,
  821. RecordDate: recordDateTime,
  822. IdCardNo: id_card_no,
  823. AdminUserId: admin_user_id,
  824. Departments: department,
  825. UserOrgId: adminInfo.CurrentOrgId,
  826. Status: 1,
  827. Ctime: time.Now().Unix(),
  828. Mtime: time.Now().Unix(),
  829. Number: res.Output.Result.MdtrtID,
  830. Doctor: doctor,
  831. PsnNo: res2.Output.Baseinfo.PsnNo,
  832. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  833. Certno: res2.Output.Baseinfo.Certno,
  834. PsnName: res2.Output.Baseinfo.PsnName,
  835. Gend: res2.Output.Baseinfo.Gend,
  836. Naty: res2.Output.Baseinfo.Naty,
  837. MedType: med_type,
  838. InsutypeType: insutype,
  839. Brdy: res2.Output.Baseinfo.Brdy,
  840. Iinfo: infoStr,
  841. Idetinfo: idetinfoStr,
  842. IptOtpNo: ipt_otp_no,
  843. AdmBed: adm_bed,
  844. IdCardType: id_card_type,
  845. Diagnosis: diagnosis_ids,
  846. SickType: sick_type,
  847. MdtrtCertType: "02",
  848. InHosptialTime: start_time,
  849. OutHosptialTime: "",
  850. InHospitalStatus: 1,
  851. Certificates: certificates,
  852. Phone: phone,
  853. BalanceAccountsType: balance_accounts_type,
  854. PsnType: psn_type,
  855. InsuplcAdmdvs: insuplc_admdvs,
  856. }
  857. service.CreateHospitalRecord(inHospital)
  858. c.ServeSuccessJSON(map[string]interface{}{
  859. "msg": "办理入院成功",
  860. "info": inHospital,
  861. })
  862. } else {
  863. c.ServeSuccessJSON(map[string]interface{}{
  864. "failed_code": -10,
  865. "msg": res.ErrMsg,
  866. })
  867. }
  868. } else {
  869. c.ServeSuccessJSON(map[string]interface{}{
  870. "failed_code": -10,
  871. "msg": res2.ErrMsg,
  872. })
  873. return
  874. }
  875. }
  876. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  877. id, _ := this.GetInt64("id")
  878. patient_id, _ := this.GetInt64("patient_id")
  879. admin_user_id, _ := this.GetInt64("admin_user_id")
  880. record_time := this.GetString("record_time")
  881. out_time := this.GetString("out_time")
  882. adminInfo := this.GetAdminUserInfo()
  883. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  884. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  885. record, _ := service.GetInHospitalRecord(id)
  886. if record.ID == 0 {
  887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  888. return
  889. }
  890. timeLayout := "2006-01-02"
  891. loc, _ := time.LoadLocation("Local")
  892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  893. if err != nil {
  894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  895. return
  896. }
  897. recordDateTime := theTime.Unix()
  898. var patient service.Patients
  899. if patient_id == 0 {
  900. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  901. } else {
  902. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  903. }
  904. fmt.Println(patient)
  905. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  906. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  907. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  908. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  909. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  910. sickConfig, _ := service.FindSickById(record.SickType)
  911. var struct2402 service.Struct2402
  912. timestamp := time.Now().Unix()
  913. tempTime := time.Unix(timestamp, 0)
  914. //timeFormat := tempTime.Format("20060102150405")
  915. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  916. struct2402.PsnNo = record.PsnNo
  917. struct2402.Insutype = record.InsutypeType
  918. struct2402.DscgWay = "1"
  919. struct2402.Endtime = out_time
  920. struct2402.DscgDeptName = departmentInfo.Number
  921. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  922. struct2402.MdtrtId = record.Number
  923. var dises []service.Diseinfo2402Struct
  924. for index, item := range diagnosisConfig {
  925. var dise service.Diseinfo2402Struct
  926. dise.PsnNo = record.PsnNo
  927. dise.DiagType = "1"
  928. if index == 0 {
  929. dise.MaindiagFlag = "1"
  930. } else {
  931. dise.MaindiagFlag = "2"
  932. }
  933. dise.MdtrtId = record.Number
  934. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  935. dise.DiseDorName = doctorInfo.UserName
  936. dise.DiagCode = item.CountryCode
  937. dise.DiagName = item.ClassName
  938. dise.DiagDept = departmentInfo.Name
  939. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  940. dise.DiagTime = timeFormatOne
  941. dises = append(dises, dise)
  942. }
  943. struct2402.Diseinfo = dises
  944. struct2402.DiseName = sickConfig.ClassName
  945. struct2402.DiseCode = sickConfig.CountryCode
  946. result, request_log := service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  947. //saveLog(result,request_log,"出院)
  948. saveLog(result, request_log, "2402", "出院")
  949. var dat map[string]interface{}
  950. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  951. fmt.Println(dat)
  952. } else {
  953. fmt.Println(err)
  954. }
  955. userJSONBytes, _ := json.Marshal(dat)
  956. var res ResultEmpty
  957. var resEmpty10265 ResultEmpty10265
  958. if miConfig.Code == "H15049901371" {
  959. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  960. utils.ErrorLog("解析失败:%v", err)
  961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  962. return
  963. }
  964. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  965. res.Infcode = Infcode
  966. res.RespondTime = resEmpty10265.RespondTime
  967. res.ErrMsg = resEmpty10265.ErrMsg
  968. res.Output = resEmpty10265.Output
  969. res.WarnMsg = resEmpty10265.WarnMsg
  970. } else {
  971. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  972. utils.ErrorLog("解析失败:%v", err)
  973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  974. return
  975. }
  976. }
  977. if res.Infcode == 0 {
  978. record.OutHospitalStatus = 1
  979. record.OutHosptialTime = struct2402.Endtime
  980. record.OutWay = 1
  981. service.CreateHospitalRecord(&record)
  982. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  983. var total float64
  984. for _, item := range orders {
  985. total = total + item.DetItemFeeSumamt
  986. }
  987. order := &models.HisOrder{
  988. UserOrgId: adminInfo.CurrentOrgId,
  989. HisPatientId: record.ID,
  990. PatientId: record.PatientId,
  991. SettleAccountsDate: recordDateTime,
  992. Ctime: time.Now().Unix(),
  993. Mtime: time.Now().Unix(),
  994. Status: 1,
  995. Number: record.Number,
  996. Infcode: 0,
  997. WarnMsg: "",
  998. Cainfo: "",
  999. ErrMsg: "",
  1000. RespondTime: "",
  1001. InfRefmsgid: "",
  1002. OrderStatus: 1,
  1003. MdtrtId: record.Number,
  1004. IsMedicineInsurance: 1,
  1005. PType: 1,
  1006. MedfeeSumamt: total,
  1007. }
  1008. err = service.CreateOrder(order)
  1009. if err != nil {
  1010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1011. return
  1012. }
  1013. this.ServeSuccessJSON(map[string]interface{}{
  1014. "msg": "出院成功",
  1015. })
  1016. } else {
  1017. this.ServeSuccessJSON(map[string]interface{}{
  1018. "failed_code": -10,
  1019. "msg": res.ErrMsg,
  1020. })
  1021. }
  1022. }
  1023. func (c *ZHHisApiController) GetSettleInfo() {
  1024. order_id, _ := c.GetInt64("order_id")
  1025. patient_id, _ := c.GetInt64("patient_id")
  1026. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1027. admin_user_id, _ := c.GetInt64("admin_user_id")
  1028. pay_way, _ := c.GetInt64("pay_way")
  1029. pay_price, _ := c.GetFloat("pay_price")
  1030. pay_card_no := c.GetString("pay_card_no")
  1031. discount_price, _ := c.GetFloat("discount_price")
  1032. preferential_price, _ := c.GetFloat("preferential_price")
  1033. reality_price, _ := c.GetFloat("reality_price")
  1034. found_price, _ := c.GetFloat("found_price")
  1035. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1036. private_price, _ := c.GetFloat("private_price")
  1037. fapiao_code := c.GetString("fapiao_code")
  1038. fapiao_number := c.GetString("fapiao_number")
  1039. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1040. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1041. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1042. order, _ := service.GetHisOrderByID(order_id)
  1043. var rf []*ResultFive
  1044. json.Unmarshal([]byte(record.Iinfo), &rf)
  1045. chrg_bchno := order.Number
  1046. cert_no := record.Certno
  1047. if record.ID == 0 {
  1048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1049. return
  1050. }
  1051. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1053. return
  1054. }
  1055. if record.IdCardType == 1 {
  1056. } else {
  1057. cert_no = record.Certno
  1058. }
  1059. var result string
  1060. var src_resquest string
  1061. timeLayout := "2006-01-02"
  1062. loc, _ := time.LoadLocation("Local")
  1063. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1064. if err != nil {
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1066. return
  1067. }
  1068. recordStartDateTime := theTime.Unix()
  1069. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1070. if err != nil {
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. recordEndDateTime := theTimeEnd.Unix()
  1075. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1076. var total float64
  1077. for _, item := range prescriptions {
  1078. if item.Type == 1 { //药品
  1079. for _, subItem := range item.HisDoctorAdviceInfo {
  1080. total = total + (subItem.Price * subItem.PrescribingNumber)
  1081. }
  1082. }
  1083. if item.Type == 2 { //项目
  1084. for _, subItem := range item.HisPrescriptionProject {
  1085. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1086. total = total + (subItem.Price * cnt)
  1087. }
  1088. }
  1089. }
  1090. //allTotal := fmt.Sprintf("%.2f", total)
  1091. var allTotal string
  1092. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1093. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1094. var total float64
  1095. for _, item := range orders {
  1096. total = total + item.DetItemFeeSumamt
  1097. }
  1098. allTotal = fmt.Sprintf("%.4f", total)
  1099. } else {
  1100. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1101. }
  1102. result, src_resquest = service.ZHGdyb2304(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates)
  1103. //saveLog()
  1104. saveLog(result, src_resquest, "2304", "住院结算")
  1105. var dat map[string]interface{}
  1106. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1107. fmt.Println(dat)
  1108. } else {
  1109. fmt.Println(err)
  1110. }
  1111. userJSONBytes, _ := json.Marshal(dat)
  1112. var res ResultSeven
  1113. var resSeven10265 ResultSeven10265
  1114. if miConfig.Code == "H15049901371" {
  1115. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1116. utils.ErrorLog("解析失败:%v", err)
  1117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1118. return
  1119. }
  1120. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1121. res.Infcode = Infcode
  1122. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1123. res.RespondTime = resSeven10265.RespondTime
  1124. res.ErrMsg = resSeven10265.ErrMsg
  1125. res.Output = resSeven10265.Output
  1126. res.WarnMsg = resSeven10265.WarnMsg
  1127. res.Cainfo = resSeven10265.Cainfo
  1128. } else {
  1129. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1130. utils.ErrorLog("解析失败:%v", err)
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1132. return
  1133. }
  1134. }
  1135. if res.Infcode != 0 {
  1136. errlog := &models.HisOrderError{
  1137. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1138. Ctime: time.Now().Unix(),
  1139. Mtime: time.Now().Unix(),
  1140. Number: chrg_bchno,
  1141. ErrMsg: res.ErrMsg,
  1142. Status: 1,
  1143. PatientId: patient_id,
  1144. RecordTime: time.Now().Unix(),
  1145. Stage: 6,
  1146. }
  1147. service.CreateErrMsgLog(errlog)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "failed_code": -10,
  1150. "msg": res.ErrMsg,
  1151. })
  1152. return
  1153. } else {
  1154. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1155. order.OrderStatus = 2
  1156. order.DiscountPrice = discount_price
  1157. order.MedicalInsurancePrice = medical_insurance_price
  1158. order.FaPiaoNumber = fapiao_number
  1159. order.FaPiaoCode = fapiao_code
  1160. order.PayWay = pay_way
  1161. order.PayPrice = pay_price
  1162. order.PayCardNo = pay_card_no
  1163. order.PreferentialPrice = preferential_price
  1164. order.RealityPrice = reality_price
  1165. order.FoundPrice = found_price
  1166. order.PrivatePrice = private_price
  1167. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1168. order.SetlId = res.Output.Setlinfo.SetlID
  1169. order.PsnNo = res.Output.Setlinfo.PsnNo
  1170. order.PsnName = res.Output.Setlinfo.PsnName
  1171. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1172. order.Certno = res.Output.Setlinfo.Certno
  1173. order.Gend = res.Output.Setlinfo.Gend
  1174. order.Naty = res.Output.Setlinfo.Naty
  1175. order.Age = res.Output.Setlinfo.Age
  1176. order.Insutype = res.Output.Setlinfo.Insutype
  1177. order.PsnType = res.Output.Setlinfo.PsnType
  1178. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1179. order.SetlTime = res.Output.Setlinfo.SetlTime
  1180. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1181. if res.Output.Setlinfo.MedType == "140104" {
  1182. order.MedType = "14"
  1183. } else {
  1184. order.MedType = res.Output.Setlinfo.MedType
  1185. }
  1186. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1187. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1188. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1189. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1190. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1191. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1192. order.HifpPay = res.Output.Setlinfo.HifpPay
  1193. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1194. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1195. order.HifesPay = res.Output.Setlinfo.HifesPay
  1196. order.HifobPay = res.Output.Setlinfo.HifobPay
  1197. order.MafPay = res.Output.Setlinfo.MafPay
  1198. order.OthPay = res.Output.Setlinfo.OthPay
  1199. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1200. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1201. order.AcctPay = res.Output.Setlinfo.AcctPay
  1202. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1203. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1204. order.Balc = res.Output.Setlinfo.Balc
  1205. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1206. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1207. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1208. order.ClrWay = res.Output.Setlinfo.ClrWay
  1209. order.Creator = order.Creator
  1210. order.Modify = roles.AdminUserId
  1211. order.RequestLog = src_resquest
  1212. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1213. detailStr := string(setlDetail)
  1214. order.SetlDetail = detailStr
  1215. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1216. err = service.UpDateOrder(order)
  1217. if err == nil {
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "msg": "结算成功",
  1220. })
  1221. } else {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1223. return
  1224. }
  1225. }
  1226. }
  1227. func (c *ZHHisApiController) GetPreSettleInfo() {
  1228. order_id, _ := c.GetInt64("order_id")
  1229. patient_id, _ := c.GetInt64("patient_id")
  1230. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1231. admin_user_id, _ := c.GetInt64("admin_user_id")
  1232. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1233. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1234. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1235. order, _ := service.GetHisOrderByID(order_id)
  1236. var allTotal string
  1237. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1238. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1239. var total float64
  1240. for _, item := range orders {
  1241. total = total + item.DetItemFeeSumamt
  1242. }
  1243. allTotal = fmt.Sprintf("%.4f", total)
  1244. } else {
  1245. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1246. }
  1247. var rf []*ResultFive
  1248. json.Unmarshal([]byte(record.Iinfo), &rf)
  1249. chrg_bchno := order.Number
  1250. cert_no := record.Certno
  1251. if record.ID == 0 {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1253. return
  1254. }
  1255. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1256. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1257. // return
  1258. //}
  1259. if record.IdCardType == 1 {
  1260. } else {
  1261. cert_no = record.Certno
  1262. }
  1263. var result string
  1264. var src_resquest string
  1265. result, src_resquest = service.ZHGdyb2303(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates)
  1266. saveLog(result, src_resquest, "2303", "住院预结算")
  1267. var dat map[string]interface{}
  1268. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1269. fmt.Println(dat)
  1270. } else {
  1271. fmt.Println(err)
  1272. }
  1273. userJSONBytes, _ := json.Marshal(dat)
  1274. var res ResultSeven
  1275. var resSeven10265 ResultSeven10265
  1276. if miConfig.Code == "H15049901371" {
  1277. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1278. utils.ErrorLog("解析失败:%v", err)
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1280. return
  1281. }
  1282. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1283. res.Infcode = Infcode
  1284. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1285. res.RespondTime = resSeven10265.RespondTime
  1286. res.ErrMsg = resSeven10265.ErrMsg
  1287. res.Output = resSeven10265.Output
  1288. res.WarnMsg = resSeven10265.WarnMsg
  1289. res.Cainfo = resSeven10265.Cainfo
  1290. } else {
  1291. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1292. utils.ErrorLog("解析失败:%v", err)
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1294. return
  1295. }
  1296. }
  1297. if res.Infcode != 0 {
  1298. errlog := &models.HisOrderError{
  1299. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1300. Ctime: time.Now().Unix(),
  1301. Mtime: time.Now().Unix(),
  1302. Number: chrg_bchno,
  1303. ErrMsg: res.ErrMsg,
  1304. Status: 1,
  1305. PatientId: patient_id,
  1306. RecordTime: time.Now().Unix(),
  1307. Stage: 6,
  1308. }
  1309. service.CreateErrMsgLog(errlog)
  1310. c.ServeSuccessJSON(map[string]interface{}{
  1311. "failed_code": -10,
  1312. "msg": res.ErrMsg,
  1313. })
  1314. return
  1315. } else {
  1316. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1317. order.OrderStatus = 1
  1318. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1319. order.SetlId = res.Output.Setlinfo.SetlID
  1320. order.PsnNo = res.Output.Setlinfo.PsnNo
  1321. order.PsnName = res.Output.Setlinfo.PsnName
  1322. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1323. order.Certno = res.Output.Setlinfo.Certno
  1324. order.Gend = res.Output.Setlinfo.Gend
  1325. order.Naty = res.Output.Setlinfo.Naty
  1326. order.Age = res.Output.Setlinfo.Age
  1327. order.Insutype = res.Output.Setlinfo.Insutype
  1328. order.PsnType = res.Output.Setlinfo.PsnType
  1329. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1330. order.SetlTime = res.Output.Setlinfo.SetlTime
  1331. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1332. if res.Output.Setlinfo.MedType == "140104" {
  1333. order.MedType = "14"
  1334. } else {
  1335. order.MedType = res.Output.Setlinfo.MedType
  1336. }
  1337. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1338. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1339. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1340. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1341. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1342. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1343. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  1344. order.HifpPay = res.Output.Setlinfo.HifpPay
  1345. order.HifesPay = res.Output.Setlinfo.HifesPay
  1346. order.HifobPay = res.Output.Setlinfo.HifobPay
  1347. order.MafPay = res.Output.Setlinfo.MafPay
  1348. order.OthPay = res.Output.Setlinfo.OthPay
  1349. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1350. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1351. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1352. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1353. order.AcctPay = res.Output.Setlinfo.AcctPay
  1354. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1355. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1356. order.Balc = res.Output.Setlinfo.Balc
  1357. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1358. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1359. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1360. order.ClrWay = res.Output.Setlinfo.ClrWay
  1361. order.Creator = order.Creator
  1362. order.Modify = roles.AdminUserId
  1363. order.RequestLog = src_resquest
  1364. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1365. detailStr := string(setlDetail)
  1366. order.SetlDetail = detailStr
  1367. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1368. if record.OutHospitalStatus == 1 && order.ID > 0 {
  1369. err := service.UpDateOrder(order)
  1370. if err == nil {
  1371. c.ServeSuccessJSON(map[string]interface{}{
  1372. "msg": "预结算成功",
  1373. "order_way": 1,
  1374. })
  1375. } else {
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1377. return
  1378. }
  1379. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  1380. c.ServeSuccessJSON(map[string]interface{}{
  1381. "msg": "预结算成功",
  1382. "order": order,
  1383. "order_way": 2,
  1384. })
  1385. }
  1386. }
  1387. }
  1388. func (c *ZHHisApiController) GetUploadInfo() {
  1389. id, _ := c.GetInt64("id")
  1390. record_time := c.GetString("record_time")
  1391. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1392. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1393. admin_user_id, _ := c.GetInt64("admin_user_id")
  1394. timeLayout := "2006-01-02"
  1395. loc, _ := time.LoadLocation("Local")
  1396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1397. if err != nil {
  1398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1399. return
  1400. }
  1401. recordDateTime := theTime.Unix()
  1402. adminUser := c.GetAdminUserInfo()
  1403. var prescriptions []*models.HisPrescription
  1404. data := make(map[string]interface{})
  1405. if settle_accounts_type == 1 { //日结
  1406. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1407. } else { //月结
  1408. start_time_str := c.GetString("start_time")
  1409. end_time_str := c.GetString("end_time")
  1410. timeLayout := "2006-01-02"
  1411. loc, _ := time.LoadLocation("Local")
  1412. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1413. if err != nil {
  1414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. recordStartTime := theStartTime.Unix()
  1418. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1419. if err != nil {
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1421. return
  1422. }
  1423. recordEndTime := theEndTime.Unix()
  1424. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1425. }
  1426. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1427. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1428. if record.ID == 0 {
  1429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1430. return
  1431. }
  1432. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1433. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1434. // return
  1435. //}
  1436. timestamp := time.Now().Unix()
  1437. tempTime := time.Unix(timestamp, 0)
  1438. timeFormat := tempTime.Format("20060102150405")
  1439. chrgBchno := rand.Intn(100000) + 10000
  1440. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  1441. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1442. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1443. department, _ := service.GetDepartMentDetail(record.Departments)
  1444. strconv.FormatInt(record.PatientId, 10)
  1445. //client := &http.Client{}
  1446. data["psn_no"] = record.PsnNo
  1447. data["mdtrt_id"] = record.Number
  1448. data["chrg_bchno"] = chrg_bchno
  1449. data["org_name"] = miConfig.OrgName
  1450. data["doctor"] = roles.UserName
  1451. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1452. data["dept"] = strconv.FormatInt(department.ID, 10)
  1453. data["fixmedins_code"] = miConfig.Code
  1454. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1455. data["dept_code"] = "15"
  1456. } else {
  1457. data["dept_code"] = department.Number
  1458. }
  1459. if miConfig.Code == "H15049901371" {
  1460. if record.MedType == 14 {
  1461. if record.InsutypeType == "390" {
  1462. data["med_type"] = "9933"
  1463. } else if record.InsutypeType == "310" {
  1464. data["med_type"] = "990502"
  1465. }
  1466. } else if record.MedType == 11 {
  1467. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1468. }
  1469. } else {
  1470. if record.MedType == 1112 {
  1471. data["med_type"] = strconv.FormatInt(11, 10)
  1472. } else {
  1473. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1474. }
  1475. }
  1476. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1477. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1478. data["secret_key"] = miConfig.SecretKey
  1479. var ids []int64
  1480. fmt.Println(data)
  1481. for _, item := range prescriptions {
  1482. ids = append(ids, item.ID)
  1483. }
  1484. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1485. if config.IsOpen == 1 { //对接了医保,走医保流程
  1486. var pagesize int = 100
  1487. var start int = 1
  1488. var stop int
  1489. var pagecount int
  1490. var curpage int
  1491. var isSuccess bool = true
  1492. var customs []*models.NewCustom
  1493. for _, item := range prescriptions {
  1494. tm := time.Unix(item.PreTime, 0)
  1495. if item.Type == 1 { //药品
  1496. for _, subItem := range item.HisDoctorAdviceInfo {
  1497. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  1498. //var randNum int
  1499. //randNum = rand.Intn(10000) + 1000
  1500. cus := &models.NewCustom{
  1501. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1502. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1503. FeedetlSn: subItem.FeedetlSn,
  1504. Price: fmt.Sprintf("%.4f", subItem.Price),
  1505. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1506. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  1507. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1508. }
  1509. customs = append(customs, cus)
  1510. }
  1511. }
  1512. }
  1513. if item.Type == 2 { //项目
  1514. for _, subItem := range item.HisPrescriptionProject {
  1515. //var randNum int
  1516. //randNum = rand.Intn(10000) + 1000
  1517. if subItem.Type == 2 {
  1518. if len(subItem.HisProject.MedicalCode) > 0 {
  1519. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1520. cus := &models.NewCustom{
  1521. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1522. Cut: fmt.Sprintf("%.4f", cnt),
  1523. FeedetlSn: subItem.FeedetlSn,
  1524. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1525. MedListCodg: subItem.HisProject.MedicalCode,
  1526. HospApprFlag: -1,
  1527. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1528. }
  1529. customs = append(customs, cus)
  1530. }
  1531. } else if subItem.Type == 3 {
  1532. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  1533. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1534. cus := &models.NewCustom{
  1535. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1536. Cut: fmt.Sprintf("%.4f", cnt),
  1537. FeedetlSn: subItem.FeedetlSn,
  1538. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1539. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1540. HospApprFlag: -1,
  1541. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1542. }
  1543. customs = append(customs, cus)
  1544. }
  1545. }
  1546. }
  1547. }
  1548. //for _, subItem := range item.HisAdditionalCharge {
  1549. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  1550. // cus := &models.NewCustom{
  1551. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*float64(subItem.Count)),
  1552. // Cut: fmt.Sprintf("%.4f", float64(subItem.Count)),
  1553. // FeedetlSn: subItem.FeedetlSn,
  1554. // Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1555. // MedListCodg: subItem.XtHisAddtionConfig.Code,
  1556. // HospApprFlag: -1,
  1557. //
  1558. // }
  1559. // customs = append(customs, cus)
  1560. // }
  1561. //}
  1562. }
  1563. //总页数,向上取整,注意除之前要先转换类型为float64
  1564. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  1565. var ress []*ResultFour
  1566. for curpage = 1; curpage <= pagecount; curpage++ {
  1567. if curpage == 1 {
  1568. start = 1
  1569. } else {
  1570. start = (curpage-1)*pagesize + 1
  1571. }
  1572. stop = curpage * pagesize
  1573. if stop > len(customs) {
  1574. stop = len(customs)
  1575. }
  1576. //data["pre"] = customs[start-1 : stop]
  1577. //bytesData, _ := json.Marshal(data)
  1578. //req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
  1579. //resp, _ := client.Do(req)
  1580. //defer resp.Body.Close()
  1581. //body, ioErr := ioutil.ReadAll(resp.Body)
  1582. //if ioErr != nil {
  1583. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1585. // return
  1586. //}
  1587. resultLog, requestLog := service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string))
  1588. saveLog(resultLog, requestLog, "2301", "上传明细")
  1589. var dat map[string]interface{}
  1590. if err := json.Unmarshal([]byte(resultLog), &dat); err == nil {
  1591. fmt.Println(dat)
  1592. } else {
  1593. fmt.Println(err)
  1594. }
  1595. userJSONBytes, _ := json.Marshal(dat)
  1596. var res ResultFour
  1597. var resFour10265 ResultFour10265
  1598. if miConfig.Code == "H15049901371" {
  1599. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  1600. utils.ErrorLog("解析失败:%v", err)
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1602. return
  1603. }
  1604. res.WarnMsg = resFour10265.WarnMsg
  1605. res.Output = resFour10265.Output
  1606. res.ErrMsg = resFour10265.ErrMsg
  1607. res.RespondTime = resFour10265.RespondTime
  1608. res.InfRefmsgid = resFour10265.InfRefmsgid
  1609. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  1610. res.Infcode = Infcode
  1611. } else {
  1612. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1613. utils.ErrorLog("解析失败:%v", err)
  1614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1615. return
  1616. }
  1617. }
  1618. if res.Infcode == 0 {
  1619. ress = append(ress, &res)
  1620. } else {
  1621. isSuccess = false
  1622. errlog := &models.HisOrderError{
  1623. UserOrgId: adminUser.CurrentOrgId,
  1624. Ctime: time.Now().Unix(),
  1625. Mtime: time.Now().Unix(),
  1626. Number: chrg_bchno,
  1627. ErrMsg: "",
  1628. Status: 1,
  1629. PatientId: id,
  1630. RecordTime: recordDateTime,
  1631. Stage: 4,
  1632. }
  1633. service.CreateErrMsgLog(errlog)
  1634. c.ServeSuccessJSON(map[string]interface{}{
  1635. "failed_code": -10,
  1636. "msg": "上传明细错误,请联系his厂商",
  1637. })
  1638. return
  1639. }
  1640. }
  1641. if isSuccess == true {
  1642. if settle_accounts_type == 1 {
  1643. for _, subItem := range ress {
  1644. for _, item := range subItem.Output.Result {
  1645. temp := strings.Split(item.FeedetlSn, "-")
  1646. var advice_id int64 = 0
  1647. var project_id int64 = 0
  1648. var types int64 = 0
  1649. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1650. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1651. if temp[1] == "1" {
  1652. advice_id = id
  1653. project_id = 0
  1654. } else if temp[1] == "2" {
  1655. advice_id = 0
  1656. project_id = id
  1657. }
  1658. info := &models.HisOrderInfo{
  1659. OrderNumber: record.Number,
  1660. FeedetlSn: item.FeedetlSn,
  1661. UploadDate: recordDateTime,
  1662. AdviceId: advice_id,
  1663. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1664. Cnt: item.Cnt,
  1665. Pric: float64(item.Pric),
  1666. PatientId: record.PatientId,
  1667. PricUplmtAmt: item.PricUplmtAmt,
  1668. SelfpayProp: item.SelfpayProp,
  1669. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1670. OverlmtAmt: item.OverlmtAmt,
  1671. PreselfpayAmt: item.PreselfpayAmt,
  1672. BasMednFlag: item.BasMednFlag,
  1673. MedChrgitmType: item.MedChrgitmType,
  1674. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1675. Status: 1,
  1676. Memo: item.Memo,
  1677. Mtime: time.Now().Unix(),
  1678. InscpScpAmt: item.InscpScpAmt,
  1679. DrtReimFlag: item.DrtReimFlag,
  1680. Ctime: time.Now().Unix(),
  1681. ListSpItemFlag: item.ListSpItemFlag,
  1682. ChldMedcFlag: item.ChldMedcFlag,
  1683. LmtUsedFlag: item.LmtUsedFlag,
  1684. ChrgitmLv: item.ChrgitmLv,
  1685. UserOrgId: adminUser.CurrentOrgId,
  1686. HisPatientId: record.ID,
  1687. OrderId: 0,
  1688. ProjectId: project_id,
  1689. Type: types,
  1690. SettleType: settle_accounts_type,
  1691. }
  1692. service.CreateOrderInfo(info)
  1693. }
  1694. }
  1695. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1696. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1697. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1698. if err == nil {
  1699. c.ServeSuccessJSON(map[string]interface{}{
  1700. "msg": "上传费用明细成功",
  1701. })
  1702. return
  1703. } else {
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1705. return
  1706. }
  1707. } else {
  1708. for _, subItem := range ress {
  1709. for _, item := range subItem.Output.Result {
  1710. temp := strings.Split(item.FeedetlSn, "-")
  1711. var advice_id int64 = 0
  1712. var project_id int64 = 0
  1713. var types int64 = 0
  1714. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1715. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1716. if temp[1] == "1" {
  1717. advice_id = id
  1718. project_id = 0
  1719. } else if temp[1] == "2" {
  1720. advice_id = 0
  1721. project_id = id
  1722. }
  1723. info := &models.HisOrderInfo{
  1724. OrderNumber: record.Number,
  1725. FeedetlSn: item.FeedetlSn,
  1726. UploadDate: time.Now().Unix(),
  1727. AdviceId: advice_id,
  1728. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1729. Cnt: item.Cnt,
  1730. Pric: float64(item.Pric),
  1731. PatientId: record.PatientId,
  1732. PricUplmtAmt: item.PricUplmtAmt,
  1733. SelfpayProp: item.SelfpayProp,
  1734. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1735. OverlmtAmt: item.OverlmtAmt,
  1736. PreselfpayAmt: item.PreselfpayAmt,
  1737. BasMednFlag: item.BasMednFlag,
  1738. MedChrgitmType: item.MedChrgitmType,
  1739. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1740. Status: 1,
  1741. Memo: item.Memo,
  1742. Mtime: time.Now().Unix(),
  1743. InscpScpAmt: item.InscpScpAmt,
  1744. DrtReimFlag: item.DrtReimFlag,
  1745. Ctime: time.Now().Unix(),
  1746. ListSpItemFlag: item.ListSpItemFlag,
  1747. ChldMedcFlag: item.ChldMedcFlag,
  1748. LmtUsedFlag: item.LmtUsedFlag,
  1749. ChrgitmLv: item.ChrgitmLv,
  1750. UserOrgId: adminUser.CurrentOrgId,
  1751. HisPatientId: record.ID,
  1752. ProjectId: project_id,
  1753. Type: types,
  1754. SettleType: settle_accounts_type,
  1755. }
  1756. service.CreateOrderInfo(info)
  1757. }
  1758. }
  1759. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1760. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1761. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1762. c.ServeSuccessJSON(map[string]interface{}{
  1763. "msg": "上传费用明细成功",
  1764. })
  1765. }
  1766. }
  1767. }
  1768. }
  1769. func (c *ZHHisApiController) ZHRefund() {
  1770. order_id, _ := c.GetInt64("order_id")
  1771. admin_user_id, _ := c.GetInt64("admin_user_id")
  1772. adminUser := c.GetAdminUserInfo()
  1773. var order models.HisOrder
  1774. order, _ = service.GetHisOrderByID(order_id)
  1775. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1776. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1777. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1778. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1779. if config.IsOpen == 1 { //对接了医保,走医保流程
  1780. result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1781. saveLog(result, src_resquest, "2305", "退费")
  1782. var dat map[string]interface{}
  1783. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1784. fmt.Println(dat)
  1785. } else {
  1786. fmt.Println(err)
  1787. }
  1788. userJSONBytes, _ := json.Marshal(dat)
  1789. var res ResultSixteen
  1790. var resSixteen ResultSixteen10265
  1791. if miConfig.Code == "H15049901371" {
  1792. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  1793. utils.ErrorLog("解析失败:%v", err)
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1795. return
  1796. }
  1797. res.Cainfo = resSixteen.Cainfo
  1798. res.WarnMsg = resSixteen.WarnMsg
  1799. res.Output = resSixteen.Output
  1800. res.ErrMsg = resSixteen.ErrMsg
  1801. res.RespondTime = resSixteen.RespondTime
  1802. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  1803. res.Infcode = Infcode
  1804. } else {
  1805. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1806. utils.ErrorLog("解析失败:%v", err)
  1807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1808. return
  1809. }
  1810. }
  1811. if res.Infcode == 0 {
  1812. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  1813. record.OutHospitalStatus = 0
  1814. service.CreateHospitalRecord(&record)
  1815. service.UpdataOrderStatusByNumber(record.Number)
  1816. if err == nil {
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "msg": "退费成功",
  1819. })
  1820. } else {
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1822. return
  1823. }
  1824. } else {
  1825. c.ServeSuccessJSON(map[string]interface{}{
  1826. "code": -10,
  1827. "msg": res.ErrMsg,
  1828. })
  1829. }
  1830. } else {
  1831. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1832. if err == nil {
  1833. c.ServeSuccessJSON(map[string]interface{}{
  1834. "msg": "退费成功",
  1835. })
  1836. } else {
  1837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1838. return
  1839. }
  1840. }
  1841. }
  1842. func (c *ZHHisApiController) ZHRefundDetail() {
  1843. patient_id, _ := c.GetInt64("patient_id")
  1844. his_patient_id, _ := c.GetInt64("his_patient_id")
  1845. record_time := c.GetString("record_time")
  1846. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1847. //order_id, _ := c.GetInt64("order_id")
  1848. admin_user_id, _ := c.GetInt64("admin_user_id")
  1849. timeLayout := "2006-01-02"
  1850. loc, _ := time.LoadLocation("Local")
  1851. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1852. if err != nil {
  1853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1854. return
  1855. }
  1856. recordDateTime := theTime.Unix()
  1857. adminUser := c.GetAdminUserInfo()
  1858. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  1859. if err != nil {
  1860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1861. return
  1862. }
  1863. recordDateTimeTwo := theTimeTwo.Unix()
  1864. //var prescriptions []*models.HisPrescription
  1865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1866. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1867. if settle_accounts_type == 1 { //日结
  1868. record, _ := service.GetInHospitalRecord(his_patient_id)
  1869. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  1870. var isSuccess bool = true
  1871. for _, item := range infos {
  1872. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  1873. saveLog(result, requestLog, "2302", "日结退明细")
  1874. var dat map[string]interface{}
  1875. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1876. fmt.Println(dat)
  1877. } else {
  1878. fmt.Println(err)
  1879. }
  1880. userJSONBytes, _ := json.Marshal(dat)
  1881. var res2 ResultEmpty
  1882. var resEmpty10265 ResultEmpty10265
  1883. if miConfig.Code == "H15049901371" {
  1884. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1885. utils.ErrorLog("解析失败:%v", err)
  1886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1887. return
  1888. }
  1889. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1890. res2.Infcode = Infcode
  1891. res2.RespondTime = resEmpty10265.RespondTime
  1892. res2.ErrMsg = resEmpty10265.ErrMsg
  1893. res2.Output = resEmpty10265.Output
  1894. res2.WarnMsg = resEmpty10265.WarnMsg
  1895. } else {
  1896. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1897. utils.ErrorLog("解析失败:%v", err)
  1898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1899. return
  1900. }
  1901. }
  1902. if res2.Infcode == -1 {
  1903. isSuccess = false
  1904. }
  1905. }
  1906. if isSuccess {
  1907. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  1908. if err != nil {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1910. return
  1911. }
  1912. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1913. if err1 != nil {
  1914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1915. return
  1916. }
  1917. c.ServeSuccessJSON(map[string]interface{}{
  1918. "msg": "撤销明细成功",
  1919. })
  1920. }
  1921. } else {
  1922. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1923. //var order models.HisOrder
  1924. //order, _ = service.GetHisOrderByID(order_id)
  1925. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1926. record, _ := service.GetInHospitalRecord(his_patient_id)
  1927. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1928. if config.IsOpen == 1 { //对接了医保,走医保流程
  1929. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  1930. //saveLog(result,requestLog,)
  1931. saveLog(result, requestLog, "2302", "月结退明细")
  1932. var dat map[string]interface{}
  1933. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1934. fmt.Println(dat)
  1935. } else {
  1936. fmt.Println(err)
  1937. }
  1938. userJSONBytes, _ := json.Marshal(dat)
  1939. var res2 ResultEmpty
  1940. var resEmpty10265 ResultEmpty10265
  1941. if miConfig.Code == "H15049901371" {
  1942. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1943. utils.ErrorLog("解析失败:%v", err)
  1944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1945. return
  1946. }
  1947. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1948. res2.Infcode = Infcode
  1949. res2.RespondTime = resEmpty10265.RespondTime
  1950. res2.ErrMsg = resEmpty10265.ErrMsg
  1951. res2.Output = resEmpty10265.Output
  1952. res2.WarnMsg = resEmpty10265.WarnMsg
  1953. } else {
  1954. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1955. utils.ErrorLog("解析失败:%v", err)
  1956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1957. return
  1958. }
  1959. }
  1960. if res2.Infcode == 0 {
  1961. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  1962. if err == nil {
  1963. c.ServeSuccessJSON(map[string]interface{}{
  1964. "msg": "撤销明细成功",
  1965. })
  1966. } else {
  1967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1968. return
  1969. }
  1970. } else {
  1971. c.ServeSuccessJSON(map[string]interface{}{
  1972. "code": -10,
  1973. "msg": res2.ErrMsg,
  1974. })
  1975. }
  1976. }
  1977. }
  1978. }
  1979. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  1980. id, _ := this.GetInt64("id")
  1981. admin_user_id, _ := this.GetInt64("admin_user_id")
  1982. adminInfo := this.GetAdminUserInfo()
  1983. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1984. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1985. record, _ := service.GetInHospitalRecord(id)
  1986. if record.ID == 0 {
  1987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1988. return
  1989. }
  1990. result, requestLog := service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1991. saveLog(result, requestLog, "2405", "出院登记撤销")
  1992. var dat map[string]interface{}
  1993. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1994. fmt.Println(dat)
  1995. } else {
  1996. fmt.Println(err)
  1997. }
  1998. userJSONBytes, _ := json.Marshal(dat)
  1999. var res ResultEmpty
  2000. var resEmpty10265 ResultEmpty10265
  2001. if miConfig.Code == "H15049901371" {
  2002. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2003. utils.ErrorLog("解析失败:%v", err)
  2004. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2005. return
  2006. }
  2007. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2008. res.Infcode = Infcode
  2009. res.RespondTime = resEmpty10265.RespondTime
  2010. res.ErrMsg = resEmpty10265.ErrMsg
  2011. res.Output = resEmpty10265.Output
  2012. res.WarnMsg = resEmpty10265.WarnMsg
  2013. } else {
  2014. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2015. utils.ErrorLog("解析失败:%v", err)
  2016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2017. return
  2018. }
  2019. }
  2020. if res.Infcode == 0 {
  2021. record.OutHospitalStatus = 0
  2022. service.CreateHospitalRecord(&record)
  2023. service.UpdataOrderStatusByNumber(record.Number)
  2024. this.ServeSuccessJSON(map[string]interface{}{
  2025. "msg": "撤销出院成功",
  2026. })
  2027. } else {
  2028. this.ServeSuccessJSON(map[string]interface{}{
  2029. "failed_code": -10,
  2030. "msg": res.ErrMsg,
  2031. })
  2032. }
  2033. }
  2034. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  2035. id, _ := this.GetInt64("id")
  2036. admin_user_id, _ := this.GetInt64("admin_user_id")
  2037. adminInfo := this.GetAdminUserInfo()
  2038. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2039. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2040. record, _ := service.GetInHospitalRecord(id)
  2041. if record.ID == 0 {
  2042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2043. return
  2044. }
  2045. result, requestLog := service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2046. //saveLog()
  2047. saveLog(result, requestLog, "2404", "入院登记撤销")
  2048. var dat map[string]interface{}
  2049. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2050. fmt.Println(dat)
  2051. } else {
  2052. fmt.Println(err)
  2053. }
  2054. userJSONBytes, _ := json.Marshal(dat)
  2055. var res ResultEmpty
  2056. var resEmpty10265 ResultEmpty10265
  2057. if miConfig.Code == "H15049901371" {
  2058. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2059. utils.ErrorLog("解析失败:%v", err)
  2060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2061. return
  2062. }
  2063. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2064. res.Infcode = Infcode
  2065. res.RespondTime = resEmpty10265.RespondTime
  2066. res.ErrMsg = resEmpty10265.ErrMsg
  2067. res.Output = resEmpty10265.Output
  2068. res.WarnMsg = resEmpty10265.WarnMsg
  2069. } else {
  2070. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2071. utils.ErrorLog("解析失败:%v", err)
  2072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2073. return
  2074. }
  2075. }
  2076. if res.Infcode == 0 {
  2077. record.Status = 0
  2078. service.CreateHospitalRecord(&record)
  2079. this.ServeSuccessJSON(map[string]interface{}{
  2080. "msg": "撤销入院成功",
  2081. })
  2082. } else {
  2083. this.ServeSuccessJSON(map[string]interface{}{
  2084. "failed_code": -10,
  2085. "msg": res.ErrMsg,
  2086. })
  2087. }
  2088. }
  2089. func saveLog(result string, request string, infno string, desc string) {
  2090. org_id, _ := beego.AppConfig.Int64("org_id")
  2091. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2092. dir := miConfig.OrgName + "日志"
  2093. utils.Mkdir(dir)
  2094. month := time.Unix(1557042972, 0).Format("1")
  2095. year := time.Now().Format("2006")
  2096. month = time.Now().Format("01")
  2097. day := time.Now().Format("02")
  2098. hour := time.Now().Format("15")
  2099. min := time.Now().Format("04")
  2100. sec := time.Now().Format("05")
  2101. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2102. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2103. file_name := file + ".txt"
  2104. file_path := miConfig.OrgName + "日志" + "/" + file_name
  2105. exist, _ := utils.PathExists(file_path)
  2106. if exist { //存在
  2107. fmt.Println("存在")
  2108. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2109. if err != nil {
  2110. fmt.Println("read fail")
  2111. }
  2112. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2113. n, _ := f.Seek(0, 2)
  2114. _, err = f.WriteAt([]byte(content), n)
  2115. } else { //不存在
  2116. fmt.Println("文件不存在,创建文件")
  2117. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2118. defer f.Close()
  2119. if err != nil {
  2120. } else {
  2121. _, err = f.Write([]byte("记录日志"))
  2122. }
  2123. }
  2124. }
  2125. type Charset string
  2126. const (
  2127. UTF8 = Charset("UTF-8")
  2128. GB18030 = Charset("GB18030")
  2129. )
  2130. func ConvertToString(src string, srcCode string, tagCode string) string {
  2131. srcCoder := mahonia.NewDecoder(srcCode)
  2132. srcResult := srcCoder.ConvertString(src)
  2133. tagCoder := mahonia.NewDecoder(tagCode)
  2134. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  2135. result := string(cdata)
  2136. return result
  2137. }