his_api_controller.go 76KB

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