his_api_controller.go 74KB

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