his_api_controller.go 82KB

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