his_api_controller.go 82KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  32. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  33. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  34. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  35. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  36. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  37. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  38. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  39. beego.Router("/api/code/get", &HisApiController{}, "get:GetCode")
  40. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  41. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  42. //beego.Router("/api/returnrecord/put", &HisApiController{}, "get:ReturnRecord")
  43. }
  44. func (c *HisApiController) Sscard() {
  45. r := CardInit()
  46. if r == 0 {
  47. GetBaseInfo()
  48. }
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "list": "11",
  51. })
  52. }
  53. func GetBaseInfo() error {
  54. handle := syscall.MustLoadDLL("SSCard.dll")
  55. ReadCardBas := handle.MustFindProc("ReadCardBas")
  56. str := make([]byte, 256)
  57. str1 := make([]byte, 256)
  58. r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  59. fmt.Println(string(str))
  60. fmt.Println(r)
  61. return nil
  62. }
  63. func CardInit() int {
  64. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  65. add := DllTestDef.MustFindProc("Init")
  66. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  67. if err != nil {
  68. fmt.Println("SSCard的运算结果为:", ret)
  69. }
  70. result := int(ret)
  71. return result
  72. }
  73. func IntPtr(n int) uintptr {
  74. return uintptr(n)
  75. }
  76. func StrPtr(s string) uintptr {
  77. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  78. }
  79. type ResultTwo struct {
  80. ErrMsg string `json:"err_msg"`
  81. InfRefmsgid string `json:"inf_refmsgid"`
  82. Infcode int64 `json:"infcode"`
  83. Output struct {
  84. Baseinfo struct {
  85. Age float64 `json:"age"`
  86. Brdy string `json:"brdy"`
  87. Certno string `json:"certno"`
  88. Gend string `json:"gend"`
  89. Naty string `json:"naty"`
  90. PsnCertType string `json:"psn_cert_type"`
  91. PsnName string `json:"psn_name"`
  92. PsnNo string `json:"psn_no"`
  93. } `json:"baseinfo"`
  94. Idetinfo []interface{} `json:"idetinfo"`
  95. Iinfo []struct {
  96. Balc int64 `json:"balc"`
  97. CvlservFlag string `json:"cvlserv_flag"`
  98. EmpName string `json:"emp_name"`
  99. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  100. Insutype string `json:"insutype"`
  101. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  102. PausInsuDate interface{} `json:"paus_insu_date"`
  103. PsnInsuDate string `json:"psn_insu_date"`
  104. PsnInsuStas string `json:"psn_insu_stas"`
  105. PsnType string `json:"psn_type"`
  106. } `json:"insuinfo"`
  107. } `json:"output"`
  108. RefmsgTime string `json:"refmsg_time"`
  109. RespondTime string `json:"respond_time"`
  110. Signtype interface{} `json:"signtype"`
  111. WarnInfo interface{} `json:"warn_info"`
  112. }
  113. type ResultThree struct {
  114. Cainfo interface{} `json:"cainfo"`
  115. ErrMsg string `json:"err_msg"`
  116. InfRefmsgid string `json:"inf_refmsgid"`
  117. Infcode int64 `json:"infcode"`
  118. Output struct {
  119. Data struct {
  120. IptOtpNo string `json:"ipt_otp_no"`
  121. MdtrtID string `json:"mdtrt_id"`
  122. PsnNo string `json:"psn_no"`
  123. } `json:"data"`
  124. } `json:"output"`
  125. RefmsgTime string `json:"refmsg_time"`
  126. RespondTime string `json:"respond_time"`
  127. Signtype interface{} `json:"signtype"`
  128. WarnMsg interface{} `json:"warn_msg"`
  129. }
  130. type ResultFour struct {
  131. Cainfo string `json:"cainfo"`
  132. ErrMsg string `json:"err_msg"`
  133. InfRefmsgid string `json:"inf_refmsgid"`
  134. Infcode int64 `json:"infcode"`
  135. Output struct {
  136. Result []struct {
  137. BasMednFlag string `json:"bas_medn_flag"`
  138. ChldMedcFlag string `json:"chld_medc_flag"`
  139. ChrgitmLv string `json:"chrgitm_lv"`
  140. Cnt float64 `json:"cnt"`
  141. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  142. DrtReimFlag string `json:"drt_reim_flag"`
  143. FeedetlSn string `json:"feedetl_sn"`
  144. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  145. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  146. InscpScpAmt float64 `json:"inscp_scp_amt"`
  147. ListSpItemFlag string `json:"list_sp_item_flag"`
  148. LmtUsedFlag string `json:"lmt_used_flag"`
  149. MedChrgitmType string `json:"med_chrgitm_type"`
  150. Memo string `json:"memo"`
  151. OverlmtAmt float64 `json:"overlmt_amt"`
  152. PreselfpayAmt float64 `json:"preselfpay_amt"`
  153. Pric float64 `json:"pric"`
  154. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  155. SelfpayProp float64 `json:"selfpay_prop"`
  156. } `json:"result"`
  157. } `json:"output"`
  158. RefmsgTime string `json:"refmsg_time"`
  159. RespondTime string `json:"respond_time"`
  160. Signtype string `json:"signtype"`
  161. WarnMsg string `json:"warn_msg"`
  162. }
  163. type ResultFive struct {
  164. Insutype string `json:"insutype"`
  165. }
  166. type ResultSix struct {
  167. Cainfo interface{} `json:"cainfo"`
  168. ErrMsg string `json:"err_msg"`
  169. InfRefmsgid string `json:"inf_refmsgid"`
  170. Infcode int64 `json:"infcode"`
  171. Output struct {
  172. } `json:"output"`
  173. RefmsgTime string `json:"refmsg_time"`
  174. RespondTime string `json:"respond_time"`
  175. Signtype interface{} `json:"signtype"`
  176. WarnMsg interface{} `json:"warn_msg"`
  177. }
  178. type ResultSeven struct {
  179. Cainfo string `json:"cainfo"`
  180. ErrMsg string `json:"err_msg"`
  181. InfRefmsgid string `json:"inf_refmsgid"`
  182. Infcode int64 `json:"infcode"`
  183. Output struct {
  184. Setldetail []interface{} `json:"setldetail"`
  185. Setlinfo struct {
  186. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  187. AcctPay float64 `json:"acct_pay"`
  188. ActPayDedc float64 `json:"act_pay_dedc"`
  189. Age float64 `json:"age"`
  190. Balc float64 `json:"balc"`
  191. Brdy string `json:"brdy"`
  192. Certno string `json:"certno"`
  193. ClrOptins string `json:"clr_optins"`
  194. ClrType string `json:"clr_type"`
  195. ClrWay string `json:"clr_way"`
  196. CvlservFlag string `json:"cvlserv_flag"`
  197. CvlservPay float64 `json:"cvlserv_pay"`
  198. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  199. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  200. Gend string `json:"gend"`
  201. HifesPay float64 `json:"hifes_pay"`
  202. HifmiPay float64 `json:"hifmi_pay"`
  203. HifpPay float64 `json:"hifp_pay"`
  204. HospPartAmt float64 `json:"hosp_part_amt"`
  205. InscpScpAmt float64 `json:"inscp_scp_amt"`
  206. Insutype string `json:"insutype"`
  207. MafPay float64 `json:"maf_pay"`
  208. MdtrtCertType string `json:"mdtrt_cert_type"`
  209. HifobPay float64 `json:"hifob_pay"`
  210. MdtrtID string `json:"mdtrt_id"`
  211. MedType string `json:"med_type"`
  212. MedfeeSumamt float64 `json:"medfee_sumamt"`
  213. MedinsSetlID string `json:"medins_setl_id"`
  214. Naty string `json:"naty"`
  215. OthPay float64 `json:"oth_pay"`
  216. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  217. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  218. PreselfpayAmt float64 `json:"preselfpay_amt"`
  219. PsnCashPay float64 `json:"psn_cash_pay"`
  220. PsnCertType string `json:"psn_cert_type"`
  221. PsnName string `json:"psn_name"`
  222. PsnNo string `json:"psn_no"`
  223. PsnPartAmt float64 `json:"psn_part_amt"`
  224. PsnType string `json:"psn_type"`
  225. SetlID string `json:"setl_id"`
  226. SetlTime string `json:"setl_time"`
  227. } `json:"setlinfo"`
  228. } `json:"output"`
  229. RefmsgTime string `json:"refmsg_time"`
  230. RespondTime string `json:"respond_time"`
  231. Signtype interface{} `json:"signtype"`
  232. WarnMsg interface{} `json:"warn_msg"`
  233. }
  234. type ResultEight struct {
  235. Cainfo string `json:"cainfo"`
  236. ErrMsg string `json:"err_msg"`
  237. InfRefmsgid string `json:"inf_refmsgid"`
  238. Infcode int64 `json:"infcode"`
  239. Output struct {
  240. Stmtinfo struct {
  241. SetlOptins string `json:"setl_optins"`
  242. StmtRslt string `json:"stmt_rslt"`
  243. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  244. } `json:"stmtinfo"`
  245. } `json:"output"`
  246. RefmsgTime string `json:"refmsg_time"`
  247. RespondTime string `json:"respond_time"`
  248. Signtype interface{} `json:"signtype"`
  249. WarnMsg interface{} `json:"warn_msg"`
  250. }
  251. type ResultNine struct {
  252. Cainfo string `json:"cainfo"`
  253. ErrMsg string `json:"err_msg"`
  254. InfRefmsgid string `json:"inf_refmsgid"`
  255. Infcode int64 `json:"infcode"`
  256. Output struct {
  257. FileQuryNo string `json:"file_qury_no"`
  258. } `json:"output"`
  259. RefmsgTime string `json:"refmsg_time"`
  260. RespondTime string `json:"respond_time"`
  261. Signtype interface{} `json:"signtype"`
  262. WarnMsg interface{} `json:"warn_msg"`
  263. }
  264. type ResultTen struct {
  265. Cainfo string `json:"cainfo"`
  266. ErrMsg string `json:"err_msg"`
  267. InfRefmsgid string `json:"inf_refmsgid"`
  268. Infcode int64 `json:"infcode"`
  269. Output struct {
  270. DldEndtime string `json:"dld_endtime"`
  271. FileQuryNo string `json:"file_qury_no"`
  272. Filename string `json:"filename"`
  273. } `json:"output"`
  274. RefmsgTime string `json:"refmsg_time"`
  275. RespondTime string `json:"respond_time"`
  276. Signtype interface{} `json:"signtype"`
  277. WarnMsg interface{} `json:"warn_msg"`
  278. }
  279. type ResultEleven struct {
  280. Cainfo string `json:"cainfo"`
  281. ErrMsg string `json:"err_msg"`
  282. InfRefmsgid string `json:"inf_refmsgid"`
  283. Infcode int64 `json:"infcode"`
  284. Output struct {
  285. Setlinfo struct {
  286. FixmedinsName string `json:"fixmedins_name"`
  287. FixmedinsCode string `json:"fixmedins_code"`
  288. PsnNo string `json:"psn_no"`
  289. PsnName string `json:"psn_name"`
  290. HifobPay float64 `json:"hifob_pay"`
  291. Gend string `json:"gend"`
  292. Brdy string `json:"brdy"`
  293. PsnCertType string `json:"psn_cert_type"`
  294. PsnType string `json:"psn_type"`
  295. EmpName string `json:"emp_name"`
  296. Certno string `json:"certno"`
  297. Insutype string `json:"insutype"`
  298. MedfeeSumamt float64 `json:"medfee_sumamt"`
  299. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  300. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  301. PreselfpayAmt float64 `json:"preselfpay_amt"`
  302. InscpScpAmt float64 `json:"inscp_scp_amt"`
  303. ActPayDedc float64 `json:"act_pay_dedc"`
  304. HifpPay float64 `json:"hifp_pay"`
  305. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  306. CvlservPay float64 `json:"cvlserv_pay"`
  307. HifesPay float64 `json:"hifes_pay"`
  308. HifmiPay float64 `json:"hifmi_pay"`
  309. MafPay float64 `json:"maf_pay"`
  310. OthPay float64 `json:"oth_pay"`
  311. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  312. PsnPay float64 `json:"psn_pay"`
  313. AcctPay float64 `json:"acct_pay"`
  314. CashPayamt float64 `json:"cash_payamt"`
  315. Balc float64 `json:"balc"`
  316. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  317. MedinsSetlId string `json:"medins_setl_id"`
  318. RefdSetlFlag string `json:"refd_setl_flag"`
  319. SetlTime string `json:"setl_time"`
  320. } `json:"setlinfo"`
  321. } `json:"output"`
  322. RefmsgTime string `json:"refmsg_time"`
  323. RespondTime string `json:"respond_time"`
  324. Signtype interface{} `json:"signtype"`
  325. WarnMsg interface{} `json:"warn_msg"`
  326. }
  327. type Custom struct {
  328. DetItemFeeSumamt string
  329. Cut string
  330. FeedetlSn string
  331. Price string
  332. MedListCodg string
  333. Type int64
  334. AdviceId int64
  335. ProjectId int64
  336. ItemId int64
  337. }
  338. //获取个人信息----挂号-----上传就诊信息
  339. func (c *HisApiController) GetRegisterInfo() {
  340. id, _ := c.GetInt64("id")
  341. record_time := c.GetString("record_time")
  342. name := c.GetString("name")
  343. gender, _ := c.GetInt64("gender")
  344. age, _ := c.GetInt64("age")
  345. birthday := c.GetString("birthday")
  346. phone := c.GetString("phone")
  347. medical_care, _ := c.GetInt64("medical_care")
  348. id_card := c.GetString("id_card")
  349. register_type, _ := c.GetInt64("register_type")
  350. registration_fee, _ := c.GetFloat("registration_fee")
  351. medical_expenses, _ := c.GetFloat("medical_expenses")
  352. certificates, _ := c.GetInt64("certificates")
  353. settlementValue, _ := c.GetInt64("settlement_value")
  354. social_type, _ := c.GetInt64("social_type")
  355. medical_insurance_card := c.GetString("medical_insurance_card")
  356. timeLayout := "2006-01-02"
  357. loc, _ := time.LoadLocation("Local")
  358. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  359. birthUnix := birthdays.Unix()
  360. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  361. if err != nil {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  363. return
  364. }
  365. recordDateTime := theTime.Unix()
  366. adminInfo := c.GetAdminUserInfo()
  367. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  368. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  369. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  370. fmt.Println(miConfig.SecretKey)
  371. if patient == nil {
  372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  373. return
  374. }
  375. if len(patient.IdCardNo) == 0 {
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  377. return
  378. }
  379. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  380. if config.IsOpen == 1 {
  381. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  382. resp, requestErr := http.Get(api)
  383. if requestErr != nil {
  384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  385. return
  386. }
  387. defer resp.Body.Close()
  388. body, ioErr := ioutil.ReadAll(resp.Body)
  389. if ioErr != nil {
  390. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  392. return
  393. }
  394. var respJSON map[string]interface{}
  395. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  396. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  398. return
  399. }
  400. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  401. userJSONBytes, _ := json.Marshal(userJSON)
  402. var res ResultTwo
  403. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  404. utils.ErrorLog("解析失败:%v", err)
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  406. return
  407. }
  408. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  409. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  410. infoStr := string(Iinfos)
  411. idetinfoStr := string(Idetinfos)
  412. if res.Infcode == 0 {
  413. his := models.VMHisPatient{
  414. Name: name,
  415. Gender: gender,
  416. Birthday: birthUnix,
  417. MedicalTreatmentType: medical_care,
  418. IdType: certificates,
  419. IdCardNo: id_card,
  420. BalanceAccountsType: settlementValue,
  421. SocialType: social_type,
  422. MedicalInsuranceNumber: medical_insurance_card,
  423. RegisterType: register_type,
  424. RegisterCost: registration_fee,
  425. TreatmentCost: medical_expenses,
  426. Status: 1,
  427. Ctime: time.Now().Unix(),
  428. Mtime: time.Now().Unix(),
  429. PsnNo: res.Output.Baseinfo.PsnNo,
  430. PsnCertType: res.Output.Baseinfo.PsnCertType,
  431. Certno: res.Output.Baseinfo.Certno,
  432. PsnName: res.Output.Baseinfo.PsnName,
  433. Gend: res.Output.Baseinfo.Gend,
  434. Naty: res.Output.Baseinfo.Naty,
  435. Brdy: res.Output.Baseinfo.Brdy,
  436. Age: res.Output.Baseinfo.Age,
  437. Iinfo: infoStr,
  438. Idetinfo: idetinfoStr,
  439. PatientId: patient.ID,
  440. RecordDate: theTime.Unix(),
  441. UserOrgId: adminInfo.CurrentOrgId,
  442. AdminUserId: adminInfo.AdminUser.Id,
  443. IsReturn: 1,
  444. }
  445. timestamp := time.Now().Unix()
  446. tempTime := time.Unix(timestamp, 0)
  447. timeFormat := tempTime.Format("20060102150405")
  448. chrgBchno := rand.Intn(100000) + 10000
  449. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  450. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  451. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  452. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  453. fmt.Println(miConfig.SecretKey)
  454. if count <= 0 {
  455. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  456. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  457. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  458. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  459. resp, requestErr := http.Get(api)
  460. if requestErr != nil {
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  462. return
  463. }
  464. defer resp.Body.Close()
  465. body, ioErr := ioutil.ReadAll(resp.Body)
  466. if ioErr != nil {
  467. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  469. return
  470. }
  471. var respJSON map[string]interface{}
  472. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  473. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  475. return
  476. }
  477. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  478. userJSONBytes, _ := json.Marshal(respJSON)
  479. var res ResultThree
  480. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  481. utils.ErrorLog("解析失败:%v", err)
  482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  483. return
  484. }
  485. if res.Infcode == -1 {
  486. adminUser := c.GetAdminUserInfo()
  487. errlog := &models.HisOrderError{
  488. UserOrgId: adminUser.CurrentOrgId,
  489. Ctime: time.Now().Unix(),
  490. Mtime: time.Now().Unix(),
  491. ErrMsg: res.ErrMsg,
  492. Status: 1,
  493. PatientId: id,
  494. RecordTime: recordDateTime,
  495. Stage: 2,
  496. }
  497. service.CreateErrMsgLog(errlog)
  498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  499. return
  500. }
  501. his.Number = res.Output.Data.MdtrtID
  502. his.PsnNo = res.Output.Data.PsnNo
  503. his.IptOtpNo = res.Output.Data.IptOtpNo
  504. his.IdCardNo = patient.IdCardNo
  505. his.PhoneNumber = patient.Phone
  506. his.UserOrgId = adminInfo.CurrentOrgId
  507. his.Ctime = time.Now().Unix()
  508. his.Mtime = time.Now().Unix()
  509. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  510. sickConfig, _ := service.FindSickById(patientPrescription.SickType)
  511. fmt.Println("1112222222")
  512. fmt.Println(sickConfig.ClassName)
  513. fmt.Println(sickConfig.CountryCode)
  514. fmt.Println("223333333")
  515. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  516. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  517. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  518. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  519. resp2, requestErr2 := http.Get(api2)
  520. if requestErr2 != nil {
  521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  522. return
  523. }
  524. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  525. if ioErr2 != nil {
  526. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  528. return
  529. }
  530. var respJSON2 map[string]interface{}
  531. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  532. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  534. return
  535. }
  536. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  537. userJSONBytes2, _ := json.Marshal(respJSON2)
  538. var res2 ResultSix
  539. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  540. utils.ErrorLog("解析失败:%v", err)
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  542. return
  543. }
  544. if res2.Infcode == -1 {
  545. adminUser := c.GetAdminUserInfo()
  546. errlog := &models.HisOrderError{
  547. UserOrgId: adminUser.CurrentOrgId,
  548. Ctime: time.Now().Unix(),
  549. Mtime: time.Now().Unix(),
  550. ErrMsg: res2.ErrMsg,
  551. Status: 1,
  552. PatientId: id,
  553. RecordTime: recordDateTime,
  554. Stage: 3,
  555. }
  556. service.CreateErrMsgLog(errlog)
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  558. return
  559. }
  560. his.Status = 1
  561. service.CreateHisPatientTwo(&his)
  562. c.ServeSuccessJSON(map[string]interface{}{
  563. "his_info": his,
  564. })
  565. } else {
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  567. return
  568. }
  569. } else {
  570. adminUser := c.GetAdminUserInfo()
  571. errlog := &models.HisOrderError{
  572. UserOrgId: adminUser.CurrentOrgId,
  573. Ctime: time.Now().Unix(),
  574. Mtime: time.Now().Unix(),
  575. ErrMsg: res.ErrMsg,
  576. Status: 1,
  577. PatientId: id,
  578. RecordTime: recordDateTime,
  579. Stage: 1,
  580. }
  581. service.CreateErrMsgLog(errlog)
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  583. return
  584. }
  585. } else {
  586. timeStr := time.Now().Format("2006-01-02")
  587. timeArr := strings.Split(timeStr, "-")
  588. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  589. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  590. var hisPatient models.XtHisPatient
  591. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  592. hisPatient = models.XtHisPatient{
  593. Name: name,
  594. Age: age,
  595. Gender: gender,
  596. Birthday: birthUnix,
  597. Phone: phone,
  598. MedicalTreatmentType: medical_care,
  599. IdType: certificates,
  600. IdCardNo: id_card,
  601. BalanceAccountsType: settlementValue,
  602. SocialType: social_type,
  603. MedicalInsuranceNumber: medical_insurance_card,
  604. RegisterType: register_type,
  605. RegisterCost: registration_fee,
  606. TreatmentCost: medical_expenses,
  607. AdminUserId: adminInfo.AdminUser.Id,
  608. UserOrgId: adminInfo.CurrentOrgId,
  609. Status: 1,
  610. RecordDate: recordDateTime,
  611. IsReturn: 1,
  612. PatientId: patient.ID,
  613. Ctime: time.Now().Unix(),
  614. Mtime: time.Now().Unix(),
  615. Number: str,
  616. }
  617. service.CreateHisPatient(&hisPatient)
  618. }
  619. c.ServeSuccessJSON(map[string]interface{}{
  620. "his_info": hisPatient,
  621. })
  622. }
  623. }
  624. //上传明细----结算
  625. func (c *HisApiController) GetUploadInfo() {
  626. id, _ := c.GetInt64("id")
  627. record_time := c.GetString("record_time")
  628. pay_way, _ := c.GetInt64("pay_way")
  629. pay_price, _ := c.GetFloat("pay_price")
  630. pay_card_no := c.GetString("pay_card_no")
  631. discount_price, _ := c.GetFloat("discount_price")
  632. preferential_price, _ := c.GetFloat("preferential_price")
  633. reality_price, _ := c.GetFloat("reality_price")
  634. found_price, _ := c.GetFloat("found_price")
  635. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  636. private_price, _ := c.GetFloat("private_price")
  637. //settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  638. timeLayout := "2006-01-02"
  639. loc, _ := time.LoadLocation("Local")
  640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  641. if err != nil {
  642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  643. return
  644. }
  645. recordDateTime := theTime.Unix()
  646. adminUser := c.GetAdminUserInfo()
  647. var prescriptions []*models.HisPrescription
  648. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  649. //if settle_accounts_type == 1 { //日结
  650. //
  651. //} else
  652. //{ //月结
  653. // start_time := c.GetString("start_time")
  654. // end_time := c.GetString("end_time")
  655. // timeLayout := "2006-01-02"
  656. // loc, _ := time.LoadLocation("Local")
  657. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  658. // if err != nil {
  659. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  660. // return
  661. // }
  662. // recordStartTime := theStartTime.Unix()
  663. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  664. // if err != nil {
  665. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. // return
  667. // }
  668. // recordEndTime := theEndTime.Unix()
  669. // monthPrescriptions, _ := service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  670. // var advices []*models.HisDoctorAdviceInfo
  671. // var projects []*models.HisPrescriptionProject
  672. // var additions []*models.HisAdditionalCharge
  673. // var customs []*models.Custom
  674. // for _, item := range monthPrescriptions {
  675. // advices = append(advices, item.HisDoctorAdviceInfo...)
  676. // projects = append(projects, item.HisPrescriptionProject...)
  677. // additions = append(additions, item.HisAdditionalCharge...)
  678. // }
  679. //
  680. // var adviceCodes []string
  681. // var projectCodes []string
  682. // var additionCodes []string
  683. //
  684. //
  685. //
  686. //
  687. // for _, item := range advices {
  688. // adviceCodes = append(adviceCodes, item.MedListCodg)
  689. // }
  690. // for _, item := range projects {
  691. // projectCodes = append(projectCodes, item.MedListCodg)
  692. // }
  693. // for _, item := range additions {
  694. // additionCodes = append(additionCodes, item.XtHisAddtionConfig.Code)
  695. // }
  696. // adviceCodes = RemoveRepeatedCode(adviceCodes)
  697. // projectCodes = RemoveRepeatedCode(projectCodes)
  698. // additionCodes = RemoveRepeatedCode(additionCodes)
  699. //
  700. // for _, item := range adviceCodes{
  701. // var custom models.Custom
  702. // for _,subItem := range advices{
  703. // if item == subItem.MedListCodg{
  704. // custom.Price =fmt.Sprintf("%.2f", subItem.Price)
  705. // custom.MedListCodg = subItem.MedListCodg
  706. // custom.Cut = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  707. // custom.DetItemFeeSumamt = fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber)
  708. // custom.FeedetlSn = subItem.FeedetlSn
  709. // customs = append(customs,&custom)
  710. // }
  711. // }
  712. // }
  713. //
  714. //
  715. // for _, item := range additionCodes{
  716. // var custom models.Custom
  717. // for _,subItem := range additions{
  718. // if item == subItem.XtHisAddtionConfig.Code{
  719. // custom.Price =fmt.Sprintf("%.2f", subItem.Price)
  720. // custom.MedListCodg = subItem.XtHisAddtionConfig.Code
  721. // custom.Cut = fmt.Sprintf("%.2f", subItem.Count)
  722. // custom.DetItemFeeSumamt = fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count))
  723. // custom.FeedetlSn = subItem.FeedetlSn
  724. // customs = append(customs,&custom)
  725. // }
  726. // }
  727. // }
  728. //
  729. // for _, item := range projectCodes{
  730. // var custom models.Custom
  731. // for _,subItem := range projects{
  732. // if item == subItem.MedListCodg{
  733. // custom.Price =fmt.Sprintf("%.2f", subItem.Price)
  734. // custom.MedListCodg = subItem.MedListCodg
  735. // custom.Cut = fmt.Sprintf("%.2f", subItem.Count)
  736. // custom.DetItemFeeSumamt = fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count))
  737. // custom.FeedetlSn = subItem.FeedetlSn
  738. // customs = append(customs,&custom)
  739. // }
  740. // }
  741. // }
  742. //
  743. //}
  744. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  745. timestamp := time.Now().Unix()
  746. tempTime := time.Unix(timestamp, 0)
  747. timeFormat := tempTime.Format("20060102150405")
  748. chrgBchno := rand.Intn(100000) + 10000
  749. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  750. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  751. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  752. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  753. strconv.FormatInt(his.PatientId, 10)
  754. client := &http.Client{}
  755. data := make(map[string]interface{})
  756. data["psn_no"] = his.PsnNo
  757. data["mdtrt_id"] = his.Number
  758. data["pre"] = prescriptions
  759. data["chrg_bchno"] = chrg_bchno
  760. data["org_name"] = miConfig.OrgName
  761. data["doctor"] = patientPrescription.Doctor
  762. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  763. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  764. data["fixmedins_code"] = miConfig.Code
  765. data["dept_code"] = department.Number
  766. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  767. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  768. data["secret_key"] = miConfig.SecretKey
  769. var ids []int64
  770. for _, item := range prescriptions {
  771. ids = append(ids, item.ID)
  772. }
  773. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  774. if config.IsOpen == 1 { //对接了医保,走医保流程
  775. bytesData, _ := json.Marshal(data)
  776. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  777. resp, _ := client.Do(req)
  778. defer resp.Body.Close()
  779. body, ioErr := ioutil.ReadAll(resp.Body)
  780. if ioErr != nil {
  781. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  783. return
  784. }
  785. var respJSON map[string]interface{}
  786. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  787. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  789. return
  790. }
  791. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  792. userJSONBytes, _ := json.Marshal(respJSON)
  793. var res ResultFour
  794. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  795. utils.ErrorLog("解析失败:%v", err)
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  797. return
  798. }
  799. if res.Infcode == 0 {
  800. order := &models.HisOrder{
  801. UserOrgId: adminUser.CurrentOrgId,
  802. HisPatientId: his.ID,
  803. PatientId: his.PatientId,
  804. SettleAccountsDate: recordDateTime,
  805. Ctime: time.Now().Unix(),
  806. Mtime: time.Now().Unix(),
  807. Status: 1,
  808. Number: chrg_bchno,
  809. Infcode: res.Infcode,
  810. WarnMsg: res.WarnMsg,
  811. Cainfo: res.Cainfo,
  812. ErrMsg: res.ErrMsg,
  813. RespondTime: res.RefmsgTime,
  814. InfRefmsgid: res.InfRefmsgid,
  815. OrderStatus: 1,
  816. PayWay: pay_way,
  817. PayPrice: pay_price,
  818. PayCardNo: pay_card_no,
  819. DiscountPrice: discount_price,
  820. PreferentialPrice: preferential_price,
  821. RealityPrice: reality_price,
  822. FoundPrice: found_price,
  823. MedicalInsurancePrice: medical_insurance_price,
  824. PrivatePrice: private_price,
  825. IsMedicineInsurance: 1,
  826. }
  827. err = service.CreateOrder(order)
  828. if err != nil {
  829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  830. return
  831. }
  832. for _, item := range res.Output.Result {
  833. temp := strings.Split(item.FeedetlSn, "-")
  834. var advice_id int64 = 0
  835. var project_id int64 = 0
  836. var types int64 = 0
  837. id, _ := strconv.ParseInt(temp[2], 10, 64)
  838. types, _ = strconv.ParseInt(temp[1], 10, 64)
  839. if temp[1] == "1" {
  840. advice_id = id
  841. project_id = 0
  842. } else if temp[1] == "2" {
  843. advice_id = 0
  844. project_id = id
  845. }
  846. info := &models.HisOrderInfo{
  847. OrderNumber: order.Number,
  848. FeedetlSn: item.FeedetlSn,
  849. UploadDate: time.Now().Unix(),
  850. AdviceId: advice_id,
  851. DetItemFeeSumamt: item.DetItemFeeSumamt,
  852. Cnt: item.Cnt,
  853. Pric: float64(item.Pric),
  854. PatientId: his.PatientId,
  855. PricUplmtAmt: item.PricUplmtAmt,
  856. SelfpayProp: item.SelfpayProp,
  857. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  858. OverlmtAmt: item.OverlmtAmt,
  859. PreselfpayAmt: item.PreselfpayAmt,
  860. BasMednFlag: item.BasMednFlag,
  861. MedChrgitmType: item.MedChrgitmType,
  862. HiNegoDrugFlag: item.HiNegoDrugFlag,
  863. Status: 1,
  864. Memo: item.Memo,
  865. Mtime: time.Now().Unix(),
  866. InscpScpAmt: item.InscpScpAmt,
  867. DrtReimFlag: item.DrtReimFlag,
  868. Ctime: time.Now().Unix(),
  869. ListSpItemFlag: item.ListSpItemFlag,
  870. ChldMedcFlag: item.ChldMedcFlag,
  871. LmtUsedFlag: item.LmtUsedFlag,
  872. ChrgitmLv: item.ChrgitmLv,
  873. UserOrgId: adminUser.CurrentOrgId,
  874. HisPatientId: his.ID,
  875. OrderId: order.ID,
  876. ProjectId: project_id,
  877. Type: types,
  878. }
  879. service.CreateOrderInfo(info)
  880. }
  881. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  882. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  883. var total float64
  884. for _, item := range prescriptions {
  885. if item.Type == 1 { //药品
  886. for _, subItem := range item.HisDoctorAdviceInfo {
  887. total = total + (subItem.Price * subItem.PrescribingNumber)
  888. }
  889. }
  890. if item.Type == 2 { //项目
  891. for _, subItem := range item.HisPrescriptionProject {
  892. total = total + (subItem.Price * float64(subItem.Count))
  893. }
  894. }
  895. }
  896. for _, item := range prescriptions {
  897. for _, subItem := range item.HisAdditionalCharge {
  898. total = total + (subItem.Price * float64(subItem.Count))
  899. }
  900. }
  901. allTotal := fmt.Sprintf("%.2f", total)
  902. if res.Infcode == 0 {
  903. var rf []*ResultFive
  904. json.Unmarshal([]byte(his.Iinfo), &rf)
  905. psn_no := his.PsnNo
  906. mdtrt_id := his.Number
  907. chrg_bchno := chrg_bchno
  908. cert_no := his.Certno
  909. insutype := rf[0].Insutype
  910. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  911. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  912. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10)
  913. resp, requestErr := http.Get(api)
  914. if requestErr != nil {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  916. return
  917. }
  918. defer resp.Body.Close()
  919. body, ioErr := ioutil.ReadAll(resp.Body)
  920. if ioErr != nil {
  921. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  923. return
  924. }
  925. var respJSON map[string]interface{}
  926. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  927. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  929. return
  930. }
  931. fmt.Println(respJSON)
  932. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  933. userJSONBytes, _ := json.Marshal(respJSON)
  934. var res ResultSeven
  935. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  936. utils.ErrorLog("解析失败:%v", err)
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  938. return
  939. }
  940. if res.Infcode == -1 {
  941. errlog := &models.HisOrderError{
  942. UserOrgId: adminUser.CurrentOrgId,
  943. Ctime: time.Now().Unix(),
  944. Mtime: time.Now().Unix(),
  945. Number: chrg_bchno,
  946. ErrMsg: res.ErrMsg,
  947. Status: 1,
  948. PatientId: id,
  949. RecordTime: recordDateTime,
  950. Stage: 6,
  951. }
  952. service.CreateErrMsgLog(errlog)
  953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  954. return
  955. } else {
  956. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  957. order.OrderStatus = 2
  958. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  959. order.SetlId = res.Output.Setlinfo.SetlID
  960. order.PsnNo = res.Output.Setlinfo.PsnNo
  961. order.PsnName = res.Output.Setlinfo.PsnName
  962. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  963. order.Certno = res.Output.Setlinfo.Certno
  964. order.Gend = res.Output.Setlinfo.Gend
  965. order.Naty = res.Output.Setlinfo.Naty
  966. order.Age = res.Output.Setlinfo.Age
  967. order.Insutype = res.Output.Setlinfo.Insutype
  968. order.PsnType = res.Output.Setlinfo.PsnType
  969. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  970. order.SetlTime = res.Output.Setlinfo.SetlTime
  971. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  972. order.MedType = res.Output.Setlinfo.MedType
  973. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  974. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  975. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  976. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  977. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  978. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  979. order.HifpPay = res.Output.Setlinfo.HifpPay
  980. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  981. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  982. order.HifesPay = res.Output.Setlinfo.HifesPay
  983. order.HifobPay = res.Output.Setlinfo.HifobPay
  984. order.MafPay = res.Output.Setlinfo.MafPay
  985. order.OthPay = res.Output.Setlinfo.OthPay
  986. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  987. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  988. order.AcctPay = res.Output.Setlinfo.AcctPay
  989. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  990. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  991. order.Balc = res.Output.Setlinfo.Balc
  992. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  993. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  994. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  995. order.ClrWay = res.Output.Setlinfo.ClrWay
  996. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  997. detailStr := string(setlDetail)
  998. order.SetlDetail = detailStr
  999. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1000. err = service.UpDateOrder(order)
  1001. if err == nil {
  1002. c.ServeSuccessJSON(map[string]interface{}{
  1003. "msg": "结算成功",
  1004. })
  1005. } else {
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1007. return
  1008. }
  1009. }
  1010. } else {
  1011. adminUser := c.GetAdminUserInfo()
  1012. errlog := &models.HisOrderError{
  1013. UserOrgId: adminUser.CurrentOrgId,
  1014. Ctime: time.Now().Unix(),
  1015. Mtime: time.Now().Unix(),
  1016. ErrMsg: res.ErrMsg,
  1017. Status: 1,
  1018. PatientId: id,
  1019. RecordTime: recordDateTime,
  1020. Stage: 4,
  1021. }
  1022. service.CreateErrMsgLog(errlog)
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1024. return
  1025. }
  1026. } else {
  1027. adminUser := c.GetAdminUserInfo()
  1028. errlog := &models.HisOrderError{
  1029. UserOrgId: adminUser.CurrentOrgId,
  1030. Ctime: time.Now().Unix(),
  1031. Mtime: time.Now().Unix(),
  1032. ErrMsg: res.ErrMsg,
  1033. Status: 1,
  1034. PatientId: id,
  1035. RecordTime: recordDateTime,
  1036. Stage: 4,
  1037. }
  1038. service.CreateErrMsgLog(errlog)
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1040. return
  1041. }
  1042. } else {
  1043. var total float64
  1044. for _, item := range prescriptions {
  1045. if item.Type == 1 { //药品
  1046. for _, subItem := range item.HisDoctorAdviceInfo {
  1047. total = total + (subItem.Price * subItem.PrescribingNumber)
  1048. }
  1049. }
  1050. if item.Type == 2 { //项目
  1051. for _, subItem := range item.HisPrescriptionProject {
  1052. total = total + (subItem.Price * float64(subItem.Count))
  1053. }
  1054. }
  1055. for _, subItem := range item.HisAdditionalCharge {
  1056. total = total + (subItem.Price * float64(subItem.Count))
  1057. }
  1058. }
  1059. allTotal := fmt.Sprintf("%.2f", total)
  1060. totals, _ := strconv.ParseFloat(allTotal, 64)
  1061. order := &models.HisOrder{
  1062. UserOrgId: adminUser.CurrentOrgId,
  1063. HisPatientId: his.ID,
  1064. PatientId: id,
  1065. SettleAccountsDate: recordDateTime,
  1066. Ctime: time.Now().Unix(),
  1067. Mtime: time.Now().Unix(),
  1068. Status: 1,
  1069. OrderStatus: 2,
  1070. Number: chrg_bchno,
  1071. MedfeeSumamt: totals,
  1072. PayWay: pay_way,
  1073. PayPrice: pay_price,
  1074. PayCardNo: pay_card_no,
  1075. DiscountPrice: discount_price,
  1076. PreferentialPrice: preferential_price,
  1077. RealityPrice: reality_price,
  1078. FoundPrice: found_price,
  1079. MedicalInsurancePrice: medical_insurance_price,
  1080. PrivatePrice: private_price,
  1081. }
  1082. err = service.CreateOrder(order)
  1083. if err != nil {
  1084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1085. return
  1086. }
  1087. var customs []*Custom
  1088. for _, item := range prescriptions {
  1089. if item.Type == 1 { //药品
  1090. for _, subItem := range item.HisDoctorAdviceInfo {
  1091. cus := &Custom{
  1092. AdviceId: subItem.ID,
  1093. ProjectId: 0,
  1094. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1095. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1096. FeedetlSn: subItem.FeedetlSn,
  1097. Price: fmt.Sprintf("%.2f", subItem.Price),
  1098. MedListCodg: subItem.MedListCodg,
  1099. Type: 1,
  1100. }
  1101. customs = append(customs, cus)
  1102. }
  1103. }
  1104. if item.Type == 2 { //项目
  1105. for _, subItem := range item.HisPrescriptionProject {
  1106. cus := &Custom{
  1107. AdviceId: 0,
  1108. ProjectId: subItem.ID,
  1109. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1110. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1111. FeedetlSn: subItem.FeedetlSn,
  1112. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1113. MedListCodg: subItem.MedListCodg,
  1114. Type: 2,
  1115. }
  1116. customs = append(customs, cus)
  1117. }
  1118. }
  1119. for _, item := range item.HisAdditionalCharge {
  1120. cus := &Custom{
  1121. ItemId: item.ID,
  1122. AdviceId: 0,
  1123. ProjectId: 0,
  1124. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1125. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1126. FeedetlSn: item.FeedetlSn,
  1127. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1128. MedListCodg: item.XtHisAddtionConfig.Code,
  1129. Type: 3,
  1130. }
  1131. customs = append(customs, cus)
  1132. }
  1133. }
  1134. for _, item := range customs {
  1135. var advice_id int64 = 0
  1136. var project_id int64 = 0
  1137. var item_id int64 = 0
  1138. var types int64 = 0
  1139. if item.Type == 1 {
  1140. advice_id = item.AdviceId
  1141. project_id = 0
  1142. item_id = 0
  1143. } else if item.Type == 2 {
  1144. advice_id = 0
  1145. item_id = 0
  1146. project_id = item.ProjectId
  1147. } else if item.Type == 3 {
  1148. advice_id = 0
  1149. item_id = item.ItemId
  1150. project_id = 0
  1151. }
  1152. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1153. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1154. pric, _ := strconv.ParseFloat(item.Price, 32)
  1155. info := &models.HisOrderInfo{
  1156. OrderNumber: order.Number,
  1157. UploadDate: time.Now().Unix(),
  1158. AdviceId: advice_id,
  1159. DetItemFeeSumamt: detItemFeeSumamt,
  1160. Cnt: cut,
  1161. Pric: pric,
  1162. PatientId: id,
  1163. Status: 1,
  1164. Mtime: time.Now().Unix(),
  1165. Ctime: time.Now().Unix(),
  1166. UserOrgId: adminUser.CurrentOrgId,
  1167. HisPatientId: his.ID,
  1168. OrderId: order.ID,
  1169. ProjectId: project_id,
  1170. Type: types,
  1171. ItemId: item_id,
  1172. }
  1173. service.CreateOrderInfo(info)
  1174. }
  1175. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1176. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1177. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1178. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1179. if err == nil {
  1180. c.ServeSuccessJSON(map[string]interface{}{
  1181. "msg": "结算成功",
  1182. })
  1183. } else {
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1185. return
  1186. }
  1187. }
  1188. }
  1189. //退款
  1190. func (c *HisApiController) Refund() {
  1191. order_id, _ := c.GetInt64("order_id")
  1192. number := c.GetString("number")
  1193. record_time := c.GetString("record_time")
  1194. patient_id, _ := c.GetInt64("patient_id")
  1195. timeLayout := "2006-01-02"
  1196. loc, _ := time.LoadLocation("Local")
  1197. adminUser := c.GetAdminUserInfo()
  1198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1199. fmt.Println(err)
  1200. if err != nil {
  1201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1202. return
  1203. }
  1204. recordDateTime := theTime.Unix()
  1205. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1206. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1207. order, _ := service.GetHisOrderByID(order_id)
  1208. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1209. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1210. if config.IsOpen == 1 { //对接了医保,走医保流程
  1211. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1212. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1213. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1214. resp, requestErr := http.Get(api)
  1215. if requestErr != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1217. return
  1218. }
  1219. body, ioErr := ioutil.ReadAll(resp.Body)
  1220. if ioErr != nil {
  1221. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1223. return
  1224. }
  1225. var respJSON map[string]interface{}
  1226. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1227. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1229. return
  1230. }
  1231. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1232. userJSONBytes, _ := json.Marshal(respJSON)
  1233. fmt.Println(respJSON)
  1234. fmt.Println(userJSONBytes)
  1235. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1236. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1237. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1238. resp2, requestErr2 := http.Get(api2)
  1239. if requestErr2 != nil {
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1241. return
  1242. }
  1243. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1244. if ioErr2 != nil {
  1245. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1247. return
  1248. }
  1249. var respJSON2 map[string]interface{}
  1250. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1251. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1253. return
  1254. }
  1255. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1256. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1257. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1258. resp3, requestErr3 := http.Get(api3)
  1259. if requestErr3 != nil {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1261. return
  1262. }
  1263. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1264. if ioErr3 != nil {
  1265. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1267. return
  1268. }
  1269. var respJSON3 map[string]interface{}
  1270. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1271. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1273. return
  1274. }
  1275. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1276. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1277. if err == nil {
  1278. c.ServeSuccessJSON(map[string]interface{}{
  1279. "msg": "退费成功",
  1280. })
  1281. } else {
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1283. return
  1284. }
  1285. } else {
  1286. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1287. if err == nil {
  1288. c.ServeSuccessJSON(map[string]interface{}{
  1289. "msg": "退费成功",
  1290. })
  1291. } else {
  1292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1293. return
  1294. }
  1295. }
  1296. }
  1297. func (c *HisApiController) RefundNumber() {
  1298. record_time := c.GetString("record_time")
  1299. patient_id, _ := c.GetInt64("patient_id")
  1300. timeLayout := "2006-01-02"
  1301. loc, _ := time.LoadLocation("Local")
  1302. adminUser := c.GetAdminUserInfo()
  1303. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1304. fmt.Println(err)
  1305. if err != nil {
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1307. return
  1308. }
  1309. recordDateTime := theTime.Unix()
  1310. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1311. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1312. //order, _ := service.GetHisOrderByID(order_id)
  1313. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1314. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1315. if config.IsOpen == 1 { //对接了医保,走医保流程
  1316. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1317. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1318. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1319. resp3, requestErr3 := http.Get(api3)
  1320. if requestErr3 != nil {
  1321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1322. return
  1323. }
  1324. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1325. if ioErr3 != nil {
  1326. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1328. return
  1329. }
  1330. var respJSON3 map[string]interface{}
  1331. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1332. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1334. return
  1335. }
  1336. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1337. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1338. if err == nil {
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "msg": "退费成功",
  1341. })
  1342. } else {
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1344. return
  1345. }
  1346. } else {
  1347. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1348. //if err == nil {
  1349. // c.ServeSuccessJSON(map[string]interface{}{
  1350. // "msg": "退费成功",
  1351. // })
  1352. //} else {
  1353. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1354. // return
  1355. //}
  1356. }
  1357. }
  1358. func (c *HisApiController) RefundDetail() {
  1359. order_id, _ := c.GetInt64("order_id")
  1360. number := c.GetString("number")
  1361. record_time := c.GetString("record_time")
  1362. patient_id, _ := c.GetInt64("patient_id")
  1363. timeLayout := "2006-01-02"
  1364. loc, _ := time.LoadLocation("Local")
  1365. adminUser := c.GetAdminUserInfo()
  1366. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1367. fmt.Println(err)
  1368. if err != nil {
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1370. return
  1371. }
  1372. recordDateTime := theTime.Unix()
  1373. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1374. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1375. order, _ := service.GetHisOrderByID(order_id)
  1376. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1377. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1378. if config.IsOpen == 1 { //对接了医保,走医保流程
  1379. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1380. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1381. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1382. resp2, requestErr2 := http.Get(api2)
  1383. if requestErr2 != nil {
  1384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1385. return
  1386. }
  1387. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1388. if ioErr2 != nil {
  1389. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1391. return
  1392. }
  1393. var respJSON2 map[string]interface{}
  1394. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1395. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1397. return
  1398. }
  1399. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1400. if err == nil {
  1401. c.ServeSuccessJSON(map[string]interface{}{
  1402. "msg": "退费成功",
  1403. })
  1404. } else {
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1406. return
  1407. }
  1408. } else {
  1409. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1410. if err == nil {
  1411. c.ServeSuccessJSON(map[string]interface{}{
  1412. "msg": "退费成功",
  1413. })
  1414. } else {
  1415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1416. return
  1417. }
  1418. }
  1419. }
  1420. //对账
  1421. func (c *HisApiController) GetCheckAccount() {
  1422. start_time := c.GetString("start_time")
  1423. end_time := c.GetString("end_time")
  1424. insutype := c.GetString("insutype")
  1425. clr_type := c.GetString("clr_type")
  1426. adminUser := c.GetAdminUserInfo()
  1427. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1428. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1429. timeLayout := "2006-01-02"
  1430. loc, _ := time.LoadLocation("Local")
  1431. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1432. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1433. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1434. decimal.DivisionPrecision = 2
  1435. var medfee_sumamt float64
  1436. var acct_pay float64
  1437. var fund_pay_sumamt float64
  1438. fixmedins_setl_cnt := int64(len(orders))
  1439. for _, item := range orders {
  1440. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1441. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1442. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1443. }
  1444. var user_name string
  1445. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1446. if role.ID == 0 {
  1447. user_name = "xxx"
  1448. } else {
  1449. user_name = role.UserName
  1450. }
  1451. if config.IsOpen == 1 {
  1452. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1453. "insutype=" + insutype +
  1454. "&clr_type=" + clr_type +
  1455. "&setl_optins=" + miConfig.OrgName +
  1456. "&stmt_begndate=" + start_time +
  1457. "&stm_enddate=" + end_time +
  1458. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1459. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1460. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1461. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1462. "&fixmedins_code=" + miConfig.Code +
  1463. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1464. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1465. "&secret_key=" + miConfig.SecretKey +
  1466. "&org_name=" + miConfig.OrgName +
  1467. "&doctor=" + user_name
  1468. fmt.Println(api)
  1469. resp, requestErr := http.Get(api)
  1470. if requestErr != nil {
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1472. return
  1473. }
  1474. body, ioErr := ioutil.ReadAll(resp.Body)
  1475. fmt.Println(body)
  1476. if ioErr != nil {
  1477. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1479. return
  1480. }
  1481. var respJSON map[string]interface{}
  1482. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1483. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1485. return
  1486. }
  1487. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1488. userJSONBytes, _ := json.Marshal(respJSON)
  1489. var res ResultEight
  1490. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1491. utils.ErrorLog("解析失败:%v", err)
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1493. return
  1494. }
  1495. if res.Infcode == 0 {
  1496. c.ServeSuccessJSON(map[string]interface{}{
  1497. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1498. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1499. })
  1500. } else {
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1502. }
  1503. }
  1504. }
  1505. //对账明细
  1506. func (c *HisApiController) GetCheckDetailAccount() {
  1507. start_time := c.GetString("start_time")
  1508. end_time := c.GetString("end_time")
  1509. adminUser := c.GetAdminUserInfo()
  1510. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1511. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1512. timeLayout := "2006-01-02"
  1513. loc, _ := time.LoadLocation("Local")
  1514. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1515. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1516. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1517. Mkdir(miConfig.OrgName)
  1518. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1519. file_name := file + ".txt"
  1520. zip_name := file + ".zip"
  1521. zip_path := miConfig.OrgName + "/" + zip_name
  1522. file_path := miConfig.OrgName + "/" + file_name
  1523. decimal.DivisionPrecision = 2
  1524. var medfee_sumamt float64
  1525. var psn_cash_pay float64
  1526. var fund_pay_sumamt float64
  1527. fixmedins_setl_cnt := int64(len(orders))
  1528. for _, item := range orders {
  1529. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1530. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1531. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1532. }
  1533. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1534. defer f.Close()
  1535. if err != nil {
  1536. fmt.Println(err.Error())
  1537. } else {
  1538. for _, item := range orders {
  1539. var refd_setl_flag string
  1540. if item.OrderStatus == 2 {
  1541. refd_setl_flag = "0"
  1542. }
  1543. if item.OrderStatus == 3 {
  1544. refd_setl_flag = "1"
  1545. }
  1546. var str string
  1547. str = item.SetlId + " " +
  1548. item.MdtrtId + " " +
  1549. item.PsnNo + " " +
  1550. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1551. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1552. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1553. _, err = f.Write([]byte(str))
  1554. }
  1555. }
  1556. Zip(file_path, zip_path)
  1557. fmt.Println(ReadFile(zip_path))
  1558. fmt.Println(string(ReadFile(zip_path)))
  1559. if config.IsOpen == 1 {
  1560. var user_name string
  1561. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1562. if role.ID == 0 {
  1563. user_name = "xxx"
  1564. } else {
  1565. user_name = role.UserName
  1566. }
  1567. baseParams := models.BaseParams{
  1568. SecretKey: miConfig.SecretKey,
  1569. FixmedinsCode: miConfig.Code,
  1570. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1571. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1572. OrgName: miConfig.OrgName,
  1573. Doctor: user_name,
  1574. }
  1575. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1576. var dat map[string]interface{}
  1577. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1578. fmt.Println(dat)
  1579. } else {
  1580. fmt.Println(err)
  1581. }
  1582. userJSONBytes, _ := json.Marshal(dat)
  1583. var res ResultNine
  1584. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1585. utils.ErrorLog("解析失败:%v", err)
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1587. return
  1588. }
  1589. if res.Infcode == 0 {
  1590. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1591. "file_qury_no=" + res.Output.FileQuryNo +
  1592. "&setl_optins=" + miConfig.OrgName +
  1593. "&stmt_begndate=" + start_time +
  1594. "&stm_enddate=" + end_time +
  1595. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1596. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1597. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1598. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1599. "&fixmedins_code=" + miConfig.Code +
  1600. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1601. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1602. "&secret_key=" + miConfig.SecretKey +
  1603. "&org_name=" + miConfig.OrgName +
  1604. "&doctor=" + user_name
  1605. resp, requestErr := http.Get(api)
  1606. if requestErr != nil {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1608. return
  1609. }
  1610. body, ioErr := ioutil.ReadAll(resp.Body)
  1611. if ioErr != nil {
  1612. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1614. return
  1615. }
  1616. var respJSON map[string]interface{}
  1617. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1618. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1620. return
  1621. }
  1622. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1623. userJSONBytes, _ := json.Marshal(respJSON)
  1624. var res ResultTen
  1625. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1626. utils.ErrorLog("解析失败:%v", err)
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1628. return
  1629. }
  1630. if res.Infcode == 0 {
  1631. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1632. c.ServeSuccessJSON(map[string]interface{}{
  1633. "msg": "明细对账成功",
  1634. })
  1635. }
  1636. } else {
  1637. }
  1638. }
  1639. }
  1640. func (c *HisApiController) GetSettleAccounts() {
  1641. //id, _ := c.GetInt64("id")
  1642. //record_time := c.GetString("record_time")
  1643. order_id, _ := c.GetInt64("order_id")
  1644. //timeLayout := "2006-01-02"
  1645. //loc, _ := time.LoadLocation("Local")
  1646. //
  1647. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1648. //if err != nil {
  1649. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1650. // return
  1651. //}
  1652. //recordDateTime := theTime.Unix()
  1653. adminUser := c.GetAdminUserInfo()
  1654. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1655. order, _ := service.GetHisOrderByID(order_id)
  1656. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  1657. var bedCostTotal float64 = 0 //床位总费
  1658. var bedCostSelfTotal float64 = 0 //床位自费
  1659. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  1660. var operationCostTotal float64 = 0 //手术费
  1661. var operationCostSelfTotal float64 = 0 //手术费
  1662. var operationCostPartSelfTotal float64 = 0 //手术费
  1663. var otherCostTotal float64 = 0 //其他费用
  1664. var otherCostSelfTotal float64 = 0 //其他费用
  1665. var otherCostPartSelfTotal float64 = 0 //其他费用
  1666. var materialCostTotal float64 = 0 //材料费
  1667. var materialCostSelfTotal float64 = 0 //材料费
  1668. var materialCostPartSelfTotal float64 = 0 //材料费
  1669. var westernMedicineCostTotal float64 = 0 //西药费
  1670. var westernMedicineCostSelfTotal float64 = 0 //西药费
  1671. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  1672. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  1673. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  1674. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  1675. var checkCostTotal float64 = 0 //检查费
  1676. var checkCostSelfTotal float64 = 0 //检查费
  1677. var checkCostPartSelfTotal float64 = 0 //检查费
  1678. var laboratoryCostTotal float64 = 0 //化验费
  1679. var laboratoryCostSelfTotal float64 = 0 //化验费
  1680. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  1681. var treatCostTotal float64 = 0 //治疗费用
  1682. var treatCostSelfTotal float64 = 0 //治疗费用
  1683. var treatCostPartSelfTotal float64 = 0 //治疗费用
  1684. decimal.DivisionPrecision = 2
  1685. for _, item := range orderInfos {
  1686. if item.MedChrgitmType == "01" { //床位费
  1687. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1688. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1689. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1690. }
  1691. if item.MedChrgitmType == "03" { //检查费
  1692. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1693. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1694. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1695. }
  1696. if item.MedChrgitmType == "04" { //化验费
  1697. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1698. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1699. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1700. }
  1701. if item.MedChrgitmType == "05" { //治疗费
  1702. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1703. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1704. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1705. }
  1706. if item.MedChrgitmType == "06" { //手术费
  1707. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1708. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1709. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1710. }
  1711. if item.MedChrgitmType == "08" { //材料费
  1712. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1713. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1714. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1715. }
  1716. if item.MedChrgitmType == "09" { //西药费
  1717. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1718. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1719. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1720. }
  1721. if item.MedChrgitmType == "11" { //中成费
  1722. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1723. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1724. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1725. }
  1726. if item.MedChrgitmType == "14" { //其他费
  1727. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1728. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1729. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1730. }
  1731. }
  1732. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1733. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1734. var user_name string
  1735. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1736. if role.ID == 0 {
  1737. user_name = "xxx"
  1738. } else {
  1739. user_name = role.UserName
  1740. }
  1741. baseParams := models.BaseParams{
  1742. SecretKey: miConfig.SecretKey,
  1743. FixmedinsCode: miConfig.Code,
  1744. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1745. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1746. OrgName: miConfig.OrgName,
  1747. Doctor: user_name,
  1748. }
  1749. businessParams := models.BusinessParams{
  1750. PsnNo: order.PsnNo,
  1751. MdtrtId: order.MdtrtId,
  1752. SetlId: order.SetlId,
  1753. }
  1754. if config.IsOpen == 1 {
  1755. result := service.Gdyb5203(baseParams, businessParams)
  1756. var dat map[string]interface{}
  1757. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1758. fmt.Println(dat)
  1759. } else {
  1760. fmt.Println(err)
  1761. }
  1762. userJSONBytes, _ := json.Marshal(dat)
  1763. var res ResultEleven
  1764. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1765. utils.ErrorLog("解析失败:%v", err)
  1766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1767. return
  1768. }
  1769. if res.Infcode == 0 {
  1770. c.ServeSuccessJSON(map[string]interface{}{
  1771. "info": res.Output.Setlinfo,
  1772. "bedCostTotal": bedCostTotal,
  1773. "bedCostSelfTotal": bedCostSelfTotal,
  1774. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1775. "operationCostTotal": operationCostTotal,
  1776. "operationCostSelfTotal": operationCostSelfTotal,
  1777. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1778. "otherCostTotal": otherCostTotal,
  1779. "otherCostSelfTotal": otherCostSelfTotal,
  1780. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1781. "materialCostTotal": materialCostTotal,
  1782. "materialCostSelfTotal": materialCostSelfTotal,
  1783. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1784. "westernMedicineCostTotal": westernMedicineCostTotal,
  1785. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1786. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1787. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1788. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1789. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1790. "checkCostTotal": checkCostTotal,
  1791. "checkCostSelfTotal": checkCostSelfTotal,
  1792. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1793. "laboratoryCostTotal": laboratoryCostTotal,
  1794. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1795. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1796. "treatCostTotal": treatCostTotal,
  1797. "treatCostSelfTotal": treatCostSelfTotal,
  1798. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1799. })
  1800. }
  1801. }
  1802. }
  1803. func (c *HisApiController) GetCode() {
  1804. name := c.GetString("name")
  1805. codg := c.GetString("codg")
  1806. adminUser := c.GetAdminUserInfo()
  1807. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1808. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1809. var user_name string
  1810. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1811. if role.ID == 0 {
  1812. user_name = "xxx"
  1813. } else {
  1814. user_name = role.UserName
  1815. }
  1816. baseParams := models.BaseParams{
  1817. SecretKey: miConfig.SecretKey,
  1818. FixmedinsCode: miConfig.Code,
  1819. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1820. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1821. OrgName: miConfig.OrgName,
  1822. Doctor: user_name,
  1823. }
  1824. if config.IsOpen == 1 {
  1825. result := service.Gdyb3301(baseParams, name, codg)
  1826. var dat map[string]interface{}
  1827. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1828. fmt.Println(dat)
  1829. } else {
  1830. fmt.Println(err)
  1831. }
  1832. }
  1833. }
  1834. func (c *HisApiController) CheckTreatment() {
  1835. patient_id, _ := c.GetInt64("patient_id", 0)
  1836. record_time := c.GetString("record_time")
  1837. insutype := c.GetString("insutype")
  1838. timeLayout := "2006-01-02"
  1839. loc, _ := time.LoadLocation("Local")
  1840. adminUser := c.GetAdminUserInfo()
  1841. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1842. fmt.Println(err)
  1843. if err != nil {
  1844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1845. return
  1846. }
  1847. recordDateTime := theTime.Unix()
  1848. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1849. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1850. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1851. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1852. var user_name string
  1853. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1854. if role.ID == 0 {
  1855. user_name = "xxx"
  1856. } else {
  1857. user_name = role.UserName
  1858. }
  1859. baseParams := models.BaseParams{
  1860. SecretKey: miConfig.SecretKey,
  1861. FixmedinsCode: miConfig.Code,
  1862. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1863. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1864. OrgName: miConfig.OrgName,
  1865. Doctor: user_name,
  1866. }
  1867. if config.IsOpen == 1 {
  1868. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  1869. var dat map[string]interface{}
  1870. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1871. fmt.Println(dat)
  1872. } else {
  1873. fmt.Println(err)
  1874. }
  1875. }
  1876. }
  1877. func (c *HisApiController) PutRecord() {
  1878. id, _ := c.GetInt64("id")
  1879. record_time := c.GetString("record_time")
  1880. timeLayout := "2006-01-02"
  1881. loc, _ := time.LoadLocation("Local")
  1882. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1883. if err != nil {
  1884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1885. return
  1886. }
  1887. recordDateTime := theTime.Unix()
  1888. adminInfo := c.GetAdminUserInfo()
  1889. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1890. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1891. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1892. fmt.Println(miConfig.SecretKey)
  1893. if patient == nil {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1895. return
  1896. }
  1897. if len(patient.IdCardNo) == 0 {
  1898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1899. return
  1900. }
  1901. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1902. if config.IsOpen == 1 {
  1903. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1904. resp, requestErr := http.Get(api)
  1905. if requestErr != nil {
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. defer resp.Body.Close()
  1910. body, ioErr := ioutil.ReadAll(resp.Body)
  1911. if ioErr != nil {
  1912. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1914. return
  1915. }
  1916. var respJSON map[string]interface{}
  1917. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1918. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1920. return
  1921. }
  1922. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1923. userJSONBytes, _ := json.Marshal(userJSON)
  1924. var res ResultTwo
  1925. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1926. utils.ErrorLog("解析失败:%v", err)
  1927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1928. return
  1929. }
  1930. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1931. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1932. infoStr := string(Iinfos)
  1933. idetinfoStr := string(Idetinfos)
  1934. if res.Infcode == 0 {
  1935. his := models.VMHisPatient{
  1936. Status: 1,
  1937. Ctime: time.Now().Unix(),
  1938. Mtime: time.Now().Unix(),
  1939. PsnNo: res.Output.Baseinfo.PsnNo,
  1940. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1941. Certno: res.Output.Baseinfo.Certno,
  1942. PsnName: res.Output.Baseinfo.PsnName,
  1943. Gend: res.Output.Baseinfo.Gend,
  1944. Naty: res.Output.Baseinfo.Naty,
  1945. Brdy: res.Output.Baseinfo.Brdy,
  1946. Age: res.Output.Baseinfo.Age,
  1947. Iinfo: infoStr,
  1948. Idetinfo: idetinfoStr,
  1949. PatientId: patient.ID,
  1950. RecordDate: theTime.Unix(),
  1951. UserOrgId: adminInfo.CurrentOrgId,
  1952. AdminUserId: adminInfo.AdminUser.Id,
  1953. IsReturn: 1,
  1954. }
  1955. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1956. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  1957. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  1958. var dat map[string]interface{}
  1959. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1960. fmt.Println(dat)
  1961. } else {
  1962. fmt.Println(err)
  1963. }
  1964. var dat2 map[string]interface{}
  1965. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  1966. fmt.Println(dat2)
  1967. } else {
  1968. fmt.Println(err)
  1969. }
  1970. } else {
  1971. adminUser := c.GetAdminUserInfo()
  1972. errlog := &models.HisOrderError{
  1973. UserOrgId: adminUser.CurrentOrgId,
  1974. Ctime: time.Now().Unix(),
  1975. Mtime: time.Now().Unix(),
  1976. ErrMsg: res.ErrMsg,
  1977. Status: 1,
  1978. PatientId: id,
  1979. RecordTime: recordDateTime,
  1980. Stage: 1,
  1981. }
  1982. service.CreateErrMsgLog(errlog)
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1984. return
  1985. }
  1986. }
  1987. }
  1988. func PathExists(path string) (bool, error) {
  1989. _, err := os.Stat(path)
  1990. if err == nil {
  1991. return true, nil
  1992. }
  1993. if os.IsNotExist(err) {
  1994. return false, nil
  1995. }
  1996. return false, err
  1997. }
  1998. //创建文件夹
  1999. func Mkdir(dir string) {
  2000. // 创建文件夹
  2001. exist, err := PathExists(dir)
  2002. if err != nil {
  2003. fmt.Println(err.Error())
  2004. } else {
  2005. if exist {
  2006. fmt.Println(dir + "文件夹已存在!")
  2007. } else {
  2008. // 文件夹名称,权限
  2009. err := os.Mkdir(dir, os.ModePerm)
  2010. if err != nil {
  2011. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2012. } else {
  2013. fmt.Println(dir + "文件夹创建成功!")
  2014. }
  2015. }
  2016. }
  2017. }
  2018. //压缩文件
  2019. func Zip(srcFile string, destZip string) error {
  2020. zipfile, err := os.Create(destZip)
  2021. if err != nil {
  2022. return err
  2023. }
  2024. defer zipfile.Close()
  2025. archive := zip.NewWriter(zipfile)
  2026. defer archive.Close()
  2027. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2028. if err != nil {
  2029. return err
  2030. }
  2031. header, err := zip.FileInfoHeader(info)
  2032. if err != nil {
  2033. return err
  2034. }
  2035. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2036. // header.Name = path
  2037. if info.IsDir() {
  2038. header.Name += "/"
  2039. } else {
  2040. header.Method = zip.Deflate
  2041. }
  2042. writer, err := archive.CreateHeader(header)
  2043. if err != nil {
  2044. return err
  2045. }
  2046. if !info.IsDir() {
  2047. file, err := os.Open(path)
  2048. if err != nil {
  2049. return err
  2050. }
  2051. defer file.Close()
  2052. _, err = io.Copy(writer, file)
  2053. }
  2054. return err
  2055. })
  2056. return err
  2057. }
  2058. func ReadFile(filePath string) []byte {
  2059. f, err := os.Open(filePath)
  2060. if err != nil {
  2061. fmt.Println("read file fail", err)
  2062. return nil
  2063. }
  2064. defer f.Close()
  2065. fd, err := ioutil.ReadAll(f)
  2066. if err != nil {
  2067. fmt.Println("read to fd fail", err)
  2068. return nil
  2069. }
  2070. return fd
  2071. }
  2072. func RemoveRepeatedCode(arr []string) (newArr []string) {
  2073. newArr = make([]string, 0)
  2074. for i := 0; i < len(arr); i++ {
  2075. repeat := false
  2076. for j := i + 1; j < len(arr); j++ {
  2077. if arr[i] == arr[j] {
  2078. repeat = true
  2079. break
  2080. }
  2081. }
  2082. if !repeat {
  2083. newArr = append(newArr, arr[i])
  2084. }
  2085. }
  2086. return
  2087. }